From 0377550b6ff46ffa3f536e54be767d16b34e7c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 9 Aug 2021 18:56:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/ActiveQuery.php | 2 -- Database/Query.php | 13 +++++++++++-- Database/Traits/QueryTrait.php | 3 +++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Database/ActiveQuery.php b/Database/ActiveQuery.php index 747500b4..f415d656 100644 --- a/Database/ActiveQuery.php +++ b/Database/ActiveQuery.php @@ -43,8 +43,6 @@ class ActiveQuery extends Component implements ISqlBuilder public array $attributes = []; - private SqlBuilder $builder; - /** * Comply constructor. diff --git a/Database/Query.php b/Database/Query.php index d1b74f78..dcef535c 100644 --- a/Database/Query.php +++ b/Database/Query.php @@ -22,13 +22,22 @@ class Query implements ISqlBuilder use QueryTrait; + + /** + * @throws Exception + */ + public function __construct() + { + $this->builder = SqlBuilder::builder($this); + } + /** * @return string * @throws Exception */ public function getSql(): string { - return SqlBuilder::builder($this)->get(); + return $this->builder->get(); } @@ -38,7 +47,7 @@ class Query implements ISqlBuilder */ public function getCondition(): string { - return SqlBuilder::builder($this)->getCondition(); + return $this->builder->getCondition(); } diff --git a/Database/Traits/QueryTrait.php b/Database/Traits/QueryTrait.php index efa1a7ca..b6988958 100644 --- a/Database/Traits/QueryTrait.php +++ b/Database/Traits/QueryTrait.php @@ -40,6 +40,9 @@ trait QueryTrait public bool $ifNotWhere = false; + + private SqlBuilder $builder; + /** * @var ActiveRecord|string|null */