Comparing version 0.2.16 to 0.2.17
@@ -510,2 +510,12 @@ var r = require('rethinkdb'); | ||
} | ||
Model.prototype.delete = function(callback) { | ||
var query = new Query(this); | ||
query = query.delete(callback); | ||
return query; | ||
} | ||
Model.prototype.update = function(update, callback) { | ||
var query = new Query(this); | ||
query = query.update(update, callback); | ||
return query; | ||
} | ||
@@ -516,2 +526,3 @@ | ||
// Events | ||
@@ -518,0 +529,0 @@ Model.prototype.addListener = function(eventKey, listener) { |
@@ -77,2 +77,3 @@ var r = require('rethinkdb'); | ||
Query.prototype.limit = function(limit, callback) { | ||
@@ -312,8 +313,19 @@ this.query = this.query.limit(limit); | ||
if (typeof callback === 'function') { | ||
this.run(callback); | ||
this.execute(callback); | ||
} | ||
return this; | ||
} | ||
Query.prototype.update = function(update, callback) { | ||
// Chain with update | ||
this.query = this.query.update(update); | ||
// Execute if a callback is passed | ||
if (typeof callback === 'function') { | ||
this.execute(callback); | ||
} | ||
return this | ||
} | ||
// Specifies fields that should be returned as query result | ||
@@ -320,0 +332,0 @@ // http://www.rethinkdb.com/api/#js:document_manipulation-pluck |
{ | ||
"name": "thinky", | ||
"version": "0.2.16", | ||
"version": "0.2.17", | ||
"description": "RethinkDB ORM for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -581,2 +581,30 @@ var thinky = require('../lib/index.js'); | ||
describe('update', function() { | ||
it('should update all docs', function(done){ | ||
Cat = thinky.createModel('Cat', { id: String, name: String, privateField: String }); | ||
Cat.update({newField: "newValue"}, function(error, result) { | ||
if (error) throw error; | ||
should(result.errors == 0); | ||
should(result.replaced > 0); | ||
done(); | ||
}) | ||
}) | ||
}); | ||
describe('delete', function() { | ||
it('should delete all docs', function(done){ | ||
Cat = thinky.createModel('Cat', { id: String, name: String, privateField: String }); | ||
Cat.delete(function(error, result) { | ||
if (error) throw error; | ||
should(result.errors == 0); | ||
should(result.deleted > 0); | ||
Cat.run(function(error, result) { | ||
if (error) throw error; | ||
should(result.length == 0); | ||
done(); | ||
}) | ||
}) | ||
}) | ||
}); | ||
describe('without', function() { | ||
@@ -583,0 +611,0 @@ var Cat; |
952805
20355