@symbiote-native/sqlite 0.1.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.
Files changed (128) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +283 -0
  3. package/build/angular/index.d.ts +2 -0
  4. package/build/angular/index.js +2 -0
  5. package/build/angular/sqlite.service.d.ts +41 -0
  6. package/build/angular/sqlite.service.js +127 -0
  7. package/build/core/index.d.ts +10 -0
  8. package/build/core/index.js +6 -0
  9. package/build/core/native-database.d.ts +65 -0
  10. package/build/core/native-database.js +13 -0
  11. package/build/core/native-module.d.ts +25 -0
  12. package/build/core/native-module.js +17 -0
  13. package/build/core/native-session.d.ts +20 -0
  14. package/build/core/native-session.js +1 -0
  15. package/build/core/native-statement.d.ts +45 -0
  16. package/build/core/native-statement.js +6 -0
  17. package/build/core/param-utils.d.ts +28 -0
  18. package/build/core/param-utils.js +126 -0
  19. package/build/core/path-utils.d.ts +6 -0
  20. package/build/core/path-utils.js +29 -0
  21. package/build/core/query-utils.d.ts +17 -0
  22. package/build/core/query-utils.js +37 -0
  23. package/build/core/sqlite-database.d.ts +246 -0
  24. package/build/core/sqlite-database.js +427 -0
  25. package/build/core/sqlite-session.d.ts +84 -0
  26. package/build/core/sqlite-session.js +121 -0
  27. package/build/core/sqlite-statement.d.ts +96 -0
  28. package/build/core/sqlite-statement.js +321 -0
  29. package/build/core/sqlite-tagged-query.d.ts +73 -0
  30. package/build/core/sqlite-tagged-query.js +119 -0
  31. package/build/core/storage.d.ts +107 -0
  32. package/build/core/storage.js +382 -0
  33. package/build/core/types.d.ts +30 -0
  34. package/build/core/types.js +1 -0
  35. package/build/react/index.d.ts +2 -0
  36. package/build/react/index.js +2 -0
  37. package/build/react/sqlite-context.d.ts +25 -0
  38. package/build/react/sqlite-context.js +129 -0
  39. package/build/solid/index.d.ts +2 -0
  40. package/build/solid/index.js +2 -0
  41. package/build/solid/sqlite-context.d.ts +23 -0
  42. package/build/solid/sqlite-context.js +106 -0
  43. package/build/svelte/SQLiteProvider.svelte +88 -0
  44. package/build/svelte/SQLiteProvider.svelte.d.ts +13 -0
  45. package/build/svelte/index.d.ts +3 -0
  46. package/build/svelte/index.js +5 -0
  47. package/build/svelte/sqlite-context.d.ts +11 -0
  48. package/build/svelte/sqlite-context.js +23 -0
  49. package/build/vue/index.d.ts +2 -0
  50. package/build/vue/index.js +2 -0
  51. package/build/vue/sqlite-context.d.ts +21 -0
  52. package/build/vue/sqlite-context.js +69 -0
  53. package/build-ngc/angular/index.d.ts +2 -0
  54. package/build-ngc/angular/index.js +3 -0
  55. package/build-ngc/angular/index.js.map +1 -0
  56. package/build-ngc/angular/sqlite.service.d.ts +44 -0
  57. package/build-ngc/angular/sqlite.service.js +85 -0
  58. package/build-ngc/angular/sqlite.service.js.map +1 -0
  59. package/build-ngc/core/index.d.ts +10 -0
  60. package/build-ngc/core/index.js +7 -0
  61. package/build-ngc/core/index.js.map +1 -0
  62. package/build-ngc/core/native-database.d.ts +65 -0
  63. package/build-ngc/core/native-database.js +14 -0
  64. package/build-ngc/core/native-database.js.map +1 -0
  65. package/build-ngc/core/native-module.d.ts +25 -0
  66. package/build-ngc/core/native-module.js +18 -0
  67. package/build-ngc/core/native-module.js.map +1 -0
  68. package/build-ngc/core/native-session.d.ts +20 -0
  69. package/build-ngc/core/native-session.js +2 -0
  70. package/build-ngc/core/native-session.js.map +1 -0
  71. package/build-ngc/core/native-statement.d.ts +45 -0
  72. package/build-ngc/core/native-statement.js +7 -0
  73. package/build-ngc/core/native-statement.js.map +1 -0
  74. package/build-ngc/core/param-utils.d.ts +28 -0
  75. package/build-ngc/core/param-utils.js +127 -0
  76. package/build-ngc/core/param-utils.js.map +1 -0
  77. package/build-ngc/core/path-utils.d.ts +6 -0
  78. package/build-ngc/core/path-utils.js +30 -0
  79. package/build-ngc/core/path-utils.js.map +1 -0
  80. package/build-ngc/core/query-utils.d.ts +17 -0
  81. package/build-ngc/core/query-utils.js +38 -0
  82. package/build-ngc/core/query-utils.js.map +1 -0
  83. package/build-ngc/core/sqlite-database.d.ts +246 -0
  84. package/build-ngc/core/sqlite-database.js +428 -0
  85. package/build-ngc/core/sqlite-database.js.map +1 -0
  86. package/build-ngc/core/sqlite-session.d.ts +84 -0
  87. package/build-ngc/core/sqlite-session.js +122 -0
  88. package/build-ngc/core/sqlite-session.js.map +1 -0
  89. package/build-ngc/core/sqlite-statement.d.ts +96 -0
  90. package/build-ngc/core/sqlite-statement.js +322 -0
  91. package/build-ngc/core/sqlite-statement.js.map +1 -0
  92. package/build-ngc/core/sqlite-tagged-query.d.ts +73 -0
  93. package/build-ngc/core/sqlite-tagged-query.js +120 -0
  94. package/build-ngc/core/sqlite-tagged-query.js.map +1 -0
  95. package/build-ngc/core/storage.d.ts +107 -0
  96. package/build-ngc/core/storage.js +383 -0
  97. package/build-ngc/core/storage.js.map +1 -0
  98. package/build-ngc/core/types.d.ts +30 -0
  99. package/build-ngc/core/types.js +2 -0
  100. package/build-ngc/core/types.js.map +1 -0
  101. package/native-link.json +12 -0
  102. package/package.json +141 -0
  103. package/src/angular/index.ts +2 -0
  104. package/src/angular/sqlite.service.ts +114 -0
  105. package/src/core/index.ts +40 -0
  106. package/src/core/native-database.ts +118 -0
  107. package/src/core/native-module.ts +57 -0
  108. package/src/core/native-session.ts +64 -0
  109. package/src/core/native-statement.ts +85 -0
  110. package/src/core/param-utils.ts +163 -0
  111. package/src/core/path-utils.ts +38 -0
  112. package/src/core/query-utils.ts +45 -0
  113. package/src/core/sqlite-database.ts +676 -0
  114. package/src/core/sqlite-session.ts +165 -0
  115. package/src/core/sqlite-statement.ts +578 -0
  116. package/src/core/sqlite-tagged-query.ts +160 -0
  117. package/src/core/storage.ts +492 -0
  118. package/src/core/types.ts +33 -0
  119. package/src/react/index.ts +2 -0
  120. package/src/react/sqlite-context.tsx +244 -0
  121. package/src/solid/index.ts +2 -0
  122. package/src/solid/sqlite-context.ts +156 -0
  123. package/src/svelte/SQLiteProvider.svelte +88 -0
  124. package/src/svelte/index.ts +6 -0
  125. package/src/svelte/sqlite-context.ts +32 -0
  126. package/src/svelte/svelte-compile.test-helper.ts +135 -0
  127. package/src/vue/index.ts +2 -0
  128. package/src/vue/sqlite-context.ts +105 -0
