Get started with idb-keyval CDN
Apache-2.0 licensed
IDB-Keyval is a lightweight, asynchronous key-value storage library for IndexedDB.
Tags:- idb
- indexeddb
- store
- keyval
- localstorage
- storage
- promise
Stable version
Copied!
How to start using idb-keyval CDN
// Include the idb-keyval library using the CDN link
const IDBKeyval = async () => {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = 'https://cdn.cdnhub.io/idb-keyval/6.2.1/compat.min.js';
script.onload = () => {
resolve(IDBKeyval);
};
script.onerror = () => {
reject(new Error('Failed to load idb-keyval library'));
};
document.head.appendChild(script);
});
};
// Initialize idb-keyval
IDBKeyval().then((IDBKeyval) => {
// Create a new key-value store named 'myStore'
const myStore = new IDBKeyval('myStore', 'myVersion');
// Set a key-value pair
myStore.set('key', 'value').then(() => {
console.log('Set value successfully');
});
// Get the value of a key
myStore.get('key').then((value) => {
console.log('Value:', value);
});
// Delete a key-value pair
myStore.delete('key').then(() => {
console.log('Deleted key-value pair successfully');
});
});
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!