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

co-rethinkdb

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-rethinkdb - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

32

index.js

@@ -38,13 +38,23 @@ // When installing co-rethinkdb for an application that uses the same version

// Since every rethinkdb method call, e.g., r.table('...') retuns a
// function, `co` is going to call their `.call()` method making it
// the perfect place to execute the `.run()` method instead.
RDBOp.prototype.call = function(_, done) {
var query = this
co(function*() {
var conn = yield r.getConnection
var res = yield run.call(query, conn)
yield r.releaseConnection(conn)
done(null, res)
})()
// Adding a `.then()` method to the object returned by, .e.g., `r.table('...')`
// makes `co` to recognize these objects as promises, making the `.then()`
// method the perfect place to execute the `.run()` method instead.
var Promise = require('bluebird')
RDBOp.prototype.then = function() {
if (!this._promise) {
var query = this
this._promise = new Promise(function(resolve, reject) {
co(function*() {
var conn = yield r.getConnection
var res = yield run.call(query, conn)
yield r.releaseConnection(conn)
resolve(res)
})(function(err) {
reject(err)
})
})
}
this._promise.then.apply(this._promise, arguments)
}

@@ -51,0 +61,0 @@

{
"name": "co-rethinkdb",
"version": "1.1.0",
"version": "1.2.0",
"author": "Markus Ast <npm.m@rkusa.st>",
"description": "Generator based querying goodness for RethinkDB",
"description": "Generator/Promise based querying goodness for RethinkDB",
"keywords": [

@@ -19,2 +19,3 @@ "rethinkdb",

"dependencies": {
"bluebird": "^2.2.2",
"co": "^3.0.5",

@@ -21,0 +22,0 @@ "rethinkdb": "~1.13.0-0"

@@ -42,2 +42,18 @@ # co-rethinkdb

### In non-generator context
With `co-rethinkdb` each RethinkDB query is directly a Promise. If called, it uses `r.getConnection` to retrieve a connection.
```js
var conn
r.getConnection = function*() {
return conn || (conn = yield r.connect({ db: db }))
}
r.table('users').get(1).then(function(user) {
...
})
```
### Koa Middleware

@@ -44,0 +60,0 @@

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