@electric-sql/d2ts
Version:
D2TS is a TypeScript implementation of Differential Dataflow.
56 lines (55 loc) • 1.52 kB
TypeScript
import { SQLiteDb } from './database.js';
import { PipedOperator } from '../types.js';
/**
* Context for storing the SQLite database
* This is used for dependency injection of SQLite database into operators
*/
declare class SQLiteContext {
private static db;
/**
* Set the database to use for all SQLite operators
* @param db - SQLite database instance
*/
static setDb(db: SQLiteDb): void;
/**
* Get the current database
* @returns SQLite database instance or null
*/
static getDb(): SQLiteDb | null;
/**
* Clear the database reference
*/
static clear(): void;
}
/**
* Provide a SQLite database to a pipeline of operators
*
* This function creates a context where the database is available to all
* SQLite operators in the pipeline without explicitly passing it.
*
* @example
* ```
* // Create a SQLite database
* const db = new BetterSQLite3Wrapper(sqlite)
*
* // Use with database injection
* input.pipe(
* withSQLite(db)(
* map((x) => x + 1),
* reduce((vals) => {
* let sum = 0
* for (const [val, diff] of vals) {
* sum += val * diff
* }
* return [[sum, 1]]
* }),
* distinct()
* )
* )
* ```
*
* @param db - The SQLite database to use
* @returns A function that wraps pipeline operators and injects the database
*/
export declare function withSQLite(db: SQLiteDb): <T, U>(...operators: PipedOperator<any, any>[]) => PipedOperator<T, U>;
export { SQLiteContext };