Skip to content

Commit

Permalink
👨‍🔧Support new version of postgres-nio
Browse files Browse the repository at this point in the history
log queries in debug by `PostgresBridge` cause `postgres-nio` doesn't log queries anymore
  • Loading branch information
MihaelIsaev committed Feb 9, 2022
1 parent 257295e commit 4fc1159
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension Array where Element == Dep {

var deps: [Dep] = []

deps.append("https://github.com/vapor/postgres-nio.git", .exact("1.4.4"), targets: .product(name: "PostgresNIO", package: "postgres-nio"))
deps.append("https://github.com/vapor/postgres-nio.git", from: "1.0.0", targets: .product(name: "PostgresNIO", package: "postgres-nio"))

if localDev {
deps.appendLocal("Bridges", targets: "Bridges")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ extension PostgresConnection: BridgeConnection {
public var dialect: SQLDialect { .psql }

public func query(raw: String) -> EventLoopFuture<Void> {
query(raw).transform(to: ())
logger.debug("\(raw)")
return query(raw).transform(to: ())
}

public func query(sql: SwifQLable) -> EventLoopFuture<Void> {
sql.execute(on: self).transform(to: ())
logger.debug("\(sql)")
return sql.execute(on: self).transform(to: ())
}

public func query<V: Decodable>(raw: String, decoding type: V.Type) -> EventLoopFuture<[V]> {
query(raw).map { $0.rows }.all(decoding: type)
logger.debug("\(raw)")
return query(raw).map { $0.rows }.all(decoding: type)
}

public func query<V>(sql: SwifQLable, decoding type: V.Type) -> EventLoopFuture<[V]> where V : Decodable {
sql.execute(on: self).all(decoding: type)
logger.debug("\(sql)")
return sql.execute(on: self).all(decoding: type)
}
}
1 change: 1 addition & 0 deletions Sources/PostgresBridge/Extensions/SwifQLable+Execute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extension SwifQLable {
} catch {
return conn.eventLoop.makeFailedFuture(error)
}
conn.logger.debug("\(prepared.query) \(binds)")
return conn.query(prepared.query, binds).map { $0.rows }
}
}

0 comments on commit 4fc1159

Please sign in to comment.