Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a6f6da70a | |||
| beb48f41d2 |
+43
-1
@@ -73,6 +73,48 @@ class ActiveQuery extends QueryTrait implements ISqlBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $column
|
||||||
|
* @param int|float $amount
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function increment(string $column, int|float $amount = 1): bool
|
||||||
|
{
|
||||||
|
return (bool)$this->buildCommand($this->builder->mathematics([$column => $amount]))->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $attributes
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function increments(array $attributes): bool
|
||||||
|
{
|
||||||
|
return (bool)$this->buildCommand($this->builder->mathematics($attributes))->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $column
|
||||||
|
* @param int|float $amount
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function decrement(string $column, int|float $amount = 1): bool
|
||||||
|
{
|
||||||
|
return (bool)$this->buildCommand($this->builder->mathematics([$column => $amount], '-'))->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $attributes
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function decrements(array $attributes): bool
|
||||||
|
{
|
||||||
|
return (bool)$this->buildCommand($this->builder->mathematics($attributes, '-'))->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
@@ -95,7 +137,7 @@ class ActiveQuery extends QueryTrait implements ISqlBuilder
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Context::inCoroutine()) {
|
if (Context::inCoroutine()) {
|
||||||
Coroutine::create(fn() => $closure($data));
|
Coroutine::create(fn () => $closure($data));
|
||||||
} else {
|
} else {
|
||||||
call_user_func($closure, $data);
|
call_user_func($closure, $data);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -1,4 +1,5 @@
|
|||||||
<?php /** @noinspection ALL */
|
<?php
|
||||||
|
/** @noinspection ALL */
|
||||||
/**
|
/**
|
||||||
* Created by PhpStorm.
|
* Created by PhpStorm.
|
||||||
* User: whwyy
|
* User: whwyy
|
||||||
@@ -234,8 +235,9 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
|||||||
* @return Model|null
|
* @return Model|null
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public static function findOne(int|string|array $param): ?static
|
public static function findOne(int|string|array|null $param): ?static
|
||||||
{
|
{
|
||||||
|
if (empty($param)) return null;
|
||||||
$model = static::instance();
|
$model = static::instance();
|
||||||
$query = new ActiveQuery($model);
|
$query = new ActiveQuery($model);
|
||||||
$query->from($model->getTable())->alias('t1');
|
$query->from($model->getTable())->alias('t1');
|
||||||
|
|||||||
+2
-2
@@ -18,10 +18,10 @@ interface ModelInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array|string|int $param
|
* @param array|string|int|null $param
|
||||||
* @return ModelInterface|null
|
* @return ModelInterface|null
|
||||||
*/
|
*/
|
||||||
public static function findOne(array|string|int $param): ?static;
|
public static function findOne(array|string|int|null $param): ?static;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user