()
| 1272 | } |
| 1273 | |
| 1274 | func (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 | |
| 1317 | func (s *SQLTestSuite) TestBatchInsertNoColumns() { |
| 1318 | sess := s.Session() |
nothing calls this directly
no test coverage detected