@op-engineering/op-sqlite 15.0.2 → 15.0.4

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.
@@ -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,C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AAQ,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,CAAC,OAAO,EAAE;QACd,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,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"}
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.4",
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;
@@ -449,10 +449,15 @@ export const isLibsql = (): boolean => {
449
449
  return OPSQLite.isLibsql();
450
450
  };
451
451
 
452
- export const isIOSEmbeeded = (): boolean => {
452
+ export const isIOSEmbedded = (): boolean => {
453
453
  if (Platform.OS !== 'ios') {
454
454
  return false;
455
455
  }
456
456
 
457
457
  return OPSQLite.isIOSEmbedded();
458
458
  };
459
+
460
+ /**
461
+ * @deprecated Use `isIOSEmbedded` instead. This alias will be removed in a future release.
462
+ */
463
+ export const isIOSEmbeeded = isIOSEmbedded;
package/src/index.ts CHANGED
@@ -1,322 +1,34 @@
1
1
  import { NativeModules } from 'react-native';
2
2
 
3
+ export {
4
+ OPSQLite,
5
+ open,
6
+ openRemote,
7
+ openSync,
8
+ moveAssetsDatabase,
9
+ getDylibPath,
10
+ isSQLCipher,
11
+ isLibsql,
12
+ isIOSEmbedded,
13
+ isIOSEmbeeded,
14
+ } from './functions';
3
15
  export { Storage } from './Storage';
4
- 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
- };
16
+ export type {
17
+ Scalar,
18
+ QueryResult,
19
+ ColumnMetadata,
20
+ SQLBatchTuple,
21
+ UpdateHookOperation,
22
+ BatchQueryResult,
23
+ FileLoadResult,
24
+ Transaction,
25
+ _PendingTransaction,
26
+ PreparedStatement,
27
+ _InternalDB,
28
+ DB,
29
+ DBParams,
30
+ OPSQLiteProxy,
31
+ } from './types';
320
32
 
321
33
  export const {
322
34
  IOS_DOCUMENT_PATH,