@@ -0,0 +1,45 @@
1
+ /** A result returned by `SQLiteStatement.executeAsync()`/`executeSync()`. */
2
+ export type ISQLiteRunResult = {
3
+ /**
4
+ * The last inserted row ID, from
5
+ * [`sqlite3_last_insert_rowid()`](https://www.sqlite.org/c3ref/last_insert_rowid.html).
6
+ */
7
+ lastInsertRowId: number;
8
+ /**
9
+ * The number of rows affected, from
10
+ * [`sqlite3_changes()`](https://www.sqlite.org/c3ref/changes.html).
11
+ */
12
+ changes: number;
13
+ };
14
+ /**
15
+ * Bind parameters to a prepared statement — a single array/variadic args for unnamed
16
+ * parameters (`?`), or a single object for named parameters (`:VVV`, `@VVV`, `$VVV`).
17
+ */
18
+ export type ISQLiteBindValue = string | number | null | boolean | ISQLiteBindBlobValue;
19
+ export type ISQLiteBindParams = Record<string, ISQLiteBindValue> | ISQLiteBindValue[];
20
+ export type ISQLiteVariadicBindParams = ISQLiteBindValue[];
21
+ export type ISQLiteBindBlobValue = Uint8Array | ArrayBuffer;
22
+ export type ISQLiteBindPrimitiveParams = Record<string, Exclude<ISQLiteBindValue, ISQLiteBindBlobValue>>;
23
+ export type ISQLiteBindBlobParams = Record<string, ISQLiteBindBlobValue>;
24
+ export type ISQLiteColumnNames = string[];
25
+ export type ISQLiteColumnValues = any[];
26
+ export type ISQLiteAnyDatabase = any;
27
+ /** An instance of a prepared SQLite statement. */
28
+ export declare class NativeStatement {
29
+ runAsync(database: ISQLiteAnyDatabase, bindParams: ISQLiteBindPrimitiveParams, bindBlobParams: ISQLiteBindBlobParams, shouldPassAsArray: boolean): Promise<ISQLiteRunResult & {
30
+ firstRowValues: ISQLiteColumnValues;
31
+ }>;
32
+ stepAsync(database: ISQLiteAnyDatabase): Promise<ISQLiteColumnValues | null | undefined>;
33
+ getAllAsync(database: ISQLiteAnyDatabase): Promise<ISQLiteColumnValues[]>;
34
+ resetAsync(database: ISQLiteAnyDatabase): Promise<void>;
35
+ getColumnNamesAsync(): Promise<ISQLiteColumnNames>;
36
+ finalizeAsync(database: ISQLiteAnyDatabase): Promise<void>;
37
+ runSync(database: ISQLiteAnyDatabase, bindParams: ISQLiteBindPrimitiveParams, bindBlobParams: ISQLiteBindBlobParams, shouldPassAsArray: boolean): ISQLiteRunResult & {
38
+ firstRowValues: ISQLiteColumnValues;
39
+ };
40
+ stepSync(database: ISQLiteAnyDatabase): ISQLiteColumnValues | null | undefined;
41
+ getAllSync(database: ISQLiteAnyDatabase): ISQLiteColumnValues[];
42
+ resetSync(database: ISQLiteAnyDatabase): void;
43
+ getColumnNamesSync(): string[];
44
+ finalizeSync(database: ISQLiteAnyDatabase): void;
45
+ }
@@ -0,0 +1,6 @@
1
+ // Ported from expo-sqlite's NativeStatement.ts (.vendors/expo @ origin/sdk-57,
2
+ // packages/expo-sqlite/src/NativeStatement.ts), renamed with this repo's `I`-prefix convention.
3
+ //
4
+ // A plain native class, instantiated directly (`new ExpoSQLite.NativeStatement()`) and then
5
+ // mutated in place by `NativeDatabase.prepareAsync`/`prepareSync` — see `sqlite-database.ts`.
6
+ export {};
@@ -0,0 +1,28 @@
1
+ import type { ISQLiteBindBlobParams, ISQLiteBindPrimitiveParams, ISQLiteColumnNames, ISQLiteColumnValues } from './native-statement';
2
+ /**
3
+ * Normalizes bind params into `[primitiveParams, blobParams, shouldPassAsArray]` for the
4
+ * native module. `params` is untyped because the public overloads
5
+ * (`ISQLiteBindParams` vs. variadic `ISQLiteVariadicBindParams`) already constrain what a
6
+ * type-checked caller can pass here — this only has to survive a caller that bypasses them.
7
+ * @hidden
8
+ */
9
+ export declare function normalizeParams(...params: unknown[]): [ISQLiteBindPrimitiveParams, ISQLiteBindBlobParams, boolean];
10
+ /**
11
+ * Composes `columnNames` and `columnValues` into a row object.
12
+ * @hidden
13
+ */
14
+ export declare function composeRow<T>(columnNames: ISQLiteColumnNames, columnValues: ISQLiteColumnValues): T;
15
+ /**
16
+ * Composes `columnNames` and `columnValuesList` into an array of row objects.
17
+ * @hidden
18
+ */
19
+ export declare function composeRows<T>(columnNames: ISQLiteColumnNames, columnValuesList: ISQLiteColumnValues[]): T[];
20
+ /**
21
+ * Normalizes the index for `SQLiteStorage.getKeyByIndexAsync`/`getKeyByIndexSync`. `index` is
22
+ * `unknown` (upstream types it `any`) because the function coerces defensively via `Number()` —
23
+ * a caller reaching this from untyped host data (e.g. a `web` `Storage` polyfill) may hand it
24
+ * anything.
25
+ * @returns The normalized index, or `null` when out of bounds.
26
+ * @hidden
27
+ */
28
+ export declare function normalizeStorageIndex(index: unknown): number | null;
@@ -0,0 +1,126 @@
1
+ function isPlainRecord(value) {
2
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
3
+ }
4
+ /**
5
+ * Normalizes bind params into `[primitiveParams, blobParams, shouldPassAsArray]` for the
6
+ * native module. `params` is untyped because the public overloads
7
+ * (`ISQLiteBindParams` vs. variadic `ISQLiteVariadicBindParams`) already constrain what a
8
+ * type-checked caller can pass here — this only has to survive a caller that bypasses them.
9
+ * @hidden
10
+ */
11
+ export function normalizeParams(...params) {
12
+ const rawParams = params.length > 1 ? params : params[0];
13
+ let bindParams = rawParams ?? [];
14
+ if (typeof bindParams !== 'object' ||
15
+ bindParams === null ||
16
+ bindParams instanceof ArrayBuffer ||
17
+ ArrayBuffer.isView(bindParams)) {
18
+ bindParams = [bindParams];
19
+ }
20
+ const shouldPassAsArray = Array.isArray(bindParams);
21
+ const entries = Array.isArray(bindParams)
22
+ ? bindParams.map((value, index) => [
23
+ String(index),
24
+ value,
25
+ ])
26
+ : isPlainRecord(bindParams)
27
+ ? Object.entries(bindParams)
28
+ : [];
29
+ const primitiveParams = {};
30
+ const blobParams = {};
31
+ for (const [key, value] of entries) {
32
+ if (value instanceof Uint8Array || value instanceof ArrayBuffer) {
33
+ blobParams[key] = value;
34
+ }
35
+ else if (typeof value === 'boolean') {
36
+ primitiveParams[key] = value ? 1 : 0;
37
+ }
38
+ else if (value === null ||
39
+ typeof value === 'string' ||
40
+ typeof value === 'number') {
41
+ primitiveParams[key] = value;
42
+ }
43
+ else {
44
+ // Not a recognized ISQLiteBindValue at this point (undefined, an object, an array, a
45
+ // function...) — keep it as-is, matching upstream's `value ?? null`, which only guards
46
+ // null/undefined and otherwise passes the value through untouched. Binding an invalid
47
+ // value is the native bridge's problem at bind time; this function only reshapes params.
48
+ // I/O edge: `value` is genuinely unknown here — a caller that bypassed the public
49
+ // `ISQLiteBindParams` overloads is the only way to reach this branch.
50
+ primitiveParams[key] = (value ?? null);
51
+ }
52
+ }
53
+ return [primitiveParams, blobParams, shouldPassAsArray];
54
+ }
55
+ /**
56
+ * Composes `columnNames` and `columnValues` into a row object.
57
+ * @hidden
58
+ */
59
+ export function composeRow(columnNames, columnValues) {
60
+ const row = {};
61
+ if (columnNames.length !== columnValues.length) {
62
+ throw new Error(`Column names and values count mismatch. Names: ${columnNames.length}, Values: ${columnValues.length}`);
63
+ }
64
+ for (let i = 0; i < columnNames.length; i++) {
65
+ const columnName = columnNames[i];
66
+ if (columnName != null) {
67
+ row[columnName] = columnValues[i];
68
+ }
69
+ }
70
+ // I/O edge: T is the caller-specified row shape (SQLiteStatement.executeAsync<T>, etc.) — the
71
+ // native bridge has no way to describe it, so it is asserted here, at the narrowest point
72
+ // native data enters the type system.
73
+ return row;
74
+ }
75
+ /**
76
+ * Composes `columnNames` and `columnValuesList` into an array of row objects.
77
+ * @hidden
78
+ */
79
+ export function composeRows(columnNames, columnValuesList) {
80
+ const firstRow = columnValuesList[0];
81
+ if (firstRow == null) {
82
+ return [];
83
+ }
84
+ if (columnNames.length !== firstRow.length) {
85
+ // Only the first row is checked — SQLite returns the same column count for every row. A
86
+ // shorter LATER row is not an error case (unlike composeRow's own check, which this
87
+ // deliberately does NOT delegate to) — a missing trailing value just composes as
88
+ // `undefined`, matching upstream's inline (non-composeRow) row construction here.
89
+ throw new Error(`Column names and values count mismatch. Names: ${columnNames.length}, Values: ${firstRow.length}`);
90
+ }
91
+ const results = [];
92
+ for (const columnValues of columnValuesList) {
93
+ const row = {};
94
+ for (let i = 0; i < columnNames.length; i++) {
95
+ const columnName = columnNames[i];
96
+ if (columnName != null) {
97
+ row[columnName] = columnValues[i];
98
+ }
99
+ }
100
+ // I/O edge, same as composeRow above.
101
+ results.push(row);
102
+ }
103
+ return results;
104
+ }
105
+ /**
106
+ * Normalizes the index for `SQLiteStorage.getKeyByIndexAsync`/`getKeyByIndexSync`. `index` is
107
+ * `unknown` (upstream types it `any`) because the function coerces defensively via `Number()` —
108
+ * a caller reaching this from untyped host data (e.g. a `web` `Storage` polyfill) may hand it
109
+ * anything.
110
+ * @returns The normalized index, or `null` when out of bounds.
111
+ * @hidden
112
+ */
113
+ export function normalizeStorageIndex(index) {
114
+ const value = Math.floor(Number(index));
115
+ if (Object.is(value, -0)) {
116
+ return 0;
117
+ }
118
+ if (!Number.isSafeInteger(value)) {
119
+ // Chromium uses a zero index when the index is out of bounds.
120
+ return 0;
121
+ }
122
+ if (value < 0) {
123
+ return null;
124
+ }
125
+ return value;
126
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Creates a normalized database path by combining the directory and database name — no
3
+ * trailing slash on the directory, no leading slash on the name, so the join never doubles up.
4
+ */
5
+ export declare function createDatabasePath(databaseName: string, directory?: string): string;
6
+ export declare function basename(path: string): string;
@@ -0,0 +1,29 @@
1
+ // Ported verbatim (logic unchanged) from expo-sqlite's pathUtils.ts (.vendors/expo @
2
+ // origin/sdk-57, packages/expo-sqlite/src/pathUtils.ts).
3
+ import { expoSQLite } from './native-module.js';
4
+ function resolveDbDirectory(directory) {
5
+ const resolvedDirectory = directory ?? expoSQLite.defaultDatabaseDirectory;
6
+ if (resolvedDirectory == null) {
7
+ throw new Error('Both provided directory and defaultDatabaseDirectory are null.');
8
+ }
9
+ return resolvedDirectory;
10
+ }
11
+ /**
12
+ * Creates a normalized database path by combining the directory and database name — no
13
+ * trailing slash on the directory, no leading slash on the name, so the join never doubles up.
14
+ */
15
+ export function createDatabasePath(databaseName, directory) {
16
+ if (databaseName === ':memory:')
17
+ return databaseName;
18
+ const resolvedDirectory = resolveDbDirectory(directory);
19
+ function removeTrailingSlash(path) {
20
+ return path.replace(/\/*$/, '');
21
+ }
22
+ function removeLeadingSlash(path) {
23
+ return path.replace(/^\/+/, '');
24
+ }
25
+ return `${removeTrailingSlash(resolvedDirectory)}/${removeLeadingSlash(databaseName)}`;
26
+ }
27
+ export function basename(path) {
28
+ return path.substring(path.lastIndexOf('/') + 1);
29
+ }
@@ -0,0 +1,17 @@
1
+ /** Information about a parsed SQL query. */
2
+ export type ISQLParsedInfo = {
3
+ canReturnRows: boolean;
4
+ };
5
+ /**
6
+ * Parses a SQL query to determine whether it can return rows, using a priority-based approach:
7
+ * `RETURNING` always returns rows; a bare mutation keyword never does; a query keyword does;
8
+ * anything else does not.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * parseSQLQuery('SELECT * FROM users') // { canReturnRows: true }
13
+ * parseSQLQuery('INSERT INTO users VALUES (1)') // { canReturnRows: false }
14
+ * parseSQLQuery('INSERT INTO users VALUES (1) RETURNING *') // { canReturnRows: true }
15
+ * ```
16
+ */
17
+ export declare function parseSQLQuery(query: string): ISQLParsedInfo;
@@ -0,0 +1,37 @@
1
+ // Ported verbatim (logic unchanged) from expo-sqlite's queryUtils.ts (.vendors/expo @
2
+ // origin/sdk-57, packages/expo-sqlite/src/queryUtils.ts), renamed with this repo's `I`-prefix
3
+ // convention. A reimplementation of Bun's SQLite query parser (credited upstream).
4
+ const SINGLE_QUOTED_STRING = /'(?:[^']|'')*'/g;
5
+ const DOUBLE_QUOTED_STRING = /"(?:[^"]|"")*"/g;
6
+ const RETURNING_KEYWORD = /\bRETURNING\b/i;
7
+ const MUTATION_KEYWORDS = /\b(INSERT|UPDATE|DELETE|CREATE|ALTER|DROP)\b/i;
8
+ const QUERY_KEYWORDS = /\b(SELECT|PRAGMA|WITH|EXPLAIN)\b/i;
9
+ /**
10
+ * Parses a SQL query to determine whether it can return rows, using a priority-based approach:
11
+ * `RETURNING` always returns rows; a bare mutation keyword never does; a query keyword does;
12
+ * anything else does not.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * parseSQLQuery('SELECT * FROM users') // { canReturnRows: true }
17
+ * parseSQLQuery('INSERT INTO users VALUES (1)') // { canReturnRows: false }
18
+ * parseSQLQuery('INSERT INTO users VALUES (1) RETURNING *') // { canReturnRows: true }
19
+ * ```
20
+ */
21
+ export function parseSQLQuery(query) {
22
+ // SQLite doubles quotes to escape them ('don''t', "test""quote") — strip quoted strings first
23
+ // so a keyword INSIDE a string literal can't produce a false positive.
24
+ const cleaned = query
25
+ .replace(SINGLE_QUOTED_STRING, "''")
26
+ .replace(DOUBLE_QUOTED_STRING, '""');
27
+ if (RETURNING_KEYWORD.test(cleaned)) {
28
+ return { canReturnRows: true };
29
+ }
30
+ if (MUTATION_KEYWORDS.test(cleaned)) {
31
+ return { canReturnRows: false };
32
+ }
33
+ if (QUERY_KEYWORDS.test(cleaned)) {
34
+ return { canReturnRows: true };
35
+ }
36
+ return { canReturnRows: false };
37
+ }
@@ -0,0 +1,246 @@
1
+ import type { EventSubscription } from 'expo-modules-core';
2
+ import { NativeDatabase } from './native-database';
3
+ import type { ISQLiteOpenOptions } from './native-database';
4
+ import { SQLiteSession } from './sqlite-session';
5
+ import { SQLiteStatement } from './sqlite-statement';
6
+ import type { ISQLiteBindParams, ISQLiteRunResult, ISQLiteVariadicBindParams } from './sqlite-statement';
7
+ import { SQLiteTaggedQuery } from './sqlite-tagged-query';
8
+ import type { IDatabaseChangeEvent, IOpenDatabaseOptions } from './types';
9
+ export type { ISQLiteOpenOptions } from './native-database';
10
+ export type { IDatabaseChangeEvent, IOnInitCallback, IOpenDatabaseOptions, } from './types';
11
+ /** A SQLite database. */
12
+ export declare class SQLiteDatabase {
13
+ readonly databasePath: string;
14
+ readonly options: ISQLiteOpenOptions;
15
+ readonly nativeDatabase: NativeDatabase;
16
+ constructor(databasePath: string, options: ISQLiteOpenOptions, nativeDatabase: NativeDatabase);
17
+ /** Whether the database is currently in a transaction. */
18
+ isInTransactionAsync(): Promise<boolean>;
19
+ /** Closes the database. */
20
+ closeAsync(): Promise<void>;
21
+ /**
22
+ * Executes all SQL queries in the supplied string.
23
+ * > **Note:** The queries are not escaped for you — be careful when constructing them.
24
+ */
25
+ execAsync(source: string): Promise<void>;
26
+ /**
27
+ * [Serializes the database](https://sqlite.org/c3ref/serialize.html) as a `Uint8Array`.
28
+ * @param databaseName The attached database name. Defaults to `main`.
29
+ */
30
+ serializeAsync(databaseName?: string): Promise<Uint8Array>;
31
+ /**
32
+ * Creates a [prepared statement](https://www.sqlite.org/c3ref/prepare.html) from `source`.
33
+ */
34
+ prepareAsync(source: string): Promise<SQLiteStatement>;
35
+ /**
36
+ * Creates a new session for the database.
37
+ * @see [`sqlite3session_create`](https://www.sqlite.org/session/sqlite3session_create.html)
38
+ * @param dbName The database name to create a session for. Defaults to `main`.
39
+ */
40
+ createSessionAsync(dbName?: string): Promise<SQLiteSession>;
41
+ /**
42
+ * Loads a SQLite extension.
43
+ * @param libPath The path to the extension library file.
44
+ * @param entryPoint The extension's entry point. Inferred by
45
+ * [`sqlite3_load_extension`](https://www.sqlite.org/c3ref/load_extension.html) when omitted.
46
+ */
47
+ loadExtensionAsync(libPath: string, entryPoint?: string): Promise<void>;
48
+ /**
49
+ * Executes a transaction, committing/rolling back automatically based on `task`'s result.
50
+ *
51
+ * > **Note:** Not exclusive — other async queries can interleave, so the order of execution
52
+ * > relative to a query issued outside the transaction is not guaranteed. Use
53
+ * > `withExclusiveTransactionAsync` when that matters.
54
+ */
55
+ withTransactionAsync(task: () => Promise<void>): Promise<void>;
56
+ /**
57
+ * Executes a transaction, committing/rolling back automatically based on `task`'s result.
58
+ * The transaction may be exclusive: once it becomes a write transaction, other async write
59
+ * queries abort with a `database is locked` error.
60
+ *
61
+ * > **Note:** Not supported on web.
62
+ *
63
+ * @param task Any queries inside it must run on the `txn` object it receives — a private
64
+ * `SQLiteDatabase` subclass bound to the exclusive connection, typed here as the base class
65
+ * since the subclass is an implementation detail, not a public export.
66
+ */
67
+ withExclusiveTransactionAsync(task: (txn: SQLiteDatabase) => Promise<void>): Promise<void>;
68
+ /** Whether the database is currently in a transaction. */
69
+ isInTransactionSync(): boolean;
70
+ /** Closes the database. */
71
+ closeSync(): void;
72
+ /**
73
+ * Executes all SQL queries in the supplied string.
74
+ * > **Note:** The queries are not escaped for you. Running heavy tasks with this function can
75
+ * > block the JavaScript thread.
76
+ */
77
+ execSync(source: string): void;
78
+ /**
79
+ * [Serializes the database](https://sqlite.org/c3ref/serialize.html) as a `Uint8Array`.
80
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
81
+ */
82
+ serializeSync(databaseName?: string): Uint8Array;
83
+ /**
84
+ * Creates a [prepared statement](https://www.sqlite.org/c3ref/prepare.html) from `source`.
85
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
86
+ */
87
+ prepareSync(source: string): SQLiteStatement;
88
+ /**
89
+ * Creates a new session for the database.
90
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
91
+ * @see [`sqlite3session_create`](https://www.sqlite.org/session/sqlite3session_create.html)
92
+ */
93
+ createSessionSync(dbName?: string): SQLiteSession;
94
+ /**
95
+ * Loads a SQLite extension.
96
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
97
+ */
98
+ loadExtensionSync(libPath: string, entryPoint?: string): void;
99
+ /**
100
+ * Executes a transaction, committing/rolling back automatically based on `task`'s result.
101
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
102
+ */
103
+ withTransactionSync(task: () => void): void;
104
+ /**
105
+ * Executes SQL queries using tagged template literals (Bun-style), automatically parameterized
106
+ * against SQL injection. Directly awaitable (returns rows/`ISQLiteRunResult`); use `.values()`,
107
+ * `.first()`, `.each()`, or the `*Sync` variants for other shapes.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const users = await db.sql<User>`SELECT * FROM users WHERE age > ${21}`;
112
+ * const rows = await db.sql`SELECT name, age FROM users`.values();
113
+ * const user = await db.sql<User>`SELECT * FROM users WHERE id = ${userId}`.first();
114
+ * ```
115
+ */
116
+ sql: <T = unknown>(strings: TemplateStringsArray, ...values: unknown[]) => SQLiteTaggedQuery<T>;
117
+ /**
118
+ * A convenience wrapper around `prepareAsync()`, `SQLiteStatement.executeAsync()`, and
119
+ * `SQLiteStatement.finalizeAsync()`.
120
+ */
121
+ runAsync(source: string, params: ISQLiteBindParams): Promise<ISQLiteRunResult>;
122
+ /** @hidden */
123
+ runAsync(source: string, ...params: ISQLiteVariadicBindParams): Promise<ISQLiteRunResult>;
124
+ /**
125
+ * A convenience wrapper around `prepareAsync()`, `SQLiteStatement.executeAsync()`,
126
+ * `ISQLiteExecuteAsyncResult.getFirstAsync()`, and `SQLiteStatement.finalizeAsync()`.
127
+ */
128
+ getFirstAsync<T>(source: string, params: ISQLiteBindParams): Promise<T | null>;
129
+ /** @hidden */
130
+ getFirstAsync<T>(source: string, ...params: ISQLiteVariadicBindParams): Promise<T | null>;
131
+ /**
132
+ * A convenience wrapper around `prepareAsync()`, `SQLiteStatement.executeAsync()`, the
133
+ * `ISQLiteExecuteAsyncResult` async iterator, and `SQLiteStatement.finalizeAsync()`.
134
+ */
135
+ getEachAsync<T>(source: string, params: ISQLiteBindParams): AsyncIterableIterator<T>;
136
+ /** @hidden */
137
+ getEachAsync<T>(source: string, ...params: ISQLiteVariadicBindParams): AsyncIterableIterator<T>;
138
+ /**
139
+ * A convenience wrapper around `prepareAsync()`, `SQLiteStatement.executeAsync()`,
140
+ * `ISQLiteExecuteAsyncResult.getAllAsync()`, and `SQLiteStatement.finalizeAsync()`.
141
+ */
142
+ getAllAsync<T>(source: string, params: ISQLiteBindParams): Promise<T[]>;
143
+ /** @hidden */
144
+ getAllAsync<T>(source: string, ...params: ISQLiteVariadicBindParams): Promise<T[]>;
145
+ /**
146
+ * A convenience wrapper around `prepareSync()`, `SQLiteStatement.executeSync()`, and
147
+ * `SQLiteStatement.finalizeSync()`.
148
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
149
+ */
150
+ runSync(source: string, params: ISQLiteBindParams): ISQLiteRunResult;
151
+ /** @hidden */
152
+ runSync(source: string, ...params: ISQLiteVariadicBindParams): ISQLiteRunResult;
153
+ /**
154
+ * A convenience wrapper around `prepareSync()`, `SQLiteStatement.executeSync()`,
155
+ * `ISQLiteExecuteSyncResult.getFirstSync()`, and `SQLiteStatement.finalizeSync()`.
156
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
157
+ */
158
+ getFirstSync<T>(source: string, params: ISQLiteBindParams): T | null;
159
+ /** @hidden */
160
+ getFirstSync<T>(source: string, ...params: ISQLiteVariadicBindParams): T | null;
161
+ /**
162
+ * A convenience wrapper around `prepareSync()`, `SQLiteStatement.executeSync()`, the
163
+ * `ISQLiteExecuteSyncResult` iterator, and `SQLiteStatement.finalizeSync()`.
164
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
165
+ */
166
+ getEachSync<T>(source: string, params: ISQLiteBindParams): IterableIterator<T>;
167
+ /** @hidden */
168
+ getEachSync<T>(source: string, ...params: ISQLiteVariadicBindParams): IterableIterator<T>;
169
+ /**
170
+ * A convenience wrapper around `prepareSync()`, `SQLiteStatement.executeSync()`,
171
+ * `ISQLiteExecuteSyncResult.getAllSync()`, and `SQLiteStatement.finalizeSync()`.
172
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
173
+ */
174
+ getAllSync<T>(source: string, params: ISQLiteBindParams): T[];
175
+ /** @hidden */
176
+ getAllSync<T>(source: string, ...params: ISQLiteVariadicBindParams): T[];
177
+ /** Synchronizes the local database with the remote libSQL server (libSQL integration only). */
178
+ syncLibSQL(): Promise<void>;
179
+ }
180
+ /** The default directory new databases are created in. */
181
+ export declare const defaultDatabaseDirectory: string;
182
+ /**
183
+ * Pre-bundled SQLite extensions. Bundling one (e.g. `sqlite-vec`) is a manual native-config
184
+ * step this package does not automate — see the README.
185
+ */
186
+ export declare const bundledExtensions: Record<string, {
187
+ libPath: string;
188
+ entryPoint: string;
189
+ } | undefined>;
190
+ /**
191
+ * Opens a database.
192
+ * @param databaseName The database file name to open.
193
+ * @param options Open options — see `IOpenDatabaseOptions` for the `onInit` deviation from
194
+ * upstream (documented in the README).
195
+ * @param directory The directory the database file is located in. Defaults to
196
+ * `defaultDatabaseDirectory`.
197
+ */
198
+ export declare function openDatabaseAsync(databaseName: string, options?: IOpenDatabaseOptions, directory?: string): Promise<SQLiteDatabase>;
199
+ /**
200
+ * Opens a database.
201
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
202
+ */
203
+ export declare function openDatabaseSync(databaseName: string, options?: IOpenDatabaseOptions, directory?: string): SQLiteDatabase;
204
+ /**
205
+ * Given `Uint8Array` data, [deserializes it to an in-memory database](https://sqlite.org/c3ref/deserialize.html).
206
+ * @param serializedData The binary array from `SQLiteDatabase.serializeAsync()`.
207
+ */
208
+ export declare function deserializeDatabaseAsync(serializedData: Uint8Array, options?: ISQLiteOpenOptions): Promise<SQLiteDatabase>;
209
+ /**
210
+ * Given `Uint8Array` data, [deserializes it to an in-memory database](https://sqlite.org/c3ref/deserialize.html).
211
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
212
+ */
213
+ export declare function deserializeDatabaseSync(serializedData: Uint8Array, options?: ISQLiteOpenOptions): SQLiteDatabase;
214
+ /** Deletes a database file. */
215
+ export declare function deleteDatabaseAsync(databaseName: string, directory?: string): Promise<void>;
216
+ /**
217
+ * Deletes a database file.
218
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
219
+ */
220
+ export declare function deleteDatabaseSync(databaseName: string, directory?: string): void;
221
+ /**
222
+ * Backs up a database to another database.
223
+ * @see https://www.sqlite.org/c3ref/backup_finish.html
224
+ */
225
+ export declare function backupDatabaseAsync(options: {
226
+ sourceDatabase: SQLiteDatabase;
227
+ sourceDatabaseName?: string;
228
+ destDatabase: SQLiteDatabase;
229
+ destDatabaseName?: string;
230
+ }): Promise<void>;
231
+ /**
232
+ * Backs up a database to another database.
233
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread.
234
+ * @see https://www.sqlite.org/c3ref/backup_finish.html
235
+ */
236
+ export declare function backupDatabaseSync(options: {
237
+ sourceDatabase: SQLiteDatabase;
238
+ sourceDatabaseName?: string;
239
+ destDatabase: SQLiteDatabase;
240
+ destDatabaseName?: string;
241
+ }): void;
242
+ /**
243
+ * Adds a listener for database changes.
244
+ * > **Note:** requires `enableChangeListener: true` in `ISQLiteOpenOptions` when opening.
245
+ */
246
+ export declare function addDatabaseChangeListener(listener: (event: IDatabaseChangeEvent) => void): EventSubscription;