Commit 9d56d4aa authored by Taylor Otwell's avatar Taylor Otwell

more database simplifications

parent 59a7e47f
......@@ -140,14 +140,7 @@ class Connection {
*/
public function table($table)
{
switch ($this->driver())
{
case 'pgsql':
return new Queries\Postgres($this, $this->grammar(), $table);
default:
return new Queries\Query($this, $this->grammar(), $table);
}
return new Query($this, $this->grammer(), $table);
}
/**
......
<?php namespace Laravel\Database\Queries;
use Laravel\Database\Connection;
<?php namespace Laravel\Database;
class Query {
/**
* The database connection.
*
* @var Database\Connection
* @var Connection
*/
public $connection;
......@@ -92,7 +90,7 @@ class Query {
/**
* Create a new query instance.
*
* @param Database\Connection $connection
* @param Connection $connection
* @param Grammars\Grammar $grammar
* @param string $table
* @return void
......@@ -119,10 +117,6 @@ class Query {
/**
* Add an array of columns to the SELECT clause.
*
* <code>
* $query->select(array('id', 'email'));
* </code>
*
* @param array $columns
* @return Query
*/
......@@ -136,10 +130,6 @@ class Query {
/**
* Add a join clause to the query.
*
* <code>
* $query->join('users', 'users.id', '=', 'posts.user_id');
* </code>
*
* @param string $table
* @param string $column1
* @param string $operator
......@@ -157,10 +147,6 @@ class Query {
/**
* Add a left join to the query.
*
* <code>
* $query->left_join('users', 'users.id', '=', 'posts.user_id');
* </code>
*
* @param string $table
* @param string $column1
* @param string $operator
......@@ -187,10 +173,6 @@ class Query {
/**
* Add a raw where condition to the query.
*
* <code>
* $query->raw_where('user_id = ? and password = ?', array(1, 'secret'));
* </code>
*
* @param string $where
* @param array $bindings
* @param string $connector
......@@ -208,10 +190,6 @@ class Query {
/**
* Add a raw or where condition to the query.
*
* <code>
* $query->raw_or_where('user_id = ? and password = ?', array(1, 'secret'));
* </code>
*
* @param string $where
* @param array $bindings
* @return Query
......@@ -224,10 +202,6 @@ class Query {
/**
* Add a where condition to the query.
*
* <code>
* $query->where('id', '=', 1);
* </code>
*
* @param string $column
* @param string $operator
* @param mixed $value
......@@ -246,10 +220,6 @@ class Query {
/**
* Add an or where condition to the query.
*
* <code>
* $query->or_where('id', '=', 1);
* </code>
*
* @param string $column
* @param string $operator
* @param mixed $value
......@@ -260,28 +230,9 @@ class Query {
return $this->where($column, $operator, $value, 'OR');
}
/**
* Add a where condition for the primary key to the query.
*
* <code>
* $query->where_id(1);
* </code>
*
* @param mixed $value
* @return Query
*/
public function where_id($value)
{
return $this->where('id', '=', $value);
}
/**
* Add an or where condition for the primary key to the query.
*
* <code>
* $query->or_where_id(1);
* </code>
*
* @param mixed $value
* @return Query
*/
......@@ -293,10 +244,6 @@ class Query {
/**
* Add a where in condition to the query.
*
* <code>
* $query->where_in('id', array(1, 2, 3));
* </code>
*
* @param string $column
* @param array $values
* @param string $connector
......@@ -315,10 +262,6 @@ class Query {
/**
* Add an or where in condition to the query.
*
* <code>
* $query->or_where_in('id', array(1, 2, 3));
* </code>
*
* @param string $column
* @param array $values
* @return Query
......@@ -331,10 +274,6 @@ class Query {
/**
* Add a where not in condition to the query.
*
* <code>
* $query->where_not_in('id', array(1, 2, 3));
* </code>
*
* @param string $column
* @param array $values
* @param string $connector
......@@ -348,10 +287,6 @@ class Query {
/**
* Add an or where not in condition to the query.
*
* <code>
* $query->or_where_not_in('id', array(1, 2, 3));
* </code>
*
* @param string $column
* @param array $values
* @return Query
......@@ -457,14 +392,6 @@ class Query {
/**
* Add an ordering to the query.
*
* <code>
* // Set an ascending sort on the query
* $query->order_by('votes', 'asc');
*
* // Set a descending sort on the query
* $query->order_by('votes', 'desc');
* </code>
*
* @param string $column
* @param string $direction
* @return Query
......@@ -507,11 +434,6 @@ class Query {
*
* If the given page is not an integer or is less than zero, one will be used.
*
* <code>
* // Get the the 15 users that should be displayed for page 1
* $results = DB::table('users')->for_page(1, 15);
* </code>
*
* @param int $page
* @param int $per_page
* @return Query
......@@ -526,11 +448,6 @@ class Query {
/**
* Find a record by the primary key.
*
* <code>
* // Get the user having an ID of 1
* $user = DB::table('users')->find(1);
* </code>
*
* @param int $id
* @param array $columns
* @return object
......@@ -593,11 +510,6 @@ class Query {
/**
* Insert an array of values into the database table.
*
* <code>
* // Insert into the "users" table
* $success = DB::table('users')->insert(array('id' => 1, 'email' => 'example@gmail.com'));
* </code>
*
* @param array $values
* @return bool
*/
......@@ -609,29 +521,20 @@ class Query {
/**
* Insert an array of values into the database table and return the value of the ID column.
*
* <code>
* // Insert into the "users" table and get the auto-incrementing ID
* $id = DB::table('users')->insert_get_id(array('email' => 'example@gmail.com'));
* </code>
*
* @param array $values
* @param string $sequence
* @return int
*/
public function insert_get_id($values)
public function insert_get_id($values, $sequence = null)
{
$this->connection->query($this->grammar->insert($this, $values), array_values($values));
return (int) $this->connection->pdo->lastInsertId();
return (int) $this->connection->pdo->lastInsertId($sequence);
}
/**
* Update an array of values in the database table.
*
* <code>
* // Update a user's e-mail address
* $affected = DB::table('users')->where_id(1)->update(array('email' => 'new_email@example.com'));
* </code>
*
* @param array $values
* @return int
*/
......@@ -645,17 +548,6 @@ class Query {
*
* Optionally, an ID may be passed to the method do delete a specific row.
*
* <code>
* // Delete everything from the "users" table
* $affected = DB::table('users')->delete();
*
* // Delete a specific user from the table
* $affected = DB::table('users')->delete(1);
*
* // Execute a delete statement with where conditions
* $affected = DB::table('users')->where_email($email)->delete();
* </code>
*
* @param int $id
* @return int
*/
......@@ -669,15 +561,8 @@ class Query {
/**
* Magic Method for handling dynamic functions.
*
* This method handles all calls to aggregate functions as well as the construction of dynamic where clauses.
*
* <code>
* // Get the total number of rows on the "users" table
* $count = DB::table('users')->count();
*
* // Get a user using a dynamic where clause
* $user = DB::table('users')->where_email('example@gmail.com')->first();
* </code>
* This method handles all calls to aggregate functions as well as the construction
* of dynamic where clauses via the "dynamic_where" method.
*/
public function __call($method, $parameters)
{
......
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