slight database refactoring.
This commit is contained in:
parent
fe0502ded9
commit
75d96c9204
|
@ -16,13 +16,6 @@ class Connection {
|
|||
*/
|
||||
public $config;
|
||||
|
||||
/**
|
||||
* The Connector instance.
|
||||
*
|
||||
* @var Connector
|
||||
*/
|
||||
public $connector;
|
||||
|
||||
/**
|
||||
* The PDO connection.
|
||||
*
|
||||
|
@ -33,17 +26,16 @@ class Connection {
|
|||
/**
|
||||
* Create a new Connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param object $config
|
||||
* @param Conector $connector
|
||||
* @param string $name
|
||||
* @param object $config
|
||||
* @param Connector $connector
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($name, $config, $connector)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->config = $config;
|
||||
$this->connector = $connector;
|
||||
$this->pdo = $this->connector->connect($this->config);
|
||||
$this->pdo = $connector->connect($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -84,8 +84,8 @@ class Query {
|
|||
*/
|
||||
public function __construct($table, $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->table = $table;
|
||||
$this->connection = $connection;
|
||||
$this->from = 'FROM '.$this->wrap($table);
|
||||
}
|
||||
|
||||
|
@ -471,7 +471,9 @@ private function aggregate($aggregator, $column)
|
|||
*/
|
||||
public function paginate($per_page, $columns = array('*'))
|
||||
{
|
||||
list($select, $total) = array($this->select, $this->count());
|
||||
$select = $this->select;
|
||||
|
||||
$total = $this->count();
|
||||
|
||||
// Every query clears the SELECT clause, so we store the contents of the clause
|
||||
// before executing the count query and then put the contents back in afterwards.
|
||||
|
@ -515,20 +517,11 @@ public function get($columns = array('*'))
|
|||
|
||||
$sql = $this->select.' '.$this->from.' '.$this->where;
|
||||
|
||||
if (count($this->orderings) > 0)
|
||||
{
|
||||
$sql .= ' ORDER BY '.implode(', ', $this->orderings);
|
||||
}
|
||||
if (count($this->orderings) > 0) $sql .= ' ORDER BY '.implode(', ', $this->orderings);
|
||||
|
||||
if ( ! is_null($this->limit))
|
||||
{
|
||||
$sql .= ' LIMIT '.$this->limit;
|
||||
}
|
||||
if ( ! is_null($this->limit)) $sql .= ' LIMIT '.$this->limit;
|
||||
|
||||
if ( ! is_null($this->offset))
|
||||
{
|
||||
$sql .= ' OFFSET '.$this->offset;
|
||||
}
|
||||
if ( ! is_null($this->offset)) $sql .= ' OFFSET '.$this->offset;
|
||||
|
||||
$results = $this->connection->query($sql, $this->bindings);
|
||||
|
||||
|
|
Loading…
Reference in New Issue