Skip to content

Commit 6ebaabe

Browse files
a11rewChriztiaan
andauthored
fix: construct open options with defined properties only (powersync-ja#638)
Co-authored-by: Christiaan Landman <[email protected]>
1 parent b7255b7 commit 6ebaabe

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

.changeset/five-colts-whisper.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/op-sqlite': patch
3+
---
4+
5+
Fixed an issue where the default `op-sqlite` database location determination logic was being overridden. The `dbLocation` is now only applied when explicitly provided, resolving issues with features like iOS App Groups.

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+
// 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)