Skip to content

Commit 07102a2

Browse files
committed
support UUID
1 parent b6d3cfd commit 07102a2

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

Sources/Compiler/Gen/SwiftGenerator.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ public struct SwiftGenerator: Language {
187187
queries: [Query]
188188
) throws -> SourceFileSyntax {
189189
return try SourceFileSyntax {
190+
try ImportDeclSyntax("import Foundation")
190191
try ImportDeclSyntax("import Feather")
191-
192+
192193
for table in tables {
193194
table
194195
}

Sources/Feather/DatabasePrimitive.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import SQLite3
9+
import Foundation
910

1011
@usableFromInline let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
1112

@@ -102,3 +103,21 @@ extension Optional: DatabasePrimitive where Wrapped: DatabasePrimitive {
102103
}
103104
}
104105
}
106+
107+
extension UUID: DatabasePrimitive {
108+
@inlinable public init(from cursor: OpaquePointer, at index: Int32) throws(FeatherError) {
109+
guard let ptr = sqlite3_column_text(cursor, index) else {
110+
throw .columnIsNil(index)
111+
}
112+
113+
guard let value = UUID(uuidString: String(cString: ptr)) else {
114+
throw .invalidUuidString
115+
}
116+
117+
self = value
118+
}
119+
120+
@inlinable public func bind(to statement: OpaquePointer, at index: Int32) throws(FeatherError) {
121+
try uuidString.bind(to: statement, at: index)
122+
}
123+
}

Sources/Feather/FeatherError.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ public enum FeatherError: Error {
2020
/// A query observation was attempted
2121
/// to be started twice.
2222
case subscriptionAlreadyStarted
23+
case invalidUuidString
2324
}

0 commit comments

Comments
 (0)