web-sqlite-js 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.
Files changed (3) hide show
  1. package/dist/index.d.ts +68 -0
  2. package/dist/index.js +13107 -0
  3. package/package.json +64 -0
@@ -0,0 +1,68 @@
1
+ /** Primary DB interface used by client code. */
2
+ declare interface DBInterface {
3
+ /**
4
+ * Execute a SQL script (one or more statements) without returning rows.
5
+ * Intended for migrations, schema setup, or bulk SQL execution.
6
+ * @param sql - SQL string to execute.
7
+ * @param params - Optional bind parameters for the statement.
8
+ */
9
+ exec(sql: string, params?: SQLParams): Promise<ExecResult>;
10
+ /**
11
+ * Execute a query and return all result rows as an array of objects.
12
+ * @param sql - SELECT SQL to execute.
13
+ * @param params - Optional bind parameters for the query.
14
+ */
15
+ query<T = unknown>(sql: string, params?: SQLParams): Promise<T[]>;
16
+ /**
17
+ * Run a callback inside a transaction. The implementation should BEGIN before calling `fn`
18
+ * and COMMIT on success or ROLLBACK on error.
19
+ * @param fn - Callback that receives a DBInterface and performs transactional work.
20
+ */
21
+ transaction<T>(fn: transactionCallback<T>): Promise<T>;
22
+ /** Close the database and release resources. */
23
+ close(): Promise<void>;
24
+ }
25
+
26
+ /**
27
+ * Metadata returned for non-query statements.
28
+ * @property changes Number of rows changed by last operation (may be bigint on some builds).
29
+ * @property lastInsertRowid Last inserted row id when applicable.
30
+ */
31
+ declare type ExecResult = {
32
+ changes?: number | bigint;
33
+ lastInsertRowid?: number | bigint;
34
+ };
35
+
36
+ /**
37
+ * Opens a SQLite database connection.
38
+ *
39
+ * @param filename - The path to the SQLite database file to open.
40
+ * @param options - Optional configuration options for opening the database.
41
+ * @returns A promise that resolves to a DBInterface object providing methods to interact with the database.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const db = await openDB('./mydata.db');
46
+ * const results = await db.query('SELECT * FROM users');
47
+ * await db.close();
48
+ * ```
49
+ */
50
+ declare const openDB: (filename: string, options?: WorkerOpenDBOptions) => Promise<DBInterface>;
51
+ export default openDB;
52
+ export { openDB }
53
+
54
+ /** A bindable parameter collection: positional or named. */
55
+ declare type SQLParams = SqlValue[] | Record<string, SqlValue>;
56
+
57
+ /**
58
+ * A value which can be bound to a SQLite parameter.
59
+ */
60
+ declare type SqlValue = null | number | string | boolean | bigint | Uint8Array | ArrayBuffer;
61
+
62
+ declare type transactionCallback<T> = (db: Pick<DBInterface, "exec" | "query">) => Promise<T>;
63
+
64
+ declare type WorkerOpenDBOptions = {
65
+ debug?: boolean;
66
+ };
67
+
68
+ export { }