@@ -8,12 +8,12 @@ import {
88 DBLockOptions ,
99 LockContext ,
1010 QueryResult ,
11- SQLOpenOptions ,
1211 Transaction
1312} from '@powersync/web' ;
1413import Lock from 'async-lock' ;
1514import { PowerSyncCore } from '../plugin/PowerSyncCore' ;
1615import { messageForErrorCode } from '../plugin/PowerSyncPlugin' ;
16+ import { CapacitorSQLiteOpenFactoryOptions , DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory' ;
1717
1818/**
1919 * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
@@ -27,7 +27,7 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
2727 protected initializedPromise : Promise < void > ;
2828 protected lock : Lock ;
2929
30- constructor ( protected options : SQLOpenOptions ) {
30+ constructor ( protected options : CapacitorSQLiteOpenFactoryOptions ) {
3131 super ( ) ;
3232 this . _writeConnection = null ;
3333 this . _readConnection = null ;
@@ -72,11 +72,17 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
7272 this . _writeConnection = await sqlite . createConnection ( this . options . dbFilename , false , 'no-encryption' , 1 , false ) ;
7373 this . _readConnection = await sqlite . createConnection ( this . options . dbFilename , false , 'no-encryption' , 1 , true ) ;
7474
75- // TODO validate WAL mode
7675 await this . _writeConnection . open ( ) ;
77- await this . _readConnection . open ( ) ;
7876
79- this . writeConnection . query ( "SELECT powersync_update_hooks('install')" ) ;
77+ const { cacheSizeKb, journalSizeLimit, synchronous } = { ...DEFAULT_SQLITE_OPTIONS , ...this . options . sqliteOptions } ;
78+ await this . writeConnection . query ( "SELECT powersync_update_hooks('install')" ) ;
79+ await this . writeConnection . query ( 'PRAGMA journal_mode = WAL' ) ;
80+ await this . writeConnection . query ( `PRAGMA journal_size_limit = ${ journalSizeLimit } ` ) ;
81+ await this . writeConnection . query ( `PRAGMA temp_store = memory` ) ;
82+ await this . writeConnection . query ( `PRAGMA synchronous = ${ synchronous } ` ) ;
83+ await this . writeConnection . query ( `PRAGMA cache_size = -${ cacheSizeKb } ` ) ;
84+
85+ await this . _readConnection . open ( ) ;
8086 }
8187
8288 async close ( ) : Promise < void > {
0 commit comments