-
Notifications
You must be signed in to change notification settings - Fork 56
Node: Support using node:sqlite and encryption #690
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 8ef7933 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 |
This looks quite promising! If this works well, we could perhaps switch to node:sqlite by default when we do a v1.0 release, moving better-sqlite3 support to a separate package or import (removing it from the default dependencies). I'm also wondering: Could we use the same approach for update notifications for better-sqlite3? Would that allow us to switch back to upstream better-sqlite3, or are there other blockers currently? |
2579765
to
c99ebb0
Compare
Yes! I've refactored the connection setup to share that between
That seems to have been the only blocker, I've migrated the package back to I've also expanded the worker API to allow custom
To prepare for that, I've made
Still, I think it's worth it because we need this for encryption / to later support |
This PR updates the
node
driver to use the thepowersync_update_hooks
helper instead of registering update hooks on the SQLite connection.Because update hooks were the only reason we needed a
better-sqlite3
fork, this migrates the package back to upstreambetter-sqlite3
(which is nice because that has prebuilts set up and is much easier to install).Additionally, this allows customizing workers to load another package instead of
better-sqlite3
. This is particularly interesting for e.g.better-sqlite3-multiple-ciphers
for encryption. I've updated the node demo to support both packages, switching between them depending on environment variables.Because update hooks are no longer something we need from the underlying driver, this also adds an experimental database implementation based on
node:sqlite
APIs.I've made
better-sqlite3
an optional peer dependency, and I'm only importing it conditionally when it's actually used. This works well with the node demo, but for apps that use bundlers, the bundler needs a static hint to bundlebetter-sqlite3
now. I've adopted the Electron demo, and added a section about this to the readme.