Commit 15449c34 authored by Taylor Otwell's avatar Taylor Otwell

refactoring database layer.

parent 277729ed
......@@ -30,14 +30,6 @@ class Connection {
/**
* 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 @@ class Connection {
/**
* 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 @@ class Connection {
* 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 @@ class Connection {
/**
* 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 @@ class Connection {
/**
* 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)
{
......
<?php namespace Laravel\Database\Query\Grammars;
<?php namespace Laravel\Database\Grammars;
use Laravel\Database\Queries\Query;
use Laravel\Database\Query;
class Grammar {
......
<?php namespace Laravel\Database\Query\Grammars;
<?php namespace Laravel\Database\Grammars;
class MySQL extends Grammar {
......
......@@ -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 @@ class Manager {
*
* 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 @@ class Manager {
/**
* 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 @@ class Manager {
* 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)
{
......
<?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');
}
}
\ No newline at end of file
<?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;
}
}
\ No newline at end of file
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