This commit is contained in:
2021-03-26 14:26:38 +08:00
parent ef1c5ffe6c
commit 17f4f8c896
+18
View File
@@ -13,6 +13,7 @@ namespace Database\Traits;
use Database\ActiveQuery;
use Database\ActiveRecord;
use Database\Condition\MathematicsCondition;
use Database\Sql;
use Exception;
/**
@@ -56,6 +57,23 @@ trait QueryTrait
$this->filter = [];
}
/**
* @param $condition
* @param $condition1
* @param $condition2
* @return $this
* @throws Exception
*/
public function if(string $condition, string|array $condition1, string|array $condition2): static
{
$condition1 = (new Sql())->where($condition1)->getCondition();
$condition2 = (new Sql())->where($condition2)->getCondition();
$this->where[] = 'IF(' . $condition . ',' . $condition1 . ',' . $condition2 . ')';
return $this;
}
/**
* @param $bool
* @return $this