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?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- How to toggle on Order in ReactJS
You should use HTML5 database storage (it supports SQL through transactions). a tutorial here: http://www.html5rocks.com/tutorials/webdatabase/todo/
Try this: http://kailashnadh.name/code/localstoragedb/
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.
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:
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.
Check out Will HTML5 be SQL-free? and DOM Storage: a Cure for the Common Cookie for some links and opinions.
W3C Database specification says:
As of now, at least Google Chrome supports SQL dialect. I have checked myself.