import { DatabaseAdapter as DatabaseAdapterInterface, RunResult, TableNameImpl, Transaction as Tx, UncoordinatedDatabaseAdapter } from '../../electric/adapter.js'; import { Row, Statement } from '../../util/index.js'; import { Mutex } from 'async-mutex'; /** * A generic database adapter. * Uses a mutex to ensure that transactions are not interleaved. * Concrete adapters extending this class must implement the * `_run`, `_query`, and `runInTransaction` methods. */ declare abstract class DatabaseAdapter extends TableNameImpl implements DatabaseAdapterInterface { protected txMutex: Mutex; abstract readonly defaultNamespace: 'main' | 'public'; constructor(); /** * Runs a single SQL statement against the DB. * @param stmt The SQL statement to execute * @returns The number of rows modified by this statement. */ abstract _run(stmt: Statement): Promise; /** * Runs a single SQL query against the DB. * @param stmt The SQL statement to execute * @returns The rows read by the query. */ abstract _query(stmt: Statement): Promise; /** * @param statements A list of SQL statements to execute against the DB. */ abstract _runInTransaction(...statements: Statement[]): Promise; _transaction(f: (_tx: Tx, setResult: (res: T) => void) => void): Promise; transaction(f: (_tx: Tx, setResult: (res: T) => void) => void): Promise; run(stmt: Statement): Promise; query(stmt: Statement): Promise; runInTransaction(...statements: Statement[]): Promise; _runExclusively(f: (adapter: UncoordinatedDatabaseAdapter) => Promise | T): Promise; runExclusively(f: (adapter: UncoordinatedDatabaseAdapter) => Promise | T): Promise; get isLocked(): boolean; } /** * A generic database adapter that uses batch execution of SQL queries. * Extend this database adapter if your driver supports batch execution of SQL queries. */ export declare abstract class BatchDatabaseAdapter extends DatabaseAdapter implements DatabaseAdapterInterface { abstract readonly defaultNamespace: 'main' | 'public'; /** * @param statements SQL statements to execute against the DB in a single batch. */ abstract execBatch(statements: Statement[]): Promise; _runInTransaction(...statements: Statement[]): Promise; } /** * A generic database adapter that uses serial execution of SQL queries. * Extend this database adapter if your driver does not support batch execution of SQL queries. */ export declare abstract class SerialDatabaseAdapter extends DatabaseAdapter implements DatabaseAdapterInterface { abstract readonly defaultNamespace: 'main' | 'public'; _runInTransaction(...statements: Statement[]): Promise; } export {};