I have a dead-simple question. How to use any SQLite library with nodejs under Windows? I have looked into the sqlite3 lib and it requires compilation which is linux-specific. In general, this is not the first time I’m facing a question of this type. Same problem I had with TameJS. If anyone knows any solution for this, I would be grateful. Google is silent.
PS: Cygwin is not an option. The target application should be an easy in usage portable database, driven by nodejs, and having a web-browser interface.
Read at the bottom for Update 2 (2013-12-06) – there is now a pure JS module which looks promising for windows work…
I’ve been having a similar problem, and shy some pretty magic with re-linking the windows SQLite (or compiling the existing nodejs packages) the best I could come up with is to use a child process and shell out to the console sqlite client and then capture the results… Not the prettiest, and I have no idea if this can scale, but in a limited intranet scenario it might be Good Enough™.
Update:
Here’s some code which I cobbled together – give you an idea in case you’re not that familiar with child_process module. This works on
nodejs 0.6.0.First I build up the command required to pull something out of sqlite:
Note, if you include the optional flags
-noheaderand-listthen you might get slightly better output for parsing. You can also control the field delimiter by using-separator 'x'wherexis your delimiter.Then I actually spawn the child process:
In combination with some string parsing and playing with the sqlite console client’s options you may be able to get this to do enough. I do say again, however, this is not production tested – I’m just mocking up some intranet stuff, and even so I’m sure it’s not the best approach!
Update 2 (2013-12-06):
For folks reading this question now, you might be interested to check out sql.js on github; it is a pure JS implementation of sqlite which looks promising for interacting on windows (or whatever platform). Please note, to install via npm the package name is
node-sqlite-purejs.