Commit 75d96c92 authored by Taylor Otwell's avatar Taylor Otwell

slight database refactoring.

parent fe0502de
......@@ -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 @@ class Query {
*/
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 @@ class Query {
$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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment