diff --git a/README.md b/README.md index 0e27e50..7563aaa 100644 --- a/README.md +++ b/README.md @@ -1085,8 +1085,7 @@ func main() { trdsql.NewImporter(trdsql.InDelimiter(":")), trdsql.NewExporter(trdsql.NewWriter()), ) - err := trd.Exec("SELECT c1 FROM /etc/passwd") - if err != nil { + if err := trd.Exec("SELECT c1 FROM /etc/passwd"); err != nil { log.Fatal(err) } } diff --git a/_example/simple/main.go b/_example/simple/main.go index ff94b64..eea371d 100644 --- a/_example/simple/main.go +++ b/_example/simple/main.go @@ -12,8 +12,7 @@ func main() { trdsql.NewImporter(trdsql.InDelimiter(":")), trdsql.NewExporter(trdsql.NewWriter()), ) - err := trd.Exec("SELECT c1 FROM /etc/passwd") - if err != nil { + if err := trd.Exec("SELECT c1 FROM /etc/passwd"); err != nil { log.Fatal(err) } } diff --git a/importer_buffer.go b/importer_buffer.go index 991c70f..92f2d06 100644 --- a/importer_buffer.go +++ b/importer_buffer.go @@ -44,5 +44,5 @@ func (i *BufferImporter) ImportContext(ctx context.Context, db *DB, query string if err := db.CreateTable(i.tableName, names, types, true); err != nil { return query, err } - return query, db.Import(i.tableName, names, i.Reader) + return query, db.ImportContext(ctx, i.tableName, names, i.Reader) } diff --git a/importer_slice.go b/importer_slice.go index bca1b62..55e181c 100644 --- a/importer_slice.go +++ b/importer_slice.go @@ -36,5 +36,5 @@ func (i *SliceImporter) ImportContext(ctx context.Context, db *DB, query string) if err := db.CreateTable(i.tableName, names, types, true); err != nil { return query, err } - return query, db.Import(i.tableName, names, i.SliceReader) + return query, db.ImportContext(ctx, i.tableName, names, i.SliceReader) } diff --git a/output_raw.go b/output_raw.go index 5459a34..9fc9f51 100644 --- a/output_raw.go +++ b/output_raw.go @@ -17,13 +17,14 @@ type RAWWriter struct { // NewRAWWriter returns RAWWriter. func NewRAWWriter(writeOpts *WriteOpts) *RAWWriter { - var err error - w := &RAWWriter{} - w.writer = bufio.NewWriter(writeOpts.OutStream) - w.delimiter, err = strconv.Unquote(`"` + writeOpts.OutDelimiter + `"`) + delimiter, err := strconv.Unquote(`"` + writeOpts.OutDelimiter + `"`) if err != nil { debug.Printf("%s\n", err) } + + w := &RAWWriter{} + w.writer = bufio.NewWriter(writeOpts.OutStream) + w.delimiter = delimiter w.outHeader = writeOpts.OutHeader if writeOpts.OutUseCRLF { w.endLine = "\r\n" diff --git a/reader.go b/reader.go index efec33b..01d0d9f 100644 --- a/reader.go +++ b/reader.go @@ -51,8 +51,12 @@ var readerFuncs = map[Format]ReaderFunc{ }, } -var extFormat Format = 100 -var registerMux = &sync.Mutex{} +var ( + // extFormat is the next format number to be assigned. + extFormat Format = 100 + // registerMux is a mutex to protect access to the register. + registerMux = &sync.Mutex{} +) func RegisterReaderFunc(ext string, readerFunc ReaderFunc) { registerMux.Lock() diff --git a/strings.go b/strings.go index 32b93c5..7eb1ca9 100644 --- a/strings.go +++ b/strings.go @@ -9,7 +9,7 @@ import ( ) // ValString converts database value to string. -func ValString(v interface{}) string { +func ValString(v any) string { switch t := v.(type) { case nil: return "" @@ -33,7 +33,7 @@ func ValString(v interface{}) string { } } -func replaceNULL(nullString string, v interface{}) interface{} { +func replaceNULL(nullString string, v any) any { switch t := v.(type) { case nil: return nil diff --git a/strings_test.go b/strings_test.go index 0447adb..6c69439 100644 --- a/strings_test.go +++ b/strings_test.go @@ -8,7 +8,7 @@ import ( func TestValString(t *testing.T) { type args struct { - v interface{} + v any } tests := []struct { name string @@ -53,21 +53,21 @@ func TestValString(t *testing.T) { func Test_replaceNULL(t *testing.T) { type args struct { NULLString string - v interface{} + v any } tests := []struct { name string args args - want interface{} + want any }{ { name: "test1", - args: args{NULLString: "NULL", v: interface{}("N")}, + args: args{NULLString: "NULL", v: any("N")}, want: "N", }, { name: "testMatch", - args: args{NULLString: "NULL", v: interface{}("NULL")}, + args: args{NULLString: "NULL", v: any("NULL")}, want: nil, }, {