Skip to content

Commit

Permalink
Merge pull request #267 from noborus/replace-any
Browse files Browse the repository at this point in the history
replace interface{} with "any"
  • Loading branch information
noborus authored Jan 10, 2024
2 parents 2b9907d + eea5379 commit 57ad842
Show file tree
Hide file tree
Showing 38 changed files with 215 additions and 215 deletions.
2 changes: 1 addition & 1 deletion _example/slice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/noborus/trdsql"
)

func sliceQuery(slice interface{}, tableName string, query string) ([][]interface{}, error) {
func sliceQuery(slice any, tableName string, query string) ([][]any, error) {
// trdsql.EnableDebug()
importer := trdsql.NewSliceImporter(tableName, slice)
writer := trdsql.NewSliceWriter()
Expand Down
2 changes: 1 addition & 1 deletion _example/writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (w *Write) PreWrite(columns []string, types []string) error {
return nil
}

func (w *Write) WriteRow(values []interface{}, columns []string) error {
func (w *Write) WriteRow(values []any, columns []string) error {
for i, v := range values {
if i > 0 {
if _, err := w.writer.Write([]byte(",")); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (db *DB) queryCreateTable(tableName string, columnNames []string, columnTyp
type importTable struct {
tableName string
columns []string
row []interface{}
row []any
maxCap int
lastCount int
count int
Expand All @@ -125,7 +125,7 @@ func (db *DB) ImportContext(ctx context.Context, tableName string, columnNames [
columns[i] = db.QuotedName(columnNames[i])
}

row := make([]interface{}, len(columnNames))
row := make([]any, len(columnNames))
table := &importTable{
tableName: tableName,
columns: columns,
Expand Down Expand Up @@ -209,7 +209,7 @@ func (db *DB) insertImport(ctx context.Context, table *importTable, reader Reade
} else {
table.maxCap = (db.maxBulk / len(table.row)) * len(table.row)
}
bulk := make([]interface{}, 0, table.maxCap)
bulk := make([]any, 0, table.maxCap)

preRows := reader.PreReadRow()
preRowNum := len(preRows)
Expand Down Expand Up @@ -262,7 +262,7 @@ func (db *DB) stmtClose(stmt *sql.Stmt) {
}
}

func bulkPush(ctx context.Context, table *importTable, input Reader, bulk []interface{}) ([]interface{}, error) {
func bulkPush(ctx context.Context, table *importTable, input Reader, bulk []any) ([]any, error) {
for (table.count * len(table.row)) < table.maxCap {
row, err := input.ReadRow(table.row)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func EnableDebug() {
debug = true
}

func (d debugT) Printf(format string, args ...interface{}) {
func (d debugT) Printf(format string, args ...any) {
if d {
log.Printf(format, args...)
}
Expand Down
4 changes: 2 additions & 2 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func (e *WriteFormat) exportContext(ctx context.Context, db *DB, query string) e
}

func (e *WriteFormat) write(ctx context.Context, rows *sql.Rows) error {
values := make([]interface{}, len(e.columns))
scanArgs := make([]interface{}, len(e.columns))
values := make([]any, len(e.columns))
scanArgs := make([]any, len(e.columns))
for i := range values {
scanArgs[i] = &values[i]
}
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ require (
github.com/klauspost/compress v1.17.4
github.com/lib/pq v1.10.9
github.com/mattn/go-runewidth v0.0.15
github.com/mattn/go-sqlite3 v1.14.18
github.com/mattn/go-sqlite3 v1.14.19
github.com/multiprocessio/go-sqlite3-stdlib v0.0.0-20220822170115-9f6825a1cd25
github.com/noborus/guesswidth v0.3.4
github.com/noborus/sqlss v0.1.0
github.com/noborus/tbln v0.0.2
github.com/olekukonko/tablewriter v0.0.5
github.com/pierrec/lz4 v2.6.1+incompatible
github.com/ulikunitz/xz v0.5.11
golang.org/x/term v0.15.0
golang.org/x/term v0.16.0
modernc.org/sqlite v1.28.0
)

Expand All @@ -35,16 +35,16 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.16.1 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/ccgo/v3 v3.16.15 // indirect
modernc.org/libc v1.37.5 // indirect
modernc.org/libc v1.40.1 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/opt v0.1.3 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+5aI=
github.com/mattn/go-sqlite3 v1.14.18/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/multiprocessio/go-sqlite3-stdlib v0.0.0-20220822170115-9f6825a1cd25 h1:bnhGk2UFFPqylhxTEffs1ehDRn4bEZsEoDH53Z4HqA8=
github.com/multiprocessio/go-sqlite3-stdlib v0.0.0-20220822170115-9f6825a1cd25/go.mod h1:RrGEZqqiyEcLyTVLDSgtNZVLqJykj0F4vwuuqvMdT60=
github.com/noborus/guesswidth v0.3.4 h1:+iKmbm0iFTS3pksIOKQQvLVZVOKNZHavqJoFK2mPoTQ=
Expand Down Expand Up @@ -87,8 +87,8 @@ github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4A
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
Expand All @@ -101,13 +101,13 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211004093028-2c5d950f24ef/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
Expand All @@ -127,8 +127,8 @@ modernc.org/ccgo/v3 v3.16.15 h1:KbDR3ZAVU+wiLyMESPtbtE/Add4elztFyfsWoNTgxS0=
modernc.org/ccgo/v3 v3.16.15/go.mod h1:yT7B+/E2m43tmMOT51GMoM98/MtHIcQQSleGnddkUNI=
modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
modernc.org/libc v1.37.5 h1:IDpTjKpyMYFenZ7DkOr6Jswhn79yxsXeWHi/4DaFDBA=
modernc.org/libc v1.37.5/go.mod h1:YAXkAZ8ktnkCKaN9sw/UDeUVkGYJ/YquGO4FTi5nmHE=
modernc.org/libc v1.40.1 h1:ZhRylEBcj3GyQbPVC8JxIg7SdrT4JOxIDJoUon0NfF8=
modernc.org/libc v1.40.1/go.mod h1:YAXkAZ8ktnkCKaN9sw/UDeUVkGYJ/YquGO4FTi5nmHE=
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
Expand Down
2 changes: 1 addition & 1 deletion importer_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type SliceImporter struct {
}

// NewSliceImporter returns trdsql SliceImporter.
func NewSliceImporter(tableName string, data interface{}) *SliceImporter {
func NewSliceImporter(tableName string, data any) *SliceImporter {
return &SliceImporter{
SliceReader: NewSliceReader(tableName, data),
}
Expand Down
10 changes: 5 additions & 5 deletions importer_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func TestNewSliceImporter(t *testing.T) {
type args struct {
tableName string
data interface{}
data any
}
tests := []struct {
name string
Expand All @@ -19,7 +19,7 @@ func TestNewSliceImporter(t *testing.T) {
name: "test1",
args: args{
tableName: "test",
data: [][]interface{}{
data: [][]any{
{1, "one"},
{2, "two"},
{3, "three"},
Expand All @@ -40,7 +40,7 @@ func TestNewSliceImporter(t *testing.T) {
func TestSliceImporter_Import(t *testing.T) {
type fields struct {
tableName string
data interface{}
data any
}
tests := []struct {
name string
Expand All @@ -53,7 +53,7 @@ func TestSliceImporter_Import(t *testing.T) {
name: "testErr",
fields: fields{
tableName: "",
data: [][]interface{}{
data: [][]any{
{1, "one"},
{2, "two"},
{3, "three"},
Expand All @@ -67,7 +67,7 @@ func TestSliceImporter_Import(t *testing.T) {
name: "test1",
fields: fields{
tableName: "test",
data: [][]interface{}{
data: [][]any{
{1, "one"},
{2, "two"},
{3, "three"},
Expand Down
8 changes: 4 additions & 4 deletions input_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ func (r *CSVReader) Types() ([]string, error) {
}

// PreReadRow is returns only columns that store preread rows.
func (r *CSVReader) PreReadRow() [][]interface{} {
func (r *CSVReader) PreReadRow() [][]any {
rowNum := len(r.preRead)
rows := make([][]interface{}, rowNum)
rows := make([][]any, rowNum)
for n := 0; n < rowNum; n++ {
rows[n] = make([]interface{}, len(r.names))
rows[n] = make([]any, len(r.names))
for i, f := range r.preRead[n] {
rows[n][i] = f
if r.needNULL {
Expand All @@ -156,7 +156,7 @@ func (r *CSVReader) PreReadRow() [][]interface{} {
}

// ReadRow is read the rest of the row.
func (r *CSVReader) ReadRow(row []interface{}) ([]interface{}, error) {
func (r *CSVReader) ReadRow(row []any) ([]any, error) {
if r.limitRead {
return nil, io.EOF
}
Expand Down
28 changes: 14 additions & 14 deletions input_csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ func TestCSVReader_PreReadRow(t *testing.T) {
name string
fileName string
opts *ReadOpts
want [][]interface{}
want [][]any
}{
{
name: "testBlank",
fileName: "testnull.csv",
opts: NewReadOpts(),
want: [][]interface{}{
want: [][]any{
{"1", ""},
},
},
Expand All @@ -314,7 +314,7 @@ func TestCSVReader_PreReadRow(t *testing.T) {
InNeedNULL(true),
InNULL(""),
),
want: [][]interface{}{
want: [][]any{
{"1", nil},
},
},
Expand All @@ -325,7 +325,7 @@ func TestCSVReader_PreReadRow(t *testing.T) {
InNeedNULL(true),
InNULL("1"),
),
want: [][]interface{}{
want: [][]any{
{nil, ""},
},
},
Expand All @@ -349,26 +349,26 @@ func TestCSVReader_PreReadRow(t *testing.T) {

func TestCSVReader_ReadRow(t *testing.T) {
type args struct {
row []interface{}
row []any
}
tests := []struct {
name string
fileName string
opts *ReadOpts
args args
want []interface{}
want []any
wantErr bool
}{
{
name: "test.csv",
fileName: "test.csv",
opts: NewReadOpts(),
args: args{
[]interface{}{
[]any{
"", "",
},
},
want: []interface{}{
want: []any{
"2", "Melon",
},
wantErr: false,
Expand All @@ -378,11 +378,11 @@ func TestCSVReader_ReadRow(t *testing.T) {
fileName: "testnull2.csv",
opts: NewReadOpts(),
args: args{
[]interface{}{
[]any{
"", "", "",
},
},
want: []interface{}{
want: []any{
"2", "", "g3",
},
wantErr: false,
Expand All @@ -395,11 +395,11 @@ func TestCSVReader_ReadRow(t *testing.T) {
InNULL(""),
),
args: args{
[]interface{}{
[]any{
"", "", "",
},
},
want: []interface{}{
want: []any{
"2", nil, "g3",
},
wantErr: false,
Expand All @@ -409,11 +409,11 @@ func TestCSVReader_ReadRow(t *testing.T) {
fileName: "test_indefinite2.csv",
opts: NewReadOpts(),
args: args{
[]interface{}{
[]any{
"", "", "",
},
},
want: []interface{}{
want: []any{
"2", "Melon", nil,
},
wantErr: false,
Expand Down
8 changes: 4 additions & 4 deletions input_gw.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ func (r *GWReader) Types() ([]string, error) {
}

// PreReadRow is returns only columns that store preread rows.
func (r *GWReader) PreReadRow() [][]interface{} {
rows := make([][]interface{}, r.preRead)
func (r *GWReader) PreReadRow() [][]any {
rows := make([][]any, r.preRead)
for n := 0; n < r.preRead; n++ {
record, err := r.reader.Read()
if err != nil {
return rows
}
rows[n] = make([]interface{}, len(r.names))
rows[n] = make([]any, len(r.names))
for i := 0; i < len(r.names); i++ {
rows[n][i] = record[i]
if r.needNULL {
Expand All @@ -94,7 +94,7 @@ func (r *GWReader) PreReadRow() [][]interface{} {
}

// ReadRow is read the rest of the row.
func (r *GWReader) ReadRow(row []interface{}) ([]interface{}, error) {
func (r *GWReader) ReadRow(row []any) ([]any, error) {
if r.limitRead {
return nil, io.EOF
}
Expand Down
Loading

0 comments on commit 57ad842

Please sign in to comment.