- From: Kyaw Tun <kyawtun@yathit.com>
- Date: Tue, 12 Feb 2013 13:02:32 +0800
- To: www-tag@w3.org
- Message-ID: <CAFPCW964tcvGp_FrOk=oMTFa-Q72+xb+nvgpo_SxHSc4trkudQ@mail.gmail.com>
The criticisms on IndexedDB API by pointing out IndexedDB suck links is
unfair. If they have enough time to play around it, they will love it.
There are a lot of beauty in IndexedDB API like composite index,
element-wise indexing, auto commit transaction, powerful serialisation and
full reflection. Arms with these it is very possible to write butter smooth
database library.
I would like to point out my own open source library as an example:
https://bitbucket.org/ytkyaw/ydn-db
.
The library features:
- Support *all* features of asynchronous IndexedDB API.
- Well tested closure library module.
- Fixed schema, auto versioning, on-the-fly schema generation while
maintaining multiple connections (on tabs, or worker).
- Low-level cursor iteration, high level query and key joining
algorithms.
- Each method call is an atomic transaction, while supporting
transaction and advance transaction
*workflow*<http://dev.yathit.com/ydn-db/starting/transaction.html>
.
CRUD operations :
var db = new ydn.db.Storage('test-store');
db.put('store1', {test: 'Hello World!'}, 123);
var req = db.get('store1', 123).done(function(record) {
1. console.log(record);
2. });
Basic query
1. var lower = + new Date(1942, 1, 1); // 1942 February 1
2. var upper = + new Date(1942, 2, 1); // 1942 March 1
3. var iter = ydn.db.IndexValueCursors.where('author', 'born', '>=',lower
, '<', upper);
4. db.values(iter).done(function(records) {
5. console.log(records);
6. records.map(function(x) {
7. console.log(x.first + ' ' + x.last + ' ' + new Date(x.born));
8. });
9. });
Advanced query for: SELECT * FROM article WHERE license = 'SA' AND
publisher = 'Nature' ORDER BY 'title'
1. var license_sa_iter = ydn.db.Cursors.where('article', 'license, title'
, '^', ['SA']);
2. var publisher_nature_iter = ydn.db.Cursors.where('article', 'publisher,
title', '^', ['Nature']);
3. var match_keys = [];
4. var solver = new ydn.db.algo.ZigzagMerge(match_keys);
5. var req = db.scan([license_sa_iter, publisher_nature_iter], solver);
6. req.then(function() {
7. db.list('article', match_keys).done(function(results) {
8. console.log(results);
9. });
10. }, function(e) {
11. throw e;
12. });
Received on Tuesday, 12 February 2013 05:03:00 UTC