You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lovasoa edited this page Jan 1, 2015
·
5 revisions
How to use sql.js API from nodejs
This example code shows how to open an sqlite3 file on the filesystem, and load it in sql.js
//Node filesystem module - You know that.varfs=require('fs');//Ditto, path modulevarpath=require('path');//Actual path I'm using to get to sql.js in my project. varSQL=require('sql.js');varfilebuffer=fs.readFileSync(path.resolve('test.sqlite'));// Load the dbvardb=newSQL.Database(filebuffer);//[{"columns":["id","content"],"values":[["0","hello"],["1","world"]]}]console.dir(db.exec("SELECT * FROM test WHERE ID <= 10"));
Note
If your application doesn't need to be usable from a browser or portable, then you might be interested in using node-sqlite3 instead of sql.js. This module includes a native compiled version of sqlite, which is faster than the one compiled to javascript which is included in sql.js.