dbms_primeidc_init...1

This commit is contained in:
최준흠 2025-04-09 11:06:50 +09:00
parent 9de5af04be
commit ae9e3cb813
2 changed files with 25 additions and 25 deletions

View File

@ -22,15 +22,15 @@ class QueryBuilder
{
$this->pdo = $pdo;
}
final public function setDebug(bool $debug): void
final final public function setDebug(bool $debug): void
{
$this->_debug = $debug;
}
final public function getLastQuery(): string
final final public function getLastQuery(): string
{
return $this->latestQuery;
}
public function table(string $table): static
final public function table(string $table): static
{
$this->table = $table;
return $this;
@ -68,14 +68,14 @@ class QueryBuilder
}
//Select부분분
public function select(array|string $columns): static
final public function select(array|string $columns): static
{
$this->select = is_array($columns) ? $columns : explode(',', $columns);
return $this;
}
//Where절부분
public function where(array|string $column, mixed $operator = null, mixed $value = null): static
final public function where(array|string $column, mixed $operator = null, mixed $value = null): static
{
if (is_array($column)) {
foreach ($column as $col => $val) {
@ -98,12 +98,12 @@ class QueryBuilder
$this->bindings[$placeholder] = $value;
return $this;
}
public function orWhere(string $column, mixed $operator = null, mixed $value = null): static
final public function orWhere(string $column, mixed $operator = null, mixed $value = null): static
{
return $this->where($column, $operator, $value, "OR");
}
public function whereIn(string $column, array $values, string $boolean = 'AND', $conditon_boolean = "IN"): static
final public function whereIn(string $column, array $values, string $boolean = 'AND', $conditon_boolean = "IN"): static
{
if (empty($values)) {
throw new \InvalidArgumentException(__FUNCTION__ . ": values 배열이 비어있을 수 없습니다.");
@ -118,14 +118,14 @@ class QueryBuilder
$this->where[] = ['condition' => $condition, 'boolean' => $boolean];
return $this;
}
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_boolean = "NOT IN"): static
{
if (empty($values)) {
throw new \InvalidArgumentException(__FUNCTION__ . ": values 배열이 비어있을 수 없습니다.");
}
return $this->whereIn($column, $values, $boolean, $conditon_boolean);
}
public function orWhereIn(string $column, array $values, $boolean = "OR", $conditon_boolean = "IN"): static
final public function orWhereIn(string $column, array $values, $boolean = "OR", $conditon_boolean = "IN"): static
{
if (empty($values)) {
throw new \InvalidArgumentException(__FUNCTION__ . ": values 배열이 비어있을 수 없습니다.");
@ -134,14 +134,14 @@ class QueryBuilder
}
//Join
public function join(string $table, string $on, string $type = 'INNER'): static
final public function join(string $table, string $on, string $type = 'INNER'): static
{
$this->joins[] = strtoupper($type) . " JOIN $table ON $on";
return $this;
}
//Order
public function orderBy(mixed $column, string $direction = 'ASC'): static
final public function orderBy(mixed $column, string $direction = 'ASC'): static
{
if (is_array($column)) {
// 배열 형식의 여러 컬럼 정렬을 처리
@ -156,19 +156,19 @@ class QueryBuilder
return $this;
}
//Limit부분
public function limit(int $limit): static
final public function limit(int $limit): static
{
$this->limit = $limit;
return $this;
}
public function offset(int $offset): static
final public function offset(int $offset): static
{
$this->offset = $offset;
return $this;
}
//Customer SQL 실행부분
public function raw(string $sql, array $bindings = []): array
final public function raw(string $sql, array $bindings = []): array
{
$stmt = $this->pdo->prepare($sql);
foreach ($bindings as $key => $value) {
@ -180,7 +180,7 @@ class QueryBuilder
//Result부분
//binding까지 완료한 SQL문을 return함
public function toRawSql(): string
final public function toRawSql(): string
{
$sql = $this->buildSelectSql();
$raw = $sql;
@ -196,7 +196,7 @@ class QueryBuilder
}
return $raw;
}
public function get(): array
final public function get(): array
{
$sql = $this->buildSelectSql();
if ($this->_debug) {
@ -213,14 +213,14 @@ class QueryBuilder
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function first(): ?array
final public function first(): ?array
{
$this->limit = 1;
$results = $this->get();
return $results[0] ?? null;
}
public function count(string $select = "'COUNT(*) as cnt'"): int
final public function count(string $select = "COUNT(*) as cnt"): int
{
$this->select = [$select];
$results = $this->get();
@ -228,7 +228,7 @@ class QueryBuilder
}
//CUD부분
public function insert(array $data): bool
final public function insert(array $data): bool
{
$columns = array_keys($data);
$placeholders = array_map(fn($c) => ':' . $c, $columns);
@ -240,7 +240,7 @@ class QueryBuilder
return $stmt->execute();
}
public function update(array $data): bool
final public function update(array $data): bool
{
if (empty($this->where)) throw new \Exception("Update without WHERE is not allowed.");
@ -259,7 +259,7 @@ class QueryBuilder
return $stmt->execute();
}
public function delete(): bool
final public function delete(): bool
{
if (empty($this->where)) throw new \Exception("Delete without WHERE is not allowed.");
$sql = "DELETE FROM {$this->table} WHERE " . implode(' AND ', $this->where);
@ -271,17 +271,17 @@ class QueryBuilder
}
//transaction관련련
public function beginTransaction(): void
final public function beginTransaction(): void
{
$this->pdo->beginTransaction();
}
public function commit(): void
final public function commit(): void
{
$this->pdo->commit();
}
public function rollBack(): void
final public function rollBack(): void
{
if ($this->pdo->inTransaction()) {
$this->pdo->rollBack();

View File

@ -42,7 +42,7 @@ abstract class CommonService extends Core
}
return $entitys;
} //
final public function getCount(string $select = "'COUNT(*) as cnt'"): int
final public function getCount(string $select = "COUNT(*) as cnt"): int
{
$count = $this->getModel()->count($select);
// echo "<BR>" . $this->getModel()->getLastQuery();