Skip to content

Commit

Permalink
Fix: fix parseGroup error when has expression
Browse files Browse the repository at this point in the history
  • Loading branch information
welefen committed Mar 14, 2016
1 parent c1e45fa commit 8d5ad98
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/adapter/db/_parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ export default class extends think.base {
return '';
}
if (think.isString(group)) {
//group may be `date_format(create_time,'%Y-%m-%d')`
if(group.indexOf('(') !== -1){
return ' GROUP BY ' + group;
}
group = group.split(/\s*,\s*/);
}
let result = group.map(item => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default {
//package alias
let pkgAlias = {
'babel-runtime': 'babel-runtime/helpers/inherits'
}
};
let pkgPath = `${think.ROOT_PATH}${think.sep}node_modules${think.sep}`;
for(let pkg in dependencies){
pkg = pkgAlias[pkg] || pkg;
Expand Down
5 changes: 5 additions & 0 deletions test/adapter/db/_parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ describe('adapter/db/_parse.js', function(){
var data = instance.parseGroup('name');
assert.equal(data, ' GROUP BY `name`');
})
it('parseGroup, name', function(){
var instance = new Parse();
var data = instance.parseGroup("date_format(create_time,'%Y-%m-%d')");
assert.equal(data, " GROUP BY date_format(create_time,'%Y-%m-%d')");
})
it('parseGroup, name,title', function(){
var instance = new Parse();
var data = instance.parseGroup('name, title');
Expand Down

0 comments on commit 8d5ad98

Please sign in to comment.