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

Commit b4b0b9b7 by Sascha Depold

Add new methods for and / or queries

1 parent e1d048e2
Showing with 20 additions and 0 deletions
...@@ -422,6 +422,14 @@ module.exports = (function() { ...@@ -422,6 +422,14 @@ module.exports = (function() {
return new Utils.asIs(val) return new Utils.asIs(val)
} }
Sequelize.and = Sequelize.prototype.and = function() {
return new Utils.and(Array.prototype.slice.call(arguments))
}
Sequelize.or = Sequelize.prototype.or = function() {
return new Utils.or(Array.prototype.slice.call(arguments))
}
Sequelize.prototype.transaction = function(_options, _callback) { Sequelize.prototype.transaction = function(_options, _callback) {
var options = (typeof _options === 'function') ? {} : _options var options = (typeof _options === 'function') ? {} : _options
, callback = (typeof _options === 'function') ? _options : _callback , callback = (typeof _options === 'function') ? _options : _callback
......
...@@ -523,6 +523,7 @@ var Utils = module.exports = { ...@@ -523,6 +523,7 @@ var Utils = module.exports = {
tickChar = tickChar || Utils.TICK_CHAR tickChar = tickChar || Utils.TICK_CHAR
return s.replace(new RegExp(tickChar, 'g'), "") return s.replace(new RegExp(tickChar, 'g'), "")
}, },
/* /*
* Utility functions for representing SQL functions, and columns that should be escaped. * Utility functions for representing SQL functions, and columns that should be escaped.
* Please do not use these functions directly, use Sequelize.fn and Sequelize.col instead. * Please do not use these functions directly, use Sequelize.fn and Sequelize.col instead.
...@@ -531,13 +532,16 @@ var Utils = module.exports = { ...@@ -531,13 +532,16 @@ var Utils = module.exports = {
this.fn = fn this.fn = fn
this.args = args this.args = args
}, },
col: function (col) { col: function (col) {
this.col = col this.col = col
}, },
cast: function (val, type) { cast: function (val, type) {
this.val = val this.val = val
this.type = (type || '').trim() this.type = (type || '').trim()
}, },
literal: function (val) { literal: function (val) {
this.val = val this.val = val
}, },
...@@ -546,6 +550,14 @@ var Utils = module.exports = { ...@@ -546,6 +550,14 @@ var Utils = module.exports = {
this.val = val this.val = val
}, },
and: function(args) {
this.args = args
},
or: function(args) {
this.args = args
},
generateUUID: function() { generateUUID: function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8) var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!