Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hden/rethinkdb-co
Harness RethinkDB Callbacks with ECMAScript 6 Generators
https://github.com/hden/rethinkdb-co
Last synced: 24 days ago
JSON representation
Harness RethinkDB Callbacks with ECMAScript 6 Generators
- Host: GitHub
- URL: https://github.com/hden/rethinkdb-co
- Owner: hden
- License: mit
- Archived: true
- Created: 2013-12-30T16:56:39.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-08-16T08:28:46.000Z (over 4 years ago)
- Last Synced: 2024-03-29T02:04:04.640Z (9 months ago)
- Language: CoffeeScript
- Size: 5.86 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rethinkdb - RethinkDB Callbacks with ECMAScript 6 Generators
README
rethinkdb-co
============Harness RethinkDB Callbacks with ECMAScript 6 Generators
## Installation
$ npm install rethinkdb-co
## Example
```javascript
var rco = require('rethinkdb-co');
var r = require('rethinkdb');
var co = require('co');var query = r.tableList();
co(function *() {
// pause and wait for connection
var connection = yield rco.connect();
// pause and wait for result
var result = yield rco.run(query);
console.log('result', result);
// disconnect
yield rco.disconnect();
})();
```## With koa-rethinkdb
```javascript
var rethinkdbPool = require('koa-rethinkdb');
var rco = require('rethinkdb-co');
var r = require('rethinkdb');app.use(rethinkdbPool(options));
app.use(function *(next) {
// get the list of table
var query1 = r.db('test').tableList();var list = yield rco.run(query1);
// select a few documents
var query2 = r.db('test').table('foobar').limit(10);result = yield rco.runf(query2);
yield next;
// connections are released back to the pool.
});
````## methond: run
Return the result you would expect from rethinkdb client.
## methond: runf
If the query returns a cursor, run `cursor.toArray()` for you, since that's probably what you want.
## License
MIT