@@ -397,7 +397,7 @@ class QueryIntegrationTests : SQLiteTestCase {
397
397
let id = Expression < Int64 > ( " id " )
398
398
let email = Expression < String > ( " email " )
399
399
let age = Expression < Int > ( " age " )
400
-
400
+
401
401
override func setUp( ) {
402
402
super. setUp ( )
403
403
@@ -509,16 +509,16 @@ class QueryIntegrationTests : SQLiteTestCase {
509
509
let fetchAge = { ( ) throws -> Int ? in
510
510
return try self . db
. pluck ( self . users
. filter ( self . email
== " [email protected] " ) ) . flatMap { $0 [ self . age
] }
511
511
}
512
-
512
+
513
513
let id = try db
. run ( users
. upsert ( email
<- " [email protected] " , age
<- 30 , onConflictOf
: email
) )
514
514
XCTAssertEqual ( 1 , id)
515
515
XCTAssertEqual ( 30 , try fetchAge ( ) )
516
-
516
+
517
517
let nextId = try db
. run ( users
. upsert ( email
<- " [email protected] " , age
<- 42 , onConflictOf
: email
) )
518
518
XCTAssertEqual ( 1 , nextId)
519
519
XCTAssertEqual ( 42 , try fetchAge ( ) )
520
520
}
521
-
521
+
522
522
func test_update( ) {
523
523
let changes = try ! db
. run ( users
. update ( email
<- " [email protected] " ) )
524
524
XCTAssertEqual ( 0 , changes)
@@ -528,24 +528,24 @@ class QueryIntegrationTests : SQLiteTestCase {
528
528
let changes = try ! db. run ( users. delete ( ) )
529
529
XCTAssertEqual ( 0 , changes)
530
530
}
531
-
531
+
532
532
func test_union( ) throws {
533
533
let expectedIDs = [
534
534
try db
. run ( users
. insert ( email
<- " [email protected] " ) ) ,
535
535
try db
. run ( users
. insert ( email
<- " [email protected] " ) )
536
536
]
537
-
537
+
538
538
let query1 = users
. filter ( email
== " [email protected] " )
539
539
let query2 = users
. filter ( email
== " [email protected] " )
540
-
540
+
541
541
let actualIDs = try db. prepare ( query1. union ( query2) ) . map { $0 [ id] }
542
542
XCTAssertEqual ( expectedIDs, actualIDs)
543
-
543
+
544
544
let query3 = users
. select ( users [ * ] , Expression < Int > ( literal
: " 1 AS weight " ) ) . filter ( email
== " [email protected] " )
545
545
let query4 = users
. select ( users [ * ] , Expression < Int > ( literal
: " 2 AS weight " ) ) . filter ( email
== " [email protected] " )
546
-
546
+
547
547
print ( query3. union ( query4) . order ( Expression < Int > ( literal: " weight " ) ) . asSQL ( ) )
548
-
548
+
549
549
let orderedIDs = try db. prepare ( query3. union ( query4) . order ( Expression < Int > ( literal: " weight " ) , email) ) . map { $0 [ id] }
550
550
XCTAssertEqual ( Array ( expectedIDs. reversed ( ) ) , orderedIDs)
551
551
}
0 commit comments