Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

idb

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idb - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

9

package.json
{
"name": "idb",
"version": "1.1.0",
"version": "1.1.1",
"description": "IndexedDB but with promises",
"main": "lib/idb.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "gulp serve"
},
"repository": {
"type": "git",
"url": "git://github.com/jakearchibald/indexeddb-promised.git"
},
"author": "Jake Archibald",

@@ -10,0 +15,0 @@ "license": "ISC",

@@ -5,6 +5,107 @@ # IndexedDB Promised

## Limitations
# Examples
### Transaction lifetime
## Keyval Store
This is very similar to `localStorage`, but async.
```js
const dbPromsie = idb.open('my-db', 1, upgradeDB => {
upgradeDB.createObjectStore('key-val');
});
const keyValStore = {
get(key) {
return dbPromise.then(db => {
return db.transaction('key-val')
.objectStore('key-val').get(key);
});
},
set(key, val) {
return dbPromise.then(db => {
const tx = db.transaction('key-val', 'readwrite');
tx.objectStore('key-val').put(val, key);
return tx.complete;
});
},
delete(key) {
return dbPromise.then(db => {
const tx = db.transaction('key-val', 'readwrite');
tx.objectStore('key-val').delete(key);
return tx.complete;
});
}
};
```
### Usage
```js
keyValStore.set('foo', {hello: 'world'});
// logs: {hello: 'world'}
keyValStore.get('foo').then(val => console.log(val));
```
## Set of objects
Imagine we had a set of objects like…
```json
{
"id": 123456,
"data": {"foo": "bar"}
}
```
### Upgrading existing DB
```js
const dbPromise = idb.open('my-db', 2, upgradeDB => {
// Note: we don't use 'break' in this switch statement,
// the fall-through behaviour is what we want.
switch (upgradeDB.oldVersion) {
case 0:
upgradeDB.createObjectStore('key-val');
case 1:
upgradeDB.createObjectStore('objs', {keyPath: 'id'});
}
});
```
### Adding
```js
dbPromise.then(db => {
const tx = db.transaction('objs', 'readwrite');
tx.objectStore('objs').put({
id: 123456,
data: {foo: "bar"}
});
return tx.complete;
});
```
### Getting all
```js
dbPromise.then(db => {
return db.transaction('objs')
.objectStore('objs').getAll();
}).then(allObjs => console.log(allObjs));
```
### Getting by ID
```js
dbPromise.then(db => {
return db.transaction('objs')
.objectStore('objs').get(123456);
}).then(obj => console.log(obj));
```
# Limitations
## Transaction lifetime
At time of writing, all browsers aside from Chrome don't treat promise callbacks as microtasks, or call microtasks incorrectly. This means transactions end by the time promise callbacks are called. In practice, this means you cannot perform transactions that involve waiting for a value, then using it within the same transaction.

@@ -22,6 +123,8 @@

### Safari
## Safari
This is a simple wrapper library, so you're exposed to bugs in the underlying implementation. Unfortunately [Safari has a lot of these](http://www.raymondcamden.com/2014/09/25/IndexedDB-on-iOS-8-Broken-Bad).
# API
## `idb`

@@ -57,3 +160,3 @@

```js
idb.delete('my-database').then(_ => console.log('done!'));
idb.delete('my-database').then(() => console.log('done!'));
```

@@ -65,5 +168,6 @@

* `name` - as `idbDatabase.name`
* `version` - as `idbDatabase.version`
* `objectStoreNames` - as `idbDatabase.objectStoreNames`
* Same as equivalent properties on an instance of `IDBDatabase`:
* `name`
* `version`
* `objectStoreNames`

@@ -94,4 +198,5 @@ Methods:

* `complete` - a promise. Resolves when transaction completes, rejects if transaction aborts or errors
* `objectStoreNames` - as `idbTransaction.objectStoreNames`
* `mode` - as `idbTransaction.mode`
* Same as equivalent properties on an instance of `IDBTransaction`:
* `objectStoreNames`
* `mode`

