Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from sroebert/feature/allowAllTypesAsString
Browse files Browse the repository at this point in the history
Instead of returning nil, return string for unknown types
  • Loading branch information
sroebert authored Oct 26, 2016
2 parents 35e1e00 + a9fa90f commit 80bfc24
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/PostgreSQL/Node+Oid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions Tests/PostgreSQLTests/PostgreSQLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class PostgreSQLTests: XCTestCase {
("testSelectVersion", testSelectVersion),
("testTables", testTables),
("testParameterization", testParameterization),
("testCustomType", testCustomType),
]

var postgreSQL: PostgreSQL.Database!
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 80bfc24

Please sign in to comment.