@happyvertical/sql 0.88.2 → 0.89.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -4
- package/dist/chunks/{connection-cache-C32-070B.js → connection-cache-WEH2ulk5.js} +26 -12
- package/dist/chunks/connection-cache-WEH2ulk5.js.map +1 -0
- package/dist/chunks/{duckdb-CY0_khO7.js → duckdb-Di0KdU5i.js} +2 -2
- package/dist/chunks/{duckdb-CY0_khO7.js.map → duckdb-Di0KdU5i.js.map} +1 -1
- package/dist/chunks/{sqlite-CywLOmXl.js → sqlite-BTmP_O5Q.js} +4 -4
- package/dist/chunks/{sqlite-CywLOmXl.js.map → sqlite-BTmP_O5Q.js.map} +1 -1
- package/dist/chunks/{sqlite-connection-cache-DlPkovaY.js → sqlite-connection-cache-DfB52hp6.js} +2 -2
- package/dist/chunks/{sqlite-connection-cache-DlPkovaY.js.map → sqlite-connection-cache-DfB52hp6.js.map} +1 -1
- package/dist/chunks/{sqlite-native-D1SWh34H.js → sqlite-native-FrjMCnBh.js} +3 -3
- package/dist/chunks/{sqlite-native-D1SWh34H.js.map → sqlite-native-FrjMCnBh.js.map} +1 -1
- package/dist/chunks/types-uVFHgaSU.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/shared/types.d.ts +5 -2
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/utils.d.ts +13 -7
- package/dist/shared/utils.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/chunks/connection-cache-C32-070B.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-native-D1SWh34H.js","names":[],"sources":["../../src/sqlite-native.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { DatabaseError } from '@happyvertical/utils';\nimport { DatabaseSchemaManager } from './schema-manager.js';\nimport {\n generateAddColumnStatement,\n generateCreateIndexStatement,\n validateColumnName,\n validateColumnNames,\n validateIndexName,\n validateTableName,\n} from './shared/alter-utils.js';\nimport { getCachedSqliteDatabase } from './shared/sqlite-connection-cache.js';\nimport { createTransactionLock } from './shared/transaction-lock.js';\nimport type {\n ColumnDefinition,\n ColumnDefinitionWithName,\n DatabaseInterface,\n IndexDefinition,\n NotificationCapabilities,\n NotificationListenOptions,\n NotificationPruneOptions,\n NotificationWaitOptions,\n QueryResult,\n SchemaInitializationOptions,\n SchemaProvider,\n SqliteNotificationCapabilityOptions,\n SqliteVectorCapabilityOptions,\n TableInterface,\n TableSchemaInfo,\n TransactionHandle,\n UpsertOptions,\n VectorCapabilities,\n VectorIndexOptions,\n VectorSearchOptions,\n VectorSearchResult,\n WhereClause,\n} from './shared/types.js';\nimport { NestedTransactionError, resolveSchemas } from './shared/types.js';\nimport {\n buildWhere,\n formatDbError,\n resolveInsertColumns,\n wrapDatabaseError,\n} from './shared/utils.js';\nimport type { SqliteOptions } from './sqlite.js';\n\ntype NativeDatabase = any;\ntype NativeStatement = any;\ntype NativeCloseable = { close?: () => void };\n\n/** @internal Best-effort, retryable closer used by native SQLite. */\nexport function createNativeSqliteCloser(\n notificationCloseables: Set<NativeCloseable>,\n honkerDb: NativeCloseable | null,\n database: { close(): void },\n): () => Promise<void> {\n const completed = new Set<object>();\n let active: Promise<void> | undefined;\n return async () => {\n active ??= (async () => {\n const resources: NativeCloseable[] = [\n ...notificationCloseables,\n ...(honkerDb ? [honkerDb] : []),\n database,\n ];\n const errors: unknown[] = [];\n for (const resource of resources) {\n if (completed.has(resource)) continue;\n try {\n resource.close?.();\n completed.add(resource);\n notificationCloseables.delete(resource);\n } catch (error) {\n errors.push(error);\n }\n }\n if (errors.length === 1) throw errors[0];\n if (errors.length > 1) {\n throw new AggregateError(\n errors,\n 'Failed to close native SQLite resources',\n );\n }\n })();\n try {\n await active;\n } finally {\n active = undefined;\n }\n };\n}\n\nconst nativeNullAwareUpsertLocks = new Map<string, Promise<void>>();\nlet nodeSqliteModulePromise: Promise<any> | null = null;\n// sqlite-vector's ESM wrapper uses dynamic require for platform packages.\nconst requireOptionalPackage = createRequire(import.meta.url);\n\ninterface NativeSqliteLocation {\n location: string;\n filePath: string | null;\n isMemory: boolean;\n}\n\ninterface NativeQueryResult {\n rows: Record<string, any>[];\n rowCount: number;\n command?: string;\n fields?: Array<{ name: string }>;\n}\n\nfunction getCapabilityOptions<T extends Record<string, any>>(\n value: boolean | T | undefined,\n): T {\n return typeof value === 'object' && value ? value : ({} as T);\n}\n\nfunction resolveNativeLocation(url = ':memory:'): NativeSqliteLocation {\n if (\n url.startsWith('libsql://') ||\n url.startsWith('http://') ||\n url.startsWith('https://')\n ) {\n throw new DatabaseError(\n 'SQLite native capabilities are only supported for local SQLite databases',\n {\n url,\n hint: \"Use a local file path, 'file:...' URL, or ':memory:' when enabling SQLite capabilities.\",\n },\n );\n }\n\n if (url === ':memory:' || url.startsWith('file::memory:')) {\n return { location: url, filePath: null, isMemory: true };\n }\n\n if (url.startsWith('file://')) {\n const filePath = fileURLToPath(new URL(url));\n return { location: filePath, filePath, isMemory: false };\n }\n\n if (url.startsWith('file:')) {\n const path = url.slice('file:'.length);\n if (!path || path.includes('?')) {\n throw new DatabaseError(\n 'SQLite native capabilities do not support file: URLs with query parameters',\n { url },\n );\n }\n const filePath = resolve(path);\n return { location: filePath, filePath, isMemory: false };\n }\n\n const filePath = resolve(url);\n return { location: filePath, filePath, isMemory: false };\n}\n\nasync function loadNodeSqlite(): Promise<any> {\n nodeSqliteModulePromise ??= importNodeSqlite().catch((error) => {\n nodeSqliteModulePromise = null;\n throw error;\n });\n return nodeSqliteModulePromise;\n}\n\nasync function importNodeSqlite(): Promise<any> {\n const originalEmitWarning = process.emitWarning;\n\n try {\n process.emitWarning = function suppressNodeSqliteExperimentalWarning(\n warning: string | Error,\n ...args: any[]\n ) {\n if (\n args[0] === 'ExperimentalWarning' &&\n String(warning).includes('SQLite is an experimental feature')\n ) {\n return;\n }\n\n return originalEmitWarning.call(process, warning as any, ...args);\n } as typeof process.emitWarning;\n\n const moduleName = 'node:sqlite';\n return (await import(/* @vite-ignore */ moduleName)) as any;\n } catch (error) {\n throw new DatabaseError('Node native SQLite is not available', {\n originalError: formatDbError(error),\n hint: 'SQLite native capabilities require a Node.js runtime with node:sqlite support.',\n });\n } finally {\n process.emitWarning = originalEmitWarning;\n }\n}\n\nasync function loadSqliteVectorExtension(\n database: NativeDatabase,\n): Promise<void> {\n try {\n const moduleName = '@sqliteai/sqlite-vector';\n const module = requireOptionalPackage(moduleName) as any;\n const getExtensionPath =\n module.getExtensionPath ?? module.default?.getExtensionPath;\n\n if (typeof getExtensionPath !== 'function') {\n throw new Error('getExtensionPath export was not found');\n }\n\n database.enableLoadExtension(true);\n database.loadExtension(getExtensionPath());\n } catch (error) {\n throw new DatabaseError(\n 'Failed to load optional SQLite vector capability: install @sqliteai/sqlite-vector',\n {\n packageName: '@sqliteai/sqlite-vector',\n originalError: formatDbError(error),\n hint: 'Install @sqliteai/sqlite-vector to use SQLite vector capabilities.',\n },\n );\n } finally {\n try {\n database.enableLoadExtension(false);\n } catch (_error) {\n // Leave the original extension-loading failure intact.\n }\n }\n}\n\nasync function openHonkerDatabase(\n filePath: string,\n options: SqliteNotificationCapabilityOptions,\n): Promise<any> {\n try {\n const moduleName = '@russellthehippo/honker-node';\n const module = requireOptionalPackage(moduleName) as any;\n const open = module.open ?? module.default?.open;\n\n if (typeof open !== 'function') {\n throw new Error('open export was not found');\n }\n\n return open(filePath, options.maxReaders, options.watcherBackend);\n } catch (error) {\n throw new DatabaseError(\n 'Failed to load optional SQLite notification capability: install @russellthehippo/honker-node',\n {\n packageName: '@russellthehippo/honker-node',\n originalError: formatDbError(error),\n hint: 'Install @russellthehippo/honker-node to use SQLite notification capabilities.',\n },\n );\n }\n}\n\nfunction toPlainRow(row: Record<string, any>): Record<string, any> {\n return Object.fromEntries(Object.entries(row));\n}\n\nfunction getErrorMessage(error: unknown): string | undefined {\n return error instanceof Error ? error.message : undefined;\n}\n\nfunction firstSqlToken(sql: string): string {\n return sql.trim().split(/\\s+/)[0]?.toUpperCase() ?? '';\n}\n\nfunction normalizeNativeQuery(\n sql: string,\n values: any[],\n): { sql: string; args: any[] } {\n const flatArgs = Array.isArray(values[0]) ? values[0] : values;\n const parameterIndexes = Array.from(sql.matchAll(/\\$(\\d+)/g)).map((match) =>\n Number(match[1]),\n );\n\n if (parameterIndexes.length === 0) {\n return { sql, args: flatArgs };\n }\n\n const args = parameterIndexes.map((index) => flatArgs[index - 1]);\n return { sql: sql.replace(/\\$(\\d+)/g, '?'), args };\n}\n\nfunction executeNativeQuery(\n database: NativeDatabase,\n sql: string,\n args: any[] = [],\n): NativeQueryResult {\n const statement: NativeStatement = database.prepare(sql);\n const columns = statement.columns();\n\n if (columns.length > 0) {\n const rows = statement.all(...args).map(toPlainRow);\n return {\n rows,\n rowCount: rows.length,\n command: firstSqlToken(sql),\n fields: columns.map((column: { name: string }) => ({\n name: column.name,\n })),\n };\n }\n\n const result = statement.run(...args);\n return {\n rows: [],\n rowCount: Number(result?.changes ?? 0),\n command: firstSqlToken(sql),\n fields: [],\n };\n}\n\nfunction createNativeTablesFromSchemas(\n database: NativeDatabase,\n schemas: Record<string, SchemaProvider>,\n): void {\n for (const [tableName, schema] of Object.entries(schemas)) {\n try {\n const result = executeNativeQuery(\n database,\n \"SELECT name FROM sqlite_master WHERE type='table' AND name=?\",\n [tableName],\n );\n\n if (result.rows.length > 0) {\n continue;\n }\n\n database.exec(schema.ddl);\n\n for (const indexSql of schema.indexes ?? []) {\n try {\n database.exec(indexSql);\n } catch (error) {\n console.warn(\n `[sqlite] Failed to create index for ${tableName}: ${formatDbError(error)}`,\n );\n }\n }\n\n for (const triggerSql of schema.triggers ?? []) {\n try {\n database.exec(triggerSql);\n } catch (error) {\n console.warn(\n `[sqlite] Failed to create trigger for ${tableName}: ${formatDbError(error)}`,\n );\n }\n }\n } catch (error) {\n throw new DatabaseError(\n `Failed to create table ${tableName} from schema`,\n {\n tableName,\n schema,\n originalError: formatDbError(error),\n },\n );\n }\n }\n}\n\nfunction quoteIdentifier(identifier: string): string {\n return `\"${identifier.replace(/\"/g, '\"\"')}\"`;\n}\n\nfunction buildQuestionWhere(where: WhereClause, startIndex = 1) {\n const built = buildWhere(where, startIndex, 'sqlite');\n return {\n sql: built.sql.replace(/\\$(\\d+)/g, '?'),\n values: built.values,\n };\n}\n\nfunction serializeValue(value: any): any {\n if (value === null || value === undefined) {\n return value;\n }\n if (value instanceof Date) {\n return value.toISOString();\n }\n if (typeof value === 'object') {\n return JSON.stringify(value);\n }\n return value;\n}\n\nfunction serializeRecord(record: Record<string, any>): Record<string, any> {\n const serialized: Record<string, any> = {};\n for (const [key, value] of Object.entries(record)) {\n if (value === undefined) {\n continue;\n }\n serialized[key] = serializeValue(value);\n }\n return serialized;\n}\n\nasync function withNativeNullAwareUpsertLock<T>(\n lockKey: string,\n callback: () => Promise<T>,\n): Promise<T> {\n const previous = nativeNullAwareUpsertLocks.get(lockKey) ?? Promise.resolve();\n let release: () => void = () => {};\n const current = new Promise<void>((resolve) => {\n release = resolve;\n });\n const next = previous.catch(() => {}).then(() => current);\n\n nativeNullAwareUpsertLocks.set(lockKey, next);\n await previous.catch(() => {});\n\n try {\n return await callback();\n } finally {\n release();\n if (nativeNullAwareUpsertLocks.get(lockKey) === next) {\n nativeNullAwareUpsertLocks.delete(lockKey);\n }\n }\n}\n\nfunction sqliteVectorDistance(metric: 'cosine' | 'l2' | 'ip'): string {\n switch (metric) {\n case 'l2':\n return 'L2';\n case 'ip':\n return 'DOT';\n default:\n return 'COSINE';\n }\n}\n\nfunction sqliteVectorQuantization(\n options: SqliteVectorCapabilityOptions,\n): string {\n const parts: string[] = [];\n\n switch (options.quantization ?? 'turbo4') {\n case 'turbo2':\n parts.push('qtype=TURBO,qbits=2');\n break;\n case 'turbo3':\n parts.push('qtype=TURBO,qbits=3');\n break;\n case 'turbo4':\n parts.push('qtype=TURBO,qbits=4');\n break;\n case 'uint8':\n parts.push('qtype=UINT8');\n break;\n case 'int8':\n parts.push('qtype=INT8');\n break;\n case '1bit':\n parts.push('qtype=1BIT');\n break;\n }\n\n if (options.maxMemory) {\n parts.push(`max_memory=${options.maxMemory}`);\n }\n\n return parts.join(',');\n}\n\nfunction createNotificationCapabilities(\n honkerDb: any,\n closeables: Set<{ close?: () => void }>,\n): NotificationCapabilities {\n return {\n async notify(channel: string, payload: any): Promise<number> {\n return Number(honkerDb.notify(channel, payload));\n },\n\n listen(channel: string, options?: NotificationListenOptions) {\n const listener = honkerDb.listen(channel, {\n fallbackPollS:\n options?.fallbackPollMs === null\n ? null\n : options?.fallbackPollMs !== undefined\n ? options.fallbackPollMs / 1000\n : undefined,\n });\n closeables.add(listener);\n return listener;\n },\n\n async waitForUpdate(options?: NotificationWaitOptions): Promise<boolean> {\n const updateEvents = honkerDb.updateEvents();\n closeables.add(updateEvents);\n let timeout: NodeJS.Timeout | undefined;\n let removeAbortListener: (() => void) | undefined;\n\n try {\n if (options?.signal?.aborted) {\n return false;\n }\n\n const updatePromise = updateEvents.next().then(\n () => true,\n () => false,\n );\n const races: Array<Promise<boolean>> = [updatePromise];\n\n if (options?.timeoutMs !== undefined) {\n const timeoutMs = options.timeoutMs;\n races.push(\n new Promise((resolve) => {\n timeout = setTimeout(\n () => resolve(false),\n Math.max(0, timeoutMs),\n );\n }),\n );\n }\n\n if (options?.signal) {\n races.push(\n new Promise((resolve) => {\n const onAbort = () => resolve(false);\n options.signal?.addEventListener('abort', onAbort, {\n once: true,\n });\n removeAbortListener = () =>\n options.signal?.removeEventListener('abort', onAbort);\n }),\n );\n }\n\n return await Promise.race(races);\n } finally {\n if (timeout) {\n clearTimeout(timeout);\n }\n removeAbortListener?.();\n closeables.delete(updateEvents);\n updateEvents.close?.();\n }\n },\n\n async prune(options?: NotificationPruneOptions): Promise<number> {\n return Number(\n honkerDb.pruneNotifications(options?.olderThanS, options?.maxKeep),\n );\n },\n };\n}\n\nfunction createVectorCapabilities(\n database: NativeDatabase,\n options: SqliteVectorCapabilityOptions,\n): VectorCapabilities {\n const initialized = new Map<\n string,\n { dimensions: number; metric: 'cosine' | 'l2' | 'ip' }\n >();\n const indexed = new Map<\n string,\n { metric: 'cosine' | 'l2' | 'ip'; options: SqliteVectorCapabilityOptions }\n >();\n\n const keyFor = (table: string, column: string) => `${table}.${column}`;\n\n const columnExists = (table: string, column: string): boolean => {\n const rows = database\n .prepare(`PRAGMA table_info(${quoteIdentifier(table)})`)\n .all()\n .map(toPlainRow);\n return rows.some((row: Record<string, any>) => row.name === column);\n };\n\n const ensureInitialized = (\n table: string,\n column: string,\n dimensions: number,\n metric: 'cosine' | 'l2' | 'ip' = 'cosine',\n ): void => {\n if (!Number.isInteger(dimensions) || dimensions <= 0) {\n throw new DatabaseError('Vector dimensions must be a positive integer', {\n dimensions,\n });\n }\n\n validateTableName(table);\n validateColumnName(column);\n\n executeNativeQuery(database, 'SELECT vector_init(?, ?, ?)', [\n table,\n column,\n `dimension=${dimensions},type=FLOAT32,distance=${sqliteVectorDistance(metric)}`,\n ]);\n initialized.set(keyFor(table, column), { dimensions, metric });\n };\n\n const quantize = (\n table: string,\n column: string,\n vectorOptions: SqliteVectorCapabilityOptions,\n ): void => {\n const quantizationOptions = sqliteVectorQuantization(vectorOptions);\n if (quantizationOptions) {\n executeNativeQuery(database, 'SELECT vector_quantize(?, ?, ?)', [\n table,\n column,\n quantizationOptions,\n ]);\n } else {\n executeNativeQuery(database, 'SELECT vector_quantize(?, ?)', [\n table,\n column,\n ]);\n }\n\n if (vectorOptions.preload) {\n executeNativeQuery(database, 'SELECT vector_quantize_preload(?, ?)', [\n table,\n column,\n ]);\n }\n };\n\n return {\n async ensureColumn(\n table: string,\n column: string,\n dimensions: number,\n ): Promise<void> {\n validateTableName(table);\n validateColumnName(column);\n\n try {\n if (!columnExists(table, column)) {\n executeNativeQuery(\n database,\n `ALTER TABLE ${quoteIdentifier(table)} ADD COLUMN ${quoteIdentifier(column)} BLOB`,\n );\n }\n ensureInitialized(table, column, dimensions, 'cosine');\n } catch (error) {\n throw new DatabaseError('Failed to ensure SQLite vector column', {\n table,\n column,\n dimensions,\n originalError: formatDbError(error),\n });\n }\n },\n\n async ensureIndex(\n table: string,\n column: string,\n indexOptions?: VectorIndexOptions,\n ): Promise<void> {\n validateTableName(table);\n validateColumnName(column);\n\n const key = keyFor(table, column);\n const dimensions =\n indexOptions?.dimensions ?? initialized.get(key)?.dimensions;\n if (!dimensions) {\n throw new DatabaseError(\n 'SQLite vector index creation requires dimensions',\n {\n table,\n column,\n hint: 'Call ensureColumn(table, column, dimensions) first or pass dimensions to ensureIndex().',\n },\n );\n }\n\n const metric = indexOptions?.metric ?? 'cosine';\n\n try {\n ensureInitialized(table, column, dimensions, metric);\n const vectorOptions = { ...options };\n quantize(table, column, vectorOptions);\n indexed.set(key, { metric, options: vectorOptions });\n } catch (error) {\n throw new DatabaseError('Failed to ensure SQLite vector index', {\n table,\n column,\n originalError: formatDbError(error),\n });\n }\n },\n\n async upsertVector(\n table: string,\n where: Record<string, any>,\n column: string,\n embedding: number[],\n ): Promise<void> {\n validateTableName(table);\n validateColumnName(column);\n\n const key = keyFor(table, column);\n const dimensions = initialized.get(key)?.dimensions ?? embedding.length;\n const { sql: whereClause, values } = buildQuestionWhere(where);\n\n if (!whereClause) {\n throw new DatabaseError(\n 'SQLite vector update requires at least one WHERE condition',\n { table, column },\n );\n }\n\n try {\n ensureInitialized(\n table,\n column,\n dimensions,\n initialized.get(key)?.metric ?? 'cosine',\n );\n executeNativeQuery(\n database,\n `UPDATE ${quoteIdentifier(table)} SET ${quoteIdentifier(column)} = vector_as_f32(?) ${whereClause}`,\n [JSON.stringify(embedding), ...values],\n );\n\n const indexState = indexed.get(key);\n if (indexState) {\n quantize(table, column, indexState.options);\n }\n } catch (error) {\n throw new DatabaseError('Failed to upsert SQLite vector', {\n table,\n column,\n where,\n originalError: formatDbError(error),\n });\n }\n },\n\n async search(\n table: string,\n column: string,\n embedding: number[],\n searchOptions?: VectorSearchOptions,\n ): Promise<VectorSearchResult[]> {\n validateTableName(table);\n validateColumnName(column);\n\n const key = keyFor(table, column);\n const metric = searchOptions?.metric ?? 'cosine';\n const limit = searchOptions?.limit ?? 10;\n const limitArg = BigInt(limit);\n const dimensions = initialized.get(key)?.dimensions ?? embedding.length;\n const indexState = indexed.get(key);\n const useQuantizedScan = indexState?.metric === metric;\n const scanFunction = useQuantizedScan\n ? 'vector_quantize_scan'\n : 'vector_full_scan';\n const convertedWhere = searchOptions?.where\n ? searchOptions.where.replace(/\\$(\\d+)/g, '?')\n : '';\n const whereParams = searchOptions?.params ?? [];\n\n try {\n ensureInitialized(table, column, dimensions, metric);\n\n const rows = convertedWhere\n ? executeNativeQuery(\n database,\n `SELECT base.*, base.rowid AS __sqlite_rowid, vec.distance\n FROM ${scanFunction}(?, ?, vector_as_f32(?)) AS vec\n JOIN ${quoteIdentifier(table)} AS base ON base.rowid = vec.rowid\n WHERE (${convertedWhere})\n ORDER BY vec.distance\n LIMIT ?`,\n [\n table,\n column,\n JSON.stringify(embedding),\n ...whereParams,\n limitArg,\n ],\n ).rows\n : executeNativeQuery(\n database,\n `SELECT base.*, base.rowid AS __sqlite_rowid, vec.distance\n FROM ${scanFunction}(?, ?, vector_as_f32(?), ?) AS vec\n JOIN ${quoteIdentifier(table)} AS base ON base.rowid = vec.rowid\n ORDER BY vec.distance`,\n [table, column, JSON.stringify(embedding), limitArg],\n ).rows;\n\n return rows.map((row) => {\n const { __sqlite_rowid: rowid, ...result } = row;\n return {\n ...result,\n id: String(result.id ?? rowid),\n distance: Number(row.distance),\n };\n });\n } catch (error) {\n throw new DatabaseError('Failed to execute SQLite vector search', {\n table,\n column,\n metric,\n limit,\n originalError: formatDbError(error),\n });\n }\n },\n };\n}\n\nexport async function getNativeSqliteDatabase(\n options: SqliteOptions = {},\n): Promise<DatabaseInterface> {\n const url = options.url || ':memory:';\n\n return getCachedSqliteDatabase('native', options, () =>\n createNativeSqliteDatabase(options, url),\n );\n}\n\nasync function createNativeSqliteDatabase(\n options: SqliteOptions,\n url: string,\n): Promise<DatabaseInterface> {\n const location = resolveNativeLocation(url);\n const notificationsOptions = getCapabilityOptions(\n options.capabilities?.notifications,\n );\n const vectorOptions = getCapabilityOptions(options.capabilities?.vector);\n const wantsNotifications = Boolean(options.capabilities?.notifications);\n const wantsVector = Boolean(options.capabilities?.vector);\n\n if (wantsNotifications && location.isMemory) {\n throw new DatabaseError(\n 'SQLite notification capabilities require a file-backed database',\n {\n url,\n hint: 'Use a temporary file-backed .db for development and tests that need notifications.',\n },\n );\n }\n\n const { DatabaseSync } = await loadNodeSqlite();\n const database = new DatabaseSync(location.location, {\n allowExtension: wantsVector,\n });\n\n // One lock per connection. `getNativeSqliteDatabase` hands cached callers\n // this same closure, so \"created here\" and \"per connection\" are the same\n // scope.\n const connectionLock = createTransactionLock(\n 'sqlite (native)',\n options.transactionQueueTimeout,\n );\n let closeResources: (() => Promise<void>) | undefined;\n\n try {\n if (wantsVector) {\n await loadSqliteVectorExtension(database);\n }\n\n const honkerDb =\n wantsNotifications && location.filePath\n ? await openHonkerDatabase(location.filePath, notificationsOptions)\n : null;\n const notificationCloseables = new Set<{ close?: () => void }>();\n\n const vectorCapabilities = wantsVector\n ? createVectorCapabilities(database, vectorOptions)\n : undefined;\n const notificationCapabilities = honkerDb\n ? createNotificationCapabilities(honkerDb, notificationCloseables)\n : undefined;\n\n const query = async (\n sql: string,\n ...values: any[]\n ): Promise<{ rows: Record<string, any>[]; rowCount: number }> => {\n const normalized = normalizeNativeQuery(sql, values);\n try {\n const result = executeNativeQuery(\n database,\n normalized.sql,\n normalized.args,\n );\n return { rows: result.rows, rowCount: result.rowCount };\n } catch (error) {\n throw wrapDatabaseError('Failed to execute raw query', error, {\n sql: normalized.sql,\n values: normalized.args,\n });\n }\n };\n\n const parseTemplate = (strings: TemplateStringsArray, ...vars: any[]) => {\n let sql = strings[0];\n const values = [];\n for (let i = 0; i < vars.length; i++) {\n values.push(vars[i]);\n sql += `?${strings[i + 1]}`;\n }\n return { sql, values };\n };\n\n const insert = async (\n table: string,\n data: Record<string, any> | Record<string, any>[],\n ): Promise<QueryResult> => {\n validateTableName(table);\n const records = (Array.isArray(data) ? data : [data]).map(\n serializeRecord,\n );\n if (records.length === 0) {\n return { operation: 'insert', affected: 0 };\n }\n const keys = resolveInsertColumns(table, records);\n validateColumnNames(keys);\n const placeholders = records\n .map(() => `(${keys.map(() => '?').join(', ')})`)\n .join(', ');\n const values = records.flatMap((record) =>\n keys.map((key) => record[key]),\n );\n const sql = `INSERT INTO ${table} (${keys.join(', ')}) VALUES ${placeholders}`;\n\n try {\n const result = executeNativeQuery(database, sql, values);\n return { operation: 'insert', affected: result.rowCount };\n } catch (error) {\n throw new DatabaseError('Failed to insert records into table', {\n table,\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const get = async (\n table: string,\n where: WhereClause,\n ): Promise<Record<string, any> | null> => {\n validateTableName(table);\n const { sql: whereClause, values } = buildQuestionWhere(where);\n if (!whereClause) {\n throw new DatabaseError(\n 'GET requires at least one WHERE condition to prevent returning an arbitrary record',\n { table },\n );\n }\n\n const sql = `SELECT * FROM ${table} ${whereClause}`;\n try {\n const result = executeNativeQuery(database, sql, values);\n return result.rows[0] || null;\n } catch (error) {\n throw new DatabaseError('Failed to retrieve record from table', {\n table,\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const list = async (\n table: string,\n where: WhereClause,\n ): Promise<Record<string, any>[]> => {\n validateTableName(table);\n const { sql: whereClause, values } = buildQuestionWhere(where);\n const sql = `SELECT * FROM ${table} ${whereClause}`;\n try {\n return executeNativeQuery(database, sql, values).rows;\n } catch (error) {\n throw new DatabaseError('Failed to list records from table', {\n table,\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const update = async (\n table: string,\n where: WhereClause,\n data: Record<string, any>,\n ): Promise<QueryResult> => {\n validateTableName(table);\n const serializedData = serializeRecord(data);\n const keys = Object.keys(serializedData);\n validateColumnNames(keys);\n const values = Object.values(serializedData);\n const setClause = keys.map((key) => `${key} = ?`).join(', ');\n const { sql: whereClause, values: whereValues } =\n buildQuestionWhere(where);\n\n if (!whereClause) {\n throw new DatabaseError(\n 'UPDATE requires at least one WHERE condition to prevent accidental update of all records',\n { table },\n );\n }\n\n const sql = `UPDATE ${table} SET ${setClause} ${whereClause}`;\n try {\n const result = executeNativeQuery(database, sql, [\n ...values,\n ...whereValues,\n ]);\n return { operation: 'update', affected: result.rowCount };\n } catch (error) {\n throw new DatabaseError('Failed to update records in table', {\n table,\n sql,\n values: [...values, ...whereValues],\n originalError: formatDbError(error),\n });\n }\n };\n\n const hasNullConflictValue = (\n conflictColumns: string[],\n data: Record<string, any>,\n ): boolean => conflictColumns.some((column) => data[column] === null);\n\n const validateUpsertConflictColumns = (\n table: string,\n conflictColumns: string[],\n serializedData: Record<string, any>,\n ): void => {\n const missingColumns = conflictColumns.filter(\n (column) => !(column in serializedData),\n );\n\n if (missingColumns.length > 0) {\n throw new DatabaseError('Conflict columns missing from data', {\n table,\n conflictColumns,\n missingColumns,\n availableColumns: Object.keys(serializedData),\n hint: 'All columns specified in ON CONFLICT must be present in the data being inserted. Undefined values are filtered out during serialization - consider using null or an empty string instead.',\n });\n }\n };\n\n const executeStandardUpsert = (\n table: string,\n conflictColumns: string[],\n serializedData: Record<string, any>,\n ): QueryResult => {\n const keys = Object.keys(serializedData);\n const values = Object.values(serializedData);\n const placeholders = keys.map(() => '?').join(', ');\n const updateSet = keys\n .map((key) => `${key} = excluded.${key}`)\n .join(', ');\n const conflict = conflictColumns.join(', ');\n const sql = `INSERT INTO ${table} (${keys.join(', ')}) VALUES (${placeholders}) ON CONFLICT(${conflict}) DO UPDATE SET ${updateSet}`;\n const result = executeNativeQuery(database, sql, values);\n return { operation: 'upsert', affected: result.rowCount };\n };\n\n const executeNullAwareUpsertAttempt = (\n table: string,\n conflictColumns: string[],\n serializedData: Record<string, any>,\n ): QueryResult => {\n const keys = Object.keys(serializedData);\n const values = Object.values(serializedData);\n const updateSet = keys.map((key) => `${key} = ?`).join(', ');\n const whereClause = conflictColumns\n .map((column) => `${column} IS ?`)\n .join(' AND ');\n const whereValues = conflictColumns.map(\n (column) => serializedData[column],\n );\n\n const updateResult = executeNativeQuery(\n database,\n `UPDATE ${table} SET ${updateSet} WHERE ${whereClause}`,\n [...values, ...whereValues],\n );\n\n if (updateResult.rowCount > 0) {\n return { operation: 'upsert', affected: updateResult.rowCount };\n }\n\n const placeholders = keys.map(() => '?').join(', ');\n const insertResult = executeNativeQuery(\n database,\n `INSERT INTO ${table} (${keys.join(', ')}) VALUES (${placeholders})`,\n values,\n );\n\n return { operation: 'upsert', affected: insertResult.rowCount };\n };\n\n /**\n * Rejects hostile table/column identifiers before an upsert builds SQL.\n *\n * Called from the public entry points rather than from `executeUpsert`, so\n * the failure reaches the caller naming the bad identifier instead of being\n * flattened into the wrapper's generic \"Failed to upsert record into table\".\n *\n * Validates the keys of the already-serialized snapshot — the exact array\n * the executors interpolate — not a fresh enumeration of the caller's\n * `data`. Enumerating `data` again could disagree with the snapshot if it is\n * a Proxy whose `ownKeys` trap returns different keys on successive reads.\n */\n const validateUpsertIdentifiers = (\n table: string,\n conflictColumns: string[],\n serializedData: Record<string, any>,\n ): void => {\n validateTableName(table);\n validateColumnNames([...conflictColumns, ...Object.keys(serializedData)]);\n };\n\n const executeUpsert = async (\n table: string,\n conflictColumns: string[],\n serializedData: Record<string, any>,\n upsertOptions: UpsertOptions | undefined,\n acquireTransaction: boolean,\n ): Promise<QueryResult> => {\n validateUpsertConflictColumns(table, conflictColumns, serializedData);\n\n if (\n upsertOptions?.nullsDistinct ||\n !hasNullConflictValue(conflictColumns, serializedData)\n ) {\n return executeStandardUpsert(table, conflictColumns, serializedData);\n }\n\n if (!acquireTransaction) {\n return executeNullAwareUpsertAttempt(\n table,\n conflictColumns,\n serializedData,\n );\n }\n\n const lockKey = `${location.location}:${table}:${conflictColumns\n .map((column) => `${column}:${JSON.stringify(serializedData[column])}`)\n .join('|')}`;\n\n return withNativeNullAwareUpsertLock(lockKey, async () => {\n // This opens a transaction on the shared connection like any other, so\n // it takes the same lock — otherwise a null-aware upsert overlapping a\n // `transaction()` call reintroduces exactly the corruption the lock\n // exists to prevent.\n const releaseConnection = await connectionLock.acquire();\n try {\n database.exec('BEGIN IMMEDIATE');\n const result = executeNullAwareUpsertAttempt(\n table,\n conflictColumns,\n serializedData,\n );\n database.exec('COMMIT');\n return result;\n } catch (error) {\n try {\n database.exec('ROLLBACK');\n } catch (_rollbackError) {\n // Preserve the original failure.\n }\n throw error;\n } finally {\n releaseConnection();\n }\n });\n };\n\n const upsert = async (\n table: string,\n conflictColumns: string[],\n data: Record<string, any>,\n upsertOptions?: UpsertOptions,\n ): Promise<QueryResult> => {\n // Snapshot the record and the conflict columns once and thread both\n // through validation and SQL, so neither a hostile record nor a hostile\n // conflict-column array can present different identifiers to each.\n const serializedData = serializeRecord(data);\n const conflictCols = [...conflictColumns];\n validateUpsertIdentifiers(table, conflictCols, serializedData);\n try {\n return await executeUpsert(\n table,\n conflictCols,\n serializedData,\n upsertOptions,\n true,\n );\n } catch (error) {\n if (getErrorMessage(error) === 'Conflict columns missing from data') {\n throw error;\n }\n throw new DatabaseError('Failed to upsert record into table', {\n table,\n values: data,\n conflictColumns,\n originalError: formatDbError(error),\n });\n }\n };\n\n const upsertInCurrentTransaction = (\n table: string,\n conflictColumns: string[],\n data: Record<string, any>,\n upsertOptions?: UpsertOptions,\n ): Promise<QueryResult> => {\n // Snapshot the record and the conflict columns once and thread both\n // through validation and SQL, so neither a hostile record nor a hostile\n // conflict-column array can present different identifiers to each.\n const serializedData = serializeRecord(data);\n const conflictCols = [...conflictColumns];\n validateUpsertIdentifiers(table, conflictCols, serializedData);\n return executeUpsert(\n table,\n conflictCols,\n serializedData,\n upsertOptions,\n false,\n );\n };\n\n const getOrInsert = async (\n table: string,\n where: WhereClause,\n data: Record<string, any>,\n ): Promise<Record<string, any>> => {\n const existing = await get(table, where);\n if (existing) return existing;\n await insert(table, data);\n const inserted = await get(table, where);\n if (!inserted) {\n throw new DatabaseError('Failed to insert and retrieve record', {\n table,\n where,\n data,\n });\n }\n return inserted;\n };\n\n const deleteRecords = async (\n table: string,\n where: WhereClause,\n ): Promise<QueryResult> => {\n validateTableName(table);\n const { sql: whereClause, values } = buildQuestionWhere(where);\n if (!whereClause) {\n throw new DatabaseError(\n 'DELETE requires at least one WHERE condition to prevent accidental deletion of all records',\n { table },\n );\n }\n\n try {\n const result = executeNativeQuery(\n database,\n `DELETE FROM ${table} ${whereClause}`,\n values,\n );\n return { operation: 'delete', affected: result.rowCount };\n } catch (error) {\n throw new DatabaseError('Failed to delete records from table', {\n table,\n where,\n originalError: formatDbError(error),\n });\n }\n };\n\n const count = async (\n table: string,\n where?: WhereClause,\n ): Promise<number> => {\n validateTableName(table);\n if (\n !where ||\n (typeof where === 'object' && Object.keys(where).length === 0)\n ) {\n const result = executeNativeQuery(\n database,\n `SELECT COUNT(*) as count FROM ${table}`,\n );\n return Number(result.rows[0]?.count) || 0;\n }\n\n const { sql: whereClause, values } = buildQuestionWhere(where);\n const result = executeNativeQuery(\n database,\n `SELECT COUNT(*) as count FROM ${table} ${whereClause}`,\n values,\n );\n return Number(result.rows[0]?.count) || 0;\n };\n\n const tableExists = async (tableName: string): Promise<boolean> => {\n const result = executeNativeQuery(\n database,\n \"SELECT name FROM sqlite_master WHERE type='table' AND name=?\",\n [tableName],\n );\n return result.rows.length > 0;\n };\n\n const syncSchema = async (schema: string): Promise<void> => {\n const commands = schema\n .replace(/\\s+/g, ' ')\n .replace(/DEFAULT CAST\\(([^)]+)\\s+AS\\s+\\w+\\)/gi, 'DEFAULT $1')\n .trim()\n .split(';')\n .map((command) => command.trim())\n .filter((command) => command.length > 0);\n\n for (const command of commands) {\n database.exec(command);\n }\n };\n\n const many = async (\n strings: TemplateStringsArray,\n ...vars: any[]\n ): Promise<Record<string, any>[]> => {\n const { sql, values } = parseTemplate(strings, ...vars);\n try {\n return executeNativeQuery(database, sql, values).rows;\n } catch (error) {\n throw new DatabaseError('Failed to execute many query', {\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const single = async (\n strings: TemplateStringsArray,\n ...vars: any[]\n ): Promise<Record<string, any> | null> => {\n const { sql, values } = parseTemplate(strings, ...vars);\n try {\n return executeNativeQuery(database, sql, values).rows[0] || null;\n } catch (error) {\n throw new DatabaseError('Failed to execute single query', {\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const pluck = async (\n strings: TemplateStringsArray,\n ...vars: any[]\n ): Promise<any> => {\n const { sql, values } = parseTemplate(strings, ...vars);\n try {\n const row = executeNativeQuery(database, sql, values).rows[0];\n return row ? Object.values(row)[0] : null;\n } catch (error) {\n throw new DatabaseError('Failed to execute pluck query', {\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const execute = async (\n strings: TemplateStringsArray,\n ...vars: any[]\n ): Promise<void> => {\n const { sql, values } = parseTemplate(strings, ...vars);\n try {\n if (values.length === 0) {\n database.exec(sql);\n return;\n }\n executeNativeQuery(database, sql, values);\n } catch (error) {\n throw new DatabaseError('Failed to execute query', {\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const oo = many;\n const oO = single;\n const ox = pluck;\n const xx = execute;\n\n const table = (tableName: string): TableInterface => ({\n insert: (data) => insert(tableName, data),\n get: (where) => get(tableName, where),\n list: (where) => list(tableName, where),\n });\n\n // Names nested savepoints. Only ever appended to an identifier the adapter\n // generates, never caller input.\n let savepointSequence = 0;\n\n /**\n * Re-enters the transaction already in progress under a savepoint.\n *\n * This is what the transaction-scoped interface exposes as `transaction`.\n * Handing it the top-level `transaction` instead — the previous behaviour —\n * sent a nested call into a second BEGIN on the one shared connection; that\n * throws, and the nested call's own ROLLBACK then discarded the *enclosing*\n * transaction's work while later writes committed in autocommit.\n */\n const nestedTransaction = async <T>(\n callback: (tx: DatabaseInterface) => Promise<T>,\n ): Promise<T> => {\n savepointSequence += 1;\n const name = `hv_sp_${savepointSequence}`;\n database.exec(`SAVEPOINT ${name}`);\n try {\n const result = await callback(\n buildDatabaseInterface(\n upsertInCurrentTransaction,\n nestedTransaction,\n refuseNestedBeginTransaction,\n ),\n );\n database.exec(`RELEASE SAVEPOINT ${name}`);\n return result;\n } catch (error) {\n try {\n // ROLLBACK TO leaves the savepoint defined, so release it too or it\n // accumulates for the life of the transaction.\n database.exec(`ROLLBACK TO SAVEPOINT ${name}`);\n database.exec(`RELEASE SAVEPOINT ${name}`);\n } catch {\n // The enclosing transaction is already unwinding; its teardown owns\n // the connection from here.\n }\n throw error;\n }\n };\n\n const transaction = async <T>(\n callback: (tx: DatabaseInterface) => Promise<T>,\n ): Promise<T> =>\n // Held across the whole BEGIN … COMMIT/ROLLBACK span. Without it two\n // overlapping calls raced on the one connection: the second BEGIN threw,\n // its catch ran ROLLBACK, and that rollback ended the *first*\n // transaction — half of its writes durable, half lost, and its promise\n // rejected, so the caller was told nothing had happened.\n connectionLock.run(async () => {\n try {\n database.exec('BEGIN TRANSACTION');\n const txDb = buildDatabaseInterface(\n upsertInCurrentTransaction,\n nestedTransaction,\n refuseNestedBeginTransaction,\n );\n const result = await callback(txDb);\n database.exec('COMMIT');\n return result;\n } catch (error) {\n // A failing ROLLBACK must not replace the caller's error: SQLite\n // reports \"cannot rollback - no transaction is active\" whenever the\n // transaction is already gone, which says nothing about what failed.\n try {\n database.exec('ROLLBACK');\n } catch {\n // Nothing left to roll back.\n }\n throw error;\n }\n });\n\n /**\n * The `beginTransaction` exposed on a transaction-scoped interface.\n *\n * Unlike `transaction`, a manual handle has no savepoint equivalent: it\n * would have to own the connection until the caller ends it, which the\n * enclosing transaction already does. Issuing a second BEGIN threw before\n * transactions were serialized; now it would instead wait on a lock its own\n * caller holds, so refuse explicitly rather than deadlock.\n */\n const refuseNestedBeginTransaction = async (): Promise<never> => {\n throw new NestedTransactionError(\n 'beginTransaction() cannot be called inside a transaction. Use the transaction you already have, or nest with transaction() to re-enter it under a savepoint.',\n { adapter: 'sqlite-native' },\n );\n };\n\n const beginTransaction = async (): Promise<TransactionHandle> => {\n // The handle owns the connection until the caller ends it, so the lock is\n // held across the gap rather than around a single call. A handle that is\n // never committed or rolled back therefore blocks every later transaction\n // until the queue timeout reports it.\n const releaseConnection = await connectionLock.acquire();\n try {\n database.exec('BEGIN TRANSACTION');\n } catch (error) {\n // No transaction was opened, so there is no handle to end it and\n // nothing left to release the connection.\n releaseConnection();\n throw error;\n }\n\n let active = true;\n\n // COMMIT and ROLLBACK can both throw, and the transaction is over either\n // way, so the connection goes back before the error is rethrown.\n const end = (command: 'COMMIT' | 'ROLLBACK'): void => {\n if (!active) {\n throw new DatabaseError('Transaction already ended', {});\n }\n try {\n database.exec(command);\n } catch (error) {\n // COMMIT can fail and leave the transaction *open* — SQLite documents\n // exactly that for SQLITE_BUSY. Releasing the connection then would hand\n // the next queued caller a connection still inside a transaction: its\n // BEGIN would throw, and its catch would ROLLBACK, discarding this\n // transaction's work. So normalize before releasing, the way the pooled\n // adapter's discardTxClient does.\n try {\n database.exec('ROLLBACK');\n } catch {\n // Already gone; nothing left to normalize.\n }\n throw error;\n } finally {\n active = false;\n releaseConnection();\n }\n };\n\n const commit = async (): Promise<void> => end('COMMIT');\n\n const rollback = async (): Promise<void> => end('ROLLBACK');\n\n return {\n // The handle is inside a transaction for the same reason a callback\n // scope is, so it re-enters via savepoint too.\n ...buildDatabaseInterface(\n upsertInCurrentTransaction,\n nestedTransaction,\n refuseNestedBeginTransaction,\n ),\n commit,\n rollback,\n isActive: () => active,\n };\n };\n\n const initializeSchemas = async (\n schemaOptions: SchemaInitializationOptions,\n ): Promise<void> => {\n const schemaManager = new DatabaseSchemaManager();\n await schemaManager.initializeSchemas(\n buildDatabaseInterface(upsert),\n schemaOptions,\n );\n };\n\n const getTableSchema = async (\n tableName: string,\n ): Promise<TableSchemaInfo | null> => {\n validateTableName(tableName);\n\n if (!(await tableExists(tableName))) {\n return null;\n }\n\n const columnRows = database\n .prepare(`PRAGMA table_info(${quoteIdentifier(tableName)})`)\n .all()\n .map(toPlainRow);\n\n const columns: Record<string, ColumnDefinition> = {};\n for (const row of columnRows) {\n columns[row.name as string] = {\n type: row.type as string,\n primaryKey: row.pk === 1,\n notNull: row.notnull === 1,\n defaultValue: row.dflt_value,\n };\n }\n\n const indexRows = executeNativeQuery(\n database,\n `SELECT name FROM sqlite_master\n WHERE type = 'index'\n AND tbl_name = ?\n AND name NOT LIKE 'sqlite_%'`,\n [tableName],\n ).rows;\n\n const indexes: IndexDefinition[] = [];\n for (const row of indexRows) {\n const indexName = row.name as string;\n const indexInfoRows = database\n .prepare(`PRAGMA index_info(${quoteIdentifier(indexName)})`)\n .all()\n .map(toPlainRow);\n const indexListRows = database\n .prepare(`PRAGMA index_list(${quoteIdentifier(tableName)})`)\n .all()\n .map(toPlainRow);\n\n indexes.push({\n name: indexName,\n columns: indexInfoRows.map((info: Record<string, any>) => info.name),\n unique: indexListRows.some(\n (info: Record<string, any>) =>\n info.name === indexName && info.unique === 1,\n ),\n });\n }\n\n const fkRows = database\n .prepare(`PRAGMA foreign_key_list(${quoteIdentifier(tableName)})`)\n .all()\n .map(toPlainRow);\n\n return {\n tableName,\n columns,\n indexes,\n foreignKeys: fkRows.map((row: Record<string, any>) => ({\n column: row.from as string,\n referencesTable: row.table as string,\n referencesColumn: row.to as string,\n onDelete: row.on_delete as string | undefined,\n onUpdate: row.on_update as string | undefined,\n })),\n };\n };\n\n const alterTable = {\n addColumn: async (\n tableName: string,\n column: ColumnDefinitionWithName,\n ): Promise<void> => {\n validateTableName(tableName);\n validateColumnName(column.name);\n let sql: string | undefined;\n try {\n sql = generateAddColumnStatement(tableName, column, 'sqlite');\n executeNativeQuery(database, sql);\n } catch (error) {\n throw wrapDatabaseError('Failed to add column to table', error, {\n table: tableName,\n column: column.name,\n ...(sql ? { sql } : {}),\n });\n }\n },\n\n addIndex: async (\n tableName: string,\n index: IndexDefinition,\n ): Promise<void> => {\n validateTableName(tableName);\n validateIndexName(index.name);\n for (const column of index.columns) {\n validateColumnName(column);\n }\n let sql: string | undefined;\n try {\n sql = generateCreateIndexStatement(tableName, index);\n executeNativeQuery(database, sql);\n } catch (error) {\n throw wrapDatabaseError('Failed to create index on table', error, {\n table: tableName,\n index: index.name,\n ...(sql ? { sql } : {}),\n });\n }\n },\n };\n\n const close = createNativeSqliteCloser(\n notificationCloseables,\n honkerDb,\n database,\n );\n closeResources = close;\n\n function buildDatabaseInterface(\n upsertImpl: DatabaseInterface['upsert'],\n transactionImpl: DatabaseInterface['transaction'] = transaction,\n beginTransactionImpl: DatabaseInterface['beginTransaction'] = beginTransaction,\n ): DatabaseInterface {\n return {\n url,\n client: database,\n query,\n insert,\n update,\n upsert: upsertImpl,\n get,\n list,\n getOrInsert,\n delete: deleteRecords,\n count,\n table,\n tableExists,\n many,\n single,\n pluck,\n execute,\n oo,\n oO,\n ox,\n xx,\n syncSchema,\n initializeSchemas,\n transaction: transactionImpl,\n beginTransaction: beginTransactionImpl,\n getTableSchema,\n alterTable,\n close,\n ...(vectorCapabilities ? { vector: vectorCapabilities } : {}),\n ...(notificationCapabilities\n ? { notifications: notificationCapabilities }\n : {}),\n };\n }\n\n const db = buildDatabaseInterface(upsert);\n const resolvedSchemas = resolveSchemas(options.schemas);\n if (resolvedSchemas && Object.keys(resolvedSchemas).length > 0) {\n createNativeTablesFromSchemas(database, resolvedSchemas);\n }\n\n return db;\n } catch (error) {\n try {\n if (closeResources) await closeResources();\n else database.close();\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n 'Native SQLite initialization and cleanup failed',\n );\n }\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;AAqDA,SAAgB,yBACd,wBACA,UACA,UACqB;CACrB,MAAM,4BAAY,IAAI,IAAY;CAClC,IAAI;CACJ,OAAO,YAAY;EACjB,YAAY,YAAY;GACtB,MAAM,YAA+B;IACnC,GAAG;IACH,GAAI,WAAW,CAAC,QAAQ,IAAI,CAA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AmB,MAAM;IAE3B,IAAI;IACJ,IAAI;KACF,MAAM,6BAA6B,WAAW,KAAK;KACnD,mBAAmB,UAAU,GAAG;IAClC,SAAS,OAAO;KACd,MAAM,kBAAkB,mCAAmC,OAAO;MAChE,OAAO;MACP,OAAO,MAAM;MACb,GAAI,MAAM,EAAE,IAAI,IAAI,CAAC;KACvB,CAAC;IACH;GACF;EACF;EAEA,MAAM,QAAQ,yBACZ,wBACA,UACA,QACF;EACA,iBAAiB;EAEjB,SAAS,uBACP,YACA,kBAAoD,aACpD,uBAA8D,kBAC3C;GACnB,OAAO;IACL;IACA,QAAQ;IACR;IACA;IACA;IACA,QAAQ;IACR;IACA;IACA;IACA,QAAQ;IACR;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,aAAa;IACb,kBAAkB;IAClB;IACA;IACA;IACA,GAAI,qBAAqB,EAAE,QAAQ,mBAAmB,IAAI,CAAC;IAC3D,GAAI,2BACA,EAAE,eAAe,yBAAyB,IAC1C,CAAC;GACP;EACF;EAEA,MAAM,KAAK,uBAAuB,MAAM;EACxC,MAAM,kBAAkB,eAAe,QAAQ,OAAO;EACtD,IAAI,mBAAmB,OAAO,KAAK,eAAe,CAAC,CAAC,SAAS,GAC3D,8BAA8B,UAAU,eAAe;EAGzD,OAAO;CACT,SAAS,OAAO;EACd,IAAI;GACF,IAAI,gBAAgB,MAAM,eAAe;QACpC,SAAS,MAAM;EACtB,SAAS,cAAc;GACrB,MAAM,IAAI,eACR,CAAC,OAAO,YAAY,GACpB,iDACF;EACF;EACA,MAAM;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"sqlite-native-FrjMCnBh.js","names":[],"sources":["../../src/sqlite-native.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { DatabaseError } from '@happyvertical/utils';\nimport { DatabaseSchemaManager } from './schema-manager.js';\nimport {\n generateAddColumnStatement,\n generateCreateIndexStatement,\n validateColumnName,\n validateColumnNames,\n validateIndexName,\n validateTableName,\n} from './shared/alter-utils.js';\nimport { getCachedSqliteDatabase } from './shared/sqlite-connection-cache.js';\nimport { createTransactionLock } from './shared/transaction-lock.js';\nimport type {\n ColumnDefinition,\n ColumnDefinitionWithName,\n DatabaseInterface,\n IndexDefinition,\n NotificationCapabilities,\n NotificationListenOptions,\n NotificationPruneOptions,\n NotificationWaitOptions,\n QueryResult,\n SchemaInitializationOptions,\n SchemaProvider,\n SqliteNotificationCapabilityOptions,\n SqliteVectorCapabilityOptions,\n TableInterface,\n TableSchemaInfo,\n TransactionHandle,\n UpsertOptions,\n VectorCapabilities,\n VectorIndexOptions,\n VectorSearchOptions,\n VectorSearchResult,\n WhereClause,\n} from './shared/types.js';\nimport { NestedTransactionError, resolveSchemas } from './shared/types.js';\nimport {\n buildWhere,\n formatDbError,\n resolveInsertColumns,\n wrapDatabaseError,\n} from './shared/utils.js';\nimport type { SqliteOptions } from './sqlite.js';\n\ntype NativeDatabase = any;\ntype NativeStatement = any;\ntype NativeCloseable = { close?: () => void };\n\n/** @internal Best-effort, retryable closer used by native SQLite. */\nexport function createNativeSqliteCloser(\n notificationCloseables: Set<NativeCloseable>,\n honkerDb: NativeCloseable | null,\n database: { close(): void },\n): () => Promise<void> {\n const completed = new Set<object>();\n let active: Promise<void> | undefined;\n return async () => {\n active ??= (async () => {\n const resources: NativeCloseable[] = [\n ...notificationCloseables,\n ...(honkerDb ? [honkerDb] : []),\n database,\n ];\n const errors: unknown[] = [];\n for (const resource of resources) {\n if (completed.has(resource)) continue;\n try {\n resource.close?.();\n completed.add(resource);\n notificationCloseables.delete(resource);\n } catch (error) {\n errors.push(error);\n }\n }\n if (errors.length === 1) throw errors[0];\n if (errors.length > 1) {\n throw new AggregateError(\n errors,\n 'Failed to close native SQLite resources',\n );\n }\n })();\n try {\n await active;\n } finally {\n active = undefined;\n }\n };\n}\n\nconst nativeNullAwareUpsertLocks = new Map<string, Promise<void>>();\nlet nodeSqliteModulePromise: Promise<any> | null = null;\n// sqlite-vector's ESM wrapper uses dynamic require for platform packages.\nconst requireOptionalPackage = createRequire(import.meta.url);\n\ninterface NativeSqliteLocation {\n location: string;\n filePath: string | null;\n isMemory: boolean;\n}\n\ninterface NativeQueryResult {\n rows: Record<string, any>[];\n rowCount: number;\n command?: string;\n fields?: Array<{ name: string }>;\n}\n\nfunction getCapabilityOptions<T extends Record<string, any>>(\n value: boolean | T | undefined,\n): T {\n return typeof value === 'object' && value ? value : ({} as T);\n}\n\nfunction resolveNativeLocation(url = ':memory:'): NativeSqliteLocation {\n if (\n url.startsWith('libsql://') ||\n url.startsWith('http://') ||\n url.startsWith('https://')\n ) {\n throw new DatabaseError(\n 'SQLite native capabilities are only supported for local SQLite databases',\n {\n url,\n hint: \"Use a local file path, 'file:...' URL, or ':memory:' when enabling SQLite capabilities.\",\n },\n );\n }\n\n if (url === ':memory:' || url.startsWith('file::memory:')) {\n return { location: url, filePath: null, isMemory: true };\n }\n\n if (url.startsWith('file://')) {\n const filePath = fileURLToPath(new URL(url));\n return { location: filePath, filePath, isMemory: false };\n }\n\n if (url.startsWith('file:')) {\n const path = url.slice('file:'.length);\n if (!path || path.includes('?')) {\n throw new DatabaseError(\n 'SQLite native capabilities do not support file: URLs with query parameters',\n { url },\n );\n }\n const filePath = resolve(path);\n return { location: filePath, filePath, isMemory: false };\n }\n\n const filePath = resolve(url);\n return { location: filePath, filePath, isMemory: false };\n}\n\nasync function loadNodeSqlite(): Promise<any> {\n nodeSqliteModulePromise ??= importNodeSqlite().catch((error) => {\n nodeSqliteModulePromise = null;\n throw error;\n });\n return nodeSqliteModulePromise;\n}\n\nasync function importNodeSqlite(): Promise<any> {\n const originalEmitWarning = process.emitWarning;\n\n try {\n process.emitWarning = function suppressNodeSqliteExperimentalWarning(\n warning: string | Error,\n ...args: any[]\n ) {\n if (\n args[0] === 'ExperimentalWarning' &&\n String(warning).includes('SQLite is an experimental feature')\n ) {\n return;\n }\n\n return originalEmitWarning.call(process, warning as any, ...args);\n } as typeof process.emitWarning;\n\n const moduleName = 'node:sqlite';\n return (await import(/* @vite-ignore */ moduleName)) as any;\n } catch (error) {\n throw new DatabaseError('Node native SQLite is not available', {\n originalError: formatDbError(error),\n hint: 'SQLite native capabilities require a Node.js runtime with node:sqlite support.',\n });\n } finally {\n process.emitWarning = originalEmitWarning;\n }\n}\n\nasync function loadSqliteVectorExtension(\n database: NativeDatabase,\n): Promise<void> {\n try {\n const moduleName = '@sqliteai/sqlite-vector';\n const module = requireOptionalPackage(moduleName) as any;\n const getExtensionPath =\n module.getExtensionPath ?? module.default?.getExtensionPath;\n\n if (typeof getExtensionPath !== 'function') {\n throw new Error('getExtensionPath export was not found');\n }\n\n database.enableLoadExtension(true);\n database.loadExtension(getExtensionPath());\n } catch (error) {\n throw new DatabaseError(\n 'Failed to load optional SQLite vector capability: install @sqliteai/sqlite-vector',\n {\n packageName: '@sqliteai/sqlite-vector',\n originalError: formatDbError(error),\n hint: 'Install @sqliteai/sqlite-vector to use SQLite vector capabilities.',\n },\n );\n } finally {\n try {\n database.enableLoadExtension(false);\n } catch (_error) {\n // Leave the original extension-loading failure intact.\n }\n }\n}\n\nasync function openHonkerDatabase(\n filePath: string,\n options: SqliteNotificationCapabilityOptions,\n): Promise<any> {\n try {\n const moduleName = '@russellthehippo/honker-node';\n const module = requireOptionalPackage(moduleName) as any;\n const open = module.open ?? module.default?.open;\n\n if (typeof open !== 'function') {\n throw new Error('open export was not found');\n }\n\n return open(filePath, options.maxReaders, options.watcherBackend);\n } catch (error) {\n throw new DatabaseError(\n 'Failed to load optional SQLite notification capability: install @russellthehippo/honker-node',\n {\n packageName: '@russellthehippo/honker-node',\n originalError: formatDbError(error),\n hint: 'Install @russellthehippo/honker-node to use SQLite notification capabilities.',\n },\n );\n }\n}\n\nfunction toPlainRow(row: Record<string, any>): Record<string, any> {\n return Object.fromEntries(Object.entries(row));\n}\n\nfunction getErrorMessage(error: unknown): string | undefined {\n return error instanceof Error ? error.message : undefined;\n}\n\nfunction firstSqlToken(sql: string): string {\n return sql.trim().split(/\\s+/)[0]?.toUpperCase() ?? '';\n}\n\nfunction normalizeNativeQuery(\n sql: string,\n values: any[],\n): { sql: string; args: any[] } {\n const flatArgs = Array.isArray(values[0]) ? values[0] : values;\n const parameterIndexes = Array.from(sql.matchAll(/\\$(\\d+)/g)).map((match) =>\n Number(match[1]),\n );\n\n if (parameterIndexes.length === 0) {\n return { sql, args: flatArgs };\n }\n\n const args = parameterIndexes.map((index) => flatArgs[index - 1]);\n return { sql: sql.replace(/\\$(\\d+)/g, '?'), args };\n}\n\nfunction executeNativeQuery(\n database: NativeDatabase,\n sql: string,\n args: any[] = [],\n): NativeQueryResult {\n const statement: NativeStatement = database.prepare(sql);\n const columns = statement.columns();\n\n if (columns.length > 0) {\n const rows = statement.all(...args).map(toPlainRow);\n return {\n rows,\n rowCount: rows.length,\n command: firstSqlToken(sql),\n fields: columns.map((column: { name: string }) => ({\n name: column.name,\n })),\n };\n }\n\n const result = statement.run(...args);\n return {\n rows: [],\n rowCount: Number(result?.changes ?? 0),\n command: firstSqlToken(sql),\n fields: [],\n };\n}\n\nfunction createNativeTablesFromSchemas(\n database: NativeDatabase,\n schemas: Record<string, SchemaProvider>,\n): void {\n for (const [tableName, schema] of Object.entries(schemas)) {\n try {\n const result = executeNativeQuery(\n database,\n \"SELECT name FROM sqlite_master WHERE type='table' AND name=?\",\n [tableName],\n );\n\n if (result.rows.length > 0) {\n continue;\n }\n\n database.exec(schema.ddl);\n\n for (const indexSql of schema.indexes ?? []) {\n try {\n database.exec(indexSql);\n } catch (error) {\n console.warn(\n `[sqlite] Failed to create index for ${tableName}: ${formatDbError(error)}`,\n );\n }\n }\n\n for (const triggerSql of schema.triggers ?? []) {\n try {\n database.exec(triggerSql);\n } catch (error) {\n console.warn(\n `[sqlite] Failed to create trigger for ${tableName}: ${formatDbError(error)}`,\n );\n }\n }\n } catch (error) {\n throw new DatabaseError(\n `Failed to create table ${tableName} from schema`,\n {\n tableName,\n schema,\n originalError: formatDbError(error),\n },\n );\n }\n }\n}\n\nfunction quoteIdentifier(identifier: string): string {\n return `\"${identifier.replace(/\"/g, '\"\"')}\"`;\n}\n\nfunction buildQuestionWhere(where: WhereClause, startIndex = 1) {\n const built = buildWhere(where, startIndex, 'sqlite');\n return {\n sql: built.sql.replace(/\\$(\\d+)/g, '?'),\n values: built.values,\n };\n}\n\nfunction serializeValue(value: any): any {\n if (value === null || value === undefined) {\n return value;\n }\n if (value instanceof Date) {\n return value.toISOString();\n }\n if (typeof value === 'object') {\n return JSON.stringify(value);\n }\n return value;\n}\n\nfunction serializeRecord(record: Record<string, any>): Record<string, any> {\n const serialized: Record<string, any> = {};\n for (const [key, value] of Object.entries(record)) {\n if (value === undefined) {\n continue;\n }\n serialized[key] = serializeValue(value);\n }\n return serialized;\n}\n\nasync function withNativeNullAwareUpsertLock<T>(\n lockKey: string,\n callback: () => Promise<T>,\n): Promise<T> {\n const previous = nativeNullAwareUpsertLocks.get(lockKey) ?? Promise.resolve();\n let release: () => void = () => {};\n const current = new Promise<void>((resolve) => {\n release = resolve;\n });\n const next = previous.catch(() => {}).then(() => current);\n\n nativeNullAwareUpsertLocks.set(lockKey, next);\n await previous.catch(() => {});\n\n try {\n return await callback();\n } finally {\n release();\n if (nativeNullAwareUpsertLocks.get(lockKey) === next) {\n nativeNullAwareUpsertLocks.delete(lockKey);\n }\n }\n}\n\nfunction sqliteVectorDistance(metric: 'cosine' | 'l2' | 'ip'): string {\n switch (metric) {\n case 'l2':\n return 'L2';\n case 'ip':\n return 'DOT';\n default:\n return 'COSINE';\n }\n}\n\nfunction sqliteVectorQuantization(\n options: SqliteVectorCapabilityOptions,\n): string {\n const parts: string[] = [];\n\n switch (options.quantization ?? 'turbo4') {\n case 'turbo2':\n parts.push('qtype=TURBO,qbits=2');\n break;\n case 'turbo3':\n parts.push('qtype=TURBO,qbits=3');\n break;\n case 'turbo4':\n parts.push('qtype=TURBO,qbits=4');\n break;\n case 'uint8':\n parts.push('qtype=UINT8');\n break;\n case 'int8':\n parts.push('qtype=INT8');\n break;\n case '1bit':\n parts.push('qtype=1BIT');\n break;\n }\n\n if (options.maxMemory) {\n parts.push(`max_memory=${options.maxMemory}`);\n }\n\n return parts.join(',');\n}\n\nfunction createNotificationCapabilities(\n honkerDb: any,\n closeables: Set<{ close?: () => void }>,\n): NotificationCapabilities {\n return {\n async notify(channel: string, payload: any): Promise<number> {\n return Number(honkerDb.notify(channel, payload));\n },\n\n listen(channel: string, options?: NotificationListenOptions) {\n const listener = honkerDb.listen(channel, {\n fallbackPollS:\n options?.fallbackPollMs === null\n ? null\n : options?.fallbackPollMs !== undefined\n ? options.fallbackPollMs / 1000\n : undefined,\n });\n closeables.add(listener);\n return listener;\n },\n\n async waitForUpdate(options?: NotificationWaitOptions): Promise<boolean> {\n const updateEvents = honkerDb.updateEvents();\n closeables.add(updateEvents);\n let timeout: NodeJS.Timeout | undefined;\n let removeAbortListener: (() => void) | undefined;\n\n try {\n if (options?.signal?.aborted) {\n return false;\n }\n\n const updatePromise = updateEvents.next().then(\n () => true,\n () => false,\n );\n const races: Array<Promise<boolean>> = [updatePromise];\n\n if (options?.timeoutMs !== undefined) {\n const timeoutMs = options.timeoutMs;\n races.push(\n new Promise((resolve) => {\n timeout = setTimeout(\n () => resolve(false),\n Math.max(0, timeoutMs),\n );\n }),\n );\n }\n\n if (options?.signal) {\n races.push(\n new Promise((resolve) => {\n const onAbort = () => resolve(false);\n options.signal?.addEventListener('abort', onAbort, {\n once: true,\n });\n removeAbortListener = () =>\n options.signal?.removeEventListener('abort', onAbort);\n }),\n );\n }\n\n return await Promise.race(races);\n } finally {\n if (timeout) {\n clearTimeout(timeout);\n }\n removeAbortListener?.();\n closeables.delete(updateEvents);\n updateEvents.close?.();\n }\n },\n\n async prune(options?: NotificationPruneOptions): Promise<number> {\n return Number(\n honkerDb.pruneNotifications(options?.olderThanS, options?.maxKeep),\n );\n },\n };\n}\n\nfunction createVectorCapabilities(\n database: NativeDatabase,\n options: SqliteVectorCapabilityOptions,\n): VectorCapabilities {\n const initialized = new Map<\n string,\n { dimensions: number; metric: 'cosine' | 'l2' | 'ip' }\n >();\n const indexed = new Map<\n string,\n { metric: 'cosine' | 'l2' | 'ip'; options: SqliteVectorCapabilityOptions }\n >();\n\n const keyFor = (table: string, column: string) => `${table}.${column}`;\n\n const columnExists = (table: string, column: string): boolean => {\n const rows = database\n .prepare(`PRAGMA table_info(${quoteIdentifier(table)})`)\n .all()\n .map(toPlainRow);\n return rows.some((row: Record<string, any>) => row.name === column);\n };\n\n const ensureInitialized = (\n table: string,\n column: string,\n dimensions: number,\n metric: 'cosine' | 'l2' | 'ip' = 'cosine',\n ): void => {\n if (!Number.isInteger(dimensions) || dimensions <= 0) {\n throw new DatabaseError('Vector dimensions must be a positive integer', {\n dimensions,\n });\n }\n\n validateTableName(table);\n validateColumnName(column);\n\n executeNativeQuery(database, 'SELECT vector_init(?, ?, ?)', [\n table,\n column,\n `dimension=${dimensions},type=FLOAT32,distance=${sqliteVectorDistance(metric)}`,\n ]);\n initialized.set(keyFor(table, column), { dimensions, metric });\n };\n\n const quantize = (\n table: string,\n column: string,\n vectorOptions: SqliteVectorCapabilityOptions,\n ): void => {\n const quantizationOptions = sqliteVectorQuantization(vectorOptions);\n if (quantizationOptions) {\n executeNativeQuery(database, 'SELECT vector_quantize(?, ?, ?)', [\n table,\n column,\n quantizationOptions,\n ]);\n } else {\n executeNativeQuery(database, 'SELECT vector_quantize(?, ?)', [\n table,\n column,\n ]);\n }\n\n if (vectorOptions.preload) {\n executeNativeQuery(database, 'SELECT vector_quantize_preload(?, ?)', [\n table,\n column,\n ]);\n }\n };\n\n return {\n async ensureColumn(\n table: string,\n column: string,\n dimensions: number,\n ): Promise<void> {\n validateTableName(table);\n validateColumnName(column);\n\n try {\n if (!columnExists(table, column)) {\n executeNativeQuery(\n database,\n `ALTER TABLE ${quoteIdentifier(table)} ADD COLUMN ${quoteIdentifier(column)} BLOB`,\n );\n }\n ensureInitialized(table, column, dimensions, 'cosine');\n } catch (error) {\n throw new DatabaseError('Failed to ensure SQLite vector column', {\n table,\n column,\n dimensions,\n originalError: formatDbError(error),\n });\n }\n },\n\n async ensureIndex(\n table: string,\n column: string,\n indexOptions?: VectorIndexOptions,\n ): Promise<void> {\n validateTableName(table);\n validateColumnName(column);\n\n const key = keyFor(table, column);\n const dimensions =\n indexOptions?.dimensions ?? initialized.get(key)?.dimensions;\n if (!dimensions) {\n throw new DatabaseError(\n 'SQLite vector index creation requires dimensions',\n {\n table,\n column,\n hint: 'Call ensureColumn(table, column, dimensions) first or pass dimensions to ensureIndex().',\n },\n );\n }\n\n const metric = indexOptions?.metric ?? 'cosine';\n\n try {\n ensureInitialized(table, column, dimensions, metric);\n const vectorOptions = { ...options };\n quantize(table, column, vectorOptions);\n indexed.set(key, { metric, options: vectorOptions });\n } catch (error) {\n throw new DatabaseError('Failed to ensure SQLite vector index', {\n table,\n column,\n originalError: formatDbError(error),\n });\n }\n },\n\n async upsertVector(\n table: string,\n where: Record<string, any>,\n column: string,\n embedding: number[],\n ): Promise<void> {\n validateTableName(table);\n validateColumnName(column);\n\n const key = keyFor(table, column);\n const dimensions = initialized.get(key)?.dimensions ?? embedding.length;\n const { sql: whereClause, values } = buildQuestionWhere(where);\n\n if (!whereClause) {\n throw new DatabaseError(\n 'SQLite vector update requires at least one WHERE condition',\n { table, column },\n );\n }\n\n try {\n ensureInitialized(\n table,\n column,\n dimensions,\n initialized.get(key)?.metric ?? 'cosine',\n );\n executeNativeQuery(\n database,\n `UPDATE ${quoteIdentifier(table)} SET ${quoteIdentifier(column)} = vector_as_f32(?) ${whereClause}`,\n [JSON.stringify(embedding), ...values],\n );\n\n const indexState = indexed.get(key);\n if (indexState) {\n quantize(table, column, indexState.options);\n }\n } catch (error) {\n throw new DatabaseError('Failed to upsert SQLite vector', {\n table,\n column,\n where,\n originalError: formatDbError(error),\n });\n }\n },\n\n async search(\n table: string,\n column: string,\n embedding: number[],\n searchOptions?: VectorSearchOptions,\n ): Promise<VectorSearchResult[]> {\n validateTableName(table);\n validateColumnName(column);\n\n const key = keyFor(table, column);\n const metric = searchOptions?.metric ?? 'cosine';\n const limit = searchOptions?.limit ?? 10;\n const limitArg = BigInt(limit);\n const dimensions = initialized.get(key)?.dimensions ?? embedding.length;\n const indexState = indexed.get(key);\n const useQuantizedScan = indexState?.metric === metric;\n const scanFunction = useQuantizedScan\n ? 'vector_quantize_scan'\n : 'vector_full_scan';\n const convertedWhere = searchOptions?.where\n ? searchOptions.where.replace(/\\$(\\d+)/g, '?')\n : '';\n const whereParams = searchOptions?.params ?? [];\n\n try {\n ensureInitialized(table, column, dimensions, metric);\n\n const rows = convertedWhere\n ? executeNativeQuery(\n database,\n `SELECT base.*, base.rowid AS __sqlite_rowid, vec.distance\n FROM ${scanFunction}(?, ?, vector_as_f32(?)) AS vec\n JOIN ${quoteIdentifier(table)} AS base ON base.rowid = vec.rowid\n WHERE (${convertedWhere})\n ORDER BY vec.distance\n LIMIT ?`,\n [\n table,\n column,\n JSON.stringify(embedding),\n ...whereParams,\n limitArg,\n ],\n ).rows\n : executeNativeQuery(\n database,\n `SELECT base.*, base.rowid AS __sqlite_rowid, vec.distance\n FROM ${scanFunction}(?, ?, vector_as_f32(?), ?) AS vec\n JOIN ${quoteIdentifier(table)} AS base ON base.rowid = vec.rowid\n ORDER BY vec.distance`,\n [table, column, JSON.stringify(embedding), limitArg],\n ).rows;\n\n return rows.map((row) => {\n const { __sqlite_rowid: rowid, ...result } = row;\n return {\n ...result,\n id: String(result.id ?? rowid),\n distance: Number(row.distance),\n };\n });\n } catch (error) {\n throw new DatabaseError('Failed to execute SQLite vector search', {\n table,\n column,\n metric,\n limit,\n originalError: formatDbError(error),\n });\n }\n },\n };\n}\n\nexport async function getNativeSqliteDatabase(\n options: SqliteOptions = {},\n): Promise<DatabaseInterface> {\n const url = options.url || ':memory:';\n\n return getCachedSqliteDatabase('native', options, () =>\n createNativeSqliteDatabase(options, url),\n );\n}\n\nasync function createNativeSqliteDatabase(\n options: SqliteOptions,\n url: string,\n): Promise<DatabaseInterface> {\n const location = resolveNativeLocation(url);\n const notificationsOptions = getCapabilityOptions(\n options.capabilities?.notifications,\n );\n const vectorOptions = getCapabilityOptions(options.capabilities?.vector);\n const wantsNotifications = Boolean(options.capabilities?.notifications);\n const wantsVector = Boolean(options.capabilities?.vector);\n\n if (wantsNotifications && location.isMemory) {\n throw new DatabaseError(\n 'SQLite notification capabilities require a file-backed database',\n {\n url,\n hint: 'Use a temporary file-backed .db for development and tests that need notifications.',\n },\n );\n }\n\n const { DatabaseSync } = await loadNodeSqlite();\n const database = new DatabaseSync(location.location, {\n allowExtension: wantsVector,\n });\n\n // One lock per connection. `getNativeSqliteDatabase` hands cached callers\n // this same closure, so \"created here\" and \"per connection\" are the same\n // scope.\n const connectionLock = createTransactionLock(\n 'sqlite (native)',\n options.transactionQueueTimeout,\n );\n let closeResources: (() => Promise<void>) | undefined;\n\n try {\n if (wantsVector) {\n await loadSqliteVectorExtension(database);\n }\n\n const honkerDb =\n wantsNotifications && location.filePath\n ? await openHonkerDatabase(location.filePath, notificationsOptions)\n : null;\n const notificationCloseables = new Set<{ close?: () => void }>();\n\n const vectorCapabilities = wantsVector\n ? createVectorCapabilities(database, vectorOptions)\n : undefined;\n const notificationCapabilities = honkerDb\n ? createNotificationCapabilities(honkerDb, notificationCloseables)\n : undefined;\n\n const query = async (\n sql: string,\n ...values: any[]\n ): Promise<{ rows: Record<string, any>[]; rowCount: number }> => {\n const normalized = normalizeNativeQuery(sql, values);\n try {\n const result = executeNativeQuery(\n database,\n normalized.sql,\n normalized.args,\n );\n return { rows: result.rows, rowCount: result.rowCount };\n } catch (error) {\n throw wrapDatabaseError('Failed to execute raw query', error, {\n sql: normalized.sql,\n values: normalized.args,\n });\n }\n };\n\n const parseTemplate = (strings: TemplateStringsArray, ...vars: any[]) => {\n let sql = strings[0];\n const values = [];\n for (let i = 0; i < vars.length; i++) {\n values.push(vars[i]);\n sql += `?${strings[i + 1]}`;\n }\n return { sql, values };\n };\n\n const insert = async (\n table: string,\n data: Record<string, any> | Record<string, any>[],\n ): Promise<QueryResult> => {\n validateTableName(table);\n const records = (Array.isArray(data) ? data : [data]).map(\n serializeRecord,\n );\n if (records.length === 0) {\n return { operation: 'insert', affected: 0 };\n }\n const keys = resolveInsertColumns(table, records);\n validateColumnNames(keys);\n const placeholders = records\n .map(() => `(${keys.map(() => '?').join(', ')})`)\n .join(', ');\n const values = records.flatMap((record) =>\n keys.map((key) => record[key]),\n );\n const sql = `INSERT INTO ${table} (${keys.join(', ')}) VALUES ${placeholders}`;\n\n try {\n const result = executeNativeQuery(database, sql, values);\n return { operation: 'insert', affected: result.rowCount };\n } catch (error) {\n throw new DatabaseError('Failed to insert records into table', {\n table,\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const get = async (\n table: string,\n where: WhereClause,\n ): Promise<Record<string, any> | null> => {\n validateTableName(table);\n const { sql: whereClause, values } = buildQuestionWhere(where);\n if (!whereClause) {\n throw new DatabaseError(\n 'GET requires at least one WHERE condition to prevent returning an arbitrary record',\n { table },\n );\n }\n\n const sql = `SELECT * FROM ${table} ${whereClause}`;\n try {\n const result = executeNativeQuery(database, sql, values);\n return result.rows[0] || null;\n } catch (error) {\n throw new DatabaseError('Failed to retrieve record from table', {\n table,\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const list = async (\n table: string,\n where: WhereClause,\n ): Promise<Record<string, any>[]> => {\n validateTableName(table);\n const { sql: whereClause, values } = buildQuestionWhere(where);\n const sql = `SELECT * FROM ${table} ${whereClause}`;\n try {\n return executeNativeQuery(database, sql, values).rows;\n } catch (error) {\n throw new DatabaseError('Failed to list records from table', {\n table,\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const update = async (\n table: string,\n where: WhereClause,\n data: Record<string, any>,\n ): Promise<QueryResult> => {\n validateTableName(table);\n const serializedData = serializeRecord(data);\n const keys = Object.keys(serializedData);\n validateColumnNames(keys);\n const values = Object.values(serializedData);\n const setClause = keys.map((key) => `${key} = ?`).join(', ');\n const { sql: whereClause, values: whereValues } =\n buildQuestionWhere(where);\n\n if (!whereClause) {\n throw new DatabaseError(\n 'UPDATE requires at least one WHERE condition to prevent accidental update of all records',\n { table },\n );\n }\n\n const sql = `UPDATE ${table} SET ${setClause} ${whereClause}`;\n try {\n const result = executeNativeQuery(database, sql, [\n ...values,\n ...whereValues,\n ]);\n return { operation: 'update', affected: result.rowCount };\n } catch (error) {\n throw new DatabaseError('Failed to update records in table', {\n table,\n sql,\n values: [...values, ...whereValues],\n originalError: formatDbError(error),\n });\n }\n };\n\n const hasNullConflictValue = (\n conflictColumns: string[],\n data: Record<string, any>,\n ): boolean => conflictColumns.some((column) => data[column] === null);\n\n const validateUpsertConflictColumns = (\n table: string,\n conflictColumns: string[],\n serializedData: Record<string, any>,\n ): void => {\n const missingColumns = conflictColumns.filter(\n (column) => !(column in serializedData),\n );\n\n if (missingColumns.length > 0) {\n throw new DatabaseError('Conflict columns missing from data', {\n table,\n conflictColumns,\n missingColumns,\n availableColumns: Object.keys(serializedData),\n hint: 'All columns specified in ON CONFLICT must be present in the data being inserted. Undefined values are filtered out during serialization - consider using null or an empty string instead.',\n });\n }\n };\n\n const executeStandardUpsert = (\n table: string,\n conflictColumns: string[],\n serializedData: Record<string, any>,\n ): QueryResult => {\n const keys = Object.keys(serializedData);\n const values = Object.values(serializedData);\n const placeholders = keys.map(() => '?').join(', ');\n const updateSet = keys\n .map((key) => `${key} = excluded.${key}`)\n .join(', ');\n const conflict = conflictColumns.join(', ');\n const sql = `INSERT INTO ${table} (${keys.join(', ')}) VALUES (${placeholders}) ON CONFLICT(${conflict}) DO UPDATE SET ${updateSet}`;\n const result = executeNativeQuery(database, sql, values);\n return { operation: 'upsert', affected: result.rowCount };\n };\n\n const executeNullAwareUpsertAttempt = (\n table: string,\n conflictColumns: string[],\n serializedData: Record<string, any>,\n ): QueryResult => {\n const keys = Object.keys(serializedData);\n const values = Object.values(serializedData);\n const updateSet = keys.map((key) => `${key} = ?`).join(', ');\n const whereClause = conflictColumns\n .map((column) => `${column} IS ?`)\n .join(' AND ');\n const whereValues = conflictColumns.map(\n (column) => serializedData[column],\n );\n\n const updateResult = executeNativeQuery(\n database,\n `UPDATE ${table} SET ${updateSet} WHERE ${whereClause}`,\n [...values, ...whereValues],\n );\n\n if (updateResult.rowCount > 0) {\n return { operation: 'upsert', affected: updateResult.rowCount };\n }\n\n const placeholders = keys.map(() => '?').join(', ');\n const insertResult = executeNativeQuery(\n database,\n `INSERT INTO ${table} (${keys.join(', ')}) VALUES (${placeholders})`,\n values,\n );\n\n return { operation: 'upsert', affected: insertResult.rowCount };\n };\n\n /**\n * Rejects hostile table/column identifiers before an upsert builds SQL.\n *\n * Called from the public entry points rather than from `executeUpsert`, so\n * the failure reaches the caller naming the bad identifier instead of being\n * flattened into the wrapper's generic \"Failed to upsert record into table\".\n *\n * Validates the keys of the already-serialized snapshot — the exact array\n * the executors interpolate — not a fresh enumeration of the caller's\n * `data`. Enumerating `data` again could disagree with the snapshot if it is\n * a Proxy whose `ownKeys` trap returns different keys on successive reads.\n */\n const validateUpsertIdentifiers = (\n table: string,\n conflictColumns: string[],\n serializedData: Record<string, any>,\n ): void => {\n validateTableName(table);\n validateColumnNames([...conflictColumns, ...Object.keys(serializedData)]);\n };\n\n const executeUpsert = async (\n table: string,\n conflictColumns: string[],\n serializedData: Record<string, any>,\n upsertOptions: UpsertOptions | undefined,\n acquireTransaction: boolean,\n ): Promise<QueryResult> => {\n validateUpsertConflictColumns(table, conflictColumns, serializedData);\n\n if (\n upsertOptions?.nullsDistinct ||\n !hasNullConflictValue(conflictColumns, serializedData)\n ) {\n return executeStandardUpsert(table, conflictColumns, serializedData);\n }\n\n if (!acquireTransaction) {\n return executeNullAwareUpsertAttempt(\n table,\n conflictColumns,\n serializedData,\n );\n }\n\n const lockKey = `${location.location}:${table}:${conflictColumns\n .map((column) => `${column}:${JSON.stringify(serializedData[column])}`)\n .join('|')}`;\n\n return withNativeNullAwareUpsertLock(lockKey, async () => {\n // This opens a transaction on the shared connection like any other, so\n // it takes the same lock — otherwise a null-aware upsert overlapping a\n // `transaction()` call reintroduces exactly the corruption the lock\n // exists to prevent.\n const releaseConnection = await connectionLock.acquire();\n try {\n database.exec('BEGIN IMMEDIATE');\n const result = executeNullAwareUpsertAttempt(\n table,\n conflictColumns,\n serializedData,\n );\n database.exec('COMMIT');\n return result;\n } catch (error) {\n try {\n database.exec('ROLLBACK');\n } catch (_rollbackError) {\n // Preserve the original failure.\n }\n throw error;\n } finally {\n releaseConnection();\n }\n });\n };\n\n const upsert = async (\n table: string,\n conflictColumns: string[],\n data: Record<string, any>,\n upsertOptions?: UpsertOptions,\n ): Promise<QueryResult> => {\n // Snapshot the record and the conflict columns once and thread both\n // through validation and SQL, so neither a hostile record nor a hostile\n // conflict-column array can present different identifiers to each.\n const serializedData = serializeRecord(data);\n const conflictCols = [...conflictColumns];\n validateUpsertIdentifiers(table, conflictCols, serializedData);\n try {\n return await executeUpsert(\n table,\n conflictCols,\n serializedData,\n upsertOptions,\n true,\n );\n } catch (error) {\n if (getErrorMessage(error) === 'Conflict columns missing from data') {\n throw error;\n }\n throw new DatabaseError('Failed to upsert record into table', {\n table,\n values: data,\n conflictColumns,\n originalError: formatDbError(error),\n });\n }\n };\n\n const upsertInCurrentTransaction = (\n table: string,\n conflictColumns: string[],\n data: Record<string, any>,\n upsertOptions?: UpsertOptions,\n ): Promise<QueryResult> => {\n // Snapshot the record and the conflict columns once and thread both\n // through validation and SQL, so neither a hostile record nor a hostile\n // conflict-column array can present different identifiers to each.\n const serializedData = serializeRecord(data);\n const conflictCols = [...conflictColumns];\n validateUpsertIdentifiers(table, conflictCols, serializedData);\n return executeUpsert(\n table,\n conflictCols,\n serializedData,\n upsertOptions,\n false,\n );\n };\n\n const getOrInsert = async (\n table: string,\n where: WhereClause,\n data: Record<string, any>,\n ): Promise<Record<string, any>> => {\n const existing = await get(table, where);\n if (existing) return existing;\n await insert(table, data);\n const inserted = await get(table, where);\n if (!inserted) {\n throw new DatabaseError('Failed to insert and retrieve record', {\n table,\n where,\n data,\n });\n }\n return inserted;\n };\n\n const deleteRecords = async (\n table: string,\n where: WhereClause,\n ): Promise<QueryResult> => {\n validateTableName(table);\n const { sql: whereClause, values } = buildQuestionWhere(where);\n if (!whereClause) {\n throw new DatabaseError(\n 'DELETE requires at least one WHERE condition to prevent accidental deletion of all records',\n { table },\n );\n }\n\n try {\n const result = executeNativeQuery(\n database,\n `DELETE FROM ${table} ${whereClause}`,\n values,\n );\n return { operation: 'delete', affected: result.rowCount };\n } catch (error) {\n throw new DatabaseError('Failed to delete records from table', {\n table,\n where,\n originalError: formatDbError(error),\n });\n }\n };\n\n const count = async (\n table: string,\n where?: WhereClause,\n ): Promise<number> => {\n validateTableName(table);\n if (\n !where ||\n (typeof where === 'object' && Object.keys(where).length === 0)\n ) {\n const result = executeNativeQuery(\n database,\n `SELECT COUNT(*) as count FROM ${table}`,\n );\n return Number(result.rows[0]?.count) || 0;\n }\n\n const { sql: whereClause, values } = buildQuestionWhere(where);\n const result = executeNativeQuery(\n database,\n `SELECT COUNT(*) as count FROM ${table} ${whereClause}`,\n values,\n );\n return Number(result.rows[0]?.count) || 0;\n };\n\n const tableExists = async (tableName: string): Promise<boolean> => {\n const result = executeNativeQuery(\n database,\n \"SELECT name FROM sqlite_master WHERE type='table' AND name=?\",\n [tableName],\n );\n return result.rows.length > 0;\n };\n\n const syncSchema = async (schema: string): Promise<void> => {\n const commands = schema\n .replace(/\\s+/g, ' ')\n .replace(/DEFAULT CAST\\(([^)]+)\\s+AS\\s+\\w+\\)/gi, 'DEFAULT $1')\n .trim()\n .split(';')\n .map((command) => command.trim())\n .filter((command) => command.length > 0);\n\n for (const command of commands) {\n database.exec(command);\n }\n };\n\n const many = async (\n strings: TemplateStringsArray,\n ...vars: any[]\n ): Promise<Record<string, any>[]> => {\n const { sql, values } = parseTemplate(strings, ...vars);\n try {\n return executeNativeQuery(database, sql, values).rows;\n } catch (error) {\n throw new DatabaseError('Failed to execute many query', {\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const single = async (\n strings: TemplateStringsArray,\n ...vars: any[]\n ): Promise<Record<string, any> | null> => {\n const { sql, values } = parseTemplate(strings, ...vars);\n try {\n return executeNativeQuery(database, sql, values).rows[0] || null;\n } catch (error) {\n throw new DatabaseError('Failed to execute single query', {\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const pluck = async (\n strings: TemplateStringsArray,\n ...vars: any[]\n ): Promise<any> => {\n const { sql, values } = parseTemplate(strings, ...vars);\n try {\n const row = executeNativeQuery(database, sql, values).rows[0];\n return row ? Object.values(row)[0] : null;\n } catch (error) {\n throw new DatabaseError('Failed to execute pluck query', {\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const execute = async (\n strings: TemplateStringsArray,\n ...vars: any[]\n ): Promise<void> => {\n const { sql, values } = parseTemplate(strings, ...vars);\n try {\n if (values.length === 0) {\n database.exec(sql);\n return;\n }\n executeNativeQuery(database, sql, values);\n } catch (error) {\n throw new DatabaseError('Failed to execute query', {\n sql,\n values,\n originalError: formatDbError(error),\n });\n }\n };\n\n const oo = many;\n const oO = single;\n const ox = pluck;\n const xx = execute;\n\n const table = (tableName: string): TableInterface => ({\n insert: (data) => insert(tableName, data),\n get: (where) => get(tableName, where),\n list: (where) => list(tableName, where),\n });\n\n // Names nested savepoints. Only ever appended to an identifier the adapter\n // generates, never caller input.\n let savepointSequence = 0;\n\n /**\n * Re-enters the transaction already in progress under a savepoint.\n *\n * This is what the transaction-scoped interface exposes as `transaction`.\n * Handing it the top-level `transaction` instead — the previous behaviour —\n * sent a nested call into a second BEGIN on the one shared connection; that\n * throws, and the nested call's own ROLLBACK then discarded the *enclosing*\n * transaction's work while later writes committed in autocommit.\n */\n const nestedTransaction = async <T>(\n callback: (tx: DatabaseInterface) => Promise<T>,\n ): Promise<T> => {\n savepointSequence += 1;\n const name = `hv_sp_${savepointSequence}`;\n database.exec(`SAVEPOINT ${name}`);\n try {\n const result = await callback(\n buildDatabaseInterface(\n upsertInCurrentTransaction,\n nestedTransaction,\n refuseNestedBeginTransaction,\n ),\n );\n database.exec(`RELEASE SAVEPOINT ${name}`);\n return result;\n } catch (error) {\n try {\n // ROLLBACK TO leaves the savepoint defined, so release it too or it\n // accumulates for the life of the transaction.\n database.exec(`ROLLBACK TO SAVEPOINT ${name}`);\n database.exec(`RELEASE SAVEPOINT ${name}`);\n } catch {\n // The enclosing transaction is already unwinding; its teardown owns\n // the connection from here.\n }\n throw error;\n }\n };\n\n const transaction = async <T>(\n callback: (tx: DatabaseInterface) => Promise<T>,\n ): Promise<T> =>\n // Held across the whole BEGIN … COMMIT/ROLLBACK span. Without it two\n // overlapping calls raced on the one connection: the second BEGIN threw,\n // its catch ran ROLLBACK, and that rollback ended the *first*\n // transaction — half of its writes durable, half lost, and its promise\n // rejected, so the caller was told nothing had happened.\n connectionLock.run(async () => {\n try {\n database.exec('BEGIN TRANSACTION');\n const txDb = buildDatabaseInterface(\n upsertInCurrentTransaction,\n nestedTransaction,\n refuseNestedBeginTransaction,\n );\n const result = await callback(txDb);\n database.exec('COMMIT');\n return result;\n } catch (error) {\n // A failing ROLLBACK must not replace the caller's error: SQLite\n // reports \"cannot rollback - no transaction is active\" whenever the\n // transaction is already gone, which says nothing about what failed.\n try {\n database.exec('ROLLBACK');\n } catch {\n // Nothing left to roll back.\n }\n throw error;\n }\n });\n\n /**\n * The `beginTransaction` exposed on a transaction-scoped interface.\n *\n * Unlike `transaction`, a manual handle has no savepoint equivalent: it\n * would have to own the connection until the caller ends it, which the\n * enclosing transaction already does. Issuing a second BEGIN threw before\n * transactions were serialized; now it would instead wait on a lock its own\n * caller holds, so refuse explicitly rather than deadlock.\n */\n const refuseNestedBeginTransaction = async (): Promise<never> => {\n throw new NestedTransactionError(\n 'beginTransaction() cannot be called inside a transaction. Use the transaction you already have, or nest with transaction() to re-enter it under a savepoint.',\n { adapter: 'sqlite-native' },\n );\n };\n\n const beginTransaction = async (): Promise<TransactionHandle> => {\n // The handle owns the connection until the caller ends it, so the lock is\n // held across the gap rather than around a single call. A handle that is\n // never committed or rolled back therefore blocks every later transaction\n // until the queue timeout reports it.\n const releaseConnection = await connectionLock.acquire();\n try {\n database.exec('BEGIN TRANSACTION');\n } catch (error) {\n // No transaction was opened, so there is no handle to end it and\n // nothing left to release the connection.\n releaseConnection();\n throw error;\n }\n\n let active = true;\n\n // COMMIT and ROLLBACK can both throw, and the transaction is over either\n // way, so the connection goes back before the error is rethrown.\n const end = (command: 'COMMIT' | 'ROLLBACK'): void => {\n if (!active) {\n throw new DatabaseError('Transaction already ended', {});\n }\n try {\n database.exec(command);\n } catch (error) {\n // COMMIT can fail and leave the transaction *open* — SQLite documents\n // exactly that for SQLITE_BUSY. Releasing the connection then would hand\n // the next queued caller a connection still inside a transaction: its\n // BEGIN would throw, and its catch would ROLLBACK, discarding this\n // transaction's work. So normalize before releasing, the way the pooled\n // adapter's discardTxClient does.\n try {\n database.exec('ROLLBACK');\n } catch {\n // Already gone; nothing left to normalize.\n }\n throw error;\n } finally {\n active = false;\n releaseConnection();\n }\n };\n\n const commit = async (): Promise<void> => end('COMMIT');\n\n const rollback = async (): Promise<void> => end('ROLLBACK');\n\n return {\n // The handle is inside a transaction for the same reason a callback\n // scope is, so it re-enters via savepoint too.\n ...buildDatabaseInterface(\n upsertInCurrentTransaction,\n nestedTransaction,\n refuseNestedBeginTransaction,\n ),\n commit,\n rollback,\n isActive: () => active,\n };\n };\n\n const initializeSchemas = async (\n schemaOptions: SchemaInitializationOptions,\n ): Promise<void> => {\n const schemaManager = new DatabaseSchemaManager();\n await schemaManager.initializeSchemas(\n buildDatabaseInterface(upsert),\n schemaOptions,\n );\n };\n\n const getTableSchema = async (\n tableName: string,\n ): Promise<TableSchemaInfo | null> => {\n validateTableName(tableName);\n\n if (!(await tableExists(tableName))) {\n return null;\n }\n\n const columnRows = database\n .prepare(`PRAGMA table_info(${quoteIdentifier(tableName)})`)\n .all()\n .map(toPlainRow);\n\n const columns: Record<string, ColumnDefinition> = {};\n for (const row of columnRows) {\n columns[row.name as string] = {\n type: row.type as string,\n primaryKey: row.pk === 1,\n notNull: row.notnull === 1,\n defaultValue: row.dflt_value,\n };\n }\n\n const indexRows = executeNativeQuery(\n database,\n `SELECT name FROM sqlite_master\n WHERE type = 'index'\n AND tbl_name = ?\n AND name NOT LIKE 'sqlite_%'`,\n [tableName],\n ).rows;\n\n const indexes: IndexDefinition[] = [];\n for (const row of indexRows) {\n const indexName = row.name as string;\n const indexInfoRows = database\n .prepare(`PRAGMA index_info(${quoteIdentifier(indexName)})`)\n .all()\n .map(toPlainRow);\n const indexListRows = database\n .prepare(`PRAGMA index_list(${quoteIdentifier(tableName)})`)\n .all()\n .map(toPlainRow);\n\n indexes.push({\n name: indexName,\n columns: indexInfoRows.map((info: Record<string, any>) => info.name),\n unique: indexListRows.some(\n (info: Record<string, any>) =>\n info.name === indexName && info.unique === 1,\n ),\n });\n }\n\n const fkRows = database\n .prepare(`PRAGMA foreign_key_list(${quoteIdentifier(tableName)})`)\n .all()\n .map(toPlainRow);\n\n return {\n tableName,\n columns,\n indexes,\n foreignKeys: fkRows.map((row: Record<string, any>) => ({\n column: row.from as string,\n referencesTable: row.table as string,\n referencesColumn: row.to as string,\n onDelete: row.on_delete as string | undefined,\n onUpdate: row.on_update as string | undefined,\n })),\n };\n };\n\n const alterTable = {\n addColumn: async (\n tableName: string,\n column: ColumnDefinitionWithName,\n ): Promise<void> => {\n validateTableName(tableName);\n validateColumnName(column.name);\n let sql: string | undefined;\n try {\n sql = generateAddColumnStatement(tableName, column, 'sqlite');\n executeNativeQuery(database, sql);\n } catch (error) {\n throw wrapDatabaseError('Failed to add column to table', error, {\n table: tableName,\n column: column.name,\n ...(sql ? { sql } : {}),\n });\n }\n },\n\n addIndex: async (\n tableName: string,\n index: IndexDefinition,\n ): Promise<void> => {\n validateTableName(tableName);\n validateIndexName(index.name);\n for (const column of index.columns) {\n validateColumnName(column);\n }\n let sql: string | undefined;\n try {\n sql = generateCreateIndexStatement(tableName, index);\n executeNativeQuery(database, sql);\n } catch (error) {\n throw wrapDatabaseError('Failed to create index on table', error, {\n table: tableName,\n index: index.name,\n ...(sql ? { sql } : {}),\n });\n }\n },\n };\n\n const close = createNativeSqliteCloser(\n notificationCloseables,\n honkerDb,\n database,\n );\n closeResources = close;\n\n function buildDatabaseInterface(\n upsertImpl: DatabaseInterface['upsert'],\n transactionImpl: DatabaseInterface['transaction'] = transaction,\n beginTransactionImpl: DatabaseInterface['beginTransaction'] = beginTransaction,\n ): DatabaseInterface {\n return {\n url,\n client: database,\n query,\n insert,\n update,\n upsert: upsertImpl,\n get,\n list,\n getOrInsert,\n delete: deleteRecords,\n count,\n table,\n tableExists,\n many,\n single,\n pluck,\n execute,\n oo,\n oO,\n ox,\n xx,\n syncSchema,\n initializeSchemas,\n transaction: transactionImpl,\n beginTransaction: beginTransactionImpl,\n getTableSchema,\n alterTable,\n close,\n ...(vectorCapabilities ? { vector: vectorCapabilities } : {}),\n ...(notificationCapabilities\n ? { notifications: notificationCapabilities }\n : {}),\n };\n }\n\n const db = buildDatabaseInterface(upsert);\n const resolvedSchemas = resolveSchemas(options.schemas);\n if (resolvedSchemas && Object.keys(resolvedSchemas).length > 0) {\n createNativeTablesFromSchemas(database, resolvedSchemas);\n }\n\n return db;\n } catch (error) {\n try {\n if (closeResources) await closeResources();\n else database.close();\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n 'Native SQLite initialization and cleanup failed',\n );\n }\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;AAqDA,SAAgB,yBACd,wBACA,UACA,UACqB;CACrB,MAAM,4BAAY,IAAI,IAAY;CAClC,IAAI;CACJ,OAAO,YAAY;EACjB,YAAY,YAAY;GACtB,MAAM,YAA+B;IACnC,GAAG;IACH,GAAI,WAAW,CA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