- 
                Notifications
    You must be signed in to change notification settings 
- Fork 58
Capacitor Community SQLite #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| 🦋 Changeset detectedLatest commit: fd25e44 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
 Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR | 
| 
 The future is now! With version 0.4.5 of the core extension, you can: 
 | 
| Some basic benchmark comparisons were ran on an Android Emulator + iPhone Simulator. const now = performance.now();
for (let i = 0; i < 1_000; i++) {
  await powerSync.execute('INSERT INTO customers (id, name) VALUES (uuid(), ?)', [`Customer`]);
}
const end = performance.now();
 For general mobile comparisons, see https://www.powersync.com/blog/react-native-database-performance-comparison | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool to see powersync_update_hooks in action :)
        fd25e44
      
    
Overview
Theoretically, one should be able to use the PowerSync Web SDK in Capacitor Webviews. Recent support items have shown that while this works in practice, the experience is not very stable in some circumstances.
This uses https://github.com/capacitor-community/sqlite as the SQLite driver for PowerSync - with the main aim to target iOS and Android platforms (only iOS has been tested so far).
The Capacitor Community SQLite package currently poses some challenges for PowerSync's use-case:
Unhandled Promise Rejection: Error: "CapacitorSQLite.loadExtension()" is not implemented on iosexecutemethods.We can work around most of these limitations.
Extension Loading
This PR adds a Capacitor Plugin which includes the PowerSync Rust core into a project. We can then register a static SQLite auto extension. We use the low level C APIs for this.
We currently statically register the PowerSync core extension on iOS platforms.
Android now supports dynamically loading extensions.
Update Hooks
We register an update hook implementation internally via our Rust Core implementation.
Query execution differences
This is documented as a limitation of the API for Android.
Changes In This PR
example-capacitordemo is upgraded to Capacitor v7.@powersync/capacitorpackage is introduced. The scaffolding for this was taken from a Capacitor plugin templateexample-appto verify iOS compilationTODOS
CapacitorSQLiteAdapterfor theDBAdapterprovided to the PowerSync Web SDK. While this does work, it seems messy. We should probably introduce a dedicated Capacitor PowerSyncDatabase constructor.Future Work:
Unit tests will be added after the initial release.