Skip to content

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Aug 8, 2025

This PR updates the node driver to use the the powersync_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 upstream better-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 bundle better-sqlite3 now. I've adopted the Electron demo, and added a section about this to the readme.

Copy link

changeset-bot bot commented Aug 8, 2025

🦋 Changeset detected

Latest commit: 8ef7933

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@powersync/node Minor

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

@rkistner
Copy link
Contributor

rkistner commented Aug 8, 2025

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?

@simolus3 simolus3 changed the title Node: Support using node:sqlite driver Node: Support using node:sqlite and encryption Sep 11, 2025
@simolus3 simolus3 marked this pull request as ready for review September 11, 2025 10:52
@simolus3 simolus3 requested a review from rkistner September 11, 2025 10:52
@simolus3
Copy link
Contributor Author

simolus3 commented Sep 11, 2025

Could we use the same approach for update notifications for better-sqlite3

Yes! I've refactored the connection setup to share that between node:sqlite and better-sqlite3.

Would that allow us to switch back to upstream better-sqlite3, or are there other blockers currently?

That seems to have been the only blocker, I've migrated the package back to better-sqlite3.

I've also expanded the worker API to allow custom better-sqlite3 forks, the demo now supports encryption thanks to this.

we could perhaps switch to node:sqlite by default when we do a v1.0 release

To prepare for that, I've made better-sqlite3 an optional peer dependency. That is a breaking change, because:

  • users now need to import that package.
  • we only import better-sqlite3 with a dynamic import() / require() call when it's actually used (to avoid having it as a dependency when users want to use node:sqlite). This breaks some bundler setups, but I've described the issue in the readme and updated the examples.

Still, I think it's worth it because we need this for encryption / to later support node:sqlite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants