Save your dataIntroduction to IndexedDB    Paweł Maciejewski      @fragphace
Agenda    1. Why Indexed Database?    2. Structure    3. Transactions    4. Database creation    5. Basic IndexedDB patter...
Why Indexed Database?   Answer 1   There are only Web Storage and Indexed Database (Web SQL is   deprecated). In many case...
Structure       IDB enables (more) advanced key-value data management,       Many databases associated with one origin, ma...
Transactions       Every request must be performed within a transaction       Transaction scope determines the object stor...
Database creation 1   // Lets specify db version 2   var connectionReq = window.indexedDB.open(myDB, 3); 3 4   connectionR...
Basic IndexedDB pattern 1   var connectionReq = window.indexedDB.open(myDB, 3); 2 3   connectionReq.onsuccess = function(e...
Theres (much) more       Cursors, bounds, indexes, cross-window events       Not ready for production, new specification im...
Thank you!
Interested in joining us?       More info in the lobby
Upcoming SlideShare
Loading in...5
×

Save your data

325

Published on

Short introduction to IndexedDB

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
325
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Save your data

  1. 1. Save your dataIntroduction to IndexedDB Paweł Maciejewski @fragphace
  2. 2. Agenda 1. Why Indexed Database? 2. Structure 3. Transactions 4. Database creation 5. Basic IndexedDB pattern 6. Theres (much) more
  3. 3. Why Indexed Database? Answer 1 There are only Web Storage and Indexed Database (Web SQL is deprecated). In many cases Local Storage is too simple. Answer 2 It is good for your programming skills to play with asynchronous API of Indexed Database.
  4. 4. Structure IDB enables (more) advanced key-value data management, Many databases associated with one origin, many object stores associated with one database Its NoSQL: you must take care of mapping relations between data, there is no full text search... . Origin Databases Object stores
  5. 5. Transactions Every request must be performed within a transaction Transaction scope determines the object stores with witch transaction can interact There are three modes of transactions: READ_ONLY READ_WRITE VERSION_CHANGE . Request Request Transaction Request
  6. 6. Database creation 1 // Lets specify db version 2 var connectionReq = window.indexedDB.open(myDB, 3); 3 4 connectionReq.onsuccess = function(event) {}; 5 connectionReq.onerror = function(event) {}; 6 7 connectionReq.onupgradeneeded = function(event) { 8 var connection = event.target.result; 9 var storeNames = connection.objectStoreNames;1011 if (storeNames.contains(workers)) {12 // Delete an object store13 connection.deleteObjectStore(workers);14 }1516 if (!storeNames.contains(employees)) {17 // Create an object store18 connection.createObjectStore(employees, { keyPath: email});19 }20 };
  7. 7. Basic IndexedDB pattern 1 var connectionReq = window.indexedDB.open(myDB, 3); 2 3 connectionReq.onsuccess = function(event) { 4 var connection = event.target.result; 5 var transaction = connection.transaction(employees, IDBTransaction. READ_WRITE); 6 var employees = transaction.objectStore(employees); 7 8 var setReq = employees.set({ 9 email: fragphace@gmail.com,10 name: Pawel Maciejewski11 });1213 var getReq = employees.get(fragphace@gmail.com);1415 // ...16 };
  8. 8. Theres (much) more Cursors, bounds, indexes, cross-window events Not ready for production, new specification implemented only in Firefox 12 Prefixes for indexedDB, IDBTransaction and others
  9. 9. Thank you!
  10. 10. Interested in joining us? More info in the lobby
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×