Fix an issue with multiple group by columns

This commit is contained in:
Timothy Warren 2014-10-28 09:05:27 -04:00
parent 3c5ed1e58a
commit a1ad4caea4
4 changed files with 9 additions and 5 deletions

View File

@ -2,6 +2,8 @@
A node query builder for various SQL databases, based on CodeIgniter's query builder. A node query builder for various SQL databases, based on CodeIgniter's query builder.
[![Build Status](https://travis-ci.org/timw4mail/node-query.svg?branch=master)](https://travis-ci.org/timw4mail/node-query)
### Basic use ### Basic use
var nodeQuery = require('node-query'); var nodeQuery = require('node-query');

View File

@ -93,6 +93,7 @@
<section class="readme-section"> <section class="readme-section">
<article><h1>Node-query</h1><p>A node query builder for various SQL databases, based on CodeIgniter's query builder.</p> <article><h1>Node-query</h1><p>A node query builder for various SQL databases, based on CodeIgniter's query builder.</p>
<p><a href="https://travis-ci.org/timw4mail/node-query"><img src="https://travis-ci.org/timw4mail/node-query.svg?branch=master" alt="Build Status"></a></p>
<h3>Basic use</h3><pre class="prettyprint source"><code>var nodeQuery = require('node-query'); <h3>Basic use</h3><pre class="prettyprint source"><code>var nodeQuery = require('node-query');
var connection = ... // Database module connection var connection = ... // Database module connection

View File

@ -273,8 +273,8 @@ var QueryBuilder = function(driver, adapter) {
{ {
sql = _p.compile(type, table); sql = _p.compile(type, table);
} }
//console.log(sql); console.log(sql);
//console.log('------------------------'); console.log('------------------------');
if ( ! vals) if ( ! vals)
{ {
@ -621,10 +621,10 @@ var QueryBuilder = function(driver, adapter) {
* @return this * @return this
*/ */
this.groupBy = function(field) { this.groupBy = function(field) {
if (Array.isArray(field)) if ( ! helpers.isScalar(field))
{ {
var newGroupArray = field.map(driver.quoteIdentifiers); var newGroupArray = field.map(driver.quoteIdentifiers);
state.groupArray.concat(newGroupArray); state.groupArray = state.groupArray.concat(newGroupArray);
} }
else else
{ {

View File

@ -185,7 +185,8 @@ module.exports = (function() {
.from('create_test') .from('create_test')
.where('id >', 0) .where('id >', 0)
.where('id <', 9000) .where('id <', 9000)
.groupBy('id') .groupBy('k')
.groupBy(['id', 'val'])
.orderBy('id', 'DESC') .orderBy('id', 'DESC')
.orderBy('k', "ASC") .orderBy('k', "ASC")
.limit(5, 2) .limit(5, 2)