Compare commits

...

7 Commits

Author SHA1 Message Date
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
58 changed files with 7281 additions and 7351 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;
+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);
}
+4 -25
View File
@@ -22,10 +22,10 @@ use Kiri\Abstracts\Config;
use Kiri\Events\EventProvider;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use Note\Inject;
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;
/**
@@ -86,12 +82,6 @@ class Connection extends Component
$this->eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
$this->eventProvider->on(Rollback::class, [$this, 'rollback'], 0);
$this->eventProvider->on(Commit::class, [$this, 'commit'], 0);
if (Db::transactionsActive()) {
$this->beginTransaction();
}
$this->_schema->db = $this;
}
@@ -106,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,9 @@ 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\Server\Events\OnWorkerStart;
/**
* Class DatabasesProviders
@@ -20,8 +19,6 @@ use Server\Events\OnWorkerStart;
class DatabasesProviders extends Providers
{
private array $_pooLength = ['min' => 0, 'max' => 1];
/**
* @param Application $application
@@ -29,10 +26,6 @@ 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']);
}
@@ -40,14 +33,11 @@ class DatabasesProviders extends Providers
/**
* @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);
}
@@ -61,10 +51,15 @@ class DatabasesProviders extends Providers
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 +88,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
+14 -12
View File
@@ -17,6 +17,7 @@ use Kiri\Exception\NotFindClassException;
use Kiri\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;
}
/**
View File
View File
View File
@@ -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();