https://github.com/localforage/localforage-getitems
Adds getItems method to localForage.
https://github.com/localforage/localforage-getitems
Last synced: 7 months ago
JSON representation
Adds getItems method to localForage.
- Host: GitHub
- URL: https://github.com/localforage/localforage-getitems
- Owner: localForage
- License: other
- Created: 2015-05-14T04:45:51.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-02-14T11:42:27.000Z (over 3 years ago)
- Last Synced: 2024-12-11T00:39:03.720Z (over 1 year ago)
- Language: JavaScript
- Size: 59.6 KB
- Stars: 25
- Watchers: 5
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
localForage-getItems
====================
[](https://www.npmjs.com/package/localforage-getitems)
Adds getItems method to [localForage](https://github.com/mozilla/localForage).
## Requirements
* [localForage](https://github.com/mozilla/localForage) v1.4.0+
* for earlier versions of localforage, please use the v1.1.x releases
## Installation
`npm i localforage-getitems`
## jsperf links
* [default driver order (indexedDB prefered)](https://jsperf.com/localforage-getitems-2017/1)
* [websql (not for firefox)](https://jsperf.com/localforage-getitems-websql-2017b/1)
## API
Just like `getItem()` but you can pass an array with the keys that need to be retrieved.
```js
var keys = ['asdf','asap','async'];
localforage.getItems(keys).then(function(results) {
console.log(results);
// prints:
// {
// asdf: 'asdf value!',
// asap: 'asap value!',
// async: 'async value!'
// }
console.log(results.asdf);
console.log(results['asdf']);
console.log(results[keys[0]]);
// all the above print 'asdf value!'
});
```
Invoking `getItems()` without arguments (or with `null` as the first argument) will retrieve all the items of the current driver instance.
```js
localforage.getItems().then(function(results) { });
// or by using callbacks
localforage.getItems(null, function(results) { });
```