@@ -50,6 +50,56 @@ public function testUpsertOnUniqueIndex(): void
5050 $ this ->seeInDatabase ('user ' , ['name ' => 'Upsert One ' ]);
5151 }
5252
53+ public function testUpsertBatch (): void
54+ {
55+ $ table = 'type_test ' ;
56+
57+ // Prepares test data.
58+ $ builder = $ this ->db ->table ($ table );
59+ $ builder ->truncate ();
60+
61+ $ this ->forge = Database::forge ($ this ->DBGroup );
62+ $ this ->forge ->addKey (['type_varchar ' ], false , true );
63+ $ this ->forge ->processIndexes ($ table );
64+
65+ for ($ i = 1 ; $ i < 2 ; $ i ++) {
66+ $ builder ->insert ([
67+ 'type_varchar ' => 'test ' . $ i ,
68+ 'type_char ' => 'char ' ,
69+ 'type_smallint ' => 32767 ,
70+ 'type_integer ' => 2_147_483_647 ,
71+ 'type_bigint ' => 9_223_372_036_854_775_807 ,
72+ 'type_numeric ' => 123.23 ,
73+ 'type_date ' => '2023-12-0 ' . $ i ,
74+ 'type_datetime ' => '2023-12-21 12:00:00 ' ,
75+ ]);
76+ }
77+
78+ $ data = [
79+ // new row insert
80+ [
81+ 'type_varchar ' => 'insert ' , // Key
82+ 'type_bigint ' => 9_999_999 ,
83+ 'type_date ' => '2024-01-01 ' ,
84+ 'type_datetime ' => '2024-01-01 09:00:00 ' ,
85+ ],
86+ // update
87+ [
88+ 'type_varchar ' => 'test1 ' , // Key
89+ 'type_bigint ' => 9_999_999 ,
90+ 'type_date ' => '2024-01-01 ' ,
91+ 'type_datetime ' => '2024-01-01 09:00:00 ' ,
92+ ],
93+ ];
94+
95+ $ builder ->onConstraint ('type_varchar ' )->upsertBatch ($ data );
96+
97+ $ expected = $ data ;
98+ $ this ->seeInDatabase ($ table , $ expected [0 ]);
99+ $ this ->seeInDatabase ($ table , $ expected [1 ]);
100+ $ this ->assertSame (2 , $ builder ->countAll ());
101+ }
102+
53103 public function testUpsertAndUpsertBatchWithObject (): void
54104 {
55105 $ data = [];
0 commit comments