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
Add manual transaction API with commit and automatic rollback support (#48)
## 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
```rust
// 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
- [x] Unit tests for successful transaction commit
- [x] Unit tests for automatic rollback on Drop
- [x] All existing tests still pass
- [x] Code formatting and linting checks pass
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-authored-by: Claude <[email protected]>
0 commit comments