Hacker News new | ask | show | jobs
by myoon 3936 days ago
Unfortunately, there are a few major downsides to sql.js:

1. Not API compatible with node-sqlite3, so you can't just drop it in and use it with knex or other wrappers.

2. Doesn't support in-place editing of a db. You have to load the entire DB into memory, modify it, and then save it back, making it unsuitable for any concurrent application.

I love the idea of the project though, and it would be awesome not to have to deal with compiling sqlite or using node-pregyp to build embedded chromium apps.

5 comments

I think the whole point is that it runs in a browser, where you can't install sqlite otherwise. If you're running node, you can almost certainly run a native binary of sqlite.
All good points, but I think the primary use case (in a browser) doesn't experience these downsides nearly as much (JS is single threaded in the browser so concurrent access is not a big deal). It would be nice to use knex with it though..
Build a VFS layer that uses something like https://code.google.com/p/limbo-machine/wiki/JS to talk over a websocket or http message proxy to a file store and you get in-place editing. It will probably be hell for the 'usual' usecase of nonconcurrent in-page use however. Also, LOL locking, which is the real utility of SQLite's VFS layer.
>Doesn't support in-place editing of a db.

I wonder why that is. Is it just a fuction they simply didn't create a binding for? Or is it some performance concern?

Not OP, but I imagine it's a couple things: 1) No clear mapping between file APIs that SQLite uses and browser file APIs. 2) SQLite uses blocking file I/O internally which is generally a big no-no for JavaScript due to it being single threaded.
SQLite is proably saving files in emscripten's virtual filesystem (emscripten's implementation of fopen() etc. by default makes them work on memory), and the sql.js API just reads and writes the file there.
there is an VFS layer in sqlite, I haven't used it, but it seems like you can override block I/O operations.