stratadb / Transaction
Type Alias: Transaction
type Transaction = object;Defined in: src/database-types.ts:155
Transaction interface for atomic multi-operation execution.
Remarks
Transactions ensure that multiple operations either all succeed or all fail. Uses SQLite's transaction support underneath. Implements Symbol.dispose for automatic rollback if commit is not called.
Example
// Using try/finally pattern
const tx = db.transaction();
try {
const users = tx.collection('users', userSchema);
await users.insertOne({ name: 'Alice' });
await users.insertOne({ name: 'Bob' });
tx.commit();
} catch (error) {
tx.rollback();
throw error;
}
// Using Symbol.dispose (automatic rollback on scope exit)
using tx = db.transaction();
const users = tx.collection('users', userSchema);
await users.insertOne({ name: 'Alice' });
tx.commit(); // Must call commit, otherwise rollback on scope exitMethods
[dispose]()
dispose: void;Defined in: src/database-types.ts:182
Disposes the transaction (rolls back if not committed). Enables using tx = db.transaction() syntax.
Returns
void
collection()
collection<T>(name, schema): Collection<T>;Defined in: src/database-types.ts:163
Gets a collection within this transaction.
Type Parameters
T
T extends Document
Parameters
name
string
Collection name
schema
Schema definition for the collection
Returns
Collection<T>
Collection bound to this transaction
commit()
commit(): void;Defined in: src/database-types.ts:171
Commits all changes made within this transaction.
Returns
void
rollback()
rollback(): void;Defined in: src/database-types.ts:176
Rolls back all changes made within this transaction.
Returns
void