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

Method TestBatchInsert

internal/testsuite/sql_suite.go:1274–1315  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1272}
1273
1274func (s *SQLTestSuite) TestBatchInsert() {
1275 sess := s.Session()
1276
1277 for batchSize := 0; batchSize < 17; batchSize++ {
1278 err := sess.Collection("artist").Truncate()
1279 s.NoError(err)
1280
1281 q := sess.SQL().InsertInto("artist").Columns("name")
1282
1283 switch s.Adapter() {
1284 case "postgresql", "cockroachdb":
1285 q = q.Amend(func(query string) string {
1286 return query + ` ON CONFLICT DO NOTHING`
1287 })
1288 }
1289
1290 batch := q.Batch(batchSize)
1291
1292 totalItems := int(rand.Int31n(21))
1293
1294 go func() {
1295 defer batch.Done()
1296 for i := 0; i < totalItems; i++ {
1297 batch.Values(fmt.Sprintf("artist-%d", i))
1298 }
1299 }()
1300
1301 err = batch.Wait()
1302 s.NoError(err)
1303 s.NoError(batch.Err())
1304
1305 c, err := sess.Collection("artist").Find().Count()
1306 s.NoError(err)
1307 s.Equal(uint64(totalItems), c)
1308
1309 for i := 0; i < totalItems; i++ {
1310 c, err := sess.Collection("artist").Find(db.Cond{"name": fmt.Sprintf("artist-%d", i)}).Count()
1311 s.NoError(err)
1312 s.Equal(uint64(1), c)
1313 }
1314 }
1315}
1316
1317func (s *SQLTestSuite) TestBatchInsertNoColumns() {
1318 sess := s.Session()

Callers

nothing calls this directly

Calls 15

SessionMethod · 0.65
TruncateMethod · 0.65
CollectionMethod · 0.65
ColumnsMethod · 0.65
InsertIntoMethod · 0.65
SQLMethod · 0.65
AdapterMethod · 0.65
AmendMethod · 0.65
BatchMethod · 0.65
DoneMethod · 0.65
ValuesMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected