Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- idxdDB.open = function () {
- var version = 1;
- var request = indexedDB.open("db_undo", version);
- // We can only create Object stores in a versionchange transaction.
- request.onupgradeneeded = function (e) {
- var db = e.target.result;
- // A versionchange transaction is started automatically.
- e.target.transaction.onerror = function (e) {
- console.log("Error", e);
- };
- if (db.objectStoreNames.contains("undo_point")) {
- db.deleteObjectStore("undo_point");
- }
- var store = db.createObjectStore("undo_point");
- };
- request.onsuccess = function (e) {
- idxdDB.db = e.target.result;
- // Clear the store
- var trans = idxdDB.db.transaction(["undo_point"], "readwrite");
- var store = trans.objectStore("undo_point");
- var req = store.clear();
- req.onsuccess = function(evt) {
- console.log("Store cleared");
- getQuota();
- listAllStore(store);
- };
- };
- request.onerror = function (e) {
- console.log("Error!", e);
- };
- };
- function getQuota () {
- if (window.webkitStorageInfo && window.webkitStorageInfo.queryUsageAndQuota) {
- window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY,
- function (used, remaining) {
- console.log("Used quota: " + used + ", remaining quota: " + remaining);
- }, function (e) {
- console.log('Error', e);
- });
- }
- }
- function listAllStore (store) {
- store.openCursor().onsuccess = function(event) {
- var cursor = event.target.result;
- // if there is still another cursor to go, keep runing this code
- if(cursor) {
- console.log (cursor);
- // continue on to the next item in the cursor
- cursor.continue();
- // if there are no more cursor items to iterate through, say so, and exit the function
- } else {
- console.log ("Cursor finished");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement