@op-engineering/op-sqlite 15.0.2 → 15.0.3

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.
@@ -1 +1 @@
1
- {"version":3,"names":["open","Storage","constructor","options","db","name","executeSync","getItem","key","result","execute","value","rows","Error","getItemSync","setItem","toString","setItemSync","removeItem","removeItemSync","clear","clearSync","getAllKeys","map","row","delete"],"sourceRoot":"../../src","sources":["Storage.ts"],"mappings":";;AACA,SAASA,IAAI,QAAQ,gBAAa;AAOlC;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,CAAC;EAGnBC,WAAWA,CAACC,OAAuB,EAAE;IACnC,IAAI,CAACC,EAAE,GAAGJ,IAAI,CAAC;MAAE,GAAGG,OAAO;MAAEE,IAAI,EAAE;IAA4B,CAAC,CAAC;IACjE,IAAI,CAACD,EAAE,CAACE,WAAW,CAAC,4BAA4B,CAAC;IACjD,IAAI,CAACF,EAAE,CAACE,WAAW,CACjB,qFACF,CAAC;EACH;EAEA,MAAMC,OAAOA,CAACC,GAAW,EAA+B;IACtD,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACL,EAAE,CAACM,OAAO,CAClC,yCAAyC,EACzC,CAACF,GAAG,CACN,CAAC;IAED,IAAIG,KAAK,GAAGF,MAAM,CAACG,IAAI,CAAC,CAAC,CAAC,EAAED,KAAK;IACjC,IAAI,OAAOA,KAAK,KAAK,WAAW,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7D,MAAM,IAAIE,KAAK,CAAC,qCAAqC,CAAC;IACxD;IACA,OAAOF,KAAK;EACd;EAEAG,WAAWA,CAACN,GAAW,EAAsB;IAC3C,MAAMC,MAAM,GAAG,IAAI,CAACL,EAAE,CAACE,WAAW,CAChC,yCAAyC,EACzC,CAACE,GAAG,CACN,CAAC;IAED,IAAIG,KAAK,GAAGF,MAAM,CAACG,IAAI,CAAC,CAAC,CAAC,EAAED,KAAK;IACjC,IAAI,OAAOA,KA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open","Storage","constructor","options","db","name","executeSync","getItem","key","result","execute","value","rows","Error","getItemSync","setItem","toString","setItemSync","removeItem","removeItemSync","clear","clearSync","getAllKeys","map","row","delete"],"sourceRoot":"../../src","sources":["Storage.ts"],"mappings":";;AAAA,SAASA,IAAI,QAAQ,gBAAa;AAQlC;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,CAAC;EAGnBC,WAAWA,CAACC,OAAuB,EAAE;IACnC,IAAI,CAACC,EAAE,GAAGJ,IAAI,CAAC;MAAE,GAAGG,OAAO;MAAEE,IAAI,EAAE;IAA4B,CAAC,CAAC;IACjE,IAAI,CAACD,EAAE,CAACE,WAAW,CAAC,4BAA4B,CAAC;IACjD,IAAI,CAACF,EAAE,CAACE,WAAW,CACjB,qFACF,CAAC;EACH;EAEA,MAAMC,OAAOA,CAACC,GAAW,EAA+B;IACtD,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACL,EAAE,CAACM,OAAO,CAClC,yCAAyC,EACzC,CAACF,GAAG,CACN,CAAC;IAED,IAAIG,KAAK,GAAGF,MAAM,CAACG,IAAI,CAAC,CAAC,CAAC,EAAED,KAAK;IACjC,IAAI,OAAOA,KAAK,KAAK,WAAW,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7D,MAAM,IAAIE,KAAK,CAAC,qCAAqC,CAAC;IACxD;IACA,OAAOF,KAAK;EACd;EAEAG,WAAWA,CAACN,GAAW,EAAsB;IAC3C,MAAMC,MAAM,GAAG,IAAI,CAACL,EAAE,CAACE,WAAW,CAChC,yCAAyC,EACzC,CAACE,GAAG,CACN,CAAC;IAED,IAAIG,KAAK,GAAGF,MAAM,CAACG,IAAI,CAAC,CAAC,CAAC,EAAED,KAAK;IACjC,IAAI,OAAOA,KAAK,KAAK,WAAW,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7D,MAAM,IAAIE,KAAK,CAAC,qCAAqC,CAAC;IACxD;IAEA,OAAOF,KAAK;EACd;EAEA,MAAMI,OAAOA,CAACP,GAAW,EAAEG,KAAa,EAAE;IACxC,MAAM,IAAI,CAACP,EAAE,CAACM,OAAO,CACnB,2DAA2D,EAC3D,CAACF,GAAG,EAAEG,KAAK,CAACK,QAAQ,CAAC,CAAC,CACxB,CAAC;EACH;EAEAC,WAAWA,CAACT,GAAW,EAAEG,KAAa,EAAE;IACtC,IAAI,CAACP,EAAE,CAACE,WAAW,CACjB,2DAA2D,EAC3D,CAACE,GAAG,EAAEG,KAAK,CAACK,QAAQ,CAAC,CAAC,CACxB,CAAC;EACH;EAEA,MAAME,UAAUA,CAACV,GAAW,EAAE;IAC5B,MAAM,IAAI,CAACJ,EAAE,CAACM,OAAO,CAAC,mCAAmC,EAAE,CAACF,GAAG,CAAC,CAAC;EACnE;EAEAW,cAAcA,CAACX,GAAW,EAAE;IAC1B,IAAI,CAACJ,EAAE,CAACE,WAAW,CAAC,mCAAmC,EAAE,CAACE,GAAG,CAAC,CAAC;EACjE;EAEA,MAAMY,KAAKA,CAAA,EAAG;IACZ,MAAM,IAAI,CAAChB,EAAE,CAACM,OAAO,CAAC,qBAAqB,CAAC;EAC9C;EAEAW,SAASA,CAAA,EAAG;IACV,IAAI,CAACjB,EAAE,CAACE,WAAW,CAAC,qBAAqB,CAAC;EAC5C;EAEAgB,UAAUA,CAAA,EAAG;IACX,OAAO,IAAI,CAAClB,EAAE,CACXE,WAAW,CAAC,yBAAyB,CAAC,CACtCM,IAAI,CAACW,GAAG,CAAEC,GAAQ,IAAKA,GAAG,CAAChB,GAAG,CAAC;EACpC;;EAEA;AACF;AACA;EACEiB,MAAMA,CAAA,EAAG;IACP,IAAI,CAACrB,EAAE,CAACqB,MAAM,CAAC,CAAC;EAClB;AACF","ignoreList":[]}
@@ -1,43 +1,9 @@
1
1
  "use strict";
2
2
 
3
3
  import { NativeModules } from 'react-native';
4
- export { Storage } from "./Storage.js";
5
4
  export * from "./functions.js";
