Skip to content

feat: migrate from better-sqlite3 to Signal K Database API#59

Open
dirkwa wants to merge 1 commit intoxbgmsharp:mainfrom
dirkwa:feat-database-api
Open

feat: migrate from better-sqlite3 to Signal K Database API#59
dirkwa wants to merge 1 commit intoxbgmsharp:mainfrom
dirkwa:feat-database-api

Conversation

@dirkwa
Copy link

@dirkwa dirkwa commented Mar 4, 2026

Summary

Migrate from shipping better-sqlite3 as a direct dependency to using the new server-managed Database API.

  • Remove better-sqlite3 from package.json — no more native binary, no more rebuild issues on ARM or Node upgrades
  • Use app.getDatabaseApi().getPluginDb(plugin.id) for an isolated, server-managed SQLite database
  • Schema migrations handled by db.migrate() with version tracking
  • All queries converted from sync db.prepare().all/run() to async db.query()/db.run()
  • Added async init guards — interval callbacks check if (!db) since getPluginDb() is async

Depends on

This PR requires SignalK/signalk-server#2409 to be merged first. That PR adds the Database API to Signal K server.

Tested

  • Verified on a live server (Node 22, Debian) with real GPS data
  • Buffer table created and migrated correctly
  • Data queued, submitted to PostgSail backend, and deleted from buffer as expected
  • WAL mode active (.db-shm and .db-wal files present)

Replace direct better-sqlite3 usage with the server-managed Database API.
The server now provides an isolated database per plugin — no need to ship
our own SQLite binary.

- Remove better-sqlite3 dependency from package.json
- Use app.getDatabaseApi().getPluginDb() for async DB initialization
- Convert all db.prepare().run/all() calls to db.run()/db.query()
- Add async init guards for interval callbacks (db may be undefined
  until getPluginDb() resolves)
- Migrations handled by db.migrate() instead of manual CREATE TABLE
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.

1 participant