UNPKG

axiodb

Version:

The Pure JavaScript Alternative to SQLite. Embedded NoSQL database for Node.js with MongoDB-style queries, zero native dependencies, built-in InMemoryCache, and web GUI. Perfect for desktop apps, CLI tools, and embedded systems. No compilation, no platfor

59 lines (58 loc) 2.25 kB
import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface"; export default class Transaction { private readonly collectionPath; private readonly transactionId; private operations; private readonly WAL; private readonly LockManager; private readonly Registry; private readonly IndexManager; private readonly isEncrypted; private readonly ResponseHelper; private readonly Converter; private readonly FileManager; private readonly cryptoInstance?; private readonly encryptionKey?; private readonly startTime; private readonly timeoutMs; private lockedDocuments; private savepoints; private pendingWALEntries; private resolvedOperations; constructor(collectionPath: string, isEncrypted?: boolean, encryptionKey?: string); /** * Creates a savepoint at the current state of the transaction. * Allows partial rollback to this point using rollbackTo(). * * @param name - Unique name for the savepoint * @returns The Transaction instance for chaining * @throws Error if savepoint name already exists */ savepoint(name: string): Transaction; /** * Rolls back the transaction to a specific savepoint. * All operations after the savepoint are discarded. * * @param name - Name of the savepoint to rollback to * @returns The Transaction instance for chaining * @throws Error if savepoint doesn't exist */ rollbackTo(name: string): Transaction; /** * Releases a savepoint without rolling back. * The savepoint is removed but operations remain. * * @param name - Name of the savepoint to release * @returns The Transaction instance for chaining */ releaseSavepoint(name: string): Transaction; insert(data: object): Transaction; update(query: object, data: object): Transaction; delete(query: object): Transaction; commit(): Promise<SuccessInterface | ErrorInterface>; rollback(): Promise<SuccessInterface | ErrorInterface>; private resolveAndLockDocuments; private executeOperations; private applyChanges; static recoverTransactions(collectionPath: string): Promise<void>; }