MCPcopy Index your code
hub / github.com/upper/db / TestStringAndInt64Array

Method TestStringAndInt64Array

adapter/postgresql/postgresql_test.go:1134–1200  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1132}
1133
1134func (s *AdapterTests) TestStringAndInt64Array() {
1135 sess := s.Session()
1136 driver := sess.Driver().(*sql.DB)
1137
1138 defer func() {
1139 _, _ = driver.Exec(`DROP TABLE IF EXISTS array_types`)
1140 }()
1141
1142 if _, err := driver.Exec(`
1143 CREATE TABLE array_types (
1144 id serial primary key,
1145 integers bigint[] DEFAULT NULL,
1146 strings varchar(64)[]
1147 )`); err != nil {
1148 s.NoError(err)
1149 }
1150
1151 arrayTypes := sess.Collection("array_types")
1152 err := arrayTypes.Truncate()
1153 s.NoError(err)
1154
1155 type arrayType struct {
1156 ID int64 `db:"id,pk"`
1157 Integers Int64Array `db:"integers"`
1158 Strings StringArray `db:"strings"`
1159 }
1160
1161 tt := []arrayType{
1162 // Test nil arrays.
1163 arrayType{
1164 ID: 1,
1165 Integers: nil,
1166 Strings: nil,
1167 },
1168
1169 // Test empty arrays.
1170 arrayType{
1171 ID: 2,
1172 Integers: []int64{},
1173 Strings: []string{},
1174 },
1175
1176 // Test non-empty arrays.
1177 arrayType{
1178 ID: 3,
1179 Integers: []int64{1, 2, 3},
1180 Strings: []string{"1", "2", "3"},
1181 },
1182 }
1183
1184 for _, item := range tt {
1185 record, err := arrayTypes.Insert(item)
1186 s.NoError(err)
1187
1188 if pk, ok := record.ID().(int64); !ok || pk == 0 {
1189 s.T().Errorf("Expecting an ID.")
1190 }
1191

Callers

nothing calls this directly

Calls 11

SessionMethod · 0.65
DriverMethod · 0.65
ExecMethod · 0.65
CollectionMethod · 0.65
TruncateMethod · 0.65
InsertMethod · 0.65
IDMethod · 0.65
ErrorfMethod · 0.65
OneMethod · 0.65
FindMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected