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

Commit f4f0edc7 by Cao Jiannan Committed by Sushant

Allow captial (#6407)

* add uppercase name JSON field test
* Solve the quote problem of JSON field
* fix typo
* fix test quotation issue
* fix test quotation issue
* fix test quotation issue again
* using template quote
* modify test for find attributes
* add change log for JSON attributes quote issue
1 parent c77aa224
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
- [SECURITY] `GEOMETRY` and `GEOGRAPHY` SQL injection attacks [#6194](https://github.com/sequelize/sequelize/issues/6194) - [SECURITY] `GEOMETRY` and `GEOGRAPHY` SQL injection attacks [#6194](https://github.com/sequelize/sequelize/issues/6194)
- [FIXED] `DECIMAL` now supports `UNSIGNED` / `ZEROFILL` (MySQL) [#2038](https://github.com/sequelize/sequelize/issues/2038) - [FIXED] `DECIMAL` now supports `UNSIGNED` / `ZEROFILL` (MySQL) [#2038](https://github.com/sequelize/sequelize/issues/2038)
- [FIXED] Generate correct SQL of nested include when quoteIdentifiers is false. (Postgres) [#6351](https://github.com/sequelize/sequelize/issues/6351) - [FIXED] Generate correct SQL of nested include when quoteIdentifiers is false. (Postgres) [#6351](https://github.com/sequelize/sequelize/issues/6351)
- [FIXED] Generate correct SQL for JSON attributes with quote.
[#6406](https://github.com/sequelize/sequelize/issues/6406)
## BC breaks: ## BC breaks:
- Range type bounds now default to [postgres default](https://www.postgresql.org/docs/9.5/static/rangetypes.html#RANGETYPES-CONSTRUCT) `[)` (inclusive, exclusive), previously was `()` (exclusive, exclusive) - Range type bounds now default to [postgres default](https://www.postgresql.org/docs/9.5/static/rangetypes.html#RANGETYPES-CONSTRUCT) `[)` (inclusive, exclusive), previously was `()` (exclusive, exclusive)
......
...@@ -130,7 +130,7 @@ const QueryGenerator = { ...@@ -130,7 +130,7 @@ const QueryGenerator = {
// Parse nested object // Parse nested object
if (smth.conditions) { if (smth.conditions) {
const conditions = _.map(this.parseConditionObject(smth.conditions), condition => const conditions = _.map(this.parseConditionObject(smth.conditions), condition =>
`${_.first(condition.path)}#>>'{${_.tail(condition.path).join(',')}}' = '${condition.value}'` `${this.quoteIdentifier(_.first(condition.path))}#>>'{${_.tail(condition.path).join(',')}}' = '${condition.value}'`
); );
return conditions.join(' and '); return conditions.join(' and ');
...@@ -143,7 +143,7 @@ const QueryGenerator = { ...@@ -143,7 +143,7 @@ const QueryGenerator = {
} else { } else {
// Also support json dot notation // Also support json dot notation
const path = smth.path.split('.'); const path = smth.path.split('.');
str = `${_.first(path)}#>>'{${_.tail(path).join(',')}}'`; str = `${this.quoteIdentifier(_.first(path))}#>>'{${_.tail(path).join(',')}}'`;
} }
if (smth.value) { if (smth.value) {
......
...@@ -20,6 +20,7 @@ if (dialect.match(/^postgres/)) { ...@@ -20,6 +20,7 @@ if (dialect.match(/^postgres/)) {
document: { type: DataTypes.HSTORE, defaultValue: { default: "'value'" } }, document: { type: DataTypes.HSTORE, defaultValue: { default: "'value'" } },
phones: DataTypes.ARRAY(DataTypes.HSTORE), phones: DataTypes.ARRAY(DataTypes.HSTORE),
emergency_contact: DataTypes.JSON, emergency_contact: DataTypes.JSON,
emergencyContact: DataTypes.JSON,
friends: { friends: {
type: DataTypes.ARRAY(DataTypes.JSON), type: DataTypes.ARRAY(DataTypes.JSON),
defaultValue: [] defaultValue: []
...@@ -251,6 +252,23 @@ if (dialect.match(/^postgres/)) { ...@@ -251,6 +252,23 @@ if (dialect.match(/^postgres/)) {
expect(user.emergency_contact.name).to.equal('joe'); expect(user.emergency_contact.name).to.equal('joe');
}); });
}); });
it('should be able to query using dot syntax with uppercase name', function() {
var self = this;
return this.sequelize.Promise.all([
this.User.create({ username: 'swen', emergencyContact: { name: 'kate' } }),
this.User.create({ username: 'anna', emergencyContact: { name: 'joe' } })])
.then(function() {
return self.User.find({
attributes: [[sequelize.json('emergencyContact.name'), 'contactName']],
where: sequelize.json('emergencyContact.name', 'joe')
});
})
.then(function(user) {
expect(user.get("contactName")).to.equal('joe');
});
});
it('should be able to store values that require JSON escaping', function() { it('should be able to store values that require JSON escaping', function() {
var self = this; var self = this;
......
...@@ -194,13 +194,13 @@ describe(Support.getTestDialectTeaser('Utils'), function() { ...@@ -194,13 +194,13 @@ describe(Support.getTestDialectTeaser('Utils'), function() {
}, },
another_json_field: { x: 1 } another_json_field: { x: 1 }
}; };
var expected = "metadata#>>'{language}' = 'icelandic' and metadata#>>'{pg_rating,dk}' = 'G' and another_json_field#>>'{x}' = '1'"; var expected = `"metadata"#>>'{language}' = 'icelandic' and "metadata"#>>'{pg_rating,dk}' = 'G' and "another_json_field"#>>'{x}' = '1'`;
expect(queryGenerator.handleSequelizeMethod(new Utils.Json(conditions))).to.deep.equal(expected); expect(queryGenerator.handleSequelizeMethod(new Utils.Json(conditions))).to.deep.equal(expected);
}); });
it('successfully parses a string using dot notation', function() { it('successfully parses a string using dot notation', function() {
var path = 'metadata.pg_rating.dk'; var path = 'metadata.pg_rating.dk';
expect(queryGenerator.handleSequelizeMethod(new Utils.Json(path))).to.equal("metadata#>>'{pg_rating,dk}'"); expect(queryGenerator.handleSequelizeMethod(new Utils.Json(path))).to.equal(`"metadata"#>>'{pg_rating,dk}'`);
}); });
it('allows postgres json syntax', function() { it('allows postgres json syntax', function() {
...@@ -211,7 +211,7 @@ describe(Support.getTestDialectTeaser('Utils'), function() { ...@@ -211,7 +211,7 @@ describe(Support.getTestDialectTeaser('Utils'), function() {
it('can take a value to compare against', function() { it('can take a value to compare against', function() {
var path = 'metadata.pg_rating.is'; var path = 'metadata.pg_rating.is';
var value = 'U'; var value = 'U';
expect(queryGenerator.handleSequelizeMethod(new Utils.Json(path, value))).to.equal("metadata#>>'{pg_rating,is}' = 'U'"); expect(queryGenerator.handleSequelizeMethod(new Utils.Json(path, value))).to.equal(`"metadata"#>>'{pg_rating,is}' = 'U'`);
}); });
}); });
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!