You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
how to map to swift struct models and back. How to use PostgresDecodable.
can I use code like next instead withTaskGroup:
let runned = Task {
await client.run()
}
// do sql actions
runned.cancel()
For now I'm using
static func query<T: Codable>(_ closure: @escaping ((PostgresClient) async throws -> T)) async throws -> T {
return try await withThrowingTaskGroup(of: Void.self) { taskGroup in
defer {
taskGroup.cancelAll()
}
taskGroup.addTask {
await client.run()
}
let result: T = try await closure(client)
return result
}
}
try await Database.query { client in
let rows = try await client.query("""
SELECT * FROM "\(Constants.reviewersTableName)"
"""
)
}
And get an error on the second call PostgresNIO/PostgresClient.swift:420: Precondition failed: PostgresClient.run() should just be called once!
What is wrong? I thought block in defer is closing connection.
It would be useful to have a guide.
The text was updated successfully, but these errors were encountered:
Hello, thanks for the great framework!
When trying to use it there are a lot of questions and I thought that it would be great to make some examples of use. I watched https://github.com/vapor/postgres-nio/blob/main/Snippets/Birthdays.swift and it helps a lot, but there are still questions. Like:
For now I'm using
And get an error on the second call
PostgresNIO/PostgresClient.swift:420: Precondition failed: PostgresClient.run() should just be called once!
What is wrong? I thought block in
defer
is closing connection.It would be useful to have a guide.
The text was updated successfully, but these errors were encountered: