Guest User

Untitled

a guest
Jun 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. var global = this,
  2. dbOpen, db, store, index, result;
  3.  
  4. document.addEventListener('DOMContentLoaded', function () {
  5.  
  6.  
  7. dbOpen = webkitIndexedDB.open( 'test_' + (+new Date()), 'This is my temporary indexedDB');
  8.  
  9. console.log( "dbOpen", dbOpen );
  10.  
  11. for ( var prop in dbOpen ) {
  12. console.log(prop, typeof dbOpen[prop]);
  13. }
  14.  
  15.  
  16. dbOpen.addEventListener('success', function (event) {
  17.  
  18.  
  19. // IDBSuccessEvent
  20. console.log("event", event);
  21.  
  22. // IDBDatabase
  23. console.log("event.result", event.result);
  24.  
  25. // Alias IDBDatabase
  26. db = event.result;
  27.  
  28. for ( var prop in db ) {
  29.  
  30. //console.log(prop, db[prop]);
  31.  
  32. // name tempDB
  33. // version a version id
  34. // objectStores DOMStringList
  35. // createObjectStore function createObjectStore() { [native code] }
  36. // removeObjectStore function removeObjectStore() { [native code] }
  37. // setVersion function setVersion() { [native code] }
  38. // transaction function transaction() { [native code] }
  39. // close function close() { [native code] }
  40. }
  41.  
  42.  
  43. var vdb = db.setVersion('a version id');
  44.  
  45. vdb.addEventListener('success', function (event) {
  46.  
  47. console.log("event", event);
  48.  
  49. console.log("event.result", event.result);
  50.  
  51. console.log("db.version", db.version);
  52.  
  53. // objectStores [methods: contains, item]
  54. console.log("db.objectStores", db.objectStores);
  55.  
  56. console.log("typeof db.objectStores", typeof db.objectStores);
  57. // object
  58.  
  59. console.log("db.objectStores.length", db.objectStores.length);
  60. // 0
  61.  
  62.  
  63.  
  64. for ( var prop in db.objectStores ) {
  65.  
  66. console.log(prop, db.objectStores[prop], typeof db.objectStores[prop]);
  67.  
  68.  
  69. // length 0
  70. // item function item() { [native code] }
  71. // contains function contains() { [native code] }
  72.  
  73. }
  74.  
  75. store = db.createObjectStore('cooler', null);
  76. //store = db.objectStores.item(0);
  77.  
  78. console.log(store);
  79.  
  80. console.log(db.objectStores.item(0));
  81.  
  82. index = store.createIndex('anIndex', 'foo', true);
  83.  
  84. console.log("store", store); // null ?
  85.  
  86. console.log("db.objectStores", db.objectStores);
  87.  
  88. console.log("db.objectStores.length", db.objectStores.length);
  89.  
  90. console.log("db.objectStores.contains('cooler')", db.objectStores.contains('cooler'));
  91.  
  92. console.log("index", index);
  93.  
  94. console.log("store.indexNames.contains('anIndex')", store.indexNames.contains('anIndex'));
  95.  
  96.  
  97. /*
  98. transaction = db.transaction();
  99.  
  100.  
  101. store = transaction.objectStore('cooler');
  102.  
  103.  
  104. result = store.add({ 'foo': 'bar'}, 'key');
  105.  
  106.  
  107. console.log("result", result);
  108. */
  109.  
  110.  
  111. }, false);
  112.  
  113. }, false);
  114.  
  115. }, false);
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. // Constants
  123. console.log(webkitIDBKeyRange.SINGLE, 0);
  124. console.log(webkitIDBKeyRange.LEFT_OPEN, 1);
  125. console.log(webkitIDBKeyRange.RIGHT_OPEN, 2);
  126. console.log(webkitIDBKeyRange.LEFT_BOUND, 4);
  127. console.log(webkitIDBKeyRange.RIGHT_BOUND, 8);
  128.  
  129. console.log(webkitIDBDatabaseException.UNKNOWN_ERR, 0);
  130. console.log(webkitIDBDatabaseException.NON_TRANSIENT_ERR, 1);
  131. console.log(webkitIDBDatabaseException.NOT_FOUND_ERR, 2);
  132. console.log(webkitIDBDatabaseException.CONSTRAINT_ERR, 3);
  133. console.log(webkitIDBDatabaseException.DATA_ERR, 4);
  134. console.log(webkitIDBDatabaseException.NOT_ALLOWED_ERR, 5);
  135. console.log(webkitIDBDatabaseException.SERIAL_ERR, 11);
  136. console.log(webkitIDBDatabaseException.RECOVERABLE_ERR, 21);
  137. console.log(webkitIDBDatabaseException.TRANSIENT_ERR, 31);
  138. console.log(webkitIDBDatabaseException.TIMEOUT_ERR, 32);
  139. console.log(webkitIDBDatabaseException.DEADLOCK_ERR, 33);
  140.  
  141. console.log(webkitIDBRequest.LOADING, 1);
  142. console.log(webkitIDBRequest.DONE, 2);
  143.  
  144. console.log(webkitIDBCursor.NEXT, 0);
  145. console.log(webkitIDBCursor.NEXT_NO_DUPLICATE, 1);
  146. console.log(webkitIDBCursor.PREV, 2);
  147. console.log(webkitIDBCursor.PREV_NO_DUPLICATE, 3);
  148.  
  149. console.log(webkitIDBTransaction.READ_WRITE, 0);
  150. console.log(webkitIDBTransaction.READ_ONLY, 1);
  151. console.log(webkitIDBTransaction.SNAPSHOT_READ, 2);
  152. console.log(webkitIDBTransaction.VERSION_CHANGE, 3);
Add Comment
Please, Sign In to add comment