Skip to content
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.
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('sql.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.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.

Clone this wiki locally
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy