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

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