@@ -29,7 +29,7 @@ export interface SQLJSOpenOptions extends SQLOpenOptions {
29
29
}
30
30
31
31
export interface ResolvedSQLJSOpenOptions extends SQLJSOpenOptions {
32
- persister : SQLJSPersister ;
32
+ persister ? : SQLJSPersister ;
33
33
logger : ILogger ;
34
34
}
35
35
@@ -96,21 +96,19 @@ export class SQLJSDBAdapter extends BaseObserver<DBAdapterListener> implements D
96
96
} ) ;
97
97
98
98
this . writeScheduler = new ControlledExecutor ( async ( db : SQLJs . Database ) => {
99
+ if ( ! this . options . persister ) {
100
+ return ;
101
+ }
102
+
99
103
await this . options . persister . writeFile ( db . export ( ) ) ;
100
104
} ) ;
101
105
}
102
106
103
107
protected resolveOptions ( options : SQLJSOpenOptions ) : ResolvedSQLJSOpenOptions {
104
- const persister = options . persister ?? {
105
- readFile : async ( ) => null ,
106
- writeFile : async ( ) => { }
107
- } ;
108
-
109
108
const logger = options . logger ?? createLogger ( 'SQLJSDBAdapter' ) ;
110
109
111
110
return {
112
111
...options ,
113
- persister,
114
112
logger
115
113
} ;
116
114
}
@@ -125,7 +123,7 @@ export class SQLJSDBAdapter extends BaseObserver<DBAdapterListener> implements D
125
123
this . options . logger . error ( '[stderr]' , text ) ;
126
124
}
127
125
} ) ;
128
- const existing = await this . options . persister . readFile ( ) ;
126
+ const existing = await this . options . persister ? .readFile ( ) ;
129
127
const db = new SQL . Database ( existing ) ;
130
128
this . dbP = db [ 'db' ] ;
131
129
this . _db = db ;
@@ -262,7 +260,10 @@ export class SQLJSDBAdapter extends BaseObserver<DBAdapterListener> implements D
262
260
const db = await this . getDB ( ) ;
263
261
const result = await fn ( this . generateLockContext ( ) ) ;
264
262
265
- this . writeScheduler . schedule ( db ) ;
263
+ // No point to schedule a write if there's no persister.
264
+ if ( this . options . persister ) {
265
+ this . writeScheduler . schedule ( db ) ;
266
+ }
266
267
267
268
const notification : BatchedUpdateNotification = {
268
269
rawUpdates : [ ] ,
0 commit comments