forked from pointfreeco/sqlite-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigrationTests.swift
More file actions
39 lines (35 loc) · 947 Bytes
/
MigrationTests.swift
File metadata and controls
39 lines (35 loc) · 947 Bytes
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
import Foundation
import SQLiteData
import Testing
@Suite struct MigrationTests {
@available(iOS 15, *)
@Test func dates() throws {
let database = try DatabaseQueue()
try database.write { db in
try #sql(
"""
CREATE TABLE "models" (
"date" TEXT NOT NULL
)
"""
)
.execute(db)
}
let timestamp = 123.456
try database.write { db in
try db.execute(
literal: "INSERT INTO models (date) VALUES (\(Date(timeIntervalSince1970: timestamp)))"
)
}
try database.read { db in
let grdbDate = try Date.fetchOne(db, sql: "SELECT * FROM models")
try #expect(abs(#require(grdbDate).timeIntervalSince1970 - timestamp) < 0.001)
let date = try #require(try Model.all.fetchOne(db)).date
#expect(abs(date.timeIntervalSince1970 - timestamp) < 0.001)
}
}
}
@available(iOS 15, *)
@Table private struct Model {
var date: Date
}