Skip to content

Commit c0a2d24

Browse files
committed
add test for #24
1 parent 6019b64 commit c0a2d24

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Sources/FluentPostgreSQL/FluentPostgreSQLProvider.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class PostgreSQLVersionCheckProvider: Provider {
4040
public func boot(_ worker: Container) throws {
4141
try worker.withConnection(to: .psql) { conn in
4242
conn.simpleQuery("SELECT current_setting('server_version') as version").map(to: Void.self) { rows in
43-
_serverVersion = try rows[0]["version"]!.decode(String.self)
43+
_serverVersion = try rows[0].firstValue(forColumn: "version")!.decode(String.self)
4444
if let versionString = _serverVersion {
4545
let pointIndex = versionString.index(of: ".") ?? versionString.endIndex
4646
let majorVersion = versionString[..<pointIndex]
@@ -61,4 +61,4 @@ public final class PostgreSQLVersionCheckProvider: Provider {
6161
/// server version string
6262
internal var _serverVersion: String?
6363
/// Enabled by default
64-
internal var _globalEnableIdentityColumns: Bool = true
64+
internal var _globalEnableIdentityColumns: Bool = true

Sources/FluentPostgreSQL/PostgreSQLDatabase+QuerySupporting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extension PostgreSQLDatabase: QuerySupporting, CustomSQLSupporting {
6767
return Future.map(on: connection) { model }
6868
}
6969
case .didCreate:
70-
if M.ID.self == Int.self {
70+
if M.ID.self == Int.self, model.fluentID == nil {
7171
return connection.simpleQuery("SELECT LASTVAL();").map(to: M.self) { row in
7272
var model = model
7373
try model.fluentID = row[0].firstValue(forColumn: "lastval")?.decode(Int.self) as? M.ID

Tests/FluentPostgreSQLTests/FluentPostgreSQLTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ class FluentPostgreSQLTests: XCTestCase {
132132
benchmarker.pool.releaseConnection(conn)
133133
}
134134

135+
func testGH24() throws {
136+
benchmarker.database.enableLogging(using: .print)
137+
let conn = try benchmarker.pool.requestConnection().wait()
138+
try? Allergy.revert(on: conn).wait()
139+
try Allergy.prepare(on: conn).wait()
140+
struct Allergy: PostgreSQLModel, Migration {
141+
static let entity = "allergies"
142+
var id: Int?
143+
}
144+
_ = try Allergy(id: 2).create(on: conn).wait()
145+
_ = try Allergy(id: 4).create(on: conn).wait()
146+
let stuff = try Allergy.query(on: conn).filter(\Allergy.id, in: [1, 2, 3]).all().wait()
147+
XCTAssertEqual(stuff.count, 1)
148+
XCTAssertEqual(stuff.first?.id, 2)
149+
}
150+
135151
static let allTests = [
136152
("testSchema", testSchema),
137153
("testModels", testModels),
@@ -146,6 +162,7 @@ class FluentPostgreSQLTests: XCTestCase {
146162
("testReferentialActions", testReferentialActions),
147163
("testIndexSupporting", testIndexSupporting),
148164
("testMinimumViableModelDeclaration", testMinimumViableModelDeclaration),
165+
("testGH24", testGH24),
149166
]
150167
}
151168

0 commit comments

Comments
 (0)