12

I understand that HTML5 "localStorage" is a key:value store but I am wondering if there is a Javascript library available that offers a more SQL-ish API?

1

6 Answers 6

8

Check out Will HTML5 be SQL-free? and DOM Storage: a Cure for the Common Cookie for some links and opinions.

Sign up to request clarification or add additional context in comments.

1 Comment

Good reading in those links, thanks! I am also just going to add an article linked to in one of those that gave a good perspective on the usage of SQL for the browser storage > blog.vlad1.com/2009/04/06/html5-web-storage-and-sql
5

W3C Database specification says:

User agents must implement the SQL dialect supported by Sqlite 3.6.19.

As of now, at least Google Chrome supports SQL dialect. I have checked myself.

2 Comments

I am using 5.0.342.1 dev version of Chrome.
Around November 2010, the document now reads "This document was on the W3C Recommendation track but specification work has stopped." The IndexedDB document now supersedes it - w3.org/TR/IndexedDB
3

You should use HTML5 database storage (it supports SQL through transactions). a tutorial here: http://www.html5rocks.com/tutorials/webdatabase/todo/

1 Comment

Time and tide keep washing over HTML5. It seems like WebDatabase is out and indexDB is in. Here's the updated article by the same author: html5rocks.com/en/tutorials/indexeddb/todo
1

HTML5 local database storage comes with a SQL interface by default, if I'm not mistaken

Here is a Webkit post with some examples: http://webkit.org/blog/126/webkit-does-html5-client-side-database-storage/

Currently, Chrome forces you to use Gears, which is slightly different, but still SQL-based. Future versions of Chrome will follow the HTML5 spec, however.

1 Comment

See 4.11. Client-side database storage - whatwg.org/specs/web-apps/2007-10-26/#sql
1

Try this: http://kailashnadh.name/code/localstoragedb/

Comments

1

You can try Alasql. It supports standard SQL language and keeps data in memory or localStorage. There are sevelar ways, how to use Alasql with localStorage. Below you can see how to create localStorage database with name "Atlas", attach it to Alasql as "MyAtlas", then you can work with tables like any other database. By default, Alasql uses AUTOCOMMIT ON mode, so it saves data to localStorage after each SQL statement.

This is a sample:

alasql('CREATE localStorage DATABASE IF NOT EXISTS Atlas');
alasql('ATTACH localStorage DATABASE Atlas AS MyAtlas');
alasql('CREATE TABLE IF NOT EXISTS MyAtlas.City (city string, population number)');
alasql('SELECT * INTO MyAtlas.City FROM ?',[[{city:'Vienna', population:1731000}, 
    {city:'Budapest', population:1728000}]]);
var res = alasql('SELECT * FROM MyAtlas.City');

Play with this sample in jsFiddle. Run this sample two or three times (or reload page), and you will see, how the number of lines will grow in the table.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.