MCPcopy
hub / github.com/gocraft/dbr / TestSliceWithSQLScannerSelect

Function TestSliceWithSQLScannerSelect

select_test.go:53–81  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestSliceWithSQLScannerSelect(t *testing.T) {
54 for _, sess := range testSession {
55 reset(t, sess)
56
57 _, err := sess.InsertInto("dbr_people").
58 Columns("name", "email").
59 Values("test1", "test1@test.com").
60 Values("test2", "test2@test.com").
61 Values("test3", "test3@test.com").
62 Exec()
63 require.NoError(t, err)
64
65 //plain string slice (original behavior)
66 var stringSlice []string
67 cnt, err := sess.Select("name").From("dbr_people").Load(&stringSlice)
68
69 require.NoError(t, err)
70 require.Equal(t, 3, cnt)
71 require.Len(t, stringSlice, 3)
72
73 //string slice with sql.Scanner implemented, should act as a single record
74 var sliceScanner stringSliceWithSQLScanner
75 cnt, err = sess.Select("name").From("dbr_people").Load(&sliceScanner)
76
77 require.NoError(t, err)
78 require.Equal(t, 1, cnt)
79 require.Len(t, sliceScanner, 1)
80 }
81}
82
83func TestMaps(t *testing.T) {
84 for _, sess := range testSession {

Callers

nothing calls this directly

Calls 8

resetFunction · 0.85
ValuesMethod · 0.80
ColumnsMethod · 0.80
FromMethod · 0.80
InsertIntoMethod · 0.65
SelectMethod · 0.65
ExecMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…