Skip to content

Commit 31d0344

Browse files
committed
fix: construct open options with defined properties only
1 parent 7590cc5 commit 31d0344

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

packages/powersync-op-sqlite/src/db/OPSqliteAdapter.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,30 +112,21 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
112112
});
113113
}
114114

115-
private getDbLocation(dbLocation?: string): string {
116-
if (Platform.OS === 'ios') {
117-
return dbLocation ?? IOS_LIBRARY_PATH;
118-
} else {
119-
return dbLocation ?? ANDROID_DATABASE_PATH;
115+
private openDatabase(dbFilename: string, encryptionKey?: string): DB {
116+
const openOptions: Parameters<typeof open>[0] = {
117+
name: dbFilename
118+
};
119+
120+
if (this.options.dbLocation) {
121+
openOptions.location = this.options.dbLocation;
120122
}
121-
}
122123

123-
private openDatabase(dbFilename: string, encryptionKey?: string): DB {
124-
//This is needed because an undefined/null dbLocation will cause the open function to fail
125-
const location = this.getDbLocation(this.options.dbLocation);
126-
//Simarlily if the encryption key is undefined/null when using SQLCipher it will cause the open function to fail
124+
// Similarly if the encryption key is undefined/null when using SQLCipher it will cause the open function to fail
127125
if (encryptionKey) {
128-
return open({
129-
name: dbFilename,
130-
location: location,
131-
encryptionKey: encryptionKey
132-
});
133-
} else {
134-
return open({
135-
name: dbFilename,
136-
location: location
137-
});
126+
openOptions.encryptionKey = encryptionKey;
138127
}
128+
129+
return open(openOptions);
139130
}
140131

141132
private loadAdditionalExtensions(DB: DB) {

0 commit comments

Comments
 (0)