不要怂,就是干,撸起袖子干!

Commit 0c114c36 by Jan Aagaard Meier

Removed all queryAndEmit calls from the regular queryinterface

1 parent 80503f1f
...@@ -5,6 +5,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell ...@@ -5,6 +5,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- Sequelize now returns promises instead of its custom event emitter from most calls. This affects methods that return multiple values (like `findOrCreate` or `findOrInitialize`). If your current callbacks do not accept the 2nd success parameter you might be seeing an array as the first param. Either use `.spread()` for these methods or add another argument to your callback: `.success(instance)` -> `.success(instance, created)`. - Sequelize now returns promises instead of its custom event emitter from most calls. This affects methods that return multiple values (like `findOrCreate` or `findOrInitialize`). If your current callbacks do not accept the 2nd success parameter you might be seeing an array as the first param. Either use `.spread()` for these methods or add another argument to your callback: `.success(instance)` -> `.success(instance, created)`.
- `.success()`/`.done()` and any other non promise methods are now deprecated (we will keep the codebase around for a few versions though). on('sql') persists for debugging purposes. - `.success()`/`.done()` and any other non promise methods are now deprecated (we will keep the codebase around for a few versions though). on('sql') persists for debugging purposes.
- Model association calls (belongsTo/hasOne/hasMany) are no longer chainable. (this is to support being able to pass association references to include rather than model/as combinations) - Model association calls (belongsTo/hasOne/hasMany) are no longer chainable. (this is to support being able to pass association references to include rather than model/as combinations)
- `QueryInterface` no longer emits events
# v2.0.0-dev11 # v2.0.0-dev11
### Caution: This release contains many changes and is highly experimental ### Caution: This release contains many changes and is highly experimental
......
...@@ -102,7 +102,7 @@ Hooks.runHooks = function() { ...@@ -102,7 +102,7 @@ Hooks.runHooks = function() {
}) })
if (fn) { if (fn) {
promise.spread(function () { promise = promise.spread(function () {
fn.apply(self, [null].concat(Array.prototype.slice.apply(arguments))); fn.apply(self, [null].concat(Array.prototype.slice.apply(arguments)));
}, fn); }, fn);
} }
......
...@@ -648,17 +648,15 @@ module.exports = (function() { ...@@ -648,17 +648,15 @@ module.exports = (function() {
// This semi awkward syntax where we can't return the chain directly but have to return the last .then() call is to allow sql proxying // This semi awkward syntax where we can't return the chain directly but have to return the last .then() call is to allow sql proxying
return self.Model.runHooks(self.Model.options.hooks.beforeDestroy, self).then(function () { return self.Model.runHooks(self.Model.options.hooks.beforeDestroy, self).then(function () {
var query var identifier
, identifier
if (self.Model._timestampAttributes.deletedAt && options.force === false) { if (self.Model._timestampAttributes.deletedAt && options.force === false) {
self.dataValues[self.Model._timestampAttributes.deletedAt] = new Date() self.dataValues[self.Model._timestampAttributes.deletedAt] = new Date()
query = self.save(options) return self.save(options)
} else { } else {
identifier = self.__options.hasPrimaryKeys ? self.primaryKeyValues : { id: self.id }; identifier = self.__options.hasPrimaryKeys ? self.primaryKeyValues : { id: self.id };
query = self.QueryInterface.delete(self, self.QueryInterface.QueryGenerator.addSchema(self.Model), identifier, options) return self.QueryInterface.delete(self, self.QueryInterface.QueryGenerator.addSchema(self.Model), identifier, options)
} }
return query;
}).then(function (results) { }).then(function (results) {
return self.Model.runHooks(self.Model.options.hooks.afterDestroy, self).return(results); return self.Model.runHooks(self.Model.options.hooks.afterDestroy, self).return(results);
}); });
......
...@@ -170,7 +170,7 @@ module.exports = (function() { ...@@ -170,7 +170,7 @@ module.exports = (function() {
type: QueryTypes.SELECT type: QueryTypes.SELECT
}, options || {}) }, options || {})
return self.QueryInterface.queryAndEmit([result.toSql(), self, options], 'snafu') return self.sequelize.query(result.toSql(), self, options)
} }
return result return result
...@@ -393,7 +393,7 @@ module.exports = (function() { ...@@ -393,7 +393,7 @@ module.exports = (function() {
if (options.force) { if (options.force) {
return self.drop(options).then(function () { return self.drop(options).then(function () {
return doQuery().return(self); return doQuery().return(self)
}); });
} else { } else {
return doQuery().return(this) return doQuery().return(this)
...@@ -1143,7 +1143,7 @@ module.exports = (function() { ...@@ -1143,7 +1143,7 @@ module.exports = (function() {
} }
if(this.sequelize.options.dialect === 'postgres' && options.ignoreDuplicates) { if(this.sequelize.options.dialect === 'postgres' && options.ignoreDuplicates) {
return this.sequelize.Promise.reject(new Error('Postgres does not support the \'ignoreDuplicates\' option.')) return Utils.Promise.reject(new Error('Postgres does not support the \'ignoreDuplicates\' option.'))
} }
var self = this var self = this
......
...@@ -21,12 +21,12 @@ module.exports = (function() { ...@@ -21,12 +21,12 @@ module.exports = (function() {
QueryInterface.prototype.createSchema = function(schema) { QueryInterface.prototype.createSchema = function(schema) {
var sql = this.QueryGenerator.createSchema(schema) var sql = this.QueryGenerator.createSchema(schema)
return queryAndEmit.call(this, sql, 'createSchema') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} }
QueryInterface.prototype.dropSchema = function(schema) { QueryInterface.prototype.dropSchema = function(schema) {
var sql = this.QueryGenerator.dropSchema(schema) var sql = this.QueryGenerator.dropSchema(schema)
return queryAndEmit.call(this, sql, 'dropSchema') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} }
QueryInterface.prototype.dropAllSchemas = function() { QueryInterface.prototype.dropAllSchemas = function() {
...@@ -35,15 +35,9 @@ module.exports = (function() { ...@@ -35,15 +35,9 @@ module.exports = (function() {
if (!this.QueryGenerator._dialect.supports.schemas) { if (!this.QueryGenerator._dialect.supports.schemas) {
return this.sequelize.drop() return this.sequelize.drop()
} else { } else {
return new Utils.CustomEventEmitter(function(emitter) { return this.showAllSchemas().map(function (schemaName, index, length) {
self.showAllSchemas().success(function(schemaNames) { return self.dropSchema(schemaName)
var chainer = new Utils.QueryChainer()
schemaNames.forEach(function(schemaName) {
chainer.add(self.dropSchema(schemaName))
}) })
chainer.run().proxy(emitter)
}).proxy(emitter, {events: ['sql', 'error']})
}).run()
} }
} }
...@@ -55,16 +49,15 @@ module.exports = (function() { ...@@ -55,16 +49,15 @@ module.exports = (function() {
raw: true raw: true
}, options || {}) }, options || {})
return new Utils.CustomEventEmitter(function(emitter) {
var showSchemasSql = self.QueryGenerator.showSchemasQuery() var showSchemasSql = self.QueryGenerator.showSchemasQuery()
self.sequelize.query(showSchemasSql, null, options).success(function(schemaNames) {
self.emit('showAllSchemas', null) return this.sequelize.query(showSchemasSql, null, options).then(function (schemaNames) {
emitter.emit('success', Utils._.flatten(Utils._.map(schemaNames, function(value){ return (!!value.schema_name ? value.schema_name : value) }))) return Utils._.flatten(
}).error(function(err) { Utils._.map(schemaNames, function(value){
self.emit('showAllSchemas', err) return (!!value.schema_name ? value.schema_name : value)
emitter.emit('error', err) })
)
}) })
}).run()
} }
QueryInterface.prototype.createTable = function(tableName, attributes, options) { QueryInterface.prototype.createTable = function(tableName, attributes, options) {
...@@ -145,14 +138,14 @@ module.exports = (function() { ...@@ -145,14 +138,14 @@ module.exports = (function() {
sql = self.QueryGenerator.createTableQuery(tableName, attributes, options) sql = self.QueryGenerator.createTableQuery(tableName, attributes, options)
return Promise.all(promises).then(function() { return Promise.all(promises).then(function() {
return queryAndEmit.call(self, sql, 'createTable', options) return self.sequelize.query(sql, null, options)
}) })
}) })
} else { } else {
attributes = self.QueryGenerator.attributesToSQL(attributeHashes) attributes = self.QueryGenerator.attributesToSQL(attributeHashes)
sql = self.QueryGenerator.createTableQuery(tableName, attributes, options) sql = self.QueryGenerator.createTableQuery(tableName, attributes, options)
return queryAndEmit.call(self, sql, 'createTable', options) return self.sequelize.query(sql, null, options)
} }
} }
...@@ -164,19 +157,15 @@ module.exports = (function() { ...@@ -164,19 +157,15 @@ module.exports = (function() {
var sql = this.QueryGenerator.dropTableQuery(tableName, options) var sql = this.QueryGenerator.dropTableQuery(tableName, options)
, self = this , self = this
return queryAndEmit.call(this, sql, 'dropTable', options).then(function () { return this.sequelize.query(sql, null, options).then(function () {
var promises = [] var promises = []
// Since postgres has a special case for enums, we should drop the related // Since postgres has a special case for enums, we should drop the related
// enum type within the table and attribute // enum type within the table and attribute
if (self.sequelize.options.dialect === "postgres") { if (self.sequelize.options.dialect === "postgres") {
// Find the table that we're trying to drop // Find the table that we're trying to drop
daoTable = self.sequelize.daoFactoryManager.daos.filter(function(dao) { daoTable = self.sequelize.daoFactoryManager.getDAO(tableName, 'tableName')
return dao.tableName === tableName
})
// Just in case if we're trying to drop a non-existing table
daoTable = daoTable.length > 0 ? daoTable[0] : null
if (!!daoTable) { if (!!daoTable) {
var getTableName = (!options || !options.schema || options.schema === "public" ? '' : options.schema + '_') + tableName var getTableName = (!options || !options.schema || options.schema === "public" ? '' : options.schema + '_') + tableName
...@@ -192,9 +181,7 @@ module.exports = (function() { ...@@ -192,9 +181,7 @@ module.exports = (function() {
} }
} }
return Promise.all(promises).then(function (results) { return Promise.all(promises).get(0);
return results[0];
});
}) })
} }
...@@ -220,7 +207,6 @@ module.exports = (function() { ...@@ -220,7 +207,6 @@ module.exports = (function() {
} }
self.showAllTables().success(function(tableNames) { self.showAllTables().success(function(tableNames) {
self.getForeignKeysForTables(tableNames).success(function(foreignKeys) { self.getForeignKeysForTables(tableNames).success(function(foreignKeys) {
// add the foreign key removal query to the chainer // add the foreign key removal query to the chainer
Object.keys(foreignKeys).forEach(function(tableName) { Object.keys(foreignKeys).forEach(function(tableName) {
foreignKeys[tableName].forEach(function(foreignKey) { foreignKeys[tableName].forEach(function(foreignKey) {
...@@ -248,37 +234,26 @@ module.exports = (function() { ...@@ -248,37 +234,26 @@ module.exports = (function() {
QueryInterface.prototype.dropAllEnums = function(options) { QueryInterface.prototype.dropAllEnums = function(options) {
if (this.sequelize.getDialect() !== 'postgres') { if (this.sequelize.getDialect() !== 'postgres') {
return new Utils.CustomEventEmitter(function (emitter) { return Utils.Promise.resolve()
emitter.emit('success')
}).run()
} }
options = options || {} options = options || {}
var self = this var self = this
, emitter = new Utils.CustomEventEmitter()
, chainer = new Utils.QueryChainer()
, sql = this.QueryGenerator.pgListEnums() , sql = this.QueryGenerator.pgListEnums()
this.sequelize.query(sql, null, { plain: false, raw: true, type: QueryTypes.SELECT, logging: options.logging }) return this.sequelize.query(sql, null, { plain: false, raw: true, type: QueryTypes.SELECT, logging: options.logging }).map(function (result) {
.proxy(emitter, {events: ['sql', 'error']}) return self.sequelize.query(
.success(function (results) {
results.forEach(function (result) {
chainer.add(self.sequelize.query(
self.QueryGenerator.pgEnumDrop(null, null, self.QueryGenerator.pgEscapeAndQuote(result.enum_name)), self.QueryGenerator.pgEnumDrop(null, null, self.QueryGenerator.pgEscapeAndQuote(result.enum_name)),
null, null,
{logging: options.logging, raw: true} {logging: options.logging, raw: true}
)) )
})
chainer.run().proxy(emitter)
}) })
return emitter
} }
QueryInterface.prototype.renameTable = function(before, after) { QueryInterface.prototype.renameTable = function(before, after) {
var sql = this.QueryGenerator.renameTableQuery(before, after) var sql = this.QueryGenerator.renameTableQuery(before, after)
return queryAndEmit.call(this, sql, 'renameTable') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} }
QueryInterface.prototype.showAllTables = function(options) { QueryInterface.prototype.showAllTables = function(options) {
...@@ -341,7 +316,8 @@ module.exports = (function() { ...@@ -341,7 +316,8 @@ module.exports = (function() {
var options = this.QueryGenerator.attributesToSQL(attributes) var options = this.QueryGenerator.attributesToSQL(attributes)
, sql = this.QueryGenerator.addColumnQuery(tableName, options) , sql = this.QueryGenerator.addColumnQuery(tableName, options)
return queryAndEmit.call(this, sql, 'addColumn')
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} }
QueryInterface.prototype.removeColumn = function(tableName, attributeName) { QueryInterface.prototype.removeColumn = function(tableName, attributeName) {
...@@ -350,7 +326,7 @@ module.exports = (function() { ...@@ -350,7 +326,7 @@ module.exports = (function() {
return SQLiteQueryInterface.removeColumn.call(this, tableName, attributeName, null, queryAndEmit) return SQLiteQueryInterface.removeColumn.call(this, tableName, attributeName, null, queryAndEmit)
} else { } else {
var sql = this.QueryGenerator.removeColumnQuery(tableName, attributeName) var sql = this.QueryGenerator.removeColumnQuery(tableName, attributeName)
return queryAndEmit.call(this, sql, 'removeColumn') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} }
} }
...@@ -370,7 +346,7 @@ module.exports = (function() { ...@@ -370,7 +346,7 @@ module.exports = (function() {
var options = this.QueryGenerator.attributesToSQL(attributes) var options = this.QueryGenerator.attributesToSQL(attributes)
, sql = this.QueryGenerator.changeColumnQuery(tableName, options) , sql = this.QueryGenerator.changeColumnQuery(tableName, options)
return queryAndEmit.call(this, sql, 'changeColumn') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} }
} }
...@@ -400,59 +376,52 @@ module.exports = (function() { ...@@ -400,59 +376,52 @@ module.exports = (function() {
attrNameBefore, attrNameBefore,
this.QueryGenerator.attributesToSQL(options) this.QueryGenerator.attributesToSQL(options)
) )
return queryAndEmit.call(this, sql, 'renameColumn', {}) return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} }
}.bind(this)); }.bind(this));
} }
QueryInterface.prototype.addIndex = function(tableName, attributes, options) { QueryInterface.prototype.addIndex = function(tableName, attributes, options) {
var sql = this.QueryGenerator.addIndexQuery(tableName, attributes, options) var sql = this.QueryGenerator.addIndexQuery(tableName, attributes, options)
return queryAndEmit.call(this, sql, 'addIndex') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} }
QueryInterface.prototype.showIndex = function(tableName, options) { QueryInterface.prototype.showIndex = function(tableName, options) {
var sql = this.QueryGenerator.showIndexQuery(tableName, options) var sql = this.QueryGenerator.showIndexQuery(tableName, options)
return queryAndEmit.call(this, sql, 'showIndex') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} }
QueryInterface.prototype.getForeignKeysForTables = function(tableNames) { QueryInterface.prototype.getForeignKeysForTables = function(tableNames) {
var self = this var self = this
return new Utils.CustomEventEmitter(function(emitter) {
if (tableNames.length === 0) { if (tableNames.length === 0) {
emitter.emit('success', {}) return Utils.Promise.resolve({})
} else { }
var chainer = new Utils.QueryChainer()
tableNames.forEach(function(tableName) {
var sql = self.QueryGenerator.getForeignKeysQuery(tableName, self.sequelize.config.database)
chainer.add(self.sequelize, 'query', [sql])
})
chainer.runSerially().proxy(emitter, { return Utils.Promise.map(tableNames, function (tableName) {
skipEvents: ['success'] return self.sequelize.query(self.QueryGenerator.getForeignKeysQuery(tableName, self.sequelize.config.database))
}).success(function(results) { }).then(function (results) {
var result = {} var result = {}
tableNames.forEach(function(tableName, i) { tableNames.forEach(function(tableName, i) {
result[tableName] = Utils._.compact(results[i]).map(function(r) { return r.constraint_name }) result[tableName] = Utils._.compact(results[i]).map(function(r) {
return r.constraint_name
})
}) })
emitter.emit('success', result) return result
}) })
} }
}).run()
}
QueryInterface.prototype.removeIndex = function(tableName, indexNameOrAttributes) { QueryInterface.prototype.removeIndex = function(tableName, indexNameOrAttributes) {
var sql = this.QueryGenerator.removeIndexQuery(tableName, indexNameOrAttributes) var sql = this.QueryGenerator.removeIndexQuery(tableName, indexNameOrAttributes)
return queryAndEmit.call(this, sql, "removeIndex") return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} }
QueryInterface.prototype.insert = function(dao, tableName, values, options) { QueryInterface.prototype.insert = function(dao, tableName, values, options) {
var sql = this.QueryGenerator.insertQuery(tableName, values, dao.Model.rawAttributes); var sql = this.QueryGenerator.insertQuery(tableName, values, dao.Model.rawAttributes);
return queryAndEmit.call(this, [sql, dao, options], 'insert').then(function (result) { return this.sequelize.query(sql, dao, options).then(function (result) {
result.isNewRecord = false; result.isNewRecord = false;
return result; return result;
}); });
...@@ -460,7 +429,7 @@ module.exports = (function() { ...@@ -460,7 +429,7 @@ module.exports = (function() {
QueryInterface.prototype.bulkInsert = function(tableName, records, options, Model) { QueryInterface.prototype.bulkInsert = function(tableName, records, options, Model) {
var sql = this.QueryGenerator.bulkInsertQuery(tableName, records, options, Model.rawAttributes) var sql = this.QueryGenerator.bulkInsertQuery(tableName, records, options, Model.rawAttributes)
return queryAndEmit.call(this, [sql, null, options], 'bulkInsert') return this.sequelize.query(sql, null, options)
} }
QueryInterface.prototype.update = function(dao, tableName, values, identifier, options) { QueryInterface.prototype.update = function(dao, tableName, values, identifier, options) {
...@@ -480,13 +449,13 @@ module.exports = (function() { ...@@ -480,13 +449,13 @@ module.exports = (function() {
} }
} }
return this.queryAndEmit([sql, dao, options], 'update') return this.sequelize.query(sql, dao, options)
} }
QueryInterface.prototype.bulkUpdate = function(tableName, values, identifier, options, attributes) { QueryInterface.prototype.bulkUpdate = function(tableName, values, identifier, options, attributes) {
var sql = this.QueryGenerator.updateQuery(tableName, values, identifier, options, attributes) var sql = this.QueryGenerator.updateQuery(tableName, values, identifier, options, attributes)
return this.queryAndEmit([sql, null, options], 'bulkUpdate') return this.sequelize.query(sql, null, options)
} }
QueryInterface.prototype.delete = function(dao, tableName, identifier, options) { QueryInterface.prototype.delete = function(dao, tableName, identifier, options) {
...@@ -512,7 +481,7 @@ module.exports = (function() { ...@@ -512,7 +481,7 @@ module.exports = (function() {
} }
} }
return new Promise(function (resolve, reject) { return new Utils.Promise(function (resolve, reject) {
var tick = 0 var tick = 0
var iterate = function(err, i) { var iterate = function(err, i) {
if (err) { if (err) {
...@@ -561,14 +530,13 @@ module.exports = (function() { ...@@ -561,14 +530,13 @@ module.exports = (function() {
resolve(); resolve();
} }
}).then(function () { }).then(function () {
return self.queryAndEmit([sql, dao, options], 'delete'); return self.sequelize.query(sql, dao, options)
}); });
} }
QueryInterface.prototype.bulkDelete = function(tableName, identifier, options) { QueryInterface.prototype.bulkDelete = function(tableName, identifier, options) {
var sql = this.QueryGenerator.deleteQuery(tableName, identifier, Utils._.defaults(options || {}, {limit: null})) var sql = this.QueryGenerator.deleteQuery(tableName, identifier, Utils._.defaults(options || {}, {limit: null}))
return this.sequelize.query(sql, null, options)
return this.queryAndEmit([sql, null, options], 'bulkDelete', options)
} }
QueryInterface.prototype.select = function(factory, tableName, options, queryOptions) { QueryInterface.prototype.select = function(factory, tableName, options, queryOptions) {
...@@ -601,12 +569,12 @@ module.exports = (function() { ...@@ -601,12 +569,12 @@ module.exports = (function() {
originalAttributes: options.originalAttributes originalAttributes: options.originalAttributes
}) })
return queryAndEmit.call(this, [sql, factory, queryOptions], 'select') return this.sequelize.query(sql, factory, queryOptions)
} }
QueryInterface.prototype.increment = function(dao, tableName, values, identifier, options) { QueryInterface.prototype.increment = function(dao, tableName, values, identifier, options) {
var sql = this.QueryGenerator.incrementQuery(tableName, values, identifier, options.attributes) var sql = this.QueryGenerator.incrementQuery(tableName, values, identifier, options.attributes)
return queryAndEmit.call(this, [sql, dao, options], 'increment') return this.sequelize.query(sql, dao, options)
} }
QueryInterface.prototype.rawSelect = function(tableName, options, attributeSelector, Model) { QueryInterface.prototype.rawSelect = function(tableName, options, attributeSelector, Model) {
...@@ -643,72 +611,54 @@ module.exports = (function() { ...@@ -643,72 +611,54 @@ module.exports = (function() {
var sql = this.QueryGenerator.createTrigger(tableName, triggerName, timingType, fireOnArray, functionName var sql = this.QueryGenerator.createTrigger(tableName, triggerName, timingType, fireOnArray, functionName
, functionParams, optionsArray) , functionParams, optionsArray)
if (sql){ if (sql){
return queryAndEmit.call(this, sql, 'createTrigger') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} else { } else {
return new Utils.CustomEventEmitter(function(emitter) { return Utils.Promise.resolve()
this.emit('createTrigger', null)
emitter.emit('success')
}).run()
} }
} }
QueryInterface.prototype.dropTrigger = function(tableName, triggerName) { QueryInterface.prototype.dropTrigger = function(tableName, triggerName) {
var sql = this.QueryGenerator.dropTrigger(tableName, triggerName) var sql = this.QueryGenerator.dropTrigger(tableName, triggerName)
if (sql){ if (sql){
return queryAndEmit.call(this, sql, 'dropTrigger') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} else { } else {
return new Utils.CustomEventEmitter(function(emitter) { return Utils.Promise.resolve()
this.emit('dropTrigger', null)
emitter.emit('success')
}).run()
} }
} }
QueryInterface.prototype.renameTrigger = function(tableName, oldTriggerName, newTriggerName) { QueryInterface.prototype.renameTrigger = function(tableName, oldTriggerName, newTriggerName) {
var sql = this.QueryGenerator.renameTrigger(tableName, oldTriggerName, newTriggerName) var sql = this.QueryGenerator.renameTrigger(tableName, oldTriggerName, newTriggerName)
if (sql){ if (sql){
return queryAndEmit.call(this, sql, 'renameTrigger') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} else { } else {
return new Utils.CustomEventEmitter(function(emitter) { return Utils.Promise.resolve()
this.emit('renameTrigger', null)
emitter.emit('success')
}).run()
} }
} }
QueryInterface.prototype.createFunction = function(functionName, params, returnType, language, body, options) { QueryInterface.prototype.createFunction = function(functionName, params, returnType, language, body, options) {
var sql = this.QueryGenerator.createFunction(functionName, params, returnType, language, body, options) var sql = this.QueryGenerator.createFunction(functionName, params, returnType, language, body, options)
if (sql){ if (sql){
return queryAndEmit.call(this, sql, 'createFunction') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} else { } else {
return new Utils.CustomEventEmitter(function(emitter) { return Utils.Promise.resolve()
this.emit('createFunction', null)
emitter.emit('success')
}).run()
} }
} }
QueryInterface.prototype.dropFunction = function(functionName, params) { QueryInterface.prototype.dropFunction = function(functionName, params) {
var sql = this.QueryGenerator.dropFunction(functionName, params) var sql = this.QueryGenerator.dropFunction(functionName, params)
if (sql){ if (sql){
return queryAndEmit.call(this, sql, 'dropFunction') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} else { } else {
return new Utils.CustomEventEmitter(function(emitter) { return Utils.Promise.resolve()
this.emit('dropFunction', null)
emitter.emit('success')
}).run()
} }
} }
QueryInterface.prototype.renameFunction = function(oldFunctionName, params, newFunctionName) { QueryInterface.prototype.renameFunction = function(oldFunctionName, params, newFunctionName) {
var sql = this.QueryGenerator.renameFunction(oldFunctionName, params, newFunctionName) var sql = this.QueryGenerator.renameFunction(oldFunctionName, params, newFunctionName)
if (sql){ if (sql){
return queryAndEmit.call(this, sql, 'renameFunction') return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging})
} else { } else {
return new Utils.CustomEventEmitter(function(emitter) { return Utils.Promise.resolve()
this.emit('renameFunction', null)
emitter.emit('success')
}).run()
} }
} }
...@@ -727,7 +677,6 @@ module.exports = (function() { ...@@ -727,7 +677,6 @@ module.exports = (function() {
return this.QueryGenerator.quoteTable(identifier) return this.QueryGenerator.quoteTable(identifier)
} }
/** /**
* Split an identifier into .-separated tokens and quote each part. * Split an identifier into .-separated tokens and quote each part.
* If force is true, the identifier will be quoted even if the * If force is true, the identifier will be quoted even if the
...@@ -750,7 +699,7 @@ module.exports = (function() { ...@@ -750,7 +699,7 @@ module.exports = (function() {
} }
var sql = this.QueryGenerator.setAutocommitQuery(value) var sql = this.QueryGenerator.setAutocommitQuery(value)
return this.queryAndEmit([sql, null, { transaction: transaction }], 'setAutocommit') return this.sequelize.query(sql, null, { transaction: transaction})
} }
QueryInterface.prototype.setIsolationLevel = function(transaction, value) { QueryInterface.prototype.setIsolationLevel = function(transaction, value) {
...@@ -759,7 +708,7 @@ module.exports = (function() { ...@@ -759,7 +708,7 @@ module.exports = (function() {
} }
var sql = this.QueryGenerator.setIsolationLevelQuery(value) var sql = this.QueryGenerator.setIsolationLevelQuery(value)
return this.queryAndEmit([sql, null, { transaction: transaction }], 'setIsolationLevel') return this.sequelize.query(sql, null, { transaction: transaction })
} }
QueryInterface.prototype.startTransaction = function(transaction, options) { QueryInterface.prototype.startTransaction = function(transaction, options) {
...@@ -772,7 +721,7 @@ module.exports = (function() { ...@@ -772,7 +721,7 @@ module.exports = (function() {
}, options || {}) }, options || {})
var sql = this.QueryGenerator.startTransactionQuery(options) var sql = this.QueryGenerator.startTransactionQuery(options)
return this.queryAndEmit([sql, null, options], 'startTransaction') return this.sequelize.query(sql, null, options)
} }
QueryInterface.prototype.commitTransaction = function(transaction, options) { QueryInterface.prototype.commitTransaction = function(transaction, options) {
...@@ -785,7 +734,7 @@ module.exports = (function() { ...@@ -785,7 +734,7 @@ module.exports = (function() {
}, options || {}) }, options || {})
var sql = this.QueryGenerator.commitTransactionQuery(options) var sql = this.QueryGenerator.commitTransactionQuery(options)
return this.queryAndEmit([sql, null, options], 'commitTransaction') return this.sequelize.query(sql, null, options)
} }
QueryInterface.prototype.rollbackTransaction = function(transaction, options) { QueryInterface.prototype.rollbackTransaction = function(transaction, options) {
...@@ -798,7 +747,7 @@ module.exports = (function() { ...@@ -798,7 +747,7 @@ module.exports = (function() {
}, options || {}) }, options || {})
var sql = this.QueryGenerator.rollbackTransactionQuery(options) var sql = this.QueryGenerator.rollbackTransactionQuery(options)
return this.queryAndEmit([sql, null, options], 'rollbackTransaction') return this.sequelize.query(sql, null, options)
} }
// private // private
......
...@@ -361,9 +361,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() { ...@@ -361,9 +361,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
Task.create({ title: 'task' }).success(function(task) { Task.create({ title: 'task' }).success(function(task) {
task.setUser(user).success(function() { task.setUser(user).success(function() {
// Should fail due to FK restriction // Should fail due to FK restriction
user.destroy().then(function () { user.destroy().catch(function(err) {
assert(false);
}, function(err) {
expect(err).to.be.ok; expect(err).to.be.ok;
Task.findAll().success(function(tasks) { Task.findAll().success(function(tasks) {
expect(tasks).to.have.length(1) expect(tasks).to.have.length(1)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!