
import { isString } from 'lodash' 

/**
 * @class Aggregate
 */
export default class {
  
  /**
   * 
   * @param {String} method
   * @param {String|Array} columns
   * @param {String} as
   * @param {Boolean} isDistinct
   * @constructor
   */
  constructor(method, columns, as = null, isDistinct = false) {
    if ( isString(columns) ) columns = columns.split(/\s*,\s*/)
    
    // TODO ensure aggregation method is valid
    
    this.name       = as
    this.method     = method
    this.columns     = columns
    this.isDistinct = isDistinct
  }
  
  compile(compiler = null) {
    // FIXME where to get the dialect
    if (! compiler ) compiler = createCompiler(dialect)
    
    var columns = compiler.columnize(this.columns)
    var distinct = this.isDistinct ? 'distinct ' : ''
    
    return compiler.alias(`${this.method}(${distinct}${columns})`, this.name)
  }
  
}

@@ -27,17 +27,48 @@
 'lodash'
- 
+%0Aimport Expression from './base'
 %0A%0A/**%0A *
@@ -110,16 +110,45 @@
 t class 
+Aggregate extends Expression 
 %7B%0A  %0A  /
@@ -632,117 +632,11 @@
 iler
- = null) %7B%0A    // FIXME where to get the dialect%0A    if (! compiler ) compiler = createCompiler(dialect)%0A    
+) %7B
 %0A   

Update aggregate.js