Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yields/dex
Lightweight IndexedDB wrapper
https://github.com/yields/dex
Last synced: 2 months ago
JSON representation
Lightweight IndexedDB wrapper
- Host: GitHub
- URL: https://github.com/yields/dex
- Owner: yields
- Created: 2013-11-03T12:25:22.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-07T01:24:28.000Z (almost 11 years ago)
- Last Synced: 2024-10-19T21:46:52.947Z (2 months ago)
- Language: JavaScript
- Size: 321 KB
- Stars: 18
- Watchers: 4
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/yields/dex.png?branch=master)](https://travis-ci.org/yields/dex)
# dex
Lightweight IndexedDB wrapper
```js
var dex = require('dex')();// set
dex
.set('foo', 'baz')
.set('baz', 'foo')
.end(function(err, all){});// get
dex
.get('foo')
.get('baz')
.end(function(err, all){
assert('baz' == all.shift().item.value);
assert('foo' == all.shift().item.value);
});// del
dex
.del('foo')
.del('baz')
.end(function(err, all){});// exists
dex
.exists('foo')
.exists('baz')
.end(function(err, bools){});
```## Installation
Install with [component(1)](http://component.io):
$ component install yields/dex
## API
### events
- `("connect", event)`
- `("abort", event)`, emitted when a transaction is aborted
- `("complete", event)`, emitted when a transaction is completed
- `("progress", event)`, emitted on transaction progress
- `("set", key, value)`, emitted when `key`, `value` are saved.
- `("del", key)`, emitted when a `key` is deleted.### dex#command
`command(name, fn)` is a static method that allows you
to define new commands easily.all `dex()` commands are defined using this method, see examples in [`lib/commands.js`](lib/commands.js)
### dex()
Create a new `Database` instance.
#### #connect
The method is called automatically, you don't need to call
it unless you `quit()`.#### #quit
Disconnect
#### #set
Set `key`, `value` with optional `fn(err, o)`
#### #get
Get `key`'s `value`.
#### #exists
Determine if a `key` exists.
#### #del
Delete `key`
#### #keys
Get all `keys` that match a `regexp`
```js
dex().keys(/a/, function(err, keys){});
```#### #abort
Abort all running transactions.
```js
var d = dex();
var i = 0;
d.set('multi', 1);
d.set(1, 1);
d.set(2, 2);
d.set(3, 3);
d.get(3);
d.set(4, 4);d.on('progress', function(e){
if (1 == i++) d.abort();
});d.end(function(err){
assert(err);
d.get('multi', function(err, o){
if (err) return done(err);
assert(!o.item);
});
});
```#### #end
Invoke the transaction.
```js
dex()
.set('foo', 'baz')
.set('baz', 'foo')
.set('more', { stuff: [] })
.end(function(err, all){});
```under the hood dex will create a single transaction of `readwrite`.
```js
dex()
.get('foo')
.get('baz')
.get('more')
.end(function(err, all){});
```in the above snippet `dex()` will create a single `readonly` transaction.
```js
dex()
.set('foo', 'foo')
.get('foo')
.set('baz', 'foo')
.set('some', 'stuff')
.del('foo')
.end(function(err, all){});
```two transactions will be created `readwrite` and `readonly`.
## Tests
```bash
$ make test
```## License
MIT