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

Commit 7229ccb9 by Yu Qi Committed by Sushant

fix(query-generator): options.group should be quoted (#8326)

1 parent 79485c3c
...@@ -1138,7 +1138,7 @@ const QueryGenerator = { ...@@ -1138,7 +1138,7 @@ const QueryGenerator = {
// Add GROUP BY to sub or main query // Add GROUP BY to sub or main query
if (options.group) { if (options.group) {
options.group = Array.isArray(options.group) ? options.group.map(t => this.quote(t, model)).join(', ') : options.group; options.group = Array.isArray(options.group) ? options.group.map(t => this.quote(t, model)).join(', ') : this.quote(options.group, model);
if (subQuery) { if (subQuery) {
subQueryItems.push(' GROUP BY ' + options.group); subQueryItems.push(' GROUP BY ' + options.group);
} else { } else {
......
...@@ -261,9 +261,9 @@ if (dialect === 'mysql') { ...@@ -261,9 +261,9 @@ if (dialect === 'mysql') {
context: QueryGenerator, context: QueryGenerator,
needsSequelize: true needsSequelize: true
}, { }, {
title: 'single string argument is not quoted', title: 'single string argument should be quoted',
arguments: ['myTable', {group: 'name'}], arguments: ['myTable', {group: 'name'}],
expectation: 'SELECT * FROM `myTable` GROUP BY name;', expectation: 'SELECT * FROM `myTable` GROUP BY `name`;',
context: QueryGenerator context: QueryGenerator
}, { }, {
arguments: ['myTable', { group: ['name'] }], arguments: ['myTable', { group: ['name'] }],
...@@ -291,7 +291,7 @@ if (dialect === 'mysql') { ...@@ -291,7 +291,7 @@ if (dialect === 'mysql') {
needsSequelize: true needsSequelize: true
}, { }, {
arguments: ['myTable', {group: 'name', order: [['id', 'DESC']]}], arguments: ['myTable', {group: 'name', order: [['id', 'DESC']]}],
expectation: 'SELECT * FROM `myTable` GROUP BY name ORDER BY `id` DESC;', expectation: 'SELECT * FROM `myTable` GROUP BY `name` ORDER BY `id` DESC;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'HAVING clause works with where-like hash', title: 'HAVING clause works with where-like hash',
......
...@@ -358,9 +358,9 @@ if (dialect.match(/^postgres/)) { ...@@ -358,9 +358,9 @@ if (dialect.match(/^postgres/)) {
context: QueryGenerator, context: QueryGenerator,
needsSequelize: true needsSequelize: true
}, { }, {
title: 'single string argument is not quoted', title: 'single string argument should be quoted',
arguments: ['myTable', {group: 'name'}], arguments: ['myTable', {group: 'name'}],
expectation: 'SELECT * FROM \"myTable\" GROUP BY name;' expectation: 'SELECT * FROM \"myTable\" GROUP BY \"name\";'
}, { }, {
arguments: ['myTable', {group: ['name']}], arguments: ['myTable', {group: ['name']}],
expectation: 'SELECT * FROM \"myTable\" GROUP BY \"name\";' expectation: 'SELECT * FROM \"myTable\" GROUP BY \"name\";'
......
...@@ -251,9 +251,9 @@ if (dialect === 'sqlite') { ...@@ -251,9 +251,9 @@ if (dialect === 'sqlite') {
context: QueryGenerator, context: QueryGenerator,
needsSequelize: true needsSequelize: true
}, { }, {
title: 'single string argument is not quoted', title: 'single string argument should be quoted',
arguments: ['myTable', {group: 'name'}], arguments: ['myTable', {group: 'name'}],
expectation: 'SELECT * FROM `myTable` GROUP BY name;', expectation: 'SELECT * FROM `myTable` GROUP BY `name`;',
context: QueryGenerator context: QueryGenerator
}, { }, {
arguments: ['myTable', {group: ['name']}], arguments: ['myTable', {group: ['name']}],
...@@ -285,7 +285,7 @@ if (dialect === 'sqlite') { ...@@ -285,7 +285,7 @@ if (dialect === 'sqlite') {
context: QueryGenerator context: QueryGenerator
}, { }, {
arguments: ['myTable', {group: 'name', order: [['id', 'DESC']]}], arguments: ['myTable', {group: 'name', order: [['id', 'DESC']]}],
expectation: 'SELECT * FROM `myTable` GROUP BY name ORDER BY `id` DESC;', expectation: 'SELECT * FROM `myTable` GROUP BY `name` ORDER BY `id` DESC;',
context: QueryGenerator context: QueryGenerator
}, { }, {
title: 'HAVING clause works with where-like hash', title: 'HAVING clause works with where-like hash',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!