signalk-parquet
Version:
Vessel data Parquet file archive with automated value and geospatial triggers. History API compliant with cloud backups and queries.
33 lines • 1.89 kB
TypeScript
/**
* Stage SQLite buffer rows into a DuckDB TEMP table for federated queries.
*
* The buffer must never be opened by DuckDB's bundled SQLite (ATTACH ... TYPE SQLITE):
* two SQLite libraries in one process cannot see each other's POSIX advisory locks,
* so DuckDB's copy would treat the live database as unused, run WAL recovery, and
* truncate the -shm file under node:sqlite's active mmap — crashing the server with
* SIGBUS on the next large write transaction. Instead, rows are read through the
* buffer's own node:sqlite connection and copied into a per-connection DuckDB temp
* table, which the federated SQL unions with parquet exactly as before.
*/
import { DuckDBConnection } from '@duckdb/node-api';
/** The minimal slice of SQLiteBuffer that staging needs. */
export interface BufferStagingSource {
getTableSchema(signalkPath: string): Array<{
name: string;
type: string;
}> | undefined;
getRowsForFederation(signalkPath: string, context: string, fromIso: string, toIso: string, afterId: number, limit: number): Array<Record<string, unknown>>;
}
/**
* Copy the buffer rows a query needs (one path, one context, time-windowed,
* unexported only) into a TEMP table on the given DuckDB connection.
*
* Returns the qualified temp table name to use in FROM clauses, or null when
* the path has no buffer table or no rows match (callers skip the UNION ALL,
* as they did when ATTACH-era subqueries returned null).
*
* The temp table carries all buffer columns, so the existing subquery WHERE
* clauses (context/time/exported/filters) remain valid against it.
*/
export declare function stageBufferTable(connection: DuckDBConnection, buffer: BufferStagingSource, context: string, signalkPath: string, fromIso: string, toIso: string, warn?: (msg: string) => void): Promise<string | null>;
//# sourceMappingURL=buffer-staging.d.ts.map