Refactor Query class. Remove comment bloat.
This commit is contained in:
parent
98a691fa58
commit
bc8c0f2cc7
|
@ -125,10 +125,8 @@ public function select()
|
||||||
|
|
||||||
foreach (func_get_args() as $column)
|
foreach (func_get_args() as $column)
|
||||||
{
|
{
|
||||||
// ---------------------------------------------------------
|
// If the column name is being aliased, we will need to wrap the column
|
||||||
// If the column name is being aliased, we will need to
|
// name and its alias in keyword identifiers.
|
||||||
// wrap the column name and its alias.
|
|
||||||
// ---------------------------------------------------------
|
|
||||||
if (strpos(strtolower($column), ' as ') !== false)
|
if (strpos(strtolower($column), ' as ') !== false)
|
||||||
{
|
{
|
||||||
$segments = explode(' ', $column);
|
$segments = explode(' ', $column);
|
||||||
|
@ -433,6 +431,7 @@ public function get()
|
||||||
private function aggregate($aggregator, $column)
|
private function aggregate($aggregator, $column)
|
||||||
{
|
{
|
||||||
$this->select = 'SELECT '.$aggregator.'('.$this->wrap($column).') AS '.$this->wrap('aggregate');
|
$this->select = 'SELECT '.$aggregator.'('.$this->wrap($column).') AS '.$this->wrap('aggregate');
|
||||||
|
|
||||||
return $this->first()->aggregate;
|
return $this->first()->aggregate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,10 +456,8 @@ public function insert_get_id($values)
|
||||||
{
|
{
|
||||||
$sql = Query\Compiler::insert($this, $values);
|
$sql = Query\Compiler::insert($this, $values);
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// Use the RETURNING clause on Postgres instead of the PDO lastInsertID method.
|
||||||
// Use the RETURNING clause on Postgres instead of PDO.
|
// The PDO method is a little cumbersome using Postgres.
|
||||||
// The Postgres PDO ID method is slightly cumbersome.
|
|
||||||
// ---------------------------------------------------------
|
|
||||||
if (DB::driver($this->connection) == 'pgsql')
|
if (DB::driver($this->connection) == 'pgsql')
|
||||||
{
|
{
|
||||||
$query = DB::connection($this->connection)->prepare($sql.' RETURNING '.$this->wrap('id'));
|
$query = DB::connection($this->connection)->prepare($sql.' RETURNING '.$this->wrap('id'));
|
||||||
|
@ -470,9 +467,6 @@ public function insert_get_id($values)
|
||||||
return $query->fetch(\PDO::FETCH_CLASS, 'stdClass')->id;
|
return $query->fetch(\PDO::FETCH_CLASS, 'stdClass')->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
|
||||||
// Use the PDO ID method for MySQL and SQLite.
|
|
||||||
// ---------------------------------------------------------
|
|
||||||
DB::query($sql, array_values($values), $this->connection);
|
DB::query($sql, array_values($values), $this->connection);
|
||||||
|
|
||||||
return DB::connection($this->connection)->lastInsertId();
|
return DB::connection($this->connection)->lastInsertId();
|
||||||
|
@ -514,6 +508,7 @@ public function delete($id = null)
|
||||||
public function wrap($value)
|
public function wrap($value)
|
||||||
{
|
{
|
||||||
$wrap = (DB::driver($this->connection) == 'mysql') ? '`' : '"';
|
$wrap = (DB::driver($this->connection) == 'mysql') ? '`' : '"';
|
||||||
|
|
||||||
return implode('.', array_map(function($segment) use ($wrap) {return ($segment != '*') ? $wrap.$segment.$wrap : $segment;}, explode('.', $value)));
|
return implode('.', array_map(function($segment) use ($wrap) {return ($segment != '*') ? $wrap.$segment.$wrap : $segment;}, explode('.', $value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,20 +528,11 @@ public function parameterize($values)
|
||||||
*/
|
*/
|
||||||
public function __call($method, $parameters)
|
public function __call($method, $parameters)
|
||||||
{
|
{
|
||||||
// ---------------------------------------------------------
|
|
||||||
// Dynamic methods allows the building of very expressive
|
|
||||||
// queries. All dynamic methods start with "where_".
|
|
||||||
//
|
|
||||||
// Ex: DB::table('users')->where_email($email)->first();
|
|
||||||
// ---------------------------------------------------------
|
|
||||||
if (strpos($method, 'where_') === 0)
|
if (strpos($method, 'where_') === 0)
|
||||||
{
|
{
|
||||||
return Query\Dynamic::build($method, $parameters, $this);
|
return Query\Dynamic::build($method, $parameters, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
|
||||||
// Handle any of the aggregate functions.
|
|
||||||
// ---------------------------------------------------------
|
|
||||||
if (in_array($method, array('count', 'min', 'max', 'avg', 'sum')))
|
if (in_array($method, array('count', 'min', 'max', 'avg', 'sum')))
|
||||||
{
|
{
|
||||||
return ($method == 'count') ? $this->aggregate(strtoupper($method), '*') : $this->aggregate(strtoupper($method), $parameters[0]);
|
return ($method == 'count') ? $this->aggregate(strtoupper($method), '*') : $this->aggregate(strtoupper($method), $parameters[0]);
|
||||||
|
|
Loading…
Reference in New Issue