diff --git a/Sources/PostgreSQL/Node+Oid.swift b/Sources/PostgreSQL/Node+Oid.swift index ae250b1..e07bf0d 100644 --- a/Sources/PostgreSQL/Node+Oid.swift +++ b/Sources/PostgreSQL/Node+Oid.swift @@ -21,7 +21,8 @@ public enum OID: Oid { extension Node { init(oid: Oid, value: String) { guard let type = OID(rawValue: oid) else { - self = .null + // Always fallback to string, allowing to use with custom types as strings + self = .string(value) return } diff --git a/Tests/PostgreSQLTests/PostgreSQLTests.swift b/Tests/PostgreSQLTests/PostgreSQLTests.swift index 5be545e..78c14fc 100644 --- a/Tests/PostgreSQLTests/PostgreSQLTests.swift +++ b/Tests/PostgreSQLTests/PostgreSQLTests.swift @@ -6,6 +6,7 @@ class PostgreSQLTests: XCTestCase { ("testSelectVersion", testSelectVersion), ("testTables", testTables), ("testParameterization", testParameterization), + ("testCustomType", testCustomType), ] var postgreSQL: PostgreSQL.Database! @@ -119,4 +120,18 @@ class PostgreSQLTests: XCTestCase { XCTFail("Testing parameterization failed: \(error)") } } + + func testCustomType() throws { + let uuidString = "7fe1743a-96a8-417c-b6c2-c8bb20d3017e" + let dateString = "2016-10-24 23:04:19.223+00" + + try postgreSQL.execute("DROP TABLE IF EXISTS foo") + try postgreSQL.execute("CREATE TABLE foo (uuid UUID, date TIMESTAMP WITH TIME ZONE)") + try postgreSQL.execute("INSERT INTO foo VALUES ($1, $2)", [.string(uuidString), .string(dateString)]) + + let result = try postgreSQL.execute("SELECT * FROM foo").first + XCTAssertNotNil(result) + XCTAssertEqual(result!["uuid"]?.string, uuidString) + XCTAssertEqual(result!["date"]?.string, dateString) + } }