New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

thinky

Package Overview
Dependencies
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thinky - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

examples/express-todo/node_modules/connect/.npmignore

2

examples/express-todo/app.js

@@ -9,3 +9,3 @@ /**

// mongoose setup
// thinky setup
require( './db' );

@@ -12,0 +12,0 @@

@@ -1,12 +0,9 @@

var mongoose = require( 'mongoose' );
var Schema = mongoose.Schema;
var thinky = require( 'thinky' );
var Todo = new Schema({
thinky.init({});
var Todo = thinky.createModel('Todo', {
id : String,
user_id : String,
content : String,
updated_at : Date
updated_at : {_type: Number , default: function() { return Date.now() } }
});
mongoose.model( 'Todo', Todo );
mongoose.connect( 'mongodb://localhost/express-todo' );

@@ -9,4 +9,4 @@ {

"ejs" : "0.8.3",
"mongoose" : "3.3.1"
"thinky" : "0.2.3"
}
}

@@ -1,3 +0,3 @@

var mongoose = require( 'mongoose' );
var Todo = mongoose.model( 'Todo' );
var thinky = require( 'thinky' );
var Todo = thinky.models['Todo'];
var utils = require( 'connect' ).utils;

@@ -10,7 +10,7 @@

Todo.
find({ user_id : user_id }).
sort( '-updated_at' ).
exec( function ( err, todos ){
filter({ user_id : user_id }).
orderBy( 'updated_at' ).
run( function ( err, todos ){
if( err ) return next( err );
console.log(todos);
res.render( 'index', {

@@ -36,3 +36,3 @@ title : 'Express Todo Example',

exports.destroy = function ( req, res, next ){
Todo.findById( req.params.id, function ( err, todo ){
Todo.get( req.params.id, null, function ( err, todo ){
var user_id = req.cookies ?

@@ -45,3 +45,3 @@ req.cookies.user_id : undefined;

todo.remove( function ( err, todo ){
todo.delete( function ( err, todo ){
if( err ) return next( err );

@@ -60,4 +60,4 @@

find({ user_id : user_id }).
sort( '-updated_at' ).
exec( function ( err, todos ){
orderBy( 'updated_at' ).
run( function ( err, todos ){
if( err ) return next( err );

@@ -74,3 +74,3 @@

exports.update = function( req, res, next ){
Todo.findById( req.params.id, function ( err, todo ){
Todo.get( req.params.id, null, function ( err, todo ){
var user_id = req.cookies ?

@@ -77,0 +77,0 @@ req.cookies.user_id : undefined;

@@ -143,2 +143,36 @@ var eventEmitter = require('events').EventEmitter;

Document.createCallbackDelete = function(doc, callback, count, originalDoc, originalCopyDoc,
joinClause, joinType, saveJoin) {
var arg = arguments;
var docSettings = doc.getDocSettings();
fn = function(error, result) {
if (error) {
if ((callback) && (typeof callback === 'function')) callback(error, null);;
}
else if ((result) && (result.errors > 0)) {
if ((callback) && (typeof callback === 'function')) callback(result, null);
}
else {
count.deleted++;
doc.getDocSettings().saved = false;
if (count.deleted === count.toDelete) {
// All sub document have been saved
// Let's save the parent
if ((originalDoc != null) && (joinClause != null) && (originalDoc !== doc)) {
originalDoc.delete({deleteJoin: false}, callback);
}
else {
if ((callback) && (typeof callback === 'function')) callback(null, doc);
// Need to emit other events...
doc.emit('delete', doc);
}
}
}
}
fn.__wrapped = true;
return fn
}
//TODO We don't need _save. Clean and merge _save and save

@@ -245,2 +279,94 @@ Document.prototype.save = function(callback, options) {

Document.prototype.delete = function(options, callback) {
var self = this; // The document
var model = this.getModel();
if ((options == null) || (options.saveJoin == null)) {
options = {
deleteJoin: false
}
}
var docSettings = self.getDocSettings();
var query, cb;
var count = {
toDelete: 0,
deleted: 0
}
if (options.deleteJoin === true) {
for(var key in self) {
if (self.hasOwnProperty(key) === true) {
if (model.joins.hasOwnProperty(key) === true) {
if (Object.prototype.toString.call(self[key]) === '[object Array]') {
for(var i= 0; i<self[key].length; i++) {
count.toDelete++;
if (typeof model.joins[key].joinClause === 'object') {
cb = Document.createCallbackDelete(self[key][i], callback, count, self, copyDoc,
model.joins[key].joinClause, 'hasMany', false)
}
else {
cb = Document.createCallbackDelete(self[key][i], callback, count, null, null,
null, 'hasMany')
}
self[key][i].delete(cb, true);
}
}
else if ((typeof self[key] === 'object') && (self[key] != null)) {
count.toDelete++;
if (typeof model.joins[key].joinClause === 'object') {
cb = Document.createCallbackDelete(self[key], callback, count, self, copyDoc,
model.joins[key].joinClause, 'hasOne', false)
}
else {
cb = Document.createCallbackDelete(self[key], callback, count, null, null,
null, 'hasOne')
}
self[key].delete(cb, true);
}
}
}
}
}
// If no sub document to save, we directly save things
if (count.toDelete === 0) {
if (docSettings.saved === true) {
count.toDelete++;
query = r.db(model.thinkyOptions.db).table(model.name)
.get(self[model.getPrimaryKey()])
.delete()
// we have to wrap the callback if the callback has not been wrapped before.
if (callback == null) {
cb = Document.createCallbackDelete(self, callback, count)
}
else if (callback.__wrapped === true) {
cb = callback
}
else {
cb = Document.createCallbackDelete(self, callback, count)
}
this._execute.call(self, query, cb);
}
else {
// we have to wrap the callback if the callback has not been wrapped before.
if (callback == null) {
cb = Document.createCallbackDelete(self, callback, count)
}
else if (callback.__wrapped === true) {
cb = callback
}
else {
cb = Document.createCallbackDelete(self, callback, count)
}
cb(null, {deleted: 1})
}
}
return this;
}
Document.prototype.off = function(eventKey, listener) {

@@ -247,0 +373,0 @@ if (arguments.length <= 1) {

{
"name": "thinky",
"version": "0.2.3",
"version": "0.2.4",
"description": "RethinkDB ORM for Node.js",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -68,3 +68,3 @@ # Thinky

### Roadmap
- Stick closer to the driver -- Things will be chainable
- Clean the code to save/delete -- My eyes are bleeding...
- Add examples on how to use Thinky.

@@ -71,0 +71,0 @@ - Clean/reorganize tests and add more tests.

@@ -144,4 +144,18 @@ var thinky = require('../lib/index.js');

});
describe('delete', function() {
it('should delete the doc', function(done){
Cat = thinky.createModel('Cat', { id: String, name: String });
catou = new Cat({name: 'Catou'});
catou.save( function(error, result) {
should.exist(result.id);
catou.delete( null, function(error, result) {
catou.getDocSettings().saved.should.be.false
done();
})
})
});
});
// Test listener

@@ -148,0 +162,0 @@ describe('on', function() {

@@ -512,3 +512,3 @@ var thinky = require('../lib/index.js');

it('retrieve documents in the database', function(done){
Cat.filter(function(doc) { return r.expr([catouCopy.id, minouCopy.id]).contains(doc("id")) },
Cat.filter(function(doc) { return r.expr([scope.catou.id, scope.minou.id]).contains(doc("id")) },
null,

@@ -710,2 +710,30 @@ function(error, result) {

});
it('should be able to delete the joined doc -- nested joins', function(done) {
Cat = thinky.createModel('Cat', {id: String, name: String, idHuman: String});
Human = thinky.createModel('Human', {id: String, ownerName: String, idMom: String});
Mother = thinky.createModel('Mother', {id: String, motherName: String});
Human.hasOne(Mother, 'mom', {leftKey: 'idMom', rightKey: 'id'});
Cat.hasOne(Human, 'owner', {leftKey: 'idHuman', rightKey: 'id'});
var owner = new Human({ownerName: "Michel"});
var catou = new Cat({name: "Catou"});
var mother = new Mother({motherName: "Mom"});
catou['owner'] = owner;
owner['mom'] = mother;
catou.save( function(error, result) {
should.exist(catou.id);
should.exist(catou.idHuman);
should.exist(catou.owner.id);
catou_id = catou.id;
catou.delete( {deleteJoin: true}, function(error, result) {
catou.getDocSettings().saved.should.be.false
catou.owner.getDocSettings().saved.should.be.false
catou.owner.mom.getDocSettings().saved.should.be.false
done();
})
}, {saveJoin: true});
});
it('getAll should work -- nested joins', function(done) {

@@ -712,0 +740,0 @@ Cat = thinky.createModel('Cat', {id: String, name: String, idHuman: String});

Sorry, the diff of this file is not supported yet

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