valeur par défaut pour le pk dans le querybuilder, ajout du whereRaw sur le model, fixation à * sur la liste de colonnes si non définie
This commit is contained in:
@@ -14,7 +14,7 @@ class QueryBuilder
|
||||
protected ?int $offset;
|
||||
protected string $raw_query;
|
||||
|
||||
public function __construct($table, $pk)
|
||||
public function __construct($table, $pk = "id")
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->pk = $pk;
|
||||
@@ -83,6 +83,12 @@ class QueryBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function whereRaw(string $raw)
|
||||
{
|
||||
$this->wheres[] = $raw;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function find($id): mixed
|
||||
{
|
||||
$this->reset();
|
||||
@@ -153,12 +159,24 @@ class QueryBuilder
|
||||
$ret->setQuery("");
|
||||
$ret->setData([]);
|
||||
|
||||
if (count($this->columns) == 0) {
|
||||
$this->columns("*");
|
||||
}
|
||||
|
||||
$columns = implode(",", $this->columns);
|
||||
$where = "";
|
||||
foreach ($this->wheres as $expression) {
|
||||
$sw = $expression->raw();
|
||||
$ret->addData($expression->getValue());
|
||||
if ($where != "") {
|
||||
$sw = "";
|
||||
if ($expression instanceof Expression) {
|
||||
$sw = $expression->raw();
|
||||
$ret->addData($expression->getValue());
|
||||
}
|
||||
if ($expression instanceof string) {
|
||||
if (trim($expression) !== "") {
|
||||
$sw = "(" . $expression . ")";
|
||||
}
|
||||
}
|
||||
if ($where != "" && $sw != "") {
|
||||
$where .= " AND ";
|
||||
}
|
||||
$where .= $sw;
|
||||
|
||||
Reference in New Issue
Block a user