Skip to content

Commit 9fc2b0e

Browse files
committed
add uuid, url support
1 parent 9ef5c33 commit 9fc2b0e

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SQLite/Foundation.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ extension Data : Value {
3939
return Blob(bytes: pointer.baseAddress!, length: count)
4040
}
4141
}
42-
4342
}
4443

4544
extension Date : Value {
@@ -55,7 +54,36 @@ extension Date : Value {
5554
public var datatypeValue: String {
5655
return sqlDateFormatter.string(from: self)
5756
}
57+
}
58+
59+
extension UUID : Value {
60+
61+
public static var declaredDatatype: String {
62+
return String.declaredDatatype
63+
}
64+
65+
public static func fromDatatypeValue(_ stringValue: String) -> UUID {
66+
return UUID(uuidString: stringValue)!
67+
}
68+
69+
public var datatypeValue: String {
70+
return self.uuidString
71+
}
72+
}
73+
74+
extension URL : Value {
5875

76+
public static var declaredDatatype: String {
77+
return String.declaredDatatype
78+
}
79+
80+
public static func fromDatatypeValue(_ stringValue: String) -> URL {
81+
return URL(string: stringValue)!
82+
}
83+
84+
public var datatypeValue: String {
85+
return self.absoluteString
86+
}
5987
}
6088

6189
/// A global date formatter used to serialize and deserialize `NSDate` objects.

Tests/SQLiteTests/FoundationTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,28 @@ class FoundationTests : XCTestCase {
1313
let data = Data.fromDatatypeValue(blob)
1414
XCTAssertEqual(Data([1, 2, 3]), data)
1515
}
16+
17+
func testStringFromUUID() {
18+
let uuid = UUID(uuidString: "4ABE10C9-FF12-4CD4-90C1-4B429001BAD3")!
19+
let string = uuid.datatypeValue
20+
XCTAssertEqual("4ABE10C9-FF12-4CD4-90C1-4B429001BAD3", string)
21+
}
22+
23+
func testUUIDFromString() {
24+
let string = "4ABE10C9-FF12-4CD4-90C1-4B429001BAD3"
25+
let uuid = UUID.fromDatatypeValue(string)
26+
XCTAssertEqual(UUID(uuidString: "4ABE10C9-FF12-4CD4-90C1-4B429001BAD3"), uuid)
27+
}
28+
29+
func testStringFromURL() {
30+
let url = URL(string: "https://google.com")!
31+
let string = url.datatypeValue
32+
XCTAssertEqual("https://google.com", string)
33+
}
34+
35+
func testURLFromString() {
36+
let string = "https://google.com"
37+
let url = URL.fromDatatypeValue(string)
38+
XCTAssertEqual(URL(string: "https://google.com")!, url)
39+
}
1640
}

0 commit comments

Comments
 (0)