@@ -29,7 +29,7 @@ export interface SQLJSOpenOptions extends SQLOpenOptions {
2929}
3030
3131export interface ResolvedSQLJSOpenOptions extends SQLJSOpenOptions {
32- persister : SQLJSPersister ;
32+ persister ? : SQLJSPersister ;
3333 logger : ILogger ;
3434}
3535
@@ -96,21 +96,19 @@ export class SQLJSDBAdapter extends BaseObserver<DBAdapterListener> implements D
9696 } ) ;
9797
9898 this . writeScheduler = new ControlledExecutor ( async ( db : SQLJs . Database ) => {
99+ if ( ! this . options . persister ) {
100+ return ;
101+ }
102+
99103 await this . options . persister . writeFile ( db . export ( ) ) ;
100104 } ) ;
101105 }
102106
103107 protected resolveOptions ( options : SQLJSOpenOptions ) : ResolvedSQLJSOpenOptions {
104- const persister = options . persister ?? {
105- readFile : async ( ) => null ,
106- writeFile : async ( ) => { }
107- } ;
108-
109108 const logger = options . logger ?? createLogger ( 'SQLJSDBAdapter' ) ;
110109
111110 return {
112111 ...options ,
113- persister,
114112 logger
115113 } ;
116114 }
@@ -125,7 +123,7 @@ export class SQLJSDBAdapter extends BaseObserver<DBAdapterListener> implements D
125123 this . options . logger . error ( '[stderr]' , text ) ;
126124 }
127125 } ) ;
128- const existing = await this . options . persister . readFile ( ) ;
126+ const existing = await this . options . persister ? .readFile ( ) ;
129127 const db = new SQL . Database ( existing ) ;
130128 this . dbP = db [ 'db' ] ;
131129 this . _db = db ;
@@ -262,7 +260,10 @@ export class SQLJSDBAdapter extends BaseObserver<DBAdapterListener> implements D
262260 const db = await this . getDB ( ) ;
263261 const result = await fn ( this . generateLockContext ( ) ) ;
264262
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+ }
266267
267268 const notification : BatchedUpdateNotification = {
268269 rawUpdates : [ ] ,
0 commit comments