Skip to content

Commit a335c3d

Browse files
committed
fix typo in upsert
1 parent 32e68ab commit a335c3d

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

Sources/PostgreSQL/SQL/PostgreSQLUpsert.swift

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ public struct PostgreSQLUpsert: SQLSerializable {
66
public typealias Expression = PostgreSQLExpression
77

88
/// See `SQLUpsert`.
9-
public static func upsert(_ columns: [PostgreSQLColumnIdentifier]?, _ values: [(Identifier, Expression)]) -> PostgreSQLUpsert {
10-
if let columns = columns, !columns.isEmpty {
11-
return self.init(columns: columns, values: values)
12-
} else {
13-
return self.init(columns: [.column(nil, .identifier("id"))], values: values)
14-
}
9+
public static func upsert(_ columns: [PostgreSQLColumnIdentifier], _ values: [(Identifier, Expression)]) -> PostgreSQLUpsert {
10+
return self.init(columns: columns, values: values)
1511
}
1612

1713
/// See `SQLUpsert`.
@@ -24,7 +20,7 @@ public struct PostgreSQLUpsert: SQLSerializable {
2420
public func serialize(_ binds: inout [Encodable]) -> String {
2521
var sql: [String] = []
2622
sql.append("ON CONFLICT")
27-
sql.append("(" + columns.serialize(&binds) + ")")
23+
sql.append("(" + columns.map { $0.identifier }.serialize(&binds) + ")")
2824
sql.append("DO UPDATE SET")
2925
sql.append(values.map { $0.0.serialize(&binds) + " = " + $0.1.serialize(&binds) }.joined(separator: ", "))
3026
return sql.joined(separator: " ")

Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift

-16
Original file line numberDiff line numberDiff line change
@@ -540,21 +540,6 @@ class PostgreSQLConnectionTests: XCTestCase {
540540
print(c)
541541
}
542542
}
543-
544-
func testUpsert() throws {
545-
let values: [(PostgreSQLUpsert.Identifier, PostgreSQLUpsert.Expression)] = []
546-
547-
var upsert: PostgreSQLUpsert
548-
549-
upsert = PostgreSQLUpsert.upsert(nil, values)
550-
XCTAssertEqual(upsert.columns, [PostgreSQLColumnIdentifier.column(nil, .identifier("id"))])
551-
552-
upsert = PostgreSQLUpsert.upsert([], values)
553-
XCTAssertEqual(upsert.columns, [PostgreSQLColumnIdentifier.column(nil, .identifier("id"))])
554-
555-
upsert = PostgreSQLUpsert.upsert([.column(nil, .identifier("field"))], values)
556-
XCTAssertEqual(upsert.columns, [PostgreSQLColumnIdentifier.column(nil, .identifier("field"))])
557-
}
558543

559544
static var allTests = [
560545
("testBenchmark", testBenchmark),
@@ -575,7 +560,6 @@ class PostgreSQLConnectionTests: XCTestCase {
575560
("testOrderBy", testOrderBy),
576561
("testInvalidDate", testInvalidDate),
577562
("testEmptyArray", testEmptyArray),
578-
("testUpsert", testUpsert),
579563
]
580564
}
581565

0 commit comments

Comments
 (0)