@@ -110,6 +215,6 @@ Methods:

}).then(db => {
let tx = db.transaction('key-val');
let tx = db.transaction('key-val', 'readwrite');
tx.objectStore('key-val').put('hello', 'world');
return tx.complete;
}).then(_ => console.log("Done!"));
}).then(() => console.log("Done!"));
```

@@ -121,22 +226,26 @@

* `name` - as `idbObjectStore.name`
* `keyPath` - as `idbObjectStore.keyPath`
* `indexNames` - as `idbObjectStore.indexNames`
* `autoIncrement` - as `idbObjectStore.autoIncrement`
* Same as equivalent properties on an instance of `IDBObjectStore`:
* `name`
* `keyPath`
* `indexNames`
* `autoIncrement`
Methods:
* `put` - as `idbObjectStore.put` but returns a promise that resolves/rejects based on operation success/failure
* `add` - as `idbObjectStore.add` but returns a promise that resolves/rejects based on operation success/failure
* `delete` - as `idbObjectStore.delete` but returns a promise that resolves/rejects based on operation success/failure
* `clear` - as `idbObjectStore.clear` but returns a promise that resolves/rejects based on operation success/failure
* `get` - as `idbObjectStore.get` but returns a promise that resolves/rejects based on operation success/failure
* `getAll` - as `idbObjectStore.getAll` but returns a promise that resolves/rejects based on operation success/failure
* `getAllKeys` - as `idbObjectStore.getAllKeys` but returns a promise that resolves/rejects based on operation success/failure
* `count` - as `idbObjectStore.count` but returns a promise that resolves/rejects based on operation success/failure
* `openCursor` - as `idbObjectStore.openCursor` but returns a promise that resolves with a `Cursor`
* `openKeyCursor` - as `idbObjectStore.openKeyCursor` but returns a promise that resolves with a `Cursor`
* Same as equivalent methods on an instance of `IDBObjectStore`, but returns a promise that resolves/rejects based on operation success/failure:
* `put`
* `add`
* `delete`
* `clear`
* `get`
* `getAll`
* `getAllKeys`
* `count`
* Same as equivalent methods on an instance of `IDBObjectStore`, but returns a promise that resolves with a `Cursor`:
* `openCursor`
* `openKeyCursor`
* `deleteIndex` - as `idbObjectStore.deleteIndex`
* `createIndex` - as `idbObjectStore.createIndex` but returns an `Index`
* `index` - as `idbObjectStore.index` but returns an `Index`
* Same as equivalent methods on an instance of `IDBObjectStore`, but returns an `Index`:
* `createIndex`
* `index`
* `iterateCursor` - see below

@@ -158,3 +267,3 @@ * `iterateKeyCursor` - see below

});
tx.complete.then(_ => console.log('done'));
tx.complete.then(() => console.log('done'));
```

@@ -171,3 +280,3 @@

});
tx.complete.then(_ => console.log('done'));
tx.complete.then(() => console.log('done'));
```

@@ -181,16 +290,19 @@

* `name` - as `idbIndex.name`
* `keyPath` - as `idbIndex.keyPath`
* `multiEntry` - as `idbIndex.multiEntry`
* `unique` - as `idbIndex.unique`
* Same as equivalent properties on an instance of `IDBIndex`:
* `name`
* `keyPath`
* `multiEntry`
* `unique`
Methods:
* `get` - as `idbIndex.get`, but returns a promise that resolves/rejects based on operation success/failure
* `getKey` - as `idbIndex.getKey`, but returns a promise that resolves/rejects based on operation success/failure
* `getAll` - as `idbIndex.getAll`, but returns a promise that resolves/rejects based on operation success/failure
* `getAllKeys` - as `idbIndex.getAllKeys`, but returns a promise that resolves/rejects based on operation success/failure
* `count` - as `idbIndex.count`, but returns a promise that resolves/rejects based on operation success/failure
* `openCursor` - as `idbIndex.openCursor` but returns a promise that resolves with a `Cursor`
* `openKeyCursor` - as `idbIndex.openKeyCursor` but returns a promise that resolves with a `Cursor`
* Same as equivalent methods on an instance of `IDBIndex`, but returns a promise that resolves/rejects based on operation success/failure:
* `get`
* `getKey`
* `getAll`
* `getAllKeys`
* `count`
* Same as equivalent methods on an instance of `IDBIndex`, but returns a promise that resolves with a `Cursor`:
* `openCursor`
* `openKeyCursor`
* `iterateCursor` - as `objectStore.iterateCursor` but over the index

@@ -203,13 +315,16 @@ * `iterateKeyCursor` - as `objectStore.iterateKeyCursor` but over the index

* `direction` - as `idbCursor.direction`
* `key` - as `idbCursor.key`
* `primaryKey` - as `idbCursor.primaryKey`
* `value` - as `idbCursor.value`
* Same as equivalent properties on an instance of `IDBCursor`:
* `direction`
* `key`
* `primaryKey`
* `value`
Methods:
* `update` - as `idbCursor.update` but returns a promise that resolves/rejects based on operation success/failure
* `delete` - as `idbCursor.delete` but returns a promise that resolves/rejects based on operation success/failure
* `advance` - as `idbCursor.advance` but returns a promise that resolves to a `Cursor`
* `continue` - as `idbCursor.continue` but returns a promise that resolves to a `Cursor`
* `continuePrimaryKey` - as `idbCursor.continuePrimaryKey` but returns a promise that resolves to a `Cursor`
* Same as equivalent methods on an instance of `IDBCursor`, but returns a promise that resolves/rejects based on operation success/failure:
* `update`
* `delete`
* Same as equivalent methods on an instance of `IDBCursor`, but returns a promise that resolves with a `Cursor`:
* `advance`
* `continue`
* `continuePrimaryKey`
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc