Compare commits

...

12 Commits

Author SHA1 Message Date
as2252258 7c347bc373 eee 2025-07-09 10:34:46 +08:00
as2252258 d5c9b3bc86 eee 2025-07-09 10:28:20 +08:00
as2252258 ef7e85746d eee 2025-05-19 11:20:32 +08:00
as2252258 89f6949556 eee 2025-05-19 11:19:20 +08:00
as2252258 555d160b40 eee 2025-05-19 11:09:33 +08:00
as2252258 45b949747d eee 2025-05-19 11:06:27 +08:00
as2252258 94857ecb46 eee 2025-02-17 16:29:10 +08:00
as2252258 0f0a3349fb eee 2025-02-17 16:26:32 +08:00
as2252258 7fb9c3ea05 eee 2025-01-18 20:28:24 +08:00
as2252258 11a939e8a1 eee 2024-12-31 15:52:20 +08:00
as2252258 1666af9906 eee 2024-12-29 21:34:12 +08:00
as2252258 78f7faba55 eee 2024-12-29 21:10:58 +08:00
3 changed files with 1898 additions and 1871 deletions
+3 -3
View File
@@ -692,14 +692,14 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
public function __set(string $name, mixed $value): void
{
$prefix = 'set' . ucfirst($name);
if (method_exists($name, $prefix)) {
if (method_exists($this, $prefix)) {
$this->{$prefix}($value);
return;
}
$method = $prefix . 'Attribute';
if (method_exists($this, $method)) {
$this->_attributes[$name] = $this->{$method} ($value);
$this->_attributes[$name] = $this->{$method}($value);
} else {
$this->_attributes[$name] = $value;
}
@@ -766,7 +766,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
*/
protected function withRelate(string $name): mixed
{
$response = $this->$name();
$response = $this->{'get' . ucfirst($name)}();
if ($response instanceof \Database\Traits\Relation) {
$response = $response->get();
}
+6 -4
View File
@@ -1,4 +1,5 @@
<?php /** @noinspection ALL */
<?php
/** @noinspection ALL */
declare(strict_types=1);
@@ -189,7 +190,7 @@ class SqlBuilder extends Component
if (is_null($value)) {
return $keys;
}
if (preg_match('/^[+|-]\s\d+$/', $value)) {
if (preg_match('/^[+|-]\s\d+$/', (string)$value)) {
$keys[] = $key . '=' . $key . ' ' . $value;
} else {
$this->query->pushParam($value);
@@ -205,7 +206,8 @@ class SqlBuilder extends Component
*/
public function one(): string
{
return $this->makeSelect($this->query->getSelect()) . $this->make() . $this->makeLimit($this->query->limit(1));
$this->query->offset(0)->limit(1);
return $this->makeSelect($this->query->getSelect()) . $this->make() . $this->makeLimit();
}
@@ -215,7 +217,7 @@ class SqlBuilder extends Component
*/
public function all(): string
{
return $this->makeSelect($this->query->getSelect()) . $this->make() . $this->makeLimit($this->query);
return $this->makeSelect($this->query->getSelect()) . $this->make() . $this->makeLimit();
}
+34 -9
View File
@@ -84,6 +84,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
{
if ($callback instanceof Query) {
$this->where[] = 'NOT EXISTS(' . $callback->build() . ')';
$this->mergeParams($callback->getParams());
} else {
$this->where[] = 'NOT EXISTS(' . $this->makeClosureFunction($callback) . ')';
}
@@ -104,6 +105,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
{
if ($callback instanceof Query) {
$this->where[] = 'EXISTS(' . $callback->build() . ')';
$this->mergeParams($callback->getParams());
} else {
$this->where[] = 'EXISTS(' . $this->makeClosureFunction($callback) . ')';
}
@@ -302,6 +304,18 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
}
/**
* @param array $params
* @return void
*/
public function mergeParams(array $params): void
{
foreach ($params as $key => $value) {
$this->pushParam($value);
}
}
/**
* @param string $column
* @param callable $callable
@@ -442,6 +456,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
{
if ($tableName instanceof Query) {
$this->from = '(' . $tableName->build() . ')';
$this->mergeParams($tableName->getParams());
} else if ($tableName instanceof Closure) {
$this->from = '(' . $this->makeClosureFunction($tableName) . ')';
} else if (class_exists($tableName)) {
@@ -793,20 +808,23 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
/**
* @param string $columns
* @param array|Closure $value
* @param array|Closure|Query $value
*
* @return $this
* @throws
* @throws Exception
*/
public function whereIn(string $columns, array|Closure $value): static
public function whereIn(string $columns, array|Closure|Query $value): static
{
if ($value instanceof Closure) {
$value = $this->makeClosureFunction($value);
}
if (count($value) < 1) {
$value = [-1];
}
if (is_array($value)) {
if (count($value) < 1) throw new Exception('Value must be an not empty array');
$this->where[] = $columns . ' IN (' . implode(',', $value) . ')';
} else if ($value instanceof Query) {
$this->where[] = $columns . ' IN (' . $value->build() . ')';
$this->mergeParams($value->getParams());
} else {
$this->where[] = $columns . ' IN (' . $this->makeClosureFunction($value) . ')';
}
return $this;
}
@@ -951,6 +969,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
} else {
$generate->addArray($closure);
}
$this->mergeParams($generate->getParams());
return $generate->build();
}
@@ -1039,6 +1058,12 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
*/
private function sprintf(string $column, mixed $value, string $opera = '='): string
{
if (is_string($value)) {
[$alias, $field] = explode('.', $value);
if (in_array($alias, $this->_alias)) {
return $column . ' ' . $opera . ' ' . $value;
}
}
$this->pushParam($value);
return $column . ' ' . $opera . ' ?';
}