dbms_primeidc_init...1
This commit is contained in:
parent
0c5077c5b3
commit
0d2ba4c88c
@ -75,35 +75,33 @@ class QueryBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Where절부분
|
//Where절부분
|
||||||
final public function where(array|string $column, mixed $operator = null, mixed $value = null): static
|
final public function where(array|string $column, mixed $value = null, ?string $operator = null, string $boolean = "AND"): static
|
||||||
{
|
{
|
||||||
if (is_array($column)) {
|
if (is_array($column)) {
|
||||||
foreach ($column as $col => $val) {
|
foreach ($column as $col => $val) {
|
||||||
$this->where($col, '=', $val); // 재귀 호출
|
$this->where($col, $val); // 재귀 호출
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
// where("col = NOW()") 형태의 raw 처리
|
// where("col = NOW()") 형태의 raw 처리
|
||||||
if ($operator === null && $value === null) {
|
if ($value === null && $operator === null) {
|
||||||
$this->where[] = ['condition' => $column, 'boolean' => 'AND'];
|
$this->where[] = ['condition' => $column, 'boolean' => $boolean];
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
// where("col", "val") → operator 생략 시 = 처리
|
// where("col", "val") → operator 생략 시 = 처리
|
||||||
if ($value === null) {
|
if ($operator === null) {
|
||||||
$value = $operator;
|
$operator = "=";
|
||||||
$operator = '=';
|
|
||||||
}
|
}
|
||||||
$placeholder = ':w_' . count($this->bindings);
|
$placeholder = ':w_' . count($this->bindings);
|
||||||
$this->where[] = ['condition' => "$column $operator $placeholder", 'boolean' => 'AND'];
|
$this->where[] = ['condition' => "$column $operator $placeholder", 'boolean' => $boolean];
|
||||||
$this->bindings[$placeholder] = $value;
|
$this->bindings[$placeholder] = $value;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
final public function orWhere(string $column, mixed $operator = null, mixed $value = null): static
|
final public function orWhere(array|string $column, mixed $value = null, ?string $operator = null, string $boolean = "OR"): static
|
||||||
{
|
{
|
||||||
return $this->where($column, $operator, $value, "OR");
|
return $this->where($column, $value, $operator, $boolean);
|
||||||
}
|
}
|
||||||
|
final public function whereIn(string $column, array $values, string $boolean = 'AND', $conditon = "IN"): static
|
||||||
final public function whereIn(string $column, array $values, string $boolean = 'AND', $conditon_boolean = "IN"): static
|
|
||||||
{
|
{
|
||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
throw new \InvalidArgumentException(__FUNCTION__ . ": values 배열이 비어있을 수 없습니다.");
|
throw new \InvalidArgumentException(__FUNCTION__ . ": values 배열이 비어있을 수 없습니다.");
|
||||||
@ -114,23 +112,23 @@ class QueryBuilder
|
|||||||
$placeholders[] = $placeholder;
|
$placeholders[] = $placeholder;
|
||||||
$this->bindings[$placeholder] = $value;
|
$this->bindings[$placeholder] = $value;
|
||||||
}
|
}
|
||||||
$condition = "$column $conditon_boolean (" . implode(', ', $placeholders) . ")";
|
$condition = "$column $conditon (" . implode(', ', $placeholders) . ")";
|
||||||
$this->where[] = ['condition' => $condition, 'boolean' => $boolean];
|
$this->where[] = ['condition' => $condition, 'boolean' => $boolean];
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
final public function whereNotIn(string $column, array $values, $boolean = "AND", $conditon_boolean = "NOT IN"): static
|
final public function whereNotIn(string $column, array $values, $boolean = "AND", $conditon = "NOT IN"): static
|
||||||
{
|
{
|
||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
throw new \InvalidArgumentException(__FUNCTION__ . ": values 배열이 비어있을 수 없습니다.");
|
throw new \InvalidArgumentException(__FUNCTION__ . ": values 배열이 비어있을 수 없습니다.");
|
||||||
}
|
}
|
||||||
return $this->whereIn($column, $values, $boolean, $conditon_boolean);
|
return $this->whereIn($column, $values, $boolean, $conditon);
|
||||||
}
|
}
|
||||||
final public function orWhereIn(string $column, array $values, $boolean = "OR", $conditon_boolean = "IN"): static
|
final public function orWhereIn(string $column, array $values, $boolean = "OR", $conditon = "IN"): static
|
||||||
{
|
{
|
||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
throw new \InvalidArgumentException(__FUNCTION__ . ": values 배열이 비어있을 수 없습니다.");
|
throw new \InvalidArgumentException(__FUNCTION__ . ": values 배열이 비어있을 수 없습니다.");
|
||||||
}
|
}
|
||||||
return $this->whereIn($column, $values, $boolean, $conditon_boolean);
|
return $this->whereIn($column, $values, $boolean, $conditon);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Join
|
//Join
|
||||||
@ -140,6 +138,59 @@ class QueryBuilder
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Like
|
||||||
|
//사용예:
|
||||||
|
// $model->like(['name' => '%홍%', 'email' => '%@naver.com%']);
|
||||||
|
// $model->likeIn(['title', 'description'], '%공지%');
|
||||||
|
// $model->orLikeIn(['name', 'nickname'], '%철수%');
|
||||||
|
public function like(array|string $column, ?string $value = null, string $operator = 'LIKE', string $boolean = "AND"): static
|
||||||
|
{
|
||||||
|
if (is_array($column)) {
|
||||||
|
$conditions = [];
|
||||||
|
foreach ($column as $col => $val) {
|
||||||
|
$placeholder = ':l_' . count($this->bindings);
|
||||||
|
$conditions[] = "$col $operator $placeholder";
|
||||||
|
$this->bindings[$placeholder] = $val;
|
||||||
|
}
|
||||||
|
$this->where[] = '(' . implode(" $boolean ", $conditions) . ')';
|
||||||
|
} else {
|
||||||
|
$placeholder = ':l_' . count($this->bindings);
|
||||||
|
$condition = "$column $operator $placeholder";
|
||||||
|
if (empty($this->where)) {
|
||||||
|
$this->where[] = $condition;
|
||||||
|
} else {
|
||||||
|
$last = array_pop($this->where);
|
||||||
|
$this->where[] = "($last $boolean $condition)";
|
||||||
|
}
|
||||||
|
$this->bindings[$placeholder] = $value;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function orLike(array|string $column, ?string $value = null, string $operator = 'LIKE', string $boolean = "OR"): static
|
||||||
|
{
|
||||||
|
return $this->like($column, $value, $operator, $boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function likeIn(array $columns, string $value, string $operator = "LIKE", string $boolean = "AND"): static
|
||||||
|
{
|
||||||
|
$orConditions = [];
|
||||||
|
foreach ($columns as $col) {
|
||||||
|
$placeholder = ':li_' . count($this->bindings);
|
||||||
|
$orConditions[] = "$col $operator $placeholder";
|
||||||
|
$this->bindings[$placeholder] = $value;
|
||||||
|
}
|
||||||
|
$this->where[] = '(' . implode(" $boolean ", $orConditions) . ')';
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function orLikeIn(array $columns, string $value, string $operator = "LIKE", string $boolean = "OR"): static
|
||||||
|
{
|
||||||
|
return $this->likeIn($columns, $value, $operator, $boolean);
|
||||||
|
}
|
||||||
|
public function notLikeIn(array $columns, string $value, string $operator = "NOT LIKE", string $boolean = "AND"): static
|
||||||
|
{
|
||||||
|
return $this->likeIn($columns, $value, $operator, $boolean);
|
||||||
|
}
|
||||||
|
|
||||||
//Order
|
//Order
|
||||||
final public function orderBy(mixed $column, string $direction = 'ASC'): static
|
final public function orderBy(mixed $column, string $direction = 'ASC'): static
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user