UNPKG

drizzle-orm-node-sqlite

Version:
55 lines (54 loc) 2.45 kB
/** * Internal runners that satisfy Drizzle’s sqlite-proxy contract. * * Drizzle will call us with: * - method: 'run' | 'get' | 'all' | 'values' * - params: array of bound values for '?' placeholders * We must return: * - for 'run': { rows: [] } * - for 'get': { rows: string[] } (single row, as an array) * - for 'all'/'values': { rows: string[][] } (array of rows as arrays) * * See: https://orm.drizzle.team/docs/connect-drizzle-proxy (row shape details) */ import type { DatabaseSync, SQLInputValue, SQLOutputValue } from 'node:sqlite'; export type NodeSqliteRunnerMethod = 'run' | 'all' | 'get' | 'values'; /** Extra toggles we expose from node:sqlite’s StatementSync helpers. */ export interface NodeSqliteRunnerOptions { /** * When true, map INTEGER columns to JS `bigint` (Node API). * If you enable this, remember to serialize bigint in your transport (e.g., tRPC with superjson). */ readBigInts?: boolean; /** Allow binding named parameters without the prefix in the JS object (Node API). */ allowBareNamedParameters?: boolean; /** Ignore unknown named parameters rather than throwing (Node API). */ allowUnknownNamedParameters?: boolean; } /** * Build a single-statement runner for Drizzle: * - Prepares a fresh StatementSync per call * - Applies statement options (bigints / param ergonomics) * - Returns rows in the array shapes that Drizzle expects * * Node version notes: * - Node 22: statement.get()/all() return **objects**. No `setReturnArrays()` exists. * - Node 24+: you can enable array results via: * * Database option: `new DatabaseSync(path, { returnArrays: true })` * * Or per-statement: `StatementSync#setReturnArrays(true)` * We don’t *require* either; if arrays are already returned we just forward them. */ export declare function makeRunner(db: DatabaseSync, opts?: NodeSqliteRunnerOptions): (sql: string, params: SQLInputValue[], method: NodeSqliteRunnerMethod) => Promise<{ rows: SQLOutputValue[] | SQLOutputValue[][]; }>; /** * Batch executor for Drizzle’s db.batch([...]). * We simply run the single-statement executor for each item. */ export declare function makeBatchRunner(db: DatabaseSync, opts?: NodeSqliteRunnerOptions): (queries: { sql: string; params: SQLInputValue[]; method: NodeSqliteRunnerMethod; }[]) => Promise<{ rows: SQLOutputValue[] | SQLOutputValue[][]; }[]>;