refactoring the database layer.
This commit is contained in:
parent
3ada2cbd3e
commit
2521ab3c1d
|
@ -1,7 +1,5 @@
|
||||||
<?php namespace Laravel\Database\Connector;
|
<?php namespace Laravel\Database\Connector;
|
||||||
|
|
||||||
use Laravel\Database\Connector;
|
|
||||||
|
|
||||||
class Callback extends Connector {
|
class Callback extends Connector {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<?php namespace Laravel\Database;
|
<?php namespace Laravel\Database\Connector;
|
||||||
|
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php namespace Laravel\Database\Connector;
|
<?php namespace Laravel\Database\Connector;
|
||||||
|
|
||||||
use Laravel\Database\Connector;
|
use PDO;
|
||||||
|
|
||||||
class MySQL extends Connector {
|
class MySQL extends Connector {
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public function connect($config)
|
||||||
$dsn .= ';unix_socket='.$config['socket'];
|
$dsn .= ';unix_socket='.$config['socket'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$connection = new \PDO($dsn, $config['username'], $config['password'], $this->options);
|
$connection = new PDO($dsn, $config['username'], $config['password'], $this->options);
|
||||||
|
|
||||||
if (isset($config['charset']))
|
if (isset($config['charset']))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php namespace Laravel\Database\Connector;
|
<?php namespace Laravel\Database\Connector;
|
||||||
|
|
||||||
use Laravel\Database\Connector;
|
use PDO;
|
||||||
|
|
||||||
class Postgres extends Connector {
|
class Postgres extends Connector {
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ public function connect($config)
|
||||||
$dsn .= ';port='.$config['port'];
|
$dsn .= ';port='.$config['port'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$connection = new \PDO($dsn, $config['username'], $config['password'], $this->options);
|
$connection = new PDO($dsn, $config['username'], $config['password'], $this->options);
|
||||||
|
|
||||||
if (isset($config['charset']))
|
if (isset($config['charset']))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php namespace Laravel\Database\Connector;
|
<?php namespace Laravel\Database\Connector;
|
||||||
|
|
||||||
use Laravel\Database\Connector;
|
use PDO;
|
||||||
|
|
||||||
class SQLite extends Connector {
|
class SQLite extends Connector {
|
||||||
|
|
||||||
|
@ -14,15 +14,15 @@ public function connect($config)
|
||||||
{
|
{
|
||||||
if ($config['database'] == ':memory:')
|
if ($config['database'] == ':memory:')
|
||||||
{
|
{
|
||||||
return new \PDO('sqlite::memory:', null, null, $this->options);
|
return new PDO('sqlite::memory:', null, null, $this->options);
|
||||||
}
|
}
|
||||||
elseif (file_exists($path = DATABASE_PATH.$config['database'].'.sqlite'))
|
elseif (file_exists($path = DATABASE_PATH.$config['database'].'.sqlite'))
|
||||||
{
|
{
|
||||||
return new \PDO('sqlite:'.$path, null, null, $this->options);
|
return new PDO('sqlite:'.$path, null, null, $this->options);
|
||||||
}
|
}
|
||||||
elseif (file_exists($config['database']))
|
elseif (file_exists($config['database']))
|
||||||
{
|
{
|
||||||
return new \PDO('sqlite:'.$config['database'], null, null, $this->options);
|
return new PDO('sqlite:'.$config['database'], null, null, $this->options);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \Exception("SQLite database [".$config['database']."] could not be found.");
|
throw new \Exception("SQLite database [".$config['database']."] could not be found.");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<?php namespace Laravel\Database\Query;
|
<?php namespace Laravel\Database\Query\Compiler;
|
||||||
|
|
||||||
use Laravel\Database\Query;
|
use Laravel\Database\Query;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<?php namespace Laravel\Database\Query\Compiler;
|
<?php namespace Laravel\Database\Query\Compiler;
|
||||||
|
|
||||||
use Laravel\Database\Connection;
|
use Laravel\Database\Connection;
|
||||||
use Laravel\Database\Query\Compiler;
|
|
||||||
|
|
||||||
class Factory {
|
class Factory {
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
<?php namespace Laravel\Database\Query\Compiler;
|
<?php namespace Laravel\Database\Query\Compiler;
|
||||||
|
|
||||||
use Laravel\Database\Query\Compiler;
|
|
||||||
|
|
||||||
class MySQL extends Compiler {
|
class MySQL extends Compiler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
<?php namespace Laravel\Database\Query\Compiler;
|
<?php namespace Laravel\Database\Query\Compiler;
|
||||||
|
|
||||||
use Laravel\Database\Query\Compiler;
|
|
||||||
|
|
||||||
class Postgres extends Compiler {
|
class Postgres extends Compiler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?php namespace Laravel\Database\Query;
|
<?php namespace Laravel\Database\Query;
|
||||||
|
|
||||||
use Laravel\Database\Query;
|
|
||||||
use Laravel\Database\Connection;
|
use Laravel\Database\Connection;
|
||||||
|
|
||||||
class Factory {
|
class Factory {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php namespace Laravel\Database\Query;
|
<?php namespace Laravel\Database\Query;
|
||||||
|
|
||||||
use Laravel\Database\Query;
|
use PDO;
|
||||||
|
|
||||||
class Postgres extends Query {
|
class Postgres extends Query {
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ public function insert_get_id($values)
|
||||||
|
|
||||||
$query->execute(array_values($values));
|
$query->execute(array_values($values));
|
||||||
|
|
||||||
return (int) $query->fetch(\PDO::FETCH_CLASS, 'stdClass')->id;
|
return (int) $query->fetch(PDO::FETCH_CLASS, 'stdClass')->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
<?php namespace Laravel\Database;
|
<?php namespace Laravel\Database\Query;
|
||||||
|
|
||||||
|
use Laravel\Database\Connection;
|
||||||
|
|
||||||
class Query {
|
class Query {
|
||||||
|
|
||||||
|
@ -90,12 +92,12 @@ class Query {
|
||||||
/**
|
/**
|
||||||
* Create a new query instance.
|
* Create a new query instance.
|
||||||
*
|
*
|
||||||
* @param Connection $connection
|
* @param Database\Connection $connection
|
||||||
* @param Compiler $compiler
|
* @param Compiler $compiler
|
||||||
* @param string $table
|
* @param string $table
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(Connection $connection, Query\Compiler $compiler, $table)
|
public function __construct(Connection $connection, Compiler\Compiler $compiler, $table)
|
||||||
{
|
{
|
||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
$this->compiler = $compiler;
|
$this->compiler = $compiler;
|
Loading…
Reference in New Issue