{ case "read": // Methods for reading from database break; case "create": // Create a record here break; case "update": // Update Records break; case "delete": // Delete record } RemoteDatabase.replicate(); });
Model db.get(model.id, function (err, res) { if (err) { error(err); return; } options.success(res); } ); } else { // For all rows in the DB db.getAll ( function (err, resp) { if (err) { error(err); return; } options.success(resp); } ); }
a single Model var openReq = window.indexedDB.open("DatabaseName"); openReq.onsuccess = function () { var db = openReq.result; var transaction = db.transaction(["Model1”], "readonly"); var objectStore = transaction.objectStore("Model1"); var readReq = objectStore.get(model.id); readReq.onsuccess = function () { option.success(readReq.result); }; }; openReq.onerror = function (e) { options.error(e); }; }
Store key : value key : value key : value Index Cursor on Index Database Cursor on Object Store Object Store key : value key : value key : value Index Cursor on Index Transaction
= function () { var db = openReq.result; var transaction = db.transaction(["Model1”], "readonly"); var objectStore = transaction.objectStore("Model1"); var readReq = objectStore.get(model.id); readReq.onsuccess = function () { option.success(readReq.result); }; }; openReq.onerror = function (e) { options.error(e); }; }
single Model db.get(model.id, {}, function (err, res) { if (err) { error(err); return; } options.success(res); } ); } else { // For all rows in the DB db.allDocs ({}, function (err, resp) { if (err) { error(err); return; } options.success(resp); } ); } Pouch.replicate("idb://data","http://me.couchdb.com/data");
5 ') .sortBy('name') .sortBy('price') .each(function(result){ // process each result }); Querying IndexedDB Fall back on Web Workers to do the job • Sorting on multiple columns • Where clauses across object stores • Sorting and clauses across object stores Project : //linq2indexeddb.codeplex.com/
• Not comparing browsers • Comparing Common cases when writing an application • Are string keys slower than integer keys • Should I combine read and write transactions ? • Started with JSPerf, Problems with Async Setup • Using Benchmarkjs Thanks to @slace for helping with code reviews