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

Add support for Standalone transactions and explicit commits and rollbacks #370

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tiberiusferreira
Copy link

@tiberiusferreira tiberiusferreira commented Dec 18, 2024

Adds support for explicit user commits and rollbacks, while still allowing retryable transactions. Also allows users to rollback in retryable transactions, albeit the user now has to explicitly commit them too.

async fn retryable_transaction() -> Result<(), edgedb_tokio::Error> {
    let conn = edgedb_tokio::create_client().await?;
    let val = conn
        .retryable_transaction(|mut tx| async move {
            let new_value = tx
                .query_required_single::<i64, _>(
                    "
                    WITH C := UPDATE Counter SET { value := .value + 1}
                    SELECT C.value LIMIT 1
                    ",
                    &(),
                )
                .await?;
            tx.commit().await?;
            Ok(new_value)
        })
        .await?;
    Ok(())
}

Standalone transactions:

async fn transaction() -> Result<(), edgedb_tokio::Error> {
    let conn = edgedb_tokio::create_client().await?;
    let mut tx = conn.transaction().await?;
    let new_value = tx
        .query_required_single::<i64, _>(
            "
        WITH C := UPDATE Counter SET { value := .value + 1}
        SELECT C.value LIMIT 1
    ",
            &(),
        )
        .await?;
    tx.commit().await?;
    Ok(())
}

Closes: #369

@edgedb-cla
Copy link

edgedb-cla bot commented Dec 18, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@tiberiusferreira tiberiusferreira marked this pull request as ready for review December 18, 2024 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Standalone transactions
1 participant