Compare commits

...

11 Commits

Author SHA1 Message Date
as2252258 dad6a63ee2 Revert "改名"
This reverts commit fdf58326
2022-01-12 14:10:32 +08:00
as2252258 47ed967e46 Revert "改名"
This reverts commit fdf58326
2022-01-11 10:51:50 +08:00
as2252258 227aad2910 Revert "改名"
This reverts commit fdf58326
2022-01-10 11:39:56 +08:00
as2252258 5d77face53 1 2022-01-09 14:46:34 +08:00
as2252258 2109ed7667 e 2022-01-09 03:49:51 +08:00
as2252258 a45d71d760 1 2022-01-09 03:46:41 +08:00
as2252258 e71adc7cf3 1 2022-01-09 02:44:07 +08:00
as2252258 ef3e874c0c Revert "改名"
This reverts commit fdf58326
2022-01-08 18:49:06 +08:00
as2252258 614b601afa Revert "改名"
This reverts commit fdf58326
2022-01-07 14:38:36 +08:00
as2252258 cf2f26ec21 Revert "改名"
This reverts commit fdf58326
2022-01-04 17:27:37 +08:00
as2252258 2a52172af6 Revert "改名"
This reverts commit fdf58326
2022-01-04 16:04:22 +08:00
58 changed files with 7283 additions and 7366 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
<?php
namespace Database\Note;
namespace Database\Annotation;
use Attribute;
@@ -11,9 +11,9 @@ use Exception;
/**
* Class Get
* @package Note\Model
* @package Annotation\Model
*/
#[Attribute(Attribute::TARGET_METHOD)] class Get extends \Note\Attribute
#[Attribute(Attribute::TARGET_METHOD)] class Get extends \Annotation\Attribute
{
@@ -1,17 +1,17 @@
<?php
namespace Database\Note;
namespace Database\Annotation;
use Note\Attribute;
use Kiri\Annotation\Attribute;
use Database\Base\Relate;
use Exception;
/**
* Class Relation
* @package Note\Model
* @package Annotation\Model
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class Relation extends Attribute
{
+2 -2
View File
@@ -1,10 +1,10 @@
<?php
namespace Database\Note;
namespace Database\Annotation;
use Note\Attribute;
use Kiri\Annotation\Attribute;
use Database\Base\Setter;
use Exception;
@@ -101,7 +101,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
*/
public function getIterator(): Traversable|CollectionIterator|ArrayIterator
{
return new CollectionIterator($this->model, $this->query, $this->_item);
return new CollectionIterator($this->model, $this->_item);
}
@@ -20,31 +20,17 @@ class CollectionIterator extends \ArrayIterator
private ModelInterface|string $model;
/** @var ActiveQuery */
private ActiveQuery $query;
private ?ModelInterface $_clone = null;
public function clean()
{
unset($this->query);
}
/**
* CollectionIterator constructor.
* @param $model
* @param $query
* @param array $array
* @param int $flags
* @throws Exception
*/
public function __construct($model, $query, array $array = [], int $flags = 0)
public function __construct($model, array $array = [], int $flags = 0)
{
$this->model = $model;
$this->query = $query;
parent::__construct($array, $flags);
}
+1090
View File
File diff suppressed because it is too large Load Diff
+5 -13
View File
@@ -39,9 +39,6 @@ class Command extends Component
/** @var string */
public string $dbname = '';
/** @var PDOStatement|null */
private ?PDOStatement $prepare = null;
/**
* @return array|bool|int|string|PDOStatement|null
@@ -53,12 +50,10 @@ class Command extends Component
}
/**
* @param bool $isInsert
* @param mixed $hasAutoIncrement
* @return int|bool|array|string|null
* @throws Exception
*/
public function save(bool $isInsert = TRUE, mixed $hasAutoIncrement = null): int|bool|array|string|null
public function save(): int|bool|array|string|null
{
return $this->execute(static::EXECUTE);
}
@@ -110,11 +105,11 @@ class Command extends Component
}
/**
* @param $type
* @param string $type
* @return int|bool|array|string|null
* @throws Exception
*/
private function execute($type): int|bool|array|string|null
private function execute(string $type): int|bool|array|string|null
{
try {
$time = microtime(true);
@@ -136,11 +131,11 @@ class Command extends Component
/**
* @param $type
* @param string $type
* @return array|int|bool|null
* @throws Exception
*/
private function search($type): array|int|bool|null
private function search(string $type): array|int|bool|null
{
$pdo = $this->db->getConnect($this->sql);
if ($type === static::FETCH_COLUMN) {
@@ -180,9 +175,6 @@ class Command extends Component
*/
public function bindValues(array $data = []): static
{
if (!is_array($this->params)) {
$this->params = [];
}
if (!empty($data)) {
$this->params = array_merge($this->params, $data);
}
+10 -32
View File
@@ -21,11 +21,11 @@ use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config;
use Kiri\Events\EventProvider;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use Note\Inject;
use Kiri;
use Kiri\Annotation\Inject;
use ReflectionException;
use Server\Events\OnWorkerExit;
use Server\Events\OnWorkerStop;
use Kiri\Server\Events\OnWorkerExit;
use Kiri\Server\Events\OnWorkerStop;
/**
* Class Connection
@@ -68,11 +68,7 @@ class Connection extends Component
public array $attributes = [];
/**
* @var Schema
*/
#[Inject(Schema::class)]
public Schema $_schema;
private ?Schema $_schema = null;
/**
@@ -81,18 +77,11 @@ class Connection extends Component
*/
public function init()
{
$eventProvider = Kiri::getDi()->get(EventProvider::class);
$eventProvider->on(OnWorkerStop::class, [$this, 'clear_connection'], 0);
$eventProvider->on(OnWorkerExit::class, [$this, 'clear_connection'], 0);
$eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
$eventProvider->on(Rollback::class, [$this, 'rollback'], 0);
$eventProvider->on(Commit::class, [$this, 'commit'], 0);
if (Db::transactionsActive()) {
$this->beginTransaction();
}
$this->_schema->db = $this;
$this->eventProvider->on(OnWorkerStop::class, [$this, 'clear_connection'], 0);
$this->eventProvider->on(OnWorkerExit::class, [$this, 'clear_connection'], 0);
$this->eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
$this->eventProvider->on(Rollback::class, [$this, 'rollback'], 0);
$this->eventProvider->on(Commit::class, [$this, 'commit'], 0);
}
@@ -107,17 +96,6 @@ class Connection extends Component
}
/**
* @param $config
* @return $this
*/
public function configure($config): static
{
Kiri::configure($this, $config);
return $this;
}
/**
* @throws Exception
*/
@@ -8,10 +8,10 @@ use Exception;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Providers;
use Kiri\Application;
use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Server\Events\OnWorkerStart;
use Kiri;
use Kiri\Server\Events\OnTaskerStart;
use Kiri\Server\Events\OnWorkerStart;
/**
* Class DatabasesProviders
@@ -20,8 +20,6 @@ use Server\Events\OnWorkerStart;
class DatabasesProviders extends Providers
{
private array $_pooLength = ['min' => 0, 'max' => 1];
/**
* @param Application $application
@@ -29,25 +27,19 @@ class DatabasesProviders extends Providers
*/
public function onImport(Application $application)
{
$application->set('db', $this);
$this->_pooLength = Config::get('databases.pool', ['min' => 0, 'max' => 1]);
$this->eventProvider->on(OnWorkerStart::class, [$this, 'createPool']);
$this->eventProvider->on(OnTaskerStart::class, [$this, 'createPool']);
}
/**
* @param $name
* @return Connection
* @throws ConfigException
* @throws Exception
*/
public function get($name): Connection
{
$config = $this->_settings($this->getConfig($name));
return Kiri::getDi()->get(Connection::class)->configure($config);
return Kiri::app()->get($name);
}
@@ -55,16 +47,21 @@ class DatabasesProviders extends Providers
* @throws ConfigException
* @throws Exception
*/
public function createPool(OnWorkerStart $onWorkerStart)
public function createPool(OnWorkerStart|OnTaskerStart $onWorkerStart)
{
$databases = Config::get('databases.connections', []);
if (empty($databases)) {
return;
}
$connection = Kiri::getDi()->get(Connection::class);
foreach ($databases as $database) {
/** @var Connection $connection */
$connection->configure($database)->fill();
$app = Kiri::app();
foreach ($databases as $key => $database) {
$database = $this->_settings($database);
$connection = Kiri::getDi()->create(Connection::class, [$database]);
$connection->fill();
$app->set($key, $connection);
}
}
@@ -93,15 +90,4 @@ class DatabasesProviders extends Providers
}
/**
* @param $name
* @return mixed
* @throws ConfigException
*/
public function getConfig($name): mixed
{
return Config::get('databases.connections.' . $name, null, true);
}
}
View File
View File
View File
View File
+15 -13
View File
@@ -14,9 +14,10 @@ use Database\Base\Getter;
use Database\Traits\HasBase;
use Exception;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use Kiri;
use Kiri\ToArray;
use ReflectionException;
use Swoole\Coroutine;
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.');
@@ -213,16 +214,18 @@ class Model extends Base\Model
*/
public function delete(): bool
{
$conditions = $this->_oldAttributes;
if (empty($conditions)) {
return $this->addError("Delete condition do not empty.", 'mysql');
}
$primary = $this->getPrimary();
if (!empty($primary)) {
$conditions = [$primary => $this->getAttribute($primary)];
if (empty($primary) || !$this->hasPrimaryValue()) {
return $this->addError("Only primary key operations are supported.", 'mysql');
}
return static::deleteByCondition($conditions);
if (!$this->beforeDelete()) {
$result = static::deleteByCondition([$primary => $this->getPrimaryValue()]);
Coroutine::create(function () use ($result) {
$this->afterDelete($result);
});
return $result;
}
return false;
}
@@ -401,12 +404,11 @@ class Model extends Base\Model
}
/**
* @return bool
* @throws Exception
* @param bool $result
* @return void
*/
public function afterDelete(): bool
public function afterDelete(bool $result): void
{
return TRUE;
}
/**
+1 -1
View File
@@ -5,7 +5,7 @@ namespace Database\Mysql;
use Exception;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Logger;
use Kiri\Kiri;
use Kiri;
use Kiri\Pool\StopHeartbeatCheck;
use PDOStatement;
use Swoole\Timer;
View File
View File
@@ -12,7 +12,7 @@ use Database\Query;
use Exception;
use JetBrains\PhpStorm\Pure;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use Kiri;
use ReflectionException;
@@ -18,7 +18,7 @@ use Database\Query;
use Database\SqlBuilder;
use Exception;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use Kiri;
use ReflectionException;
/**
@@ -195,7 +195,7 @@ trait QueryTrait
* @param string $column
* @return $this
*/
public function whereNotEmpty(string $column): static
public function whereAnnotationmpty(string $column): static
{
$this->where[] = $column . ' <> \'\'';
return $this;
+3 -3
View File
@@ -12,12 +12,12 @@
"php": ">=8.0",
"ext-json": "*",
"ext-pdo": "*",
"game-worker/kiri-validator": "^v1.2",
"game-worker/kiri-event": "^v1.0"
"game-worker/kiri-validator": "~v2.0",
"game-worker/kiri-event": "~v2.0"
},
"autoload": {
"psr-4": {
"Database\\": "src/"
"Database\\": "./"
}
},
"require-dev": {
-1091
View File
File diff suppressed because it is too large Load Diff
-26
View File
@@ -1,26 +0,0 @@
<?php
namespace Database;
use Database\Model;
/**
*
*/
class TestModel extends Model
{
protected string $connection = '';
protected string $table = '';
public ?string $primary = '';
}
TestModel::query()->get();