Skip to content

Commit 151b7e7

Browse files
feat: add indexedDB
1 parent 8f0e73d commit 151b7e7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)