Is there a Javascript library for localStorage to emulate SQLite Is there a Javascript library for localStorage to emulate SQLite sqlite sqlite

Is there a Javascript library for localStorage to emulate SQLite


You could use one of the javascript linq implementations. They get their data from plain javascript objects/arrays, so that should make interfacing with localstorage pretty much cake.

http://jslinq.codeplex.com/
http://linqjs.codeplex.com/
or even http://www.thomasfrank.se/sqlike.html

online demo for them: http://secretgeek.net/JsLinq/ (note the options on the top left)

I'm not so sure about the insert/update aspects, but you can sure do some nice data querying with them.


Try sql.js. This is a direct port of SQLite from native C to pure javascript.


Try alasql.js. This is a SQL database written on pure JavaScript. Even it does not have functionality to work with locasStorage, but you can easily save and restore all data you need before and after the session or changes.

Here is an example how to use Alasql with localStorage:

// Create database and table structurevar db = new alasql.Database();db.exec('CREATE TABLE students (studentid INT, school STRING)');// Load table data from localStorage if it exists or create new tableif(localStorage['students']) {    db.tables.students.data = JSON.parse(localStorage['students']);} else {    db.tables.students.data = [       {studentid: 55, school: 'abc'},       {studentid: 56, school: 'klm'},       {studentid: 57, school: 'nyz'}    ];    localStorage['students'] = JSON.stringify(db.tables.students.data);};// Add new student and save databasedb.tables.students.data.push({student: 100, school:'qwe'}); localStorage['students'] = JSON.stringify(db.tables.students.data);// SQL-queryconsole.log(db.exec("SELECT * FROM students WHERE school > 'ght'"));

This example in Fiddle.