clear = function () {
return withStore('readwrite', function(store) {
store.clear();
});
}...
```js
idbKeyval.delete('hello');
```
### clear:
```js
idbKeyval.clear();
```
That's it!
...delete = function (key) {
return withStore('readwrite', function(store) {
store.delete(key);
});
}...
// logs: ["hello", "foo"]
idbKeyval.keys().then(keys => console.log(keys));
```
### delete:
```js
idbKeyval.delete('hello');
```
### clear:
```js
idbKeyval.clear();
```
...get = function (key) {
var req;
return withStore('readonly', function(store) {
req = store.get(key);
}).then(function() {
return req.result;
});
}...
.catch(err => console.log('It failed!', err));
```
### get:
```js
// logs: "world"
idbKeyval.get('hello').then(val => console.log(val));
```
If there is no 'hello' key, then `val` will be `undefined`.
### keys:
```js
...keys = function () {
var keys = [];
return withStore('readonly', function(store) {
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.
// And openKeyCursor isn't supported by Safari.
(store.openKeyCursor || store.openCursor).call(store).onsuccess = function() {
if (!this.result) return;
keys.push(this.result.key);
this.result.continue();
};
}).then(function() {
return keys;
});
}...
If there is no 'hello' key, then `val` will be `undefined`.
### keys:
```js
// logs: ["hello", "foo"]
idbKeyval.keys().then(keys => console.log(keys));
```
### delete:
```js
idbKeyval.delete('hello');
```
...set = function (key, value) {
return withStore('readwrite', function(store) {
store.put(value, key);
});
}...
This is only a keyval store. If you need to do more complex things like iteration & indexing, check out [IDB on NPM](https://
www.npmjs.com/package/idb) (a little heavier at 1.7k). The first example in its README is how to recreate this library.
## Usage
### set:
```js
idbKeyval.set('hello', 'world');
idbKeyval.set('foo', 'bar');
```
Since this is IDB-backed, you can store anything structured-clonable (numbers, arrays, objects, dates, blobs etc).
All methods return promises:
...