Files
archer/internal/row/dump.go
T
voidandClaude Sonnet 4.6 bc4a6b504f 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>
2026-11-06 22:12:17 +08:00

45 lines
985 B
Go

package row
// dumpEncoder emits MySQL LOAD DATA compatible TSV. Fields are separated by
// TAB, rows by LF, NULL is \N and the escape table matches
// SELECT ... INTO OUTFILE with the default FIELDS ESCAPED BY '\\'.
type dumpEncoder struct {
idx []int
}
func (e *dumpEncoder) Header() []byte { return nil }
func (e *dumpEncoder) Encode(dst []byte, r Row) ([]byte, error) {
for n, i := range e.idx {
if n > 0 {
dst = append(dst, '\t')
}
v := r.Values[i]
if v.IsNull() {
dst = append(dst, '\\', 'N')
continue
}
for _, b := range v.Raw {
switch b {
case '\\':
dst = append(dst, '\\', '\\')
case '\t':
dst = append(dst, '\\', 't')
case '\n':
dst = append(dst, '\\', 'n')
case '\r':
dst = append(dst, '\\', 'r')
case 0:
dst = append(dst, '\\', '0')
case '\b':
dst = append(dst, '\\', 'b')
case 0x1a:
dst = append(dst, '\\', 'Z')
default:
dst = append(dst, b)
}
}
}
return append(dst, '\n'), nil
}