MCPcopy
hub / github.com/gogf/gf / Test_DB_BatchInsert

Function Test_DB_BatchInsert

contrib/drivers/dm/dm_z_unit_basic_test.go:248–304  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

246}
247
248func Test_DB_BatchInsert(t *testing.T) {
249 table := "A_tables"
250 createInitTable(table)
251 gtest.C(t, func(t *gtest.T) {
252 r, err := db.Insert(ctx, table, g.List{
253 {
254 "ID": 400,
255 "ACCOUNT_NAME": "list_400",
256 "CREATE_TIME": gtime.Now(),
257 "UPDATED_TIME": gtime.Now(),
258 },
259 {
260 "ID": 401,
261 "ACCOUNT_NAME": "list_401",
262 "CREATE_TIME": gtime.Now(),
263 "UPDATED_TIME": gtime.Now(),
264 },
265 }, 1)
266 t.AssertNil(err)
267 n, _ := r.RowsAffected()
268 t.Assert(n, 2)
269 })
270
271 gtest.C(t, func(t *gtest.T) {
272 // []any
273 r, err := db.Insert(ctx, table, g.Slice{
274 g.Map{
275 "ID": 500,
276 "ACCOUNT_NAME": "500_batch_500",
277 "CREATE_TIME": gtime.Now(),
278 "UPDATED_TIME": gtime.Now(),
279 },
280 g.Map{
281 "ID": 501,
282 "ACCOUNT_NAME": "501_batch_501",
283 "CREATE_TIME": gtime.Now(),
284 "UPDATED_TIME": gtime.Now(),
285 },
286 }, 1)
287 t.AssertNil(err)
288 n, _ := r.RowsAffected()
289 t.Assert(n, 2)
290 })
291
292 // batch insert map
293 gtest.C(t, func(t *gtest.T) {
294 result, err := db.Insert(ctx, table, g.Map{
295 "ID": 600,
296 "ACCOUNT_NAME": "600_batch_600",
297 "CREATE_TIME": gtime.Now(),
298 "UPDATED_TIME": gtime.Now(),
299 })
300 t.AssertNil(err)
301 n, _ := result.RowsAffected()
302 t.Assert(n, 1)
303 })
304}
305

Callers

nothing calls this directly

Calls 7

CFunction · 0.92
NowFunction · 0.92
AssertNilMethod · 0.80
AssertMethod · 0.80
createInitTableFunction · 0.70
InsertMethod · 0.65
RowsAffectedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…