Changed Query::get and Query::first to accept arrays of columns instead of a dynamic parameter list.
This commit is contained in:
parent
21efdbf69b
commit
787be6bc99
|
@ -115,15 +115,16 @@ public function distinct()
|
||||||
/**
|
/**
|
||||||
* Add columns to the SELECT clause.
|
* Add columns to the SELECT clause.
|
||||||
*
|
*
|
||||||
|
* @param array $columns
|
||||||
* @return Query
|
* @return Query
|
||||||
*/
|
*/
|
||||||
public function select()
|
public function select($columns = array('*'))
|
||||||
{
|
{
|
||||||
$this->select = ($this->distinct) ? 'SELECT DISTINCT ' : 'SELECT ';
|
$this->select = ($this->distinct) ? 'SELECT DISTINCT ' : 'SELECT ';
|
||||||
|
|
||||||
$columns = array();
|
$wrapped = array();
|
||||||
|
|
||||||
foreach (func_get_args() as $column)
|
foreach ($columns 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 wrap the column
|
||||||
// name and its alias in keyword identifiers.
|
// name and its alias in keyword identifiers.
|
||||||
|
@ -131,15 +132,15 @@ public function select()
|
||||||
{
|
{
|
||||||
$segments = explode(' ', $column);
|
$segments = explode(' ', $column);
|
||||||
|
|
||||||
$columns[] = $this->wrap($segments[0]).' AS '.$this->wrap($segments[2]);
|
$wrapped[] = $this->wrap($segments[0]).' AS '.$this->wrap($segments[2]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$columns[] = $this->wrap($column);
|
$wrapped[] = $this->wrap($column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->select .= implode(', ', $columns);
|
$this->select .= implode(', ', $wrapped);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -388,34 +389,38 @@ public function take($value)
|
||||||
/**
|
/**
|
||||||
* Find a record by the primary key.
|
* Find a record by the primary key.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
|
* @param array $columns
|
||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
public function find($id)
|
public function find($id, $columns = array('*'))
|
||||||
{
|
{
|
||||||
return $this->where('id', '=', $id)->first();
|
return $this->where('id', '=', $id)->first($columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the query as a SELECT statement and return the first result.
|
* Execute the query as a SELECT statement and return the first result.
|
||||||
*
|
*
|
||||||
|
* @param array $columns
|
||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
public function first()
|
public function first($columns = array('*'))
|
||||||
{
|
{
|
||||||
return (count($results = call_user_func_array(array($this->take(1), 'get'), func_get_args())) > 0) ? $results[0] : null;
|
|
||||||
|
return (count($results = $this->take(1)->get($columns)) > 0) ? $results[0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the query as a SELECT statement.
|
* Execute the query as a SELECT statement.
|
||||||
*
|
*
|
||||||
|
* @param array $columns
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get()
|
public function get($columns = array('*'))
|
||||||
{
|
{
|
||||||
if (is_null($this->select))
|
if (is_null($this->select))
|
||||||
{
|
{
|
||||||
call_user_func_array(array($this, 'select'), (count(func_get_args()) > 0) ? func_get_args() : array('*'));
|
$this->select($columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DB::query(Query\Compiler::select($this), $this->bindings, $this->connection);
|
return DB::query(Query\Compiler::select($this), $this->bindings, $this->connection);
|
||||||
|
|
Loading…
Reference in New Issue