Skip to content

Commit

Permalink
废弃find方法,新增all方法支持数组条件
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Aug 26, 2023
1 parent 04e66fe commit d61cae8
Showing 1 changed file with 38 additions and 31 deletions.
69 changes: 38 additions & 31 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,46 @@ function limit(int $num,bool $withTotalCount = false):static
return $this;
}

function find(?array $data = null):static|array|null
// function find(?array $data = null):static|array|null
// {
// $query = new QueryBuilder();
// if($data){
// foreach ($data as $key => $item){
// $query->where($key,$item);
// }
// }
//
// if(is_callable($this->whereCall)){
// call_user_func($this->whereCall,$query);
// }
// $this->whereCall = null;
//
// $fields = null;
// $returnAsArray = false;
// if(!empty($this->fields)){
// $fields = $this->fields['fields'];
// $returnAsArray = $this->fields['returnAsArray'];
// }
// $this->fields = null;
// $this->page = null;
//
// $query->getOne($this->tableName(),$fields);
//
// $info = FastDb::getInstance()->query($query)->getResult();
// if(!empty($info)){
// if($returnAsArray){
// return $info[0];
// }
// return new static($info[0],true);
// }else{
// return null;
// }
// }

function all(?string $tableName = null,?array $data = null):ListResult
{
$query = new QueryBuilder();

if($data){
foreach ($data as $key => $item){
$query->where($key,$item);
Expand All @@ -224,36 +261,6 @@ function find(?array $data = null):static|array|null
}
$this->whereCall = null;

$fields = null;
$returnAsArray = false;
if(!empty($this->fields)){
$fields = $this->fields['fields'];
$returnAsArray = $this->fields['returnAsArray'];
}
$this->fields = null;
$this->page = null;

$query->getOne($this->tableName(),$fields);

$info = FastDb::getInstance()->query($query)->getResult();
if(!empty($info)){
if($returnAsArray){
return $info[0];
}
return new static($info[0],true);
}else{
return null;
}
}

function all(?string $tableName = null):ListResult
{
$query = new QueryBuilder();
if(is_callable($this->whereCall)){
call_user_func($this->whereCall,$query);
}
$this->whereCall = null;

$total = null;
if($this->page != null){
$query->limit(...$this->page->toLimitArray());
Expand Down

0 comments on commit d61cae8

Please sign in to comment.