diff --git a/Sources/SwiftKuery/Utils.swift b/Sources/SwiftKuery/Utils.swift index 9aabd06b..839a3213 100644 --- a/Sources/SwiftKuery/Utils.swift +++ b/Sources/SwiftKuery/Utils.swift @@ -44,7 +44,8 @@ struct Utils { } return "'\(String(describing: value))'" default: - return String(describing: item) + let val = String(describing: item) + return val == "nil" ? "NULL" : val } } diff --git a/Tests/SwiftKueryTests/TestInsert.swift b/Tests/SwiftKueryTests/TestInsert.swift index 4d74bd4c..1d38845e 100644 --- a/Tests/SwiftKueryTests/TestInsert.swift +++ b/Tests/SwiftKueryTests/TestInsert.swift @@ -66,6 +66,13 @@ class TestInsert: XCTestCase { query = "INSERT INTO \"tableInsert\" (\"a\", \"b\") VALUES ('banana', 17) RETURNING *" XCTAssertEqual(kuery, query, "\nError in query construction: \n\(kuery) \ninstead of \n\(query)") + let optionalString: String? = nil + i = Insert(into: t, columns: [t.a, t.b], values: ["banana", optionalString as Any]) + .suffix("RETURNING *") + kuery = connection.descriptionOf(query: i) + query = "INSERT INTO \"tableInsert\" (\"a\", \"b\") VALUES ('banana', NULL) RETURNING *" + XCTAssertEqual(kuery, query, "\nError in query construction: \n\(kuery) \ninstead of \n\(query)") + i = Insert(into: t, rows: [["apple", 17], ["banana", -7], ["banana", 27]]) kuery = connection.descriptionOf(query: i) query = "INSERT INTO \"tableInsert\" VALUES ('apple', 17), ('banana', -7), ('banana', 27)"