db refactoring.

This commit is contained in:
Taylor Otwell
2011-08-22 21:56:42 -05:00
parent 0700910270
commit 5ca2e2b7f9
11 changed files with 585 additions and 235 deletions

View File

@@ -0,0 +1,35 @@
<?php namespace Laravel\DB\Query\Compiler;
use Laravel\DB\Connection;
use Laravel\DB\Query\Compiler;
class Factory {
/**
* Create a new query compiler for a given connection.
*
* Using driver-based compilers allows us to provide the proper syntax to different database
* systems using a common API. A core set of functions is provided through the base Compiler
* class, which can be extended and overridden for various database systems.
*
* @param Connection $connection
* @return Compiler
*/
public static function make(Connection $connection)
{
$compiler = (isset($connection->config['compiler'])) ? $connection->config['compiler'] : $connection->driver();
switch ($compiler)
{
case 'mysql':
return new MySQL;
case 'pgsql':
return new Postgres;
default:
return new Compiler;
}
}
}

View File

@@ -0,0 +1,14 @@
<?php namespace Laravel\DB\Query\Compiler;
use Laravel\DB\Query\Compiler;
class MySQL extends Compiler {
/**
* Get the keyword identifier wrapper for the connection.
*
* @return string
*/
public function wrapper() { return '`'; }
}

View File

@@ -0,0 +1,19 @@
<?php namespace Laravel\DB\Query\Compiler;
use Laravel\DB\Query\Compiler;
class Postgres extends Compiler {
/**
* 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');
}
}