File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,8 @@ sqlite3InitModule({
5151});
5252```
5353
54+ The ` db ` object above implements the [ Object Oriented API #1 ] ( https://sqlite.org/wasm/doc/tip/api-oo1.md ) .
55+
5456### In a worker (with OPFS if available):
5557
5658> ** Warning** For this to work, you need to set the following headers on your
@@ -118,7 +120,7 @@ const sqliteWorkerPath = 'assets/js/sqlite-worker.js';
118120// This is the name of your database. It corresponds to the path in the OPFS.
119121const filename = ' /test.sqlite3' ;
120122
121- const sqlite = new Sqlite (filename, sqliteWorkerPath);
123+ const sqlite = new SqliteClient (filename, sqliteWorkerPath);
122124await sqlite .init ();
123125
124126await sqlite .executeSql (' CREATE TABLE IF NOT EXISTS test(a,b)' );
Original file line number Diff line number Diff line change @@ -5,8 +5,9 @@ export class SqliteClient {
55
66 dbFile = '' ;
77 sqliteWorkerPath = '' ;
8+ rowMode = 'object' ;
89
9- constructor ( dbFile , sqliteWorkerPath ) {
10+ constructor ( dbFile , sqliteWorkerPath , rowMode ) {
1011 if ( typeof dbFile !== 'string' ) {
1112 throw new Error (
1213 `The 'dbFile' parameter passed to the 'SqliteClient' constructor must be of type 'string'. Instead, you passed: '${ typeof dbFile } '.` ,
@@ -21,6 +22,10 @@ export class SqliteClient {
2122
2223 this . dbFile = dbFile ;
2324 this . sqliteWorkerPath = sqliteWorkerPath ;
25+ if ( rowMode && rowMode !== 'array' && rowMode !== 'object' ) {
26+ throw new Error ( 'Invalid rowMode' ) ;
27+ }
28+ this . rowMode = rowMode || this . rowMode ;
2429 }
2530
2631 async init ( ) {
@@ -32,7 +37,7 @@ export class SqliteClient {
3237
3338 this . sqliteWorker = await new SqliteWorker ( ) ;
3439
35- await this . sqliteWorker . init ( this . dbFile ) ;
40+ await this . sqliteWorker . init ( this . dbFile , this . rowMode ) ;
3641 }
3742
3843 async executeSql ( sqlStatement , bindParameters = [ ] ) {
Original file line number Diff line number Diff line change @@ -6,7 +6,12 @@ const error = (...args) => console.error(...args);
66
77class SqliteWorker {
88 db ;
9- init ( dbFile ) {
9+ rowMode = 'object' ;
10+ init ( dbFile , rowMode ) {
11+ if ( rowMode && rowMode !== 'array' && rowMode !== 'object' ) {
12+ throw new Error ( 'Invalid rowMode' ) ;
13+ }
14+ this . rowMode = rowMode || this . rowMode ;
1015 return new Promise ( ( resolve ) => {
1116 sqlite3InitModule ( {
1217 print : log ,
@@ -29,7 +34,7 @@ class SqliteWorker {
2934 sql : sqlStatement ,
3035 bind : bindParameters ,
3136 returnValue : 'resultRows' ,
32- rowMode : 'array' ,
37+ rowMode : this . rowMode ,
3338 } ) ,
3439 ) ;
3540 }
You can’t perform that action at this time.
0 commit comments