Skip to content

Commit dbf2db4

Browse files
committed
remove problematic default convert(from:) from SQLDataType and implement it in each type instead
1 parent ac9d2b6 commit dbf2db4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Sources/SwiftSQL/SQLDataType.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ public protocol SQLDataType {
1515
static func convert(from value: Any) -> Self?
1616
}
1717

18-
public extension SQLDataType {
19-
static func convert(from value: Any) -> Self? { value as? Self }
20-
}
21-
2218
extension Int: SQLDataType {
2319
public func sqlBind(statement: OpaquePointer, index: Int32) {
2420
sqlite3_bind_int64(statement, index, Int64(self))
@@ -42,6 +38,11 @@ extension Int32: SQLDataType {
4238
public static func sqlColumn(statement: OpaquePointer, index: Int32) -> Int32 {
4339
sqlite3_column_int(statement, index)
4440
}
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+
}
4546
}
4647

4748
extension Int64: SQLDataType {
@@ -52,6 +53,8 @@ extension Int64: SQLDataType {
5253
public static func sqlColumn(statement: OpaquePointer, index: Int32) -> Int64 {
5354
sqlite3_column_int64(statement, index)
5455
}
56+
57+
public static func convert(from value: Any) -> Self? { value as? Self }
5558
}
5659

5760
extension Double: SQLDataType {
@@ -62,6 +65,8 @@ extension Double: SQLDataType {
6265
public static func sqlColumn(statement: OpaquePointer, index: Int32) -> Double {
6366
sqlite3_column_double(statement, index)
6467
}
68+
69+
public static func convert(from value: Any) -> Self? { value as? Self }
6570
}
6671

6772
extension String: SQLDataType {
@@ -73,6 +78,8 @@ extension String: SQLDataType {
7378
guard let pointer = sqlite3_column_text(statement, index) else { return "" }
7479
return String(cString: pointer)
7580
}
81+
82+
public static func convert(from value: Any) -> Self? { value as? Self }
7683
}
7784

7885
extension Data: SQLDataType {
@@ -87,6 +94,8 @@ extension Data: SQLDataType {
8794
let count = Int(sqlite3_column_bytes(statement, Int32(index)))
8895
return Data(bytes: pointer, count: count)
8996
}
97+
98+
public static func convert(from value: Any) -> Self? { value as? Self }
9099
}
91100

92101
private let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)

0 commit comments

Comments
 (0)