Extract Builder creation to factory method newQuery (#24)

* Extract Builder creation to factory method newQuery

* Added autoload for Test namespace.

---------

Authored-by: Андрей Радионов <radionov@gilmon.ru>
This commit is contained in:
Андрей
2023-07-07 14:50:02 +05:00
committed by GitHub
parent ad456b4f3e
commit 0ad490c5c6
2 changed files with 16 additions and 3 deletions
+5
View File
@@ -33,5 +33,10 @@
"psr-4": {
"PhpClickHouseLaravel\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}
+11 -3
View File
@@ -256,7 +256,15 @@ class BaseModel
public static function select($select = ['*']): Builder
{
$instance = new static();
return (new Builder($instance->getThisClient()))->select($select)->from($instance->getTable());
return $instance->newQuery()->select($select)->from($instance->getTable());
}
/**
* @return Builder
*/
protected function newQuery(): Builder
{
return new Builder($this->getThisClient());
}
/**
@@ -347,7 +355,7 @@ class BaseModel
public static function where($column, $operator = null, $value = null, string $concatOperator = Operator::AND): Builder
{
$instance = new static();
$builder = (new Builder($instance->getThisClient()))->select(['*'])
$builder = $instance->newQuery()->select(['*'])
->from($instance->getTable())
->setSourcesTable($instance->getTableSources());
if (is_null($value)) {
@@ -367,7 +375,7 @@ class BaseModel
public static function whereRaw(string $expression): Builder
{
$instance = new static();
return (new Builder($instance->getThisClient()))->select(['*'])
return $instance->newQuery()->select(['*'])
->from($instance->getTable())
->setSourcesTable($instance->getTableSources())
->whereRaw($expression);