@@ -12,10 +12,7 @@ import SQLite3
12
12
public protocol SQLDataType {
13
13
func sqlBind( statement: OpaquePointer , index: Int32 )
14
14
static func sqlColumn( statement: OpaquePointer , index: Int32 ) -> Self
15
- }
16
-
17
- public extension SQLDataType {
18
- static func convert( from value: Any ) -> Self ? { value as? Self }
15
+ static func convert( from value: Any ) -> Self ?
19
16
}
20
17
21
18
extension Int : SQLDataType {
@@ -26,6 +23,11 @@ extension Int: SQLDataType {
26
23
public static func sqlColumn( statement: OpaquePointer , index: Int32 ) -> Int {
27
24
Int ( sqlite3_column_int64 ( statement, index) )
28
25
}
26
+
27
+ public static func convert( from value: Any ) -> Int ? {
28
+ guard let int64 = value as? Int64 else { return nil }
29
+ return Int ( int64)
30
+ }
29
31
}
30
32
31
33
extension Int32 : SQLDataType {
@@ -36,6 +38,11 @@ extension Int32: SQLDataType {
36
38
public static func sqlColumn( statement: OpaquePointer , index: Int32 ) -> Int32 {
37
39
sqlite3_column_int ( statement, index)
38
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
+ }
39
46
}
40
47
41
48
extension Int64 : SQLDataType {
@@ -46,6 +53,8 @@ extension Int64: SQLDataType {
46
53
public static func sqlColumn( statement: OpaquePointer , index: Int32 ) -> Int64 {
47
54
sqlite3_column_int64 ( statement, index)
48
55
}
56
+
57
+ public static func convert( from value: Any ) -> Self ? { value as? Self }
49
58
}
50
59
51
60
extension Double : SQLDataType {
@@ -56,6 +65,8 @@ extension Double: SQLDataType {
56
65
public static func sqlColumn( statement: OpaquePointer , index: Int32 ) -> Double {
57
66
sqlite3_column_double ( statement, index)
58
67
}
68
+
69
+ public static func convert( from value: Any ) -> Self ? { value as? Self }
59
70
}
60
71
61
72
extension String : SQLDataType {
@@ -67,6 +78,8 @@ extension String: SQLDataType {
67
78
guard let pointer = sqlite3_column_text ( statement, index) else { return " " }
68
79
return String ( cString: pointer)
69
80
}
81
+
82
+ public static func convert( from value: Any ) -> Self ? { value as? Self }
70
83
}
71
84
72
85
extension Data : SQLDataType {
@@ -81,6 +94,8 @@ extension Data: SQLDataType {
81
94
let count = Int ( sqlite3_column_bytes ( statement, Int32 ( index) ) )
82
95
return Data ( bytes: pointer, count: count)
83
96
}
97
+
98
+ public static func convert( from value: Any ) -> Self ? { value as? Self }
84
99
}
85
100
86
101
private let SQLITE_TRANSIENT = unsafeBitCast ( - 1 , to: sqlite3_destructor_type. self)
0 commit comments