@@ -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 ('alice@example.com', 30), ('geoff@example.com', 32), ('alex@example.com', 83) " ,
253+ users. insertMany ( [ [ email <- " alice@example.com " , age <- 30 ] , [ email <- " geoff@example.com " , age <- 32 ] , [ email <- " alex@example.com " , 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 ('alice@example.com', 30), ('geoff@example.com', 32), ('alex@example.com', 83) " ,
266+ users. insertMany ( or: . replace, [ [ email <- " alice@example.com " , age <- 30 ] , [ email <- " geoff@example.com " , age <- 32 ] , [ email <- " alex@example.com " , 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 , date: Date ( timeIntervalSince1970: 0 ) , optional: nil , sub: nil )
@@ -288,6 +308,18 @@ class QueryTests : XCTestCase {
288308 )
289309 }
290310
311+ func test_insert_many_encodable( ) throws {
312+ let emails = Table ( " emails " )
313+ let value1 = TestCodable ( int: 1 , string: " 2 " , bool: true , float: 3 , double: 4 , date: Date ( timeIntervalSince1970: 0 ) , optional: nil , sub: nil )
314+ let value2 = TestCodable ( int: 2 , string: " 3 " , bool: true , float: 3 , double: 5 , date: Date ( timeIntervalSince1970: 0 ) , optional: nil , sub: nil )
315+ let value3 = TestCodable ( int: 3 , string: " 4 " , bool: true , float: 3 , double: 6 , date: Date ( timeIntervalSince1970: 0 ) , optional: nil , sub: nil )
316+ let insert = try emails. insertMany ( [ value1, value2, value3] )
317+ AssertSQL (
318+ " INSERT INTO \" emails \" ( \" int \" , \" string \" , \" bool \" , \" float \" , \" double \" , \" date \" ) VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000'), (2, '3', 1, 3.0, 5.0, '1970-01-01T00:00:00.000'), (3, '4', 1, 3.0, 6.0, '1970-01-01T00:00:00.000') " ,
319+ insert
320+ )
321+ }
322+
291323 func test_update_compilesUpdateExpression( ) {
292324 AssertSQL (
293325 " UPDATE \" users \" SET \" age \" = 30, \" admin \" = 1 WHERE ( \" id \" = 1) " ,
@@ -505,6 +537,11 @@ class QueryIntegrationTests : SQLiteTestCase {
505537 XCTAssertEqual ( 1 , id)
506538 }
507539
540+ func test_insert_many( ) {
541+ let id = try ! db. run ( users. insertMany ( [ [ email <- " alice@example.com " ] , [ email <- " geoff@example.com " ] ] ) )
542+ XCTAssertEqual ( 2 , id)
543+ }
544+
508545 func test_upsert( ) throws {
509546 let fetchAge = { ( ) throws -> Int ? in
510547 return try self . db. pluck ( self . users. filter ( self . email == " alice@example.com " ) ) . flatMap { $0 [ self . age] }
0 commit comments