File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
1313} from '@powersync/web' ;
1414import Lock from 'async-lock' ;
1515import { PowerSyncCore } from '../plugin/PowerSyncCore' ;
16+ import { messageForErrorCode } from '../plugin/PowerSyncPlugin' ;
1617
1718/**
1819 * An implementation of {@link DBAdapter} using the Capacitor Community SQLite [plugin](https://github.com/capacitor-community/sqlite).
@@ -48,8 +49,16 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
4849 return this . _readConnection ;
4950 }
5051
52+ get name ( ) {
53+ return this . options . dbFilename ;
54+ }
55+
5156 private async init ( ) {
52- await PowerSyncCore . registerCore ( ) ;
57+ const { responseCode : registrationResponseCode } = await PowerSyncCore . registerCore ( ) ;
58+ if ( registrationResponseCode != 0 ) {
59+ throw new Error ( `Could not register PowerSync core extension: ${ messageForErrorCode ( registrationResponseCode ) } ` ) ;
60+ }
61+
5362 const sqlite = new SQLiteConnection ( CapacitorSQLite ) ;
5463
5564 // It seems like the isConnection and retrieveConnection methods
@@ -75,9 +84,6 @@ export class CapacitorSQLiteAdapter extends BaseObserver<DBAdapterListener> impl
7584 await this . writeConnection . close ( ) ;
7685 await this . readConnection . close ( ) ;
7786 }
78- get name ( ) {
79- return this . options . dbFilename ;
80- }
8187
8288 protected generateLockContext ( db : SQLiteDBConnection ) : LockContext {
8389 const execute = async ( query : string , params : any [ ] = [ ] ) : Promise < QueryResult > => {
Original file line number Diff line number Diff line change @@ -8,6 +8,19 @@ export type RegistrationResponse = {
88 responseCode : number ;
99} ;
1010
11+ export const messageForErrorCode = ( code : number ) : string => {
12+ switch ( code ) {
13+ case - 1 :
14+ return '[Android] SQLCipher library not found' ;
15+ case - 2 :
16+ return '[Android] Required symbols not found' ;
17+ case 0 :
18+ return 'Success' ;
19+ default :
20+ return `Extension registration failed with SQLite error code: ${ code } ` ;
21+ }
22+ } ;
23+
1124export interface PowerSyncPlugin {
1225 /**
1326 * Registers the PowerSync core extension with the SQLite library.
You can’t perform that action at this time.
0 commit comments