mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Preparing for schema query suppory
This commit is contained in:
parent
309641f6fe
commit
5405c6e1ea
88
DataStorage/Database/BuilderAbstract.php
Normal file
88
DataStorage/Database/BuilderAbstract.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\DataStorage\Database;
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
|
||||
/**
|
||||
* Database query builder.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class BuilderAbstract
|
||||
{
|
||||
protected $grammar = null;
|
||||
|
||||
/**
|
||||
* Database connectino.
|
||||
*
|
||||
* @var ConnectionAbstract
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $connection = null;
|
||||
|
||||
/**
|
||||
* Query type.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = null;
|
||||
|
||||
/**
|
||||
* Prefix.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $prefix = '';
|
||||
|
||||
/**
|
||||
* Set prefix.
|
||||
*
|
||||
* @param \string $prefix Prefix
|
||||
*
|
||||
* @return BuilderAbstract
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function prefix(\string $prefix)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prefix.
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getPrefix() : \string
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ namespace phpOMS\DataStorage\Database\Connection;
|
|||
|
||||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
use phpOMS\DataStorage\Database\Query\Grammar\Grammar;
|
||||
use phpOMS\DataStorage\Database\Schema\Query\Grammar\Grammar as SchemaGrammar;
|
||||
|
||||
/**
|
||||
* Database handler.
|
||||
|
|
@ -87,6 +88,14 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
*/
|
||||
protected $grammar = null;
|
||||
|
||||
/**
|
||||
* Database grammar.
|
||||
*
|
||||
* @var Grammar
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $schemaGrammar = null;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -117,8 +126,8 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGrammar() : Grammar
|
||||
{
|
||||
if (!isset($this->grammar)) {
|
||||
|
|
@ -128,6 +137,18 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
return $this->grammar;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSchemaGrammar() : SchemaGrammar
|
||||
{
|
||||
if (!isset($this->schemaGrammar)) {
|
||||
$this->schemaGrammar = new SchemaGrammar();
|
||||
}
|
||||
|
||||
return $this->schemaGrammar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Object destructor.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
namespace phpOMS\DataStorage\Database\Connection;
|
||||
|
||||
use phpOMS\DataStorage\Database\Query\Grammar\Grammar;
|
||||
use phpOMS\DataStorage\Database\Schema\Query\Grammar\Grammar as SchemaGrammar;
|
||||
|
||||
/**
|
||||
* Database connection interface.
|
||||
|
|
@ -85,4 +86,14 @@ interface ConnectionInterface
|
|||
*/
|
||||
public function getGrammar() : Grammar;
|
||||
|
||||
/**
|
||||
* Return grammar for this connection.
|
||||
*
|
||||
* @return SchemaGrammar
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getSchemaGrammar() : SchemaGrammar;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace phpOMS\DataStorage\Database\Connection;
|
|||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
use phpOMS\DataStorage\Database\DatabaseType;
|
||||
use phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar;
|
||||
use phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar as MysqlSchemaGrammar;
|
||||
|
||||
/**
|
||||
* Database handler.
|
||||
|
|
@ -48,8 +49,9 @@ class MysqlConnection extends ConnectionAbstract
|
|||
*/
|
||||
public function __construct(array $dbdata)
|
||||
{
|
||||
$this->type = DatabaseType::MYSQL;
|
||||
$this->grammar = new MysqlGrammar();
|
||||
$this->type = DatabaseType::MYSQL;
|
||||
$this->grammar = new MysqlGrammar();
|
||||
$this->schemaGrammar = new MysqlSchemaGrammar();
|
||||
$this->connect($dbdata);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\DataStorage\Database;
|
||||
|
||||
abstract class Grammar
|
||||
{
|
||||
|
||||
protected $tablePrefix = '';
|
||||
|
||||
public function getDateFormat() : \string
|
||||
{
|
||||
return 'Y-m-d H:i:s';
|
||||
}
|
||||
|
||||
public function getTablePrefix() : \string
|
||||
{
|
||||
return $this->tablePrefix;
|
||||
}
|
||||
|
||||
public function setTablePrefix(\string $prefix)
|
||||
{
|
||||
$this->tablePrefix = $prefix;
|
||||
}
|
||||
|
||||
}
|
||||
136
DataStorage/Database/GrammarAbstract.php
Normal file
136
DataStorage/Database/GrammarAbstract.php
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\DataStorage\Database;
|
||||
|
||||
abstract class GrammarAbstract
|
||||
{
|
||||
/**
|
||||
* Comment style.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $comment = '--';
|
||||
|
||||
/**
|
||||
* String quotes style.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $valueQuotes = '\'';
|
||||
|
||||
/**
|
||||
* System identifier.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public $systemIdentifier = '"';
|
||||
|
||||
/**
|
||||
* And operator.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $and = 'AND';
|
||||
|
||||
/**
|
||||
* Or operator.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $or = 'OR';
|
||||
|
||||
protected $tablePrefix = '';
|
||||
|
||||
/**
|
||||
* Compile to query.
|
||||
*
|
||||
* @param Builder $query Builder
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function compileQuery($query) : \string
|
||||
{
|
||||
return trim(
|
||||
implode(' ',
|
||||
array_filter(
|
||||
$this->compileComponents($query),
|
||||
function ($value) {
|
||||
return (string) $value !== '';
|
||||
}
|
||||
)
|
||||
)
|
||||
) . ';';
|
||||
}
|
||||
|
||||
/**
|
||||
* Expressionize elements.
|
||||
*
|
||||
* @param array $elements Elements
|
||||
* @param \string $prefix Prefix for table
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
protected function expressionizeTableColumn(array $elements, \string $prefix = '') : \string
|
||||
{
|
||||
$expression = '';
|
||||
|
||||
foreach ($elements as $key => $element) {
|
||||
if (is_string($element) && $element !== '*') {
|
||||
$expression .= $this->compileSystem($element, $prefix) . ', ';
|
||||
} elseif (is_string($element) && $element === '*') {
|
||||
$expression .= '*, ';
|
||||
} elseif ($element instanceof \Closure) {
|
||||
$expression .= $element() . ', ';
|
||||
} elseif ($element instanceof BuilderAbstract) {
|
||||
$expression .= $element->toSql() . ', ';
|
||||
} else {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
return rtrim($expression, ', ');
|
||||
}
|
||||
|
||||
public function getDateFormat() : \string
|
||||
{
|
||||
return 'Y-m-d H:i:s';
|
||||
}
|
||||
|
||||
public function getTablePrefix() : \string
|
||||
{
|
||||
return $this->tablePrefix;
|
||||
}
|
||||
|
||||
public function setTablePrefix(\string $prefix)
|
||||
{
|
||||
$this->tablePrefix = $prefix;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
namespace phpOMS\DataStorage\Database\Query;
|
||||
|
||||
use phpOMS\DataStorage\Database\BuilderAbstract;
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\DataStorage\Database\Query;
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ use phpOMS\DataStorage\Database\Query;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Builder
|
||||
class Builder extends BuilderAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
|
|
@ -153,44 +154,12 @@ class Builder
|
|||
*/
|
||||
public $lock = false;
|
||||
|
||||
/**
|
||||
* Database connectino.
|
||||
*
|
||||
* @var ConnectionAbstract
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $connection = null;
|
||||
|
||||
/**
|
||||
* Grammar.
|
||||
*
|
||||
* @var \phpOMS\DataStorage\Database\Query\Grammar\GrammarInterface
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $grammar = null;
|
||||
|
||||
/**
|
||||
* Query type.
|
||||
*
|
||||
* @var QueryType
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = QueryType::INSERT;
|
||||
|
||||
protected $unionLimit = null;
|
||||
|
||||
protected $unionOffset = null;
|
||||
|
||||
protected $unionOrders = [];
|
||||
|
||||
/**
|
||||
* Prefix.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $prefix = '';
|
||||
|
||||
/**
|
||||
* Comparison operators.
|
||||
*
|
||||
|
|
@ -241,36 +210,6 @@ class Builder
|
|||
$this->grammar = $connection->getGrammar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set prefix.
|
||||
*
|
||||
* @param \string $prefix Prefix
|
||||
*
|
||||
* @return Builder
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function prefix(\string $prefix)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prefix.
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getPrefix() : \string
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
namespace phpOMS\DataStorage\Database\Query\Grammar;
|
||||
|
||||
use phpOMS\DataStorage\Database\GrammarAbstract;
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\Query\Column;
|
||||
use phpOMS\DataStorage\Database\Query\QueryType;
|
||||
|
|
@ -31,49 +32,8 @@ use phpOMS\DataStorage\Database\Query\QueryType;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Grammar extends \phpOMS\DataStorage\Database\Grammar
|
||||
class Grammar extends GrammarAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Comment style.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $comment = '--';
|
||||
|
||||
/**
|
||||
* String quotes style.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $valueQuotes = '\'';
|
||||
|
||||
/**
|
||||
* System identifier.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public $systemIdentifier = '"';
|
||||
|
||||
/**
|
||||
* And operator.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $and = 'AND';
|
||||
|
||||
/**
|
||||
* Or operator.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $or = 'OR';
|
||||
|
||||
/**
|
||||
* Select components.
|
||||
*
|
||||
|
|
@ -119,32 +79,6 @@ class Grammar extends \phpOMS\DataStorage\Database\Grammar
|
|||
'wheres',
|
||||
];
|
||||
|
||||
/**
|
||||
* Compile to query.
|
||||
*
|
||||
* @param Builder $query Builder
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function compileQuery($query) : \string
|
||||
{
|
||||
return trim(
|
||||
implode(' ',
|
||||
array_filter(
|
||||
$this->compileComponents($query),
|
||||
function ($value) {
|
||||
return (string) $value !== '';
|
||||
}
|
||||
)
|
||||
)
|
||||
) . ';';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile components.
|
||||
*
|
||||
|
|
@ -203,45 +137,13 @@ class Grammar extends \phpOMS\DataStorage\Database\Grammar
|
|||
{
|
||||
$expression = $this->expressionizeTableColumn($columns, $query->getPrefix());
|
||||
|
||||
if ($expression == '') {
|
||||
return '';
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
}
|
||||
|
||||
return ($query->distinct ? 'SELECT DISTINCT ' : 'SELECT ') . $expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expressionize elements.
|
||||
*
|
||||
* @param array $elements Elements
|
||||
* @param \string $prefix Prefix for table
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
protected function expressionizeTableColumn(array $elements, \string $prefix = '') : \string
|
||||
{
|
||||
$expression = '';
|
||||
|
||||
foreach ($elements as $key => $element) {
|
||||
if (is_string($element) && $element !== '*') {
|
||||
$expression .= $this->compileSystem($element, $prefix) . ', ';
|
||||
} elseif (is_string($element) && $element === '*') {
|
||||
$expression .= '*, ';
|
||||
} elseif ($element instanceof \Closure) {
|
||||
$expression .= $element() . ', ';
|
||||
} elseif ($element instanceof Builder) {
|
||||
$expression .= $element->toSql() . ', ';
|
||||
} else {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
return rtrim($expression, ', ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile from.
|
||||
*
|
||||
|
|
@ -257,7 +159,7 @@ class Grammar extends \phpOMS\DataStorage\Database\Grammar
|
|||
{
|
||||
$expression = $this->expressionizeTableColumn($table, $query->getPrefix());
|
||||
|
||||
if ($expression == '') {
|
||||
if ($expression === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\DataStorage\Database\Schema\Query;
|
||||
|
||||
use phpOMS\DataStorage\Database\BuilderAbstract;
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\DataStorage\Database\Query;
|
||||
use phpOMS\DataStorage\Database\Schema\QueryType;
|
||||
|
||||
/**
|
||||
* Database query builder.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Builder extends BuilderAbstract
|
||||
{
|
||||
private $type = QueryType::SELECT;
|
||||
|
||||
private $table = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ConnectionAbstract $connection Database connection
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(ConnectionAbstract $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->grammar = $connection->getSchemaGrammar();
|
||||
}
|
||||
|
||||
public function select(...$table)
|
||||
{
|
||||
$this->type = QueryType::SELECT;
|
||||
$this->table += $table;
|
||||
$this->table = array_unique($this->table);
|
||||
}
|
||||
|
||||
public function drop(\string $table)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function create(\string $table)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function alter(array $column)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
44
DataStorage/Database/Schema/Grammar/Grammar.php
Normal file
44
DataStorage/Database/Schema/Grammar/Grammar.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\DataStorage\Database\Schema\Grammar;
|
||||
|
||||
use phpOMS\DataStorage\Database\GrammarAbstract;
|
||||
|
||||
/**
|
||||
* Database query grammar.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Grammar extends GrammarAbstract
|
||||
{
|
||||
/**
|
||||
* Select components.
|
||||
*
|
||||
* @var \string[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $selectComponents = [
|
||||
'selects',
|
||||
'from',
|
||||
];
|
||||
}
|
||||
|
|
@ -18,44 +18,4 @@ namespace phpOMS\DataStorage\Database\Schema;
|
|||
interface GrammarInterface
|
||||
{
|
||||
|
||||
public function typeTinyInt($places);
|
||||
|
||||
public function typeSmallInt($places);
|
||||
|
||||
public function typeMediumInt($places);
|
||||
|
||||
public function typeInt($places);
|
||||
|
||||
public function typeBigInt($places);
|
||||
|
||||
public function typeFloat($m, $e, $b = 10);
|
||||
|
||||
public function typeDouble($m, $e, $b = 10);
|
||||
|
||||
public function typeDecimal($a, $b);
|
||||
|
||||
public function typeBoolean();
|
||||
|
||||
public function typeJson();
|
||||
|
||||
public function typeDate();
|
||||
|
||||
public function typeTime();
|
||||
|
||||
public function typeDateTime();
|
||||
|
||||
public function typeTimestamp();
|
||||
|
||||
public function typeBinary();
|
||||
|
||||
public function typeChar();
|
||||
|
||||
public function typeString();
|
||||
|
||||
public function typeMediumText();
|
||||
|
||||
public function typeText();
|
||||
|
||||
public function typeLongText();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\DataStorage\Database\Schema\Grammar;
|
||||
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
|
||||
/**
|
||||
* Database query grammar.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class MysqlGrammar extends Grammar
|
||||
{
|
||||
/**
|
||||
* Compile select.
|
||||
*
|
||||
* @param Builder $query Builder
|
||||
* @param array $columns Columns
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
protected function compileSelects(Builder $query, array $columns) : \string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($columns);
|
||||
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
}
|
||||
|
||||
return $expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile from.
|
||||
*
|
||||
* @param Builder $query Builder
|
||||
* @param array $table Tables
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
protected function compileFrom(Builder $query, array $table) : \string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn('information_schema.tables');
|
||||
|
||||
return 'FROM ' . $expression;
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,8 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class QueryType extends Enum
|
||||
{
|
||||
const CREATE = 0;
|
||||
const DROP = 1;
|
||||
const ALTER = 2;
|
||||
const SELECT = 0;
|
||||
const CREATE = 1;
|
||||
const DROP = 2;
|
||||
const ALTER = 3;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user