Skip to content

Commit 3abce86

Browse files
committed
v2.0.6
1 parent 9942427 commit 3abce86

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

src/Database.php

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ public function __construct(array $credentials = [])
8585
$this->_validation = new Validation($this->_credentials['validation']['methods'], $this->_credentials['validation']['messages'], $this->_credentials['validation']['labels'], $this);
8686
}
8787

88+
public function __call($name, $arguments)
89+
{
90+
if(Helper::str_starts_with($name, 'findBy') === FALSE){
91+
throw new \RuntimeException('There is no "' . $name . '" method.');
92+
}
93+
$this->where(Helper::camelCaseToSnakeCase(\substr($name, 6)), \current($arguments));
94+
return $this;
95+
}
96+
8897
final public function newInstance(array $credentials = []): Database
8998
{
9099
return new self(empty($credentials) ? $this->_credentials : \array_merge($this->_credentials, $credentials));
@@ -469,41 +478,6 @@ public function createBatch(array $set)
469478
return $res->numRows() > 0;
470479
}
471480

472-
/**
473-
* QueryBuilder resetlemeden SELECT cümlesi kurar ve satır sayısını döndürür.
474-
*
475-
* @return int
476-
*/
477-
public function count(): int
478-
{
479-
$select = $this->_STRUCTURE['select'];
480-
$this->_STRUCTURE['select'][] = 'COUNT(*) AS row_count';
481-
$this->_deleteFieldBuild(false);
482-
$parameters = Parameters::get(false);
483-
$res = $this->query($this->_readQuery());
484-
$count = $res->toArray()['row_count'] ?? 0;
485-
unset($res);
486-
Parameters::merge($parameters);
487-
$this->_STRUCTURE['select'] = $select;
488-
return $count;
489-
}
490-
491-
public function pagination(int $page = 1, int $per_page_limit = 10, string $link = '?page={page}'): Pagination
492-
{
493-
$total_row = $this->count();
494-
$this->offset(($page - 1) * $per_page_limit)
495-
->limit($per_page_limit);
496-
$res = $this->query($this->_readQuery());
497-
$this->reset();
498-
499-
return new Pagination($res, $page, $per_page_limit, $total_row, $link);
500-
}
501-
502-
public function datatables(array $columns, int $method = Datatables::GET_REQUEST): string
503-
{
504-
return (new Datatables($this, $columns, $method))->__toString();
505-
}
506-
507481
/**
508482
* @param array $selector
509483
* @param array $conditions
@@ -699,6 +673,41 @@ public function onlyUndeleted(): self
699673
return $this;
700674
}
701675

676+
/**
677+
* QueryBuilder resetlemeden SELECT cümlesi kurar ve satır sayısını döndürür.
678+
*
679+
* @return int
680+
*/
681+
public function count(): int
682+
{
683+
$select = $this->_STRUCTURE['select'];
684+
$this->_STRUCTURE['select'][] = 'COUNT(*) AS row_count';
685+
$this->_deleteFieldBuild(false);
686+
$parameters = Parameters::get(false);
687+
$res = $this->query($this->_readQuery());
688+
$count = $res->toArray()['row_count'] ?? 0;
689+
unset($res);
690+
Parameters::merge($parameters);
691+
$this->_STRUCTURE['select'] = $select;
692+
return $count;
693+
}
694+
695+
public function pagination(int $page = 1, int $per_page_limit = 10, string $link = '?page={page}'): Pagination
696+
{
697+
$total_row = $this->count();
698+
$this->offset(($page - 1) * $per_page_limit)
699+
->limit($per_page_limit);
700+
$res = $this->query($this->_readQuery());
701+
$this->reset();
702+
703+
return new Pagination($res, $page, $per_page_limit, $total_row, $link);
704+
}
705+
706+
public function datatables(array $columns, int $method = Datatables::GET_REQUEST): string
707+
{
708+
return (new Datatables($this, $columns, $method))->__toString();
709+
}
710+
702711
public function _readQuery(): string
703712
{
704713
if($this->getSchema() !== null){

0 commit comments

Comments
 (0)