neverchange
Version:
NeverChange is a database solution for web applications using SQLite WASM and OPFS.
57 lines (56 loc) • 2 kB
TypeScript
import { ExecuteResult, QueryResult, NeverChangeDB as INeverChangeDB, Migration } from "./types";
export declare class NeverChangeDB implements INeverChangeDB {
private dbName;
private options;
private dbPromise;
private dbId;
private migrations;
private transactionDepth;
private savepointStack;
constructor(dbName: string, options?: {
debug?: boolean;
isMigrationActive?: boolean;
});
private log;
init(): Promise<void>;
private initializeDatabase;
private getPromiser;
private openDatabase;
execute(sql: string, params?: any[]): Promise<ExecuteResult>;
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
close(): Promise<void>;
addMigrations(migrations: Migration[]): void;
private createMigrationTable;
private getCurrentVersion;
private runMigrations;
private getPromiserOrThrow;
private escapeBlob;
dumpDatabase(options?: {
compatibilityMode?: boolean;
table?: string;
}): Promise<string>;
importDump(dumpContent: string, options?: {
compatibilityMode?: boolean;
}): Promise<void>;
dumpTableToCSV(tableName: string, options?: {
quoteAllFields?: boolean;
}): Promise<string>;
importCSVToTable(tableName: string, csvContent: string): Promise<void>;
/**
* execute a transaction.
* - if it's top-level, it will be a top-level transaction.
* - if it's nested, it will be a nested transaction.
*/
transaction<T>(fn: (tx: NeverChangeDB) => Promise<T>): Promise<T>;
/**
* explicitly rollback the current transaction.
* - if it's top-level, it will rollback all changes.
* - if it's nested, it will rollback to the last created savepoint.
*/
rollback(): Promise<never>;
/**
* if you want to commit explicitly, you can call this method.
* (but it will be committed automatically when the transaction(cb) ends.)
*/
commit(): Promise<void>;
}