From 15449c34b1b7fab8b10fb022c39fc517f03efaef Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 13 Sep 2011 23:04:28 -0500 Subject: [PATCH] refactoring database layer. --- laravel/database/connection.php | 37 ------------------- .../{queries => }/grammars/grammar.php | 4 +- .../database/{queries => }/grammars/mysql.php | 2 +- laravel/database/manager.php | 29 +-------------- .../database/queries/grammars/postgres.php | 19 ---------- laravel/database/queries/postgres.php | 22 ----------- 6 files changed, 4 insertions(+), 109 deletions(-) rename laravel/database/{queries => }/grammars/grammar.php (98%) rename laravel/database/{queries => }/grammars/mysql.php (77%) delete mode 100644 laravel/database/queries/grammars/postgres.php delete mode 100644 laravel/database/queries/postgres.php diff --git a/laravel/database/connection.php b/laravel/database/connection.php index 4542f7ec..011dd49e 100644 --- a/laravel/database/connection.php +++ b/laravel/database/connection.php @@ -30,14 +30,6 @@ class Connection { /** * Execute a SQL query against the connection and return a scalar result. * - * - * // 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)); - * - * * @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. * - * - * // 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)); - * - * * @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. * - * - * // 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)); - * - * * @param string $sql * @param array $bindings * @return mixed @@ -124,14 +100,6 @@ class Connection { /** * Begin a fluent query against a table. * - * - * // 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(); - * - * * @param string $table * @return Query */ @@ -172,11 +140,6 @@ class Connection { /** * Magic Method for dynamically beginning queries on database tables. - * - * - * // Begin a query against the "users" table - * $query = DB::connection()->users(); - * */ public function __call($method, $parameters) { diff --git a/laravel/database/queries/grammars/grammar.php b/laravel/database/grammars/grammar.php similarity index 98% rename from laravel/database/queries/grammars/grammar.php rename to laravel/database/grammars/grammar.php index 9de7eece..4e97f6b4 100644 --- a/laravel/database/queries/grammars/grammar.php +++ b/laravel/database/grammars/grammar.php @@ -1,6 +1,6 @@ -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. * - * - * // Get the default database connection - * $connection = DB::connection(); - * - * // Get a database connection by name - * $connection = DB::connection('slave'); - * - * * @param string $connection * @return Database\Connection */ @@ -63,14 +52,6 @@ class Manager { /** * Begin a fluent query against a table. * - * - * // 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'); - * - * * @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. - * - * - * // 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(); - * */ public function __call($method, $parameters) { diff --git a/laravel/database/queries/grammars/postgres.php b/laravel/database/queries/grammars/postgres.php deleted file mode 100644 index 2e146cd6..00000000 --- a/laravel/database/queries/grammars/postgres.php +++ /dev/null @@ -1,19 +0,0 @@ -insert($query, $values).' RETURNING '.$this->wrap('id'); - } - -} \ No newline at end of file diff --git a/laravel/database/queries/postgres.php b/laravel/database/queries/postgres.php deleted file mode 100644 index 62aefac2..00000000 --- a/laravel/database/queries/postgres.php +++ /dev/null @@ -1,22 +0,0 @@ -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