/** * 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; }
/** * Adds a not exists condition to the query. * * @param callable $f * * @return self */ public function notExists(callable $f) { $this->where->addNotExistsCondition($f); return $this; }