Ejemplo n.º 1
0
 /**
  * Generates the raw SQL string for the query.
  *
  * @return string
  */
 public function build()
 {
     $sql = [$this->select->build(), $this->from->build(), $this->where->build(), $this->groupBy->build(), $this->having->build(), $this->orderBy->build(), $this->limit->build(), $this->union->build()];
     $this->values = array_merge($this->where->getValues(), $this->having->getValues(), $this->union->getValues());
     $sql = implode(' ', array_filter($sql));
     // when there is no select statement then the query
     // is probably just a where subquery, thus does
     // not need to be prefixed with WHERE
     if (substr($sql, 0, 6) === 'WHERE ') {
         return substr($sql, 6);
     }
     return $sql;
 }
Ejemplo n.º 2
0
 /**
  * Sets the order for the query.
  *
  * @param string|array $fields
  * @param string       $direction
  *
  * @return self
  */
 public function orderBy($fields, $direction = false)
 {
     $this->orderBy->addFields($fields, $direction);
     return $this;
 }