6
-
7
- /**
8
- * Object returned by SQL Query executions {
9
- * insertId: Represent the auto-generated row id if applicable
10
- * rowsAffected: Number of affected rows if result of a update query
11
- * message: if status === 1, here you will find error description
12
- * rows: if status is undefined or 0 this object will contain the query results
13
- * }
14
- *
15
- * @interface QueryResult
16
- */
17
-
18
- /**
19
- * Column metadata
20
- * Describes some information about columns fetched by the query
21
- */
22
-
23
- /**
24
- * Allows the execution of bulk of sql commands
25
- * inside a transaction
26
- * If a single query must be executed many times with different arguments, its preferred
27
- * to declare it a single time, and use an array of array parameters.
28
- */
29
-
30
- /**
31
- * status: 0 or undefined for correct execution, 1 for error
32
- * message: if status === 1, here you will find error description
33
- * rowsAffected: Number of affected rows if status == 0
34
- */
35
-
36
- /**
37
- * Result of loading a file and executing every line as a SQL command
38
- * Similar to BatchQueryResult
39
- */
40
-
5
+ export { Storage } from "./Storage.js";
6
+ export * from "./types.js";
41
7
  export const {
42
8
  IOS_DOCUMENT_PATH,
43
9
  IOS_LIBRARY_PATH,
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","Storage","IOS_DOCUMENT_PATH","IOS_LIBRARY_PATH","ANDROID_DATABASE_PATH","ANDROID_FILES_PATH","ANDROID_EXTERNAL_FILES_PATH","OPSQLite","getConstants"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,cAAc;AAE5C,SAASC,OAAO,QAAQ,cAAW;AACnC,cAAc,gBAAa;;AAU3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;;AAoPA,OAAO,MAAM;EACXC,iBAAiB;EACjBC,gBAAgB;EAChBC,qBAAqB;EACrBC,kBAAkB;EAClBC;AACF,CAAC,GAAG,CAAC,CAACN,aAAa,CAACO,QAAQ,CAACC,YAAY,GACrCR,aAAa,CAACO,QAAQ,CAACC,YAAY,CAAC,CAAC,GACrCR,aAAa,CAACO,QAAQ","ignoreList":[]}
1
+ {"version":3,"names":["NativeModules","Storage","IOS_DOCUMENT_PATH","IOS_LIBRARY_PATH","ANDROID_DATABASE_PATH","ANDROID_FILES_PATH","ANDROID_EXTERNAL_FILES_PATH","OPSQLite","getConstants"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,cAAc;AAE5C,cAAc,gBAAa;AAC3B,SAASC,OAAO,QAAQ,cAAW;AACnC,cAAc,YAAS;AAEvB,OAAO,MAAM;EACXC,iBAAiB;EACjBC,gBAAgB;EAChBC,qBAAqB;EACrBC,kBAAkB;EAClBC;AACF,CAAC,GAAG,CAAC,CAACN,aAAa,CAACO,QAAQ,CAACC,YAAY,GACrCR,aAAa,CAACO,QAAQ,CAACC,YAAY,CAAC,CAAC,GACrCR,aAAa,CAACO,QAAQ","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { type DB, type OPSQLiteProxy } from './index';
1
+ import { type DB, type OPSQLiteProxy } from './types';
2
2
  declare global {
3
3
  var __OPSQLiteProxy: object | undefined;
4
4
  }
@@ -1 +1 @@
1
- {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../../src/functions.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,EAAE,EAOP,KAAK,aAAa,EACnB,MAAM,SAAS,CAAC;AAEjB,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AA0BD,eAAO,MAAM,QAAQ,EAAY,aAAa,CAAC;AAyT/C;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,QAAQ;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAA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GG;AACH,eAAO,MAAM,QAAQ,GAAI,QAAQ;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,KAAG,EASH,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,KAAG,EASvE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,IAAI,GAAI,QAAQ;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,KAAG,EAYH,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAU,MAAM;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,KAAG,OAAO,CAAC,OAAO,CAElB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,MAAM,MAAM,KAAG,MAE3D,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,OAE9B,CAAC;AAEF,eAAO,MAAM,QAAQ,QAAO,OAE3B,CAAC;AAEF,eAAO,MAAM,aAAa,QAAO,OAMhC,CAAC"}
@@ -1,275 +1,5 @@
1
- export { Storage } from './Storage';
2
1
  export * from './functions';
3
- export type Scalar = string | number | boolean | null | ArrayBuffer | ArrayBufferView;
4
- /**
5
- * Object returned by SQL Query executions {
6
- * insertId: Represent the auto-generated row id if applicable
7
- * rowsAffected: Number of affected rows if result of a update query
8
- * message: if status === 1, here you will find error description
9
- * rows: if status is undefined or 0 this object will contain the query results
10
- * }
11
- *
12
- * @interface QueryResult
13
- */
14
- export type QueryResult = {
15
- insertId?: number;
16
- rowsAffected: number;
17
- res?: any[];
18
- rows: Array<Record<string, Scalar>>;
19
- rawRows?: Scalar[][];
20
- columnNames?: string[];
21
- /**
22
- * Query metadata, available only for select query results
23
- */
24
- metadata?: ColumnMetadata[];
25
- };
26
- /**
27
- * Column metadata
28
- * Describes some information about columns fetched by the query
29
- */
30
- export type ColumnMetadata = {
31
- /** The name used for this column for this result set */
32
- name: string;
33
- /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. "UNKNOWN" for dynamic values, like function returned ones. */
34
- type: string;
35
- /**
36
- * The index for this column for this result set*/
37
- index: number;
38
- };
39
- /**
40
- * Allows the execution of bulk of sql commands
41
- * inside a transaction
42
- * If a single query must be executed many times with different arguments, its preferred
43
- * to declare it a single time, and use an array of array parameters.
44
- */
45
- export type SQLBatchTuple = [string] | [string, Scalar[]] | [string, Scalar[][]];
46
- export type UpdateHookOperation = 'INSERT' | 'DELETE' | 'UPDATE';
47
- /**
48
- * status: 0 or undefined for correct execution, 1 for error
49
- * message: if status === 1, here you will find error description
50
- * rowsAffected: Number of affected rows if status == 0
51
- */
52
- export type BatchQueryResult = {
53
- rowsAffected?: number;
54
- };
55
- /**
56
- * Result of loading a file and executing every line as a SQL command
57
- * Similar to BatchQueryResult
58
- */
59
- export type FileLoadResult = BatchQueryResult & {
60
- commands?: number;
61
- };
62
- export type Transaction = {
63
- commit: () => Promise<QueryResult>;
64
- execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
65
- rollback: () => QueryResult;
66
- };
67
- export type _PendingTransaction = {
68
- start: () => void;
69
- };
70
- export type PreparedStatement = {
71
- bind: (params: any[]) => Promise<void>;
72
- bindSync: (params: any[]) => void;
73
- execute: () => Promise<QueryResult>;
74
- };
75
- export type _InternalDB = {
76
- close: () => void;
77
- delete: (location?: string) => void;
78
- attach: (params: {
79
- secondaryDbFileName: string;
80
- alias: string;
81
- location?: string;
82
- }) => void;
83
- detach: (alias: string) => void;
84
- transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;
85
- executeSync: (query: string, params?: Scalar[]) => QueryResult;
86
- execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
87
- executeWithHostObjects: (query: string, params?: Scalar[]) => Promise<QueryResult>;
88
- executeBatch: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
89
- loadFile: (location: string) => Promise<FileLoadResult>;
90
- updateHook: (callback?: ((params: {
91
- table: string;
92
- operation: UpdateHookOperation;
93
- row?: any;
94
- rowId: number;
95
- }) => void) | null) => void;
96
- commitHook: (callback?: (() => void) | null) => void;
97
- rollbackHook: (callback?: (() => void) | null) => void;
98
- prepareStatement: (query: string) => PreparedStatement;
99
- loadExtension: (path: string, entryPoint?: string) => void;
100
- executeRaw: (query: string, params?: Scalar[]) => Promise<any[]>;
101
- executeRawSync: (query: string, params?: Scalar[]) => any[];
102
- getDbPath: (location?: string) => string;
103
- reactiveExecute: (params: {
104
- query: string;
105
- arguments: any[];
106
- fireOn: {
107
- table: string;
108
- ids?: number[];
109
- }[];
110
- callback: (response: any) => void;
111
- }) => () => void;
112
- sync: () => void;
113
- flushPendingReactiveQueries: () => Promise<void>;
114
- };
115
- export type DB = {
116
- close: () => void;
117
- delete: (location?: string) => void;
118
- attach: (params: {
119
- secondaryDbFileName: string;
120
- alias: string;
121
- location?: string;
122
- }) => void;
123
- detach: (alias: string) => void;
124
- /**
125
- * Wraps all the executions into a transaction. If an error is thrown it will rollback all of the changes
126
- *
127
- * You need to use this if you are using reactive queries for the queries to fire after the transaction is done
128
- */
129
- transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;
130
- /**
131
- * Sync version of the execute function
132
- * It will block the JS thread and therefore your UI and should be used with caution
133
- *
134
- * When writing your queries, you can use the ? character as a placeholder for parameters
135
- * The parameters will be automatically escaped and sanitized
136
- *
137
- * Example:
138
- * db.executeSync('SELECT * FROM table WHERE id = ?', [1]);
139
- *
140
- * If you are writing a query that doesn't require parameters, you can omit the second argument
141
- *
142
- * If you are writing to the database YOU SHOULD BE USING TRANSACTIONS!
143
- * Transactions protect you from partial writes and ensure that your data is always in a consistent state
144
- *
145
- * @param query
146
- * @param params
147
- * @returns QueryResult
148
- */
149
- executeSync: (query: string, params?: Scalar[]) => QueryResult;
150
- /**
151
- * Basic query execution function, it is async don't forget to await it
152
- *
153
- * When writing your queries, you can use the ? character as a placeholder for parameters
154
- * The parameters will be automatically escaped and sanitized
155
- *
156
- * Example:
157
- * await db.execute('SELECT * FROM table WHERE id = ?', [1]);
158
- *
159
- * If you are writing a query that doesn't require parameters, you can omit the second argument
160
- *
161
- * If you are writing to the database YOU SHOULD BE USING TRANSACTIONS!
162
- * Transactions protect you from partial writes and ensure that your data is always in a consistent state
163
- *
164
- * If you need a large amount of queries ran as fast as possible you should be using `executeBatch`, `executeRaw`, `loadFile` or `executeWithHostObjects`
165
- *
166
- * @param query string of your SQL query
167
- * @param params a list of parameters to bind to the query, if any
168
- * @returns Promise<QueryResult> with the result of the query
169
- */
170
- execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
171
- /**
172
- * Similar to the execute function but returns the response in HostObjects
173
- * Read more about HostObjects in the documentation and their pitfalls
174
- *
175
- * Will be a lot faster than the normal execute functions when returning data but you will pay when accessing the fields
176
- * as the conversion is done the moment you access any field
177
- * @param query
178
- * @param params
179
- * @returns
180
- */
181
- executeWithHostObjects: (query: string, params?: Scalar[]) => Promise<QueryResult>;
182
- /**
183
- * Executes all the queries in the params inside a single transaction
184
- *
185
- * It's faster than executing single queries as data is sent to the native side only once
186
- * @param commands
187
- * @returns Promise<BatchQueryResult>
188
- */
189
- executeBatch: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
190
- /**
191
- * Loads a SQLite Dump from disk. It will be the fastest way to execute a large set of queries as no JS is involved
192
- */
193
- loadFile: (location: string) => Promise<FileLoadResult>;
194
- updateHook: (callback?: ((params: {
195
- table: string;
196
- operation: UpdateHookOperation;
197
- row?: any;
198
- rowId: number;
199
- }) => void) | null) => void;
200
- commitHook: (callback?: (() => void) | null) => void;
201
- rollbackHook: (callback?: (() => void) | null) => void;
202
- /**
203
- * Constructs a prepared statement from the query string
204
- * The statement can be re-bound with parameters and executed
205
- * The performance gain is significant when the same query is executed multiple times, NOT when the query is executed (once)
206
- * The cost lies in the preparation of the statement as it is compiled and optimized by the sqlite engine, the params can then rebound
207
- * but the query itself is already optimized
208
- *
209
- * @param query string of your SQL query
210
- * @returns Prepared statement object
211
- */
212
- prepareStatement: (query: string) => PreparedStatement;
213
- /**
214
- * Loads a runtime loadable sqlite extension. Libsql and iOS embedded version do not support loading extensions
215
- */
216
- loadExtension: (path: string, entryPoint?: string) => void;
217
- /**
218
- * Same as `execute` except the results are not returned in objects but rather in arrays with just the values and not the keys
219
- * It will be faster since a lot of repeated work is skipped and only the values you care about are returned
220
- */
221
- executeRaw: (query: string, params?: Scalar[]) => Promise<any[]>;
222
- /**
223
- * Same as `executeRaw` but it will block the JS thread and therefore your UI and should be used with caution
224
- * It will return an array of arrays with just the values and not the keys
225
- */
226
- executeRawSync: (query: string, params?: Scalar[]) => any[];
227
- /**
228
- * Get's the absolute path to the db file. Useful for debugging on local builds and for attaching the DB from users devices
229
- */
230
- getDbPath: (location?: string) => string;
231
- /**
232
- * Reactive execution of queries when data is written to the database. Check the docs for how to use them.
233
- */
234
- reactiveExecute: (params: {
235
- query: string;
236
- arguments: any[];
237
- fireOn: {
238
- table: string;
239
- ids?: number[];
240
- }[];
241
- callback: (response: any) => void;
242
- }) => () => void;
243
- /** This function is only available for libsql.
244
- * Allows to trigger a sync the database with it's remote replica
245
- * In order for this function to work you need to use openSync or openRemote functions
246
- * with libsql: true in the package.json
247
- *
248
- * The database is hosted in turso
249
- **/
250
- sync: () => void;
251
- };
252
- export type DBParams = {
253
- url?: string;
254
- authToken?: string;
255
- name?: string;
256
- location?: string;
257
- syncInterval?: number;
258
- };
259
- export type OPSQLiteProxy = {
260
- open: (options: {
261
- name: string;
262
- location?: string;
263
- encryptionKey?: string;
264
- }) => _InternalDB;
265
- openRemote: (options: {
266
- url: string;
267
- authToken: string;
268
- }) => _InternalDB;
269
- openSync: (options: DBParams) => _InternalDB;
270
- isSQLCipher: () => boolean;
271
- isLibsql: () => boolean;
272
- isIOSEmbedded: () => boolean;
273
- };
2
+ export { Storage } from './Storage';
3
+ export * from './types';
274
4
  export declare const IOS_DOCUMENT_PATH: any, IOS_LIBRARY_PATH: any, ANDROID_DATABASE_PATH: any, ANDROID_FILES_PATH: any, ANDROID_EXTERNAL_FILES_PATH: any;
275
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,cAAc,aAAa,CAAC;AAE5B,MAAM,MAAM,MAAM,GACd,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,WAAW,GACX,eAAe,CAAC;AAEpB;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC;IACZ,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAEpC,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,wDAAwD;IACxD,IAAI,EAAE,MA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,MAAM,CAAC;QAClB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,KAAK,WAAW,CAAC;IAClB,UAAU,EAAE,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,KAAK,WAAW,CAAC;IACzE,QAAQ,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,WAAW,CAAC;IAC7C,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,aAAa,EAAE,MAAM,OAAO,CAAC;CAC9B,CAAC;AAEF,eAAO,MACL,iBAAiB,OACjB,gBAAgB,OAChB,qBAAqB,OACrB,kBAAkB,OAClB,2BAA2B,KAGH,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,cAAc,SAAS,CAAC;AAExB,eAAO,MACL,iBAAiB,OACjB,gBAAgB,OAChB,qBAAqB,OACrB,kBAAkB,OAClB,2BAA2B,KAGH,CAAC"}
@@ -0,0 +1,272 @@
1
+ export type Scalar = string | number | boolean | null | ArrayBuffer | ArrayBufferView;
2
+ /**
3
+ * Object returned by SQL Query executions {
4
+ * insertId: Represent the auto-generated row id if applicable
5
+ * rowsAffected: Number of affected rows if result of a update query
6
+ * message: if status === 1, here you will find error description
7
+ * rows: if status is undefined or 0 this object will contain the query results
8
+ * }
9
+ *
10
+ * @interface QueryResult
11
+ */
12
+ export type QueryResult = {
13
+ insertId?: number;
14
+ rowsAffected: number;
15
+ res?: any[];
16
+ rows: Array<Record<string, Scalar>>;
17
+ rawRows?: Scalar[][];
18
+ columnNames?: string[];
19
+ /**
20
+ * Query metadata, available only for select query results
21
+ */
22
+ metadata?: ColumnMetadata[];
23
+ };
24
+ /**
25
+ * Column metadata
26
+ * Describes some information about columns fetched by the query
27
+ */
28
+ export type ColumnMetadata = {
29
+ /** The name used for this column for this result set */
30
+ name: string;
31
+ /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. "UNKNOWN" for dynamic values, like function returned ones. */
32
+ type: string;
33
+ /**
34
+ * The index for this column for this result set*/
35
+ index: number;
36
+ };
37
+ /**
38
+ * Allows the execution of bulk of sql commands
39
+ * inside a transaction
40
+ * If a single query must be executed many times with different arguments, its preferred
41
+ * to declare it a single time, and use an array of array parameters.
42
+ */
43
+ export type SQLBatchTuple = [string] | [string, Scalar[]] | [string, Scalar[][]];
44
+ export type UpdateHookOperation = 'INSERT' | 'DELETE' | 'UPDATE';
45
+ /**
46
+ * status: 0 or undefined for correct execution, 1 for error
47
+ * message: if status === 1, here you will find error description
48
+ * rowsAffected: Number of affected rows if status == 0
49
+ */
50
+ export type BatchQueryResult = {
51
+ rowsAffected?: number;
52
+ };
53
+ /**
54
+ * Result of loading a file and executing every line as a SQL command
55
+ * Similar to BatchQueryResult
56
+ */
57
+ export type FileLoadResult = BatchQueryResult & {
58
+ commands?: number;
59
+ };
60
+ export type Transaction = {
61
+ commit: () => Promise<QueryResult>;
62
+ execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
63
+ rollback: () => QueryResult;
64
+ };
65
+ export type _PendingTransaction = {
66
+ start: () => void;
67
+ };
68
+ export type PreparedStatement = {
69
+ bind: (params: any[]) => Promise<void>;
70
+ bindSync: (params: any[]) => void;
71
+ execute: () => Promise<QueryResult>;
72
+ };
73
+ export type _InternalDB = {
74
+ close: () => void;
75
+ delete: (location?: string) => void;
76
+ attach: (params: {
77
+ secondaryDbFileName: string;
78
+ alias: string;
79
+ location?: string;
80
+ }) => void;
81
+ detach: (alias: string) => void;
82
+ transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;
83
+ executeSync: (query: string, params?: Scalar[]) => QueryResult;
84
+ execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
85
+ executeWithHostObjects: (query: string, params?: Scalar[]) => Promise<QueryResult>;
86
+ executeBatch: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
87
+ loadFile: (location: string) => Promise<FileLoadResult>;
88
+ updateHook: (callback?: ((params: {
89
+ table: string;
90
+ operation: UpdateHookOperation;
91
+ row?: any;
92
+ rowId: number;
93
+ }) => void) | null) => void;
94
+ commitHook: (callback?: (() => void) | null) => void;
95
+ rollbackHook: (callback?: (() => void) | null) => void;
96
+ prepareStatement: (query: string) => PreparedStatement;
97
+ loadExtension: (path: string, entryPoint?: string) => void;
98
+ executeRaw: (query: string, params?: Scalar[]) => Promise<any[]>;
99
+ executeRawSync: (query: string, params?: Scalar[]) => any[];
100
+ getDbPath: (location?: string) => string;
101
+ reactiveExecute: (params: {
102
+ query: string;
103
+ arguments: any[];
104
+ fireOn: {
105
+ table: string;
106
+ ids?: number[];
107
+ }[];
108
+ callback: (response: any) => void;
109
+ }) => () => void;
110
+ sync: () => void;
111
+ flushPendingReactiveQueries: () => Promise<void>;
112
+ };
113
+ export type DB = {
114
+ close: () => void;
115
+ delete: (location?: string) => void;
116
+ attach: (params: {
117
+ secondaryDbFileName: string;
118
+ alias: string;
119
+ location?: string;
120
+ }) => void;
121
+ detach: (alias: string) => void;
122
+ /**
123
+ * Wraps all the executions into a transaction. If an error is thrown it will rollback all of the changes
124
+ *
125
+ * You need to use this if you are using reactive queries for the queries to fire after the transaction is done
126
+ */
127
+ transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;
128
+ /**
129
+ * Sync version of the execute function
130
+ * It will block the JS thread and therefore your UI and should be used with caution
131
+ *
132
+ * When writing your queries, you can use the ? character as a placeholder for parameters
133
+ * The parameters will be automatically escaped and sanitized
134
+ *
135
+ * Example:
136
+ * db.executeSync('SELECT * FROM table WHERE id = ?', [1]);
137
+ *
138
+ * If you are writing a query that doesn't require parameters, you can omit the second argument
139
+ *
140
+ * If you are writing to the database YOU SHOULD BE USING TRANSACTIONS!
141
+ * Transactions protect you from partial writes and ensure that your data is always in a consistent state
142
+ *
143
+ * @param query
144
+ * @param params
145
+ * @returns QueryResult
146
+ */
147
+ executeSync: (query: string, params?: Scalar[]) => QueryResult;
148
+ /**
149
+ * Basic query execution function, it is async don't forget to await it
150
+ *
151
+ * When writing your queries, you can use the ? character as a placeholder for parameters
152
+ * The parameters will be automatically escaped and sanitized
153
+ *
154
+ * Example:
155
+ * await db.execute('SELECT * FROM table WHERE id = ?', [1]);
156
+ *
157
+ * If you are writing a query that doesn't require parameters, you can omit the second argument
158
+ *
159
+ * If you are writing to the database YOU SHOULD BE USING TRANSACTIONS!
160
+ * Transactions protect you from partial writes and ensure that your data is always in a consistent state
161
+ *
162
+ * If you need a large amount of queries ran as fast as possible you should be using `executeBatch`, `executeRaw`, `loadFile` or `executeWithHostObjects`
163
+ *
164
+ * @param query string of your SQL query
165
+ * @param params a list of parameters to bind to the query, if any
166
+ * @returns Promise<QueryResult> with the result of the query
167
+ */
168
+ execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
169
+ /**
170
+ * Similar to the execute function but returns the response in HostObjects
171
+ * Read more about HostObjects in the documentation and their pitfalls
172
+ *
173
+ * Will be a lot faster than the normal execute functions when returning data but you will pay when accessing the fields
174
+ * as the conversion is done the moment you access any field
175
+ * @param query
176
+ * @param params
177
+ * @returns
178
+ */
179
+ executeWithHostObjects: (query: string, params?: Scalar[]) => Promise<QueryResult>;
180
+ /**
181
+ * Executes all the queries in the params inside a single transaction
182
+ *
183
+ * It's faster than executing single queries as data is sent to the native side only once
184
+ * @param commands
185
+ * @returns Promise<BatchQueryResult>
186
+ */
187
+ executeBatch: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
188
+ /**
189
+ * Loads a SQLite Dump from disk. It will be the fastest way to execute a large set of queries as no JS is involved
190
+ */
191
+ loadFile: (location: string) => Promise<FileLoadResult>;
192
+ updateHook: (callback?: ((params: {
193
+ table: string;
194
+ operation: UpdateHookOperation;
195
+ row?: any;
196
+ rowId: number;
197
+ }) => void) | null) => void;
198
+ commitHook: (callback?: (() => void) | null) => void;
199
+ rollbackHook: (callback?: (() => void) | null) => void;
200
+ /**
201
+ * Constructs a prepared statement from the query string
202
+ * The statement can be re-bound with parameters and executed
203
+ * The performance gain is significant when the same query is executed multiple times, NOT when the query is executed (once)
204
+ * The cost lies in the preparation of the statement as it is compiled and optimized by the sqlite engine, the params can then rebound
205
+ * but the query itself is already optimized
206
+ *
207
+ * @param query string of your SQL query
208
+ * @returns Prepared statement object
209
+ */
210
+ prepareStatement: (query: string) => PreparedStatement;
211
+ /**
212
+ * Loads a runtime loadable sqlite extension. Libsql and iOS embedded version do not support loading extensions
213
+ */
214
+ loadExtension: (path: string, entryPoint?: string) => void;
215
+ /**
216
+ * Same as `execute` except the results are not returned in objects but rather in arrays with just the values and not the keys
217
+ * It will be faster since a lot of repeated work is skipped and only the values you care about are returned
218
+ */
219
+ executeRaw: (query: string, params?: Scalar[]) => Promise<any[]>;
220
+ /**
221
+ * Same as `executeRaw` but it will block the JS thread and therefore your UI and should be used with caution
222
+ * It will return an array of arrays with just the values and not the keys
223
+ */
224
+ executeRawSync: (query: string, params?: Scalar[]) => any[];
225
+ /**
226
+ * Get's the absolute path to the db file. Useful for debugging on local builds and for attaching the DB from users devices
227
+ */
228
+ getDbPath: (location?: string) => string;
229
+ /**
230
+ * Reactive execution of queries when data is written to the database. Check the docs for how to use them.
231
+ */
232
+ reactiveExecute: (params: {
233
+ query: string;
234
+ arguments: any[];
235
+ fireOn: {
236
+ table: string;
237
+ ids?: number[];
238
+ }[];
239
+ callback: (response: any) => void;
240
+ }) => () => void;
241
+ /** This function is only available for libsql.
242
+ * Allows to trigger a sync the database with it's remote replica
243
+ * In order for this function to work you need to use openSync or openRemote functions
244
+ * with libsql: true in the package.json
245
+ *
246
+ * The database is hosted in turso
247
+ **/
248
+ sync: () => void;
249
+ };
250
+ export type DBParams = {
251
+ url?: string;
252
+ authToken?: string;
253
+ name?: string;
254
+ location?: string;
255
+ syncInterval?: number;
256
+ };
257
+ export type OPSQLiteProxy = {
258
+ open: (options: {
259
+ name: string;
260
+ location?: string;
261
+ encryptionKey?: string;
262
+ }) => _InternalDB;
263
+ openRemote: (options: {
264
+ url: string;
265
+ authToken: string;
266
+ }) => _InternalDB;
267
+ openSync: (options: DBParams) => _InternalDB;
268
+ isSQLCipher: () => boolean;
269
+ isLibsql: () => boolean;
270
+ isIOSEmbedded: () => boolean;
271
+ };
272
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GACd,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,WAAW,GACX,eAAe,CAAC;AAEpB;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC;IACZ,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAEpC,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,uLAAuL;IACvL,IAAI,EAAE,MAAM,CAAC;IACb;sDACkD;IAClD,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GACrB,CAAC,MAAM,CAAC,GACR,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAClB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;AAEzB,MAAM,MAAM,m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O,CAAC;IAC3B,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,aAAa,EAAE,MAAM,OAAO,CAAC;CAC9B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "15.0.2",
3
+ "version": "15.0.3",
4
4
  "description": "Next generation SQLite for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
package/src/Storage.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type DB } from './index';
2
1
  import { open } from './functions';
2
+ import { type DB } from './types';
3
3
 
4
4
  type StorageOptions = {
5
5
  location?: string;
package/src/functions.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import { NativeModules, Platform } from 'react-native';
2
2
  import {
3
3
  type _InternalDB,
4
- type DBParams,
5
- type DB,
6
4
  type _PendingTransaction,
7
- type SQLBatchTuple,
8
5
  type BatchQueryResult,
9
- type Scalar,
6
+ type DB,
7
+ type DBParams,
8
+ type OPSQLiteProxy,
10
9
  type QueryResult,
10
+ type Scalar,
11
+ type SQLBatchTuple,
11
12
  type Transaction,
12
- type OPSQLiteProxy,
13
- } from './index';
13
+ } from './types';
14
14
 
15
15
  declare global {
16
16
  var __OPSQLiteProxy: object | undefined;
package/src/index.ts CHANGED
@@ -1,322 +1,8 @@
1
1
  import { NativeModules } from 'react-native';
2
2
 
3
- export { Storage } from './Storage';
4
3
  export * from './functions';
5
-
6
- export type Scalar =
7
- | string
8
- | number
9
- | boolean
10
- | null
11
- | ArrayBuffer
12
- | ArrayBufferView;
13
-
14
- /**
15
- * Object returned by SQL Query executions {
16
- * insertId: Represent the auto-generated row id if applicable
17
- * rowsAffected: Number of affected rows if result of a update query
18
- * message: if status === 1, here you will find error description
19
- * rows: if status is undefined or 0 this object will contain the query results
20
- * }
21
- *
22
- * @interface QueryResult
23
- */
24
- export type QueryResult = {
25
- insertId?: number;
26
- rowsAffected: number;
27
- res?: any[];
28
- rows: Array<Record<string, Scalar>>;
29
- // An array of intermediate results, just values without column names
30
- rawRows?: Scalar[][];
31
- columnNames?: string[];
32
- /**
33
- * Query metadata, available only for select query results
34
- */
35
- metadata?: ColumnMetadata[];
36
- };
37
-
38
- /**
39
- * Column metadata
40
- * Describes some information about columns fetched by the query
41
- */
42
- export type ColumnMetadata = {
43
- /** The name used for this column for this result set */
44
- name: string;
45
- /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. "UNKNOWN" for dynamic values, like function returned ones. */
46
- type: string;
47
- /**
48
- * The index for this column for this result set*/
49
- index: number;
50
- };
51
-
52
- /**
53
- * Allows the execution of bulk of sql commands
54
- * inside a transaction
55
- * If a single query must be executed many times with different arguments, its preferred
56
- * to declare it a single time, and use an array of array parameters.
57
- */
58
- export type SQLBatchTuple =
59
- | [string]
60
- | [string, Scalar[]]
61
- | [string, Scalar[][]];
62
-
63
- export type UpdateHookOperation = 'INSERT' | 'DELETE' | 'UPDATE';
64
-
65
- /**
66
- * status: 0 or undefined for correct execution, 1 for error
67
- * message: if status === 1, here you will find error description
68
- * rowsAffected: Number of affected rows if status == 0
69
- */
70
- export type BatchQueryResult = {
71
- rowsAffected?: number;
72
- };
73
-
74
- /**
75
- * Result of loading a file and executing every line as a SQL command
76
- * Similar to BatchQueryResult
77
- */
78
- export type FileLoadResult = BatchQueryResult & {
79
- commands?: number;
80
- };
81
-
82
- export type Transaction = {
83
- commit: () => Promise<QueryResult>;
84
- execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
85
- rollback: () => QueryResult;
86
- };
87
-
88
- export type _PendingTransaction = {
89
- /*
90
- * The start function should not throw or return a promise because the
91
- * queue just calls it and does not monitor for failures or completions.
92
- *
93
- * It should catch any errors and call the resolve or reject of the wrapping
94
- * promise when complete.
95
- *
96
- * It should also automatically commit or rollback the transaction if needed
97
- */
98
- start: () => void;
99
- };
100
-
101
- export type PreparedStatement = {
102
- bind: (params: any[]) => Promise<void>;
103
- bindSync: (params: any[]) => void;
104
- execute: () => Promise<QueryResult>;
105
- };
106
-
107
- export type _InternalDB = {
108
- close: () => void;
109
- delete: (location?: string) => void;
110
- attach: (params: {
111
- secondaryDbFileName: string;
112
- alias: string;
113
- location?: string;
114
- }) => void;
115
- detach: (alias: string) => void;
116
- transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;
117
- executeSync: (query: string, params?: Scalar[]) => QueryResult;
118
- execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
119
- executeWithHostObjects: (
120
- query: string,
121
- params?: Scalar[]
122
- ) => Promise<QueryResult>;
123
- executeBatch: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
124
- loadFile: (location: string) => Promise<FileLoadResult>;
125
- updateHook: (
126
- callback?:
127
- | ((params: {
128
- table: string;
129
- operation: UpdateHookOperation;
130
- row?: any;
131
- rowId: number;
132
- }) => void)
133
- | null
134
- ) => void;
135
- commitHook: (callback?: (() => void) | null) => void;
136
- rollbackHook: (callback?: (() => void) | null) => void;
137
- prepareStatement: (query: string) => PreparedStatement;
138
- loadExtension: (path: string, entryPoint?: string) => void;
139
- executeRaw: (query: string, params?: Scalar[]) => Promise<any[]>;
140
- executeRawSync: (query: string, params?: Scalar[]) => any[];
141
- getDbPath: (location?: string) => string;
142
- reactiveExecute: (params: {
143
- query: string;
144
- arguments: any[];
145
- fireOn: {
146
- table: string;
147
- ids?: number[];
148
- }[];
149
- callback: (response: any) => void;
150
- }) => () => void;
151
- sync: () => void;
152
- flushPendingReactiveQueries: () => Promise<void>;
153
- };
154
-
155
- export type DB = {
156
- close: () => void;
157
- delete: (location?: string) => void;
158
- attach: (params: {
159
- secondaryDbFileName: string;
160
- alias: string;
161
- location?: string;
162
- }) => void;
163
- detach: (alias: string) => void;
164
- /**
165
- * Wraps all the executions into a transaction. If an error is thrown it will rollback all of the changes
166
- *
167
- * You need to use this if you are using reactive queries for the queries to fire after the transaction is done
168
- */
169
- transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;
170
- /**
171
- * Sync version of the execute function
172
- * It will block the JS thread and therefore your UI and should be used with caution
173
- *
174
- * When writing your queries, you can use the ? character as a placeholder for parameters
175
- * The parameters will be automatically escaped and sanitized
176
- *
177
- * Example:
178
- * db.executeSync('SELECT * FROM table WHERE id = ?', [1]);
179
- *
180
- * If you are writing a query that doesn't require parameters, you can omit the second argument
181
- *
182
- * If you are writing to the database YOU SHOULD BE USING TRANSACTIONS!
183
- * Transactions protect you from partial writes and ensure that your data is always in a consistent state
184
- *
185
- * @param query
186
- * @param params
187
- * @returns QueryResult
188
- */
189
- executeSync: (query: string, params?: Scalar[]) => QueryResult;
190
- /**
191
- * Basic query execution function, it is async don't forget to await it
192
- *
193
- * When writing your queries, you can use the ? character as a placeholder for parameters
194
- * The parameters will be automatically escaped and sanitized
195
- *
196
- * Example:
197
- * await db.execute('SELECT * FROM table WHERE id = ?', [1]);
198
- *
199
- * If you are writing a query that doesn't require parameters, you can omit the second argument
200
- *
201
- * If you are writing to the database YOU SHOULD BE USING TRANSACTIONS!
202
- * Transactions protect you from partial writes and ensure that your data is always in a consistent state
203
- *
204
- * If you need a large amount of queries ran as fast as possible you should be using `executeBatch`, `executeRaw`, `loadFile` or `executeWithHostObjects`
205
- *
206
- * @param query string of your SQL query
207
- * @param params a list of parameters to bind to the query, if any
208
- * @returns Promise<QueryResult> with the result of the query
209
- */
210
- execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
211
- /**
212
- * Similar to the execute function but returns the response in HostObjects
213
- * Read more about HostObjects in the documentation and their pitfalls
214
- *
215
- * Will be a lot faster than the normal execute functions when returning data but you will pay when accessing the fields
216
- * as the conversion is done the moment you access any field
217
- * @param query
218
- * @param params
219
- * @returns
220
- */
221
- executeWithHostObjects: (
222
- query: string,
223
- params?: Scalar[]
224
- ) => Promise<QueryResult>;
225
- /**
226
- * Executes all the queries in the params inside a single transaction
227
- *
228
- * It's faster than executing single queries as data is sent to the native side only once
229
- * @param commands
230
- * @returns Promise<BatchQueryResult>
231
- */
232
- executeBatch: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
233
- /**
234
- * Loads a SQLite Dump from disk. It will be the fastest way to execute a large set of queries as no JS is involved
235
- */
236
- loadFile: (location: string) => Promise<FileLoadResult>;
237
- updateHook: (
238
- callback?:
239
- | ((params: {
240
- table: string;
241
- operation: UpdateHookOperation;
242
- row?: any;
243
- rowId: number;
244
- }) => void)
245
- | null
246
- ) => void;
247
- commitHook: (callback?: (() => void) | null) => void;
248
- rollbackHook: (callback?: (() => void) | null) => void;
249
- /**
250
- * Constructs a prepared statement from the query string
251
- * The statement can be re-bound with parameters and executed
252
- * The performance gain is significant when the same query is executed multiple times, NOT when the query is executed (once)
253
- * The cost lies in the preparation of the statement as it is compiled and optimized by the sqlite engine, the params can then rebound
254
- * but the query itself is already optimized
255
- *
256
- * @param query string of your SQL query
257
- * @returns Prepared statement object
258
- */
259
- prepareStatement: (query: string) => PreparedStatement;
260
- /**
261
- * Loads a runtime loadable sqlite extension. Libsql and iOS embedded version do not support loading extensions
262
- */
263
- loadExtension: (path: string, entryPoint?: string) => void;
264
- /**
265
- * Same as `execute` except the results are not returned in objects but rather in arrays with just the values and not the keys
266
- * It will be faster since a lot of repeated work is skipped and only the values you care about are returned
267
- */
268
- executeRaw: (query: string, params?: Scalar[]) => Promise<any[]>;
269
- /**
270
- * Same as `executeRaw` but it will block the JS thread and therefore your UI and should be used with caution
271
- * It will return an array of arrays with just the values and not the keys
272
- */
273
- executeRawSync: (query: string, params?: Scalar[]) => any[];
274
- /**
275
- * Get's the absolute path to the db file. Useful for debugging on local builds and for attaching the DB from users devices
276
- */
277
- getDbPath: (location?: string) => string;
278
- /**
279
- * Reactive execution of queries when data is written to the database. Check the docs for how to use them.
280
- */
281
- reactiveExecute: (params: {
282
- query: string;
283
- arguments: any[];
284
- fireOn: {
285
- table: string;
286
- ids?: number[];
287
- }[];
288
- callback: (response: any) => void;
289
- }) => () => void;
290
- /** This function is only available for libsql.
291
- * Allows to trigger a sync the database with it's remote replica
292
- * In order for this function to work you need to use openSync or openRemote functions
293
- * with libsql: true in the package.json
294
- *
295
- * The database is hosted in turso
296
- **/
297
- sync: () => void;
298
- };
299
-
300
- export type DBParams = {
301
- url?: string;
302
- authToken?: string;
303
- name?: string;
304
- location?: string;
305
- syncInterval?: number;
306
- };
307
-
308
- export type OPSQLiteProxy = {
309
- open: (options: {
310
- name: string;
311
- location?: string;
312
- encryptionKey?: string;
313
- }) => _InternalDB;
314
- openRemote: (options: { url: string; authToken: string }) => _InternalDB;
315
- openSync: (options: DBParams) => _InternalDB;
316
- isSQLCipher: () => boolean;
317
- isLibsql: () => boolean;
318
- isIOSEmbedded: () => boolean;
319
- };
4
+ export { Storage } from './Storage';
5
+ export * from './types';
320
6
 
321
7
  export const {
322
8
  IOS_DOCUMENT_PATH,
package/src/types.ts ADDED
@@ -0,0 +1,314 @@
1
+ export type Scalar =
2
+ | string
3
+ | number
4
+ | boolean
5
+ | null
6
+ | ArrayBuffer
7
+ | ArrayBufferView;
8
+
9
+ /**
10
+ * Object returned by SQL Query executions {
11
+ * insertId: Represent the auto-generated row id if applicable
12
+ * rowsAffected: Number of affected rows if result of a update query
13
+ * message: if status === 1, here you will find error description
14
+ * rows: if status is undefined or 0 this object will contain the query results
15
+ * }
16
+ *
17
+ * @interface QueryResult
18
+ */
19
+ export type QueryResult = {
20
+ insertId?: number;
21
+ rowsAffected: number;
22
+ res?: any[];
23
+ rows: Array<Record<string, Scalar>>;
24
+ // An array of intermediate results, just values without column names
25
+ rawRows?: Scalar[][];
26
+ columnNames?: string[];
27
+ /**
28
+ * Query metadata, available only for select query results
29
+ */
30
+ metadata?: ColumnMetadata[];
31
+ };
32
+
33
+ /**
34
+ * Column metadata
35
+ * Describes some information about columns fetched by the query
36
+ */
37
+ export type ColumnMetadata = {
38
+ /** The name used for this column for this result set */
39
+ name: string;
40
+ /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. "UNKNOWN" for dynamic values, like function returned ones. */
41
+ type: string;
42
+ /**
43
+ * The index for this column for this result set*/
44
+ index: number;
45
+ };
46
+
47
+ /**
48
+ * Allows the execution of bulk of sql commands
49
+ * inside a transaction
50
+ * If a single query must be executed many times with different arguments, its preferred
51
+ * to declare it a single time, and use an array of array parameters.
52
+ */
53
+ export type SQLBatchTuple =
54
+ | [string]
55
+ | [string, Scalar[]]
56
+ | [string, Scalar[][]];
57
+
58
+ export type UpdateHookOperation = 'INSERT' | 'DELETE' | 'UPDATE';
59
+
60
+ /**
61
+ * status: 0 or undefined for correct execution, 1 for error
62
+ * message: if status === 1, here you will find error description
63
+ * rowsAffected: Number of affected rows if status == 0
64
+ */
65
+ export type BatchQueryResult = {
66
+ rowsAffected?: number;
67
+ };
68
+
69
+ /**
70
+ * Result of loading a file and executing every line as a SQL command
71
+ * Similar to BatchQueryResult
72
+ */
73
+ export type FileLoadResult = BatchQueryResult & {
74
+ commands?: number;
75
+ };
76
+
77
+ export type Transaction = {
78
+ commit: () => Promise<QueryResult>;
79
+ execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
80
+ rollback: () => QueryResult;
81
+ };
82
+
83
+ export type _PendingTransaction = {
84
+ /*
85
+ * The start function should not throw or return a promise because the
86
+ * queue just calls it and does not monitor for failures or completions.
87
+ *
88
+ * It should catch any errors and call the resolve or reject of the wrapping
89
+ * promise when complete.
90
+ *
91
+ * It should also automatically commit or rollback the transaction if needed
92
+ */
93
+ start: () => void;
94
+ };
95
+
96
+ export type PreparedStatement = {
97
+ bind: (params: any[]) => Promise<void>;
98
+ bindSync: (params: any[]) => void;
99
+ execute: () => Promise<QueryResult>;
100
+ };
101
+
102
+ export type _InternalDB = {
103
+ close: () => void;
104
+ delete: (location?: string) => void;
105
+ attach: (params: {
106
+ secondaryDbFileName: string;
107
+ alias: string;
108
+ location?: string;
109
+ }) => void;
110
+ detach: (alias: string) => void;
111
+ transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;
112
+ executeSync: (query: string, params?: Scalar[]) => QueryResult;
113
+ execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
114
+ executeWithHostObjects: (
115
+ query: string,
116
+ params?: Scalar[]
117
+ ) => Promise<QueryResult>;
118
+ executeBatch: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
119
+ loadFile: (location: string) => Promise<FileLoadResult>;
120
+ updateHook: (
121
+ callback?:
122
+ | ((params: {
123
+ table: string;
124
+ operation: UpdateHookOperation;
125
+ row?: any;
126
+ rowId: number;
127
+ }) => void)
128
+ | null
129
+ ) => void;
130
+ commitHook: (callback?: (() => void) | null) => void;
131
+ rollbackHook: (callback?: (() => void) | null) => void;
132
+ prepareStatement: (query: string) => PreparedStatement;
133
+ loadExtension: (path: string, entryPoint?: string) => void;
134
+ executeRaw: (query: string, params?: Scalar[]) => Promise<any[]>;
135
+ executeRawSync: (query: string, params?: Scalar[]) => any[];
136
+ getDbPath: (location?: string) => string;
137
+ reactiveExecute: (params: {
138
+ query: string;
139
+ arguments: any[];
140
+ fireOn: {
141
+ table: string;
142
+ ids?: number[];
143
+ }[];
144
+ callback: (response: any) => void;
145
+ }) => () => void;
146
+ sync: () => void;
147
+ flushPendingReactiveQueries: () => Promise<void>;
148
+ };
149
+
150
+ export type DB = {
151
+ close: () => void;
152
+ delete: (location?: string) => void;
153
+ attach: (params: {
154
+ secondaryDbFileName: string;
155
+ alias: string;
156
+ location?: string;
157
+ }) => void;
158
+ detach: (alias: string) => void;
159
+ /**
160
+ * Wraps all the executions into a transaction. If an error is thrown it will rollback all of the changes
161
+ *
162
+ * You need to use this if you are using reactive queries for the queries to fire after the transaction is done
163
+ */
164
+ transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;
165
+ /**
166
+ * Sync version of the execute function
167
+ * It will block the JS thread and therefore your UI and should be used with caution
168
+ *
169
+ * When writing your queries, you can use the ? character as a placeholder for parameters
170
+ * The parameters will be automatically escaped and sanitized
171
+ *
172
+ * Example:
173
+ * db.executeSync('SELECT * FROM table WHERE id = ?', [1]);
174
+ *
175
+ * If you are writing a query that doesn't require parameters, you can omit the second argument
176
+ *
177
+ * If you are writing to the database YOU SHOULD BE USING TRANSACTIONS!
178
+ * Transactions protect you from partial writes and ensure that your data is always in a consistent state
179
+ *
180
+ * @param query
181
+ * @param params
182
+ * @returns QueryResult
183
+ */
184
+ executeSync: (query: string, params?: Scalar[]) => QueryResult;
185
+ /**
186
+ * Basic query execution function, it is async don't forget to await it
187
+ *
188
+ * When writing your queries, you can use the ? character as a placeholder for parameters
189
+ * The parameters will be automatically escaped and sanitized
190
+ *
191
+ * Example:
192
+ * await db.execute('SELECT * FROM table WHERE id = ?', [1]);
193
+ *
194
+ * If you are writing a query that doesn't require parameters, you can omit the second argument
195
+ *
196
+ * If you are writing to the database YOU SHOULD BE USING TRANSACTIONS!
197
+ * Transactions protect you from partial writes and ensure that your data is always in a consistent state
198
+ *
199
+ * If you need a large amount of queries ran as fast as possible you should be using `executeBatch`, `executeRaw`, `loadFile` or `executeWithHostObjects`
200
+ *
201
+ * @param query string of your SQL query
202
+ * @param params a list of parameters to bind to the query, if any
203
+ * @returns Promise<QueryResult> with the result of the query
204
+ */
205
+ execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
206
+ /**
207
+ * Similar to the execute function but returns the response in HostObjects
208
+ * Read more about HostObjects in the documentation and their pitfalls
209
+ *
210
+ * Will be a lot faster than the normal execute functions when returning data but you will pay when accessing the fields
211
+ * as the conversion is done the moment you access any field
212
+ * @param query
213
+ * @param params
214
+ * @returns
215
+ */
216
+ executeWithHostObjects: (
217
+ query: string,
218
+ params?: Scalar[]
219
+ ) => Promise<QueryResult>;
220
+ /**
221
+ * Executes all the queries in the params inside a single transaction
222
+ *
223
+ * It's faster than executing single queries as data is sent to the native side only once
224
+ * @param commands
225
+ * @returns Promise<BatchQueryResult>
226
+ */
227
+ executeBatch: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
228
+ /**
229
+ * Loads a SQLite Dump from disk. It will be the fastest way to execute a large set of queries as no JS is involved
230
+ */
231
+ loadFile: (location: string) => Promise<FileLoadResult>;
232
+ updateHook: (
233
+ callback?:
234
+ | ((params: {
235
+ table: string;
236
+ operation: UpdateHookOperation;
237
+ row?: any;
238
+ rowId: number;
239
+ }) => void)
240
+ | null
241
+ ) => void;
242
+ commitHook: (callback?: (() => void) | null) => void;
243
+ rollbackHook: (callback?: (() => void) | null) => void;
244
+ /**
245
+ * Constructs a prepared statement from the query string
246
+ * The statement can be re-bound with parameters and executed
247
+ * The performance gain is significant when the same query is executed multiple times, NOT when the query is executed (once)
248
+ * The cost lies in the preparation of the statement as it is compiled and optimized by the sqlite engine, the params can then rebound
249
+ * but the query itself is already optimized
250
+ *
251
+ * @param query string of your SQL query
252
+ * @returns Prepared statement object
253
+ */
254
+ prepareStatement: (query: string) => PreparedStatement;
255
+ /**
256
+ * Loads a runtime loadable sqlite extension. Libsql and iOS embedded version do not support loading extensions
257
+ */
258
+ loadExtension: (path: string, entryPoint?: string) => void;
259
+ /**
260
+ * Same as `execute` except the results are not returned in objects but rather in arrays with just the values and not the keys
261
+ * It will be faster since a lot of repeated work is skipped and only the values you care about are returned
262
+ */
263
+ executeRaw: (query: string, params?: Scalar[]) => Promise<any[]>;
264
+ /**
265
+ * Same as `executeRaw` but it will block the JS thread and therefore your UI and should be used with caution
266
+ * It will return an array of arrays with just the values and not the keys
267
+ */
268
+ executeRawSync: (query: string, params?: Scalar[]) => any[];
269
+ /**
270
+ * Get's the absolute path to the db file. Useful for debugging on local builds and for attaching the DB from users devices
271
+ */
272
+ getDbPath: (location?: string) => string;
273
+ /**
274
+ * Reactive execution of queries when data is written to the database. Check the docs for how to use them.
275
+ */
276
+ reactiveExecute: (params: {
277
+ query: string;
278
+ arguments: any[];
279
+ fireOn: {
280
+ table: string;
281
+ ids?: number[];
282
+ }[];
283
+ callback: (response: any) => void;
284
+ }) => () => void;
285
+ /** This function is only available for libsql.
286
+ * Allows to trigger a sync the database with it's remote replica
287
+ * In order for this function to work you need to use openSync or openRemote functions
288
+ * with libsql: true in the package.json
289
+ *
290
+ * The database is hosted in turso
291
+ **/
292
+ sync: () => void;
293
+ };
294
+
295
+ export type DBParams = {
296
+ url?: string;
297
+ authToken?: string;
298
+ name?: string;
299
+ location?: string;
300
+ syncInterval?: number;
301
+ };
302
+
303
+ export type OPSQLiteProxy = {
304
+ open: (options: {
305
+ name: string;
306
+ location?: string;
307
+ encryptionKey?: string;
308
+ }) => _InternalDB;
309
+ openRemote: (options: { url: string; authToken: string }) => _InternalDB;
310
+ openSync: (options: DBParams) => _InternalDB;
311
+ isSQLCipher: () => boolean;
312
+ isLibsql: () => boolean;
313
+ isIOSEmbedded: () => boolean;
314
+ };