MCPcopy Create free account
hub / github.com/upper/db / TestStringAndInt64Array

Method TestStringAndInt64Array

adapter/cockroachdb/cockroachdb_test.go:1050–1116  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1048}
1049
1050func (s *AdapterTests) TestStringAndInt64Array() {
1051 sess := s.Session()
1052 driver := sess.Driver().(*sql.DB)
1053
1054 defer func() {
1055 _, _ = driver.Exec(`DROP TABLE IF EXISTS array_types`)
1056 }()
1057
1058 if _, err := driver.Exec(`
1059 CREATE TABLE array_types (
1060 id serial primary key,
1061 integers bigint[] DEFAULT NULL,
1062 strings varchar(64)[]
1063 )`); err != nil {
1064 s.NoError(err)
1065 }
1066
1067 arrayTypes := sess.Collection("array_types")
1068 err := arrayTypes.Truncate()
1069 s.NoError(err)
1070
1071 type arrayType struct {
1072 ID int64 `db:"id,pk"`
1073 Integers Int64Array `db:"integers"`
1074 Strings StringArray `db:"strings"`
1075 }
1076
1077 tt := []arrayType{
1078 // Test nil arrays.
1079 arrayType{
1080 ID: 1,
1081 Integers: nil,
1082 Strings: nil,
1083 },
1084
1085 // Test empty arrays.
1086 arrayType{
1087 ID: 2,
1088 Integers: []int64{},
1089 Strings: []string{},
1090 },
1091
1092 // Test non-empty arrays.
1093 arrayType{
1094 ID: 3,
1095 Integers: []int64{1, 2, 3},
1096 Strings: []string{"1", "2", "3"},
1097 },
1098 }
1099
1100 for _, item := range tt {
1101 record, err := arrayTypes.Insert(item)
1102 s.NoError(err)
1103
1104 if pk, ok := record.ID().(int64); !ok || pk == 0 {
1105 s.T().Errorf("Expecting an ID.")
1106 }
1107

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