code: function buildSql (rebuild) {
      // if sql has not been built before then build sub-parts
      if (!this.sql || rebuild) {
          this.selectSql = `SELECT ${this.select.join(', ')}`
          this.fromSql = `FROM ${this.quoteName(this.table)} ${this.alias}`
          this.joinSql = ''
          // create join sql
          if (this.join.length) {
              this.joinSql = this.join.join(' ')
          }
          this.whereSql = ''
          // create where sql
          if (this.where.length) {
              this.whereSql = 'WHERE '+this.where.join(' AND ')
          }
          this.orderSql = ''
          // create order sql
          if (this.order.length) {
              this.orderSql = 'ORDER BY '+this.order.join(', ')
          }
          this.limitSql = ''
          // create limit sql
          if (typeof this.args.limit === 'number') {
              var limit = parseInt(this.args.limit)
              this.limitSql = 'LIMIT '+limit
              // add offset
              if (typeof this.args.offset === 'number') {
                  var offset = parseInt(this.args.offset)
                  this.limitSql = this.limitSql+' OFFSET '+offset
              }
          }
      }
      // build full query
      this.sql = this.selectSql
          +' '+this.fromSql
          +(this.joinSql.length ? ' '+this.joinSql : '')
          +(this.whereSql.length ? ' '+this.whereSql : '')
          +(this.orderSql.length ? ' '+this.orderSql : '')
          +(this.limitSql.length ? ' '+this.limitSql : '')
  }
docs: @function buildSql
  
  build full sql SELECT statement. when called the first time each part
  of query will be saved to its own property. These properties can be
  modified and then buildSql can be called again to rebuild only the main
  sql including the modified proeprties.
  
  to rebuild the entire query including all the sub-parts the rebuild
  flag can be passed.
  
  @param {boolean} rebuild
  
  @returns {string}