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,44 @@
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user