feat: Add dbDirectory parameter for custom database storage locations#111
Open
nightfall708 wants to merge 1 commit intopowersync-ja:mainfrom
Open
feat: Add dbDirectory parameter for custom database storage locations#111nightfall708 wants to merge 1 commit intopowersync-ja:mainfrom
nightfall708 wants to merge 1 commit intopowersync-ja:mainfrom
Conversation
…abase storage locations
This enables storing the database in a shared App Group container,
which is essential for iOS apps that need to share data between the
main app and extensions (e.g. Share Extensions, widgets).
The Kotlin SDK already supports a dbDirectory parameter - this change
threads it through the Swift API layer and ensures deleteDatabase()
respects the custom directory.
Usage:
```swift
let containerURL = FileManager.default.containerURL(
forSecurityApplicationGroupIdentifier: "group.com.example.app"
)
let db = PowerSyncDatabase(
schema: schema,
dbFilename: "powersync.db",
dbDirectory: containerURL?.path
)
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dbDirectoryparameter toPowerSyncDatabase()that allows specifying a custom directory path for the database filedbDirectory— this change threads it through the Swift API layerMotivation
Currently,
dbFilenameonly accepts a filename (not a path), and the database is always stored in the hardcoded Application Support directory. This makes it impossible to share the database between the main app and app extensions without going through a cloud round-trip.Before: Share Extension writes to its own PowerSync database → syncs to cloud → main app syncs from cloud (slow, requires connectivity)
After: Both main app and Share Extension point to the same database file in the App Group container (instant local access)
Usage
Changes
PowerSyncDatabase.swiftdbDirectory: String? = nilparameter to the public APIKotlinPowerSyncDatabaseImpl.swiftdbDirectorythrough to the Kotlin SDK; use it indeleteDatabase()KotlinPowerSyncDatabaseImplTests.swiftCHANGELOG.mdTest plan
swift build✅)swift build --build-tests✅)testCustomDbDirectory— verifies database is created in custom directory, not the defaulttestCustomDbDirectoryCloseWithDeleteDatabase— verifies all SQLite files (db, wal, shm) are cleaned up from custom directorydbDirectoryisnil)