Advertisement
Guest User

Indexed DB / Multientry Indexes

a guest
Jun 5th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.83 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <title>IndexedDB: Test the limits on multientry indexes</title>
  3. <script>
  4.  
  5. var NUM_ENTRIES = 1e4;
  6.  
  7. var openRequest = indexedDB.open('db' + Date.now());
  8. openRequest.onupgradeneeded = function() {
  9.   var db = openRequest.result;
  10.   var store = db.createObjectStore('store', {keyPath: 'id'});
  11.   store.createIndex('tags', 'tags', {unique: false, multiEntry: true});
  12. };
  13. openRequest.onsuccess = function() {
  14.   var db = openRequest.result;
  15.   var tx = db.transaction('store', 'readwrite');
  16.   var store = tx.objectStore('store');
  17.   var index = store.index('tags');
  18.  
  19.   var rec = {id: 1234, tags: []};
  20.   for (var i = 0; i < NUM_ENTRIES; ++i) {
  21.    rec.tags[i] = i;
  22.  }
  23.  store.put(rec);
  24.  
  25.  var countRequest = index.count();
  26.  countRequest.onsuccess = function() {
  27.    alert(countRequest.result);
  28.  };
  29. };
  30.  
  31. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement