-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use from node
Ophir LOJKINE edited this page Jun 12, 2014
·
5 revisions
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.
var fs = require('fs');
//Ditto, path module
var path = require('path');
//Actual path I'm using to get to sql.js in my project.
var SQL = require('../js/sql-api.js');
var filebuffer = fs.readFileSync(path.resolve('test.sqlite'));
// Load the db
var db = new SQL.Database(filebuffer);
//[{"columns":["id","content"],"values":[["0","hello"],["1","world"]]}]
console.log(JSON.stringify(db.exec("SELECT * FROM test WHERE ID <= 10")));