Initial commit: archer, a Go-native MySQL/MariaDB table archiver
Renamed from arcdb: module path, cmd/archer, internal/archererr, docs, build scripts and ARCHER_* environment variables. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
bc4a6b504f
99 files changed
+12752
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package row
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Options carries encoder-level knobs shared by all formats.
|
||||
type Options struct {
|
||||
CSVNull string
|
||||
}
|
||||
|
||||
// Encoder appends the textual representation of a row to dst. It is not safe
|
||||
// for concurrent use; each shard owns its own encoder.
|
||||
type Encoder interface {
|
||||
// Header returns bytes that must be written at the start of every shard.
|
||||
Header() []byte
|
||||
// Encode appends one row to dst.
|
||||
Encode(dst []byte, r Row) ([]byte, error)
|
||||
}
|
||||
|
||||
// NewEncoder builds an encoder for the given format. cols describes every
|
||||
// column in the row (select order) and idx selects which of them are emitted,
|
||||
// in output order.
|
||||
func NewEncoder(format string, cols []Column, idx []int, opts Options) (Encoder, error) {
|
||||
if len(idx) == 0 {
|
||||
idx = make([]int, len(cols))
|
||||
for i := range cols {
|
||||
idx[i] = i
|
||||
}
|
||||
}
|
||||
switch format {
|
||||
case "dump":
|
||||
return &dumpEncoder{idx: idx}, nil
|
||||
case "csv":
|
||||
return &csvEncoder{cols: cols, idx: idx, null: opts.CSVNull}, nil
|
||||
case "jsonl":
|
||||
return &jsonlEncoder{cols: cols, idx: idx}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported format %q", format)
|
||||
}
|
||||
}
|
||||
|
||||
// FormatExt returns the file extension for a format.
|
||||
func FormatExt(format string) string {
|
||||
switch format {
|
||||
case "dump":
|
||||
return "dump"
|
||||
case "csv":
|
||||
return "csv"
|
||||
case "jsonl":
|
||||
return "jsonl"
|
||||
}
|
||||
return format
|
||||
}
|
||||
Reference in new issue
Block a user