@@ -15,10 +15,6 @@ public protocol SQLDataType {
15
15
static func convert( from value: Any ) -> Self ?
16
16
}
17
17
18
- public extension SQLDataType {
19
- static func convert( from value: Any ) -> Self ? { value as? Self }
20
- }
21
-
22
18
extension Int : SQLDataType {
23
19
public func sqlBind( statement: OpaquePointer , index: Int32 ) {
24
20
sqlite3_bind_int64 ( statement, index, Int64 ( self ) )
@@ -42,6 +38,11 @@ extension Int32: SQLDataType {
42
38
public static func sqlColumn( statement: OpaquePointer , index: Int32 ) -> Int32 {
43
39
sqlite3_column_int ( statement, index)
44
40
}
41
+
42
+ public static func convert( from value: Any ) -> Self ? {
43
+ guard let int64 = value as? Int64 else { return nil }
44
+ return Int32 ( int64)
45
+ }
45
46
}
46
47
47
48
extension Int64 : SQLDataType {
@@ -52,6 +53,8 @@ extension Int64: SQLDataType {
52
53
public static func sqlColumn( statement: OpaquePointer , index: Int32 ) -> Int64 {
53
54
sqlite3_column_int64 ( statement, index)
54
55
}
56
+
57
+ public static func convert( from value: Any ) -> Self ? { value as? Self }
55
58
}
56
59
57
60
extension Double : SQLDataType {
@@ -62,6 +65,8 @@ extension Double: SQLDataType {
62
65
public static func sqlColumn( statement: OpaquePointer , index: Int32 ) -> Double {
63
66
sqlite3_column_double ( statement, index)
64
67
}
68
+
69
+ public static func convert( from value: Any ) -> Self ? { value as? Self }
65
70
}
66
71
67
72
extension String : SQLDataType {
@@ -73,6 +78,8 @@ extension String: SQLDataType {
73
78
guard let pointer = sqlite3_column_text ( statement, index) else { return " " }
74
79
return String ( cString: pointer)
75
80
}
81
+
82
+ public static func convert( from value: Any ) -> Self ? { value as? Self }
76
83
}
77
84
78
85
extension Data : SQLDataType {
@@ -87,6 +94,8 @@ extension Data: SQLDataType {
87
94
let count = Int ( sqlite3_column_bytes ( statement, Int32 ( index) ) )
88
95
return Data ( bytes: pointer, count: count)
89
96
}
97
+
98
+ public static func convert( from value: Any ) -> Self ? { value as? Self }
90
99
}
91
100
92
101
private let SQLITE_TRANSIENT = unsafeBitCast ( - 1 , to: sqlite3_destructor_type. self)
0 commit comments