@@ -247,6 +247,26 @@ class QueryTests : XCTestCase {
247247 )
248248 }
249249
250+ func test_insert_many_compilesInsertManyExpression( ) {
251+ AssertSQL (
252+ " INSERT INTO \" users \" ( \" email \" , \" age \" ) VALUES ('[email protected] ', 30), ('[email protected] ', 32), ('[email protected] ', 83) " , 253+ users
. insertMany ( [ [ email
<- " [email protected] " , age
<- 30 ] , [ email
<- " [email protected] " , age
<- 32 ] , [ email
<- " [email protected] " , age
<- 83 ] ] ) 254+ )
255+ }
256+ func test_insert_many_compilesInsertManyNoneExpression( ) {
257+ AssertSQL (
258+ " INSERT INTO \" users \" DEFAULT VALUES " ,
259+ users. insertMany ( [ ] )
260+ )
261+ }
262+
263+ func test_insert_many_withOnConflict_compilesInsertManyOrOnConflictExpression( ) {
264+ AssertSQL (
265+ " INSERT OR REPLACE INTO \" users \" ( \" email \" , \" age \" ) VALUES ('[email protected] ', 30), ('[email protected] ', 32), ('[email protected] ', 83) " , 266+ users
. insertMany ( or
: . replace
, [ [ email
<- " [email protected] " , age
<- 30 ] , [ email
<- " [email protected] " , age
<- 32 ] , [ email
<- " [email protected] " , age
<- 83 ] ] ) 267+ )
268+ }
269+
250270 func test_insert_encodable( ) throws {
251271 let emails = Table ( " emails " )
252272 let value = TestCodable ( int: 1 , string: " 2 " , bool: true , float: 3 , double: 4 , optional: nil , sub: nil )
@@ -270,6 +290,18 @@ class QueryTests : XCTestCase {
270290 )
271291 }
272292
293+ func test_insert_many_encodable( ) throws {
294+ let emails = Table ( " emails " )
295+ let value1 = TestCodable ( int: 1 , string: " 2 " , bool: true , float: 3 , double: 4 , optional: nil , sub: nil )
296+ let value2 = TestCodable ( int: 2 , string: " 3 " , bool: true , float: 3 , double: 5 , optional: nil , sub: nil )
297+ let value3 = TestCodable ( int: 3 , string: " 4 " , bool: true , float: 3 , double: 6 , optional: nil , sub: nil )
298+ let insert = try emails. insertMany ( [ value1, value2, value3] )
299+ AssertSQL (
300+ " INSERT INTO \" emails \" ( \" int \" , \" string \" , \" bool \" , \" float \" , \" double \" ) VALUES (1, '2', 1, 3.0, 4.0), (2, '3', 1, 3.0, 5.0), (3, '4', 1, 3.0, 6.0) " ,
301+ insert
302+ )
303+ }
304+
273305 func test_update_compilesUpdateExpression( ) {
274306 AssertSQL (
275307 " UPDATE \" users \" SET \" age \" = 30, \" admin \" = 1 WHERE ( \" id \" = 1) " ,
@@ -483,6 +515,11 @@ class QueryIntegrationTests : SQLiteTestCase {
483515 XCTAssertEqual ( 1 , id)
484516 }
485517
518+ func test_insert_many( ) {
519+ let id = try ! db
. run ( users
. insertMany ( [ [ email
<- " [email protected] " ] , [ email
<- " [email protected] " ] ] ) ) 520+ XCTAssertEqual ( 2 , id)
521+ }
522+
486523 func test_update( ) {
487524 let changes = try ! db
. run ( users
. update ( email
<- " [email protected] " ) ) 488525 XCTAssertEqual ( 0 , changes)
0 commit comments