ajout des conditions where in et where between
This commit is contained in:
@@ -17,6 +17,14 @@ class Expression
|
||||
|
||||
public function raw(): string
|
||||
{
|
||||
$operator = trim(strtolower($this->operator));
|
||||
if ($operator == "in") {
|
||||
$values = implode(",", str_split(str_repeat("?", count($this->value))));
|
||||
return "(" . $this->condition . " " . $this->operator . " (" . $values . ") )";
|
||||
}
|
||||
if ($operator == "between" && count($this->value) == 2) {
|
||||
return "(" . $this->condition . " " . $this->operator . " ? AND ? )";
|
||||
}
|
||||
return "(" . $this->condition . " " . $this->operator . " ? )";
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,13 @@ class Query
|
||||
|
||||
public function addData($value)
|
||||
{
|
||||
$this->data[] = $value;
|
||||
if (is_array($value)) {
|
||||
$this->data = array_merge($this->data, $value);
|
||||
} else {
|
||||
$this->data[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getQuery(): string
|
||||
{
|
||||
return $this->query;
|
||||
|
||||
@@ -86,6 +86,18 @@ class QueryBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function whereIn($condition, array $values)
|
||||
{
|
||||
$this->wheres[] = new Expression($condition, "in", $values);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function whereBetween($condition, $value1, $value2)
|
||||
{
|
||||
$this->wheres[] = new Expression($condition, "between", [$value1,$value2]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function where($condition, $operator, $value = null)
|
||||
{
|
||||
if ($value === null) {
|
||||
|
||||
Reference in New Issue
Block a user