Title: Replace better-sqlite3 with sql.js for cross-platform compatibility · Issue #92 · JavaScriptSolidServer/JavaScriptSolidServer · GitHub
Open Graph Title: Replace better-sqlite3 with sql.js for cross-platform compatibility · Issue #92 · JavaScriptSolidServer/JavaScriptSolidServer
X Title: Replace better-sqlite3 with sql.js for cross-platform compatibility · Issue #92 · JavaScriptSolidServer/JavaScriptSolidServer
Description: Problem After fixing bcrypt → bcryptjs in #91, the next blocker for Android/Termux compatibility is better-sqlite3, which also requires native C++ compilation. Current Error on Termux gyp: Undefined variable android_ndk_path in binding.g...
Open Graph Description: Problem After fixing bcrypt → bcryptjs in #91, the next blocker for Android/Termux compatibility is better-sqlite3, which also requires native C++ compilation. Current Error on Termux gyp: Undefine...
X Description: Problem After fixing bcrypt → bcryptjs in #91, the next blocker for Android/Termux compatibility is better-sqlite3, which also requires native C++ compilation. Current Error on Termux gyp: Undefine...
Opengraph URL: https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/issues/92
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Replace better-sqlite3 with sql.js for cross-platform compatibility","articleBody":"## Problem\n\nAfter fixing bcrypt → bcryptjs in #91, the next blocker for Android/Termux compatibility is `better-sqlite3`, which also requires native C++ compilation.\n\n### Current Error on Termux\n\n```\ngyp: Undefined variable android_ndk_path in binding.gyp\ngyp ERR! configure error \ngyp ERR! cwd .../node_modules/better-sqlite3\nnpm ERR! code 1\n```\n\n### Platforms Affected\n\nSame platforms as the bcrypt issue:\n- ✅ **Termux/Android** - Fails with `gyp: Undefined variable android_ndk_path`\n- ✅ **Windows** - Common node-gyp compilation errors\n- ✅ **ARM devices** - Various build issues\n- ✅ **Restricted environments** - No build tools available\n\n## Proposed Solution\n\n**Switch to sql.js as the primary SQLite implementation.**\n\n### Why This Makes Sense\n\n1. **Already a Dependency**\n - `sql.js` is already in package.json (line 41)\n - Just need to use it instead of better-sqlite3\n - No new dependencies required\n\n2. **Performance Impact is Minimal**\n \n JavaScriptSolidServer uses SQLite for:\n - Nostr relay event storage (when `--nostr` enabled)\n - ActivityPub/federation data (when ActivityPub enabled)\n - **NOT used for main pod storage** (that's filesystem-based)\n\n Performance difference:\n - better-sqlite3 (C++): ~0.1-0.5ms per query\n - sql.js (WASM): ~0.2-1ms per query\n - Difference: Sub-millisecond for infrequent federation operations\n\n3. **Real-World Usage**\n - SQLite is only used for optional federation features\n - Main pod operations (GET/PUT/POST/DELETE files) use the filesystem\n - Federation queries happen rarely compared to file operations\n - The performance difference is negligible\n\n4. **Cross-Platform Benefits**\n - Works everywhere JavaScript runs\n - No compilation step = faster npm install\n - Better user experience\n\n## Implementation\n\nSimilar to the bcrypt fix:\n\n**Before:**\n```javascript\nimport Database from 'better-sqlite3';\nconst db = new Database('data.db');\n```\n\n**After:**\n```javascript\nimport initSqlJs from 'sql.js';\nconst SQL = await initSqlJs();\nconst db = new SQL.Database();\n```\n\nNeed to update:\n- `package.json` - Remove better-sqlite3, keep sql.js\n- `src/ap/store.js` - ActivityPub storage\n- `src/nostr/relay.js` - Nostr event storage\n- Any other files using better-sqlite3\n\n## Testing Required\n\nTest that federation features still work:\n- Nostr relay event storage\n- ActivityPub inbox/outbox operations\n- Database persistence (sql.js needs file I/O wrapper)\n\n## Note on Persistence\n\n`sql.js` runs in-memory by default. For persistence, we need to:\n1. Load database from file on startup\n2. Save database to file periodically or on writes\n3. Use `fs.readFileSync()` / `fs.writeFileSync()` wrapper\n\nThis is straightforward but needs careful implementation to avoid data loss.\n\n## Alternative Approach\n\nCould also use a try/catch fallback like we originally had for bcrypt:\n\n```javascript\nlet Database;\ntry {\n Database = (await import('better-sqlite3')).default;\n} catch {\n // Use sql.js fallback\n const initSqlJs = (await import('sql.js')).default;\n Database = await createSqlJsWrapper(initSqlJs);\n}\n```\n\nBut based on the bcrypt experience, it's simpler to just use sql.js everywhere.\n\n## Impact\n\nThis would enable:\n- 📱 Running full Solid+Nostr+ActivityPub server on Android/Termux\n- 💻 Easier installation on Windows\n- 🌍 Universal compatibility\n- ⚡ Faster npm install (no compilation)\n\nCombined with the bcrypt fix, this would make JavaScriptSolidServer truly \"just works\" on all platforms.\n\n## Related\n\n- Closes after bcrypt fix #91\n- Builds on the cross-platform compatibility work\n\n## Testing on Termux\n\nAfter bcrypt fix (#91), installation now fails on better-sqlite3:\n\n```bash\n$ npx javascript-solid-server@latest --version\n# ✅ bcrypt passes (using bcryptjs)\n# ❌ better-sqlite3 fails (native compilation)\n```\n\nWith this fix, the entire stack would work.","author":{"url":"https://github.com/melvincarvalho","@type":"Person","name":"melvincarvalho"},"datePublished":"2026-01-16T12:14:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/92/JavaScriptSolidServer/issues/92"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:aafb6865-0187-3518-635e-aa454610bb8c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE5E:112FA5:D01A53:1126517:697C03C7 |
| html-safe-nonce | 8c48c343f5080bab3c67a55b25c1d67cd519f261476748b45316dedcfca11469 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTVFOjExMkZBNTpEMDFBNTM6MTEyNjUxNzo2OTdDMDNDNyIsInZpc2l0b3JfaWQiOiI3NTY4OTkwNjQ4MTIwNjQwNDU1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3e1971da70e8267d2d6010be1bcaa6936cfb1fdfe68aa5555860faca6a5c729b |
| hovercard-subject-tag | issue:3821794498 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/JavaScriptSolidServer/JavaScriptSolidServer/92/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5c889cc53ddbc51b17b1ec7cead7afb0c09f6228398fda9c47e4234866fda1dc/JavaScriptSolidServer/JavaScriptSolidServer/issues/92 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5c889cc53ddbc51b17b1ec7cead7afb0c09f6228398fda9c47e4234866fda1dc/JavaScriptSolidServer/JavaScriptSolidServer/issues/92 |
| og:image:alt | Problem After fixing bcrypt → bcryptjs in #91, the next blocker for Android/Termux compatibility is better-sqlite3, which also requires native C++ compilation. Current Error on Termux gyp: Undefine... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | melvincarvalho |
| hostname | github.com |
| expected-hostname | github.com |
| None | da4f0ee56809799586f8ee546b27f94fe9b5893edfbf87732e82be45be013b52 |
| turbo-cache-control | no-preview |
| go-import | github.com/JavaScriptSolidServer/JavaScriptSolidServer git https://github.com/JavaScriptSolidServer/JavaScriptSolidServer.git |
| octolytics-dimension-user_id | 205442424 |
| octolytics-dimension-user_login | JavaScriptSolidServer |
| octolytics-dimension-repository_id | 958025407 |
| octolytics-dimension-repository_nwo | JavaScriptSolidServer/JavaScriptSolidServer |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 958025407 |
| octolytics-dimension-repository_network_root_nwo | JavaScriptSolidServer/JavaScriptSolidServer |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2d0972e08a3f8dfff1c4bf1f3d026a7d3a209c26 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width