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

slight database refactoring.

parent fe0502de
...@@ -16,13 +16,6 @@ class Connection { ...@@ -16,13 +16,6 @@ class Connection {
*/ */
public $config; public $config;
/**
* The Connector instance.
*
* @var Connector
*/
public $connector;
/** /**
* The PDO connection. * The PDO connection.
* *
...@@ -33,17 +26,16 @@ class Connection { ...@@ -33,17 +26,16 @@ class Connection {
/** /**
* Create a new Connection instance. * Create a new Connection instance.
* *
* @param string $name * @param string $name
* @param object $config * @param object $config
* @param Conector $connector * @param Connector $connector
* @return void * @return void
*/ */
public function __construct($name, $config, $connector) public function __construct($name, $config, $connector)
{ {
$this->name = $name; $this->name = $name;
$this->config = $config; $this->config = $config;
$this->connector = $connector; $this->pdo = $connector->connect($this->config);
$this->pdo = $this->connector->connect($this->config);
} }
/** /**
......
...@@ -84,8 +84,8 @@ class Query { ...@@ -84,8 +84,8 @@ class Query {
*/ */
public function __construct($table, $connection) public function __construct($table, $connection)
{ {
$this->connection = $connection;
$this->table = $table; $this->table = $table;
$this->connection = $connection;
$this->from = 'FROM '.$this->wrap($table); $this->from = 'FROM '.$this->wrap($table);
} }
...@@ -471,7 +471,9 @@ class Query { ...@@ -471,7 +471,9 @@ class Query {
*/ */
public function paginate($per_page, $columns = array('*')) 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 // 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. // before executing the count query and then put the contents back in afterwards.
...@@ -515,20 +517,11 @@ class Query { ...@@ -515,20 +517,11 @@ class Query {
$sql = $this->select.' '.$this->from.' '.$this->where; $sql = $this->select.' '.$this->from.' '.$this->where;
if (count($this->orderings) > 0) if (count($this->orderings) > 0) $sql .= ' ORDER BY '.implode(', ', $this->orderings);
{
$sql .= ' ORDER BY '.implode(', ', $this->orderings);
}
if ( ! is_null($this->limit)) if ( ! is_null($this->limit)) $sql .= ' LIMIT '.$this->limit;
{
$sql .= ' LIMIT '.$this->limit;
}
if ( ! is_null($this->offset)) if ( ! is_null($this->offset)) $sql .= ' OFFSET '.$this->offset;
{
$sql .= ' OFFSET '.$this->offset;
}
$results = $this->connection->query($sql, $this->bindings); $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