From 5a6f6da70aa9e7be26c7575415e3ae177818891c Mon Sep 17 00:00:00 2001 From: xl Date: Mon, 2 Sep 2024 12:12:39 +0800 Subject: [PATCH] eee --- ActiveQuery.php | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/ActiveQuery.php b/ActiveQuery.php index d06f6b2..007aa68 100644 --- a/ActiveQuery.php +++ b/ActiveQuery.php @@ -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 */ @@ -95,7 +137,7 @@ class ActiveQuery extends QueryTrait implements ISqlBuilder return; } if (Context::inCoroutine()) { - Coroutine::create(fn() => $closure($data)); + Coroutine::create(fn () => $closure($data)); } else { call_user_func($closure, $data); }