File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
part9 (Advanced Topics)/client-side-storage Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ INFO: IndexedDB
3+ IndexedDB is a client-side NoSQL database that allows you to store structured data in the browser (objects, blobs, etc).
4+
5+
6+ INFO: Key features:
7+ 1. Asynchronous API
8+ 2. Stores large amounts of data (100s of MBs)
9+ 3. Ideal for offline apps
10+ 4. Uses transctions and object stores
11+ */
12+
13+ const request = indexedDB . open ( "myDatabase" , 1 ) ;
14+
15+ request . onupgradeneeded = function ( event ) {
16+ const db = event . target . result ;
17+ db . createObjectStore ( "users" , { keyPath : "id" } ) ;
18+ } ;
19+
20+ request . onsuccess = function ( event ) {
21+ const db = event . target . result ;
22+ const transaction = db . transaction ( [ "users" ] , "readwrite" ) ;
23+ const store = transaction . objectStore ( "users" ) ;
24+
25+ store . add ( { id : 1 , name : "rafay" , age : 21 } ) ;
26+ }
You can’t perform that action at this time.
0 commit comments