@nextlyhq/adapter-sqlite 0.0.1
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/LICENSE +22 -0
- package/README.md +102 -0
- package/dist/index.cjs +572 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +288 -0
- package/dist/index.d.ts +288 -0
- package/dist/index.mjs +567 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["DrizzleAdapter","checkDialectVersion","createDatabaseError","drizzle","isDatabaseError"],"mappings":";;;;;;;;AAgGO,IAAM,OAAA,GAAU;AAOvB,IAAM,kBAAA,GAAwD;AAAA;AAAA,EAE5D,iBAAA,EAAmB,YAAA;AAAA,EACnB,wBAAA,EAA0B,kBAAA;AAAA,EAC1B,4BAAA,EAA8B,kBAAA;AAAA,EAC9B,4BAAA,EAA8B,uBAAA;AAAA,EAC9B,yBAAA,EAA2B,oBAAA;AAAA,EAC3B,uBAAA,EAAyB,iBAAA;AAAA;AAAA,EAGzB,WAAA,EAAa,SAAA;AAAA,EACb,aAAA,EAAe,SAAA;AAAA;AAAA,EAGf,eAAA,EAAiB,YAAA;AAAA,EACjB,aAAA,EAAe,YAAA;AAAA,EACf,cAAA,EAAgB,YAAA;AAAA;AAAA,EAGhB,YAAA,EAAc,OAAA;AAAA,EACd,aAAA,EAAe,OAAA;AAAA,EACf,YAAA,EAAc;AAChB,CAAA;AAKA,IAAM,cAAA,GAAiB;AAAA,EACrB,WAAA,EAAa,GAAA;AAAA,EACb,GAAA,EAAK,IAAA;AAAA,EACL,WAAA,EAAa;AACf,CAAA;AAMA,SAAS,oBAAoB,CAAA,EAAqB;AAChD,EAAA,IAAI,CAAA,KAAM,QAAW,OAAO,IAAA;AAC5B,EAAA,IAAI,OAAO,CAAA,KAAM,SAAA,EAAW,OAAO,IAAI,CAAA,GAAI,CAAA;AAC3C,E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AAI,GAAA,IAAO,SAAS,OAAA,EAAS;AAC3B,MAAA,OAAA,GAAU,iBAAiB,OAAO,CAAA,CAAA;AAAA,IACpC;AAEA,IAAA,OAAOF,yBAAA,CAAoB;AAAA,MACzB,IAAA;AAAA,MACA,OAAA;AAAA,MACA,MAAM,WAAA,CAAY,IAAA;AAAA,MAClB,KAAA,EAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,GAAQ;AAAA,KACzC,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKmB,gBAAA,CACjB,KAAA,EACA,SAAA,EACA,KAAA,EACe;AACf,IAAA,MAAM,OAAA,GAAU,IAAA,CAAK,aAAA,CAAc,KAAK,CAAA;AAGxC,IAAA,IAAI,CAAC,OAAA,CAAQ,OAAA,CAAQ,QAAA,CAAS,SAAS,CAAA,EAAG;AACxC,MAAA,OAAA,CAAQ,UAAU,CAAA,EAAG,SAAS,+BAA+B,KAAK,CAAA,GAAA,EAAM,QAAQ,OAAO,CAAA,CAAA;AAAA,IACzF;AAEA,IAAA,IAAI,CAAC,QAAQ,KAAA,EAAO;AAClB,MAAA,OAAA,CAAQ,KAAA,GAAQ,KAAA;AAAA,IAClB;AAEA,IAAA,OAAO,OAAA;AAAA,EACT;AACF;AAkCO,SAAS,oBACd,MAAA,EACe;AACf,EAAA,OAAO,IAAI,cAAc,MAAM,CAAA;AACjC;AAgBO,SAAS,gBAAgB,KAAA,EAAwC;AACtE,EAAA,OAAO,KAAA,YAAiB,aAAA;AAC1B","file":"index.cjs","sourcesContent":["/**\n * @nextlyhq/adapter-sqlite\n *\n * SQLite database adapter for Nextly.\n * Extends DrizzleAdapter from @nextlyhq/adapter-drizzle to provide SQLite-specific functionality.\n *\n * @remarks\n * This adapter uses the better-sqlite3 package for database connectivity and provides:\n * - Synchronous API wrapped for async interface compatibility\n * - Full transaction support with savepoints (via better-sqlite3's native transaction handling)\n * - CRUD operations with RETURNING clause support (SQLite 3.35+)\n * - WAL mode for better concurrent read performance\n * - In-memory and file-based database support\n *\n * @example\n * ```typescript\n * import { createSqliteAdapter } from '@nextlyhq/adapter-sqlite';\n *\n * const adapter = createSqliteAdapter({\n * url: 'file:./data/app.db',\n * });\n *\n * await adapter.connect();\n *\n * // Query data\n * const users = await adapter.select('users', {\n * where: { and: [{ column: 'status', op: '=', value: 'active' }] },\n * limit: 10,\n * });\n *\n * await adapter.disconnect();\n * ```\n *\n * @packageDocumentation\n */\n\nimport { DrizzleAdapter } from \"@nextlyhq/adapter-drizzle\";\n// F17: connect-time DB version check shared across all adapters.\nimport {\n createDatabaseError,\n isDatabaseError,\n type SqliteAdapterConfig,\n type DatabaseCapabilities,\n type PoolStats,\n type TransactionContext,\n type TransactionOptions,\n type SqlParam,\n type WhereClause,\n type WhereCondition,\n type WhereOperator,\n type SelectOptions,\n type InsertOptions,\n type UpdateOptions,\n type DeleteOptions,\n type UpsertOptions,\n type OrderBySpec,\n type JoinSpec,\n type DatabaseError,\n type DatabaseErrorKind,\n type BaseAdapterConfig,\n type AdapterLogger,\n} from \"@nextlyhq/adapter-drizzle/types\";\nimport { checkDialectVersion } from \"@nextlyhq/adapter-drizzle/version-check\";\nimport type Database from \"better-sqlite3\";\nimport {\n drizzle,\n type BetterSQLite3Database,\n} from \"drizzle-orm/better-sqlite3\";\n\n// Re-export types for convenience\nexport type {\n SqliteAdapterConfig,\n DatabaseCapabilities,\n PoolStats,\n TransactionContext,\n TransactionOptions,\n SqlParam,\n WhereClause,\n WhereCondition,\n WhereOperator,\n SelectOptions,\n InsertOptions,\n UpdateOptions,\n DeleteOptions,\n UpsertOptions,\n OrderBySpec,\n JoinSpec,\n DatabaseError,\n DatabaseErrorKind,\n BaseAdapterConfig,\n AdapterLogger,\n};\n\n/**\n * Package version\n */\nexport const VERSION = \"0.1.0\";\n\n/**\n * SQLite error codes mapping to DatabaseErrorKind.\n *\n * @see https://sqlite.org/rescode.html\n */\nconst SQLITE_ERROR_CODES: Record<string, DatabaseErrorKind> = {\n // Constraint violations\n SQLITE_CONSTRAINT: \"constraint\",\n SQLITE_CONSTRAINT_UNIQUE: \"unique_violation\",\n SQLITE_CONSTRAINT_PRIMARYKEY: \"unique_violation\",\n SQLITE_CONSTRAINT_FOREIGNKEY: \"foreign_key_violation\",\n SQLITE_CONSTRAINT_NOTNULL: \"not_null_violation\",\n SQLITE_CONSTRAINT_CHECK: \"check_violation\",\n\n // Busy/locked errors\n SQLITE_BUSY: \"timeout\",\n SQLITE_LOCKED: \"timeout\",\n\n // Connection errors\n SQLITE_CANTOPEN: \"connection\",\n SQLITE_NOTADB: \"connection\",\n SQLITE_CORRUPT: \"connection\",\n\n // Query errors\n SQLITE_ERROR: \"query\",\n SQLITE_MISUSE: \"query\",\n SQLITE_RANGE: \"query\",\n};\n\n/**\n * Default configuration values.\n */\nconst DEFAULT_CONFIG = {\n busyTimeout: 5000,\n wal: true,\n foreignKeys: true,\n};\n\n/**\n * Converts a JavaScript value to a type that better-sqlite3 can bind.\n * better-sqlite3 only accepts: number, string, bigint, Buffer, null.\n */\nfunction sanitizeSqliteValue(v: unknown): unknown {\n if (v === undefined) return null;\n if (typeof v === \"boolean\") return v ? 1 : 0;\n if (v instanceof Date) return v.toISOString();\n if (v !== null && typeof v === \"object\") return JSON.stringify(v);\n return v;\n}\n\n/**\n * SQLite database adapter for Nextly.\n *\n * Extends the base DrizzleAdapter to provide SQLite-specific functionality\n * using the better-sqlite3 package.\n *\n * @remarks\n * SQLite has some differences from PostgreSQL:\n * - Synchronous API (wrapped for async compatibility)\n * - No connection pooling (single file/connection)\n * - RETURNING clause supported (SQLite 3.35+)\n * - Savepoints supported via nested transactions\n * - No native ILIKE (uses LOWER() LIKE workaround)\n * - JSON support (not JSONB)\n * - No array types\n *\n * @example\n * ```typescript\n * const adapter = new SqliteAdapter({\n * url: 'file:./data.db',\n * });\n *\n * await adapter.connect();\n * ```\n */\nexport class SqliteAdapter extends DrizzleAdapter {\n /**\n * The database dialect - always 'sqlite' for this adapter.\n */\n readonly dialect = \"sqlite\" as const;\n\n /**\n * Adapter configuration.\n */\n protected readonly config: SqliteAdapterConfig;\n\n /**\n * better-sqlite3 Database instance.\n */\n private db: Database.Database | null = null;\n\n /**\n * Connection state flag.\n */\n private connected = false;\n\n /**\n * Serialization queue for concurrent `transaction()` calls.\n *\n * better-sqlite3 is synchronous, single-connection, and rejects nested\n * `BEGIN` with \"cannot start a transaction within a transaction\".\n * When two `await adapter.transaction(...)` calls overlap (e.g. a bulk\n * mutation calling `Promise.allSettled` with N per-row updates), the\n * second one tries to BEGIN while the first is still open and the\n * driver throws.\n *\n * Postgres/MySQL avoid this by allocating a fresh client/connection\n * per transaction from a pool — there is no equivalent for\n * better-sqlite3, so we serialize at the JS layer instead. Every\n * `transaction()` invocation chains onto this promise; only one\n * BEGIN→COMMIT/ROLLBACK section runs at any moment, preserving\n * write-isolation semantics that callers expect from a transactional\n * adapter.\n *\n * Performance impact is the natural floor: SQLite already serializes\n * writers at the file-lock level, so the queue removes failed-call\n * surface area without changing the achievable concurrency.\n */\n private transactionQueue: Promise<unknown> = Promise.resolve();\n\n /**\n * Creates a new SQLite adapter instance.\n *\n * @param config - Adapter configuration\n */\n constructor(config: SqliteAdapterConfig) {\n super();\n this.config = config;\n }\n\n /**\n * Connect to the SQLite database.\n *\n * @remarks\n * This method initializes the database connection. For SQLite, this\n * opens the database file or creates an in-memory database.\n * Also configures WAL mode and foreign keys based on config.\n *\n * @throws {DatabaseError} If connection fails\n */\n async connect(): Promise<void> {\n if (this.connected && this.db) {\n return;\n }\n\n try {\n // Dynamic import of better-sqlite3 to avoid bundling issues\n const BetterSqlite3 = await import(\"better-sqlite3\");\n const Database = BetterSqlite3.default;\n\n // Determine database path\n let dbPath: string;\n if (this.config.memory) {\n dbPath = \":memory:\";\n } else if (this.config.url) {\n // Strip file: prefix if present\n dbPath = this.config.url.replace(/^file:/, \"\");\n } else {\n dbPath = \":memory:\";\n }\n\n // Ensure the parent directory exists for file-backed databases.\n // better-sqlite3 fails with a confusing \"Cannot open database\n // because the directory does not exist\" error if it doesn't, and\n // a fresh clone with `DATABASE_URL=file:./data/app.db` reliably\n // hits this on first run. Create the dir lazily so DATABASE_URL\n // can point anywhere without a separate setup step.\n if (dbPath !== \":memory:\" && !this.config.readonly) {\n const fs = await import(\"node:fs\");\n const path = await import(\"node:path\");\n const dir = path.dirname(path.resolve(dbPath));\n await fs.promises.mkdir(dir, { recursive: true });\n }\n\n // Create database instance\n this.db = new Database(dbPath, {\n readonly: this.config.readonly ?? false,\n timeout: this.config.busyTimeout ?? DEFAULT_CONFIG.busyTimeout,\n });\n\n // Configure WAL mode for better concurrency (unless in-memory or readonly)\n if (\n (this.config.wal ?? DEFAULT_CONFIG.wal) &&\n dbPath !== \":memory:\" &&\n !this.config.readonly\n ) {\n this.db.pragma(\"journal_mode = WAL\");\n }\n\n // Enable foreign keys\n if (this.config.foreignKeys ?? DEFAULT_CONFIG.foreignKeys) {\n this.db.pragma(\"foreign_keys = ON\");\n }\n\n // F17: check SQLite version. Hard-fails on SQLite <3.38. SQLite has\n // no recognized cloud variants we warn on, so onWarning is omitted.\n // Note: better-sqlite3's bundled SQLite is set by the package\n // version; users on this package's pinned better-sqlite3 (3.45+)\n // will always pass.\n await checkDialectVersion(this.db, \"sqlite\");\n\n this.connected = true;\n\n if (this.config.logger?.info) {\n this.config.logger.info(\"SQLite connection established\", {\n url: dbPath === \":memory:\" ? \"in-memory\" : dbPath,\n wal: this.config.wal ?? DEFAULT_CONFIG.wal,\n foreignKeys: this.config.foreignKeys ?? DEFAULT_CONFIG.foreignKeys,\n });\n }\n } catch (error) {\n // Clean up on failure\n if (this.db) {\n try {\n this.db.close();\n } catch {\n // Ignore close errors during error handling\n }\n this.db = null;\n }\n throw this.classifyError(error);\n }\n }\n\n /**\n * Disconnect from the SQLite database.\n *\n * @remarks\n * This method closes the database connection and releases resources.\n */\n // better-sqlite3 is synchronous; method is async to satisfy the DatabaseAdapter contract.\n // eslint-disable-next-line @typescript-eslint/require-await\n async disconnect(): Promise<void> {\n if (!this.db) {\n return;\n }\n\n try {\n this.db.close();\n\n if (this.config.logger?.info) {\n this.config.logger.info(\"SQLite connection closed\");\n }\n } finally {\n this.db = null;\n this.connected = false;\n }\n }\n\n /**\n * Check if connected to the database.\n */\n isConnected(): boolean {\n return this.connected && this.db !== null;\n }\n\n /**\n * Get connection pool statistics.\n *\n * @remarks\n * SQLite doesn't use connection pooling, so this returns null.\n * The database is single-file with a single connection.\n */\n getPoolStats(): PoolStats | null {\n // SQLite doesn't have connection pooling\n return null;\n }\n\n /**\n * Execute a raw SQL query.\n *\n * @param sql - SQL query string with $1, $2 placeholders (converted to ? for SQLite)\n * @param params - Query parameters\n * @returns Query results\n *\n * @throws {DatabaseError} If query execution fails\n */\n // better-sqlite3 is synchronous; method is async to satisfy the DatabaseAdapter contract.\n // eslint-disable-next-line @typescript-eslint/require-await\n async executeQuery<T = unknown>(\n sql: string,\n params: SqlParam[] = []\n ): Promise<T[]> {\n const db = this.ensureDb();\n const startTime = Date.now();\n\n try {\n // Convert $1, $2 placeholders to ? for better-sqlite3\n const convertedSql = this.convertPlaceholders(sql);\n\n // Determine if this is a SELECT query or a modifying query\n const trimmedSql = convertedSql.trim().toUpperCase();\n\n // Check for PRAGMA query statements (e.g., \"PRAGMA foreign_keys\").\n // Setting PRAGMAs (e.g., \"PRAGMA foreign_keys = OFF\") don't return data.\n const isPragmaQuery =\n trimmedSql.startsWith(\"PRAGMA\") && !trimmedSql.includes(\"=\");\n\n const isSelect =\n trimmedSql.startsWith(\"SELECT\") ||\n isPragmaQuery ||\n trimmedSql.startsWith(\"WITH\");\n const hasReturning = trimmedSql.includes(\"RETURNING\");\n\n let result: T[];\n\n const sanitizedParams = params.map(sanitizeSqliteValue);\n\n if (isSelect || hasReturning) {\n // Use .all() for SELECT queries or queries with RETURNING\n const stmt = db.prepare(convertedSql);\n result = stmt.all(...sanitizedParams) as T[];\n } else {\n // Use .run() for INSERT/UPDATE/DELETE/PRAGMA settings without RETURNING\n const stmt = db.prepare(convertedSql);\n const runResult = stmt.run(...sanitizedParams);\n // Return info about the operation\n result = [\n {\n changes: runResult.changes,\n lastInsertRowid: runResult.lastInsertRowid,\n } as unknown as T,\n ];\n }\n\n // Log query if logger configured\n if (this.config.logger?.query) {\n const durationMs = Date.now() - startTime;\n this.config.logger.query(convertedSql, params, durationMs);\n }\n\n return result;\n } catch (error) {\n throw this.classifyError(error, sql);\n }\n }\n\n /**\n * Execute work within a transaction.\n *\n * @param work - Function containing transactional operations\n * @param options - Transaction options (isolation level not fully supported in SQLite)\n * @returns Result of the work function\n *\n * @remarks\n * Uses better-sqlite3's native transaction handling which:\n * - Automatically commits on success\n * - Automatically rolls back on error\n * - Converts nested transactions to savepoints\n *\n * Note: SQLite uses DEFERRED, IMMEDIATE, or EXCLUSIVE transaction modes\n * rather than isolation levels. This adapter uses IMMEDIATE by default.\n */\n async transaction<T>(\n work: (tx: TransactionContext) => Promise<T>,\n _options?: TransactionOptions\n ): Promise<T> {\n // Why: serialize concurrent transaction() invocations to dodge\n // better-sqlite3's \"cannot start a transaction within a transaction\"\n // error when two awaits overlap on the same connection. See the\n // `transactionQueue` field comment for the full rationale. The queue\n // chains every call onto a tail promise so only one BEGIN → COMMIT\n // section runs at a time; the next call's BEGIN waits for the\n // previous COMMIT/ROLLBACK to finish.\n //\n // Failure isolation: the queue's tail promise must not reject (a\n // rejection would poison every subsequent transaction with the same\n // rejected value). We attach a no-op `.catch` so the chain stays\n // resolved while the actual error propagates back to the original\n // caller through the inner promise.\n const run = async (): Promise<T> => this.runTransaction(work);\n const next = this.transactionQueue.then(run, run);\n this.transactionQueue = next.catch(() => undefined);\n return next;\n }\n\n /**\n * Inner transaction body. Kept private so callers always go through\n * the serialized `transaction()` queue above and the BEGIN/COMMIT\n * pair is never invoked outside of it.\n */\n private async runTransaction<T>(\n work: (tx: TransactionContext) => Promise<T>\n ): Promise<T> {\n const db = this.ensureDb();\n const startTime = Date.now();\n\n try {\n // Create transaction context\n const ctx = this.createTransactionContext(db);\n\n // Since better-sqlite3's db.transaction() doesn't support async functions,\n // we manually manage the transaction with BEGIN/COMMIT/ROLLBACK\n db.exec(\"BEGIN IMMEDIATE\");\n\n try {\n const result = await work(ctx);\n db.exec(\"COMMIT\");\n\n // Log success\n if (this.config.logger?.debug) {\n const durationMs = Date.now() - startTime;\n this.config.logger.debug(\"Transaction committed\", {\n durationMs,\n });\n }\n\n return result;\n } catch (error) {\n // Rollback on error\n try {\n db.exec(\"ROLLBACK\");\n } catch {\n // Ignore rollback errors - transaction may already be aborted\n }\n throw error;\n }\n } catch (error) {\n throw this.classifyError(error);\n }\n }\n\n /**\n * Get SQLite database capabilities.\n *\n * @remarks\n * SQLite capabilities:\n * - JSON support (not JSONB)\n * - No arrays\n * - No native ILIKE\n * - RETURNING clause (3.35+)\n * - Savepoints supported\n * - ON CONFLICT supported\n */\n getCapabilities(): DatabaseCapabilities {\n return {\n dialect: \"sqlite\",\n supportsJsonb: false, // SQLite uses JSON, not JSONB\n supportsJson: true,\n supportsArrays: false, // SQLite doesn't support array types\n supportsGeneratedColumns: true, // SQLite 3.31+\n supportsFts: true, // SQLite FTS5\n supportsIlike: false, // No native ILIKE, use LOWER() LIKE\n supportsReturning: true, // SQLite 3.35+\n supportsSavepoints: true, // SQLite supports savepoints\n supportsOnConflict: true, // ON CONFLICT clause\n maxParamsPerQuery: 999, // SQLite SQLITE_MAX_VARIABLE_NUMBER default\n maxIdentifierLength: 128, // SQLite doesn't have a strict limit\n };\n }\n\n /**\n * Override insertMany for bulk insert optimization.\n *\n * @remarks\n * Uses a single multi-row INSERT statement for better performance.\n */\n override async insertMany<T = unknown>(\n table: string,\n data: Record<string, unknown>[],\n options?: InsertOptions\n ): Promise<T[]> {\n if (data.length === 0) {\n return [];\n }\n\n const db = this.ensureDb();\n\n // For single record, use parent implementation\n if (data.length === 1) {\n const result = await this.insert<T>(table, data[0], options);\n return [result];\n }\n\n // Build multi-row INSERT\n const columns = Object.keys(data[0]);\n const params: SqlParam[] = [];\n const valuesClauses: string[] = [];\n\n for (const record of data) {\n const placeholders: string[] = [];\n for (const col of columns) {\n params.push(sanitizeSqliteValue(record[col]) as SqlParam);\n placeholders.push(\"?\");\n }\n valuesClauses.push(`(${placeholders.join(\", \")})`);\n }\n\n const columnList = columns\n .map(col => this.escapeIdentifier(col))\n .join(\", \");\n let sql = `INSERT INTO ${this.escapeIdentifier(table)} (${columnList}) VALUES ${valuesClauses.join(\", \")}`;\n\n // Add RETURNING clause\n if (options?.returning) {\n const returning =\n options.returning === \"*\"\n ? \"*\"\n : options.returning.map(col => this.escapeIdentifier(col)).join(\", \");\n sql += ` RETURNING ${returning}`;\n } else {\n sql += \" RETURNING *\";\n }\n\n try {\n const stmt = db.prepare(sql);\n const rows = stmt.all(...(params as unknown[])) as T[];\n return rows;\n } catch (error) {\n throw this.handleQueryError(error, \"insertMany\", table);\n }\n }\n\n // ============================================================\n // Protected Helper Methods\n // ============================================================\n\n /**\n * Ensures database is connected and returns it.\n *\n * @throws {DatabaseError} If not connected\n */\n private ensureDb(): Database.Database {\n if (!this.db) {\n throw createDatabaseError({\n kind: \"connection\",\n message: \"SqliteAdapter is not connected. Call connect() first.\",\n });\n }\n return this.db;\n }\n\n /**\n * Return the typed Drizzle instance for SQLite.\n * Guarded for server-only usage and requires an active connection.\n *\n * @param schema - Optional schema for relational queries (db.query.*)\n * @returns Drizzle ORM instance wrapping the better-sqlite3 connection\n * @throws {Error} If called in browser or not connected\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getDrizzle<T = BetterSQLite3Database<any>>(\n schema?: Record<string, unknown>\n ): T {\n if (typeof window !== \"undefined\") {\n throw new Error(\"getDrizzle() is server-only\");\n }\n const db = this.ensureDb();\n return (schema ? drizzle(db, { schema }) : drizzle(db)) as T;\n }\n\n /**\n * Convert $1, $2 placeholders to ? for better-sqlite3.\n *\n * @param sql - SQL with PostgreSQL-style placeholders\n * @returns SQL with ? placeholders\n */\n private convertPlaceholders(sql: string): string {\n // Replace $1, $2, etc. with ?\n return sql.replace(/\\$\\d+/g, \"?\");\n }\n\n /**\n * Creates a TransactionContext for the given database connection.\n */\n private createTransactionContext(db: Database.Database): TransactionContext {\n // better-sqlite3 is synchronous; the methods below are async to satisfy\n // the TransactionContext contract shared with truly-async dialect adapters.\n return {\n // eslint-disable-next-line @typescript-eslint/require-await\n execute: async <T = unknown>(\n sql: string,\n params: SqlParam[] = []\n ): Promise<T[]> => {\n const convertedSql = this.convertPlaceholders(sql);\n const trimmedSql = convertedSql.trim().toUpperCase();\n const isSelect =\n trimmedSql.startsWith(\"SELECT\") || trimmedSql.includes(\"RETURNING\");\n const sanitizedParams = params.map(sanitizeSqliteValue);\n\n if (isSelect) {\n const stmt = db.prepare(convertedSql);\n return stmt.all(...sanitizedParams) as T[];\n } else {\n const stmt = db.prepare(convertedSql);\n const result = stmt.run(...sanitizedParams);\n return [\n {\n changes: result.changes,\n lastInsertRowid: result.lastInsertRowid,\n } as unknown as T,\n ];\n }\n },\n\n // eslint-disable-next-line @typescript-eslint/require-await\n insert: async <T = unknown>(\n table: string,\n data: Record<string, unknown>,\n options?: InsertOptions\n ): Promise<T> => {\n const columns = Object.keys(data);\n const values = Object.values(data).map(sanitizeSqliteValue);\n const placeholders = values.map(() => \"?\").join(\", \");\n\n let sql = `INSERT INTO ${this.escapeIdentifier(table)} (${columns.map(c => this.escapeIdentifier(c)).join(\", \")}) VALUES (${placeholders})`;\n\n if (options?.returning) {\n const returning =\n options.returning === \"*\"\n ? \"*\"\n : options.returning\n .map(col => this.escapeIdentifier(col))\n .join(\", \");\n sql += ` RETURNING ${returning}`;\n } else {\n sql += \" RETURNING *\";\n }\n\n const stmt = db.prepare(sql);\n const rows = stmt.all(...values) as T[];\n return rows[0];\n },\n\n // eslint-disable-next-line @typescript-eslint/require-await\n insertMany: async <T = unknown>(\n table: string,\n data: Record<string, unknown>[],\n options?: InsertOptions\n ): Promise<T[]> => {\n if (data.length === 0) return [];\n\n const columns = Object.keys(data[0]);\n const allValues: unknown[] = [];\n const valuesClauses: string[] = [];\n\n for (const record of data) {\n const placeholders: string[] = [];\n for (const col of columns) {\n allValues.push(sanitizeSqliteValue(record[col]));\n placeholders.push(\"?\");\n }\n valuesClauses.push(`(${placeholders.join(\", \")})`);\n }\n\n let sql = `INSERT INTO ${this.escapeIdentifier(table)} (${columns.map(c => this.escapeIdentifier(c)).join(\", \")}) VALUES ${valuesClauses.join(\", \")}`;\n\n if (options?.returning) {\n const returning =\n options.returning === \"*\"\n ? \"*\"\n : options.returning\n .map(col => this.escapeIdentifier(col))\n .join(\", \");\n sql += ` RETURNING ${returning}`;\n } else {\n sql += \" RETURNING *\";\n }\n\n const stmt = db.prepare(sql);\n return stmt.all(...allValues) as T[];\n },\n\n // TransactionContext CRUD methods delegate to the adapter's CRUD\n // which uses Drizzle query API via the TableResolver.\n select: async <T = unknown>(\n table: string,\n options?: SelectOptions\n ): Promise<T[]> => {\n return this.select<T>(table, options);\n },\n\n selectOne: async <T = unknown>(\n table: string,\n options?: SelectOptions\n ): Promise<T | null> => {\n return this.selectOne<T>(table, options);\n },\n\n update: async <T = unknown>(\n table: string,\n data: Record<string, unknown>,\n where: WhereClause,\n options?: UpdateOptions\n ): Promise<T[]> => {\n return this.update<T>(table, data, where, options);\n },\n\n delete: async (\n table: string,\n where: WhereClause,\n _options?: DeleteOptions\n ): Promise<number> => {\n return this.delete(table, where);\n },\n\n upsert: async <T = unknown>(\n table: string,\n data: Record<string, unknown>,\n options: UpsertOptions\n ): Promise<T> => {\n return this.upsert<T>(table, data, options);\n },\n\n // eslint-disable-next-line @typescript-eslint/require-await\n savepoint: async (name: string): Promise<void> => {\n db.exec(`SAVEPOINT ${this.escapeIdentifier(name)}`);\n },\n\n // eslint-disable-next-line @typescript-eslint/require-await\n rollbackToSavepoint: async (name: string): Promise<void> => {\n db.exec(`ROLLBACK TO SAVEPOINT ${this.escapeIdentifier(name)}`);\n },\n\n // eslint-disable-next-line @typescript-eslint/require-await\n releaseSavepoint: async (name: string): Promise<void> => {\n db.exec(`RELEASE SAVEPOINT ${this.escapeIdentifier(name)}`);\n },\n };\n }\n\n /**\n * Classifies a SQLite error into a DatabaseError.\n *\n * @param error - Original error from better-sqlite3\n * @param sql - SQL statement that caused the error (optional)\n * @returns DatabaseError with proper classification\n */\n private classifyError(error: unknown, sql?: string): DatabaseError {\n // Why short-circuit on existing DatabaseError: F17's\n // UnsupportedDialectVersionError is already a typed DatabaseError with\n // kind: \"unsupported_version\" plus detectedVersion/requiredVersion\n // fields. Re-wrapping it here would erase those fields.\n if (isDatabaseError(error)) return error;\n\n const sqliteError = error as {\n code?: string;\n message?: string;\n name?: string;\n };\n\n // Determine error kind from SQLite error code\n let kind: DatabaseErrorKind = \"unknown\";\n\n if (sqliteError.code) {\n kind = SQLITE_ERROR_CODES[sqliteError.code] || \"unknown\";\n } else if (sqliteError.message) {\n // Try to extract error type from message\n const msg = sqliteError.message.toUpperCase();\n if (msg.includes(\"UNIQUE CONSTRAINT\")) {\n kind = \"unique_violation\";\n } else if (msg.includes(\"FOREIGN KEY CONSTRAINT\")) {\n kind = \"foreign_key_violation\";\n } else if (msg.includes(\"NOT NULL CONSTRAINT\")) {\n kind = \"not_null_violation\";\n } else if (msg.includes(\"CHECK CONSTRAINT\")) {\n kind = \"check_violation\";\n } else if (msg.includes(\"BUSY\") || msg.includes(\"LOCKED\")) {\n kind = \"timeout\";\n } else if (\n msg.includes(\"SQLITE_CANTOPEN\") ||\n msg.includes(\"UNABLE TO OPEN\")\n ) {\n kind = \"connection\";\n }\n }\n\n // Build error message\n let message = sqliteError.message ?? String(error);\n if (sql && kind === \"query\") {\n message = `Query failed: ${message}`;\n }\n\n return createDatabaseError({\n kind,\n message,\n code: sqliteError.code,\n cause: error instanceof Error ? error : undefined,\n });\n }\n\n /**\n * Override handleQueryError to use SQLite-specific classification.\n */\n protected override handleQueryError(\n error: unknown,\n operation: string,\n table: string\n ): DatabaseError {\n const dbError = this.classifyError(error);\n\n // Add operation context if not already present\n if (!dbError.message.includes(operation)) {\n dbError.message = `${operation} operation failed on table '${table}': ${dbError.message}`;\n }\n\n if (!dbError.table) {\n dbError.table = table;\n }\n\n return dbError;\n }\n}\n\n/**\n * Create a SQLite database adapter.\n *\n * @param config - SQLite adapter configuration\n * @returns A new SqliteAdapter instance\n *\n * @example\n * ```typescript\n * // Simple usage with file path\n * const adapter = createSqliteAdapter({\n * url: 'file:./data.db',\n * });\n *\n * // In-memory database\n * const memAdapter = createSqliteAdapter({\n * memory: true,\n * });\n *\n * // Full configuration\n * const adapter = createSqliteAdapter({\n * url: 'file:./data.db',\n * wal: true,\n * foreignKeys: true,\n * busyTimeout: 5000,\n * logger: {\n * query: (sql, params, duration) => console.log(`Query: ${sql}`),\n * },\n * });\n *\n * await adapter.connect();\n * ```\n */\nexport function createSqliteAdapter(\n config: SqliteAdapterConfig\n): SqliteAdapter {\n return new SqliteAdapter(config);\n}\n\n/**\n * Type guard to check if a value is a SqliteAdapter.\n *\n * @param value - Value to check\n * @returns True if value is a SqliteAdapter instance\n *\n * @example\n * ```typescript\n * if (isSqliteAdapter(adapter)) {\n * // TypeScript knows adapter is SqliteAdapter\n * console.log('Using SQLite');\n * }\n * ```\n */\nexport function isSqliteAdapter(value: unknown): value is SqliteAdapter {\n return value instanceof SqliteAdapter;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { DrizzleAdapter } from '@nextlyhq/adapter-drizzle';
|
|
2
|
+
import { SqliteAdapterConfig, PoolStats, SqlParam, TransactionContext, TransactionOptions, DatabaseCapabilities, InsertOptions, DatabaseError } from '@nextlyhq/adapter-drizzle/types';
|
|
3
|
+
export { AdapterLogger, BaseAdapterConfig, DatabaseCapabilities, DatabaseError, DatabaseErrorKind, DeleteOptions, InsertOptions, JoinSpec, OrderBySpec, PoolStats, SelectOptions, SqlParam, SqliteAdapterConfig, TransactionContext, TransactionOptions, UpdateOptions, UpsertOptions, WhereClause, WhereCondition, WhereOperator } from '@nextlyhq/adapter-drizzle/types';
|
|
4
|
+
import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @nextlyhq/adapter-sqlite
|
|
8
|
+
*
|
|
9
|
+
* SQLite database adapter for Nextly.
|
|
10
|
+
* Extends DrizzleAdapter from @nextlyhq/adapter-drizzle to provide SQLite-specific functionality.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* This adapter uses the better-sqlite3 package for database connectivity and provides:
|
|
14
|
+
* - Synchronous API wrapped for async interface compatibility
|
|
15
|
+
* - Full transaction support with savepoints (via better-sqlite3's native transaction handling)
|
|
16
|
+
* - CRUD operations with RETURNING clause support (SQLite 3.35+)
|
|
17
|
+
* - WAL mode for better concurrent read performance
|
|
18
|
+
* - In-memory and file-based database support
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { createSqliteAdapter } from '@nextlyhq/adapter-sqlite';
|
|
23
|
+
*
|
|
24
|
+
* const adapter = createSqliteAdapter({
|
|
25
|
+
* url: 'file:./data/app.db',
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* await adapter.connect();
|
|
29
|
+
*
|
|
30
|
+
* // Query data
|
|
31
|
+
* const users = await adapter.select('users', {
|
|
32
|
+
* where: { and: [{ column: 'status', op: '=', value: 'active' }] },
|
|
33
|
+
* limit: 10,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* await adapter.disconnect();
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @packageDocumentation
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Package version
|
|
44
|
+
*/
|
|
45
|
+
declare const VERSION = "0.1.0";
|
|
46
|
+
/**
|
|
47
|
+
* SQLite database adapter for Nextly.
|
|
48
|
+
*
|
|
49
|
+
* Extends the base DrizzleAdapter to provide SQLite-specific functionality
|
|
50
|
+
* using the better-sqlite3 package.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* SQLite has some differences from PostgreSQL:
|
|
54
|
+
* - Synchronous API (wrapped for async compatibility)
|
|
55
|
+
* - No connection pooling (single file/connection)
|
|
56
|
+
* - RETURNING clause supported (SQLite 3.35+)
|
|
57
|
+
* - Savepoints supported via nested transactions
|
|
58
|
+
* - No native ILIKE (uses LOWER() LIKE workaround)
|
|
59
|
+
* - JSON support (not JSONB)
|
|
60
|
+
* - No array types
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const adapter = new SqliteAdapter({
|
|
65
|
+
* url: 'file:./data.db',
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* await adapter.connect();
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare class SqliteAdapter extends DrizzleAdapter {
|
|
72
|
+
/**
|
|
73
|
+
* The database dialect - always 'sqlite' for this adapter.
|
|
74
|
+
*/
|
|
75
|
+
readonly dialect: "sqlite";
|
|
76
|
+
/**
|
|
77
|
+
* Adapter configuration.
|
|
78
|
+
*/
|
|
79
|
+
protected readonly config: SqliteAdapterConfig;
|
|
80
|
+
/**
|
|
81
|
+
* better-sqlite3 Database instance.
|
|
82
|
+
*/
|
|
83
|
+
private db;
|
|
84
|
+
/**
|
|
85
|
+
* Connection state flag.
|
|
86
|
+
*/
|
|
87
|
+
private connected;
|
|
88
|
+
/**
|
|
89
|
+
* Serialization queue for concurrent `transaction()` calls.
|
|
90
|
+
*
|
|
91
|
+
* better-sqlite3 is synchronous, single-connection, and rejects nested
|
|
92
|
+
* `BEGIN` with "cannot start a transaction within a transaction".
|
|
93
|
+
* When two `await adapter.transaction(...)` calls overlap (e.g. a bulk
|
|
94
|
+
* mutation calling `Promise.allSettled` with N per-row updates), the
|
|
95
|
+
* second one tries to BEGIN while the first is still open and the
|
|
96
|
+
* driver throws.
|
|
97
|
+
*
|
|
98
|
+
* Postgres/MySQL avoid this by allocating a fresh client/connection
|
|
99
|
+
* per transaction from a pool — there is no equivalent for
|
|
100
|
+
* better-sqlite3, so we serialize at the JS layer instead. Every
|
|
101
|
+
* `transaction()` invocation chains onto this promise; only one
|
|
102
|
+
* BEGIN→COMMIT/ROLLBACK section runs at any moment, preserving
|
|
103
|
+
* write-isolation semantics that callers expect from a transactional
|
|
104
|
+
* adapter.
|
|
105
|
+
*
|
|
106
|
+
* Performance impact is the natural floor: SQLite already serializes
|
|
107
|
+
* writers at the file-lock level, so the queue removes failed-call
|
|
108
|
+
* surface area without changing the achievable concurrency.
|
|
109
|
+
*/
|
|
110
|
+
private transactionQueue;
|
|
111
|
+
/**
|
|
112
|
+
* Creates a new SQLite adapter instance.
|
|
113
|
+
*
|
|
114
|
+
* @param config - Adapter configuration
|
|
115
|
+
*/
|
|
116
|
+
constructor(config: SqliteAdapterConfig);
|
|
117
|
+
/**
|
|
118
|
+
* Connect to the SQLite database.
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* This method initializes the database connection. For SQLite, this
|
|
122
|
+
* opens the database file or creates an in-memory database.
|
|
123
|
+
* Also configures WAL mode and foreign keys based on config.
|
|
124
|
+
*
|
|
125
|
+
* @throws {DatabaseError} If connection fails
|
|
126
|
+
*/
|
|
127
|
+
connect(): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Disconnect from the SQLite database.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* This method closes the database connection and releases resources.
|
|
133
|
+
*/
|
|
134
|
+
disconnect(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Check if connected to the database.
|
|
137
|
+
*/
|
|
138
|
+
isConnected(): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Get connection pool statistics.
|
|
141
|
+
*
|
|
142
|
+
* @remarks
|
|
143
|
+
* SQLite doesn't use connection pooling, so this returns null.
|
|
144
|
+
* The database is single-file with a single connection.
|
|
145
|
+
*/
|
|
146
|
+
getPoolStats(): PoolStats | null;
|
|
147
|
+
/**
|
|
148
|
+
* Execute a raw SQL query.
|
|
149
|
+
*
|
|
150
|
+
* @param sql - SQL query string with $1, $2 placeholders (converted to ? for SQLite)
|
|
151
|
+
* @param params - Query parameters
|
|
152
|
+
* @returns Query results
|
|
153
|
+
*
|
|
154
|
+
* @throws {DatabaseError} If query execution fails
|
|
155
|
+
*/
|
|
156
|
+
executeQuery<T = unknown>(sql: string, params?: SqlParam[]): Promise<T[]>;
|
|
157
|
+
/**
|
|
158
|
+
* Execute work within a transaction.
|
|
159
|
+
*
|
|
160
|
+
* @param work - Function containing transactional operations
|
|
161
|
+
* @param options - Transaction options (isolation level not fully supported in SQLite)
|
|
162
|
+
* @returns Result of the work function
|
|
163
|
+
*
|
|
164
|
+
* @remarks
|
|
165
|
+
* Uses better-sqlite3's native transaction handling which:
|
|
166
|
+
* - Automatically commits on success
|
|
167
|
+
* - Automatically rolls back on error
|
|
168
|
+
* - Converts nested transactions to savepoints
|
|
169
|
+
*
|
|
170
|
+
* Note: SQLite uses DEFERRED, IMMEDIATE, or EXCLUSIVE transaction modes
|
|
171
|
+
* rather than isolation levels. This adapter uses IMMEDIATE by default.
|
|
172
|
+
*/
|
|
173
|
+
transaction<T>(work: (tx: TransactionContext) => Promise<T>, _options?: TransactionOptions): Promise<T>;
|
|
174
|
+
/**
|
|
175
|
+
* Inner transaction body. Kept private so callers always go through
|
|
176
|
+
* the serialized `transaction()` queue above and the BEGIN/COMMIT
|
|
177
|
+
* pair is never invoked outside of it.
|
|
178
|
+
*/
|
|
179
|
+
private runTransaction;
|
|
180
|
+
/**
|
|
181
|
+
* Get SQLite database capabilities.
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* SQLite capabilities:
|
|
185
|
+
* - JSON support (not JSONB)
|
|
186
|
+
* - No arrays
|
|
187
|
+
* - No native ILIKE
|
|
188
|
+
* - RETURNING clause (3.35+)
|
|
189
|
+
* - Savepoints supported
|
|
190
|
+
* - ON CONFLICT supported
|
|
191
|
+
*/
|
|
192
|
+
getCapabilities(): DatabaseCapabilities;
|
|
193
|
+
/**
|
|
194
|
+
* Override insertMany for bulk insert optimization.
|
|
195
|
+
*
|
|
196
|
+
* @remarks
|
|
197
|
+
* Uses a single multi-row INSERT statement for better performance.
|
|
198
|
+
*/
|
|
199
|
+
insertMany<T = unknown>(table: string, data: Record<string, unknown>[], options?: InsertOptions): Promise<T[]>;
|
|
200
|
+
/**
|
|
201
|
+
* Ensures database is connected and returns it.
|
|
202
|
+
*
|
|
203
|
+
* @throws {DatabaseError} If not connected
|
|
204
|
+
*/
|
|
205
|
+
private ensureDb;
|
|
206
|
+
/**
|
|
207
|
+
* Return the typed Drizzle instance for SQLite.
|
|
208
|
+
* Guarded for server-only usage and requires an active connection.
|
|
209
|
+
*
|
|
210
|
+
* @param schema - Optional schema for relational queries (db.query.*)
|
|
211
|
+
* @returns Drizzle ORM instance wrapping the better-sqlite3 connection
|
|
212
|
+
* @throws {Error} If called in browser or not connected
|
|
213
|
+
*/
|
|
214
|
+
getDrizzle<T = BetterSQLite3Database<any>>(schema?: Record<string, unknown>): T;
|
|
215
|
+
/**
|
|
216
|
+
* Convert $1, $2 placeholders to ? for better-sqlite3.
|
|
217
|
+
*
|
|
218
|
+
* @param sql - SQL with PostgreSQL-style placeholders
|
|
219
|
+
* @returns SQL with ? placeholders
|
|
220
|
+
*/
|
|
221
|
+
private convertPlaceholders;
|
|
222
|
+
/**
|
|
223
|
+
* Creates a TransactionContext for the given database connection.
|
|
224
|
+
*/
|
|
225
|
+
private createTransactionContext;
|
|
226
|
+
/**
|
|
227
|
+
* Classifies a SQLite error into a DatabaseError.
|
|
228
|
+
*
|
|
229
|
+
* @param error - Original error from better-sqlite3
|
|
230
|
+
* @param sql - SQL statement that caused the error (optional)
|
|
231
|
+
* @returns DatabaseError with proper classification
|
|
232
|
+
*/
|
|
233
|
+
private classifyError;
|
|
234
|
+
/**
|
|
235
|
+
* Override handleQueryError to use SQLite-specific classification.
|
|
236
|
+
*/
|
|
237
|
+
protected handleQueryError(error: unknown, operation: string, table: string): DatabaseError;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Create a SQLite database adapter.
|
|
241
|
+
*
|
|
242
|
+
* @param config - SQLite adapter configuration
|
|
243
|
+
* @returns A new SqliteAdapter instance
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* // Simple usage with file path
|
|
248
|
+
* const adapter = createSqliteAdapter({
|
|
249
|
+
* url: 'file:./data.db',
|
|
250
|
+
* });
|
|
251
|
+
*
|
|
252
|
+
* // In-memory database
|
|
253
|
+
* const memAdapter = createSqliteAdapter({
|
|
254
|
+
* memory: true,
|
|
255
|
+
* });
|
|
256
|
+
*
|
|
257
|
+
* // Full configuration
|
|
258
|
+
* const adapter = createSqliteAdapter({
|
|
259
|
+
* url: 'file:./data.db',
|
|
260
|
+
* wal: true,
|
|
261
|
+
* foreignKeys: true,
|
|
262
|
+
* busyTimeout: 5000,
|
|
263
|
+
* logger: {
|
|
264
|
+
* query: (sql, params, duration) => console.log(`Query: ${sql}`),
|
|
265
|
+
* },
|
|
266
|
+
* });
|
|
267
|
+
*
|
|
268
|
+
* await adapter.connect();
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
declare function createSqliteAdapter(config: SqliteAdapterConfig): SqliteAdapter;
|
|
272
|
+
/**
|
|
273
|
+
* Type guard to check if a value is a SqliteAdapter.
|
|
274
|
+
*
|
|
275
|
+
* @param value - Value to check
|
|
276
|
+
* @returns True if value is a SqliteAdapter instance
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* if (isSqliteAdapter(adapter)) {
|
|
281
|
+
* // TypeScript knows adapter is SqliteAdapter
|
|
282
|
+
* console.log('Using SQLite');
|
|
283
|
+
* }
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
declare function isSqliteAdapter(value: unknown): value is SqliteAdapter;
|
|
287
|
+
|
|
288
|
+
export { SqliteAdapter, VERSION, createSqliteAdapter, isSqliteAdapter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { DrizzleAdapter } from '@nextlyhq/adapter-drizzle';
|
|
2
|
+
import { SqliteAdapterConfig, PoolStats, SqlParam, TransactionContext, TransactionOptions, DatabaseCapabilities, InsertOptions, DatabaseError } from '@nextlyhq/adapter-drizzle/types';
|
|
3
|
+
export { AdapterLogger, BaseAdapterConfig, DatabaseCapabilities, DatabaseError, DatabaseErrorKind, DeleteOptions, InsertOptions, JoinSpec, OrderBySpec, PoolStats, SelectOptions, SqlParam, SqliteAdapterConfig, TransactionContext, TransactionOptions, UpdateOptions, UpsertOptions, WhereClause, WhereCondition, WhereOperator } from '@nextlyhq/adapter-drizzle/types';
|
|
4
|
+
import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @nextlyhq/adapter-sqlite
|
|
8
|
+
*
|
|
9
|
+
* SQLite database adapter for Nextly.
|
|
10
|
+
* Extends DrizzleAdapter from @nextlyhq/adapter-drizzle to provide SQLite-specific functionality.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* This adapter uses the better-sqlite3 package for database connectivity and provides:
|
|
14
|
+
* - Synchronous API wrapped for async interface compatibility
|
|
15
|
+
* - Full transaction support with savepoints (via better-sqlite3's native transaction handling)
|
|
16
|
+
* - CRUD operations with RETURNING clause support (SQLite 3.35+)
|
|
17
|
+
* - WAL mode for better concurrent read performance
|
|
18
|
+
* - In-memory and file-based database support
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { createSqliteAdapter } from '@nextlyhq/adapter-sqlite';
|
|
23
|
+
*
|
|
24
|
+
* const adapter = createSqliteAdapter({
|
|
25
|
+
* url: 'file:./data/app.db',
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* await adapter.connect();
|
|
29
|
+
*
|
|
30
|
+
* // Query data
|
|
31
|
+
* const users = await adapter.select('users', {
|
|
32
|
+
* where: { and: [{ column: 'status', op: '=', value: 'active' }] },
|
|
33
|
+
* limit: 10,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* await adapter.disconnect();
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @packageDocumentation
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Package version
|
|
44
|
+
*/
|
|
45
|
+
declare const VERSION = "0.1.0";
|
|
46
|
+
/**
|
|
47
|
+
* SQLite database adapter for Nextly.
|
|
48
|
+
*
|
|
49
|
+
* Extends the base DrizzleAdapter to provide SQLite-specific functionality
|
|
50
|
+
* using the better-sqlite3 package.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* SQLite has some differences from PostgreSQL:
|
|
54
|
+
* - Synchronous API (wrapped for async compatibility)
|
|
55
|
+
* - No connection pooling (single file/connection)
|
|
56
|
+
* - RETURNING clause supported (SQLite 3.35+)
|
|
57
|
+
* - Savepoints supported via nested transactions
|
|
58
|
+
* - No native ILIKE (uses LOWER() LIKE workaround)
|
|
59
|
+
* - JSON support (not JSONB)
|
|
60
|
+
* - No array types
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const adapter = new SqliteAdapter({
|
|
65
|
+
* url: 'file:./data.db',
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* await adapter.connect();
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare class SqliteAdapter extends DrizzleAdapter {
|
|
72
|
+
/**
|
|
73
|
+
* The database dialect - always 'sqlite' for this adapter.
|
|
74
|
+
*/
|
|
75
|
+
readonly dialect: "sqlite";
|
|
76
|
+
/**
|
|
77
|
+
* Adapter configuration.
|
|
78
|
+
*/
|
|
79
|
+
protected readonly config: SqliteAdapterConfig;
|
|
80
|
+
/**
|
|
81
|
+
* better-sqlite3 Database instance.
|
|
82
|
+
*/
|
|
83
|
+
private db;
|
|
84
|
+
/**
|
|
85
|
+
* Connection state flag.
|
|
86
|
+
*/
|
|
87
|
+
private connected;
|
|
88
|
+
/**
|
|
89
|
+
* Serialization queue for concurrent `transaction()` calls.
|
|
90
|
+
*
|
|
91
|
+
* better-sqlite3 is synchronous, single-connection, and rejects nested
|
|
92
|
+
* `BEGIN` with "cannot start a transaction within a transaction".
|
|
93
|
+
* When two `await adapter.transaction(...)` calls overlap (e.g. a bulk
|
|
94
|
+
* mutation calling `Promise.allSettled` with N per-row updates), the
|
|
95
|
+
* second one tries to BEGIN while the first is still open and the
|
|
96
|
+
* driver throws.
|
|
97
|
+
*
|
|
98
|
+
* Postgres/MySQL avoid this by allocating a fresh client/connection
|
|
99
|
+
* per transaction from a pool — there is no equivalent for
|
|
100
|
+
* better-sqlite3, so we serialize at the JS layer instead. Every
|
|
101
|
+
* `transaction()` invocation chains onto this promise; only one
|
|
102
|
+
* BEGIN→COMMIT/ROLLBACK section runs at any moment, preserving
|
|
103
|
+
* write-isolation semantics that callers expect from a transactional
|
|
104
|
+
* adapter.
|
|
105
|
+
*
|
|
106
|
+
* Performance impact is the natural floor: SQLite already serializes
|
|
107
|
+
* writers at the file-lock level, so the queue removes failed-call
|
|
108
|
+
* surface area without changing the achievable concurrency.
|
|
109
|
+
*/
|
|
110
|
+
private transactionQueue;
|
|
111
|
+
/**
|
|
112
|
+
* Creates a new SQLite adapter instance.
|
|
113
|
+
*
|
|
114
|
+
* @param config - Adapter configuration
|
|
115
|
+
*/
|
|
116
|
+
constructor(config: SqliteAdapterConfig);
|
|
117
|
+
/**
|
|
118
|
+
* Connect to the SQLite database.
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* This method initializes the database connection. For SQLite, this
|
|
122
|
+
* opens the database file or creates an in-memory database.
|
|
123
|
+
* Also configures WAL mode and foreign keys based on config.
|
|
124
|
+
*
|
|
125
|
+
* @throws {DatabaseError} If connection fails
|
|
126
|
+
*/
|
|
127
|
+
connect(): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Disconnect from the SQLite database.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* This method closes the database connection and releases resources.
|
|
133
|
+
*/
|
|
134
|
+
disconnect(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Check if connected to the database.
|
|
137
|
+
*/
|
|
138
|
+
isConnected(): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Get connection pool statistics.
|
|
141
|
+
*
|
|
142
|
+
* @remarks
|
|
143
|
+
* SQLite doesn't use connection pooling, so this returns null.
|
|
144
|
+
* The database is single-file with a single connection.
|
|
145
|
+
*/
|
|
146
|
+
getPoolStats(): PoolStats | null;
|
|
147
|
+
/**
|
|
148
|
+
* Execute a raw SQL query.
|
|
149
|
+
*
|
|
150
|
+
* @param sql - SQL query string with $1, $2 placeholders (converted to ? for SQLite)
|
|
151
|
+
* @param params - Query parameters
|
|
152
|
+
* @returns Query results
|
|
153
|
+
*
|
|
154
|
+
* @throws {DatabaseError} If query execution fails
|
|
155
|
+
*/
|
|
156
|
+
executeQuery<T = unknown>(sql: string, params?: SqlParam[]): Promise<T[]>;
|
|
157
|
+
/**
|
|
158
|
+
* Execute work within a transaction.
|
|
159
|
+
*
|
|
160
|
+
* @param work - Function containing transactional operations
|
|
161
|
+
* @param options - Transaction options (isolation level not fully supported in SQLite)
|
|
162
|
+
* @returns Result of the work function
|
|
163
|
+
*
|
|
164
|
+
* @remarks
|
|
165
|
+
* Uses better-sqlite3's native transaction handling which:
|
|
166
|
+
* - Automatically commits on success
|
|
167
|
+
* - Automatically rolls back on error
|
|
168
|
+
* - Converts nested transactions to savepoints
|
|
169
|
+
*
|
|
170
|
+
* Note: SQLite uses DEFERRED, IMMEDIATE, or EXCLUSIVE transaction modes
|
|
171
|
+
* rather than isolation levels. This adapter uses IMMEDIATE by default.
|
|
172
|
+
*/
|
|
173
|
+
transaction<T>(work: (tx: TransactionContext) => Promise<T>, _options?: TransactionOptions): Promise<T>;
|
|
174
|
+
/**
|
|
175
|
+
* Inner transaction body. Kept private so callers always go through
|
|
176
|
+
* the serialized `transaction()` queue above and the BEGIN/COMMIT
|
|
177
|
+
* pair is never invoked outside of it.
|
|
178
|
+
*/
|
|
179
|
+
private runTransaction;
|
|
180
|
+
/**
|
|
181
|
+
* Get SQLite database capabilities.
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* SQLite capabilities:
|
|
185
|
+
* - JSON support (not JSONB)
|
|
186
|
+
* - No arrays
|
|
187
|
+
* - No native ILIKE
|
|
188
|
+
* - RETURNING clause (3.35+)
|
|
189
|
+
* - Savepoints supported
|
|
190
|
+
* - ON CONFLICT supported
|
|
191
|
+
*/
|
|
192
|
+
getCapabilities(): DatabaseCapabilities;
|
|
193
|
+
/**
|
|
194
|
+
* Override insertMany for bulk insert optimization.
|
|
195
|
+
*
|
|
196
|
+
* @remarks
|
|
197
|
+
* Uses a single multi-row INSERT statement for better performance.
|
|
198
|
+
*/
|
|
199
|
+
insertMany<T = unknown>(table: string, data: Record<string, unknown>[], options?: InsertOptions): Promise<T[]>;
|
|
200
|
+
/**
|
|
201
|
+
* Ensures database is connected and returns it.
|
|
202
|
+
*
|
|
203
|
+
* @throws {DatabaseError} If not connected
|
|
204
|
+
*/
|
|
205
|
+
private ensureDb;
|
|
206
|
+
/**
|
|
207
|
+
* Return the typed Drizzle instance for SQLite.
|
|
208
|
+
* Guarded for server-only usage and requires an active connection.
|
|
209
|
+
*
|
|
210
|
+
* @param schema - Optional schema for relational queries (db.query.*)
|
|
211
|
+
* @returns Drizzle ORM instance wrapping the better-sqlite3 connection
|
|
212
|
+
* @throws {Error} If called in browser or not connected
|
|
213
|
+
*/
|
|
214
|
+
getDrizzle<T = BetterSQLite3Database<any>>(schema?: Record<string, unknown>): T;
|
|
215
|
+
/**
|
|
216
|
+
* Convert $1, $2 placeholders to ? for better-sqlite3.
|
|
217
|
+
*
|
|
218
|
+
* @param sql - SQL with PostgreSQL-style placeholders
|
|
219
|
+
* @returns SQL with ? placeholders
|
|
220
|
+
*/
|
|
221
|
+
private convertPlaceholders;
|
|
222
|
+
/**
|
|
223
|
+
* Creates a TransactionContext for the given database connection.
|
|
224
|
+
*/
|
|
225
|
+
private createTransactionContext;
|
|
226
|
+
/**
|
|
227
|
+
* Classifies a SQLite error into a DatabaseError.
|
|
228
|
+
*
|
|
229
|
+
* @param error - Original error from better-sqlite3
|
|
230
|
+
* @param sql - SQL statement that caused the error (optional)
|
|
231
|
+
* @returns DatabaseError with proper classification
|
|
232
|
+
*/
|
|
233
|
+
private classifyError;
|
|
234
|
+
/**
|
|
235
|
+
* Override handleQueryError to use SQLite-specific classification.
|
|
236
|
+
*/
|
|
237
|
+
protected handleQueryError(error: unknown, operation: string, table: string): DatabaseError;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Create a SQLite database adapter.
|
|
241
|
+
*
|
|
242
|
+
* @param config - SQLite adapter configuration
|
|
243
|
+
* @returns A new SqliteAdapter instance
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* // Simple usage with file path
|
|
248
|
+
* const adapter = createSqliteAdapter({
|
|
249
|
+
* url: 'file:./data.db',
|
|
250
|
+
* });
|
|
251
|
+
*
|
|
252
|
+
* // In-memory database
|
|
253
|
+
* const memAdapter = createSqliteAdapter({
|
|
254
|
+
* memory: true,
|
|
255
|
+
* });
|
|
256
|
+
*
|
|
257
|
+
* // Full configuration
|
|
258
|
+
* const adapter = createSqliteAdapter({
|
|
259
|
+
* url: 'file:./data.db',
|
|
260
|
+
* wal: true,
|
|
261
|
+
* foreignKeys: true,
|
|
262
|
+
* busyTimeout: 5000,
|
|
263
|
+
* logger: {
|
|
264
|
+
* query: (sql, params, duration) => console.log(`Query: ${sql}`),
|
|
265
|
+
* },
|
|
266
|
+
* });
|
|
267
|
+
*
|
|
268
|
+
* await adapter.connect();
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
declare function createSqliteAdapter(config: SqliteAdapterConfig): SqliteAdapter;
|
|
272
|
+
/**
|
|
273
|
+
* Type guard to check if a value is a SqliteAdapter.
|
|
274
|
+
*
|
|
275
|
+
* @param value - Value to check
|
|
276
|
+
* @returns True if value is a SqliteAdapter instance
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* if (isSqliteAdapter(adapter)) {
|
|
281
|
+
* // TypeScript knows adapter is SqliteAdapter
|
|
282
|
+
* console.log('Using SQLite');
|
|
283
|
+
* }
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
declare function isSqliteAdapter(value: unknown): value is SqliteAdapter;
|
|
287
|
+
|
|
288
|
+
export { SqliteAdapter, VERSION, createSqliteAdapter, isSqliteAdapter };
|