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

Avoid quoting attributes with PostgreSQL JSON operators

1 parent 75bbf4ba
Showing with 3 additions and 0 deletions
...@@ -776,6 +776,7 @@ module.exports = (function() { ...@@ -776,6 +776,7 @@ module.exports = (function() {
quoteIdentifier: function(identifier, force) { quoteIdentifier: function(identifier, force) {
var _ = Utils._;
if (identifier === '*') return identifier; if (identifier === '*') return identifier;
if (!force && this.options && this.options.quoteIdentifiers === false) { // default is `true` if (!force && this.options && this.options.quoteIdentifiers === false) { // default is `true`
// In Postgres, if tables or attributes are created double-quoted, // In Postgres, if tables or attributes are created double-quoted,
...@@ -784,6 +785,8 @@ module.exports = (function() { ...@@ -784,6 +785,8 @@ module.exports = (function() {
// impossible to write queries in portable SQL if tables are created in // impossible to write queries in portable SQL if tables are created in
// this way. Hence, we strip quotes if we don't want case sensitivity. // this way. Hence, we strip quotes if we don't want case sensitivity.
return Utils.removeTicks(identifier, '"'); return Utils.removeTicks(identifier, '"');
} else if (_.any(['->', '->>', '#>'], _.partial(_.contains, identifier))) { // Postgres json operators
return identifier;
} else { } else {
return Utils.addTicks(identifier, '"'); return Utils.addTicks(identifier, '"');
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!