IndexedDB là gì?
IndexedDB là gì?
IndexedDB là cơ sở dữ liệu NoSQL trong trình duyệt, lưu lượng dữ liệu lớn có cấu trúc (object, blob, file) theo origin, bất đồng bộ, hỗ trợ index và transaction.
const req = indexedDB.open('shop', 1);
req.onupgradeneeded = (e) => {
const db = e.target.result;
const store = db.createObjectStore('products', { keyPath: 'id' });
store.createIndex('byCategory', 'category');
};
req.onsuccess = (e) => {
const db = e.target.result;
const tx = db.transaction('products', 'readwrite');
tx.objectStore('products').put({ id: 1, name: 'Áo', category: 'thoitrang' });
tx.oncomplete = () => console.log('xong');
};
Thực tế dùng wrapper dạng Promise: idb, Dexie.js.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.