This commit is contained in:
2023-12-12 15:35:35 +08:00
parent 510a13e3da
commit e2c0f62532
32 changed files with 922 additions and 1095 deletions
+4 -4
View File
@@ -143,7 +143,7 @@ class ActiveQuery extends Component implements ISqlBuilder
/** /**
* @return ModelInterface|array|null * @return ModelInterface|array|null
* @throws Exception * @throws
*/ */
public function first(): ModelInterface|null|array public function first(): ModelInterface|null|array
{ {
@@ -168,7 +168,7 @@ class ActiveQuery extends Component implements ISqlBuilder
/** /**
* @return Collection * @return Collection
* @throws Exception * @throws
*/ */
public function get(): Collection public function get(): Collection
{ {
@@ -242,7 +242,7 @@ class ActiveQuery extends Component implements ISqlBuilder
/** /**
* @param $data * @param $data
* @return ModelInterface|array * @return ModelInterface|array
* @throws Exception * @throws
*/ */
public function populate($data): ModelInterface|array public function populate($data): ModelInterface|array
{ {
@@ -316,7 +316,7 @@ class ActiveQuery extends Component implements ISqlBuilder
/** /**
* @param bool $getSql * @param bool $getSql
* @return bool|string * @return bool|string
* @throws Exception * @throws
*/ */
public function delete(bool $getSql = FALSE): bool|string public function delete(bool $getSql = FALSE): bool|string
{ {
-41
View File
@@ -1,41 +0,0 @@
<?php
namespace Database\Annotation;
use Attribute;
/**
* Class Get
* @package Annotation\Model
* @deprecated
*/
#[Attribute(Attribute::TARGET_METHOD)] class Get
{
/**
* Get constructor.
* @param string $name
*/
public function __construct(public string $name)
{
}
/**
* @param mixed $class
* @param mixed|null $method
* @return bool
*/
public function execute(mixed $class, mixed $method = null): bool
{
// $keys = \Kiri::getDi()->get(Getter::class);
// $keys->write($this->name, $class, $method);
return true;
}
}
-38
View File
@@ -1,38 +0,0 @@
<?php
namespace Database\Annotation;
use Exception;
/**
* Class Relation
* @package Annotation\Model
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Relation
{
/**
* Relation constructor.
* @param string $name
*/
public function __construct(public string $name)
{
}
/**
* @param mixed $class
* @param mixed|null $method
* @return bool
* @throws Exception
*/
public function execute(mixed $class, mixed $method = null): bool
{
return true;
}
}
-38
View File
@@ -1,38 +0,0 @@
<?php
namespace Database\Annotation;
/**
* @deprecated
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Set
{
/**
* Set constructor.
* @param string $name
*/
public function __construct(public string $name)
{
}
/**
* @param mixed $class
* @param mixed|null $method
* @return bool
*/
public function execute(mixed $class, mixed $method = null): bool
{
// $keys = \Kiri::getDi()->get(Setter::class);
// $keys->write($this->name, $class, $method);
return true;
}
}
+12 -10
View File
@@ -44,7 +44,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
protected ActiveQuery $query; protected ActiveQuery $query;
public function clean() public function clean(): void
{ {
unset($this->query, $this->model, $this->_item); unset($this->query, $this->model, $this->_item);
} }
@@ -56,7 +56,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
* @param $query * @param $query
* @param array $array * @param array $array
* @param ModelInterface|null $model * @param ModelInterface|null $model
* @throws Exception * @throws
*/ */
public function __construct($query, array $array = [], ModelInterface $model = null) public function __construct($query, array $array = [], ModelInterface $model = null)
{ {
@@ -80,7 +80,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/** /**
* @param $item * @param $item
*/ */
public function setItems($item) public function setItems($item): void
{ {
$this->_item = $item; $this->_item = $item;
} }
@@ -89,7 +89,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/** /**
* @param $model * @param $model
*/ */
public function setModel($model) public function setModel($model): void
{ {
$this->model = $model; $this->model = $model;
} }
@@ -97,14 +97,14 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/** /**
* @param $item * @param $item
*/ */
public function addItem($item) public function addItem($item): void
{ {
$this->_item[] = $item; $this->_item[] = $item;
} }
/** /**
* @return Traversable|CollectionIterator|ArrayIterator * @return Traversable|CollectionIterator|ArrayIterator
* @throws Exception * @throws
*/ */
public function getIterator(): Traversable|CollectionIterator|ArrayIterator public function getIterator(): Traversable|CollectionIterator|ArrayIterator
{ {
@@ -114,7 +114,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/** /**
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
public function getModel(): ModelInterface public function getModel(): ModelInterface
{ {
@@ -143,7 +143,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/** /**
* @param mixed $offset * @param mixed $offset
* @return ModelInterface|null * @return ModelInterface|null
* @throws Exception * @throws
*/ */
public function offsetGet(mixed $offset): ?ModelInterface public function offsetGet(mixed $offset): ?ModelInterface
{ {
@@ -160,7 +160,8 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
* @param mixed $offset * @param mixed $offset
* @param mixed $value * @param mixed $value
*/ */
#[ReturnTypeWillChange] public function offsetSet(mixed $offset, mixed $value) #[ReturnTypeWillChange]
public function offsetSet(mixed $offset, mixed $value): void
{ {
$this->_item[$offset] = $value; $this->_item[$offset] = $value;
} }
@@ -169,7 +170,8 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/** /**
* @param mixed $offset * @param mixed $offset
*/ */
#[ReturnTypeWillChange] public function offsetUnset(mixed $offset) #[ReturnTypeWillChange]
public function offsetUnset(mixed $offset): void
{ {
if ($this->offsetExists($offset)) { if ($this->offsetExists($offset)) {
unset($this->_item[$offset]); unset($this->_item[$offset]);
+3 -4
View File
@@ -19,13 +19,12 @@ class CollectionIterator extends \ArrayIterator
private ModelInterface|string $model; private ModelInterface|string $model;
/** /**
* CollectionIterator constructor. * CollectionIterator constructor.
* @param $model * @param $model
* @param array $array * @param array $array
* @param int $flags * @param int $flags
* @throws Exception * @throws
*/ */
public function __construct($model, array $array = [], int $flags = 0) public function __construct($model, array $array = [], int $flags = 0)
{ {
@@ -37,7 +36,7 @@ class CollectionIterator extends \ArrayIterator
/** /**
* @param $current * @param $current
* @return ModelInterface * @return ModelInterface
* @throws Exception * @throws
*/ */
protected function newModel($current): ModelInterface protected function newModel($current): ModelInterface
{ {
@@ -46,7 +45,7 @@ class CollectionIterator extends \ArrayIterator
/** /**
* @throws Exception * @throws
*/ */
public function current(): ModelInterface public function current(): ModelInterface
{ {
+36 -36
View File
@@ -173,7 +173,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return string * @return string
* @throws Exception * @throws
* get last exception or other error * get last exception or other error
*/ */
public function getLastError(): string public function getLastError(): string
@@ -184,7 +184,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public function hasPrimary(): bool public function hasPrimary(): bool
{ {
@@ -193,7 +193,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return null|string * @return null|string
* @throws Exception * @throws
*/ */
public function getPrimary(): ?string public function getPrimary(): ?string
{ {
@@ -206,7 +206,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public function hasPrimaryValue(): bool public function hasPrimaryValue(): bool
{ {
@@ -219,7 +219,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return int|null * @return int|null
* @throws Exception * @throws
*/ */
public function getPrimaryValue(): ?int public function getPrimaryValue(): ?int
{ {
@@ -233,7 +233,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
* @param int|string|array $param * @param int|string|array $param
* @param null $db * @param null $db
* @return Model|null * @return Model|null
* @throws Exception * @throws
*/ */
public static function findOne(int|string|array $param, $db = NULL): ?static public static function findOne(int|string|array $param, $db = NULL): ?static
{ {
@@ -254,7 +254,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
* @param int $param * @param int $param
* @param null $db * @param null $db
* @return Model|null * @return Model|null
* @throws Exception * @throws
*/ */
public static function primary(int $param, $db = NULL): ?static public static function primary(int $param, $db = NULL): ?static
{ {
@@ -267,7 +267,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
public function optimize(): mixed public function optimize(): mixed
{ {
@@ -287,7 +287,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param int|string|array $condition * @param int|string|array $condition
* @return static|null * @return static|null
* @throws Exception * @throws
*/ */
public static function first(int|string|array $condition): ?static public static function first(int|string|array $condition): ?static
{ {
@@ -298,7 +298,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param string|array $condition * @param string|array $condition
* @return Collection * @return Collection
* @throws Exception * @throws
*/ */
public static function all(string|array $condition): Collection public static function all(string|array $condition): Collection
{ {
@@ -315,7 +315,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return ActiveQuery * @return ActiveQuery
* @throws Exception * @throws
*/ */
public static function query(): ActiveQuery public static function query(): ActiveQuery
{ {
@@ -327,7 +327,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return Connection * @return Connection
* @throws Exception * @throws
*/ */
public function getConnection(): Connection public function getConnection(): Connection
{ {
@@ -340,7 +340,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
* @param array $attributes * @param array $attributes
* *
* @return bool * @return bool
* @throws Exception * @throws
*/ */
protected static function deleteByCondition(array|string|null $condition = NULL, array $attributes = []): bool protected static function deleteByCondition(array|string|null $condition = NULL, array $attributes = []): bool
{ {
@@ -356,7 +356,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return array * @return array
* @throws Exception * @throws
*/ */
public function getAttributes(): array public function getAttributes(): array
{ {
@@ -402,7 +402,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param array $param * @param array $param
* @return $this * @return $this
* @throws Exception * @throws
*/ */
public function setAttributes(array $param): static public function setAttributes(array $param): static
{ {
@@ -428,7 +428,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return $this|bool * @return $this|bool
* @throws Exception * @throws
*/ */
private function insert(): bool|static private function insert(): bool|static
{ {
@@ -449,7 +449,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
* @param array $condition * @param array $condition
* @param array $change * @param array $change
* @return $this|bool * @return $this|bool
* @throws Exception * @throws
*/ */
protected function updateInternal(array $old, array $condition, array $change): bool|static protected function updateInternal(array $old, array $condition, array $change): bool|static
{ {
@@ -469,7 +469,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return bool|$this * @return bool|$this
* @throws Exception * @throws
*/ */
public function save(): static|bool public function save(): static|bool
{ {
@@ -488,7 +488,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return array<array, array> * @return array<array, array>
* @throws Exception * @throws
*/ */
private function diff(): array private function diff(): array
{ {
@@ -518,7 +518,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param array $rule * @param array $rule
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public function validator(array $rule): bool public function validator(array $rule): bool
{ {
@@ -536,7 +536,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param $rule * @param $rule
* @return Validator * @return Validator
* @throws Exception * @throws
*/ */
private function resolve($rule): Validator private function resolve($rule): Validator
{ {
@@ -552,7 +552,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param string $name * @param string $name
* @return null * @return null
* @throws Exception * @throws
*/ */
public function getAttribute(string $name) public function getAttribute(string $name)
{ {
@@ -562,7 +562,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return Relation|null * @return Relation|null
* @throws ReflectionException * @throws
*/ */
public function getRelation(): ?Relation public function getRelation(): ?Relation
{ {
@@ -573,7 +573,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param $attribute * @param $attribute
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public function has($attribute): bool public function has($attribute): bool
{ {
@@ -582,7 +582,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/**ƒ /**ƒ
* @return string * @return string
* @throws Exception * @throws
*/ */
public function getTable(): string public function getTable(): string
{ {
@@ -613,7 +613,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param self $model * @param self $model
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public function beforeSave(self $model): bool public function beforeSave(self $model): bool
{ {
@@ -633,7 +633,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param $name * @param $name
* @param $value * @param $value
* @throws Exception * @throws
*/ */
public function __set($name, $value): void public function __set($name, $value): void
{ {
@@ -652,7 +652,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param $name * @param $name
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
public function __get($name): mixed public function __get($name): mixed
{ {
@@ -669,7 +669,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
* @param $name * @param $name
* @param null $value * @param null $value
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
protected function withPropertyOverride($name, $value = null): mixed protected function withPropertyOverride($name, $value = null): mixed
{ {
@@ -720,7 +720,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param mixed $offset * @param mixed $offset
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public function offsetExists(mixed $offset): bool public function offsetExists(mixed $offset): bool
{ {
@@ -730,7 +730,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param mixed $offset * @param mixed $offset
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
public function offsetGet(mixed $offset): mixed public function offsetGet(mixed $offset): mixed
{ {
@@ -740,18 +740,18 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @param mixed $offset * @param mixed $offset
* @param mixed $value * @param mixed $value
* @throws Exception * @throws
*/ */
#[ReturnTypeWillChange] public function offsetSet(mixed $offset, mixed $value) #[ReturnTypeWillChange] public function offsetSet(mixed $offset, mixed $value): void
{ {
$this->__set($offset, $value); $this->__set($offset, $value);
} }
/** /**
* @param mixed $offset * @param mixed $offset
* @throws Exception * @throws
*/ */
#[ReturnTypeWillChange] public function offsetUnset(mixed $offset) #[ReturnTypeWillChange] public function offsetUnset(mixed $offset): void
{ {
if (!isset($this->_attributes[$offset]) && !isset($this->_oldAttributes[$offset])) { if (!isset($this->_attributes[$offset]) && !isset($this->_oldAttributes[$offset])) {
return; return;
@@ -772,7 +772,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
/** /**
* @return Columns * @return Columns
* @throws Exception * @throws
*/ */
public function getColumns(): Columns public function getColumns(): Columns
{ {
+4 -4
View File
@@ -34,7 +34,7 @@ class Collection extends AbstractCollection
* @param $field * @param $field
* *
* @return array|null * @return array|null
* @throws Exception * @throws
*/ */
public function values($field): ?array public function values($field): ?array
{ {
@@ -54,7 +54,7 @@ class Collection extends AbstractCollection
/** /**
* @param array $attributes * @param array $attributes
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public function update(array $attributes): bool public function update(array $attributes): bool
{ {
@@ -176,7 +176,7 @@ class Collection extends AbstractCollection
} }
/** /**
* @throws Exception * @throws
* 批量删除 * 批量删除
*/ */
public function delete(): bool public function delete(): bool
@@ -213,7 +213,7 @@ class Collection extends AbstractCollection
* @param $value * @param $value
* @param $condition * @param $condition
* @return bool * @return bool
* @throws Exception * @throws
*/ */
private function filterCheck($value, $condition): bool private function filterCheck($value, $condition): bool
{ {
+12 -13
View File
@@ -13,7 +13,6 @@ namespace Database;
use Exception; use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Di\Container; use Kiri\Di\Container;
use Kiri\Exception\ConfigException;
use PDO; use PDO;
use PDOStatement; use PDOStatement;
use Throwable; use Throwable;
@@ -32,7 +31,7 @@ class Command extends Component
/** /**
* @param array $params * @param array $params
* @throws Exception * @throws
*/ */
public function __construct(array $params = []) public function __construct(array $params = [])
{ {
@@ -43,7 +42,7 @@ class Command extends Component
/** /**
* @return int|bool * @return int|bool
* @throws Exception * @throws
*/ */
public function incrOrDecr(): int|bool public function incrOrDecr(): int|bool
{ {
@@ -52,7 +51,7 @@ class Command extends Component
/** /**
* @return int|bool * @return int|bool
* @throws Exception * @throws
*/ */
public function save(): int|bool public function save(): int|bool
{ {
@@ -62,7 +61,7 @@ class Command extends Component
/** /**
* @return bool|array * @return bool|array
* @throws Exception * @throws
*/ */
public function all(): bool|array public function all(): bool|array
{ {
@@ -71,7 +70,7 @@ class Command extends Component
/** /**
* @return bool|array|null * @return bool|array|null
* @throws Exception * @throws
*/ */
public function one(): null|bool|array public function one(): null|bool|array
{ {
@@ -80,7 +79,7 @@ class Command extends Component
/** /**
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
public function fetchColumn(): mixed public function fetchColumn(): mixed
{ {
@@ -91,7 +90,7 @@ class Command extends Component
/** /**
* @param string $method * @param string $method
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
protected function search(string $method): mixed protected function search(string $method): mixed
{ {
@@ -117,7 +116,7 @@ class Command extends Component
/** /**
* @return int|bool * @return int|bool
* @throws Exception * @throws
*/ */
public function flush(): int|bool public function flush(): int|bool
{ {
@@ -127,7 +126,7 @@ class Command extends Component
/** /**
* @return PDOStatement|int * @return PDOStatement|int
* @throws Exception * @throws
*/ */
private function _prepare(): bool|int private function _prepare(): bool|int
{ {
@@ -186,7 +185,7 @@ class Command extends Component
/** /**
* @return int|bool * @return int|bool
* @throws Exception * @throws
*/ */
public function delete(): int|bool public function delete(): int|bool
{ {
@@ -195,7 +194,7 @@ class Command extends Component
/** /**
* @return int|bool * @return int|bool
* @throws Exception * @throws
*/ */
public function exec(): int|bool public function exec(): int|bool
{ {
@@ -217,7 +216,7 @@ class Command extends Component
/** /**
* @param $sql * @param $sql
* @return $this * @return $this
* @throws Exception * @throws
*/ */
public function setSql($sql): static public function setSql($sql): static
{ {
+1 -1
View File
@@ -12,7 +12,7 @@ class HashCondition extends Condition
/** /**
* @return string * @return string
* @throws \Exception * @throws
*/ */
public function builder(): string public function builder(): string
{ {
+1 -2
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
use Exception;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
/** /**
@@ -16,7 +15,7 @@ class InCondition extends Condition
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
#[Pure] public function builder(): string #[Pure] public function builder(): string
{ {
+5 -1
View File
@@ -12,9 +12,13 @@ class JsonCondition extends Condition
{ {
public function builder() /**
* @return bool
*/
public function builder(): bool
{ {
// TODO: Implement builder() method. // TODO: Implement builder() method.
return \json_validate($this->value);
} }
} }
+1 -1
View File
@@ -15,7 +15,7 @@ class NotInCondition extends Condition
/** /**
* @return string|null * @return string|null
* @throws \Exception * @throws
*/ */
#[Pure] public function builder(): ?string #[Pure] public function builder(): ?string
{ {
+1 -1
View File
@@ -283,7 +283,7 @@ class Connection extends Component
* @param null $sql * @param null $sql
* @param array $attributes * @param array $attributes
* @return Command * @return Command
* @throws Exception * @throws
*/ */
public function createCommand($sql = null, array $attributes = []): Command public function createCommand($sql = null, array $attributes = []): Command
{ {
+15 -29
View File
@@ -15,11 +15,6 @@ use Database\Affair\Commit;
use Database\Affair\Rollback; use Database\Affair\Rollback;
use Database\Traits\QueryTrait; use Database\Traits\QueryTrait;
use Exception; use Exception;
use Kiri;
use Kiri\Exception\ConfigException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
use Throwable; use Throwable;
/** /**
@@ -43,7 +38,7 @@ class Db implements ISqlBuilder
/** /**
* @param string|Connection $dbname * @param string|Connection $dbname
* @return Db * @return Db
* @throws Exception * @throws
*/ */
public static function connect(string|Connection $dbname): Db public static function connect(string|Connection $dbname): Db
{ {
@@ -57,9 +52,7 @@ class Db implements ISqlBuilder
/** /**
* @return void * @return void
* @throws ContainerExceptionInterface * @throws
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/ */
public static function beginTransaction(): void public static function beginTransaction(): void
{ {
@@ -71,9 +64,7 @@ class Db implements ISqlBuilder
* @param Closure $closure * @param Closure $closure
* @param mixed ...$params * @param mixed ...$params
* @return mixed * @return mixed
* @throws ContainerExceptionInterface * @throws
* @throws NotFoundExceptionInterface
* @throws Exception
*/ */
public static function Transaction(Closure $closure, ...$params): mixed public static function Transaction(Closure $closure, ...$params): mixed
{ {
@@ -95,9 +86,7 @@ class Db implements ISqlBuilder
/** /**
* @return void * @return void
* @throws ContainerExceptionInterface * @throws
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/ */
public static function commit(): void public static function commit(): void
{ {
@@ -107,9 +96,7 @@ class Db implements ISqlBuilder
/** /**
* @return void * @return void
* @throws ContainerExceptionInterface * @throws
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/ */
public static function rollback(): void public static function rollback(): void
{ {
@@ -147,7 +134,7 @@ class Db implements ISqlBuilder
/** /**
* @return array|bool * @return array|bool
* @throws Exception * @throws
*/ */
public function get(): array|bool public function get(): array|bool
{ {
@@ -156,7 +143,7 @@ class Db implements ISqlBuilder
/** /**
* @return array|bool|null * @return array|bool|null
* @throws Exception * @throws
*/ */
public function first(): array|bool|null public function first(): array|bool|null
{ {
@@ -165,7 +152,7 @@ class Db implements ISqlBuilder
/** /**
* @return bool|int * @return bool|int
* @throws Exception * @throws
*/ */
public function count(): bool|int public function count(): bool|int
{ {
@@ -174,7 +161,7 @@ class Db implements ISqlBuilder
/** /**
* @return bool|int * @return bool|int
* @throws Exception * @throws
*/ */
public function exists(): bool|int public function exists(): bool|int
{ {
@@ -185,7 +172,7 @@ class Db implements ISqlBuilder
* @param string $sql * @param string $sql
* @param array $attributes * @param array $attributes
* @return array|bool|int|string|null * @return array|bool|int|string|null
* @throws Exception * @throws
*/ */
public function query(string $sql, array $attributes = []): int|bool|array|string|null public function query(string $sql, array $attributes = []): int|bool|array|string|null
{ {
@@ -196,7 +183,7 @@ class Db implements ISqlBuilder
* @param string $sql * @param string $sql
* @param array $attributes * @param array $attributes
* @return array|bool|int|string|null * @return array|bool|int|string|null
* @throws Exception * @throws
*/ */
public function one(string $sql, array $attributes = []): int|bool|array|string|null public function one(string $sql, array $attributes = []): int|bool|array|string|null
{ {
@@ -206,8 +193,7 @@ class Db implements ISqlBuilder
/** /**
* @return bool|int * @return bool|int
* @throws ConfigException * @throws
* @throws Exception
*/ */
public function delete(): bool|int public function delete(): bool|int
{ {
@@ -217,7 +203,7 @@ class Db implements ISqlBuilder
/** /**
* @param string $table * @param string $table
* @return array|bool|null * @return array|bool|null
* @throws Exception * @throws
*/ */
public static function show(string $table): array|bool|null public static function show(string $table): array|bool|null
{ {
@@ -240,7 +226,7 @@ class Db implements ISqlBuilder
* @param Connection|null $connection * @param Connection|null $connection
* @param string $database * @param string $database
* @return array|null * @return array|null
* @throws Exception * @throws
*/ */
public static function desc(string $table, ?Connection $connection = null, string $database = 'db'): ?array public static function desc(string $table, ?Connection $connection = null, string $database = 'db'): ?array
{ {
@@ -256,7 +242,7 @@ class Db implements ISqlBuilder
* @param null|Connection $connection * @param null|Connection $connection
* @param string $database * @param string $database
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
public static function getDefaultConnection(?Connection $connection = null, string $database = 'db'): Connection public static function getDefaultConnection(?Connection $connection = null, string $database = 'db'): Connection
{ {
+1 -1
View File
@@ -16,7 +16,7 @@ class HasCount extends HasBase
/** /**
* @return array|null|ModelInterface * @return array|null|ModelInterface
* @throws Exception * @throws
*/ */
public function get(): array|ModelInterface|null public function get(): array|ModelInterface|null
{ {
+1 -1
View File
@@ -24,7 +24,7 @@ class HasMany extends HasBase
/** /**
* @return array|null|Collection * @return array|null|Collection
* @throws Exception * @throws
*/ */
public function get(): array|Collection|null public function get(): array|Collection|null
{ {
+1 -1
View File
@@ -23,7 +23,7 @@ class HasOne extends HasBase
/** /**
* @return array|null|ModelInterface * @return array|null|ModelInterface
* @throws Exception * @throws
*/ */
public function get(): array|ModelInterface|null public function get(): array|ModelInterface|null
{ {
+2 -3
View File
@@ -31,7 +31,6 @@ class ImplodeCommand extends Command
public string $description = 'php kiri.php db:implode --database users /Users/admin/snowflake-bi/test.sql'; public string $description = 'php kiri.php db:implode --database users /Users/admin/snowflake-bi/test.sql';
/** /**
* @var Channel * @var Channel
*/ */
@@ -43,7 +42,7 @@ class ImplodeCommand extends Command
/** /**
* *
*/ */
protected function configure() protected function configure(): void
{ {
$this->setName('db:implode') $this->setName('db:implode')
->addArgument('path', InputArgument::REQUIRED, "save to path", null) ->addArgument('path', InputArgument::REQUIRED, "save to path", null)
@@ -57,7 +56,7 @@ class ImplodeCommand extends Command
* @param InputInterface $input * @param InputInterface $input
* @param OutputInterface $output * @param OutputInterface $output
* @return int * @return int
* @throws Exception * @throws
*/ */
public function execute(InputInterface $input, OutputInterface $output): int public function execute(InputInterface $input, OutputInterface $output): int
{ {
+19 -23
View File
@@ -11,8 +11,6 @@ namespace Database;
use Exception; use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
defined('SAVE_FAIL') or define('SAVE_FAIL', 3227); defined('SAVE_FAIL') or define('SAVE_FAIL', 3227);
defined('FIND_OR_CREATE_MESSAGE') or define('FIND_OR_CREATE_MESSAGE', 'Create a new model, but the data cannot be empty.'); defined('FIND_OR_CREATE_MESSAGE') or define('FIND_OR_CREATE_MESSAGE', 'Create a new model, but the data cannot be empty.');
@@ -32,7 +30,7 @@ class Model extends Base\Model
* @param string $column * @param string $column
* @param int|float $value * @param int|float $value
* @return ModelInterface|false * @return ModelInterface|false
* @throws Exception * @throws
*/ */
public function increment(string $column, int|float $value): bool|ModelInterface public function increment(string $column, int|float $value): bool|ModelInterface
{ {
@@ -48,7 +46,7 @@ class Model extends Base\Model
* @param string $column * @param string $column
* @param int|float $value * @param int|float $value
* @return ModelInterface|false * @return ModelInterface|false
* @throws Exception * @throws
*/ */
public function decrement(string $column, int|float $value): bool|ModelInterface public function decrement(string $column, int|float $value): bool|ModelInterface
{ {
@@ -63,7 +61,7 @@ class Model extends Base\Model
/** /**
* @param array $columns * @param array $columns
* @return ModelInterface|false * @return ModelInterface|false
* @throws Exception * @throws
*/ */
public function increments(array $columns): bool|static public function increments(array $columns): bool|static
{ {
@@ -80,7 +78,7 @@ class Model extends Base\Model
/** /**
* @param array $columns * @param array $columns
* @return ModelInterface|false * @return ModelInterface|false
* @throws Exception * @throws
*/ */
public function decrements(array $columns): bool|static public function decrements(array $columns): bool|static
{ {
@@ -97,8 +95,7 @@ class Model extends Base\Model
* @param array $condition * @param array $condition
* @param array $attributes * @param array $attributes
* @return bool|static * @return bool|static
* @throws ContainerExceptionInterface * @throws
* @throws NotFoundExceptionInterface
*/ */
public static function findOrCreate(array $condition, array $attributes): bool|static public static function findOrCreate(array $condition, array $attributes): bool|static
{ {
@@ -117,8 +114,7 @@ class Model extends Base\Model
* @param array $condition * @param array $condition
* @param array $attributes * @param array $attributes
* @return bool|static * @return bool|static
* @throws ContainerExceptionInterface * @throws
* @throws NotFoundExceptionInterface
*/ */
public static function createOrUpdate(array $condition, array $attributes = []): bool|static public static function createOrUpdate(array $condition, array $attributes = []): bool|static
{ {
@@ -138,7 +134,7 @@ class Model extends Base\Model
* @param $columns * @param $columns
* @param $action * @param $action
* @return array|bool|int|string|null * @return array|bool|int|string|null
* @throws Exception * @throws
*/ */
private function mathematics($columns, $action): int|bool|array|string|null private function mathematics($columns, $action): int|bool|array|string|null
{ {
@@ -156,7 +152,7 @@ class Model extends Base\Model
/** /**
* @param array $params * @param array $params
* @return ModelInterface|bool * @return ModelInterface|bool
* @throws Exception * @throws
*/ */
public function update(array $params): static|bool public function update(array $params): static|bool
{ {
@@ -175,7 +171,7 @@ class Model extends Base\Model
/** /**
* @param array $data * @param array $data
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public static function inserts(array $data): bool public static function inserts(array $data): bool
{ {
@@ -187,7 +183,7 @@ class Model extends Base\Model
/** /**
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public function delete(): bool public function delete(): bool
{ {
@@ -209,7 +205,7 @@ class Model extends Base\Model
* @param array $attributes * @param array $attributes
* *
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public static function updateAll(mixed $condition, array $attributes = []): bool public static function updateAll(mixed $condition, array $attributes = []): bool
{ {
@@ -220,7 +216,7 @@ class Model extends Base\Model
/** /**
* @param $condition * @param $condition
* @return array|Collection * @return array|Collection
* @throws Exception * @throws
*/ */
public static function get($condition): Collection|array public static function get($condition): Collection|array
{ {
@@ -233,7 +229,7 @@ class Model extends Base\Model
* @param array $attributes * @param array $attributes
* *
* @return array|Collection * @return array|Collection
* @throws Exception * @throws
*/ */
public static function findAll($condition, array $attributes = []): array|Collection public static function findAll($condition, array $attributes = []): array|Collection
{ {
@@ -247,7 +243,7 @@ class Model extends Base\Model
/** /**
* @return array * @return array
* @throws Exception * @throws
*/ */
public function toArray(): array public function toArray(): array
{ {
@@ -286,7 +282,7 @@ class Model extends Base\Model
* @param $foreignKey * @param $foreignKey
* @param $localKey * @param $localKey
* @return string * @return string
* @throws Exception * @throws
*/ */
private function _hasBase(ModelInterface|string $modelName, $foreignKey, $localKey): string private function _hasBase(ModelInterface|string $modelName, $foreignKey, $localKey): string
{ {
@@ -309,7 +305,7 @@ class Model extends Base\Model
* @param $foreignKey * @param $foreignKey
* @param $localKey * @param $localKey
* @return HasOne|ActiveQuery * @return HasOne|ActiveQuery
* @throws Exception * @throws
*/ */
public function hasOne(ModelInterface|string $modelName, $foreignKey, $localKey): HasOne|ActiveQuery public function hasOne(ModelInterface|string $modelName, $foreignKey, $localKey): HasOne|ActiveQuery
{ {
@@ -322,7 +318,7 @@ class Model extends Base\Model
* @param $foreignKey * @param $foreignKey
* @param $localKey * @param $localKey
* @return ActiveQuery|HasCount * @return ActiveQuery|HasCount
* @throws Exception * @throws
*/ */
public function hasCount(ModelInterface|string $modelName, $foreignKey, $localKey): ActiveQuery|HasCount public function hasCount(ModelInterface|string $modelName, $foreignKey, $localKey): ActiveQuery|HasCount
{ {
@@ -335,7 +331,7 @@ class Model extends Base\Model
* @param $foreignKey * @param $foreignKey
* @param $localKey * @param $localKey
* @return ActiveQuery|HasMany * @return ActiveQuery|HasMany
* @throws Exception * @throws
*/ */
public function hasMany(ModelInterface|string $modelName, $foreignKey, $localKey): ActiveQuery|HasMany public function hasMany(ModelInterface|string $modelName, $foreignKey, $localKey): ActiveQuery|HasMany
{ {
@@ -347,7 +343,7 @@ class Model extends Base\Model
* @param $foreignKey * @param $foreignKey
* @param $localKey * @param $localKey
* @return ActiveQuery|HasMany * @return ActiveQuery|HasMany
* @throws Exception * @throws
*/ */
public function hasIn(ModelInterface|string $modelName, $foreignKey, $localKey): ActiveQuery|HasMany public function hasIn(ModelInterface|string $modelName, $foreignKey, $localKey): ActiveQuery|HasMany
{ {
+17 -18
View File
@@ -13,7 +13,6 @@ namespace Database\Mysql;
use Database\Connection; use Database\Connection;
use Database\SqlBuilder; use Database\SqlBuilder;
use Exception;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Core\Json; use Kiri\Core\Json;
@@ -44,7 +43,7 @@ class Columns extends Component
/** /**
* @param string $table * @param string $table
* @return $this * @return $this
* @throws Exception * @throws
*/ */
public function table(string $table): static public function table(string $table): static
{ {
@@ -64,7 +63,7 @@ class Columns extends Component
* @param $key * @param $key
* @param $val * @param $val
* @return string|int|bool|float * @return string|int|bool|float
* @throws Exception * @throws
*/ */
public function fieldFormat($key, $val): string|int|bool|float public function fieldFormat($key, $val): string|int|bool|float
{ {
@@ -115,7 +114,7 @@ class Columns extends Component
* @param string $name * @param string $name
* @param $value * @param $value
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
public function _decode(string $name, $value): mixed public function _decode(string $name, $value): mixed
{ {
@@ -127,7 +126,7 @@ class Columns extends Component
* @param $val * @param $val
* @param null $format * @param null $format
* @return float|bool|int|string * @return float|bool|int|string
* @throws Exception * @throws
*/ */
public function encode($val, $format = null): float|bool|int|string public function encode($val, $format = null): float|bool|int|string
{ {
@@ -195,7 +194,7 @@ class Columns extends Component
/** /**
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
public function getFields(): array public function getFields(): array
{ {
@@ -209,7 +208,7 @@ class Columns extends Component
/** /**
* @param string $name * @param string $name
* @return bool * @return bool
* @throws Exception * @throws
*/ */
public function hasField(string $name): bool public function hasField(string $name): bool
{ {
@@ -219,7 +218,7 @@ class Columns extends Component
/** /**
* @return int|string|null * @return int|string|null
* @throws Exception * @throws
*/ */
public function getAutoIncrement(): int|string|null public function getAutoIncrement(): int|string|null
{ {
@@ -229,7 +228,7 @@ class Columns extends Component
/** /**
* @return array|null|string * @return array|null|string
* *
* @throws Exception * @throws
*/ */
public function getPrimaryKeys(): array|string|null public function getPrimaryKeys(): array|string|null
{ {
@@ -242,7 +241,7 @@ class Columns extends Component
/** /**
* @return array|null|string * @return array|null|string
* *
* @throws Exception * @throws
*/ */
#[Pure] public function getFirstPrimary(): array|string|null #[Pure] public function getFirstPrimary(): array|string|null
{ {
@@ -259,7 +258,7 @@ class Columns extends Component
* @param $name * @param $name
* @param null $index * @param null $index
* @return array * @return array
* @throws Exception * @throws
*/ */
private function columns($name, $index = null): array private function columns($name, $index = null): array
{ {
@@ -272,7 +271,7 @@ class Columns extends Component
/** /**
* @return array|static * @return array|static
* @throws Exception * @throws
*/ */
private function getColumns(): array|static private function getColumns(): array|static
{ {
@@ -283,14 +282,14 @@ class Columns extends Component
/** /**
* @param $table * @param $table
* @return array|Columns * @return array|Columns
* @throws Exception * @throws
*/ */
private function structure($table): array|static private function structure($table): array|static
{ {
if (!isset($this->columns[$table]) || empty($this->columns[$table])) { if (!isset($this->columns[$table]) || empty($this->columns[$table])) {
$column = $this->db->createCommand(SqlBuilder::builder(null)->columns($table))->all(); $column = $this->db->createCommand(SqlBuilder::builder(null)->columns($table))->all();
if (empty($column)) { if (empty($column)) {
throw new Exception("The table " . $table . " not exists."); throw new \Exception("The table " . $table . " not exists.");
} }
return $this->columns[$table] = $this->resolve($column, $table); return $this->columns[$table] = $this->resolve($column, $table);
} }
@@ -319,7 +318,7 @@ class Columns extends Component
* @param $item * @param $item
* @param $table * @param $table
*/ */
private function addPrimary($item, $table) private function addPrimary($item, $table): void
{ {
if (!isset($this->_primary[$table])) { if (!isset($this->_primary[$table])) {
$this->_primary[$table] = []; $this->_primary[$table] = [];
@@ -335,7 +334,7 @@ class Columns extends Component
* @param $item * @param $item
* @param $table * @param $table
*/ */
private function addIncrement($item, $table) private function addIncrement($item, $table): void
{ {
if ($item['Extra'] !== 'auto_increment') { if ($item['Extra'] !== 'auto_increment') {
return; return;
@@ -363,7 +362,7 @@ class Columns extends Component
/** /**
* @param null $field * @param null $field
* @return array|string|null * @return array|string|null
* @throws Exception * @throws
*/ */
public function get_fields($field = null): array|string|null public function get_fields($field = null): array|string|null
{ {
@@ -379,7 +378,7 @@ class Columns extends Component
/** /**
* @return array * @return array
* @throws Exception * @throws
*/ */
public function getAllField(): array public function getAllField(): array
{ {
+1 -2
View File
@@ -3,7 +3,6 @@ declare(strict_types=1);
namespace Database\Mysql; namespace Database\Mysql;
use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Database\Connection; use Database\Connection;
@@ -23,7 +22,7 @@ class Schema extends Component
/** /**
* @return Columns|null * @return Columns|null
* @throws Exception * @throws
*/ */
public function getColumns(): ?Columns public function getColumns(): ?Columns
{ {
+1 -2
View File
@@ -5,7 +5,6 @@ namespace Database\Orm;
use Database\Traits\Builder; use Database\Traits\Builder;
use Exception;
/** /**
* Trait Condition * Trait Condition
@@ -20,7 +19,7 @@ trait Condition
/** /**
* @param $query * @param $query
* @return string * @return string
* @throws Exception * @throws
*/ */
public function getWhere($query): string public function getWhere($query): string
{ {
+7 -7
View File
@@ -38,7 +38,7 @@ class Pagination extends Component
* PaginationIteration constructor. * PaginationIteration constructor.
* @param ActiveQuery $activeQuery * @param ActiveQuery $activeQuery
* @param array $config * @param array $config
* @throws Exception * @throws
*/ */
public function __construct(ActiveQuery $activeQuery, array $config = []) public function __construct(ActiveQuery $activeQuery, array $config = [])
{ {
@@ -71,9 +71,9 @@ class Pagination extends Component
/** /**
* @param array|Closure $callback * @param array|Closure $callback
* @throws Exception * @throws
*/ */
public function setCallback(array|Closure $callback) public function setCallback(array|Closure $callback): void
{ {
if (!is_callable($callback, true)) { if (!is_callable($callback, true)) {
throw new Exception('非法回调函数~'); throw new Exception('非法回调函数~');
@@ -129,7 +129,7 @@ class Pagination extends Component
/** /**
* @param array $param * @param array $param
* @return void * @return void
* @throws Exception * @throws
*/ */
public function plunk(array $param = []): void public function plunk(array $param = []): void
{ {
@@ -141,7 +141,7 @@ class Pagination extends Component
* 轮训 * 轮训
* @param $param * @param $param
* @return array * @return array
* @throws Exception * @throws
*/ */
public function loop($param): array public function loop($param): array
{ {
@@ -175,7 +175,7 @@ class Pagination extends Component
/** /**
* @param $data * @param $data
* @param $param * @param $param
* @throws Exception * @throws
*/ */
private function executed($data, $param): void private function executed($data, $param): void
{ {
@@ -189,7 +189,7 @@ class Pagination extends Component
/** /**
* @return array|Collection * @return array|Collection
* @throws Exception * @throws
*/ */
private function get(): Collection|array private function get(): Collection|array
{ {
+3 -4
View File
@@ -11,7 +11,6 @@ namespace Database;
use Database\Traits\QueryTrait; use Database\Traits\QueryTrait;
use Exception;
/** /**
* Class Query * Class Query
@@ -24,7 +23,7 @@ class Query implements ISqlBuilder
/** /**
* @throws Exception * @throws
*/ */
public function __construct() public function __construct()
{ {
@@ -33,7 +32,7 @@ class Query implements ISqlBuilder
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
public function getSql(): string public function getSql(): string
{ {
@@ -43,7 +42,7 @@ class Query implements ISqlBuilder
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
public function getCondition(): string public function getCondition(): string
{ {
+2 -12
View File
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Database; namespace Database;
use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Di\Context; use Kiri\Di\Context;
@@ -51,7 +50,7 @@ class Relation extends Component
/** /**
* @param string $_identification * @param string $_identification
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
public function first(string $_identification): mixed public function first(string $_identification): mixed
{ {
@@ -59,9 +58,6 @@ class Relation extends Component
return Context::get($_identification); return Context::get($_identification);
} }
$activeModel = $this->_query[$_identification]->first(); $activeModel = $this->_query[$_identification]->first();
if (empty($activeModel)) {
return $this->_query[$_identification]->mock();
}
unset($this->_query[$_identification]); unset($this->_query[$_identification]);
return Context::set($_identification, $activeModel); return Context::set($_identification, $activeModel);
} }
@@ -77,9 +73,6 @@ class Relation extends Component
return Context::get($_identification); return Context::get($_identification);
} }
$activeModel = $this->_query[$_identification]->count(); $activeModel = $this->_query[$_identification]->count();
if (empty($activeModel)) {
return $this->_query[$_identification]->mock();
}
unset($this->_query[$_identification]); unset($this->_query[$_identification]);
return Context::set($_identification, $activeModel); return Context::set($_identification, $activeModel);
} }
@@ -88,7 +81,7 @@ class Relation extends Component
/** /**
* @param string $_identification * @param string $_identification
* @return mixed * @return mixed
* @throws Exception * @throws
*/ */
public function get(string $_identification): mixed public function get(string $_identification): mixed
{ {
@@ -96,9 +89,6 @@ class Relation extends Component
return Context::get($_identification); return Context::get($_identification);
} }
$activeModel = $this->_query[$_identification]->get(); $activeModel = $this->_query[$_identification]->get();
if (empty($activeModel)) {
return $activeModel;
}
unset($this->_query[$_identification]); unset($this->_query[$_identification]);
return Context::set($_identification, $activeModel); return Context::set($_identification, $activeModel);
} }
+15 -16
View File
@@ -6,7 +6,6 @@ namespace Database;
use Database\Traits\Builder; use Database\Traits\Builder;
use Exception;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
@@ -41,7 +40,7 @@ class SqlBuilder extends Component
/** /**
* @param ISqlBuilder|null $query * @param ISqlBuilder|null $query
* @return $this * @return $this
* @throws Exception * @throws
*/ */
public static function builder(ISqlBuilder|null $query): static public static function builder(ISqlBuilder|null $query): static
{ {
@@ -51,7 +50,7 @@ class SqlBuilder extends Component
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
public function getCondition(): string public function getCondition(): string
{ {
@@ -62,7 +61,7 @@ class SqlBuilder extends Component
/** /**
* @param array $compiler * @param array $compiler
* @return string * @return string
* @throws Exception * @throws
*/ */
public function hashCompiler(array $compiler): string public function hashCompiler(array $compiler): string
{ {
@@ -73,7 +72,7 @@ class SqlBuilder extends Component
/** /**
* @param array $attributes * @param array $attributes
* @return bool|array * @return bool|array
* @throws Exception * @throws
*/ */
public function update(array $attributes): bool|string public function update(array $attributes): bool|string
{ {
@@ -91,7 +90,7 @@ class SqlBuilder extends Component
* @param array $attributes * @param array $attributes
* @param string $opera * @param string $opera
* @return bool|array * @return bool|array
* @throws Exception * @throws
*/ */
public function mathematics(array $attributes, string $opera = '+'): bool|string public function mathematics(array $attributes, string $opera = '+'): bool|string
{ {
@@ -106,7 +105,7 @@ class SqlBuilder extends Component
/** /**
* @param array $string * @param array $string
* @return string|bool * @return string|bool
* @throws Exception * @throws
*/ */
private function __updateBuilder(array $string): string|bool private function __updateBuilder(array $string): string|bool
{ {
@@ -121,7 +120,7 @@ class SqlBuilder extends Component
* @param array $attributes * @param array $attributes
* @param false $isBatch * @param false $isBatch
* @return array * @return array
* @throws Exception * @throws
*/ */
public function insert(array $attributes, bool $isBatch = false): array public function insert(array $attributes, bool $isBatch = false): array
{ {
@@ -145,7 +144,7 @@ class SqlBuilder extends Component
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
public function delete(): string public function delete(): string
{ {
@@ -209,7 +208,7 @@ class SqlBuilder extends Component
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
public function one(): string public function one(): string
{ {
@@ -222,7 +221,7 @@ class SqlBuilder extends Component
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
public function all(): string public function all(): string
{ {
@@ -235,7 +234,7 @@ class SqlBuilder extends Component
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
public function count(): string public function count(): string
{ {
@@ -255,7 +254,7 @@ class SqlBuilder extends Component
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
private function _prefix(): string private function _prefix(): string
{ {
@@ -292,7 +291,7 @@ class SqlBuilder extends Component
/** /**
* @param false $isCount * @param false $isCount
* @return string * @return string
* @throws Exception * @throws
*/ */
public function get(bool $isCount = false): string public function get(bool $isCount = false): string
{ {
@@ -305,7 +304,7 @@ class SqlBuilder extends Component
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
public function truncate(): string public function truncate(): string
{ {
@@ -315,7 +314,7 @@ class SqlBuilder extends Component
/** /**
* @return string * @return string
* @throws Exception * @throws
*/ */
private function conditionToString(): string private function conditionToString(): string
{ {
+3 -4
View File
@@ -37,7 +37,7 @@ trait Builder
/** /**
* @param $table * @param $table
* @return string * @return string
* @throws Exception * @throws
*/ */
private function builderFrom($table): string private function builderFrom($table): string
{ {
@@ -127,8 +127,7 @@ trait Builder
* @param $condition * @param $condition
* @param $_tmp * @param $_tmp
* @return string * @return string
* @throws NotFindClassException * @throws
* @throws ReflectionException|Exception
*/ */
private function resolveCondition($field, $condition, $_tmp): string private function resolveCondition($field, $condition, $_tmp): string
{ {
@@ -147,7 +146,7 @@ trait Builder
* @param $condition * @param $condition
* @param $array * @param $array
* @return string * @return string
* @throws Exception * @throws
*/ */
private function _arrayMap($condition, $array): string private function _arrayMap($condition, $array): string
{ {
+1 -1
View File
@@ -51,7 +51,7 @@ abstract class HasBase implements \Database\Traits\Relation
* @param $name * @param $name
* @param $arguments * @param $arguments
* @return static * @return static
* @throws \ReflectionException * @throws
*/ */
public function __call($name, $arguments) public function __call($name, $arguments)
{ {
-24
View File
@@ -38,8 +38,6 @@ trait QueryTrait
public bool $lock = false; public bool $lock = false;
public bool $ifNotWhere = false;
private SqlBuilder $builder; private SqlBuilder $builder;
@@ -310,28 +308,6 @@ trait QueryTrait
return $this->join("INNER JOIN " . $tableName, $alias, $onCondition, $param); return $this->join("INNER JOIN " . $tableName, $alias, $onCondition, $param);
} }
/**
* @param $array
*
* @return string
*/
private function toString($array): string
{
$tmp = [];
if (!is_array($array)) {
return $array;
}
foreach ($array as $key => $val) {
if (is_array($val)) {
$tmp[] = $this->toString($array);
} else {
$tmp[] = $key . '=:' . $key;
$this->attributes[':' . $key] = $val;
}
}
return implode(' AND ', $tmp);
}
/** /**
* @param string $field * @param string $field
* *
+1 -1
View File
@@ -41,7 +41,7 @@ class When
* @param string|int $condition * @param string|int $condition
* @param string $then * @param string $then
* @return $this * @return $this
* @throws Exception * @throws
*/ */
public function when(string|int $condition, string $then): static public function when(string|int $condition, string $then): static
{ {
+1 -1
View File
@@ -9,7 +9,7 @@
], ],
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": ">=8.0", "php": ">=8.3",
"ext-json": "*", "ext-json": "*",
"ext-pdo": "*", "ext-pdo": "*",
"game-worker/kiri-pool": "~v1.0" "game-worker/kiri-pool": "~v1.0"