# co-db

> [![Build Status](https://travis-ci.org/filipovskii/co-db.svg?branch=master)](https://travis-ci.org/filipovskii/co-db)

Latest version **0.0.1** (published 2014-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install co-db
pnpm add co-db
yarn add co-db
bun add co-db
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2014-09-18 |
| First published | 2014-09-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| Author | filipovsky |
| Maintainers | filipovsky |

## Links

- npm: https://www.npmjs.com/package/co-db
- npm.io page: https://npm.io/package/co-db

## Dependencies (4)

- [co](https://npm.io/package/co.md) ^3.1.0
- [co-fs](https://npm.io/package/co-fs.md) ^1.2.0
- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [co-filter](https://npm.io/package/co-filter.md) 0.0.1

## Recent versions

- 0.0.1 (latest) — 2014-09-18
- 0.0.0 — 2014-09-05

## README

# co-db

[![Build
Status](https://travis-ci.org/filipovskii/co-db.svg?branch=master)](https://travis-ci.org/filipovskii/co-db)

FS-based database to use with [co](https://github.com/visionmedia/co).


## Installation

```
npm install co-db
```

## Examples

### Simple DB

```
$ cd examples/simple-db
$ tree .

.
└── doc1
```

```js
var co = require('co'),
    codb = require('..');

co(function * () {
  var db = yield codb('examples/simple-db');
  var doc = yield db.doc('doc1');
  var contents = yield doc.contents;

  console.log('----Doc Obj----')
  console.log(doc);
  console.log('----Doc Contents----')
  console.log(contents.toString());
  console.log('--------------------')
})();
```

```
$ node --harmony-generators examples/simple-db.js

----Doc Obj----
{ cwd: '/path/to/co-db',
  id: 'doc1',
  base: '/path/to/co-db/examples/simple-db',
  path: '/path/to/co-db/examples/simple-db/doc1',
  contents: [Function] }
----Doc Contents----
   |
   |
   + \
   \\.G_.*=.
    `(H'/.\|
     .>' (_--.
  _=/d   ,^\
 ~~ \)-'   '
    / |
   '  '   a:f

--------------------
```

### JSON DB (middleware example)

```
$ cd examples/json-db
$ tree .

.
├── doc1.json
└── doc2.json
```

```js
// examples/json-db.js
var co = require('co'),
    codb = require('..');

co(function *() {
  var jsonDb = yield codb('examples/json-db'),
      docs = [];

  jsonDb.use(function *(doc){
    var contents = new Buffer(0),
        chunk;

    while (chunk = yield doc.contents) {
      contents = Buffer.concat([contents, chunk]);
    }

    doc.contents = JSON.parse(contents.toString());
  });

  docs = yield jsonDb.docs();

  docs.forEach(function (doc) {
    console.log('id ==', doc.id);
    console.log('contents ==', doc.contents);
    console.log('------------------------------');
  });
})();
```

```
$ node --harmony-generators examples/json-db.js

id == doc1.json
contents == { um: 'oh' }
------------------------------
id == doc2.json
contents == { wow: true }
------------------------------
```

## License

MIT

---
_Source: https://npm.io/package/co-db · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
