Skip to content

Conversation

TonyMasson
Copy link
Contributor

@TonyMasson TonyMasson commented Jul 17, 2025

Summary

  • Add Transaction struct with explicit commit() method for manual transaction control
  • Implement automatic rollback via Drop trait when transaction is not committed
  • Add begin_transaction() method to Database for creating manual transactions
  • Include comprehensive unit tests for both commit and rollback scenarios

Changes

  • Database::begin_transaction() - creates a new manual transaction
  • Transaction::commit() - explicitly commits the transaction
  • Transaction Drop implementation - automatically rolls back if not committed
  • Unit tests covering both commit and rollback behavior
  • Updated existing tests to use new collection APIs

API Design

The new Transaction API complements the existing in_transaction() callback approach:

  • Manual transactions: More flexible for complex logic and cross-function usage
  • Callback transactions: Simpler for basic cases with automatic cleanup

Usage Example

// Manual transaction with explicit commit
let mut db = Database::open("mydb", None)?;
let transaction = db.begin_transaction()?;
// ... perform operations ...
transaction.commit()?;

// Automatic rollback via Drop
{
    let _transaction = db.begin_transaction()?;
    // ... perform operations ...
} // automatic rollback here

Test plan

  • Unit tests for successful transaction commit
  • Unit tests for automatic rollback on Drop
  • All existing tests still pass
  • Code formatting and linting checks pass

🤖 Generated with Claude Code

- Add Transaction struct with explicit commit() method
- Implement automatic rollback via Drop trait when not committed
- Add begin_transaction() method to Database for creating manual transactions
- Include comprehensive unit tests for both commit and rollback scenarios
- Update existing tests to use new collection APIs

The new Transaction API complements the existing in_transaction() callback
approach, providing more flexibility for complex transaction logic and
better integration with other Rust codebases.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@TonyMasson TonyMasson marked this pull request as ready for review July 17, 2025 15:14
@TonyMasson TonyMasson requested a review from a team as a code owner July 17, 2025 15:14
Copy link
Contributor

@Nao-ris Nao-ris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing :-)

@TonyMasson TonyMasson merged commit 61ca708 into main Jul 18, 2025
8 of 9 checks passed
@TonyMasson TonyMasson deleted the bc-678-transaction branch July 18, 2025 07:29
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.

2 participants