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

Commit 4bae4b83 by Trey Thomas

Switch to clearer _.assign syntax for query options

1 parent b0a1615c
Showing with 24 additions and 23 deletions
......@@ -45,11 +45,11 @@ QueryInterface.prototype.dropAllSchemas = function(options) {
QueryInterface.prototype.showAllSchemas = function(options) {
var self = this;
options = _.assign({
options = _.assign({}, options, {
raw: true,
type: this.sequelize.QueryTypes.SELECT,
logging: false
}, options || {});
});
var showSchemasSql = self.QueryGenerator.showSchemasQuery();
......@@ -63,9 +63,10 @@ QueryInterface.prototype.showAllSchemas = function(options) {
};
QueryInterface.prototype.databaseVersion = function(options) {
return this.sequelize.query(this.QueryGenerator.versionQuery(), _.assign({
type: QueryTypes.VERSION
}, options));
return this.sequelize.query(
this.QueryGenerator.versionQuery(),
_.assign({}, options, { type: QueryTypes.VERSION })
);
};
QueryInterface.prototype.createTable = function(tableName, attributes, options, model) {
......@@ -96,7 +97,7 @@ QueryInterface.prototype.createTable = function(tableName, attributes, options,
sql = self.QueryGenerator.pgListEnums(tableName, attributes[keys[i]].field || keys[i], options);
promises.push(self.sequelize.query(
sql,
_.assign({ plain: true, raw: true, type: QueryTypes.SELECT }, options)
_.assign({}, options, { plain: true, raw: true, type: QueryTypes.SELECT })
));
}
}
......@@ -112,7 +113,7 @@ QueryInterface.prototype.createTable = function(tableName, attributes, options,
sql = self.QueryGenerator.pgEnum(tableName, attributes[keys[i]].field || keys[i], attributes[keys[i]], options);
promises.push(self.sequelize.query(
sql,
_.assign({ raw: true }, options)
_.assign({}, options, { raw: true })
));
} else if (!!results[enumIdx] && !!model) {
var enumVals = self.QueryGenerator.fromArray(results[enumIdx].enum_value)
......@@ -201,7 +202,7 @@ QueryInterface.prototype.dropTable = function(tableName, options) {
if (instanceTable.rawAttributes[keys[i]].type instanceof DataTypes.ENUM) {
sql = self.QueryGenerator.pgEnumDrop(getTableName, keys[i]);
options.supportsSearchPath = false;
promises.push(self.sequelize.query(sql, _.assign({ raw: true }, options)));
promises.push(self.sequelize.query(sql, _.assign({}, options, { raw: true })));
}
}
}
......@@ -220,7 +221,7 @@ QueryInterface.prototype.dropAllTables = function(options) {
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, _.assign({ cascade: true }, options) );
return self.dropTable(tableName, _.assign({}, options, { cascade: true }) );
}
});
};
......@@ -277,11 +278,11 @@ QueryInterface.prototype.dropAllEnums = function(options) {
return this.sequelize.query(
sql,
_.assign({ plain: false, raw: true, type: QueryTypes.SELECT }, options)
_.assign({}, options, { plain: false, raw: true, type: QueryTypes.SELECT })
).map(function(result) {
return self.sequelize.query(
self.QueryGenerator.pgEnumDrop(null, null, self.QueryGenerator.pgEscapeAndQuote(result.enum_name)),
_.assign({ raw: true }, options)
_.assign({}, options, { raw: true })
);
});
};
......@@ -294,10 +295,10 @@ QueryInterface.prototype.renameTable = function(before, after, options) {
QueryInterface.prototype.showAllTables = function(options) {
var self = this;
options = _.assign({
options = _.assign({}, options, {
raw: true,
type: QueryTypes.SHOWTABLES
}, options || {});
});
var showTablesSql = self.QueryGenerator.showTablesQuery();
return self.sequelize.query(showTablesSql, options).then(function(tableNames) {
......@@ -325,7 +326,7 @@ QueryInterface.prototype.describeTable = function(tableName, options) {
return this.sequelize.query(
sql,
_.assign({ type: QueryTypes.DESCRIBE }, options || {})
_.assign({}, options, { type: QueryTypes.DESCRIBE })
).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,
......@@ -432,12 +433,12 @@ QueryInterface.prototype.addIndex = function(tableName, attributes, options, raw
options = options || {};
options.fields = attributes;
var sql = this.QueryGenerator.addIndexQuery(tableName, options, rawTablename);
return this.sequelize.query(sql, _.assign({ supportsSearchPath: false }, options));
return this.sequelize.query(sql, _.assign({}, options, { supportsSearchPath: false }));
};
QueryInterface.prototype.showIndex = function(tableName, options) {
var sql = this.QueryGenerator.showIndexesQuery(tableName, options);
return this.sequelize.query(sql, _.assign({ type: QueryTypes.SHOWINDEXES }, options || {}));
return this.sequelize.query(sql, _.assign({}, options, { type: QueryTypes.SHOWINDEXES }));
};
QueryInterface.prototype.nameIndexes = function(indexes, rawTablename) {
......@@ -820,7 +821,7 @@ QueryInterface.prototype.setAutocommit = function(transaction, value, options) {
return Promise.resolve();
}
options = _.assign({}, options || {}, {
options = _.assign({}, options, {
transaction: transaction.parent || transaction
});
......@@ -842,7 +843,7 @@ QueryInterface.prototype.setIsolationLevel = function(transaction, value, option
return Promise.resolve();
}
options = _.assign({}, options || {}, {
options = _.assign({}, options, {
transaction: transaction.parent || transaction
});
......@@ -860,7 +861,7 @@ QueryInterface.prototype.startTransaction = function(transaction, options) {
throw new Error('Unable to start a transaction without transaction object!');
}
options = _.assign({}, options || {}, {
options = _.assign({}, options, {
transaction: transaction.parent || transaction
});
......@@ -870,9 +871,9 @@ QueryInterface.prototype.startTransaction = function(transaction, options) {
};
QueryInterface.prototype.deferConstraints = function (transaction, options) {
options = Utils._.extend({
options = _.assign({}, options, {
transaction: transaction.parent || transaction
}, options || {});
});
var sql = this.QueryGenerator.deferConstraintsQuery(options);
......@@ -892,7 +893,7 @@ QueryInterface.prototype.commitTransaction = function(transaction, options) {
return Promise.resolve();
}
options = _.assign({}, options || {}, {
options = _.assign({}, options, {
transaction: transaction.parent || transaction,
supportsSearchPath: false
});
......@@ -907,7 +908,7 @@ QueryInterface.prototype.rollbackTransaction = function(transaction, options) {
throw new Error('Unable to rollback a transaction without transaction object!');
}
options = _.assign({}, options || {}, {
options = _.assign({}, options, {
transaction: transaction.parent || transaction,
supportsSearchPath: false
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!