UNPKG

sqljs-documentstore

Version:

Minimal, encrypted, sql friendly typed document store, with support for indexed columns. Protects against transactional conflicts

38 lines (37 loc) 1.27 kB
import { BindParams, QueryExecResult, type Database } from 'sql.js'; import AsyncLock from "async-lock"; export declare class LockedDatabase implements ILockedDatabase { private db; private flush; static sharedLock: AsyncLock; lock: AsyncLock; config: configType; state: { queued: queuedItemType[]; }; txnId?: string; constructor(db: Pick<Database, 'exec' | 'run'>, flush: () => Promise<void> | void); run(txnId: string, sql: string, params?: BindParams): void; exec(sql: string, params?: BindParams): QueryExecResult[]; /** * all write operations must be wrapped in a transaction * txns are locked using async-lock library to avoid bleeding across session/txn */ txnAsync(description: string, actions: (txnId: string) => Promise<void>): Promise<void>; txn(description: string, actions: (txnId: string) => void): void; } export interface ILockedDatabase extends LockedDatabase { } export interface configType { queuedItemTypeHook?: (q: queuedItemType) => Promise<void>; loggingHook?: (s: string) => void; } export interface queuedItemType { txnId: string; description: string; timing: { waitMs: number; actionMs: number; flushMs: number; }; }