sqljs-documentstore
Version:
Minimal, encrypted, sql friendly typed document store, with support for indexed columns. Protects against transactional conflicts
36 lines (35 loc) • 1.18 kB
TypeScript
import { BindParams, QueryExecResult, type Database } from 'sql.js';
import * as AsyncLock from "async-lock";
export declare class LockedDatabase implements ILockedDatabase {
private db;
private flush;
lock: AsyncLock;
config: configType;
state: {
queued: queuedItemType[];
};
txnId?: string;
constructor(db: Pick<Database, 'exec' | 'run'>, flush: () => 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 {
loggingHook?: (q: queuedItemType) => Promise<void>;
}
export interface queuedItemType {
txnId: string;
description: string;
timing: {
waitMs: number;
actionMs: number;
flushMs: number;
};
}