diff --git a/appender_modals.go b/appender_modals.go index 95319851..d465e2f6 100644 --- a/appender_modals.go +++ b/appender_modals.go @@ -5,44 +5,44 @@ import "strconv" const standardListSize = 3000 const standardNestedListSize = 30 -type ListInt struct { - L []int32 +type ListString struct { + L []string } -func (l *ListInt) Fill() ListInt { +func (l *ListString) Fill() ListString { for j := 0; j < standardListSize; j++ { - l.L = append(l.L, int32(j)) + l.L = append(l.L, strconv.Itoa(j)+" ducks are cool") } return *l } -func (l *ListInt) FillFromInterface(i interface{}) ListInt { - inner := i.(map[string]interface{})["L"] - l.FillInnerFromInterface(inner.([]interface{})) - return *l -} - -func (l *ListInt) FillInnerFromInterface(i []interface{}) ListInt { +func (l *ListString) FillFromInterface(i []interface{}) ListString { for _, v := range i { - l.L = append(l.L, v.(int32)) + l.L = append(l.L, v.(string)) } return *l } -type ListString struct { - L []string +type ListInt struct { + L []int32 } -func (l *ListString) Fill() ListString { +func (l *ListInt) Fill() ListInt { for j := 0; j < standardListSize; j++ { - l.L = append(l.L, strconv.Itoa(j)+" ducks are cool") + l.L = append(l.L, int32(j)) } return *l } -func (l *ListString) FillFromInterface(i []interface{}) ListString { +func (l *ListInt) FillFromInterface(i interface{}) ListInt { + inner := i.(map[string]interface{})["L"] + l.FillInnerFromInterface(inner.([]interface{})) + return *l +} + +func (l *ListInt) FillInnerFromInterface(i []interface{}) ListInt { for _, v := range i { - l.L = append(l.L, v.(string)) + l.L = append(l.L, v.(int32)) } return *l } @@ -52,8 +52,8 @@ type NestedListInt struct { } func (l *NestedListInt) Fill() NestedListInt { - inner := ListInt{} for j := 0; j < standardNestedListSize; j++ { + inner := ListInt{} l.L = append(l.L, inner.Fill().L) } return *l @@ -72,8 +72,8 @@ type TripleNestedListInt struct { } func (l *TripleNestedListInt) Fill() TripleNestedListInt { - inner := NestedListInt{} - for j := 0; j < standardNestedListSize; j++ { + for j := 0; j < standardNestedListSize/3; j++ { + inner := NestedListInt{} l.L = append(l.L, inner.Fill().L) } return *l @@ -184,8 +184,8 @@ type Mix struct { func (m *Mix) Fill() Mix { m.A.Fill() - l := ListInt{} for j := 0; j < standardNestedListSize; j++ { + l := ListInt{} m.B = append(m.B, l.Fill()) } return *m @@ -193,7 +193,8 @@ func (m *Mix) Fill() Mix { func (m *Mix) FillFromInterface(i interface{}) Mix { inner := i.(map[string]interface{}) - m.A.FillFromInterface(inner["A"].([]interface{})) + innerA := inner["A"].(map[string]interface{}) + m.A.FillFromInterface(innerA["L"].([]interface{})) for _, v := range inner["B"].([]interface{}) { l := ListInt{} m.B = append(m.B, l.FillFromInterface(v)) diff --git a/appender_nested_2_test.go b/appender_nested_2_test.go deleted file mode 100644 index 472283e7..00000000 --- a/appender_nested_2_test.go +++ /dev/null @@ -1,87 +0,0 @@ -package duckdb - -// -//import ( -// "context" -// "database/sql" -// "github.com/stretchr/testify/require" -// "testing" -//) -// -//const ( -// testAppenderSMOL = ` -// CREATE TABLE test( -// smolList STRUCT(I INT)[] -// )` -//) -// -//func createAppenderSMOL(db *sql.DB, t *testing.T) *sql.Result { -// res, err := db.Exec(testAppenderSMOL) -// require.NoError(t, err) -// return &res -//} -// -//func TestNestedAppenderSMOL(t *testing.T) { -// -// c, err := NewConnector("", nil) -// require.NoError(t, err) -// -// db := sql.OpenDB(c) -// createAppenderSMOL(db, t) -// defer db.Close() -// -// type dataRow struct { -// smolList []smol -// } -// randRow := func(i int) dataRow { -// -// return dataRow{ -// smolList: fillSMOL(100), -// } -// } -// rows := []dataRow{} -// for i := 0; i < 100; i++ { -// rows = append(rows, randRow(i)) -// } -// -// conn, err := c.Connect(context.Background()) -// require.NoError(t, err) -// defer conn.Close() -// -// appender, err := NewAppenderFromConn(conn, "", "test") -// require.NoError(t, err) -// defer appender.Close() -// -// for _, row := range rows { -// err := appender.AppendRow( -// row.smolList, -// ) -// require.NoError(t, err) -// } -// err = appender.Flush() -// require.NoError(t, err) -// -// res, err := db.QueryContext( -// context.Background(), ` -// SELECT -// smolList, -// FROM test -// `) -// require.NoError(t, err) -// defer res.Close() -// -// i := 0 -// for res.Next() { -// r := dataRow{} -// var sml []interface{} -// err := res.Scan( -// &sml, -// ) -// require.NoError(t, err) -// r.smolList = convertToSmol(sml) -// require.Equal(t, rows[i], r) -// i++ -// } -// // Ensure that the number of fetched rows equals the number of inserted rows. -// require.Equal(t, i, 100) -//} diff --git a/appender_nested_fancy_test.go b/appender_nested_fancy_test.go deleted file mode 100644 index d6567735..00000000 --- a/appender_nested_fancy_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package duckdb - -// -//import ( -// "context" -// "database/sql" -// "fmt" -// "github.com/jmoiron/sqlx" -// "github.com/stretchr/testify/require" -// "testing" -//) -// -//const ( -// testAppenderTableN = ` -// CREATE OR REPLACE TABLE test ( -// id BIGINT, -// intList STRUCT(I INT, V VARCHAR) -// ); -//` -//) -// -//func createAppenderN(db *sql.DB, t *testing.T) *sql.Result { -// res, err := db.Exec(testAppenderTableN) -// require.NoError(t, err) -// return &res -//} -// -//const alskdj = 100 -// -//func TestNested(t *testing.T) { -// -// c, err := NewConnector("", nil) -// require.NoError(t, err) -// -// db := sql.OpenDB(c) -// createAppenderN(db, t) -// defer db.Close() -// -// type DataRow struct { -// ID int `db:"id"` -// IntList struct1 `db:"intList"` -// } -// randRow := func(i int) DataRow { -// return DataRow{ -// ID: i, -// IntList: createStruct1(100), -// } -// } -// rows := []DataRow{} -// for i := 0; i < alskdj; i++ { -// rows = append(rows, randRow(i)) -// } -// -// conn, err := c.Connect(context.Background()) -// require.NoError(t, err) -// defer conn.Close() -// -// appender, err := NewAppenderFromConn(conn, "", "test") -// require.NoError(t, err) -// defer appender.Close() -// -// for _, row := range rows { -// err := appender.AppendRow( -// row.ID, -// row.IntList, -// ) -// require.NoError(t, err) -// } -// err = appender.Flush() -// require.NoError(t, err) -// -// res_db := sqlx.NewDb(db, "duckdb") -// require.NoError(t, err) -// -// dataR := []DataRow{} -// err = res_db.Select(&dataR, "SELECT * FROM test") -// require.NoError(t, err) -// fmt.Println(dataR) -//} diff --git a/appender_nested_list_in_struct_in_list_test.go b/appender_nested_list_in_struct_in_list_test.go deleted file mode 100644 index d7d3f214..00000000 --- a/appender_nested_list_in_struct_in_list_test.go +++ /dev/null @@ -1,143 +0,0 @@ -package duckdb - -// -//import ( -// "context" -// "database/sql" -// "github.com/stretchr/testify/require" -// "testing" -// //"github.com/jmoiron/sqlx" -//) -// -//const ( -// testAppenderTableNestedListInStructInList = ` -// CREATE TABLE test( -// listStructList STRUCT(L STRUCT(I INT, L_I INT[])[]) -// )` -//) -// -//func createAppenderNestedListInStructInList(db *sql.DB, t *testing.T) *sql.Result { -// res, err := db.Exec(testAppenderTableNestedListInStructInList) -// require.NoError(t, err) -// return &res -//} -// -//type listInStruct struct { -// I int32 -// L_I []int32 -//} -// -//type listInStructList struct { -// L []listInStruct -//} -// -//func createListInStruct(i int) listInStruct { -// if i <= 0 { -// i = 1 -// } -// -// return listInStruct{ -// I: int32(i), -// L_I: createIntSlice(int32(i)), -// } -//} -// -//func createListInStructList(i int) listInStructList { -// if i <= 0 { -// i = 1 -// } -// -// var l []listInStruct -// var j int -// for j = 0; j < i; j++ { -// l = append(l, createListInStruct(j)) -// } -// return listInStructList{ -// L: l, -// } -//} -// -//func TestNestedListInStructInListAppender(t *testing.T) { -// -// c, err := NewConnector("", nil) -// require.NoError(t, err) -// -// db := sql.OpenDB(c) -// createAppenderNestedListInStructInList(db, t) -// defer db.Close() -// -// type dataRow struct { -// listStruct listInStructList -// } -// randRow := func(i int) dataRow { -// return dataRow{ -// listStruct: createListInStructList(5), -// } -// } -// rows := []dataRow{} -// for i := 0; i < totalRows; i++ { -// rows = append(rows, randRow(i)) -// } -// -// conn, err := c.Connect(context.Background()) -// require.NoError(t, err) -// defer conn.Close() -// -// appender, err := NewAppenderFromConn(conn, "", "test") -// require.NoError(t, err) -// defer appender.Close() -// -// for _, row := range rows { -// err := appender.AppendRow( -// row.listStruct, -// ) -// require.NoError(t, err) -// } -// err = appender.Flush() -// require.NoError(t, err) -// -// res, err := db.QueryContext( -// context.Background(), ` -// SELECT -// listStructList -// FROM test -// `) -// require.NoError(t, err) -// defer res.Close() -// -// //var resTbl []listInStructList -// //err := scan.Rows(&resTbl, res) -// -// i := 0 -// for res.Next() { -// r := dataRow{} -// var listStruct interface{} -// err := res.Scan( -// &listStruct, -// ) -// require.NoError(t, err) -// r.listStruct = convertDuckDBListStructInListToListStructInList(listStruct) -// require.Equal(t, rows[i], r) -// i++ -// } -// // Ensure that the number of fetched rows equals the number of inserted rows. -// require.Equal(t, i, totalRows) -//} -// -//func convertDuckDBListStructToListInStruct(s interface{}) listInStruct { -// var listStruct listInStruct -// vals := s.(map[string]interface{}) -// listStruct.I = vals["I"].(int32) -// listStruct.L_I = convertInterfaceToIntSlice(vals["L_I"].([]interface{})) -// return listStruct -//} -// -//func convertDuckDBListStructInListToListStructInList(s interface{}) listInStructList { -// var listStructList listInStructList -// innerList := s.(map[string]interface{})["L"] -// -// for _, v := range innerList.([]interface{}) { -// listStructList.L = append(listStructList.L, convertDuckDBListStructToListInStruct(v)) -// } -// return listStructList -//} diff --git a/appender_nested_list_in_struct_test.go b/appender_nested_list_in_struct_test.go deleted file mode 100644 index 4ecf93bc..00000000 --- a/appender_nested_list_in_struct_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package duckdb - -// -//import ( -// "context" -// "database/sql" -// "github.com/stretchr/testify/require" -// "math/rand" -// "testing" -//) -// -//const ( -// testAppenderTableNestedListInStruct = ` -// CREATE TABLE test( -// listStruct STRUCT(L INT[]) -// )` -//) -// -//func createAppenderNestedListInStruct(db *sql.DB, t *testing.T) *sql.Result { -// res, err := db.Exec(testAppenderTableNestedListInStruct) -// require.NoError(t, err) -// return &res -//} -// -//func TestNestedListInStructAppender(t *testing.T) { -// -// c, err := NewConnector("", nil) -// require.NoError(t, err) -// -// db := sql.OpenDB(c) -// createAppenderNestedListInStruct(db, t) -// defer db.Close() -// -// type dataRow struct { -// listStruct list_struct -// } -// randRow := func(i int) dataRow { -// -// return dataRow{ -// listStruct: list_struct{createIntSlice(rand.Int31n(3000))}, -// } -// } -// rows := []dataRow{} -// for i := 0; i < totalRows; i++ { -// rows = append(rows, randRow(i)) -// } -// -// conn, err := c.Connect(context.Background()) -// require.NoError(t, err) -// defer conn.Close() -// -// appender, err := NewAppenderFromConn(conn, "", "test") -// require.NoError(t, err) -// defer appender.Close() -// -// for _, row := range rows { -// err := appender.AppendRow( -// row.listStruct, -// ) -// require.NoError(t, err) -// } -// err = appender.Flush() -// require.NoError(t, err) -// -// res, err := db.QueryContext( -// context.Background(), ` -// SELECT -// listStruct -// FROM test -// `) -// require.NoError(t, err) -// defer res.Close() -// -// i := 0 -// for res.Next() { -// r := dataRow{} -// var listStruct interface{} -// err := res.Scan( -// &listStruct, -// ) -// require.NoError(t, err) -// r.listStruct = convertDuckDBListStructToListStruct(listStruct) -// require.Equal(t, rows[i], r) -// i++ -// } -// // Ensure that the number of fetched rows equals the number of inserted rows. -// require.Equal(t, i, totalRows) -//} -// -//func convertDuckDBListStructToListStruct(s interface{}) list_struct { -// var listStruct list_struct -// innerList := s.(map[string]interface{})["L"] -// -// listStruct.L = convertInterfaceToIntSlice(innerList.([]interface{})) -// return listStruct -//} diff --git a/appender_nested_mix_test.go b/appender_nested_mix_test.go deleted file mode 100644 index 34284669..00000000 --- a/appender_nested_mix_test.go +++ /dev/null @@ -1,114 +0,0 @@ -package duckdb - -// -//import ( -// "context" -// "database/sql" -// "fmt" -// "github.com/jmoiron/sqlx" -// "github.com/stretchr/testify/require" -// "math/rand" -// "testing" -//) -// -//const ( -// testAppenderTableNestedMix = ` -// CREATE OR REPLACE TABLE nested_mix (S STRUCT(A INT[], B STRUCT(C VARCHAR[])[])[]); -//` -//) -// -//func createAppenderNestedMix(db *sql.DB, t *testing.T) *sql.Result { -// res, err := db.Exec(testAppenderTableNestedMix) -// require.NoError(t, err) -// return &res -//} -// -//const mixRows = 100 -// -//func TestNestedMix(t *testing.T) { -// -// c, err := NewConnector("db", nil) -// require.NoError(t, err) -// -// db := sql.OpenDB(c) -// createAppenderNestedMix(db, t) -// defer db.Close() -// -// type dataRow struct { -// mix []S -// } -// randRow := func(i int) dataRow { -// return dataRow{ -// mix: createMixList(rand.Int31n(100)), -// } -// } -// rows := []dataRow{} -// for i := 0; i < mixRows; i++ { -// rows = append(rows, randRow(i)) -// } -// -// conn, err := c.Connect(context.Background()) -// require.NoError(t, err) -// defer conn.Close() -// -// appender, err := NewAppenderFromConn(conn, "", "nested_mix") -// require.NoError(t, err) -// defer appender.Close() -// -// for _, row := range rows { -// err := appender.AppendRow( -// row.mix, -// ) -// require.NoError(t, err) -// } -// err = appender.Flush() -// require.NoError(t, err) -// -// var res_db *sqlx.DB -// -// res_db, err = sqlx.Open("duckdb", "db") -// require.NoError(t, err) -// -// res, err := res_db.Queryx("SELECT S FROM nested_mix") -// require.NoError(t, err) -// -// type rowRes struct { -// NS []S `db:"S"` -// } -// -// for res.Next() { -// var r rowRes -// err := res.StructScan(&r) -// if err != nil { -// panic(err.Error()) -// } -// -// // Print the scanned data for debugging -// fmt.Printf("%+v\n", r.NS) -// } -// -//} -// -////res, err := db.QueryContext( -//// context.Background(), ` -//// SELECT -//// s -//// FROM nested_mix -//// `) -////require.NoError(t, err) -////defer res.Close() -// -////i := 0 -////for res.Next() { -//// r := DataRow{} -//// var mix []interface{} -//// err := res.Scan( -//// &mix, -//// ) -//// require.NoError(t, err) -//// r.mix = convertDuckDBMixListToMixList(mix) -//// require.Equal(t, rows[i], r) -//// i++ -////} -//// Ensure that the number of fetched rows equals the number of inserted rows. -////require.Equal(t, i, mixRows) diff --git a/appender_nested_struct_in_list_test.go b/appender_nested_struct_in_list_test.go deleted file mode 100644 index f6355a63..00000000 --- a/appender_nested_struct_in_list_test.go +++ /dev/null @@ -1,121 +0,0 @@ -package duckdb - -import ( - "context" - "database/sql" - "github.com/stretchr/testify/require" - "math/rand" - "testing" -) - -const ( - testAppenderTableNestedStructInList = ` - CREATE TABLE test( - structList STRUCT(I INT, V INT)[], - )` -) - -func createAppenderNestedStructInList(db *sql.DB, t *testing.T) *sql.Result { - res, err := db.Exec(testAppenderTableNestedStructInList) - require.NoError(t, err) - return &res -} - -type two_ints struct { - I int32 - V int32 -} - -func createTwoIntsStructSlice(i int) []two_ints { - if i <= 0 { - i = 1 - } - - var l []two_ints - var j int - for j = 0; j < i; j++ { - l = append(l, two_ints{ - I: int32(j), - V: int32(j + 100), - }) - } - return l -} - -const totalRows = 1000 - -func TestNestedStructInListAppender(t *testing.T) { - - c, err := NewConnector("", nil) - require.NoError(t, err) - - db := sql.OpenDB(c) - createAppenderNestedStructInList(db, t) - defer db.Close() - - type dataRow struct { - structList []two_ints - } - randRow := func(i int) dataRow { - return dataRow{ - structList: createTwoIntsStructSlice(rand.Intn(3000)), - } - } - rows := []dataRow{} - for i := 0; i < totalRows; i++ { - rows = append(rows, randRow(i)) - } - - conn, err := c.Connect(context.Background()) - require.NoError(t, err) - defer conn.Close() - - appender, err := NewAppenderFromConn(conn, "", "test") - require.NoError(t, err) - defer appender.Close() - - for _, row := range rows { - err := appender.AppendRow( - row.structList, - ) - require.NoError(t, err) - } - err = appender.Flush() - require.NoError(t, err) - - res, err := db.QueryContext( - context.Background(), ` - SELECT - structList - FROM test - `) - require.NoError(t, err) - defer res.Close() - - i := 0 - for res.Next() { - r := dataRow{} - var structList []interface{} - err := res.Scan( - &structList, - ) - require.NoError(t, err) - r.structList = convertDuckDBStructToTwoIntsSlice(structList) - require.Equal(t, rows[i], r) - i++ - } - // Ensure that the number of fetched rows equals the number of inserted rows. - require.Equal(t, i, totalRows) -} - -func convertDuckDBStructToTwoIntsSlice(s []interface{}) []two_ints { - var l []two_ints - for _, v := range s { - m := v.(map[string]interface{}) - l = append(l, two_ints{ - I: int32(m["I"].(int32)), - V: int32(m["V"].(int32)), - }) - } - return l -} diff --git a/appender_nested_test.go b/appender_nested_test.go index 5c31f634..c2cb3307 100644 --- a/appender_nested_test.go +++ b/appender_nested_test.go @@ -15,13 +15,13 @@ CREATE TABLE test( intList INT[], nestedListInt INT[][], tripleNestedListInt INT[][][], - Base STRUCT(I INT, V VARCHAR), - Wrapper STRUCT(Base STRUCT(I INT, V VARCHAR)), - TopWrapper STRUCT(Wrapper STRUCT(Base STRUCT(I INT, V VARCHAR))), + base STRUCT(I INT, V VARCHAR), + wrapper STRUCT(Base STRUCT(I INT, V VARCHAR)), + topWrapper STRUCT(Wrapper STRUCT(Base STRUCT(I INT, V VARCHAR))), structList STRUCT(I INT, V VARCHAR)[], listStruct STRUCT(L INT[]), - mix STRUCT(A STRUCT(V VARCHAR[]), B STRUCT(L INT[])[]), - mixList STRUCT(A STRUCT(V VARCHAR[]), B STRUCT(L INT[])[])[] + mix STRUCT(A STRUCT(L VARCHAR[]), B STRUCT(L INT[])[]), + mixList STRUCT(A STRUCT(L VARCHAR[]), B STRUCT(L INT[])[])[] )` ) diff --git a/appender_nested_tripple_list_test.go b/appender_nested_tripple_list_test.go deleted file mode 100644 index dd2aa286..00000000 --- a/appender_nested_tripple_list_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package duckdb - -// -//import ( -// "context" -// "database/sql" -// "github.com/stretchr/testify/require" -// "math/rand" -// "testing" -//) -// -//const ( -// testAppenderTableNestedLLL = ` -// CREATE OR REPLACE TABLE nested_list (LLL INT[][][]); -//` -//) -// -//func createAppenderNestedLLL(db *sql.DB, t *testing.T) *sql.Result { -// res, err := db.Exec(testAppenderTableNestedLLL) -// require.NoError(t, err) -// return &res -//} -// -//const LLLRows = 100 -// -//func TestNestedLLL(t *testing.T) { -// -// c, err := NewConnector("", nil) -// require.NoError(t, err) -// -// db := sql.OpenDB(c) -// createAppenderNestedLLL(db, t) -// defer db.Close() -// -// type dataRow struct { -// LLL [][][]int32 -// } -// -// randRow := func(i int) dataRow { -// return dataRow{ -// LLL: createNestedLLL(rand.Int31n(100)), -// } -// } -// rows := []dataRow{} -// for i := 0; i < LLLRows; i++ { -// rows = append(rows, randRow(i)) -// } -// -// conn, err := c.Connect(context.Background()) -// require.NoError(t, err) -// defer conn.Close() -// -// appender, err := NewAppenderFromConn(conn, "", "nested_list") -// require.NoError(t, err) -// defer appender.Close() -// -// for _, row := range rows { -// err := appender.AppendRow( -// row.LLL, -// ) -// require.NoError(t, err) -// } -// err = appender.Flush() -// require.NoError(t, err) -// -// res, err := db.QueryContext( -// context.Background(), ` -// SELECT -// LLL -// FROM nested_list -// `) -// require.NoError(t, err) -// defer res.Close() -// -// i := 0 -// for res.Next() { -// r := dataRow{} -// var LLL []interface{} -// err := res.Scan( -// &LLL, -// ) -// require.NoError(t, err) -// r.LLL = convertDuckDBListListListToListListList(LLL) -// require.Equal(t, rows[i], r) -// i++ -// } -// // Ensure that the number of fetched rows equals the number of inserted rows. -// require.Equal(t, i, LLLRows) -//} diff --git a/appender_setup.go b/appender_setup.go deleted file mode 100644 index 0c362d7b..00000000 --- a/appender_setup.go +++ /dev/null @@ -1,185 +0,0 @@ -package duckdb - -import ( - "context" - "database/sql" - "github.com/stretchr/testify/require" - "testing" -) - -package duckdb - -import ( -"context" -"database/sql" -"github.com/stretchr/testify/require" -"testing" -) - -const ( - testAppenderTableNested = ` -CREATE TABLE test( - id BIGINT, - charList VARCHAR[], - intList INT[], - nestedListInt INT[][], - tripleNestedListInt INT[][][], - Base STRUCT(I INT, V VARCHAR), - Wrapper STRUCT(Base STRUCT(I INT, V VARCHAR)), - TopWrapper STRUCT(Wrapper STRUCT(Base STRUCT(I INT, V VARCHAR))), - structList STRUCT(I INT, V VARCHAR)[], - listStruct STRUCT(L INT[]), - mix STRUCT(A STRUCT(V VARCHAR[]), B STRUCT(L INT[])[]), - mixList STRUCT(A STRUCT(V VARCHAR[]), B STRUCT(L INT[])[])[] -)` -) - -func createAppenderNestedTable(db *sql.DB) *sql.Result { - res, err := db.Exec(testAppenderTableNested) - checkIfSucceded(err) - return &res -} - -func checkIfSucceded(err error) { - if err != nil { - panic(err) - } -} - -type dataRowInterface struct { - charList []interface{} - intList []interface{} - nestedListInt []interface{} - tripleNestedListInt []interface{} - base interface{} - wrapper interface{} - topWrapper interface{} - structList []interface{} - listStruct interface{} - mix interface{} - mixList []interface{} -} - -type dataRow struct { - ID int - charList ListString - intList ListInt - nestedListInt NestedListInt - tripleNestedListInt TripleNestedListInt - base Base - wrapper Wrapper - topWrapper TopWrapper - structList []Base - listStruct ListInt - mix Mix - mixList []Mix -} - -func (dR *dataRow) Convert(i dataRowInterface) { - dR.charList.FillFromInterface(i.charList) - dR.intList.FillInnerFromInterface(i.intList) - dR.nestedListInt.FillFromInterface(i.nestedListInt) - dR.tripleNestedListInt.FillFromInterface(i.tripleNestedListInt) - dR.base.FillFromInterface(i.base) - dR.wrapper.FillFromInterface(i.wrapper) - dR.topWrapper.FillFromInterface(i.topWrapper) - dR.structList = dR.base.ListFillFromInterface(i.structList) - dR.listStruct = dR.listStruct.FillFromInterface(i.listStruct) - dR.mix.FillFromInterface(i.mix) - dR.mixList = dR.mix.ListFillFromInterface(i.mixList) -} - -func setupAppenderNested() *sql.DB { - - c, err := NewConnector("", nil) - checkIfSucceded(err) - - db := sql.OpenDB(c) - createAppenderNestedTable(db, t) - defer db.Close() - - randRow := func(i int) dataRow { - dR := dataRow{ID: i} - dR.charList.Fill() - dR.intList.Fill() - dR.nestedListInt.Fill() - dR.tripleNestedListInt.Fill() - dR.base.Fill(i) - dR.wrapper.Fill(i) - dR.topWrapper.Fill(i) - dR.structList = dR.base.ListFill(10) - dR.listStruct.Fill() - dR.mix.Fill() - dR.mixList = dR.mix.ListFill(10) - return dR - } - rows := []dataRow{} - for i := 0; i < 100; i++ { - rows = append(rows, randRow(i)) - } - - conn, err := c.Connect(context.Background()) - require.NoError(t, err) - defer conn.Close() - - appender, err := NewAppenderFromConn(conn, "", "test") - require.NoError(t, err) - defer appender.Close() - - for _, row := range rows { - err := appender.AppendRow( - row.ID, - row.charList.L, - row.intList.L, - row.nestedListInt.L, - row.tripleNestedListInt.L, - row.base, - row.wrapper, - row.topWrapper, - row.structList, - row.listStruct, - row.mix, - row.mixList, - ) - require.NoError(t, err) - } - err = appender.Flush() - require.NoError(t, err) - - return db -} - -func compareAppenderNested(db *sql.DB) { - res, err := db.QueryContext( - context.Background(), ` - SELECT * FROM test ORDER BY id - `) - require.NoError(t, err) - defer res.Close() - - i := 0 - for res.Next() { - r := dataRow{} - interfaces := dataRowInterface{} - err := res.Scan( - &r.ID, - &interfaces.charList, - &interfaces.intList, - &interfaces.nestedListInt, - &interfaces.tripleNestedListInt, - &interfaces.base, - &interfaces.wrapper, - &interfaces.topWrapper, - &interfaces.structList, - &interfaces.listStruct, - &interfaces.mix, - &interfaces.mixList, - ) - require.NoError(t, err) - r.Convert(interfaces) - require.Equal(t, rows[i], r) - i++ - } - // Ensure that the number of fetched rows equals the number of inserted rows. - require.Equal(t, i, 100) -} diff --git a/appender_test.go b/appender_test.go index ac4b8522..11e5ea5a 100644 --- a/appender_test.go +++ b/appender_test.go @@ -141,19 +141,19 @@ func TestAppender(t *testing.T) { res, err := db.QueryContext( context.Background(), ` SELECT id, - uint8, - int8, - uint16, - int16, - uint32, - int32, - uint64, - int64, - timestamp, - float, - double, - string, - bool + uint8, + int8, + uint16, + int16, + uint32, + int32, + uint64, + int64, + timestamp, + float, + double, + string, + bool FROM test ORDER BY id`) require.NoError(t, err)