Skip to content

Commit

Permalink
Readme
Browse files Browse the repository at this point in the history
Take advantage of GFL
Note on testing
  • Loading branch information
bentaber committed Mar 27, 2013
1 parent 86508c9 commit 2d156ca
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ A tiny & fast key value store with append-only disk log. Ideal for apps with < 1

## Installation

npm install dirty
```bash
npm install dirty
```

## Why dirty?

Expand All @@ -21,26 +23,27 @@ but it is a wonderful solution for anything smaller than that.

## Tutorial

require('../test/common');
var db = require('dirty')('user.db');
```javascript
var dirty = require('dirty');
var db = ('user.db');

db.on('load', function() {
db.set('john', {eyes: 'blue'});
console.log('Added john, he has %s eyes.', db.get('john').eyes);
db.on('load', function() {
db.set('john', {eyes: 'blue'});
console.log('Added john, he has %s eyes.', db.get('john').eyes);

db.set('bob', {eyes: 'brown'}, function() {
console.log('User bob is now saved on disk.')
});

db.forEach(function(key, val) {
console.log('Found key: %s, val: %j', key, val);
});
db.set('bob', {eyes: 'brown'}, function() {
console.log('User bob is now saved on disk.')
});

db.on('drain', function() {
console.log('All records are saved on disk now.');
db.forEach(function(key, val) {
console.log('Found key: %s, val: %j', key, val);
});
});

db.on('drain', function() {
console.log('All records are saved on disk now.');
});
```
Output:

Added john, he has blue eyes.
Expand All @@ -58,11 +61,12 @@ can also omit the `path` if you don't want disk persistence (useful for testing)

The constructor can be invoked in multiple ways:

require('dirty')('my.db');
require('dirty').Dirty('my.db');
new (require('dirty'))('my.db');
new (require('dirty').Dirty)('my.db');

```javascript
require('dirty')('my.db');
require('dirty').Dirty('my.db');
new (require('dirty'))('my.db');
new (require('dirty').Dirty)('my.db');
```
### dirty.path

The path of the dirty database.
Expand Down Expand Up @@ -103,6 +107,17 @@ key once, even if it had been overwritten.

Emitted whenever all records have been written to disk.

## Tests

Dirty utilizes the [Mocha](http://visionmedia.github.com/mocha/) test framework.

```bash
git clone https://github.com/felixge/node-dirty
cd node-dirty
npm install --dev
npm test
```

## License

node-dirty is licensed under the MIT license.

0 comments on commit 2d156ca

Please sign in to comment.