-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transaction #143
Comments
I don't think SQLKit supports transactions as it's not really the focus of the library. You can start a transaction directly in a database connection with a |
Any chance at another look at this? I tried 'rolling my own' transaction wrapper and it didn't work and seems to have actually 'failed successfully' .. request returns success but only the first query in the transaction appears to have actually worked. this is my attempt: struct Database {
let sql: SQLDatabase
func transaction<T>(_ operations: (SQLDatabase) async throws -> T) async throws -> T {
do {
try await sql.raw("BEGIN;").run()
let result = try await operations(sql)
try await sql.raw("COMMIT;").run()
return result
} catch let error {
try await sql.raw("ROLLBACK;").run()
throw error
}
}
} Which I use like: return try await db.transaction { sql in
let item = ItemRecord(...)
try await sql.insert(item).run()
let join = SomeJoinRecord(item, ...)
try await sql.insert(join).run()
return item
} The item is inserted but the join is not. Here is a trace from the code in production: Trace log
|
The ability to do this correctly was added as part of 3.27.0 |
What the true way to use transaction with async/await style?
Any examples?
The text was updated successfully, but these errors were encountered: