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