@@ -20,6 +20,7 @@ Postgres.prototype.visit = function(node) {
2020 case 'FROM' : return this . visitFrom ( node ) ;
2121 case 'WHERE' : return this . visitWhere ( node ) ;
2222 case 'ORDER BY' : return this . visitOrderBy ( node ) ;
23+ case 'GROUP BY' : return this . visitGroupBy ( node ) ;
2324 case 'RETURNING' : return this . visitReturning ( node ) ;
2425 case 'BINARY' : return this . visitBinary ( node ) ;
2526 case 'TABLE' : return this . visitTable ( node ) ;
@@ -28,7 +29,7 @@ Postgres.prototype.visit = function(node) {
2829 case 'TEXT' : return node . text ;
2930 case 'UNARY' : return this . visitUnary ( node ) ;
3031 case 'PARAMETER' : return this . visitParameter ( node ) ;
31- case 'LIMIT' :
32+ case 'LIMIT' :
3233 case 'OFFSET' :
3334 return this . visitModifier ( node ) ;
3435 default : throw new Error ( "Unrecognized node type " + node . type ) ;
@@ -106,6 +107,11 @@ Postgres.prototype.visitOrderBy = function(orderBy) {
106107 return result ;
107108}
108109
110+ Postgres . prototype . visitGroupBy = function ( groupBy ) {
111+ var result = [ 'GROUP BY' , groupBy . nodes . map ( this . visit . bind ( this ) ) . join ( ', ' ) ] ;
112+ return result ;
113+ }
114+
109115Postgres . prototype . visitBinary = function ( binary ) {
110116 return '(' + this . visit ( binary . left ) + ' ' + binary . operator + ' ' + this . visit ( binary . right ) + ')' ;
111117}
@@ -146,7 +152,11 @@ Postgres.prototype.visitTable = function(tableNode) {
146152
147153Postgres . prototype . visitColumn = function ( columnNode ) {
148154 var table = columnNode . table ;
155+ var inSelectClause = ! this . _selectOrDeleteEndIndex ;
149156 var txt = "" ;
157+ if ( inSelectClause && columnNode . asArray ) {
158+ txt += 'array_agg(' ;
159+ }
150160 if ( ! this . _visitedInsert && ! this . _visitingUpdate ) {
151161 if ( table . alias ) {
152162 txt = table . alias ;
@@ -157,11 +167,14 @@ Postgres.prototype.visitColumn = function(columnNode) {
157167 }
158168 txt += this . quote ( table . getName ( ) ) ;
159169 }
160- txt += '.'
170+ txt += '.' ;
161171 }
162172 txt += this . quote ( columnNode . name ) ;
163- var inSelectClause = ! this . _selectOrDeleteEndIndex ;
164- if ( inSelectClause && columnNode . alias ) {
173+ if ( inSelectClause && columnNode . asArray ) {
174+ txt += ')' ;
175+ txt += ' as ' + this . quote ( columnNode . alias ) ;
176+ }
177+ else if ( inSelectClause && columnNode . alias ) {
165178 txt += ' as ' + this . quote ( columnNode . alias ) ;
166179 }
167180 return txt ;
0 commit comments