-
-
Notifications
You must be signed in to change notification settings - Fork 727
/
Copy pathInsertRecordStructTests.swift
65 lines (57 loc) · 2.35 KB
/
InsertRecordStructTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import XCTest
import GRDB
private let insertedRowCount = 50_000
// Here we insert records.
class InsertRecordStructTests: XCTestCase {
func testGRDB() {
struct Item: PersistableRecord {
var i0: Int
var i1: Int
var i2: Int
var i3: Int
var i4: Int
var i5: Int
var i6: Int
var i7: Int
var i8: Int
var i9: Int
func encode(to container: inout PersistenceContainer) {
container["i0"] = i0
container["i1"] = i1
container["i2"] = i2
container["i3"] = i3
container["i4"] = i4
container["i5"] = i5
container["i6"] = i6
container["i7"] = i7
container["i8"] = i8
container["i9"] = i9
}
}
let databaseFileName = "GRDBPerformanceTests-\(ProcessInfo.processInfo.globallyUniqueString).sqlite"
let databasePath = (NSTemporaryDirectory() as NSString).appendingPathComponent(databaseFileName)
_ = try? FileManager.default.removeItem(atPath: databasePath)
defer {
let dbQueue = try! DatabaseQueue(path: databasePath)
try! dbQueue.inDatabase { db in
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM item")!, insertedRowCount)
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT MIN(i0) FROM item")!, 0)
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT MAX(i9) FROM item")!, insertedRowCount - 1)
}
try! FileManager.default.removeItem(atPath: databasePath)
}
measure {
_ = try? FileManager.default.removeItem(atPath: databasePath)
let dbQueue = try! DatabaseQueue(path: databasePath)
try! dbQueue.inDatabase { db in
try db.execute(sql: "CREATE TABLE item (i0 INT, i1 INT, i2 INT, i3 INT, i4 INT, i5 INT, i6 INT, i7 INT, i8 INT, i9 INT)")
}
try! dbQueue.inTransaction { db in
for i in 0..<insertedRowCount {
try Item(i0: i, i1: i, i2: i, i3: i, i4: i, i5: i, i6: i, i7: i, i8: i, i9: i).insert(db)
}
return .commit
}
}
}
}