dialect/sql: use raw NULL value in statements rather than passing nil arguments

This commit is contained in:
Ariel Mashraki
2022-08-14 10:51:41 +03:00
committed by Ariel Mashraki
parent 5c2013b5fd
commit 94b19ac973
3 changed files with 26 additions and 8 deletions

View File

@@ -1366,8 +1366,8 @@ func TestBatchCreate(t *testing.T) {
},
expect: func(m sqlmock.Sqlmock) {
// Insert nodes with FKs.
m.ExpectExec(escape("INSERT INTO `users` (`active`, `age`, `best_friend_id`, `name`, `workplace_id`) VALUES (?, ?, ?, ?, ?), (?, ?, ?, ?, ?)")).
WithArgs(false, 32, 3, "a8m", 2, nil, 30, 4, "nati", 2).
m.ExpectExec(escape("INSERT INTO `users` (`active`, `age`, `best_friend_id`, `name`, `workplace_id`) VALUES (?, ?, ?, ?, ?), (NULL, ?, ?, ?, ?)")).
WithArgs(false, 32, 3, "a8m", 2, 30, 4, "nati", 2).
WillReturnResult(sqlmock.NewResult(10, 2))
},
},
@@ -1450,8 +1450,8 @@ func TestBatchCreate(t *testing.T) {
expect: func(m sqlmock.Sqlmock) {
m.ExpectBegin()
// Insert nodes with FKs.
m.ExpectExec(escape("INSERT INTO `users` (`active`, `age`, `name`, `workplace_id`) VALUES (?, ?, ?, ?), (?, ?, ?, ?)")).
WithArgs(false, 32, "a8m", 2, nil, 30, "nati", nil).
m.ExpectExec(escape("INSERT INTO `users` (`active`, `age`, `name`, `workplace_id`) VALUES (?, ?, ?, ?), (NULL, ?, ?, NULL)")).
WithArgs(false, 32, "a8m", 2, 30, "nati").
WillReturnResult(sqlmock.NewResult(10, 2))
// Insert M2M inverse-edges.
m.ExpectExec(escape("INSERT INTO `group_users` (`group_id`, `user_id`) VALUES (?, ?), (?, ?)")).