sequelize
Advanced tools
Comparing version 1.3.2 to 1.3.3
@@ -0,1 +1,4 @@ | ||
# v1.3.3 # | ||
- [BUG] fixed sql-event emitter in all possible locations (thanks to megshark) | ||
# v1.3.2 # | ||
@@ -2,0 +5,0 @@ - [FEATURE] sqlite is now emitting the 'sql'-event as well (thanks to megshark) |
@@ -24,2 +24,3 @@ var Utils = require('./../utils') | ||
.on('failure', function(err){ customEventEmitter.emit('failure', err) }) | ||
.on('sql', function(sql) { customEventEmitter.emit('sql', sql)}) | ||
}) | ||
@@ -35,2 +36,3 @@ | ||
.error(function(err) { emitter.emit('failure', err) }) | ||
.on('sql', function(sql) { emitter.emit('sql', sql) }) | ||
.success(function() { | ||
@@ -54,2 +56,3 @@ var chainer = new Utils.QueryChainer | ||
.error(function(err) { emitter.emit('failure', err) }) | ||
.on('sql', function(sql) { emitter.emit('sql', sql) }) | ||
}) | ||
@@ -88,2 +91,3 @@ } | ||
.error(function(err) { emitter.emit('failure', err) }) | ||
.on('sql', function(sql) { emitter.emit('sql', sql) }) | ||
} | ||
@@ -90,0 +94,0 @@ }) |
@@ -29,4 +29,4 @@ var Utils = require("../../utils") | ||
this.client.query(this.sql, function(err, results, fields) { | ||
//allow clients to listen to sql to do their own logging or whatnot | ||
self.emit('sql', self.sql) | ||
@@ -80,2 +80,3 @@ err ? onFailure.call(self, err) : onSuccess.call(self, results, fields) | ||
this.emit('success', result) | ||
} | ||
@@ -82,0 +83,0 @@ |
@@ -23,3 +23,4 @@ var Utils = require("../utils") | ||
return Query | ||
})() |
@@ -28,6 +28,5 @@ var Utils = require("../../utils") | ||
//allow clients to listen to sql to do their own logging or whatnot | ||
self.emit('sql', self.sql) | ||
self.database[databaseMethod](self.sql, function(err, results) { | ||
//allow clients to listen to sql to do their own logging or whatnot | ||
self.emit('sql', self.sql) | ||
err ? onFailure.call(self, err) : onSuccess.call(self, results, this) | ||
@@ -34,0 +33,0 @@ }) |
@@ -36,3 +36,4 @@ var util = require("util") | ||
return CustomEventEmitter | ||
})() |
@@ -71,2 +71,3 @@ var Utils = require("./utils") | ||
.error(function(err) { emitter.emit('failure', err) }) | ||
.on('sql', function(sql) { emitter.emit('sql', sql) }) | ||
} | ||
@@ -73,0 +74,0 @@ |
@@ -102,2 +102,3 @@ var Utils = require("./utils") | ||
}) | ||
.on('sql', function(sql){ self.eventEmitter.emit('sql', sql) }) | ||
} | ||
@@ -104,0 +105,0 @@ |
@@ -204,5 +204,6 @@ var Utils = require('./utils') | ||
self.sequelize | ||
var qry = self.sequelize | ||
.query(sql, null, { plain: true, raw: true }) | ||
.success(function(data) { | ||
qry.success(function(data) { | ||
self.emit('rawSelect', null) | ||
@@ -215,2 +216,5 @@ emitter.emit('success', data[attributeSelector]) | ||
}) | ||
qry.on('sql', function(sql) { | ||
emitter.emit('sql', sql) | ||
}) | ||
}).run() | ||
@@ -249,2 +253,5 @@ } | ||
}) | ||
query.on('sql', function(sql) { | ||
emitter.emit('sql', sql) | ||
}) | ||
}).run() | ||
@@ -251,0 +258,0 @@ } |
{ | ||
"name": "sequelize", | ||
"description": "MySQL ORM for Node.JS", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"author": "Sascha Depold <sascha@depold.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -243,2 +243,41 @@ var config = require("../config/config") | ||
it("allows join table to be specified", function() { | ||
Helpers.async(function(done) { | ||
var Child = sequelize.define('Child', { name: Sequelize.STRING }, {underscore: true, freezeTableName: true}) | ||
var Parent = sequelize.define('Parent', { name: Sequelize.STRING }, {underscore: true, freezeTableName: true}) | ||
var ParentJoin = sequelize.define('ParentRelationship', { parent_id: Sequelize.INTEGER, child_id: Sequelize.INTEGER }, {underscore: true, freezeTableName: true}) | ||
Parent.hasMany(Child, {as: 'Children', foreignKey: 'child_id', joinTableName: 'ParentRelationship'}) | ||
Child.hasMany(Parent, {as: 'Parents', foreignKey: 'parent_id', joinTableName: 'ParentRelationship'}) | ||
var parents = [] | ||
ParentJoin.sync({force: true}).success(function() { | ||
Parent.sync({force: true}).success(function() { | ||
Child.sync({force: true}).success(function() { | ||
Parent.create({name: 'mom'}).success(function(mom) { | ||
parents.push(mom) | ||
Parent.create({name: 'dad'}).success(function(dad) { | ||
parents.push(dad) | ||
Child.create({name: 'baby'}).success(function(baby) { | ||
baby.setParents(parents).success(function(){ | ||
parents[0].getChildren().success(function(children){ | ||
expect(children).not.toBe(null) | ||
expect(children.length).toBeDefined() | ||
expect(children.length).toEqual(1) | ||
expect(children[0]).toBeDefined() | ||
expect(children[0].name).toEqual('baby') | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
it("gets and sets the connector models", function() { | ||
@@ -245,0 +284,0 @@ Helpers.async(function(done) { |
@@ -186,2 +186,15 @@ var config = require("./config/config") | ||
}) | ||
it('allows sql logging', function() { | ||
Helpers.async(function(done) { | ||
User | ||
.create({ name: 'Fluffy Bunny', smth: 'else' }) | ||
.on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("INSERT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -214,2 +227,25 @@ | ||
it('allows sql logging of delete statements', function() { | ||
Helpers.async(function(done) { | ||
User = sequelize.define('User', { | ||
name: Sequelize.STRING, | ||
bio: Sequelize.TEXT | ||
}) | ||
User.sync({force: true}).success(done) | ||
}) | ||
Helpers.async(function(done) { | ||
User.create({name: 'hallo', bio: 'welt'}).success(function(u) { | ||
User.all().success(function(users) { | ||
expect(users.length).toEqual(1) | ||
u.destroy().on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("DELETE")).toBeGreaterThan(-1) | ||
done() | ||
}).error(function(err) { console.log(err) }) | ||
}).error(function(err) { console.log(err) }) | ||
}) | ||
}) | ||
}) | ||
it('marks the database entry as deleted if model is paranoid', function() { | ||
@@ -233,2 +269,23 @@ Helpers.async(function(done) { | ||
}) | ||
it('allows sql logging of update statements', function() { | ||
Helpers.async(function(done) { | ||
User = sequelize.define('User', { | ||
name: Sequelize.STRING, bio: Sequelize.TEXT | ||
}, { paranoid:true }) | ||
User.sync({ force: true }).success(done) | ||
}) | ||
Helpers.async(function(done) { | ||
User.create({ name: 'meg', bio: 'none' }).success(function(u) { | ||
expect(u).toBeDefined() | ||
expect(u).not.toBe(null) | ||
u.destroy().on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("UPDATE")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -282,2 +339,13 @@ | ||
it('allows sql logging', function() { | ||
Helpers.async(function(done) { | ||
User.find({ where: { name: 'foo' } }) | ||
.on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("SELECT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('ignores passed limit option', function() { | ||
@@ -440,2 +508,13 @@ Helpers.async(function(done) { | ||
it('allows sql logging', function() { | ||
Helpers.async(function(done) { | ||
User.count() | ||
.on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("SELECT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
}) | ||
}) | ||
it('filters object', function() { | ||
@@ -467,2 +546,12 @@ Helpers.async(function(done) { | ||
}) | ||
it('allows sql logging', function() { | ||
Helpers.async(function(done) { | ||
User.min('age') | ||
.on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("SELECT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -480,2 +569,12 @@ | ||
}) | ||
it('allows sql logging', function() { | ||
Helpers.async(function(done) { | ||
User.max('age') | ||
.on('sql', function(sql) { | ||
expect(sql).toBeDefined() | ||
expect(sql.toUpperCase().indexOf("SELECT")).toBeGreaterThan(-1) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -482,0 +581,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
442305
5324