Skip to content
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 support #512

Open
adam-fowler opened this issue Oct 4, 2024 · 2 comments
Open

Transaction support #512

adam-fowler opened this issue Oct 4, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@adam-fowler
Copy link

Does it make sense to add support for transactions in similar manner to this

extension PostgresClient {
    func withTransaction<Value>(logger: Logger, _ process: (PostgresConnection) async throws -> Value) async throws -> Value {
        try await withConnection { connection in
            try await connection.query("BEGIN;", logger: logger)
            do {
                let value = try await process(connection)
                try await connection.query("COMMIT;", logger: logger)
                return value
            } catch {
                try await connection.query("ROLLBACK;", logger: logger)
                throw error
            }
        }
    }
}
@gwynne gwynne added the enhancement New feature or request label Oct 4, 2024
@fabianfett fabianfett removed their assignment Oct 4, 2024
@fabianfett fabianfett added the good first issue Good for newcomers label Oct 4, 2024
@fabianfett fabianfett added this to the 2.0.0 milestone Oct 4, 2024
@robertjpayne
Copy link

This was implemented in #519 and #538 but one very important omission I see is that the API doesn't allow specifying an isolation level. While the Postgres default isolation level is really safe, serializable isolation level can be preferred for some applications.

Serializable isolation can require some extra ability to allow retries since serializable errors are not fatal and retries can normally proceed just fine.

@fabianfett
Copy link
Collaborator

@robertjpayne I'd be happy to accept a PR that adds this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants