✨ PSA - this is an alpha version. Not tested in older browsers yet. File issues at will... ✨
Implementation of @jakearchibald's excellent idb-keyval API. See https://github.com/jakearchibald/idb-keyval for the original.
The intent of this version is to add some functionality not included in Jake's version, including:
- Allows multiple stores within the same browser session
- Reuse connection to same underlying store (helps in older versions of IE)
- Allow explicit closing of database connections
- TBD Allow multiple stores per database (#1)
It also includes tests which can easily be executed in various different browsers
Care has been taken to replicate the API of the original library. However, note that certain "private" properties are not currently exposed (e.g. the _dbp property of a Store object). Feel free to suggest additions if you need these.
Because this library reuses the same underlying connection when database and store match, they will not be automatically closed when references are released. You should use the closeAll
method to close connections if you are worried about releasing this memory. Although this could be achieved automatically using a WeakMap, we have chosen not to do so at this time (as it would create a breaking change between older and newer browsers).
The original library is written in typescript and compiled down to ES6 and ES5. This version is written in ES5, with a manually written typescript definition file. It also avoids class constructs and the original's "private" API, producing a slightly smaller output.
The tiny size of idb-keyval, as well as support for treeshaking, are important characteristics of the original library, so care has been taken to produce assets which are at least no bigger than the originals.
Some notes on the comparison:
- In each case "idb-keyval" has been replaced with "index".
- These files contain the extract function "closeAll" which closes connections to open databases
- File sizes are as reported when viewed in GitHub on 2019-08-27
file | size | idb-keyval size |
---|---|---|
index-cjs.js | 1.79 KB | 2.38 KB |
index-iife.js | 1.88 KB | 2.38 KB |
index-iife.min.js | 1000 Bytes | 1.06 KB |
index.mjs | 1.77 KB | 2.38 KB |
npm run build
or npm run build_watch
N.B. You only need to "build" the typescript tests - all others are written by hand.
npm run build_ts_tests
or npm run build_ts_tests_watch
Tests are deliberately manually executed by loading a browser page to ease with testing in legacy browsers.
npm run test
then navigate to http://localhost:8080/tests
As this is an implementation of a pre-defined API, please use the documentation found at https://github.com/jakearchibald/idb-keyval.
This function returns a promise to close all the database connections that have been opened in this session