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

Commit ba299865 by Mick Hansen

Let's just use ONE type of updateQuery

1 parent 58d51729
var AbstractDialect = function() {
}
AbstractDialect.prototype.supports = {
'RETURNING *': false
}
module.exports = AbstractDialect
\ No newline at end of file
...@@ -122,8 +122,29 @@ module.exports = (function() { ...@@ -122,8 +122,29 @@ module.exports = (function() {
OR a string with conditions (e.g. 'name="foo"'). OR a string with conditions (e.g. 'name="foo"').
If you use a string, you have to escape it on your own. If you use a string, you have to escape it on your own.
*/ */
updateQuery: function(tableName, values, where) { updateQuery: function(tableName, attrValueHash, where, options, attributes) {
throwMethodUndefined('updateQuery') attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, this.options.omitNull, options)
var query
, values = []
query = "UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
if (this._dialect.supports['RETURNING']) {
query += " RETURNING *"
}
for (var key in attrValueHash) {
var value = attrValueHash[key]
values.push(this.quoteIdentifier(key) + "=" + this.escape(value, (!!attributes && !!attributes[key] ? attributes[key] : undefined)))
}
var replacements = {
table: this.quoteIdentifiers(tableName),
values: values.join(","),
where: this.getWhereConditions(where)
}
return Utils._.template(query)(replacements)
}, },
/* /*
......
var _ = require('lodash')
, MySQL = require('./mysql')
var MariaDialect = function(sequelize) {
this.sequelize = sequelize
}
MariaDialect.prototype = _.extend({
}, MySQL.prototype)
module.exports = MariaDialect
\ No newline at end of file
var _ = require('lodash')
, Abstract = require('./abstract/dialect')
var MysqlDialect = function(sequelize) {
this.sequelize = sequelize
}
MysqlDialect.prototype.supports = _.extend(Abstract.prototype.supports, {
})
module.exports = MysqlDialect
\ No newline at end of file
...@@ -204,25 +204,6 @@ module.exports = (function() { ...@@ -204,25 +204,6 @@ module.exports = (function() {
return Utils._.template(query)(replacements) return Utils._.template(query)(replacements)
}, },
updateQuery: function(tableName, attrValueHash, where, options) {
attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, this.options.omitNull, options)
var values = []
for (var key in attrValueHash) {
var value = attrValueHash[key]
, _value = this.escape(value)
values.push(this.quoteIdentifier(key) + "=" + _value)
}
var query = "UPDATE " + this.quoteIdentifier(tableName) +
" SET " + values.join(",") +
" WHERE " + this.getWhereConditions(where)
return query
},
deleteQuery: function(tableName, where, options) { deleteQuery: function(tableName, where, options) {
options = options || {} options = options || {}
......
var _ = require('lodash')
, Abstract = require('./abstract/dialect')
var PostgresDialect = function(sequelize) {
this.sequelize = sequelize
}
PostgresDialect.prototype.supports = _.extend(Abstract.prototype.supports, {
'RETURNING': true
})
module.exports = PostgresDialect
\ No newline at end of file
...@@ -332,26 +332,6 @@ module.exports = (function() { ...@@ -332,26 +332,6 @@ module.exports = (function() {
return Utils._.template(query)(replacements) return Utils._.template(query)(replacements)
}, },
updateQuery: function(tableName, attrValueHash, where, options, attributes) {
attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, this.options.omitNull, options)
var query = "UPDATE <%= table %> SET <%= values %> WHERE <%= where %> RETURNING *"
, values = []
for (var key in attrValueHash) {
var value = attrValueHash[key]
values.push(this.quoteIdentifier(key) + "=" + this.escape(value, (!!attributes && !!attributes[key] ? attributes[key] : undefined)))
}
var replacements = {
table: this.quoteIdentifiers(tableName),
values: values.join(","),
where: this.getWhereConditions(where)
}
return Utils._.template(query)(replacements)
},
deleteQuery: function(tableName, where, options, factory) { deleteQuery: function(tableName, where, options, factory) {
options = options || {} options = options || {}
......
var _ = require('lodash')
, Abstract = require('./abstract/dialect')
var SqliteDialect = function(sequelize) {
this.sequelize = sequelize
}
SqliteDialect.prototype.supports = _.extend(Abstract.prototype.supports, {
})
module.exports = SqliteDialect
\ No newline at end of file
...@@ -8,6 +8,7 @@ module.exports = (function() { ...@@ -8,6 +8,7 @@ module.exports = (function() {
this.sequelize = sequelize this.sequelize = sequelize
this.QueryGenerator = require('./dialects/' + this.sequelize.options.dialect + '/query-generator') this.QueryGenerator = require('./dialects/' + this.sequelize.options.dialect + '/query-generator')
this.QueryGenerator.options = this.sequelize.options this.QueryGenerator.options = this.sequelize.options
this.QueryGenerator._dialect = this.sequelize.dialect
} }
Utils.addEventEmitter(QueryInterface) Utils.addEventEmitter(QueryInterface)
......
...@@ -112,6 +112,11 @@ module.exports = (function() { ...@@ -112,6 +112,11 @@ module.exports = (function() {
dialectOptions: this.options.dialectOptions, dialectOptions: this.options.dialectOptions,
} }
try {
this.dialect = new (require("./dialects/" + this.getDialect()))(this)
} catch(err) {
throw new Error("The dialect " + this.getDialect() + " is not supported.")
}
this.daoFactoryManager = new DAOFactoryManager(this) this.daoFactoryManager = new DAOFactoryManager(this)
this.transactionManager = new TransactionManager(this) this.transactionManager = new TransactionManager(this)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!