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

Commit bb096ffb by Ruben Bridgewater

Add logging options to all querys and insert options into functions where it's missing

Reduce arguments.length lookup when not necessary

Refactor all internal .query calls to use .query(sql, options); instead of .query(sql, callee, options)

The callee is now passed to .query by using `options.instance = callee;`
1 parent e4bd7b5d
......@@ -126,7 +126,7 @@ migration.createTable(
)
```
### dropTable(tableName)
### dropTable(tableName, options)
This method allows deletion of an existing table.
......@@ -134,7 +134,7 @@ This method allows deletion of an existing table.
migration.dropTable('nameOfTheExistingTable')
```
### dropAllTables()
### dropAllTables(options)
This method allows deletion of all existing tables in the database.
......@@ -142,7 +142,7 @@ This method allows deletion of all existing tables in the database.
migration.dropAllTables()
```
### renameTable(before, after)
### renameTable(before, after, options)
This method allows renaming of an existing table.
......@@ -150,7 +150,7 @@ This method allows renaming of an existing table.
migration.renameTable('Person', 'User')
```
### showAllTables()
### showAllTables(options)
This method returns the name of all existing tables in the database.
......@@ -158,7 +158,7 @@ This method returns the name of all existing tables in the database.
migration.showAllTables().success(function(tableNames) {})
```
### describeTable(tableName)
### describeTable(tableName, options)
This method returns an array of hashes containing information about all attributes in the table.
......@@ -183,7 +183,7 @@ migration.describeTable('Person').success(function(attributes) {
})
```
### addColumn(tableName, attributeName, dataTypeOrOptions)
### addColumn(tableName, attributeName, dataTypeOrOptions, options)
This method allows adding columns to an existing table. The data type can be simple or complex.
......@@ -206,7 +206,7 @@ migration.addColumn(
)
```
### removeColumn(tableName, attributeName)
### removeColumn(tableName, attributeName, options)
This method allows deletion of a specific column of an existing table.
......@@ -214,7 +214,7 @@ This method allows deletion of a specific column of an existing table.
migration.removeColumn('Person', 'signature')
```
### changeColumn(tableName, attributeName, dataTypeOrOptions)
### changeColumn(tableName, attributeName, dataTypeOrOptions, options)
This method changes the meta data of an attribute. It is possible to change the default value, allowance of null or the data type. Please make sure, that you are completely describing the new data type. Missing information are expected to be defaults.
......@@ -238,7 +238,7 @@ migration.changeColumn(
)
```
### renameColumn(tableName, attrNameBefore, attrNameAfter)
### renameColumn(tableName, attrNameBefore, attrNameAfter, options)
This methods allows renaming attributes.
......@@ -260,6 +260,7 @@ migration.addIndex('Person', ['firstname', 'lastname'])
// - indexName: The name of the index. Default is __
// - parser: For FULLTEXT columns set your parser
// - indexType: Set a type for the index, e.g. BTREE. See the documentation of the used dialect
// - logging: A function that receives the sql query, e.g. console.log
migration.addIndex(
'Person',
['firstname', 'lastname'],
......@@ -270,7 +271,7 @@ migration.addIndex(
)
```
### removeIndex(tableName, indexNameOrAttributes)
### removeIndex(tableName, indexNameOrAttributes, options)
This method deletes an existing index of a table.
......
......@@ -415,8 +415,8 @@ module.exports = (function() {
var association = this
, primaryKeyAttribute = association.target.primaryKeyAttribute;
obj[this.accessors.set] = function(newAssociatedObjects, additionalAttributes) {
additionalAttributes = additionalAttributes || {};
obj[this.accessors.set] = function(newAssociatedObjects, options) {
options = options || {};
if (newAssociatedObjects === null) {
newAssociatedObjects = [];
......@@ -436,20 +436,20 @@ module.exports = (function() {
var instance = this;
return instance[association.accessors.get]({}, {
transaction: additionalAttributes.transaction
transaction: options.transaction,
logging: options.logging
}).then(function(oldAssociatedObjects) {
var foreignIdentifier = association.foreignIdentifier
, sourceKeys = Object.keys(association.source.primaryKeys)
, targetKeys = Object.keys(association.target.primaryKeys)
, obsoleteAssociations = []
, changedAssociations = []
, defaultAttributes = additionalAttributes
, options = additionalAttributes
, defaultAttributes = options
, promises = []
, unassociatedObjects;
// Don't try to insert the transaction as an attribute in the through table
defaultAttributes = Utils._.omit(defaultAttributes, ['transaction', 'hooks', 'individualHooks', 'ignoreDuplicates', 'validate', 'fields']);
defaultAttributes = Utils._.omit(defaultAttributes, ['transaction', 'hooks', 'individualHooks', 'ignoreDuplicates', 'validate', 'fields', 'logging']);
unassociatedObjects = newAssociatedObjects.filter(function(obj) {
return !Utils._.find(oldAssociatedObjects, function(old) {
......@@ -536,16 +536,16 @@ module.exports = (function() {
// If newInstance is null or undefined, no-op
if (!newInstance) return Utils.Promise.resolve();
var instance = this
, primaryKeyAttribute = association.target.primaryKeyAttribute;
additionalAttributes = additionalAttributes || {};
if (association.through && association.through.scope) {
Object.keys(association.through.scope).forEach(function (attribute) {
additionalAttributes[attribute] = association.through.scope[attribute];
});
}
var instance = this
, primaryKeyAttribute = association.target.primaryKeyAttribute
, options = additionalAttributes = additionalAttributes || {};
if (Array.isArray(newInstance)) {
var newInstances = newInstance.map(function(newInstance) {
if (!(newInstance instanceof association.target.Instance)) {
......@@ -563,14 +563,13 @@ module.exports = (function() {
, targetKeys = Object.keys(association.target.primaryKeys)
, obsoleteAssociations = []
, changedAssociations = []
, defaultAttributes = additionalAttributes || {}
, options = defaultAttributes
, defaultAttributes = additionalAttributes
, promises = []
, oldAssociations = []
, unassociatedObjects;
// Don't try to insert the transaction as an attribute in the through table
defaultAttributes = Utils._.omit(defaultAttributes, ['transaction', 'hooks', 'individualHooks', 'ignoreDuplicates', 'validate', 'fields']);
defaultAttributes = Utils._.omit(defaultAttributes, ['transaction', 'hooks', 'individualHooks', 'ignoreDuplicates', 'validate', 'fields', 'logging']);
unassociatedObjects = newInstances.filter(function(obj) {
return !Utils._.find(oldAssociations, function(old) {
......@@ -664,19 +663,18 @@ module.exports = (function() {
return instance[association.accessors.get]({
where: newInstance.primaryKeyValues
}, {
transaction: (additionalAttributes || {}).transaction
transaction: (additionalAttributes || {}).transaction,
logging: options.logging
}).then(function(currentAssociatedObjects) {
additionalAttributes = additionalAttributes || {};
var attributes = {}
, foreignIdentifier = association.foreignIdentifier
, options = additionalAttributes;
, foreignIdentifier = association.foreignIdentifier;
var sourceKeys = Object.keys(association.source.primaryKeys);
var targetKeys = Object.keys(association.target.primaryKeys);
// Don't try to insert the transaction as an attribute in the through table
additionalAttributes = Utils._.omit(additionalAttributes, ['transaction', 'hooks', 'individualHooks', 'ignoreDuplicates', 'validate', 'fields']);
additionalAttributes = Utils._.omit(additionalAttributes, ['transaction', 'hooks', 'individualHooks', 'ignoreDuplicates', 'validate', 'fields', 'logging']);
attributes[association.identifier] = ((sourceKeys.length === 1) ? instance[sourceKeys[0]] : instance.id);
attributes[foreignIdentifier] = ((targetKeys.length === 1) ? newInstance[targetKeys[0]] : newInstance.id);
......
......@@ -20,13 +20,17 @@ module.exports = {
@param {String} tableName The name of the table.
@param {String} attributeName The name of the attribute that we want to remove.
@param {Object} options
@param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries
@param {CustomEventEmitter} emitter The EventEmitter from outside.
@param {Function} queryAndEmit The function from outside that triggers some events to get triggered.
@since 1.6.0
*/
removeColumn: function(tableName, attributeName) {
removeColumn: function(tableName, attributeName, options) {
var self = this;
options = options || {};
return this.describeTable(tableName).then(function(fields) {
delete fields[attributeName];
......@@ -34,7 +38,7 @@ module.exports = {
, subQueries = sql.split(';').filter(function(q) { return q !== ''; });
return Promise.each(subQueries, function(subQuery) {
return self.sequelize.query(subQuery + ';', null, { raw: true});
return self.sequelize.query(subQuery + ';', { raw: true, logging: options.logging });
});
});
},
......@@ -49,14 +53,17 @@ module.exports = {
@param {String} tableName The name of the table.
@param {Object} attributes An object with the attribute's name as key and it's options as value object.
@param {Object} options
@param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries
@param {CustomEventEmitter} emitter The EventEmitter from outside.
@param {Function} queryAndEmit The function from outside that triggers some events to get triggered.
@since 1.6.0
*/
changeColumn: function(tableName, attributes) {
changeColumn: function(tableName, attributes, options) {
var attributeName = Utils._.keys(attributes)[0]
, self = this;
options = options || {};
return this.describeTable(tableName).then(function(fields) {
fields[attributeName] = attributes[attributeName];
......@@ -65,7 +72,7 @@ module.exports = {
, subQueries = sql.split(';').filter(function(q) { return q !== ''; });
return Promise.each(subQueries, function(subQuery) {
return self.sequelize.query(subQuery + ';', null, { raw: true});
return self.sequelize.query(subQuery + ';', { raw: true, logging: options.logging });
});
});
},
......@@ -81,13 +88,17 @@ module.exports = {
@param {String} tableName The name of the table.
@param {String} attrNameBefore The name of the attribute before it was renamed.
@param {String} attrNameAfter The name of the attribute after it was renamed.
@param {Object} options
@param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries
@param {CustomEventEmitter} emitter The EventEmitter from outside.
@param {Function} queryAndEmit The function from outside that triggers some events to get triggered.
@since 1.6.0
*/
renameColumn: function(tableName, attrNameBefore, attrNameAfter) {
renameColumn: function(tableName, attrNameBefore, attrNameAfter, options) {
var self = this;
options = options || {};
return this.describeTable(tableName).then(function(fields) {
fields[attrNameAfter] = Utils._.clone(fields[attrNameBefore]);
delete fields[attrNameBefore];
......@@ -96,7 +107,7 @@ module.exports = {
, subQueries = sql.split(';').filter(function(q) { return q !== ''; });
return Promise.each(subQueries, function(subQuery) {
return self.sequelize.query(subQuery + ';', null, { raw: true});
return self.sequelize.query(subQuery + ';', { raw: true, logging: options.logging });
});
});
}
......
......@@ -537,7 +537,7 @@ module.exports = (function() {
self.scoped = true;
// Set defaults
scopeOptions = (typeof lastArg === 'object' && !Array.isArray(lastArg) && lastArg !== null ? lastArg : {}) || {}; // <-- for no arguments
scopeOptions = typeof lastArg === 'object' && !Array.isArray(lastArg) && lastArg || {};
scopeOptions.silent = (scopeOptions !== null && scopeOptions.hasOwnProperty('silent') ? scopeOptions.silent : true);
// Clear out any predefined scopes...
......
......@@ -18,24 +18,27 @@ module.exports = (function() {
this.QueryGenerator = this.sequelize.dialect.QueryGenerator;
};
QueryInterface.prototype.createSchema = function(schema) {
QueryInterface.prototype.createSchema = function(schema, options) {
options = options || {};
var sql = this.QueryGenerator.createSchema(schema);
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
};
QueryInterface.prototype.dropSchema = function(schema) {
QueryInterface.prototype.dropSchema = function(schema, options) {
options = options || {};
var sql = this.QueryGenerator.dropSchema(schema);
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
};
QueryInterface.prototype.dropAllSchemas = function() {
var self = this;
QueryInterface.prototype.dropAllSchemas = function(options) {
options = options || {};
var self = this;
if (!this.QueryGenerator._dialect.supports.schemas) {
return this.sequelize.drop();
return this.sequelize.drop({ logging: options.logging });
} else {
return this.showAllSchemas().map(function(schemaName) {
return self.dropSchema(schemaName);
return this.showAllSchemas(options).map(function(schemaName) {
return self.dropSchema(schemaName, { logging: options.logging });
});
}
};
......@@ -45,12 +48,13 @@ module.exports = (function() {
options = Utils._.extend({
raw: true,
type: this.sequelize.QueryTypes.SELECT
type: this.sequelize.QueryTypes.SELECT,
logging: false
}, options || {});
var showSchemasSql = self.QueryGenerator.showSchemasQuery();
return this.sequelize.query(showSchemasSql, undefined, options).then(function(schemaNames) {
return this.sequelize.query(showSchemasSql, options).then(function(schemaNames) {
return Utils._.flatten(
Utils._.map(schemaNames, function(value) {
return (!!value.schema_name ? value.schema_name : value);
......@@ -59,10 +63,12 @@ module.exports = (function() {
});
};
QueryInterface.prototype.databaseVersion = function() {
return this.sequelize.query(this.QueryGenerator.versionQuery(), null, {
QueryInterface.prototype.databaseVersion = function(options) {
options = options || {};
return this.sequelize.query(this.QueryGenerator.versionQuery(), {
raw: true,
type: QueryTypes.VERSION
type: QueryTypes.VERSION,
logging: options.logging
});
};
......@@ -73,6 +79,8 @@ module.exports = (function() {
, sql = ''
, i = 0;
options = options || {};
attributes = Utils._.mapValues(attributes, function(attribute) {
if (!Utils._.isPlainObject(attribute)) {
attribute = { type: attribute, allowNull: true };
......@@ -102,10 +110,6 @@ module.exports = (function() {
return attribute;
});
options = Utils._.extend({
logging: this.sequelize.options.logging,
}, options || {});
// Postgres requires a special SQL command for enums
if (self.sequelize.options.dialect === 'postgres') {
var promises = []
......@@ -116,7 +120,7 @@ module.exports = (function() {
for (i = 0; i < keyLen; i++) {
if (attributes[keys[i]].type instanceof DataTypes.ENUM) {
sql = self.QueryGenerator.pgListEnums(getTableName, attributes[keys[i]].field || keys[i], options);
promises.push(self.sequelize.query(sql, null, { plain: true, raw: true, type: QueryTypes.SELECT, logging: options.logging }));
promises.push(self.sequelize.query(sql, { plain: true, raw: true, type: QueryTypes.SELECT, logging: options.logging }));
}
}
......@@ -133,7 +137,7 @@ module.exports = (function() {
// If the enum type doesn't exist then create it
if (!results[enumIdx]) {
sql = self.QueryGenerator.pgEnum(getTableName, attributes[keys[i]].field || keys[i], attributes[keys[i]], options);
promises.push(self.sequelize.query(sql, null, { raw: true, logging: options.logging }));
promises.push(self.sequelize.query(sql, { raw: true, logging: options.logging }));
} else if (!!results[enumIdx] && !!daoTable) {
var enumVals = self.QueryGenerator.fromArray(results[enumIdx].enum_value)
, vals = daoTable.rawAttributes[keys[i]].values;
......@@ -150,7 +154,7 @@ module.exports = (function() {
else if (!!vals[idx - 1]) {
options.after = vals[idx - 1];
}
promises.push(self.sequelize.query(self.QueryGenerator.pgEnumAdd(getTableName, keys[i], value, options), undefined, options));
promises.push(self.sequelize.query(self.QueryGenerator.pgEnumAdd(getTableName, keys[i], value, options), options));
}
});
enumIdx++;
......@@ -171,7 +175,7 @@ module.exports = (function() {
sql = self.QueryGenerator.createTableQuery(tableName, attributes, options);
return Promise.all(promises).then(function() {
return self.sequelize.query(sql, null, options);
return self.sequelize.query(sql, options);
});
});
} else {
......@@ -187,7 +191,7 @@ module.exports = (function() {
});
sql = self.QueryGenerator.createTableQuery(tableName, attributes, options);
return self.sequelize.query(sql, null, options);
return self.sequelize.query(sql, options);
}
};
......@@ -199,7 +203,7 @@ module.exports = (function() {
var sql = this.QueryGenerator.dropTableQuery(tableName, options)
, self = this;
return this.sequelize.query(sql, null, options).then(function() {
return this.sequelize.query(sql, options).then(function() {
var promises = [];
// Since postgres has a special case for enums, we should drop the related
......@@ -217,7 +221,7 @@ module.exports = (function() {
for (i = 0; i < keyLen; i++) {
if (daoTable.rawAttributes[keys[i]].type instanceof DataTypes.ENUM) {
promises.push(self.sequelize.query(self.QueryGenerator.pgEnumDrop(getTableName, keys[i]), null, {logging: options.logging, raw: true}));
promises.push(self.sequelize.query(self.QueryGenerator.pgEnumDrop(getTableName, keys[i]), {logging: options.logging, raw: true}));
}
}
}
......@@ -236,7 +240,7 @@ module.exports = (function() {
return Promise.each(tableNames, function(tableName) {
// if tableName is not in the Array of tables names then dont drop it
if (skip.indexOf(tableName.tableName || tableName) === -1) {
return self.dropTable(tableName, { cascade: true });
return self.dropTable(tableName, { cascade: true, logging: options.logging });
}
});
};
......@@ -244,13 +248,13 @@ module.exports = (function() {
var skip = options.skip || [];
return self.showAllTables().then(function(tableNames) {
if (self.sequelize.options.dialect === 'sqlite') {
return self.sequelize.query('PRAGMA foreign_keys;', undefined, options).then(function(result) {
return self.sequelize.query('PRAGMA foreign_keys;', options).then(function(result) {
var foreignKeysAreEnabled = result.foreign_keys === 1;
if (foreignKeysAreEnabled) {
return self.sequelize.query('PRAGMA foreign_keys = OFF', undefined, options).then(function() {
return self.sequelize.query('PRAGMA foreign_keys = OFF', options).then(function() {
return dropAllTables(tableNames).then(function() {
return self.sequelize.query('PRAGMA foreign_keys = ON', undefined, options);
return self.sequelize.query('PRAGMA foreign_keys = ON', options);
});
});
} else {
......@@ -269,7 +273,7 @@ module.exports = (function() {
foreignKeys[normalizedTableName].forEach(function(foreignKey) {
var sql = self.QueryGenerator.dropForeignKeyQuery(tableName, foreignKey);
promises.push(self.sequelize.query(sql, undefined, options));
promises.push(self.sequelize.query(sql, options));
});
});
......@@ -291,18 +295,18 @@ module.exports = (function() {
var self = this
, sql = this.QueryGenerator.pgListEnums();
return this.sequelize.query(sql, null, { plain: false, raw: true, type: QueryTypes.SELECT, logging: options.logging }).map(function(result) {
return this.sequelize.query(sql, { plain: false, raw: true, type: QueryTypes.SELECT, logging: options.logging }).map(function(result) {
return self.sequelize.query(
self.QueryGenerator.pgEnumDrop(null, null, self.QueryGenerator.pgEscapeAndQuote(result.enum_name)),
null,
{logging: options.logging, raw: true}
);
});
};
QueryInterface.prototype.renameTable = function(before, after) {
QueryInterface.prototype.renameTable = function(before, after, options) {
options = options || {};
var sql = this.QueryGenerator.renameTableQuery(before, after);
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, { logging: options.logging });
};
QueryInterface.prototype.showAllTables = function(options) {
......@@ -313,7 +317,7 @@ module.exports = (function() {
}, options || {});
var showTablesSql = self.QueryGenerator.showTablesQuery();
return self.sequelize.query(showTablesSql, null, options).then(function(tableNames) {
return self.sequelize.query(showTablesSql, options).then(function(tableNames) {
return Utils._.flatten(tableNames);
});
};
......@@ -336,7 +340,7 @@ module.exports = (function() {
var sql = this.QueryGenerator.describeTableQuery(tableName, schema, schemaDelimiter);
return this.sequelize.query(sql, undefined, { type: QueryTypes.DESCRIBE, logging: options && options.logging }).then(function(data) {
return this.sequelize.query(sql, { type: QueryTypes.DESCRIBE, logging: options && options.logging }).then(function(data) {
// If no data is returned from the query, then the table name may be wrong.
// Query generators that use information_schema for retrieving table info will just return an empty result set,
// it will not throw an error like built-ins do (e.g. DESCRIBE on MySql).
......@@ -348,23 +352,26 @@ module.exports = (function() {
});
};
QueryInterface.prototype.addColumn = function(table, key, attribute) {
QueryInterface.prototype.addColumn = function(table, key, attribute, options) {
options = options || {};
attribute = this.sequelize.normalizeAttribute(attribute);
return this.sequelize.query(this.QueryGenerator.addColumnQuery(table, key, attribute), null, {logging: this.sequelize.options.logging});
return this.sequelize.query(this.QueryGenerator.addColumnQuery(table, key, attribute), { logging: options.logging });
};
QueryInterface.prototype.removeColumn = function(tableName, attributeName) {
QueryInterface.prototype.removeColumn = function(tableName, attributeName, options) {
options = options || {};
if (this.sequelize.options.dialect === 'sqlite') {
// sqlite needs some special treatment as it cannot drop a column
return SQLiteQueryInterface.removeColumn.call(this, tableName, attributeName);
return SQLiteQueryInterface.removeColumn.call(this, tableName, attributeName, {logging: options.logging});
} else {
var sql = this.QueryGenerator.removeColumnQuery(tableName, attributeName);
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
}
};
QueryInterface.prototype.changeColumn = function(tableName, attributeName, dataTypeOrOptions) {
QueryInterface.prototype.changeColumn = function(tableName, attributeName, dataTypeOrOptions, options) {
var attributes = {};
options = options || {};
if (Utils._.values(DataTypes).indexOf(dataTypeOrOptions) > -1) {
attributes[attributeName] = { type: dataTypeOrOptions, allowNull: true };
......@@ -376,22 +383,23 @@ module.exports = (function() {
if (this.sequelize.options.dialect === 'sqlite') {
// sqlite needs some special treatment as it cannot change a column
return SQLiteQueryInterface.changeColumn.call(this, tableName, attributes);
return SQLiteQueryInterface.changeColumn.call(this, tableName, attributes, {logging: options.logging});
} else {
var options = this.QueryGenerator.attributesToSQL(attributes)
, sql = this.QueryGenerator.changeColumnQuery(tableName, options);
var query = this.QueryGenerator.attributesToSQL(attributes)
, sql = this.QueryGenerator.changeColumnQuery(tableName, query);
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
}
};
QueryInterface.prototype.renameColumn = function(tableName, attrNameBefore, attrNameAfter) {
return this.describeTable(tableName).then(function(data) {
QueryInterface.prototype.renameColumn = function(tableName, attrNameBefore, attrNameAfter, options) {
options = options || {};
return this.describeTable(tableName, options).then(function(data) {
data = data[attrNameBefore] || {};
var options = {};
var _options = {};
options[attrNameAfter] = {
_options[attrNameAfter] = {
attribute: attrNameAfter,
type: data.type,
allowNull: data.allowNull,
......@@ -400,30 +408,29 @@ module.exports = (function() {
// fix: a not-null column cannot have null as default value
if (data.defaultValue === null && !data.allowNull) {
delete options[attrNameAfter].defaultValue;
delete _options[attrNameAfter].defaultValue;
}
if (this.sequelize.options.dialect === 'sqlite') {
// sqlite needs some special treatment as it cannot rename a column
return SQLiteQueryInterface.renameColumn.call(this, tableName, attrNameBefore, attrNameAfter);
return SQLiteQueryInterface.renameColumn.call(this, tableName, attrNameBefore, attrNameAfter, {logging: options.logging});
} else {
var sql = this.QueryGenerator.renameColumnQuery(
tableName,
attrNameBefore,
this.QueryGenerator.attributesToSQL(options)
this.QueryGenerator.attributesToSQL(_options)
);
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
}
}.bind(this));
};
QueryInterface.prototype.addIndex = function(tableName, _attributes, _options, _rawTablename) {
var attributes, options, rawTablename;
QueryInterface.prototype.addIndex = function(tableName, _attributes, options, _rawTablename) {
var attributes, rawTablename;
// Support for passing tableName, attributes, options or tableName, options (with a fields param which is the attributes)
if (Array.isArray(_attributes)) {
attributes = _attributes;
options = _options;
rawTablename = _rawTablename;
} else {
......@@ -431,7 +438,7 @@ module.exports = (function() {
options = _attributes;
attributes = options.fields;
rawTablename = _options;
rawTablename = options;
}
if (!rawTablename) {
......@@ -442,14 +449,14 @@ module.exports = (function() {
options = options || {};
options.fields = attributes;
var sql = this.QueryGenerator.addIndexQuery(tableName, options, rawTablename);
return this.sequelize.query(sql, null, {logging: options.hasOwnProperty('logging') ? options.logging : this.sequelize.options.logging});
return this.sequelize.query(sql, { logging: options.logging });
};
QueryInterface.prototype.showIndex = function(tableName, options) {
var sql = this.QueryGenerator.showIndexesQuery(tableName, options);
options = options || {};
return this.sequelize.query(sql, null, {
logging: options.hasOwnProperty('logging') ? options.logging : this.sequelize.options.logging,
return this.sequelize.query(sql, {
logging: options.logging,
type: QueryTypes.SHOWINDEXES
});
};
......@@ -458,15 +465,16 @@ module.exports = (function() {
return this.QueryGenerator.nameIndexes(indexes, rawTablename);
};
QueryInterface.prototype.getForeignKeysForTables = function(tableNames) {
QueryInterface.prototype.getForeignKeysForTables = function(tableNames, options) {
var self = this;
options = options || {};
if (tableNames.length === 0) {
return Promise.resolve({});
}
return Promise.map(tableNames, function(tableName) {
return self.sequelize.query(self.QueryGenerator.getForeignKeysQuery(tableName, self.sequelize.config.database)).get(0);
return self.sequelize.query(self.QueryGenerator.getForeignKeysQuery(tableName, self.sequelize.config.database), {logging: options.logging}).get(0);
}).then(function(results) {
var result = {};
......@@ -484,16 +492,18 @@ module.exports = (function() {
});
};
QueryInterface.prototype.removeIndex = function(tableName, indexNameOrAttributes) {
QueryInterface.prototype.removeIndex = function(tableName, indexNameOrAttributes, options) {
options = options || {};
var sql = this.QueryGenerator.removeIndexQuery(tableName, indexNameOrAttributes);
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
};
QueryInterface.prototype.insert = function(dao, tableName, values, options) {
var sql = this.QueryGenerator.insertQuery(tableName, values, dao && dao.Model.rawAttributes, options);
options.type = QueryTypes.INSERT;
return this.sequelize.query(sql, dao, options).then(function(result) {
options.instance = dao;
return this.sequelize.query(sql, options).then(function(result) {
if (dao) result.isNewRecord = false;
return result;
});
......@@ -563,7 +573,7 @@ module.exports = (function() {
}
var sql = this.QueryGenerator.upsertQuery(tableName, values, updateValues, where, model.rawAttributes, options);
return this.sequelize.query(sql, null, options).then(function (rowCount) {
return this.sequelize.query(sql, options).then(function (rowCount) {
if (rowCount === undefined) {
return rowCount;
}
......@@ -577,7 +587,7 @@ module.exports = (function() {
QueryInterface.prototype.bulkInsert = function(tableName, records, options, attributes) {
options.type = QueryTypes.INSERT;
var sql = this.QueryGenerator.bulkInsertQuery(tableName, records, options, attributes);
return this.sequelize.query(sql, null, options);
return this.sequelize.query(sql, options);
};
QueryInterface.prototype.update = function(dao, tableName, values, identifier, options) {
......@@ -600,7 +610,8 @@ module.exports = (function() {
}
}
return this.sequelize.query(sql, dao, options);
options.instance = dao;
return this.sequelize.query(sql, options);
};
QueryInterface.prototype.bulkUpdate = function(tableName, values, identifier, options, attributes) {
......@@ -608,8 +619,10 @@ module.exports = (function() {
, table = Utils._.isObject(tableName) ? tableName : { tableName: tableName }
, daoTable = Utils._.find(this.sequelize.daoFactoryManager.daos, { tableName: table.tableName });
options = options || {};
daoTable.__options = daoTable.options;
return this.sequelize.query(sql, daoTable, options);
options.instance = daoTable;
return this.sequelize.query(sql, options);
};
QueryInterface.prototype.delete = function(dao, tableName, identifier, options) {
......@@ -617,6 +630,8 @@ module.exports = (function() {
, cascades = []
, sql = self.QueryGenerator.deleteQuery(tableName, identifier, null, dao.Model);
options = options || {};
// Check for a restrict field
if (!!dao.Model && !!dao.Model.associations) {
var keys = Object.keys(dao.Model.associations)
......@@ -633,24 +648,27 @@ module.exports = (function() {
return Promise.each(cascades, function (cascade) {
return dao[cascade]({
transaction: options.transaction
transaction: options.transaction,
logging: options.logging
}).then(function (instances) {
if (!Array.isArray(instances)) instances = [instances];
return Promise.each(instances, function (instance) {
return instance.destroy({
transaction: options.transaction
transaction: options.transaction,
logging: options.logging
});
});
});
}).then(function () {
return self.sequelize.query(sql, dao, options);
options.instance = dao;
return self.sequelize.query(sql, options);
});
};
QueryInterface.prototype.bulkDelete = function(tableName, identifier, options, model) {
var sql = this.QueryGenerator.deleteQuery(tableName, identifier, Utils._.defaults(options || {}, {limit: null}), model);
return this.sequelize.query(sql, null, options);
return this.sequelize.query(sql, options);
};
QueryInterface.prototype.select = function(model, tableName, options, queryOptions) {
......@@ -678,9 +696,9 @@ module.exports = (function() {
});
}
options.instance = model;
return this.sequelize.query(
this.QueryGenerator.selectQuery(tableName, options, model),
model,
options
);
};
......@@ -688,8 +706,11 @@ module.exports = (function() {
QueryInterface.prototype.increment = function(dao, tableName, values, identifier, options) {
var sql = this.QueryGenerator.incrementQuery(tableName, values, identifier, options.attributes);
options = options || {};
options.type = QueryTypes.RAW;
return this.sequelize.query(sql, dao, options);
options.instance = dao;
return this.sequelize.query(sql, options);
};
QueryInterface.prototype.rawSelect = function(tableName, options, attributeSelector, Model) {
......@@ -709,7 +730,7 @@ module.exports = (function() {
throw new Error('Please pass an attribute selector!');
}
return this.sequelize.query(sql, null, queryOptions).then(function(data) {
return this.sequelize.query(sql, queryOptions).then(function(data) {
if (!queryOptions.plain) {
return data;
}
......@@ -736,30 +757,33 @@ module.exports = (function() {
});
};
QueryInterface.prototype.createTrigger = function(tableName, triggerName, timingType, fireOnArray,
functionName, functionParams, optionsArray) {
var sql = this.QueryGenerator.createTrigger(tableName, triggerName, timingType, fireOnArray, functionName
, functionParams, optionsArray);
QueryInterface.prototype.createTrigger = function(tableName, triggerName, timingType, fireOnArray, functionName, functionParams, optionsArray, options) {
var sql = this.QueryGenerator.createTrigger(tableName, triggerName, timingType, fireOnArray, functionName, functionParams, optionsArray);
options = options || {};
if (sql) {
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
} else {
return Promise.resolve();
}
};
QueryInterface.prototype.dropTrigger = function(tableName, triggerName) {
QueryInterface.prototype.dropTrigger = function(tableName, triggerName, options) {
var sql = this.QueryGenerator.dropTrigger(tableName, triggerName);
options = options || {};
if (sql) {
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
} else {
return Promise.resolve();
}
};
QueryInterface.prototype.renameTrigger = function(tableName, oldTriggerName, newTriggerName) {
QueryInterface.prototype.renameTrigger = function(tableName, oldTriggerName, newTriggerName, options) {
var sql = this.QueryGenerator.renameTrigger(tableName, oldTriggerName, newTriggerName);
options = options || {};
if (sql) {
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
} else {
return Promise.resolve();
}
......@@ -767,26 +791,32 @@ module.exports = (function() {
QueryInterface.prototype.createFunction = function(functionName, params, returnType, language, body, options) {
var sql = this.QueryGenerator.createFunction(functionName, params, returnType, language, body, options);
options = options || {};
if (sql) {
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
} else {
return Promise.resolve();
}
};
QueryInterface.prototype.dropFunction = function(functionName, params) {
QueryInterface.prototype.dropFunction = function(functionName, params, options) {
var sql = this.QueryGenerator.dropFunction(functionName, params);
options = options || {};
if (sql) {
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
} else {
return Promise.resolve();
}
};
QueryInterface.prototype.renameFunction = function(oldFunctionName, params, newFunctionName) {
QueryInterface.prototype.renameFunction = function(oldFunctionName, params, newFunctionName, options) {
var sql = this.QueryGenerator.renameFunction(oldFunctionName, params, newFunctionName);
options = options || {};
if (sql) {
return this.sequelize.query(sql, null, {logging: this.sequelize.options.logging});
return this.sequelize.query(sql, {logging: options.logging});
} else {
return Promise.resolve();
}
......@@ -834,7 +864,7 @@ module.exports = (function() {
var sql = this.QueryGenerator.setAutocommitQuery(value, options);
if (sql) {
return this.sequelize.query(sql, null, { transaction: transaction, logging: options.logging });
return this.sequelize.query(sql, { transaction: transaction, logging: options.logging });
} else {
return Promise.resolve();
}
......@@ -852,7 +882,7 @@ module.exports = (function() {
var sql = this.QueryGenerator.setIsolationLevelQuery(value, options);
if (sql) {
return this.sequelize.query(sql, null, { transaction: transaction, logging: options.logging });
return this.sequelize.query(sql, { transaction: transaction, logging: options.logging });
} else {
return Promise.resolve();
}
......@@ -869,7 +899,7 @@ module.exports = (function() {
}, options || {});
var sql = this.QueryGenerator.startTransactionQuery(transaction, options);
return this.sequelize.query(sql, null, options);
return this.sequelize.query(sql, options);
};
QueryInterface.prototype.commitTransaction = function(transaction, options) {
......@@ -885,7 +915,7 @@ module.exports = (function() {
var sql = this.QueryGenerator.commitTransactionQuery(options);
if (sql) {
return this.sequelize.query(sql, null, options);
return this.sequelize.query(sql, options);
} else {
return Promise.resolve();
}
......@@ -902,7 +932,7 @@ module.exports = (function() {
}, options || {});
var sql = this.QueryGenerator.rollbackTransactionQuery(transaction, options);
return this.sequelize.query(sql, null, options);
return this.sequelize.query(sql, options);
};
// private
......
......@@ -667,19 +667,17 @@ module.exports = (function() {
*/
Sequelize.prototype.query = function(sql, callee, options, replacements) {
var self = this;
if (arguments.length === 4) {
deprecated('passing raw query replacements as the 4th argument to sequelize.query is deprecated. Please use options.replacements instead');
options.replacements = replacements;
} else if (arguments.length === 3) {
options = options;
} else if (arguments.length === 2) {
if (arguments.length === 2) {
if (callee instanceof Sequelize.Model) {
options = {};
} else {
options = callee;
callee = undefined;
callee = options.instance || undefined;
}
} else {
} else if (arguments.length === 4) {
deprecated('passing raw query replacements as the 4th argument to sequelize.query is deprecated. Please use options.replacements instead');
options.replacements = replacements;
} else if (arguments.length !== 3) {
options = { raw: true };
}
......@@ -789,7 +787,7 @@ module.exports = (function() {
return '@'+k +' := '+ ( typeof v === 'string' ? '"'+v+'"' : v );
}).join(', ');
return this.query(query, null, options);
return this.query(query, options);
};
/**
......@@ -810,10 +808,12 @@ module.exports = (function() {
*
* @see {Model#schema}
* @param {String} schema Name of the schema
* @param {Object} options={}
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
* @return {Promise}
*/
Sequelize.prototype.createSchema = function(schema) {
return this.getQueryInterface().createSchema(schema);
Sequelize.prototype.createSchema = function(schema, options) {
return this.getQueryInterface().createSchema(schema, options);
};
/**
......@@ -821,10 +821,12 @@ module.exports = (function() {
*
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* not a database table. In mysql and sqlite, this will show all tables.
* @param {Object} options={}
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
* @return {Promise}
*/
Sequelize.prototype.showAllSchemas = function() {
return this.getQueryInterface().showAllSchemas();
Sequelize.prototype.showAllSchemas = function(options) {
return this.getQueryInterface().showAllSchemas(options);
};
/**
......@@ -833,10 +835,12 @@ module.exports = (function() {
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* not a database table. In mysql and sqlite, this drop a table matching the schema name
* @param {String} schema Name of the schema
* @param {Object} options={}
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
* @return {Promise}
*/
Sequelize.prototype.dropSchema = function(schema) {
return this.getQueryInterface().dropSchema(schema);
Sequelize.prototype.dropSchema = function(schema, options) {
return this.getQueryInterface().dropSchema(schema, options);
};
/**
......@@ -844,10 +848,12 @@ module.exports = (function() {
*
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* not a database table. In mysql and sqlite, this is the equivalent of drop all tables.
* @param {Object} options={}
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
* @return {Promise}
*/
Sequelize.prototype.dropAllSchemas = function() {
return this.getQueryInterface().dropAllSchemas();
Sequelize.prototype.dropAllSchemas = function(options) {
return this.getQueryInterface().dropAllSchemas(options);
};
/**
......@@ -903,6 +909,7 @@ module.exports = (function() {
* @see {Model#drop} for options
*
* @param {object} options The options passed to each call to Model.drop
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
* @return {Promise}
*/
Sequelize.prototype.drop = function(options) {
......@@ -928,13 +935,13 @@ module.exports = (function() {
* @return {Promise}
*/
Sequelize.prototype.authenticate = function() {
return this.query('SELECT 1+1 AS result', null, { raw: true, plain: true }).return().catch(function(err) {
return this.query('SELECT 1+1 AS result', { raw: true, plain: true }).return().catch(function(err) {
throw new Error(err);
});
};
Sequelize.prototype.databaseVersion = function() {
return this.queryInterface.databaseVersion();
Sequelize.prototype.databaseVersion = function(options) {
return this.queryInterface.databaseVersion(options);
};
Sequelize.prototype.validate = Sequelize.prototype.authenticate;
......
......@@ -874,7 +874,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
logging: spy
});
}).then(function() {
expect(spy.calledOnce).to.be.ok;
expect(spy.calledTwice).to.be.ok;
});
});
......@@ -892,7 +892,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
logging: spy
});
}).then(function() {
expect(spy.calledOnce).to.be.ok;
expect(spy.calledTwice).to.be.ok;
});
});
}); // end optimization using bulk create, destroy and update
......@@ -1070,6 +1070,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
it('should correctly get associations even after a child instance is deleted', function() {
var self = this;
var spy = sinon.spy();
return this.sequelize.sync({force: true}).then(function() {
return Promise.join(
......@@ -1078,13 +1079,20 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
self.Project.create({name: 'The Departed'})
);
}).spread(function(user, project1, project2) {
return user.addProjects([project1, project2]).return (user);
return user.addProjects([project1, project2], {
logging: spy
}).return (user);
}).then(function(user) {
expect(spy.calledOnce).to.be.ok;
spy.reset();
return Promise.join(
user,
user.getProjects()
user.getProjects({
logging: spy
})
);
}).spread(function(user, projects) {
expect(spy.calledOnce).to.be.ok;
var project = projects[0];
expect(project).to.be.ok;
return project.destroy().return (user);
......@@ -1112,15 +1120,24 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), function() {
}).spread(function(user, project) {
self.user = user;
self.project = project;
return user.addProject(project).return (user);
return user.addProject(project, { logging: spy }).return (user);
}).then(function(user) {
return user.getProjects();
expect(spy.calledTwice).to.be.ok; // Once for SELECT, once for INSERT
spy.reset();
return user.getProjects({
logging: spy
});
}).then(function(projects) {
var project = projects[0];
expect(spy.calledOnce).to.be.ok;
spy.reset();
expect(project).to.be.ok;
return self.user.removeProject(project, {
logging: spy
logging: function(sql) {
console.error(sql);
spy();
}
}).return (project);
}).then(function(project) {
expect(spy.calledTwice).to.be.ok; // Once for SELECT, once for REMOVE
......
......@@ -6,7 +6,14 @@ var chai = require('chai')
, Support = require(__dirname + '/support')
, DataTypes = require(__dirname + '/../../lib/data-types')
, dialect = Support.getTestDialect()
, _ = require('lodash');
, _ = require('lodash')
, count = 0
, log = function (sql) {
// sqlite fires a lot more querys than the other dbs. this is just a simple hack, since i'm lazy
if (dialect !== 'sqlite' || count === 0) {
count++;
}
};
chai.config.includeStack = true;
......@@ -20,12 +27,22 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
it('should drop all tables', function() {
var self = this;
return this.queryInterface.dropAllTables().then(function() {
return self.queryInterface.showAllTables().then(function(tableNames) {
return self.queryInterface.showAllTables({logging: log}).then(function(tableNames) {
expect(count).to.be.equal(1);
count = 0;
expect(tableNames).to.be.empty;
return self.queryInterface.createTable('table', { name: DataTypes.STRING }).then(function() {
return self.queryInterface.showAllTables().then(function(tableNames) {
return self.queryInterface.createTable('table', { name: DataTypes.STRING }, {
logging: log
}).then(function() {
expect(count).to.be.equal(1);
count = 0;
return self.queryInterface.showAllTables({logging: log}).then(function(tableNames) {
expect(count).to.be.equal(1);
count = 0;
expect(tableNames).to.have.length(1);
return self.queryInterface.dropAllTables().then(function() {
return self.queryInterface.dropAllTables({logging: log}).then(function() {
expect(count).to.be.equal(1);
count = 0;
return self.queryInterface.showAllTables().then(function(tableNames) {
expect(tableNames).to.be.empty;
});
......@@ -56,7 +73,9 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
describe('indexes', function() {
beforeEach(function() {
var self = this;
return this.queryInterface.dropTable('Group').then(function() {
return this.queryInterface.dropTable('Group', {logging: log}).then(function() {
expect(count).to.be.equal(1);
count = 0;
return self.queryInterface.createTable('Group', {
username: DataTypes.STRING,
isAdmin: DataTypes.BOOLEAN,
......@@ -67,11 +86,20 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
it('adds, reads and removes an index to the table', function() {
var self = this;
return this.queryInterface.addIndex('Group', ['username', 'isAdmin']).then(function() {
return self.queryInterface.showIndex('Group').then(function(indexes) {
return this.queryInterface.addIndex('Group', ['username', 'isAdmin'], {
logging: log
}).then(function() {
expect(count).to.be.equal(1);
count = 0;
return self.queryInterface.showIndex('Group', {logging: log}).then(function(indexes) {
expect(count).to.be.equal(1);
count = 0;
var indexColumns = _.uniq(indexes.map(function(index) { return index.name; }));
expect(indexColumns).to.include('group_username_is_admin');
return self.queryInterface.removeIndex('Group', ['username', 'isAdmin']).then(function() {
return self.queryInterface.removeIndex('Group', ['username', 'isAdmin'], {logging: log}).then(function() {
expect(count).to.be.equal(1);
count = 0;
return self.queryInterface.showIndex('Group').then(function(indexes) {
indexColumns = _.uniq(indexes.map(function(index) { return index.name; }));
expect(indexColumns).to.be.empty;
......@@ -96,7 +124,10 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}, { freezeTableName: true });
return Users.sync({ force: true }).then(function() {
return self.queryInterface.describeTable('_Users').then(function(metadata) {
return self.queryInterface.describeTable('_Users', {logging: log}).then(function(metadata) {
expect(count).to.be.equal(1);
count = 0;
var username = metadata.username;
var isAdmin = metadata.isAdmin;
var enumVals = metadata.enumVals;
......@@ -179,9 +210,16 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
it('should work with schemas', function() {
var self = this;
return self.sequelize.dropAllSchemas().then(function() {
return self.sequelize.createSchema('hero');
return self.sequelize.dropAllSchemas({logging: log}).then(function() {
// TODO: FIXME: somehow these do not fire the logging function
if (dialect !== 'mysql' && dialect !== 'sqlite' && dialect !== 'mariadb') {
expect(count).to.be.above(0);
}
count = 0;
return self.sequelize.createSchema('hero', {logging: log});
}).then(function() {
expect(count).to.be.equal(1);
count = 0;
return self.queryInterface.createTable('User', {
name: {
type: DataTypes.STRING
......@@ -191,8 +229,12 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
});
}).then(function() {
return self.queryInterface.rawSelect('User', {
schema: 'hero'
schema: 'hero',
logging: log
}, 'name');
}).then(function() {
expect(count).to.be.equal(1);
count = 0;
});
});
});
......@@ -205,7 +247,12 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}, { freezeTableName: true });
return Users.sync({ force: true }).then(function() {
return self.queryInterface.renameColumn('_Users', 'username', 'pseudo');
return self.queryInterface.renameColumn('_Users', 'username', 'pseudo', {logging: log}).then(function() {
if (dialect === 'sqlite')
count++;
expect(count).to.be.equal(2);
count = 0;
});
});
});
......@@ -297,6 +344,11 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
schema: 'archive'
}, 'currency', {
type: DataTypes.FLOAT
}, {
logging: log
}).then(function() {
expect(count).to.be.equal(1);
count = 0;
});
});
});
......@@ -328,7 +380,10 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
referenceKey: 'id',
onUpdate: 'cascade',
onDelete: 'set null'
});
}, {logging: log});
}).then(function() {
expect(count).to.be.equal(1);
count = 0;
});
});
......@@ -404,8 +459,10 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
it('should get a list of foreign keys for the table', function() {
var sql = this.queryInterface.QueryGenerator.getForeignKeysQuery('hosts', this.sequelize.config.database);
return this.sequelize.query(sql, {type: this.sequelize.QueryTypes.FOREIGNKEYS}).then(function(fks) {
return this.sequelize.query(sql, {type: this.sequelize.QueryTypes.FOREIGNKEYS, logging: log}).then(function(fks) {
expect(count).to.be.equal(1);
expect(fks).to.have.length(3);
count = 0;
var keys = Object.keys(fks[0]),
keys2 = Object.keys(fks[1]),
keys3 = Object.keys(fks[2]);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!