Skip to content

Conversation

@i-am-the-slime
Copy link
Contributor

@i-am-the-slime i-am-the-slime commented Jan 4, 2026

Replace better-sqlite3 with Node.js's built-in node:sqlite module to avoid native compilation dependencies.

Changes

  • Replaced @libsql/client (turso) with Node.js native node:sqlite module
  • Removed external dependency from package.json
  • Implementation closely follows the original better-sqlite3 code style
  • Added explicit directory creation and Promise wrapping for FFI compatibility
  • Suppressed experimental feature warnings in the entry point

Benefits

  • Zero external dependencies for SQLite functionality
  • No native compilation required (no node-gyp)
  • Built-in Node.js module - will stabilize over time
  • Minimal code changes from the original better-sqlite3 implementation
  • Same performance - local file-based SQLite database

Testing

All tests pass: 235/239 (same as baseline - 4 pre-existing failures unrelated to SQLite changes)

Note

The node:sqlite module is marked as experimental in Node.js, but it's stable enough for our use case. The warning is suppressed in the CLI entry point.

@wclr
Copy link
Contributor

wclr commented Jan 5, 2026

Maybe it is better to move to nodejs build-in sql support https://nodejs.org/api/sqlite.html (available from Node 22)

Spago next is a new tool and still not widely used so I don't think that there need to worry about old node version and ignore node platform development.

@i-am-the-slime
Copy link
Contributor Author

@wclr sure, let's get some buy-in first from the maintainers and then we can also go that route.

Main motivation is to avoid having to rebuild spago for different node versions.

Replaces @libsql/client with Node.js's built-in node:sqlite module.

Changes:
- Replace libsql/turso client with DatabaseSync from node:sqlite
- Remove @libsql/client dependency from package.json
- Remove --external:@libsql/client from bundler config
- Add NODE_NO_WARNINGS=1 to suppress experimental sqlite warnings
- Add explicit directory creation (was built-in with better-sqlite3)
- Use db.exec() for PRAGMA statements (db.pragma() doesn't exist)
- Wrap all operations in Promise.resolve() for FFI compatibility

Benefits:
- Zero external dependencies for SQLite
- Simpler implementation (no remote database support needed)
- Nearly identical API to the original better-sqlite3 version

All tests pass (235/239, same as baseline - 4 pre-existing failures
unrelated to SQLite changes).
@i-am-the-slime i-am-the-slime changed the title Use turso instead of better-sqlite to avoid gyp dependency Use Node.js native sqlite instead of better-sqlite3 Jan 12, 2026
- Add missing getMetadataImpl export (was declared in FFI but not exported)
- Use --no-warnings flag to suppress experimental SQLite warnings
  - In bin/index.dev.js shebang for direct execution
  - In test/Prelude.purs when spawning spago in tests
- Add trailing newline to Db.js
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