refactoring database layer.

This commit is contained in:
Taylor Otwell 2011-09-13 23:04:28 -05:00
parent 277729ed3e
commit 15449c34b1
6 changed files with 4 additions and 109 deletions

View File

@ -30,14 +30,6 @@ public function __construct(PDO $pdo) { $this->pdo = $pdo; }
/**
* Execute a SQL query against the connection and return a scalar result.
*
* <code>
* // Get the number of rows in the "users" table
* $count = DB::connection()->scalar('select count(*) from users');
*
* // Get the sum of payments from the "bank" table
* $sum = DB::connection()->scalar('select sum(payment) from banks where bank_id = ?', array(1));
* </code>
*
* @param string $sql
* @param array $bindings
* @return int|float
@ -52,14 +44,6 @@ public function scalar($sql, $bindings = array())
/**
* Execute a SQL query against the connection and return the first result.
*
* <code>
* // Get the first result from the "users" table
* $user = DB::connection()->first('select * from users limit 1');
*
* // Get the first result from a specified group of users
* $user = DB::connection()->first('select * from users where group_id = ?', array(1));
* </code>
*
* @param string $sql
* @param array $bindings
* @return object
@ -79,14 +63,6 @@ public function first($sql, $bindings = array())
* DELETE -> Number of Rows affected.
* ELSE -> Boolean true / false depending on success.
*
* <code>
* // Execute a query against the connection
* $users = DB::connection()->query('select * from users');
*
* // Execute a query against the connection using bindings
* $users = DB::connection()->query('select * from users where group_id = ?', array(1));
* </code>
*
* @param string $sql
* @param array $bindings
* @return mixed
@ -124,14 +100,6 @@ protected function execute(PDOStatement $statement, $bindings)
/**
* Begin a fluent query against a table.
*
* <code>
* // Begin a fluent query against the "users" table
* $query = DB::connection()->table('users');
*
* // Retrieve an entire table using a fluent query
* $users = DB::connection()->table('users')->get();
* </code>
*
* @param string $table
* @return Query
*/
@ -172,11 +140,6 @@ public function driver()
/**
* Magic Method for dynamically beginning queries on database tables.
*
* <code>
* // Begin a query against the "users" table
* $query = DB::connection()->users();
* </code>
*/
public function __call($method, $parameters)
{

View File

@ -1,6 +1,6 @@
<?php namespace Laravel\Database\Query\Grammars;
<?php namespace Laravel\Database\Grammars;
use Laravel\Database\Queries\Query;
use Laravel\Database\Query;
class Grammar {

View File

@ -1,4 +1,4 @@
<?php namespace Laravel\Database\Query\Grammars;
<?php namespace Laravel\Database\Grammars;
class MySQL extends Grammar {

View File

@ -15,10 +15,7 @@ class Manager {
* @param array $config
* @return void
*/
public function __construct($config)
{
$this->config = $config;
}
public function __construct($config) { $this->config = $config; }
/**
* Get a database connection.
@ -28,14 +25,6 @@ public function __construct($config)
*
* Note: Database connections are managed as singletons.
*
* <code>
* // Get the default database connection
* $connection = DB::connection();
*
* // Get a database connection by name
* $connection = DB::connection('slave');
* </code>
*
* @param string $connection
* @return Database\Connection
*/
@ -63,14 +52,6 @@ public function connection($connection = null)
/**
* Begin a fluent query against a table.
*
* <code>
* // Begin a fluent query against the "users" table using the default connection
* $query = DB::table('users');
*
* // Begin a fluent query against the "users" table using a specified connection
* $query = DB::table('users', 'slave');
* </code>
*
* @param string $table
* @param string $connection
* @return Queries\Query
@ -84,14 +65,6 @@ public function table($table, $connection = null)
* Magic Method for calling methods on the default database connection.
*
* This provides a convenient API for querying or examining the default database connection.
*
* <code>
* // Perform a query against the default connection
* $results = DB::query('select * from users');
*
* // Get the name of the PDO driver being used by the default connection
* $driver = DB::driver();
* </code>
*/
public function __call($method, $parameters)
{

View File

@ -1,19 +0,0 @@
<?php namespace Laravel\Database\Query\Grammars;
use Laravel\Database\Queries\Query;
class Postgres extends Grammar {
/**
* Compile a SQL INSERT statment that returns an auto-incrementing ID from a Query instance.
*
* @param Query $query
* @param array $values
* @return string
*/
public function insert_get_id(Query $query, $values)
{
return $this->insert($query, $values).' RETURNING '.$this->wrap('id');
}
}

View File

@ -1,22 +0,0 @@
<?php namespace Laravel\Database\Queries;
use PDO;
class Postgres extends Query {
/**
* Insert an array of values into the database table and return the value of the ID column.
*
* @param array $values
* @return int
*/
public function insert_get_id($values)
{
$query = $this->connection->pdo->prepare($this->grammar->insert_get_id($this, $values));
$query->execute(array_values($values));
return (int) $query->fetch(PDO::FETCH_CLASS, 'stdClass')->id;
}
}