Merge branch 'master' of github.com:hyperf-cloud/hyperf

This commit is contained in:
huangzhhui 2018-12-31 16:32:20 +08:00
commit 1c9b78f7d0
55 changed files with 585 additions and 4949 deletions

View File

@ -84,6 +84,7 @@
},
"autoload-dev": {
"psr-4": {
"HyperfTest\\Dispatcher\\": "test"
}
},
"config": {

View File

@ -20,13 +20,11 @@ trait ManagesTransactions
/**
* Execute a Closure within a transaction.
*
* @param \Closure $callback
* @param int $attempts
* @return mixed
*
* @throws \Exception|\Throwable
*/
public function transaction(Closure $callback, $attempts = 1)
public function transaction(Closure $callback, int $attempts = 1)
{
for ($currentAttempt = 1; $currentAttempt <= $attempts; $currentAttempt++) {
$this->beginTransaction();
@ -59,9 +57,6 @@ trait ManagesTransactions
/**
* Start a new database transaction.
*
* @return void
*
* @throws \Exception
*/
public function beginTransaction(): void
@ -75,8 +70,6 @@ trait ManagesTransactions
/**
* Commit the active database transaction.
*
* @return void
*/
public function commit(): void
{

View File

@ -23,7 +23,7 @@ use Hyperf\Database\Query\Grammars\Grammar as QueryGrammar;
use Hyperf\Database\Query\Processors\Processor;
use Hyperf\Database\Schema\Builder as SchemaBuilder;
use Hyperf\Utils\Arr;
use Illuminate\Contracts\Events\Dispatcher;
use Hyperf\Contracts\Events\Dispatcher;
use LogicException;
use PDO;
use PDOStatement;
@ -79,28 +79,28 @@ class Connection implements ConnectionInterface
/**
* The query grammar implementation.
*
* @var \Illuminate\Database\Query\Grammars\Grammar
* @var \Hyperf\Database\Query\Grammars\Grammar
*/
protected $queryGrammar;
/**
* The schema grammar implementation.
*
* @var \Illuminate\Database\Schema\Grammars\Grammar
* @var \Hyperf\Database\Schema\Grammars\Grammar
*/
protected $schemaGrammar;
/**
* The query post processor implementation.
*
* @var \Illuminate\Database\Query\Processors\Processor
* @var \Hyperf\Database\Query\Processors\Processor
*/
protected $postProcessor;
/**
* The event dispatcher instance.
*
* @var \Illuminate\Contracts\Events\Dispatcher
* @var \Hyperf\Contracts\Events\Dispatcher
*/
protected $events;
@ -192,38 +192,31 @@ class Connection implements ConnectionInterface
/**
* Set the query grammar to the default implementation.
*
* @return void
*/
public function useDefaultQueryGrammar()
public function useDefaultQueryGrammar():void
{
$this->queryGrammar = $this->getDefaultQueryGrammar();
}
/**
* Set the schema grammar to the default implementation.
*
* @return void
*/
public function useDefaultSchemaGrammar()
public function useDefaultSchemaGrammar():void
{
$this->schemaGrammar = $this->getDefaultSchemaGrammar();
}
/**
* Set the query post processor to the default implementation.
*
* @return void
*/
public function useDefaultPostProcessor()
public function useDefaultPostProcessor():void
{
$this->postProcessor = $this->getDefaultPostProcessor();
}
/**
* Get a schema builder instance for the connection.
*
* @return \Illuminate\Database\Schema\Builder
* @return SchemaBuilder
*/
public function getSchemaBuilder()
{
@ -236,21 +229,16 @@ class Connection implements ConnectionInterface
/**
* Begin a fluent query against a database table.
*
* @param string $table
* @return \Illuminate\Database\Query\Builder
*/
public function table($table): Builder
public function table(string $table): Builder
{
return $this->query()->from($table);
}
/**
* Get a new query builder instance.
*
* @return \Illuminate\Database\Query\Builder
*/
public function query()
public function query(): QueryBuilder
{
return new QueryBuilder(
$this,
@ -261,13 +249,9 @@ class Connection implements ConnectionInterface
/**
* Run a select statement and return a single result.
*
* @param string $query
* @param array $bindings
* @param bool $useReadPdo
* @return mixed
*/
public function selectOne($query, $bindings = [], $useReadPdo = true)
public function selectOne(string $query, array $bindings = [], bool $useReadPdo = true)
{
$records = $this->select($query, $bindings, $useReadPdo);
@ -276,25 +260,16 @@ class Connection implements ConnectionInterface
/**
* Run a select statement against the database.
*
* @param string $query
* @param array $bindings
* @return array
*/
public function selectFromWriteConnection($query, $bindings = [])
public function selectFromWriteConnection(string $query, array $bindings = []):array
{
return $this->select($query, $bindings, false);
}
/**
* Run a select statement against the database.
*
* @param string $query
* @param array $bindings
* @param bool $useReadPdo
* @return array
*/
public function select($query, $bindings = [], $useReadPdo = true): array
public function select(string $query, array $bindings = [], bool $useReadPdo = true): array
{
return $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
if ($this->pretending()) {
@ -317,13 +292,8 @@ class Connection implements ConnectionInterface
/**
* Run a select statement against the database and returns a generator.
*
* @param string $query
* @param array $bindings
* @param bool $useReadPdo
* @return \Generator
*/
public function cursor($query, $bindings = [], $useReadPdo = true): \Generator
public function cursor(string $query, array $bindings = [], bool $useReadPdo = true): \Generator
{
$statement = $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
if ($this->pretending()) {
@ -356,48 +326,32 @@ class Connection implements ConnectionInterface
/**
* Run an insert statement against the database.
*
* @param string $query
* @param array $bindings
* @return bool
*/
public function insert($query, $bindings = []): bool
public function insert(string $query, array $bindings = []): bool
{
return $this->statement($query, $bindings);
}
/**
* Run an update statement against the database.
*
* @param string $query
* @param array $bindings
* @return int
*/
public function update($query, $bindings = []): int
public function update(string $query, array $bindings = []): int
{
return $this->affectingStatement($query, $bindings);
}
/**
* Run a delete statement against the database.
*
* @param string $query
* @param array $bindings
* @return int
*/
public function delete($query, $bindings = []): int
public function delete(string $query, array $bindings = []): int
{
return $this->affectingStatement($query, $bindings);
}
/**
* Execute an SQL statement and return the boolean result.
*
* @param string $query
* @param array $bindings
* @return bool
*/
public function statement($query, $bindings = []): bool
public function statement(string $query, array $bindings = []): bool
{
return $this->run($query, $bindings, function ($query, $bindings) {
if ($this->pretending()) {
@ -416,12 +370,8 @@ class Connection implements ConnectionInterface
/**
* Run an SQL statement and get the number of rows affected.
*
* @param string $query
* @param array $bindings
* @return int
*/
public function affectingStatement($query, $bindings = []): int
public function affectingStatement(string $query, array $bindings = []): int
{
return $this->run($query, $bindings, function ($query, $bindings) {
if ($this->pretending()) {
@ -447,11 +397,8 @@ class Connection implements ConnectionInterface
/**
* Run a raw, unprepared query against the PDO connection.
*
* @param string $query
* @return bool
*/
public function unprepared($query): bool
public function unprepared(string $query): bool
{
return $this->run($query, [], function ($query) {
if ($this->pretending()) {
@ -468,9 +415,6 @@ class Connection implements ConnectionInterface
/**
* Execute the given callback in "dry run" mode.
*
* @param \Closure $callback
* @return array
*/
public function pretend(Closure $callback): array
{
@ -490,12 +434,8 @@ class Connection implements ConnectionInterface
/**
* Bind values to their parameters in the given statement.
*
* @param \PDOStatement $statement
* @param array $bindings
* @return void
*/
public function bindValues($statement, $bindings)
public function bindValues(\PDOStatement $statement, array $bindings): void
{
foreach ($bindings as $key => $value) {
$statement->bindValue(
@ -508,9 +448,6 @@ class Connection implements ConnectionInterface
/**
* Prepare the query bindings for execution.
*
* @param array $bindings
* @return array
*/
public function prepareBindings(array $bindings): array
{
@ -590,7 +527,7 @@ class Connection implements ConnectionInterface
* Get a new raw query expression.
*
* @param mixed $value
* @return \Illuminate\Database\Query\Expression
* @return \Hyperf\Database\Query\Expression
*/
public function raw($value): Expression
{
@ -775,7 +712,7 @@ class Connection implements ConnectionInterface
/**
* Get the query grammar used by the connection.
*
* @return \Illuminate\Database\Query\Grammars\Grammar
* @return \Hyperf\Database\Query\Grammars\Grammar
*/
public function getQueryGrammar()
{
@ -785,7 +722,7 @@ class Connection implements ConnectionInterface
/**
* Set the query grammar used by the connection.
*
* @param \Illuminate\Database\Query\Grammars\Grammar $grammar
* @param \Hyperf\Database\Query\Grammars\Grammar $grammar
* @return $this
*/
public function setQueryGrammar(Query\Grammars\Grammar $grammar)
@ -798,7 +735,7 @@ class Connection implements ConnectionInterface
/**
* Get the schema grammar used by the connection.
*
* @return \Illuminate\Database\Schema\Grammars\Grammar
* @return \Hyperf\Database\Schema\Grammars\Grammar
*/
public function getSchemaGrammar()
{
@ -808,7 +745,7 @@ class Connection implements ConnectionInterface
/**
* Set the schema grammar used by the connection.
*
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
* @return $this
*/
public function setSchemaGrammar(Schema\Grammars\Grammar $grammar)
@ -821,7 +758,7 @@ class Connection implements ConnectionInterface
/**
* Get the query post processor used by the connection.
*
* @return \Illuminate\Database\Query\Processors\Processor
* @return \Hyperf\Database\Query\Processors\Processor
*/
public function getPostProcessor()
{
@ -831,7 +768,7 @@ class Connection implements ConnectionInterface
/**
* Set the query post processor used by the connection.
*
* @param \Illuminate\Database\Query\Processors\Processor $processor
* @param \Hyperf\Database\Query\Processors\Processor $processor
* @return $this
*/
public function setPostProcessor(Processor $processor)
@ -844,7 +781,7 @@ class Connection implements ConnectionInterface
/**
* Get the event dispatcher used by the connection.
*
* @return \Illuminate\Contracts\Events\Dispatcher
* @return \Hyperf\Contracts\Events\Dispatcher
*/
public function getEventDispatcher()
{
@ -854,7 +791,7 @@ class Connection implements ConnectionInterface
/**
* Set the event dispatcher instance on the connection.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @param \Hyperf\Contracts\Events\Dispatcher $events
* @return $this
*/
public function setEventDispatcher(Dispatcher $events)
@ -985,8 +922,8 @@ class Connection implements ConnectionInterface
/**
* Set the table prefix and return the grammar.
*
* @param \Illuminate\Database\Grammar $grammar
* @return \Illuminate\Database\Grammar
* @param \Hyperf\Database\Grammar $grammar
* @return \Hyperf\Database\Grammar
*/
public function withTablePrefix(Grammar $grammar)
{
@ -1021,7 +958,7 @@ class Connection implements ConnectionInterface
/**
* Get the default query grammar instance.
*
* @return \Illuminate\Database\Query\Grammars\Grammar
* @return \Hyperf\Database\Query\Grammars\Grammar
*/
protected function getDefaultQueryGrammar()
{
@ -1031,7 +968,7 @@ class Connection implements ConnectionInterface
/**
* Get the default schema grammar instance.
*
* @return \Illuminate\Database\Schema\Grammars\Grammar
* @return \Hyperf\Database\Schema\Grammars\Grammar
*/
protected function getDefaultSchemaGrammar()
{
@ -1041,7 +978,7 @@ class Connection implements ConnectionInterface
/**
* Get the default post processor instance.
*
* @return \Illuminate\Database\Query\Processors\Processor
* @return \Hyperf\Database\Query\Processors\Processor
*/
protected function getDefaultPostProcessor()
{
@ -1112,7 +1049,7 @@ class Connection implements ConnectionInterface
* @param \Closure $callback
* @return mixed
*
* @throws \Illuminate\Database\QueryException
* @throws \Hyperf\Database\QueryException
*/
protected function run($query, $bindings, Closure $callback)
{
@ -1154,7 +1091,7 @@ class Connection implements ConnectionInterface
* @param \Closure $callback
* @return mixed
*
* @throws \Illuminate\Database\QueryException
* @throws \Hyperf\Database\QueryException
*/
protected function runQueryCallback($query, $bindings, Closure $callback)
{
@ -1218,13 +1155,13 @@ class Connection implements ConnectionInterface
/**
* Handle a query exception that occurred during query execution.
*
* @param \Illuminate\Database\QueryException $e
* @param \Hyperf\Database\QueryException $e
* @param string $query
* @param array $bindings
* @param \Closure $callback
* @return mixed
*
* @throws \Illuminate\Database\QueryException
* @throws \Hyperf\Database\QueryException
*/
protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, Closure $callback)
{

View File

@ -20,155 +20,95 @@ interface ConnectionInterface
{
/**
* Begin a fluent query against a database table.
*
* @param string $table
* @return \Illuminate\Database\Query\Builder
*/
public function table($table): Builder;
public function table(string $table): Builder;
/**
* Get a new raw query expression.
*
* @param mixed $value
* @return \Illuminate\Database\Query\Expression
*/
public function raw($value): Expression;
/**
* Run a select statement and return a single result.
*
* @param string $query
* @param array $bindings
* @param bool $useReadPdo
* @return mixed
*/
public function selectOne($query, $bindings = [], $useReadPdo = true);
public function selectOne(string $query, array $bindings = [], bool $useReadPdo = true);
/**
* Run a select statement against the database.
*
* @param string $query
* @param array $bindings
* @param bool $useReadPdo
* @return array
*/
public function select($query, $bindings = [], $useReadPdo = true): array;
public function select(string $query, array $bindings = [], bool $useReadPdo = true): array;
/**
* Run a select statement against the database and returns a generator.
*
* @param string $query
* @param array $bindings
* @param bool $useReadPdo
* @return \Generator
*/
public function cursor($query, $bindings = [], $useReadPdo = true): Generator;
public function cursor(string $query, array $bindings = [], bool $useReadPdo = true): Generator;
/**
* Run an insert statement against the database.
*
* @param string $query
* @param array $bindings
* @return bool
*/
public function insert($query, $bindings = []): bool;
public function insert(string $query, array $bindings = []): bool;
/**
* Run an update statement against the database.
*
* @param string $query
* @param array $bindings
* @return int
*/
public function update($query, $bindings = []): int;
public function update(string $query, array $bindings = []): int;
/**
* Run a delete statement against the database.
*
* @param string $query
* @param array $bindings
* @return int
*/
public function delete($query, $bindings = []): int;
public function delete(string $query, array $bindings = []): int;
/**
* Execute an SQL statement and return the boolean result.
*
* @param string $query
* @param array $bindings
* @return bool
*/
public function statement($query, $bindings = []): bool;
public function statement(string $query, array $bindings = []): bool;
/**
* Run an SQL statement and get the number of rows affected.
*
* @param string $query
* @param array $bindings
* @return int
*/
public function affectingStatement($query, $bindings = []): int;
public function affectingStatement(string $query, array $bindings = []): int;
/**
* Run a raw, unprepared query against the PDO connection.
*
* @param string $query
* @return bool
*/
public function unprepared($query): bool;
public function unprepared(string $query): bool;
/**
* Prepare the query bindings for execution.
*
* @param array $bindings
* @return array
*/
public function prepareBindings(array $bindings): array;
/**
* Execute a Closure within a transaction.
*
* @param \Closure $callback
* @param int $attempts
* @return mixed
*
* @throws \Throwable
*/
public function transaction(Closure $callback, $attempts = 1);
public function transaction(Closure $callback, int $attempts = 1);
/**
* Start a new database transaction.
*
* @return void
*/
public function beginTransaction(): void;
/**
* Commit the active database transaction.
*
* @return void
*/
public function commit(): void;
/**
* Rollback the active database transaction.
*
* @return void
*/
public function rollBack(): void;
/**
* Get the number of active transactions.
*
* @return int
*/
public function transactionLevel(): int;
/**
* Execute the given callback in "dry run" mode.
*
* @param \Closure $callback
* @return array
*/
public function pretend(Closure $callback): array;
}

View File

@ -44,7 +44,7 @@ class ConnectionResolver implements ConnectionResolverInterface
* Get a database connection instance.
*
* @param string $name
* @return \Illuminate\Database\ConnectionInterface
* @return \Hyperf\Database\ConnectionInterface
*/
public function connection($name = null)
{
@ -59,7 +59,7 @@ class ConnectionResolver implements ConnectionResolverInterface
* Add a connection to the resolver.
*
* @param string $name
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Hyperf\Database\ConnectionInterface $connection
* @return void
*/
public function addConnection($name, ConnectionInterface $connection)

View File

@ -275,7 +275,7 @@ class ConnectionFactory
* @param string $database
* @param string $prefix
* @param array $config
* @return \Illuminate\Database\Connection
* @return \Hyperf\Database\Connection
*
* @throws \InvalidArgumentException
*/

View File

@ -18,21 +18,21 @@ use InvalidArgumentException;
use PDO;
/**
* @mixin \Illuminate\Database\Connection
* @mixin \Hyperf\Database\Connection
*/
class DatabaseManager implements ConnectionResolverInterface
{
/**
* The application instance.
*
* @var \Illuminate\Contracts\Foundation\Application
* @var \Hyperf\Contracts\Foundation\Application
*/
protected $app;
/**
* The database connection factory instance.
*
* @var \Illuminate\Database\Connectors\ConnectionFactory
* @var \Hyperf\Database\Connectors\ConnectionFactory
*/
protected $factory;
@ -53,8 +53,8 @@ class DatabaseManager implements ConnectionResolverInterface
/**
* Create a new database manager instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Database\Connectors\ConnectionFactory $factory
* @param \Hyperf\Contracts\Foundation\Application $app
* @param \Hyperf\Database\Connectors\ConnectionFactory $factory
* @return void
*/
public function __construct($app, ConnectionFactory $factory)
@ -79,7 +79,7 @@ class DatabaseManager implements ConnectionResolverInterface
* Get a database connection instance.
*
* @param string $name
* @return \Illuminate\Database\Connection
* @return \Hyperf\Database\Connection
*/
public function connection($name = null)
{
@ -132,7 +132,7 @@ class DatabaseManager implements ConnectionResolverInterface
* Reconnect to the given database.
*
* @param string $name
* @return \Illuminate\Database\Connection
* @return \Hyperf\Database\Connection
*/
public function reconnect($name = null)
{
@ -229,7 +229,7 @@ class DatabaseManager implements ConnectionResolverInterface
* Make the database connection instance.
*
* @param string $name
* @return \Illuminate\Database\Connection
* @return \Hyperf\Database\Connection
*/
protected function makeConnection($name)
{
@ -279,9 +279,9 @@ class DatabaseManager implements ConnectionResolverInterface
/**
* Prepare the database connection instance.
*
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Connection $connection
* @param string $type
* @return \Illuminate\Database\Connection
* @return \Hyperf\Database\Connection
*/
protected function configure(Connection $connection, $type)
{
@ -307,9 +307,9 @@ class DatabaseManager implements ConnectionResolverInterface
/**
* Prepare the read / write mode for database connection instance.
*
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Connection $connection
* @param string $type
* @return \Illuminate\Database\Connection
* @return \Hyperf\Database\Connection
*/
protected function setPdoForType(Connection $connection, $type = null)
{
@ -326,7 +326,7 @@ class DatabaseManager implements ConnectionResolverInterface
* Refresh the PDO connections on a given connection.
*
* @param string $name
* @return \Illuminate\Database\Connection
* @return \Hyperf\Database\Connection
*/
protected function refreshPdoConnections($name)
{

View File

@ -23,14 +23,14 @@ abstract class ConnectionEvent
/**
* The database connection instance.
*
* @var \Illuminate\Database\Connection
* @var \Hyperf\Database\Connection
*/
public $connection;
/**
* Create a new event instance.
*
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Connection $connection
* @return void
*/
public function __construct($connection)

View File

@ -16,7 +16,7 @@ class StatementPrepared
/**
* The database connection instance.
*
* @var \Illuminate\Database\Connection
* @var \Hyperf\Database\Connection
*/
public $connection;
@ -30,7 +30,7 @@ class StatementPrepared
/**
* Create a new event instance.
*
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Connection $connection
* @param \PDOStatement $statement
* @return void
*/

View File

@ -39,7 +39,7 @@ abstract class Grammar
/**
* Wrap a table in keyword identifiers.
*
* @param \Illuminate\Database\Query\Expression|string $table
* @param \Hyperf\Database\Query\Expression|string $table
* @return string
*/
public function wrapTable($table)
@ -54,7 +54,7 @@ abstract class Grammar
/**
* Wrap a value in keyword identifiers.
*
* @param \Illuminate\Database\Query\Expression|string $value
* @param \Hyperf\Database\Query\Expression|string $value
* @param bool $prefixAlias
* @return string
*/
@ -136,7 +136,7 @@ abstract class Grammar
/**
* Get the value of a raw expression.
*
* @param \Illuminate\Database\Query\Expression $expression
* @param \Hyperf\Database\Query\Expression $expression
* @return string
*/
public function getValue($expression)

View File

@ -19,10 +19,10 @@ use Hyperf\Database\Query\Builder as QueryBuilder;
use Hyperf\Utils\Arr;
use Hyperf\Utils\Contracts\Arrayable;
use Hyperf\Utils\Str;
use Illuminate\Pagination\Paginator;
use Hyperf\Pagination\Paginator;
/**
* @mixin \Illuminate\Database\Query\Builder
* @mixin \Hyperf\Database\Query\Builder
*/
class Builder
{
@ -31,7 +31,7 @@ class Builder
/**
* The base query builder instance.
*
* @var \Illuminate\Database\Query\Builder
* @var \Hyperf\Database\Query\Builder
*/
protected $query;
@ -97,7 +97,7 @@ class Builder
/**
* Create a new Model query builder instance.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return void
*/
public function __construct(QueryBuilder $query)
@ -419,7 +419,7 @@ class Builder
/**
* Find multiple models by their primary keys.
*
* @param \Illuminate\Contracts\Support\Arrayable|array $ids
* @param \Hyperf\Contracts\Support\Arrayable|array $ids
* @param array $columns
* @return \Hyperf\Database\Model\Collection
*/
@ -722,7 +722,7 @@ class Builder
*
* @param string $column
* @param string|null $key
* @return \Illuminate\Support\Collection
* @return \Hyperf\Support\Collection
*/
public function pluck($column, $key = null)
{
@ -749,7 +749,7 @@ class Builder
* @param array $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
* @return \Hyperf\Contracts\Pagination\LengthAwarePaginator
*
* @throws \InvalidArgumentException
*/
@ -776,7 +776,7 @@ class Builder
* @param array $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\Paginator
* @return \Hyperf\Contracts\Pagination\Paginator
*/
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
@ -1017,7 +1017,7 @@ class Builder
/**
* Get the underlying query builder instance.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
public function getQuery()
{
@ -1027,7 +1027,7 @@ class Builder
/**
* Set the underlying query builder instance.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return $this
*/
public function setQuery($query)
@ -1040,7 +1040,7 @@ class Builder
/**
* Get a base query builder instance.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
public function toBase()
{
@ -1243,7 +1243,7 @@ class Builder
/**
* Nest where conditions by slicing them at the given where count.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param int $originalWhereCount
* @return void
*/
@ -1270,7 +1270,7 @@ class Builder
/**
* Slice where conditions at the given offset and add them to the query as a nested condition.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $whereSlice
* @return void
*/

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Hyperf\Database\Model\Concerns;
use Illuminate\Support\Str;
use Hyperf\Support\Str;
trait GuardsAttributes
{

View File

@ -15,12 +15,12 @@ use Carbon\CarbonInterface;
use DateTimeInterface;
use Hyperf\Database\Model\JsonEncodingException;
use Hyperf\Database\Model\Relations\Relation;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection as BaseCollection;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Str;
use Hyperf\Contracts\Support\Arrayable;
use Hyperf\Support\Arr;
use Hyperf\Support\Carbon;
use Hyperf\Support\Collection as BaseCollection;
use Hyperf\Support\Facades\Date;
use Hyperf\Support\Str;
use LogicException;
trait HasAttributes
@ -1110,7 +1110,7 @@ trait HasAttributes
* Return a timestamp as DateTime object with time set to 00:00:00.
*
* @param mixed $value
* @return \Illuminate\Support\Carbon
* @return \Hyperf\Support\Carbon
*/
protected function asDate($value)
{
@ -1121,7 +1121,7 @@ trait HasAttributes
* Return a timestamp as DateTime object.
*
* @param mixed $value
* @return \Illuminate\Support\Carbon
* @return \Hyperf\Support\Carbon
*/
protected function asDateTime($value)
{

View File

@ -11,8 +11,8 @@ declare(strict_types=1);
namespace Hyperf\Database\Model\Concerns;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Arr;
use Hyperf\Contracts\Events\Dispatcher;
use Hyperf\Support\Arr;
trait HasEvents
{
@ -231,7 +231,7 @@ trait HasEvents
/**
* Get the event dispatcher instance.
*
* @return \Illuminate\Contracts\Events\Dispatcher
* @return \Hyperf\Contracts\Events\Dispatcher
*/
public static function getEventDispatcher()
{
@ -241,7 +241,7 @@ trait HasEvents
/**
* Set the event dispatcher instance.
*
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
* @param \Hyperf\Contracts\Events\Dispatcher $dispatcher
* @return void
*/
public static function setEventDispatcher(Dispatcher $dispatcher)

View File

@ -25,8 +25,8 @@ use Hyperf\Database\Model\Relations\MorphOne;
use Hyperf\Database\Model\Relations\MorphTo;
use Hyperf\Database\Model\Relations\MorphToMany;
use Hyperf\Database\Model\Relations\Relation;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Hyperf\Support\Arr;
use Hyperf\Support\Str;
trait HasRelationships
{

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Hyperf\Database\Model\Concerns;
use Illuminate\Support\Facades\Date;
use Hyperf\Support\Facades\Date;
trait HasTimestamps
{
@ -67,7 +67,7 @@ trait HasTimestamps
/**
* Get a fresh timestamp for the model.
*
* @return \Illuminate\Support\Carbon
* @return \Hyperf\Support\Carbon
*/
public function freshTimestamp()
{

View File

@ -15,9 +15,9 @@ use Closure;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Relations\MorphTo;
use Hyperf\Database\Model\Relations\Relation;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Str;
use Hyperf\Database\Query\Builder as QueryBuilder;
use Hyperf\Database\Query\Expression;
use Hyperf\Support\Str;
use RuntimeException;
trait QueriesRelationships
@ -298,7 +298,7 @@ trait QueriesRelationships
/**
* Add a sub-query count clause to this query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param string $operator
* @param int $count
* @param string $boolean

View File

@ -256,7 +256,7 @@ class FactoryBuilder
/**
* Run after making callbacks on a collection of models.
*
* @param \Illuminate\Support\Collection $models
* @param \Hyperf\Support\Collection $models
* @return void
*/
public function callAfterMaking($models)
@ -267,7 +267,7 @@ class FactoryBuilder
/**
* Run after creating callbacks on a collection of models.
*
* @param \Illuminate\Support\Collection $models
* @param \Hyperf\Support\Collection $models
* @return void
*/
public function callAfterCreating($models)
@ -278,7 +278,7 @@ class FactoryBuilder
/**
* Set the connection name on the results and store them.
*
* @param \Illuminate\Support\Collection $results
* @param \Hyperf\Support\Collection $results
* @return void
*/
protected function store($results)
@ -418,7 +418,7 @@ class FactoryBuilder
* Call after callbacks for each model and state.
*
* @param array $afterCallbacks
* @param \Illuminate\Support\Collection $models
* @param \Hyperf\Support\Collection $models
* @return void
*/
protected function callAfter(array $afterCallbacks, $models)

View File

@ -21,7 +21,7 @@ use Hyperf\Utils\Collection as BaseCollection;
use Hyperf\Utils\Contracts\Arrayable;
use Hyperf\Utils\Contracts\Jsonable;
use Hyperf\Utils\Str;
use Illuminate\Contracts\Queue\QueueableCollection;
use Hyperf\Contracts\Queue\QueueableCollection;
use JsonSerializable;
abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
@ -121,7 +121,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
/**
* The event dispatcher instance.
*
* @var \Illuminate\Contracts\Events\Dispatcher
* @var \Hyperf\Contracts\Events\Dispatcher
*/
protected static $dispatcher;
@ -449,7 +449,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
/**
* Begin querying the model on the write connection.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
public static function onWriteConnection()
{
@ -638,7 +638,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
/**
* Destroy the models for the given IDs.
*
* @param \Illuminate\Support\Collection|array|int $ids
* @param \Hyperf\Support\Collection|array|int $ids
* @return int
*/
public static function destroy($ids)
@ -815,7 +815,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
/**
* Create a new Model query builder for the model.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return \Hyperf\Database\Model\Builder|static
*/
public function newEloquentBuilder($query)
@ -1564,7 +1564,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
/**
* Get a new query builder instance for the connection.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
protected function newBaseQueryBuilder()
{

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Hyperf\Database\Model;
use Illuminate\Support\Arr;
use Hyperf\Support\Arr;
use RuntimeException;
class ModelNotFoundException extends RuntimeException

View File

@ -1,38 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Database\Model;
use Illuminate\Contracts\Queue\EntityNotFoundException;
use Illuminate\Contracts\Queue\EntityResolver as EntityResolverContract;
class QueueEntityResolver implements EntityResolverContract
{
/**
* Resolve the entity for the given ID.
*
* @param string $type
* @param mixed $id
* @return mixed
*
* @throws \Illuminate\Contracts\Queue\EntityNotFoundException
*/
public function resolve($type, $id)
{
$instance = (new $type)->find($id);
if ($instance) {
return $instance;
}
throw new EntityNotFoundException($type, $id);
}
}

View File

@ -15,7 +15,7 @@ use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Model;
use Hyperf\Database\Model\ModelNotFoundException;
use Illuminate\Support\Str;
use Hyperf\Support\Str;
use InvalidArgumentException;
class BelongsToMany extends Relation
@ -366,7 +366,7 @@ class BelongsToMany extends Relation
*
* @param mixed $id
* @param array $columns
* @return \Illuminate\Support\Collection|\Hyperf\Database\Model\Model
* @return \Hyperf\Support\Collection|\Hyperf\Database\Model\Model
*/
public function findOrNew($id, $columns = ['*'])
{
@ -564,7 +564,7 @@ class BelongsToMany extends Relation
* @param array $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
* @return \Hyperf\Contracts\Pagination\LengthAwarePaginator
*/
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
@ -582,7 +582,7 @@ class BelongsToMany extends Relation
* @param array $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\Paginator
* @return \Hyperf\Contracts\Pagination\Paginator
*/
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
@ -671,7 +671,7 @@ class BelongsToMany extends Relation
/**
* Get all of the IDs for the related models.
*
* @return \Illuminate\Support\Collection
* @return \Hyperf\Support\Collection
*/
public function allRelatedIds()
{
@ -698,7 +698,7 @@ class BelongsToMany extends Relation
/**
* Save an array of new models and attach them to the parent model.
*
* @param \Illuminate\Support\Collection|array $models
* @param \Hyperf\Support\Collection|array $models
* @param array $pivotAttributes
* @return array
*/

View File

@ -13,7 +13,7 @@ namespace Hyperf\Database\Model\Relations\Concerns;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;
use Illuminate\Support\Str;
use Hyperf\Support\Str;
trait AsPivot
{

View File

@ -13,7 +13,7 @@ namespace Hyperf\Database\Model\Relations\Concerns;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Model;
use Illuminate\Support\Collection as BaseCollection;
use Hyperf\Support\Collection as BaseCollection;
trait InteractsWithPivotTable
{
@ -73,7 +73,7 @@ trait InteractsWithPivotTable
/**
* Sync the intermediate tables with a list of IDs without detaching.
*
* @param \Illuminate\Support\Collection|\Hyperf\Database\Model\Model|array $ids
* @param \Hyperf\Support\Collection|\Hyperf\Database\Model\Model|array $ids
* @return array
*/
public function syncWithoutDetaching($ids)
@ -84,7 +84,7 @@ trait InteractsWithPivotTable
/**
* Sync the intermediate tables with a list of IDs or collection of models.
*
* @param \Illuminate\Support\Collection|\Hyperf\Database\Model\Model|array $ids
* @param \Hyperf\Support\Collection|\Hyperf\Database\Model\Model|array $ids
* @param bool $detaching
* @return array
*/
@ -251,7 +251,7 @@ trait InteractsWithPivotTable
/**
* Get a new plain query builder for the pivot table.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
public function newPivotStatement()
{
@ -262,7 +262,7 @@ trait InteractsWithPivotTable
* Get a new pivot statement for a given "other" ID.
*
* @param mixed $id
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
public function newPivotStatementForId($id)
{
@ -468,7 +468,7 @@ trait InteractsWithPivotTable
/**
* Create a new query builder for the pivot table.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
protected function newPivotQuery()
{

View File

@ -350,7 +350,7 @@ class HasManyThrough extends Relation
* @param array $columns
* @param string $pageName
* @param int $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
* @return \Hyperf\Contracts\Pagination\LengthAwarePaginator
*/
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
@ -366,7 +366,7 @@ class HasManyThrough extends Relation
* @param array $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\Paginator
* @return \Hyperf\Contracts\Pagination\Paginator
*/
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{

View File

@ -129,7 +129,7 @@ abstract class HasOneOrMany extends Relation
*
* @param mixed $id
* @param array $columns
* @return \Illuminate\Support\Collection|\Hyperf\Database\Model\Model
* @return \Hyperf\Support\Collection|\Hyperf\Database\Model\Model
*/
public function findOrNew($id, $columns = ['*'])
{

View File

@ -12,7 +12,7 @@ declare(strict_types=1);
namespace Hyperf\Database\Model\Relations;
use Hyperf\Database\Model\Builder;
use Illuminate\Support\Str;
use Hyperf\Support\Str;
class MorphPivot extends Pivot
{

View File

@ -13,7 +13,7 @@ namespace Hyperf\Database\Model\Relations;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;
use Illuminate\Support\Arr;
use Hyperf\Support\Arr;
class MorphToMany extends BelongsToMany
{
@ -196,7 +196,7 @@ class MorphToMany extends BelongsToMany
/**
* Create a new query builder for the pivot table.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
protected function newPivotQuery()
{

View File

@ -15,10 +15,10 @@ use Closure;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Model;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Arr;
use Illuminate\Support\Traits\ForwardsCalls;
use Illuminate\Support\Traits\Macroable;
use Hyperf\Database\Query\Expression;
use Hyperf\Support\Arr;
use Hyperf\Utils\Traits\ForwardsCalls;
use Hyperf\Utils\Traits\Macroable;
/**
* @mixin \Hyperf\Database\Model\Builder
@ -271,7 +271,7 @@ abstract class Relation
/**
* Get the base query builder driving the Model builder.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
public function getBaseQuery()
{

View File

@ -22,10 +22,8 @@ class MySqlConnection extends Connection
{
/**
* Get a schema builder instance for the connection.
*
* @return \Illuminate\Database\Schema\MySqlBuilder
*/
public function getSchemaBuilder()
public function getSchemaBuilder(): MySqlBuilder
{
if (is_null($this->schemaGrammar)) {
$this->useDefaultSchemaGrammar();
@ -36,12 +34,8 @@ class MySqlConnection extends Connection
/**
* Bind values to their parameters in the given statement.
*
* @param \PDOStatement $statement
* @param array $bindings
* @return void
*/
public function bindValues($statement, $bindings)
public function bindValues(\PDOStatement $statement, array $bindings): void
{
foreach ($bindings as $key => $value) {
$statement->bindValue(
@ -55,7 +49,7 @@ class MySqlConnection extends Connection
/**
* Get the default query grammar instance.
*
* @return \Illuminate\Database\Query\Grammars\MySqlGrammar
* @return \Hyperf\Database\Query\Grammars\MySqlGrammar
*/
protected function getDefaultQueryGrammar()
{
@ -65,7 +59,7 @@ class MySqlConnection extends Connection
/**
* Get the default schema grammar instance.
*
* @return \Illuminate\Database\Schema\Grammars\MySqlGrammar
* @return \Hyperf\Database\Schema\Grammars\MySqlGrammar
*/
protected function getDefaultSchemaGrammar()
{
@ -75,7 +69,7 @@ class MySqlConnection extends Connection
/**
* Get the default post processor instance.
*
* @return \Illuminate\Database\Query\Processors\MySqlProcessor
* @return \Hyperf\Database\Query\Processors\MySqlProcessor
*/
protected function getDefaultPostProcessor()
{

View File

@ -43,14 +43,14 @@ class Builder
/**
* The database query grammar instance.
*
* @var \Illuminate\Database\Query\Grammars\Grammar
* @var \Hyperf\Database\Query\Grammars\Grammar
*/
public $grammar;
/**
* The database query post processor instance.
*
* @var \Illuminate\Database\Query\Processors\Processor
* @var \Hyperf\Database\Query\Processors\Processor
*/
public $processor;
@ -205,9 +205,9 @@ class Builder
/**
* Create a new query builder instance.
*
* @param \Illuminate\Database\ConnectionInterface $connection
* @param \Illuminate\Database\Query\Grammars\Grammar $grammar
* @param \Illuminate\Database\Query\Processors\Processor $processor
* @param \Hyperf\Database\ConnectionInterface $connection
* @param \Hyperf\Database\Query\Grammars\Grammar $grammar
* @param \Hyperf\Database\Query\Processors\Processor $processor
* @return void
*/
public function __construct(
@ -258,9 +258,9 @@ class Builder
/**
* Add a subselect expression to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|string $query
* @param \Closure|\Hyperf\Database\Query\Builder|string $query
* @param string $as
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*
* @throws \InvalidArgumentException
*/
@ -279,7 +279,7 @@ class Builder
*
* @param string $expression
* @param array $bindings
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function selectRaw($expression, array $bindings = [])
{
@ -295,9 +295,9 @@ class Builder
/**
* Makes "from" fetch from a subquery.
*
* @param \Closure|\Illuminate\Database\Query\Builder|string $query
* @param \Closure|\Hyperf\Database\Query\Builder|string $query
* @param string $as
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*
* @throws \InvalidArgumentException
*/
@ -313,7 +313,7 @@ class Builder
*
* @param string $expression
* @param mixed $bindings
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function fromRaw($expression, $bindings = [])
{
@ -412,7 +412,7 @@ class Builder
* @param string $operator
* @param string $second
* @param string $type
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function joinWhere($table, $first, $operator, $second, $type = 'inner')
{
@ -422,14 +422,14 @@ class Builder
/**
* Add a subquery join clause to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|string $query
* @param \Closure|\Hyperf\Database\Query\Builder|string $query
* @param string $as
* @param \Closure|string $first
* @param string|null $operator
* @param string|null $second
* @param string $type
* @param bool $where
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*
* @throws \InvalidArgumentException
*/
@ -451,7 +451,7 @@ class Builder
* @param \Closure|string $first
* @param string|null $operator
* @param string|null $second
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function leftJoin($table, $first, $operator = null, $second = null)
{
@ -465,7 +465,7 @@ class Builder
* @param string $first
* @param string $operator
* @param string $second
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function leftJoinWhere($table, $first, $operator, $second)
{
@ -475,12 +475,12 @@ class Builder
/**
* Add a subquery left join to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|string $query
* @param \Closure|\Hyperf\Database\Query\Builder|string $query
* @param string $as
* @param string $first
* @param string|null $operator
* @param string|null $second
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function leftJoinSub($query, $as, $first, $operator = null, $second = null)
{
@ -494,7 +494,7 @@ class Builder
* @param \Closure|string $first
* @param string|null $operator
* @param string|null $second
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function rightJoin($table, $first, $operator = null, $second = null)
{
@ -508,7 +508,7 @@ class Builder
* @param string $first
* @param string $operator
* @param string $second
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function rightJoinWhere($table, $first, $operator, $second)
{
@ -518,12 +518,12 @@ class Builder
/**
* Add a subquery right join to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|string $query
* @param \Closure|\Hyperf\Database\Query\Builder|string $query
* @param string $as
* @param string $first
* @param string|null $operator
* @param string|null $second
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function rightJoinSub($query, $as, $first, $operator = null, $second = null)
{
@ -537,7 +537,7 @@ class Builder
* @param \Closure|string|null $first
* @param string|null $operator
* @param string|null $second
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function crossJoin($table, $first = null, $operator = null, $second = null)
{
@ -675,7 +675,7 @@ class Builder
* @param string|array|\Closure $column
* @param mixed $operator
* @param mixed $value
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhere($column, $operator = null, $value = null)
{
@ -695,7 +695,7 @@ class Builder
* @param string|null $operator
* @param string|null $second
* @param string|null $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereColumn($first, $operator = null, $second = null, $boolean = 'and')
{
@ -735,7 +735,7 @@ class Builder
* @param string|array $first
* @param string|null $operator
* @param string|null $second
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereColumn($first, $operator = null, $second = null)
{
@ -764,7 +764,7 @@ class Builder
*
* @param string $sql
* @param mixed $bindings
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereRaw($sql, $bindings = [])
{
@ -819,7 +819,7 @@ class Builder
*
* @param string $column
* @param mixed $values
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereIn($column, $values)
{
@ -832,7 +832,7 @@ class Builder
* @param string $column
* @param mixed $values
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereNotIn($column, $values, $boolean = 'and')
{
@ -844,7 +844,7 @@ class Builder
*
* @param string $column
* @param mixed $values
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereNotIn($column, $values)
{
@ -855,7 +855,7 @@ class Builder
* Add a "where in raw" clause for integer values to the query.
*
* @param string $column
* @param \Illuminate\Contracts\Support\Arrayable|array $values
* @param \Hyperf\Contracts\Support\Arrayable|array $values
* @param string $boolean
* @param bool $not
* @return $this
@ -881,7 +881,7 @@ class Builder
* Add a "where not in raw" clause for integer values to the query.
*
* @param string $column
* @param \Illuminate\Contracts\Support\Arrayable|array $values
* @param \Hyperf\Contracts\Support\Arrayable|array $values
* @param string $boolean
* @return $this
*/
@ -911,7 +911,7 @@ class Builder
* Add an "or where null" clause to the query.
*
* @param string $column
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereNull($column)
{
@ -923,7 +923,7 @@ class Builder
*
* @param string $column
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereNotNull($column, $boolean = 'and')
{
@ -955,7 +955,7 @@ class Builder
*
* @param string $column
* @param array $values
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereBetween($column, array $values)
{
@ -968,7 +968,7 @@ class Builder
* @param string $column
* @param array $values
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereNotBetween($column, array $values, $boolean = 'and')
{
@ -980,7 +980,7 @@ class Builder
*
* @param string $column
* @param array $values
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereNotBetween($column, array $values)
{
@ -991,7 +991,7 @@ class Builder
* Add an "or where not null" clause to the query.
*
* @param string $column
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereNotNull($column)
{
@ -1005,7 +1005,7 @@ class Builder
* @param string $operator
* @param \DateTimeInterface|string $value
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereDate($column, $operator, $value = null, $boolean = 'and')
{
@ -1028,7 +1028,7 @@ class Builder
* @param string $column
* @param string $operator
* @param \DateTimeInterface|string $value
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereDate($column, $operator, $value = null)
{
@ -1048,7 +1048,7 @@ class Builder
* @param string $operator
* @param \DateTimeInterface|string $value
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereTime($column, $operator, $value = null, $boolean = 'and')
{
@ -1071,7 +1071,7 @@ class Builder
* @param string $column
* @param string $operator
* @param \DateTimeInterface|string $value
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereTime($column, $operator, $value = null)
{
@ -1091,7 +1091,7 @@ class Builder
* @param string $operator
* @param \DateTimeInterface|string $value
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereDay($column, $operator, $value = null, $boolean = 'and')
{
@ -1114,7 +1114,7 @@ class Builder
* @param string $column
* @param string $operator
* @param \DateTimeInterface|string $value
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereDay($column, $operator, $value = null)
{
@ -1134,7 +1134,7 @@ class Builder
* @param string $operator
* @param \DateTimeInterface|string $value
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereMonth($column, $operator, $value = null, $boolean = 'and')
{
@ -1157,7 +1157,7 @@ class Builder
* @param string $column
* @param string $operator
* @param \DateTimeInterface|string $value
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereMonth($column, $operator, $value = null)
{
@ -1177,7 +1177,7 @@ class Builder
* @param string $operator
* @param \DateTimeInterface|string|int $value
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereYear($column, $operator, $value = null, $boolean = 'and')
{
@ -1200,7 +1200,7 @@ class Builder
* @param string $column
* @param string $operator
* @param \DateTimeInterface|string|int $value
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereYear($column, $operator, $value = null)
{
@ -1218,7 +1218,7 @@ class Builder
*
* @param \Closure $callback
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereNested(Closure $callback, $boolean = 'and')
{
@ -1230,7 +1230,7 @@ class Builder
/**
* Create a new query instance for nested where condition.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
public function forNestedWhere()
{
@ -1240,7 +1240,7 @@ class Builder
/**
* Add another query builder as a nested where to the query builder.
*
* @param \Illuminate\Database\Query\Builder|static $query
* @param \Hyperf\Database\Query\Builder|static $query
* @param string $boolean
* @return $this
*/
@ -1282,7 +1282,7 @@ class Builder
*
* @param \Closure $callback
* @param bool $not
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereExists(Closure $callback, $not = false)
{
@ -1294,7 +1294,7 @@ class Builder
*
* @param \Closure $callback
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function whereNotExists(Closure $callback, $boolean = 'and')
{
@ -1305,7 +1305,7 @@ class Builder
* Add a where not exists clause to the query.
*
* @param \Closure $callback
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orWhereNotExists(Closure $callback)
{
@ -1315,7 +1315,7 @@ class Builder
/**
* Add an exists clause to the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param string $boolean
* @param bool $not
* @return $this
@ -1582,7 +1582,7 @@ class Builder
* @param string $column
* @param string|null $operator
* @param string|null $value
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orHaving($column, $operator = null, $value = null)
{
@ -1602,7 +1602,7 @@ class Builder
* @param array $values
* @param string $boolean
* @param bool $not
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function havingBetween($column, array $values, $boolean = 'and', $not = false)
{
@ -1639,7 +1639,7 @@ class Builder
*
* @param string $sql
* @param array $bindings
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function orHavingRaw($sql, array $bindings = [])
{
@ -1678,7 +1678,7 @@ class Builder
* Add an "order by" clause for a timestamp to the query.
*
* @param string $column
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function latest($column = 'created_at')
{
@ -1689,7 +1689,7 @@ class Builder
* Add an "order by" clause for a timestamp to the query.
*
* @param string $column
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function oldest($column = 'created_at')
{
@ -1729,7 +1729,7 @@ class Builder
* Alias to set the "offset" value of the query.
*
* @param int $value
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function skip($value)
{
@ -1755,7 +1755,7 @@ class Builder
* Alias to set the "limit" value of the query.
*
* @param int $value
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function take($value)
{
@ -1784,7 +1784,7 @@ class Builder
*
* @param int $page
* @param int $perPage
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function forPage($page, $perPage = 15)
{
@ -1797,7 +1797,7 @@ class Builder
* @param int $perPage
* @param int|null $lastId
* @param string $column
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')
{
@ -1814,9 +1814,9 @@ class Builder
/**
* Add a union statement to the query.
*
* @param \Illuminate\Database\Query\Builder|\Closure $query
* @param \Hyperf\Database\Query\Builder|\Closure $query
* @param bool $all
* @return \Illuminate\Database\Query\Builder|static
* @return \Hyperf\Database\Query\Builder|static
*/
public function union($query, $all = false)
{
@ -1834,8 +1834,8 @@ class Builder
/**
* Add a union all statement to the query.
*
* @param \Illuminate\Database\Query\Builder|\Closure $query
* @return \Illuminate\Database\Query\Builder|static
* @param \Hyperf\Database\Query\Builder|\Closure $query
* @return \Hyperf\Database\Query\Builder|static
*/
public function unionAll($query)
{
@ -1862,7 +1862,7 @@ class Builder
/**
* Lock the selected rows in the table for updating.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
public function lockForUpdate()
{
@ -1872,7 +1872,7 @@ class Builder
/**
* Share lock the selected rows in the table.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
public function sharedLock()
{
@ -1918,7 +1918,7 @@ class Builder
* Execute the query as a "select" statement.
*
* @param array|string $columns
* @return \Illuminate\Support\Collection
* @return \Hyperf\Support\Collection
*/
public function get($columns = ['*'])
{
@ -1934,7 +1934,7 @@ class Builder
* @param array $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
* @return \Hyperf\Contracts\Pagination\LengthAwarePaginator
*/
public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
{
@ -1959,7 +1959,7 @@ class Builder
* @param array $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\Paginator
* @return \Hyperf\Contracts\Pagination\Paginator
*/
public function simplePaginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
{
@ -2064,7 +2064,7 @@ class Builder
*
* @param string $column
* @param string|null $key
* @return \Illuminate\Support\Collection
* @return \Hyperf\Support\Collection
*/
public function pluck($column, $key = null)
{
@ -2319,7 +2319,7 @@ class Builder
* Insert new records into the table using a subquery.
*
* @param array $columns
* @param \Closure|\Illuminate\Database\Query\Builder|string $query
* @param \Closure|\Hyperf\Database\Query\Builder|string $query
* @return bool
*/
public function insertUsing(array $columns, $query)
@ -2443,7 +2443,7 @@ class Builder
/**
* Get a new instance of the query builder.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
public function newQuery()
{
@ -2454,7 +2454,7 @@ class Builder
* Create a raw database expression.
*
* @param mixed $value
* @return \Illuminate\Database\Query\Expression
* @return \Hyperf\Database\Query\Expression
*/
public function raw($value)
{
@ -2528,7 +2528,7 @@ class Builder
/**
* Merge an array of bindings into our bindings.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return $this
*/
public function mergeBindings(self $query)
@ -2541,7 +2541,7 @@ class Builder
/**
* Get the database connection instance.
*
* @return \Illuminate\Database\ConnectionInterface
* @return \Hyperf\Database\ConnectionInterface
*/
public function getConnection()
{
@ -2551,7 +2551,7 @@ class Builder
/**
* Get the database query processor instance.
*
* @return \Illuminate\Database\Query\Processors\Processor
* @return \Hyperf\Database\Query\Processors\Processor
*/
public function getProcessor()
{
@ -2561,7 +2561,7 @@ class Builder
/**
* Get the query grammar instance.
*
* @return \Illuminate\Database\Query\Grammars\Grammar
* @return \Hyperf\Database\Query\Grammars\Grammar
*/
public function getGrammar()
{
@ -2613,7 +2613,7 @@ class Builder
/**
* Creates a subquery and parse it.
*
* @param \Closure|\Illuminate\Database\Query\Builder|string $query
* @param \Closure|\Hyperf\Database\Query\Builder|string $query
* @return array
*/
protected function createSub($query)
@ -2723,7 +2723,7 @@ class Builder
* Add an external sub-select to the query.
*
* @param string $column
* @param \Illuminate\Database\Query\Builder|static $query
* @param \Hyperf\Database\Query\Builder|static $query
* @param string $boolean
* @param bool $not
* @return $this
@ -2900,7 +2900,7 @@ class Builder
* @param array $queryResult
* @param string $column
* @param string $key
* @return \Illuminate\Support\Collection
* @return \Hyperf\Support\Collection
*/
protected function pluckFromObjectColumn($queryResult, $column, $key)
{
@ -2925,7 +2925,7 @@ class Builder
* @param array $queryResult
* @param string $column
* @param string $key
* @return \Illuminate\Support\Collection
* @return \Hyperf\Support\Collection
*/
protected function pluckFromArrayColumn($queryResult, $column, $key)
{
@ -2991,7 +2991,7 @@ class Builder
/**
* Create a new query instance for a sub-query.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
protected function forSubQuery()
{

View File

@ -50,7 +50,7 @@ class Grammar extends BaseGrammar
/**
* Compile a select query into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return string
*/
public function compileSelect(Builder $query)
@ -107,7 +107,7 @@ class Grammar extends BaseGrammar
/**
* Compile an exists statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return string
*/
public function compileExists(Builder $query)
@ -120,7 +120,7 @@ class Grammar extends BaseGrammar
/**
* Compile an insert statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $values
* @return string
*/
@ -150,7 +150,7 @@ class Grammar extends BaseGrammar
/**
* Compile an insert and get ID statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $values
* @param string $sequence
* @return string
@ -163,7 +163,7 @@ class Grammar extends BaseGrammar
/**
* Compile an insert statement using a subquery into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $columns
* @param string $sql
* @return string
@ -176,7 +176,7 @@ class Grammar extends BaseGrammar
/**
* Compile an update statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $values
* @return string
*/
@ -227,7 +227,7 @@ class Grammar extends BaseGrammar
/**
* Compile a delete statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return string
*/
public function compileDelete(Builder $query)
@ -251,7 +251,7 @@ class Grammar extends BaseGrammar
/**
* Compile a truncate table statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return array
*/
public function compileTruncate(Builder $query)
@ -294,7 +294,7 @@ class Grammar extends BaseGrammar
/**
* Wrap a value in keyword identifiers.
*
* @param \Illuminate\Database\Query\Expression|string $value
* @param \Hyperf\Database\Query\Expression|string $value
* @param bool $prefixAlias
* @return string
*/
@ -334,7 +334,7 @@ class Grammar extends BaseGrammar
/**
* Compile the components necessary for a select clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return array
*/
protected function compileComponents(Builder $query)
@ -358,7 +358,7 @@ class Grammar extends BaseGrammar
/**
* Compile an aggregated select clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $aggregate
* @return string
*/
@ -379,7 +379,7 @@ class Grammar extends BaseGrammar
/**
* Compile the "select *" portion of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $columns
* @return string|null
*/
@ -400,7 +400,7 @@ class Grammar extends BaseGrammar
/**
* Compile the "from" portion of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param string $table
* @return string
*/
@ -412,7 +412,7 @@ class Grammar extends BaseGrammar
/**
* Compile the "join" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $joins
* @return string
*/
@ -432,7 +432,7 @@ class Grammar extends BaseGrammar
/**
* Compile the "where" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return string
*/
protected function compileWheres(Builder $query)
@ -457,7 +457,7 @@ class Grammar extends BaseGrammar
/**
* Get an array of all the where clauses for the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return array
*/
protected function compileWheresToArray($query)
@ -470,7 +470,7 @@ class Grammar extends BaseGrammar
/**
* Format the where clause statements into one string.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $sql
* @return string
*/
@ -484,7 +484,7 @@ class Grammar extends BaseGrammar
/**
* Compile a raw where clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -496,7 +496,7 @@ class Grammar extends BaseGrammar
/**
* Compile a basic where clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -510,7 +510,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where in" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -526,7 +526,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where not in" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -544,7 +544,7 @@ class Grammar extends BaseGrammar
*
* For safety, whereIntegerInRaw ensures this method is only used with integer values.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -560,7 +560,7 @@ class Grammar extends BaseGrammar
/**
* Compile a where in sub-select clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -572,7 +572,7 @@ class Grammar extends BaseGrammar
/**
* Compile a where not in sub-select clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -586,7 +586,7 @@ class Grammar extends BaseGrammar
*
* For safety, whereIntegerInRaw ensures this method is only used with integer values.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -602,7 +602,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where null" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -614,7 +614,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where not null" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -626,7 +626,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "between" where clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -644,7 +644,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where date" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -656,7 +656,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where time" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -668,7 +668,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where day" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -680,7 +680,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where month" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -692,7 +692,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where year" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -705,7 +705,7 @@ class Grammar extends BaseGrammar
* Compile a date based where clause.
*
* @param string $type
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -719,7 +719,7 @@ class Grammar extends BaseGrammar
/**
* Compile a where clause comparing two columns..
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -731,7 +731,7 @@ class Grammar extends BaseGrammar
/**
* Compile a nested where clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -748,7 +748,7 @@ class Grammar extends BaseGrammar
/**
* Compile a where condition with a sub-select.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -762,7 +762,7 @@ class Grammar extends BaseGrammar
/**
* Compile a where exists clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -774,7 +774,7 @@ class Grammar extends BaseGrammar
/**
* Compile a where exists clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -786,7 +786,7 @@ class Grammar extends BaseGrammar
/**
* Compile a where row values condition.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -802,7 +802,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where JSON contains" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -833,7 +833,7 @@ class Grammar extends BaseGrammar
/**
* Compile a "where JSON length" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $where
* @return string
*/
@ -864,7 +864,7 @@ class Grammar extends BaseGrammar
/**
* Compile the "group by" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $groups
* @return string
*/
@ -876,7 +876,7 @@ class Grammar extends BaseGrammar
/**
* Compile the "having" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $havings
* @return string
*/
@ -944,7 +944,7 @@ class Grammar extends BaseGrammar
/**
* Compile the "order by" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $orders
* @return string
*/
@ -960,7 +960,7 @@ class Grammar extends BaseGrammar
/**
* Compile the query orders to an array.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $orders
* @return array
*/
@ -976,7 +976,7 @@ class Grammar extends BaseGrammar
/**
* Compile the "limit" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param int $limit
* @return string
*/
@ -988,7 +988,7 @@ class Grammar extends BaseGrammar
/**
* Compile the "offset" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param int $offset
* @return string
*/
@ -1000,7 +1000,7 @@ class Grammar extends BaseGrammar
/**
* Compile the "union" queries attached to the main query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return string
*/
protected function compileUnions(Builder $query)
@ -1042,7 +1042,7 @@ class Grammar extends BaseGrammar
/**
* Compile a union aggregate query into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return string
*/
protected function compileUnionAggregate(Builder $query)
@ -1057,7 +1057,7 @@ class Grammar extends BaseGrammar
/**
* Compile the lock into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param bool|string $value
* @return string
*/

View File

@ -78,7 +78,7 @@ class MySqlGrammar extends Grammar
/**
* Compile an update statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param array $values
* @return string
*/
@ -145,7 +145,7 @@ class MySqlGrammar extends Grammar
/**
* Compile a delete statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @return string
*/
public function compileDelete(Builder $query)
@ -219,7 +219,7 @@ class MySqlGrammar extends Grammar
/**
* Compile the lock into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param bool|string $value
* @return string
*/
@ -253,7 +253,7 @@ class MySqlGrammar extends Grammar
* Prepares a JSON column being updated using the JSON_SET function.
*
* @param string $key
* @param \Illuminate\Database\Query\JsonExpression $value
* @param \Hyperf\Database\Query\JsonExpression $value
* @return string
*/
protected function compileJsonUpdateColumn($key, JsonExpression $value)
@ -266,7 +266,7 @@ class MySqlGrammar extends Grammar
/**
* Compile a delete query that does not use joins.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param string $table
* @param array $where
* @return string
@ -292,7 +292,7 @@ class MySqlGrammar extends Grammar
/**
* Compile a delete query that uses joins.
*
* @param \Illuminate\Database\Query\Builder $query
* @param \Hyperf\Database\Query\Builder $query
* @param string $table
* @param array $where
* @return string

View File

@ -1,413 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Query\Grammars;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
class PostgresGrammar extends Grammar
{
/**
* All of the available clause operators.
*
* @var array
*/
protected $operators = [
'=', '<', '>', '<=', '>=', '<>', '!=',
'like', 'not like', 'between', 'ilike', 'not ilike',
'~', '&', '|', '#', '<<', '>>', '<<=', '>>=',
'&&', '@>', '<@', '?', '?|', '?&', '||', '-', '-', '#-',
'is distinct from', 'is not distinct from',
];
/**
* {@inheritdoc}
*/
public function compileInsert(Builder $query, array $values)
{
$table = $this->wrapTable($query->from);
return empty($values)
? "insert into {$table} DEFAULT VALUES"
: parent::compileInsert($query, $values);
}
/**
* Compile an insert and get ID statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @param string $sequence
* @return string
*/
public function compileInsertGetId(Builder $query, $values, $sequence)
{
if (is_null($sequence)) {
$sequence = 'id';
}
return $this->compileInsert($query, $values).' returning '.$this->wrap($sequence);
}
/**
* Compile an update statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @return string
*/
public function compileUpdate(Builder $query, $values)
{
$table = $this->wrapTable($query->from);
// Each one of the columns in the update statements needs to be wrapped in the
// keyword identifiers, also a place-holder needs to be created for each of
// the values in the list of bindings so we can make the sets statements.
$columns = $this->compileUpdateColumns($query, $values);
$from = $this->compileUpdateFrom($query);
$where = $this->compileUpdateWheres($query);
return trim("update {$table} set {$columns}{$from} {$where}");
}
/**
* Prepare the bindings for an update statement.
*
* @param array $bindings
* @param array $values
* @return array
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
$values = collect($values)->map(function ($value, $column) {
return $this->isJsonSelector($column) && ! $this->isExpression($value)
? json_encode($value)
: $value;
})->all();
// Update statements with "joins" in Postgres use an interesting syntax. We need to
// take all of the bindings and put them on the end of this array since they are
// added to the end of the "where" clause statements as typical where clauses.
$bindingsWithoutJoin = Arr::except($bindings, 'join');
return array_values(
array_merge($values, $bindings['join'], Arr::flatten($bindingsWithoutJoin))
);
}
/**
* Compile a delete statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
public function compileDelete(Builder $query)
{
$table = $this->wrapTable($query->from);
return isset($query->joins)
? $this->compileDeleteWithJoins($query, $table)
: parent::compileDelete($query);
}
/**
* Compile a truncate table statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return array
*/
public function compileTruncate(Builder $query)
{
return ['truncate '.$this->wrapTable($query->from).' restart identity cascade' => []];
}
/**
* {@inheritdoc}
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereBasic(Builder $query, $where)
{
if (Str::contains(strtolower($where['operator']), 'like')) {
return sprintf(
'%s::text %s %s',
$this->wrap($where['column']),
$where['operator'],
$this->parameter($where['value'])
);
}
return parent::whereBasic($query, $where);
}
/**
* Compile a "where date" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereDate(Builder $query, $where)
{
$value = $this->parameter($where['value']);
return $this->wrap($where['column']).'::date '.$where['operator'].' '.$value;
}
/**
* Compile a "where time" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereTime(Builder $query, $where)
{
$value = $this->parameter($where['value']);
return $this->wrap($where['column']).'::time '.$where['operator'].' '.$value;
}
/**
* Compile a date based where clause.
*
* @param string $type
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function dateBasedWhere($type, Builder $query, $where)
{
$value = $this->parameter($where['value']);
return 'extract('.$type.' from '.$this->wrap($where['column']).') '.$where['operator'].' '.$value;
}
/**
* Compile a "JSON contains" statement into SQL.
*
* @param string $column
* @param string $value
* @return string
*/
protected function compileJsonContains($column, $value)
{
$column = str_replace('->>', '->', $this->wrap($column));
return '('.$column.')::jsonb @> '.$value;
}
/**
* Compile a "JSON length" statement into SQL.
*
* @param string $column
* @param string $operator
* @param string $value
* @return string
*/
protected function compileJsonLength($column, $operator, $value)
{
$column = str_replace('->>', '->', $this->wrap($column));
return 'json_array_length(('.$column.')::json) '.$operator.' '.$value;
}
/**
* Compile the lock into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param bool|string $value
* @return string
*/
protected function compileLock(Builder $query, $value)
{
if (! is_string($value)) {
return $value ? 'for update' : 'for share';
}
return $value;
}
/**
* Compile the columns for the update statement.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @return string
*/
protected function compileUpdateColumns($query, $values)
{
// When gathering the columns for an update statement, we'll wrap each of the
// columns and convert it to a parameter value. Then we will concatenate a
// list of the columns that can be added into this update query clauses.
return collect($values)->map(function ($value, $key) use ($query) {
$column = Str::after($key, $query->from.'.');
if ($this->isJsonSelector($key)) {
return $this->compileJsonUpdateColumn($column, $value);
}
return $this->wrap($column).' = '.$this->parameter($value);
})->implode(', ');
}
/**
* Prepares a JSON column being updated using the JSONB_SET function.
*
* @param string $key
* @param mixed $value
* @return string
*/
protected function compileJsonUpdateColumn($key, $value)
{
$parts = explode('->', $key);
$field = $this->wrap(array_shift($parts));
$path = '\'{"'.implode('","', $parts).'"}\'';
return "{$field} = jsonb_set({$field}::jsonb, {$path}, {$this->parameter($value)})";
}
/**
* Compile the "from" clause for an update with a join.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string|null
*/
protected function compileUpdateFrom(Builder $query)
{
if (! isset($query->joins)) {
return '';
}
// When using Postgres, updates with joins list the joined tables in the from
// clause, which is different than other systems like MySQL. Here, we will
// compile out the tables that are joined and add them to a from clause.
$froms = collect($query->joins)->map(function ($join) {
return $this->wrapTable($join->table);
})->all();
if (count($froms) > 0) {
return ' from '.implode(', ', $froms);
}
}
/**
* Compile the additional where clauses for updates with joins.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
protected function compileUpdateWheres(Builder $query)
{
$baseWheres = $this->compileWheres($query);
if (! isset($query->joins)) {
return $baseWheres;
}
// Once we compile the join constraints, we will either use them as the where
// clause or append them to the existing base where clauses. If we need to
// strip the leading boolean we will do so when using as the only where.
$joinWheres = $this->compileUpdateJoinWheres($query);
if (trim($baseWheres) == '') {
return 'where '.$this->removeLeadingBoolean($joinWheres);
}
return $baseWheres.' '.$joinWheres;
}
/**
* Compile the "join" clause where clauses for an update.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
protected function compileUpdateJoinWheres(Builder $query)
{
$joinWheres = [];
// Here we will just loop through all of the join constraints and compile them
// all out then implode them. This should give us "where" like syntax after
// everything has been built and then we will join it to the real wheres.
foreach ($query->joins as $join) {
foreach ($join->wheres as $where) {
$method = "where{$where['type']}";
$joinWheres[] = $where['boolean'].' '.$this->$method($query, $where);
}
}
return implode(' ', $joinWheres);
}
/**
* Compile a delete query that uses joins.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $table
* @return string
*/
protected function compileDeleteWithJoins($query, $table)
{
$using = ' USING '.collect($query->joins)->map(function ($join) {
return $this->wrapTable($join->table);
})->implode(', ');
$where = count($query->wheres) > 0 ? ' '.$this->compileUpdateWheres($query) : '';
return trim("delete from {$table}{$using}{$where}");
}
/**
* Wrap the given JSON selector.
*
* @param string $value
* @return string
*/
protected function wrapJsonSelector($value)
{
$path = explode('->', $value);
$field = $this->wrapSegments(explode('.', array_shift($path)));
$wrappedPath = $this->wrapJsonPathAttributes($path);
$attribute = array_pop($wrappedPath);
if (! empty($wrappedPath)) {
return $field.'->'.implode('->', $wrappedPath).'->>'.$attribute;
}
return $field.'->>'.$attribute;
}
/**
* Wrap the attributes of the give JSON path.
*
* @param array $path
* @return array
*/
protected function wrapJsonPathAttributes($path)
{
return array_map(function ($attribute) {
return "'$attribute'";
}, $path);
}
}

View File

@ -1,290 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Query\Grammars;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
class SQLiteGrammar extends Grammar
{
/**
* The components that make up a select clause.
*
* @var array
*/
protected $selectComponents = [
'aggregate',
'columns',
'from',
'joins',
'wheres',
'groups',
'havings',
'orders',
'limit',
'offset',
'lock',
];
/**
* All of the available clause operators.
*
* @var array
*/
protected $operators = [
'=', '<', '>', '<=', '>=', '<>', '!=',
'like', 'not like', 'ilike',
'&', '|', '<<', '>>',
];
/**
* Compile a select query into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
public function compileSelect(Builder $query)
{
if ($query->unions && $query->aggregate) {
return $this->compileUnionAggregate($query);
}
$sql = parent::compileSelect($query);
if ($query->unions) {
$sql = 'select * from ('.$sql.') '.$this->compileUnions($query);
}
return $sql;
}
/**
* Compile an insert statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @return string
*/
public function compileInsert(Builder $query, array $values)
{
$table = $this->wrapTable($query->from);
return empty($values)
? "insert into {$table} DEFAULT VALUES"
: parent::compileInsert($query, $values);
}
/**
* Compile an update statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @return string
*/
public function compileUpdate(Builder $query, $values)
{
$table = $this->wrapTable($query->from);
$columns = collect($values)->map(function ($value, $key) use ($query) {
return $this->wrap(Str::after($key, $query->from.'.')).' = '.$this->parameter($value);
})->implode(', ');
if (isset($query->joins) || isset($query->limit)) {
$selectSql = parent::compileSelect($query->select("{$query->from}.rowid"));
return "update {$table} set $columns where {$this->wrap('rowid')} in ({$selectSql})";
}
return trim("update {$table} set {$columns} {$this->compileWheres($query)}");
}
/**
* Prepare the bindings for an update statement.
*
* @param array $bindings
* @param array $values
* @return array
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
$cleanBindings = Arr::except($bindings, ['select', 'join']);
return array_values(
array_merge($values, $bindings['join'], Arr::flatten($cleanBindings))
);
}
/**
* Compile a delete statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
public function compileDelete(Builder $query)
{
if (isset($query->joins) || isset($query->limit)) {
$selectSql = parent::compileSelect($query->select("{$query->from}.rowid"));
return "delete from {$this->wrapTable($query->from)} where {$this->wrap('rowid')} in ({$selectSql})";
}
$wheres = is_array($query->wheres) ? $this->compileWheres($query) : '';
return trim("delete from {$this->wrapTable($query->from)} $wheres");
}
/**
* Prepare the bindings for a delete statement.
*
* @param array $bindings
* @return array
*/
public function prepareBindingsForDelete(array $bindings)
{
$cleanBindings = Arr::except($bindings, ['select', 'join']);
return array_values(
array_merge($bindings['join'], Arr::flatten($cleanBindings))
);
}
/**
* Compile a truncate table statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return array
*/
public function compileTruncate(Builder $query)
{
return [
'delete from sqlite_sequence where name = ?' => [$query->from],
'delete from '.$this->wrapTable($query->from) => [],
];
}
/**
* Compile a single union statement.
*
* @param array $union
* @return string
*/
protected function compileUnion(array $union)
{
$conjunction = $union['all'] ? ' union all ' : ' union ';
return $conjunction.'select * from ('.$union['query']->toSql().')';
}
/**
* Compile a "where date" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereDate(Builder $query, $where)
{
return $this->dateBasedWhere('%Y-%m-%d', $query, $where);
}
/**
* Compile a "where day" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereDay(Builder $query, $where)
{
return $this->dateBasedWhere('%d', $query, $where);
}
/**
* Compile a "where month" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereMonth(Builder $query, $where)
{
return $this->dateBasedWhere('%m', $query, $where);
}
/**
* Compile a "where year" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereYear(Builder $query, $where)
{
return $this->dateBasedWhere('%Y', $query, $where);
}
/**
* Compile a "where time" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereTime(Builder $query, $where)
{
return $this->dateBasedWhere('%H:%M:%S', $query, $where);
}
/**
* Compile a date based where clause.
*
* @param string $type
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function dateBasedWhere($type, Builder $query, $where)
{
$value = $this->parameter($where['value']);
return "strftime('{$type}', {$this->wrap($where['column'])}) {$where['operator']} cast({$value} as text)";
}
/**
* Compile a "JSON length" statement into SQL.
*
* @param string $column
* @param string $operator
* @param string $value
* @return string
*/
protected function compileJsonLength($column, $operator, $value)
{
[$field, $path] = $this->wrapJsonFieldAndPath($column);
return 'json_array_length('.$field.$path.') '.$operator.' '.$value;
}
/**
* Wrap the given JSON selector.
*
* @param string $value
* @return string
*/
protected function wrapJsonSelector($value)
{
[$field, $path] = $this->wrapJsonFieldAndPath($value);
return 'json_extract('.$field.$path.')';
}
}

View File

@ -1,523 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Query\Grammars;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Arr;
class SqlServerGrammar extends Grammar
{
/**
* All of the available clause operators.
*
* @var array
*/
protected $operators = [
'=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=',
'like', 'not like', 'ilike',
'&', '&=', '|', '|=', '^', '^=',
];
/**
* Compile a select query into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
public function compileSelect(Builder $query)
{
if (! $query->offset) {
return parent::compileSelect($query);
}
// If an offset is present on the query, we will need to wrap the query in
// a big "ANSI" offset syntax block. This is very nasty compared to the
// other database systems but is necessary for implementing features.
if (is_null($query->columns)) {
$query->columns = ['*'];
}
return $this->compileAnsiOffset(
$query,
$this->compileComponents($query)
);
}
/**
* Prepare the binding for a "JSON contains" statement.
*
* @param mixed $binding
* @return string
*/
public function prepareBindingForJsonContains($binding)
{
return is_bool($binding) ? json_encode($binding) : $binding;
}
/**
* Compile the random statement into SQL.
*
* @param string $seed
* @return string
*/
public function compileRandom($seed)
{
return 'NEWID()';
}
/**
* Compile an exists statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
public function compileExists(Builder $query)
{
$existsQuery = clone $query;
$existsQuery->columns = [];
return $this->compileSelect($existsQuery->selectRaw('1 [exists]')->limit(1));
}
/**
* Compile a delete statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
public function compileDelete(Builder $query)
{
$table = $this->wrapTable($query->from);
$where = is_array($query->wheres) ? $this->compileWheres($query) : '';
return isset($query->joins)
? $this->compileDeleteWithJoins($query, $table, $where)
: trim("delete from {$table} {$where}");
}
/**
* Compile a truncate table statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return array
*/
public function compileTruncate(Builder $query)
{
return ['truncate table '.$this->wrapTable($query->from) => []];
}
/**
* Compile an update statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @return string
*/
public function compileUpdate(Builder $query, $values)
{
[$table, $alias] = $this->parseUpdateTable($query->from);
// Each one of the columns in the update statements needs to be wrapped in the
// keyword identifiers, also a place-holder needs to be created for each of
// the values in the list of bindings so we can make the sets statements.
$columns = collect($values)->map(function ($value, $key) {
return $this->wrap($key).' = '.$this->parameter($value);
})->implode(', ');
// If the query has any "join" clauses, we will setup the joins on the builder
// and compile them so we can attach them to this update, as update queries
// can get join statements to attach to other tables when they're needed.
$joins = '';
if (isset($query->joins)) {
$joins = ' '.$this->compileJoins($query, $query->joins);
}
// Of course, update queries may also be constrained by where clauses so we'll
// need to compile the where clauses and attach it to the query so only the
// intended records are updated by the SQL statements we generate to run.
$where = $this->compileWheres($query);
if (! empty($joins)) {
return trim("update {$alias} set {$columns} from {$table}{$joins} {$where}");
}
return trim("update {$table}{$joins} set $columns $where");
}
/**
* Prepare the bindings for an update statement.
*
* @param array $bindings
* @param array $values
* @return array
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
// Update statements with joins in SQL Servers utilize an unique syntax. We need to
// take all of the bindings and put them on the end of this array since they are
// added to the end of the "where" clause statements as typical where clauses.
$bindingsWithoutJoin = Arr::except($bindings, 'join');
return array_values(
array_merge($values, $bindings['join'], Arr::flatten($bindingsWithoutJoin))
);
}
/**
* Determine if the grammar supports savepoints.
*
* @return bool
*/
public function supportsSavepoints()
{
return true;
}
/**
* Compile the SQL statement to define a savepoint.
*
* @param string $name
* @return string
*/
public function compileSavepoint($name)
{
return 'SAVE TRANSACTION '.$name;
}
/**
* Compile the SQL statement to execute a savepoint rollback.
*
* @param string $name
* @return string
*/
public function compileSavepointRollBack($name)
{
return 'ROLLBACK TRANSACTION '.$name;
}
/**
* Get the format for database stored dates.
*
* @return string
*/
public function getDateFormat()
{
return 'Y-m-d H:i:s.v';
}
/**
* Wrap a table in keyword identifiers.
*
* @param \Illuminate\Database\Query\Expression|string $table
* @return string
*/
public function wrapTable($table)
{
if (! $this->isExpression($table)) {
return $this->wrapTableValuedFunction(parent::wrapTable($table));
}
return $this->getValue($table);
}
/**
* Compile the "select *" portion of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $columns
* @return string|null
*/
protected function compileColumns(Builder $query, $columns)
{
if (! is_null($query->aggregate)) {
return;
}
$select = $query->distinct ? 'select distinct ' : 'select ';
// If there is a limit on the query, but not an offset, we will add the top
// clause to the query, which serves as a "limit" type clause within the
// SQL Server system similar to the limit keywords available in MySQL.
if ($query->limit > 0 && $query->offset <= 0) {
$select .= 'top '.$query->limit.' ';
}
return $select.$this->columnize($columns);
}
/**
* Compile the "from" portion of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $table
* @return string
*/
protected function compileFrom(Builder $query, $table)
{
$from = parent::compileFrom($query, $table);
if (is_string($query->lock)) {
return $from.' '.$query->lock;
}
if (! is_null($query->lock)) {
return $from.' with(rowlock,'.($query->lock ? 'updlock,' : '').'holdlock)';
}
return $from;
}
/**
* Compile a "where date" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereDate(Builder $query, $where)
{
$value = $this->parameter($where['value']);
return 'cast('.$this->wrap($where['column']).' as date) '.$where['operator'].' '.$value;
}
/**
* Compile a "where time" clause.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $where
* @return string
*/
protected function whereTime(Builder $query, $where)
{
$value = $this->parameter($where['value']);
return 'cast('.$this->wrap($where['column']).' as time) '.$where['operator'].' '.$value;
}
/**
* Compile a "JSON contains" statement into SQL.
*
* @param string $column
* @param string $value
* @return string
*/
protected function compileJsonContains($column, $value)
{
[$field, $path] = $this->wrapJsonFieldAndPath($column);
return $value.' in (select [value] from openjson('.$field.$path.'))';
}
/**
* Compile a "JSON length" statement into SQL.
*
* @param string $column
* @param string $operator
* @param string $value
* @return string
*/
protected function compileJsonLength($column, $operator, $value)
{
[$field, $path] = $this->wrapJsonFieldAndPath($column);
return '(select count(*) from openjson('.$field.$path.')) '.$operator.' '.$value;
}
/**
* Create a full ANSI offset clause for the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $components
* @return string
*/
protected function compileAnsiOffset(Builder $query, $components)
{
// An ORDER BY clause is required to make this offset query work, so if one does
// not exist we'll just create a dummy clause to trick the database and so it
// does not complain about the queries for not having an "order by" clause.
if (empty($components['orders'])) {
$components['orders'] = 'order by (select 0)';
}
// We need to add the row number to the query so we can compare it to the offset
// and limit values given for the statements. So we will add an expression to
// the "select" that will give back the row numbers on each of the records.
$components['columns'] .= $this->compileOver($components['orders']);
unset($components['orders']);
// Next we need to calculate the constraints that should be placed on the query
// to get the right offset and limit from our query but if there is no limit
// set we will just handle the offset only since that is all that matters.
$sql = $this->concatenate($components);
return $this->compileTableExpression($sql, $query);
}
/**
* Compile the over statement for a table expression.
*
* @param string $orderings
* @return string
*/
protected function compileOver($orderings)
{
return ", row_number() over ({$orderings}) as row_num";
}
/**
* Compile a common table expression for a query.
*
* @param string $sql
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
protected function compileTableExpression($sql, $query)
{
$constraint = $this->compileRowConstraint($query);
return "select * from ({$sql}) as temp_table where row_num {$constraint} order by row_num";
}
/**
* Compile the limit / offset row constraint for a query.
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
protected function compileRowConstraint($query)
{
$start = $query->offset + 1;
if ($query->limit > 0) {
$finish = $query->offset + $query->limit;
return "between {$start} and {$finish}";
}
return ">= {$start}";
}
/**
* Compile the "limit" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param int $limit
* @return string
*/
protected function compileLimit(Builder $query, $limit)
{
return '';
}
/**
* Compile the "offset" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param int $offset
* @return string
*/
protected function compileOffset(Builder $query, $offset)
{
return '';
}
/**
* Compile the lock into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param bool|string $value
* @return string
*/
protected function compileLock(Builder $query, $value)
{
return '';
}
/**
* Compile a delete statement with joins into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $table
* @param string $where
* @return string
*/
protected function compileDeleteWithJoins(Builder $query, $table, $where)
{
$joins = ' '.$this->compileJoins($query, $query->joins);
$alias = stripos($table, ' as ') !== false
? explode(' as ', $table)[1] : $table;
return trim("delete {$alias} from {$table}{$joins} {$where}");
}
/**
* Get the table and alias for the given table.
*
* @param string $table
* @return array
*/
protected function parseUpdateTable($table)
{
$table = $alias = $this->wrapTable($table);
if (stripos($table, '] as [') !== false) {
$alias = '['.explode('] as [', $table)[1];
}
return [$table, $alias];
}
/**
* Wrap a single string in keyword identifiers.
*
* @param string $value
* @return string
*/
protected function wrapValue($value)
{
return $value === '*' ? $value : '['.str_replace(']', ']]', $value).']';
}
/**
* Wrap the given JSON selector.
*
* @param string $value
* @return string
*/
protected function wrapJsonSelector($value)
{
[$field, $path] = $this->wrapJsonFieldAndPath($value);
return 'json_value('.$field.$path.')';
}
/**
* Wrap a table in keyword identifiers.
*
* @param string $table
* @return string
*/
protected function wrapTableValuedFunction($table)
{
if (preg_match('/^(.+?)(\(.*?\))]$/', $table, $matches) === 1) {
$table = $matches[1].']'.$matches[2];
}
return $table;
}
}

View File

@ -9,7 +9,7 @@ declare(strict_types=1);
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Query;
namespace Hyperf\Database\Query;
use Closure;
@ -32,14 +32,14 @@ class JoinClause extends Builder
/**
* The parent query builder instance.
*
* @var \Illuminate\Database\Query\Builder
* @var \Hyperf\Database\Query\Builder
*/
private $parentQuery;
/**
* Create a new join clause instance.
*
* @param \Illuminate\Database\Query\Builder $parentQuery
* @param \Hyperf\Database\Query\Builder $parentQuery
* @param string $type
* @param string $table
* @return void
@ -92,7 +92,7 @@ class JoinClause extends Builder
* @param \Closure|string $first
* @param string|null $operator
* @param string|null $second
* @return \Illuminate\Database\Query\JoinClause
* @return \Hyperf\Database\Query\JoinClause
*/
public function orOn($first, $operator = null, $second = null)
{
@ -102,7 +102,7 @@ class JoinClause extends Builder
/**
* Get a new instance of the join clause builder.
*
* @return \Illuminate\Database\Query\JoinClause
* @return \Hyperf\Database\Query\JoinClause
*/
public function newQuery()
{
@ -112,7 +112,7 @@ class JoinClause extends Builder
/**
* Create a new query instance for sub-query.
*
* @return \Illuminate\Database\Query\Builder
* @return \Hyperf\Database\Query\Builder
*/
protected function forSubQuery()
{

View File

@ -1,50 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Query\Processors;
use Illuminate\Database\Query\Builder;
class PostgresProcessor extends Processor
{
/**
* Process an "insert get ID" query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $sql
* @param array $values
* @param string $sequence
* @return int
*/
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$result = $query->getConnection()->selectFromWriteConnection($sql, $values)[0];
$sequence = $sequence ?: 'id';
$id = is_object($result) ? $result->{$sequence} : $result[$sequence];
return is_numeric($id) ? (int) $id : $id;
}
/**
* Process the results of a column listing query.
*
* @param array $results
* @return array
*/
public function processColumnListing($results)
{
return array_map(function ($result) {
return ((object) $result)->column_name;
}, $results);
}
}

View File

@ -1,28 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Query\Processors;
class SQLiteProcessor extends Processor
{
/**
* Process the results of a column listing query.
*
* @param array $results
* @return array
*/
public function processColumnListing($results)
{
return array_map(function ($result) {
return ((object) $result)->name;
}, $results);
}
}

View File

@ -1,79 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Query\Processors;
use Exception;
use Illuminate\Database\Connection;
use Illuminate\Database\Query\Builder;
class SqlServerProcessor extends Processor
{
/**
* Process an "insert get ID" query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $sql
* @param array $values
* @param string $sequence
* @return int
*/
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$connection = $query->getConnection();
$connection->insert($sql, $values);
if ($connection->getConfig('odbc') === true) {
$id = $this->processInsertGetIdForOdbc($connection);
} else {
$id = $connection->getPdo()->lastInsertId();
}
return is_numeric($id) ? (int) $id : $id;
}
/**
* Process the results of a column listing query.
*
* @param array $results
* @return array
*/
public function processColumnListing($results)
{
return array_map(function ($result) {
return ((object) $result)->name;
}, $results);
}
/**
* Process an "insert get ID" query for ODBC.
*
* @param \Illuminate\Database\Connection $connection
* @return int
*
* @throws \Exception
*/
protected function processInsertGetIdForOdbc(Connection $connection)
{
$result = $connection->selectFromWriteConnection(
'SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) AS insertid'
);
if (! $result) {
throw new Exception('Unable to retrieve lastInsertID for ODBC.');
}
$row = $result[0];
return is_object($row) ? $row->insertid : $row['insertid'];
}
}

View File

@ -17,7 +17,7 @@ use Hyperf\Database\Connection;
use Hyperf\Database\Schema\Grammars\Grammar;
use Hyperf\Utils\Fluent;
use Hyperf\Utils\Traits\Macroable;
use Illuminate\Database\SQLiteConnection;
use Hyperf\Database\SQLiteConnection;
class Blueprint
{
@ -64,14 +64,14 @@ class Blueprint
/**
* The columns that should be added to the table.
*
* @var \Illuminate\Database\Schema\ColumnDefinition[]
* @var \Hyperf\Database\Schema\ColumnDefinition[]
*/
protected $columns = [];
/**
* The commands that should be run for the table.
*
* @var \Illuminate\Support\Fluent[]
* @var \Hyperf\Support\Fluent[]
*/
protected $commands = [];
@ -96,8 +96,8 @@ class Blueprint
/**
* Execute the blueprint against the database.
*
* @param \Illuminate\Database\Connection $connection
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
* @param \Hyperf\Database\Connection $connection
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
* @return void
*/
public function build(Connection $connection, Grammar $grammar)
@ -110,8 +110,8 @@ class Blueprint
/**
* Get the raw SQL statements for the blueprint.
*
* @param \Illuminate\Database\Connection $connection
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
* @param \Hyperf\Database\Connection $connection
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
* @return array
*/
public function toSql(Connection $connection, Grammar $grammar)
@ -141,7 +141,7 @@ class Blueprint
/**
* Add the fluent commands specified on any columns.
*
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
* @return void
*/
public function addFluentCommands(Grammar $grammar)
@ -167,7 +167,7 @@ class Blueprint
/**
* Indicate that the table needs to be created.
*
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function create()
{
@ -187,7 +187,7 @@ class Blueprint
/**
* Indicate that the table should be dropped.
*
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function drop()
{
@ -197,7 +197,7 @@ class Blueprint
/**
* Indicate that the table should be dropped if it exists.
*
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function dropIfExists()
{
@ -208,7 +208,7 @@ class Blueprint
* Indicate that the given columns should be dropped.
*
* @param array|mixed $columns
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function dropColumn($columns)
{
@ -222,7 +222,7 @@ class Blueprint
*
* @param string $from
* @param string $to
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function renameColumn($from, $to)
{
@ -233,7 +233,7 @@ class Blueprint
* Indicate that the given primary key should be dropped.
*
* @param string|array $index
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function dropPrimary($index = null)
{
@ -244,7 +244,7 @@ class Blueprint
* Indicate that the given unique key should be dropped.
*
* @param string|array $index
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function dropUnique($index)
{
@ -255,7 +255,7 @@ class Blueprint
* Indicate that the given index should be dropped.
*
* @param string|array $index
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function dropIndex($index)
{
@ -266,7 +266,7 @@ class Blueprint
* Indicate that the given spatial index should be dropped.
*
* @param string|array $index
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function dropSpatialIndex($index)
{
@ -277,7 +277,7 @@ class Blueprint
* Indicate that the given foreign key should be dropped.
*
* @param string|array $index
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function dropForeign($index)
{
@ -289,7 +289,7 @@ class Blueprint
*
* @param string $from
* @param string $to
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function renameIndex($from, $to)
{
@ -366,7 +366,7 @@ class Blueprint
* Rename the table to a given name.
*
* @param string $to
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function rename($to)
{
@ -379,7 +379,7 @@ class Blueprint
* @param string|array $columns
* @param string $name
* @param string|null $algorithm
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function primary($columns, $name = null, $algorithm = null)
{
@ -392,7 +392,7 @@ class Blueprint
* @param string|array $columns
* @param string $name
* @param string|null $algorithm
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function unique($columns, $name = null, $algorithm = null)
{
@ -405,7 +405,7 @@ class Blueprint
* @param string|array $columns
* @param string $name
* @param string|null $algorithm
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function index($columns, $name = null, $algorithm = null)
{
@ -417,7 +417,7 @@ class Blueprint
*
* @param string|array $columns
* @param string $name
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function spatialIndex($columns, $name = null)
{
@ -429,7 +429,7 @@ class Blueprint
*
* @param string|array $columns
* @param string $name
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
public function foreign($columns, $name = null)
{
@ -440,7 +440,7 @@ class Blueprint
* Create a new auto-incrementing integer (4-byte) column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function increments($column)
{
@ -451,7 +451,7 @@ class Blueprint
* Create a new auto-incrementing integer (4-byte) column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function integerIncrements($column)
{
@ -462,7 +462,7 @@ class Blueprint
* Create a new auto-incrementing tiny integer (1-byte) column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function tinyIncrements($column)
{
@ -473,7 +473,7 @@ class Blueprint
* Create a new auto-incrementing small integer (2-byte) column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function smallIncrements($column)
{
@ -484,7 +484,7 @@ class Blueprint
* Create a new auto-incrementing medium integer (3-byte) column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function mediumIncrements($column)
{
@ -495,7 +495,7 @@ class Blueprint
* Create a new auto-incrementing big integer (8-byte) column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function bigIncrements($column)
{
@ -507,7 +507,7 @@ class Blueprint
*
* @param string $column
* @param int $length
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function char($column, $length = null)
{
@ -521,7 +521,7 @@ class Blueprint
*
* @param string $column
* @param int $length
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function string($column, $length = null)
{
@ -534,7 +534,7 @@ class Blueprint
* Create a new text column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function text($column)
{
@ -545,7 +545,7 @@ class Blueprint
* Create a new medium text column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function mediumText($column)
{
@ -556,7 +556,7 @@ class Blueprint
* Create a new long text column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function longText($column)
{
@ -569,7 +569,7 @@ class Blueprint
* @param string $column
* @param bool $autoIncrement
* @param bool $unsigned
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function integer($column, $autoIncrement = false, $unsigned = false)
{
@ -582,7 +582,7 @@ class Blueprint
* @param string $column
* @param bool $autoIncrement
* @param bool $unsigned
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function tinyInteger($column, $autoIncrement = false, $unsigned = false)
{
@ -595,7 +595,7 @@ class Blueprint
* @param string $column
* @param bool $autoIncrement
* @param bool $unsigned
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function smallInteger($column, $autoIncrement = false, $unsigned = false)
{
@ -608,7 +608,7 @@ class Blueprint
* @param string $column
* @param bool $autoIncrement
* @param bool $unsigned
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function mediumInteger($column, $autoIncrement = false, $unsigned = false)
{
@ -621,7 +621,7 @@ class Blueprint
* @param string $column
* @param bool $autoIncrement
* @param bool $unsigned
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function bigInteger($column, $autoIncrement = false, $unsigned = false)
{
@ -633,7 +633,7 @@ class Blueprint
*
* @param string $column
* @param bool $autoIncrement
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function unsignedInteger($column, $autoIncrement = false)
{
@ -645,7 +645,7 @@ class Blueprint
*
* @param string $column
* @param bool $autoIncrement
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function unsignedTinyInteger($column, $autoIncrement = false)
{
@ -657,7 +657,7 @@ class Blueprint
*
* @param string $column
* @param bool $autoIncrement
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function unsignedSmallInteger($column, $autoIncrement = false)
{
@ -669,7 +669,7 @@ class Blueprint
*
* @param string $column
* @param bool $autoIncrement
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function unsignedMediumInteger($column, $autoIncrement = false)
{
@ -681,7 +681,7 @@ class Blueprint
*
* @param string $column
* @param bool $autoIncrement
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function unsignedBigInteger($column, $autoIncrement = false)
{
@ -694,7 +694,7 @@ class Blueprint
* @param string $column
* @param int $total
* @param int $places
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function float($column, $total = 8, $places = 2)
{
@ -707,7 +707,7 @@ class Blueprint
* @param string $column
* @param int|null $total
* @param int|null $places
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function double($column, $total = null, $places = null)
{
@ -720,7 +720,7 @@ class Blueprint
* @param string $column
* @param int $total
* @param int $places
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function decimal($column, $total = 8, $places = 2)
{
@ -733,7 +733,7 @@ class Blueprint
* @param string $column
* @param int $total
* @param int $places
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function unsignedDecimal($column, $total = 8, $places = 2)
{
@ -746,7 +746,7 @@ class Blueprint
* Create a new boolean column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function boolean($column)
{
@ -758,7 +758,7 @@ class Blueprint
*
* @param string $column
* @param array $allowed
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function enum($column, array $allowed)
{
@ -769,7 +769,7 @@ class Blueprint
* Create a new json column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function json($column)
{
@ -780,7 +780,7 @@ class Blueprint
* Create a new jsonb column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function jsonb($column)
{
@ -791,7 +791,7 @@ class Blueprint
* Create a new date column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function date($column)
{
@ -803,7 +803,7 @@ class Blueprint
*
* @param string $column
* @param int $precision
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function dateTime($column, $precision = 0)
{
@ -815,7 +815,7 @@ class Blueprint
*
* @param string $column
* @param int $precision
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function dateTimeTz($column, $precision = 0)
{
@ -827,7 +827,7 @@ class Blueprint
*
* @param string $column
* @param int $precision
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function time($column, $precision = 0)
{
@ -839,7 +839,7 @@ class Blueprint
*
* @param string $column
* @param int $precision
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function timeTz($column, $precision = 0)
{
@ -851,7 +851,7 @@ class Blueprint
*
* @param string $column
* @param int $precision
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function timestamp($column, $precision = 0)
{
@ -863,7 +863,7 @@ class Blueprint
*
* @param string $column
* @param int $precision
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function timestampTz($column, $precision = 0)
{
@ -914,7 +914,7 @@ class Blueprint
*
* @param string $column
* @param int $precision
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function softDeletes($column = 'deleted_at', $precision = 0)
{
@ -926,7 +926,7 @@ class Blueprint
*
* @param string $column
* @param int $precision
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function softDeletesTz($column = 'deleted_at', $precision = 0)
{
@ -937,7 +937,7 @@ class Blueprint
* Create a new year column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function year($column)
{
@ -948,7 +948,7 @@ class Blueprint
* Create a new binary column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function binary($column)
{
@ -959,7 +959,7 @@ class Blueprint
* Create a new uuid column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function uuid($column)
{
@ -970,7 +970,7 @@ class Blueprint
* Create a new IP address column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function ipAddress($column)
{
@ -981,7 +981,7 @@ class Blueprint
* Create a new MAC address column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function macAddress($column)
{
@ -992,7 +992,7 @@ class Blueprint
* Create a new geometry column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function geometry($column)
{
@ -1004,7 +1004,7 @@ class Blueprint
*
* @param string $column
* @param int|null $srid
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function point($column, $srid = null)
{
@ -1015,7 +1015,7 @@ class Blueprint
* Create a new linestring column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function lineString($column)
{
@ -1026,7 +1026,7 @@ class Blueprint
* Create a new polygon column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function polygon($column)
{
@ -1037,7 +1037,7 @@ class Blueprint
* Create a new geometrycollection column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function geometryCollection($column)
{
@ -1048,7 +1048,7 @@ class Blueprint
* Create a new multipoint column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function multiPoint($column)
{
@ -1059,7 +1059,7 @@ class Blueprint
* Create a new multilinestring column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function multiLineString($column)
{
@ -1070,7 +1070,7 @@ class Blueprint
* Create a new multipolygon column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function multiPolygon($column)
{
@ -1112,7 +1112,7 @@ class Blueprint
/**
* Adds the `remember_token` column to the table.
*
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function rememberToken()
{
@ -1125,7 +1125,7 @@ class Blueprint
* @param string $type
* @param string $name
* @param array $parameters
* @return \Illuminate\Database\Schema\ColumnDefinition
* @return \Hyperf\Database\Schema\ColumnDefinition
*/
public function addColumn($type, $name, array $parameters = [])
{
@ -1164,7 +1164,7 @@ class Blueprint
/**
* Get the columns on the blueprint.
*
* @return \Illuminate\Database\Schema\ColumnDefinition[]
* @return \Hyperf\Database\Schema\ColumnDefinition[]
*/
public function getColumns()
{
@ -1174,7 +1174,7 @@ class Blueprint
/**
* Get the commands on the blueprint.
*
* @return \Illuminate\Support\Fluent[]
* @return \Hyperf\Support\Fluent[]
*/
public function getCommands()
{
@ -1184,7 +1184,7 @@ class Blueprint
/**
* Get the columns on the blueprint that should be added.
*
* @return \Illuminate\Database\Schema\ColumnDefinition[]
* @return \Hyperf\Database\Schema\ColumnDefinition[]
*/
public function getAddedColumns()
{
@ -1196,7 +1196,7 @@ class Blueprint
/**
* Get the columns on the blueprint that should be changed.
*
* @return \Illuminate\Database\Schema\ColumnDefinition[]
* @return \Hyperf\Database\Schema\ColumnDefinition[]
*/
public function getChangedColumns()
{
@ -1208,7 +1208,7 @@ class Blueprint
/**
* Ensure the commands on the blueprint are valid for the connection type.
*
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Connection $connection
* @return void
*
* @throws \BadMethodCallException
@ -1234,7 +1234,7 @@ class Blueprint
* Get all of the commands matching the given names.
*
* @param array $names
* @return \Illuminate\Support\Collection
* @return \Hyperf\Support\Collection
*/
protected function commandsNamed(array $names)
{
@ -1246,7 +1246,7 @@ class Blueprint
/**
* Add the commands that are implied by the blueprint's state.
*
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
* @return void
*/
protected function addImpliedCommands(Grammar $grammar)
@ -1313,7 +1313,7 @@ class Blueprint
* @param string|array $columns
* @param string $index
* @param string|null $algorithm
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
protected function indexCommand($type, $columns, $index, $algorithm = null)
{
@ -1336,7 +1336,7 @@ class Blueprint
* @param string $command
* @param string $type
* @param string|array $index
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
protected function dropIndexCommand($command, $type, $index)
{
@ -1371,7 +1371,7 @@ class Blueprint
*
* @param string $name
* @param array $parameters
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
protected function addCommand($name, array $parameters = [])
{
@ -1385,7 +1385,7 @@ class Blueprint
*
* @param string $name
* @param array $parameters
* @return \Illuminate\Support\Fluent
* @return \Hyperf\Support\Fluent
*/
protected function createCommand($name, array $parameters = [])
{

View File

@ -27,14 +27,14 @@ class Builder
/**
* The database connection instance.
*
* @var \Illuminate\Database\Connection
* @var \Hyperf\Database\Connection
*/
protected $connection;
/**
* The schema grammar instance.
*
* @var \Illuminate\Database\Schema\Grammars\Grammar
* @var \Hyperf\Database\Schema\Grammars\Grammar
*/
protected $grammar;
@ -48,7 +48,7 @@ class Builder
/**
* Create a new database Schema manager.
*
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Connection $connection
* @return void
*/
public function __construct(Connection $connection)
@ -267,7 +267,7 @@ class Builder
/**
* Get the database connection instance.
*
* @return \Illuminate\Database\Connection
* @return \Hyperf\Database\Connection
*/
public function getConnection()
{
@ -277,7 +277,7 @@ class Builder
/**
* Set the database connection instance.
*
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Connection $connection
* @return $this
*/
public function setConnection(Connection $connection)
@ -301,7 +301,7 @@ class Builder
/**
* Execute the blueprint to build / modify the table.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @return void
*/
protected function build(Blueprint $blueprint)
@ -314,7 +314,7 @@ class Builder
*
* @param string $table
* @param \Closure|null $callback
* @return \Illuminate\Database\Schema\Blueprint
* @return \Hyperf\Database\Schema\Blueprint
*/
protected function createBlueprint($table, Closure $callback = null)
{

View File

@ -9,9 +9,9 @@ declare(strict_types=1);
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Schema;
namespace Hyperf\Database\Schema;
use Illuminate\Support\Fluent;
use Hyperf\Utils\Fluent;
/**
* @method ColumnDefinition after(string $column) Place the column "after" another column (MySQL)

View File

@ -25,10 +25,10 @@ class ChangeColumn
/**
* Compile a change column command into a series of SQL statements.
*
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @param \Hyperf\Database\Connection $connection
* @return array
*
* @throws \RuntimeException
@ -58,8 +58,8 @@ class ChangeColumn
/**
* Get the Doctrine table difference for the given changes.
*
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
* @return \Doctrine\DBAL\Schema\TableDiff|bool
*/
@ -76,7 +76,7 @@ class ChangeColumn
/**
* Get a copy of the given Doctrine table after making the column changes.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Doctrine\DBAL\Schema\Table $table
* @return \Doctrine\DBAL\Schema\Table
*/
@ -106,7 +106,7 @@ class ChangeColumn
* Get the Doctrine column instance for a column change.
*
* @param \Doctrine\DBAL\Schema\Table $table
* @param \Illuminate\Support\Fluent $fluent
* @param \Hyperf\Support\Fluent $fluent
* @return \Doctrine\DBAL\Schema\Column
*/
protected static function getDoctrineColumn(Table $table, Fluent $fluent)
@ -120,7 +120,7 @@ class ChangeColumn
/**
* Get the Doctrine column change options.
*
* @param \Illuminate\Support\Fluent $fluent
* @param \Hyperf\Support\Fluent $fluent
* @return array
*/
protected static function getDoctrineColumnChangeOptions(Fluent $fluent)

View File

@ -38,9 +38,9 @@ abstract class Grammar extends BaseGrammar
/**
* Compile a rename column command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @param \Hyperf\Database\Connection $connection
* @return array
*/
public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
@ -51,9 +51,9 @@ abstract class Grammar extends BaseGrammar
/**
* Compile a change column command into a series of SQL statements.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @param \Hyperf\Database\Connection $connection
* @return array
*
* @throws \RuntimeException
@ -66,8 +66,8 @@ abstract class Grammar extends BaseGrammar
/**
* Compile a foreign key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileForeign(Blueprint $blueprint, Fluent $command)
@ -135,7 +135,7 @@ abstract class Grammar extends BaseGrammar
/**
* Wrap a value in keyword identifiers.
*
* @param \Illuminate\Database\Query\Expression|string $value
* @param \Hyperf\Database\Query\Expression|string $value
* @param bool $prefixAlias
* @return string
*/
@ -150,7 +150,7 @@ abstract class Grammar extends BaseGrammar
/**
* Create an empty Doctrine DBAL TableDiff from the Blueprint.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
* @return \Doctrine\DBAL\Schema\TableDiff
*/
@ -186,7 +186,7 @@ abstract class Grammar extends BaseGrammar
/**
* Compile the blueprint's column definitions.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @return array
*/
protected function getColumns(Blueprint $blueprint)
@ -208,7 +208,7 @@ abstract class Grammar extends BaseGrammar
/**
* Get the SQL for the column data type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function getType(Fluent $column)
@ -220,8 +220,8 @@ abstract class Grammar extends BaseGrammar
* Add the column modifiers to the definition.
*
* @param string $sql
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function addModifiers($sql, Blueprint $blueprint, Fluent $column)
@ -238,9 +238,9 @@ abstract class Grammar extends BaseGrammar
/**
* Get the primary key command if it exists on the blueprint.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param string $name
* @return \Illuminate\Support\Fluent|null
* @return \Hyperf\Support\Fluent|null
*/
protected function getCommandByName(Blueprint $blueprint, $name)
{
@ -254,7 +254,7 @@ abstract class Grammar extends BaseGrammar
/**
* Get all of the commands with a given name.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param string $name
* @return array
*/

View File

@ -57,9 +57,9 @@ class MySqlGrammar extends Grammar
/**
* Compile a create table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @param \Hyperf\Database\Connection $connection
* @return string
*/
public function compileCreate(Blueprint $blueprint, Fluent $command, Connection $connection)
@ -92,8 +92,8 @@ class MySqlGrammar extends Grammar
/**
* Compile an add column command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileAdd(Blueprint $blueprint, Fluent $command)
@ -106,8 +106,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a primary key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compilePrimary(Blueprint $blueprint, Fluent $command)
@ -120,8 +120,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileUnique(Blueprint $blueprint, Fluent $command)
@ -132,8 +132,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a plain index key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileIndex(Blueprint $blueprint, Fluent $command)
@ -144,8 +144,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a spatial index key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
@ -156,8 +156,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a drop table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileDrop(Blueprint $blueprint, Fluent $command)
@ -168,8 +168,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a drop table (if exists) command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
@ -180,8 +180,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a drop column command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
@ -194,8 +194,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a drop primary key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
@ -206,8 +206,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a drop unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
@ -220,8 +220,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a drop index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
@ -234,8 +234,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a drop spatial index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
@ -246,8 +246,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a drop foreign key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
@ -260,8 +260,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a rename table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileRename(Blueprint $blueprint, Fluent $command)
@ -274,8 +274,8 @@ class MySqlGrammar extends Grammar
/**
* Compile a rename index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @return string
*/
public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
@ -353,7 +353,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a spatial Geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
public function typeGeometry(Fluent $column)
@ -364,7 +364,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a spatial Point type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
public function typePoint(Fluent $column)
@ -375,7 +375,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a spatial LineString type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
public function typeLineString(Fluent $column)
@ -386,7 +386,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a spatial Polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
public function typePolygon(Fluent $column)
@ -397,7 +397,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a spatial GeometryCollection type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
public function typeGeometryCollection(Fluent $column)
@ -408,7 +408,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a spatial MultiPoint type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
public function typeMultiPoint(Fluent $column)
@ -419,7 +419,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a spatial MultiLineString type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
public function typeMultiLineString(Fluent $column)
@ -430,7 +430,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a spatial MultiPolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
public function typeMultiPolygon(Fluent $column)
@ -441,9 +441,9 @@ class MySqlGrammar extends Grammar
/**
* Create the main create table clause.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @param \Hyperf\Database\Connection $connection
* @return string
*/
protected function compileCreateTable($blueprint, $command, $connection)
@ -460,8 +460,8 @@ class MySqlGrammar extends Grammar
* Append the character set specifications to a command.
*
* @param string $sql
* @param \Illuminate\Database\Connection $connection
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Database\Connection $connection
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @return string
*/
protected function compileCreateEncoding($sql, Connection $connection, Blueprint $blueprint)
@ -491,8 +491,8 @@ class MySqlGrammar extends Grammar
* Append the engine specifications to a command.
*
* @param string $sql
* @param \Illuminate\Database\Connection $connection
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Database\Connection $connection
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @return string
*/
protected function compileCreateEngine($sql, Connection $connection, Blueprint $blueprint)
@ -509,8 +509,8 @@ class MySqlGrammar extends Grammar
/**
* Compile an index creation command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @param string $type
* @return string
*/
@ -529,7 +529,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a char type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeChar(Fluent $column)
@ -540,7 +540,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a string type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeString(Fluent $column)
@ -551,7 +551,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a text type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeText(Fluent $column)
@ -562,7 +562,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a medium text type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeMediumText(Fluent $column)
@ -573,7 +573,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a long text type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeLongText(Fluent $column)
@ -584,7 +584,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a big integer type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeBigInteger(Fluent $column)
@ -595,7 +595,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for an integer type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeInteger(Fluent $column)
@ -606,7 +606,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a medium integer type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeMediumInteger(Fluent $column)
@ -617,7 +617,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a tiny integer type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeTinyInteger(Fluent $column)
@ -628,7 +628,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a small integer type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeSmallInteger(Fluent $column)
@ -639,7 +639,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a float type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeFloat(Fluent $column)
@ -650,7 +650,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a double type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeDouble(Fluent $column)
@ -665,7 +665,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a decimal type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeDecimal(Fluent $column)
@ -676,7 +676,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a boolean type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeBoolean(Fluent $column)
@ -687,7 +687,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for an enumeration type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeEnum(Fluent $column)
@ -698,7 +698,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a json type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeJson(Fluent $column)
@ -709,7 +709,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a jsonb type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeJsonb(Fluent $column)
@ -720,7 +720,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a date type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeDate(Fluent $column)
@ -731,7 +731,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a date-time type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeDateTime(Fluent $column)
@ -744,7 +744,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a date-time (with time zone) type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeDateTimeTz(Fluent $column)
@ -755,7 +755,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a time type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeTime(Fluent $column)
@ -766,7 +766,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a time (with time zone) type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeTimeTz(Fluent $column)
@ -777,7 +777,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a timestamp type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeTimestamp(Fluent $column)
@ -790,7 +790,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a timestamp (with time zone) type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeTimestampTz(Fluent $column)
@ -801,7 +801,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a year type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeYear(Fluent $column)
@ -812,7 +812,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a binary type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeBinary(Fluent $column)
@ -823,7 +823,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a uuid type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeUuid(Fluent $column)
@ -834,7 +834,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for an IP address type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeIpAddress(Fluent $column)
@ -845,7 +845,7 @@ class MySqlGrammar extends Grammar
/**
* Create the column definition for a MAC address type.
*
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Support\Fluent $column
* @return string
*/
protected function typeMacAddress(Fluent $column)
@ -856,8 +856,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for a generated virtual column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
@ -870,8 +870,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for a generated stored column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyStoredAs(Blueprint $blueprint, Fluent $column)
@ -884,8 +884,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for an unsigned column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyUnsigned(Blueprint $blueprint, Fluent $column)
@ -898,8 +898,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for a character set column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyCharset(Blueprint $blueprint, Fluent $column)
@ -912,8 +912,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for a collation column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyCollate(Blueprint $blueprint, Fluent $column)
@ -926,8 +926,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for a nullable column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
@ -940,8 +940,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for a default column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
@ -954,8 +954,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for an auto-increment column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
@ -968,8 +968,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for a "first" column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyFirst(Blueprint $blueprint, Fluent $column)
@ -982,8 +982,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for an "after" column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyAfter(Blueprint $blueprint, Fluent $column)
@ -996,8 +996,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for a "comment" column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifyComment(Blueprint $blueprint, Fluent $column)
@ -1010,8 +1010,8 @@ class MySqlGrammar extends Grammar
/**
* Get the SQL for a SRID column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $column
* @return string|null
*/
protected function modifySrid(Blueprint $blueprint, Fluent $column)

View File

@ -1,915 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Schema\Grammars;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Fluent;
class PostgresGrammar extends Grammar
{
/**
* If this Grammar supports schema changes wrapped in a transaction.
*
* @var bool
*/
protected $transactions = true;
/**
* The possible column modifiers.
*
* @var array
*/
protected $modifiers = ['Increment', 'Nullable', 'Default'];
/**
* The columns available as serials.
*
* @var array
*/
protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];
/**
* The commands to be executed outside of create or alter command.
*
* @var array
*/
protected $fluentCommands = ['Comment'];
/**
* Compile the query to determine if a table exists.
*
* @return string
*/
public function compileTableExists()
{
return 'select * from information_schema.tables where table_schema = ? and table_name = ?';
}
/**
* Compile the query to determine the list of columns.
*
* @return string
*/
public function compileColumnListing()
{
return 'select column_name from information_schema.columns where table_schema = ? and table_name = ?';
}
/**
* Compile a create table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileCreate(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'%s table %s (%s)',
$blueprint->temporary ? 'create temporary' : 'create',
$this->wrapTable($blueprint),
implode(', ', $this->getColumns($blueprint))
);
}
/**
* Compile a column addition command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileAdd(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'alter table %s %s',
$this->wrapTable($blueprint),
implode(', ', $this->prefixArray('add column', $this->getColumns($blueprint)))
);
}
/**
* Compile a primary key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compilePrimary(Blueprint $blueprint, Fluent $command)
{
$columns = $this->columnize($command->columns);
return 'alter table '.$this->wrapTable($blueprint)." add primary key ({$columns})";
}
/**
* Compile a unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileUnique(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'alter table %s add constraint %s unique (%s)',
$this->wrapTable($blueprint),
$this->wrap($command->index),
$this->columnize($command->columns)
);
}
/**
* Compile a plain index key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileIndex(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'create index %s on %s%s (%s)',
$this->wrap($command->index),
$this->wrapTable($blueprint),
$command->algorithm ? ' using '.$command->algorithm : '',
$this->columnize($command->columns)
);
}
/**
* Compile a spatial index key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
{
$command->algorithm = 'gist';
return $this->compileIndex($blueprint, $command);
}
/**
* Compile a foreign key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileForeign(Blueprint $blueprint, Fluent $command)
{
$sql = parent::compileForeign($blueprint, $command);
if (! is_null($command->deferrable)) {
$sql .= $command->deferrable ? ' deferrable' : ' not deferrable';
}
if ($command->deferrable && ! is_null($command->initiallyImmediate)) {
$sql .= $command->initiallyImmediate ? ' initially immediate' : ' initially deferred';
}
if (! is_null($command->notValid)) {
$sql .= ' not valid';
}
return $sql;
}
/**
* Compile a drop table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDrop(Blueprint $blueprint, Fluent $command)
{
return 'drop table '.$this->wrapTable($blueprint);
}
/**
* Compile a drop table (if exists) command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
{
return 'drop table if exists '.$this->wrapTable($blueprint);
}
/**
* Compile the SQL needed to drop all tables.
*
* @param string $tables
* @return string
*/
public function compileDropAllTables($tables)
{
return 'drop table "'.implode('","', $tables).'" cascade';
}
/**
* Compile the SQL needed to drop all views.
*
* @param string $views
* @return string
*/
public function compileDropAllViews($views)
{
return 'drop view "'.implode('","', $views).'" cascade';
}
/**
* Compile the SQL needed to retrieve all table names.
*
* @param string $schema
* @return string
*/
public function compileGetAllTables($schema)
{
return "select tablename from pg_catalog.pg_tables where schemaname = '{$schema}'";
}
/**
* Compile the SQL needed to retrieve all view names.
*
* @param string $schema
* @return string
*/
public function compileGetAllViews($schema)
{
return "select viewname from pg_catalog.pg_views where schemaname = '{$schema}'";
}
/**
* Compile a drop column command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
{
$columns = $this->prefixArray('drop column', $this->wrapArray($command->columns));
return 'alter table '.$this->wrapTable($blueprint).' '.implode(', ', $columns);
}
/**
* Compile a drop primary key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
{
$index = $this->wrap("{$blueprint->getTable()}_pkey");
return 'alter table '.$this->wrapTable($blueprint)." drop constraint {$index}";
}
/**
* Compile a drop unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
{
$index = $this->wrap($command->index);
return "alter table {$this->wrapTable($blueprint)} drop constraint {$index}";
}
/**
* Compile a drop index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
{
return "drop index {$this->wrap($command->index)}";
}
/**
* Compile a drop spatial index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
{
return $this->compileDropIndex($blueprint, $command);
}
/**
* Compile a drop foreign key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
{
$index = $this->wrap($command->index);
return "alter table {$this->wrapTable($blueprint)} drop constraint {$index}";
}
/**
* Compile a rename table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileRename(Blueprint $blueprint, Fluent $command)
{
$from = $this->wrapTable($blueprint);
return "alter table {$from} rename to ".$this->wrapTable($command->to);
}
/**
* Compile a rename index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'alter index %s rename to %s',
$this->wrap($command->from),
$this->wrap($command->to)
);
}
/**
* Compile the command to enable foreign key constraints.
*
* @return string
*/
public function compileEnableForeignKeyConstraints()
{
return 'SET CONSTRAINTS ALL IMMEDIATE;';
}
/**
* Compile the command to disable foreign key constraints.
*
* @return string
*/
public function compileDisableForeignKeyConstraints()
{
return 'SET CONSTRAINTS ALL DEFERRED;';
}
/**
* Compile a comment command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileComment(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'comment on column %s.%s is %s',
$this->wrapTable($blueprint),
$this->wrap($command->column->name),
"'".str_replace("'", "''", $command->value)."'"
);
}
/**
* Create the column definition for a spatial MultiLineString type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultiLineString(Fluent $column)
{
return $this->formatPostGisType('multilinestring');
}
/**
* Create the column definition for a char type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeChar(Fluent $column)
{
return "char({$column->length})";
}
/**
* Create the column definition for a string type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeString(Fluent $column)
{
return "varchar({$column->length})";
}
/**
* Create the column definition for a text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeText(Fluent $column)
{
return 'text';
}
/**
* Create the column definition for a medium text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMediumText(Fluent $column)
{
return 'text';
}
/**
* Create the column definition for a long text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeLongText(Fluent $column)
{
return 'text';
}
/**
* Create the column definition for an integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeInteger(Fluent $column)
{
return $this->generatableColumn('integer', $column);
}
/**
* Create the column definition for a big integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeBigInteger(Fluent $column)
{
return $this->generatableColumn('bigint', $column);
}
/**
* Create the column definition for a medium integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMediumInteger(Fluent $column)
{
return $this->generatableColumn('integer', $column);
}
/**
* Create the column definition for a tiny integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTinyInteger(Fluent $column)
{
return $this->generatableColumn('smallint', $column);
}
/**
* Create the column definition for a small integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeSmallInteger(Fluent $column)
{
return $this->generatableColumn('smallint', $column);
}
/**
* Create the column definition for a generatable column.
*
* @param string $type
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function generatableColumn($type, Fluent $column)
{
if (! $column->autoIncrement && is_null($column->generatedAs)) {
return $type;
}
if ($column->autoIncrement && is_null($column->generatedAs)) {
return with([
'integer' => 'serial',
'bigint' => 'bigserial',
'smallint' => 'smallserial',
])[$type];
}
$options = '';
if (! is_bool($column->generatedAs) && ! empty($column->generatedAs)) {
$options = sprintf(' (%s)', $column->generatedAs);
}
return sprintf(
'%s generated %s as identity%s',
$type,
$column->always ? 'always' : 'by default',
$options
);
}
/**
* Create the column definition for a float type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeFloat(Fluent $column)
{
return $this->typeDouble($column);
}
/**
* Create the column definition for a double type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDouble(Fluent $column)
{
return 'double precision';
}
/**
* Create the column definition for a real type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeReal(Fluent $column)
{
return 'real';
}
/**
* Create the column definition for a decimal type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDecimal(Fluent $column)
{
return "decimal({$column->total}, {$column->places})";
}
/**
* Create the column definition for a boolean type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeBoolean(Fluent $column)
{
return 'boolean';
}
/**
* Create the column definition for an enumeration type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeEnum(Fluent $column)
{
return sprintf(
'varchar(255) check ("%s" in (%s))',
$column->name,
$this->quoteString($column->allowed)
);
}
/**
* Create the column definition for a json type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeJson(Fluent $column)
{
return 'json';
}
/**
* Create the column definition for a jsonb type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeJsonb(Fluent $column)
{
return 'jsonb';
}
/**
* Create the column definition for a date type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDate(Fluent $column)
{
return 'date';
}
/**
* Create the column definition for a date-time type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDateTime(Fluent $column)
{
return $this->typeTimestamp($column);
}
/**
* Create the column definition for a date-time (with time zone) type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDateTimeTz(Fluent $column)
{
return $this->typeTimestampTz($column);
}
/**
* Create the column definition for a time type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTime(Fluent $column)
{
return "time($column->precision) without time zone";
}
/**
* Create the column definition for a time (with time zone) type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTimeTz(Fluent $column)
{
return "time($column->precision) with time zone";
}
/**
* Create the column definition for a timestamp type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTimestamp(Fluent $column)
{
$columnType = "timestamp($column->precision) without time zone";
return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
}
/**
* Create the column definition for a timestamp (with time zone) type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTimestampTz(Fluent $column)
{
$columnType = "timestamp($column->precision) with time zone";
return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
}
/**
* Create the column definition for a year type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeYear(Fluent $column)
{
return $this->typeInteger($column);
}
/**
* Create the column definition for a binary type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeBinary(Fluent $column)
{
return 'bytea';
}
/**
* Create the column definition for a uuid type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeUuid(Fluent $column)
{
return 'uuid';
}
/**
* Create the column definition for an IP address type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeIpAddress(Fluent $column)
{
return 'inet';
}
/**
* Create the column definition for a MAC address type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMacAddress(Fluent $column)
{
return 'macaddr';
}
/**
* Create the column definition for a spatial Geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeGeometry(Fluent $column)
{
return $this->formatPostGisType('geometry');
}
/**
* Create the column definition for a spatial Point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typePoint(Fluent $column)
{
return $this->formatPostGisType('point');
}
/**
* Create the column definition for a spatial LineString type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeLineString(Fluent $column)
{
return $this->formatPostGisType('linestring');
}
/**
* Create the column definition for a spatial Polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typePolygon(Fluent $column)
{
return $this->formatPostGisType('polygon');
}
/**
* Create the column definition for a spatial GeometryCollection type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeGeometryCollection(Fluent $column)
{
return $this->formatPostGisType('geometrycollection');
}
/**
* Create the column definition for a spatial MultiPoint type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMultiPoint(Fluent $column)
{
return $this->formatPostGisType('multipoint');
}
/**
* Create the column definition for a spatial MultiPolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMultiPolygon(Fluent $column)
{
return $this->formatPostGisType('multipolygon');
}
/**
* Get the SQL for a nullable column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
{
return $column->nullable ? ' null' : ' not null';
}
/**
* Get the SQL for a default column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->default)) {
return ' default '.$this->getDefaultValue($column->default);
}
}
/**
* Get the SQL for an auto-increment column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
{
if ((in_array($column->type, $this->serials) || ($column->generatedAs !== null)) && $column->autoIncrement) {
return ' primary key';
}
}
/**
* Format the column definition for a PostGIS spatial type.
*
* @param string $type
* @return string
*/
private function formatPostGisType(string $type)
{
return "geography($type, 4326)";
}
}

View File

@ -9,24 +9,24 @@ declare(strict_types=1);
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Schema\Grammars;
namespace Hyperf\Database\Schema\Grammars;
use Doctrine\DBAL\Schema\AbstractSchemaManager as SchemaManager;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Fluent;
use Hyperf\Database\Connection;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Support\Fluent;
class RenameColumn
{
/**
* Compile a rename column command.
*
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @param \Hyperf\Database\Connection $connection
* @return array
*/
public static function compile(Grammar $grammar, Blueprint $blueprint, Fluent $command, Connection $connection)
@ -50,9 +50,9 @@ class RenameColumn
/**
* Get a new column instance with the new column name.
*
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
* @param \Hyperf\Database\Schema\Blueprint $blueprint
* @param \Hyperf\Support\Fluent $command
* @param \Doctrine\DBAL\Schema\Column $column
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
* @return \Doctrine\DBAL\Schema\TableDiff
@ -70,7 +70,7 @@ class RenameColumn
* Set the renamed columns on the table diff.
*
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Illuminate\Support\Fluent $command
* @param \Hyperf\Support\Fluent $command
* @param \Doctrine\DBAL\Schema\Column $column
* @return \Doctrine\DBAL\Schema\TableDiff
*/

View File

@ -1,879 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Schema\Grammars;
use Doctrine\DBAL\Schema\Index;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Arr;
use Illuminate\Support\Fluent;
use RuntimeException;
class SQLiteGrammar extends Grammar
{
/**
* The possible column modifiers.
*
* @var array
*/
protected $modifiers = ['Nullable', 'Default', 'Increment'];
/**
* The columns available as serials.
*
* @var array
*/
protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];
/**
* Compile the query to determine if a table exists.
*
* @return string
*/
public function compileTableExists()
{
return "select * from sqlite_master where type = 'table' and name = ?";
}
/**
* Compile the query to determine the list of columns.
*
* @param string $table
* @return string
*/
public function compileColumnListing($table)
{
return 'pragma table_info('.$this->wrap(str_replace('.', '__', $table)).')';
}
/**
* Compile a create table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileCreate(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'%s table %s (%s%s%s)',
$blueprint->temporary ? 'create temporary' : 'create',
$this->wrapTable($blueprint),
implode(', ', $this->getColumns($blueprint)),
(string) $this->addForeignKeys($blueprint),
(string) $this->addPrimaryKeys($blueprint)
);
}
/**
* Compile alter table commands for adding columns.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return array
*/
public function compileAdd(Blueprint $blueprint, Fluent $command)
{
$columns = $this->prefixArray('add column', $this->getColumns($blueprint));
return collect($columns)->map(function ($column) use ($blueprint) {
return 'alter table '.$this->wrapTable($blueprint).' '.$column;
})->all();
}
/**
* Compile a unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileUnique(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'create unique index %s on %s (%s)',
$this->wrap($command->index),
$this->wrapTable($blueprint),
$this->columnize($command->columns)
);
}
/**
* Compile a plain index key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileIndex(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'create index %s on %s (%s)',
$this->wrap($command->index),
$this->wrapTable($blueprint),
$this->columnize($command->columns)
);
}
/**
* Compile a spatial index key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
*
* @throws \RuntimeException
*/
public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
{
throw new RuntimeException('The database driver in use does not support spatial indexes.');
}
/**
* Compile a foreign key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileForeign(Blueprint $blueprint, Fluent $command)
{
// Handled on table creation...
}
/**
* Compile a drop table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDrop(Blueprint $blueprint, Fluent $command)
{
return 'drop table '.$this->wrapTable($blueprint);
}
/**
* Compile a drop table (if exists) command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
{
return 'drop table if exists '.$this->wrapTable($blueprint);
}
/**
* Compile the SQL needed to drop all tables.
*
* @return string
*/
public function compileDropAllTables()
{
return "delete from sqlite_master where type in ('table', 'index', 'trigger')";
}
/**
* Compile the SQL needed to drop all views.
*
* @return string
*/
public function compileDropAllViews()
{
return "delete from sqlite_master where type in ('view')";
}
/**
* Compile the SQL needed to rebuild the database.
*
* @return string
*/
public function compileRebuild()
{
return 'vacuum';
}
/**
* Compile a drop column command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @return array
*/
public function compileDropColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
{
$tableDiff = $this->getDoctrineTableDiff(
$blueprint,
$schema = $connection->getDoctrineSchemaManager()
);
foreach ($command->columns as $name) {
$tableDiff->removedColumns[$name] = $connection->getDoctrineColumn(
$this->getTablePrefix().$blueprint->getTable(),
$name
);
}
return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
}
/**
* Compile a drop unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
{
$index = $this->wrap($command->index);
return "drop index {$index}";
}
/**
* Compile a drop index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
{
$index = $this->wrap($command->index);
return "drop index {$index}";
}
/**
* Compile a drop spatial index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
*
* @throws \RuntimeException
*/
public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
{
throw new RuntimeException('The database driver in use does not support spatial indexes.');
}
/**
* Compile a rename table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileRename(Blueprint $blueprint, Fluent $command)
{
$from = $this->wrapTable($blueprint);
return "alter table {$from} rename to ".$this->wrapTable($command->to);
}
/**
* Compile a rename index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @return array
*/
public function compileRenameIndex(Blueprint $blueprint, Fluent $command, Connection $connection)
{
$schemaManager = $connection->getDoctrineSchemaManager();
$indexes = $schemaManager->listTableIndexes($this->getTablePrefix().$blueprint->getTable());
$index = Arr::get($indexes, $command->from);
if (! $index) {
throw new RuntimeException("Index [{$command->from}] does not exist.");
}
$newIndex = new Index(
$command->to,
$index->getColumns(),
$index->isUnique(),
$index->isPrimary(),
$index->getFlags(),
$index->getOptions()
);
$platform = $schemaManager->getDatabasePlatform();
return [
$platform->getDropIndexSQL($command->from, $this->getTablePrefix().$blueprint->getTable()),
$platform->getCreateIndexSQL($newIndex, $this->getTablePrefix().$blueprint->getTable()),
];
}
/**
* Compile the command to enable foreign key constraints.
*
* @return string
*/
public function compileEnableForeignKeyConstraints()
{
return 'PRAGMA foreign_keys = ON;';
}
/**
* Compile the command to disable foreign key constraints.
*
* @return string
*/
public function compileDisableForeignKeyConstraints()
{
return 'PRAGMA foreign_keys = OFF;';
}
/**
* Compile the SQL needed to enable a writable schema.
*
* @return string
*/
public function compileEnableWriteableSchema()
{
return 'PRAGMA writable_schema = 1;';
}
/**
* Compile the SQL needed to disable a writable schema.
*
* @return string
*/
public function compileDisableWriteableSchema()
{
return 'PRAGMA writable_schema = 0;';
}
/**
* Create the column definition for a spatial Geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometry(Fluent $column)
{
return 'geometry';
}
/**
* Create the column definition for a spatial Point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePoint(Fluent $column)
{
return 'point';
}
/**
* Create the column definition for a spatial LineString type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeLineString(Fluent $column)
{
return 'linestring';
}
/**
* Create the column definition for a spatial Polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePolygon(Fluent $column)
{
return 'polygon';
}
/**
* Create the column definition for a spatial GeometryCollection type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometryCollection(Fluent $column)
{
return 'geometrycollection';
}
/**
* Create the column definition for a spatial MultiPoint type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultiPoint(Fluent $column)
{
return 'multipoint';
}
/**
* Create the column definition for a spatial MultiLineString type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultiLineString(Fluent $column)
{
return 'multilinestring';
}
/**
* Create the column definition for a spatial MultiPolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultiPolygon(Fluent $column)
{
return 'multipolygon';
}
/**
* Get the foreign key syntax for a table creation statement.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @return string|null
*/
protected function addForeignKeys(Blueprint $blueprint)
{
$foreigns = $this->getCommandsByName($blueprint, 'foreign');
return collect($foreigns)->reduce(function ($sql, $foreign) {
// Once we have all the foreign key commands for the table creation statement
// we'll loop through each of them and add them to the create table SQL we
// are building, since SQLite needs foreign keys on the tables creation.
$sql .= $this->getForeignKey($foreign);
if (! is_null($foreign->onDelete)) {
$sql .= " on delete {$foreign->onDelete}";
}
// If this foreign key specifies the action to be taken on update we will add
// that to the statement here. We'll append it to this SQL and then return
// the SQL so we can keep adding any other foreign constraints onto this.
if (! is_null($foreign->onUpdate)) {
$sql .= " on update {$foreign->onUpdate}";
}
return $sql;
}, '');
}
/**
* Get the SQL for the foreign key.
*
* @param \Illuminate\Support\Fluent $foreign
* @return string
*/
protected function getForeignKey($foreign)
{
// We need to columnize the columns that the foreign key is being defined for
// so that it is a properly formatted list. Once we have done this, we can
// return the foreign key SQL declaration to the calling method for use.
return sprintf(
', foreign key(%s) references %s(%s)',
$this->columnize($foreign->columns),
$this->wrapTable($foreign->on),
$this->columnize((array) $foreign->references)
);
}
/**
* Get the primary key syntax for a table creation statement.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @return string|null
*/
protected function addPrimaryKeys(Blueprint $blueprint)
{
if (! is_null($primary = $this->getCommandByName($blueprint, 'primary'))) {
return ", primary key ({$this->columnize($primary->columns)})";
}
}
/**
* Create the column definition for a char type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeChar(Fluent $column)
{
return 'varchar';
}
/**
* Create the column definition for a string type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeString(Fluent $column)
{
return 'varchar';
}
/**
* Create the column definition for a text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeText(Fluent $column)
{
return 'text';
}
/**
* Create the column definition for a medium text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMediumText(Fluent $column)
{
return 'text';
}
/**
* Create the column definition for a long text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeLongText(Fluent $column)
{
return 'text';
}
/**
* Create the column definition for a integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeInteger(Fluent $column)
{
return 'integer';
}
/**
* Create the column definition for a big integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeBigInteger(Fluent $column)
{
return 'integer';
}
/**
* Create the column definition for a medium integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMediumInteger(Fluent $column)
{
return 'integer';
}
/**
* Create the column definition for a tiny integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTinyInteger(Fluent $column)
{
return 'integer';
}
/**
* Create the column definition for a small integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeSmallInteger(Fluent $column)
{
return 'integer';
}
/**
* Create the column definition for a float type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeFloat(Fluent $column)
{
return 'float';
}
/**
* Create the column definition for a double type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDouble(Fluent $column)
{
return 'float';
}
/**
* Create the column definition for a decimal type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDecimal(Fluent $column)
{
return 'numeric';
}
/**
* Create the column definition for a boolean type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeBoolean(Fluent $column)
{
return 'tinyint(1)';
}
/**
* Create the column definition for an enumeration type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeEnum(Fluent $column)
{
return sprintf(
'varchar check ("%s" in (%s))',
$column->name,
$this->quoteString($column->allowed)
);
}
/**
* Create the column definition for a json type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeJson(Fluent $column)
{
return 'text';
}
/**
* Create the column definition for a jsonb type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeJsonb(Fluent $column)
{
return 'text';
}
/**
* Create the column definition for a date type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDate(Fluent $column)
{
return 'date';
}
/**
* Create the column definition for a date-time type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDateTime(Fluent $column)
{
return $this->typeTimestamp($column);
}
/**
* Create the column definition for a date-time (with time zone) type.
*
* Note: "SQLite does not have a storage class set aside for storing dates and/or times."
* @link https://www.sqlite.org/datatype3.html
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDateTimeTz(Fluent $column)
{
return $this->typeDateTime($column);
}
/**
* Create the column definition for a time type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTime(Fluent $column)
{
return 'time';
}
/**
* Create the column definition for a time (with time zone) type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTimeTz(Fluent $column)
{
return $this->typeTime($column);
}
/**
* Create the column definition for a timestamp type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTimestamp(Fluent $column)
{
return $column->useCurrent ? 'datetime default CURRENT_TIMESTAMP' : 'datetime';
}
/**
* Create the column definition for a timestamp (with time zone) type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTimestampTz(Fluent $column)
{
return $this->typeTimestamp($column);
}
/**
* Create the column definition for a year type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeYear(Fluent $column)
{
return $this->typeInteger($column);
}
/**
* Create the column definition for a binary type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeBinary(Fluent $column)
{
return 'blob';
}
/**
* Create the column definition for a uuid type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeUuid(Fluent $column)
{
return 'varchar';
}
/**
* Create the column definition for an IP address type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeIpAddress(Fluent $column)
{
return 'varchar';
}
/**
* Create the column definition for a MAC address type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMacAddress(Fluent $column)
{
return 'varchar';
}
/**
* Get the SQL for a nullable column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
{
return $column->nullable ? ' null' : ' not null';
}
/**
* Get the SQL for a default column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->default)) {
return ' default '.$this->getDefaultValue($column->default);
}
}
/**
* Get the SQL for an auto-increment column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
{
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
return ' primary key autoincrement';
}
}
}

View File

@ -1,816 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Schema\Grammars;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Fluent;
class SqlServerGrammar extends Grammar
{
/**
* If this Grammar supports schema changes wrapped in a transaction.
*
* @var bool
*/
protected $transactions = true;
/**
* The possible column modifiers.
*
* @var array
*/
protected $modifiers = ['Increment', 'Collate', 'Nullable', 'Default'];
/**
* The columns available as serials.
*
* @var array
*/
protected $serials = ['tinyInteger', 'smallInteger', 'mediumInteger', 'integer', 'bigInteger'];
/**
* Compile the query to determine if a table exists.
*
* @return string
*/
public function compileTableExists()
{
return "select * from sysobjects where type = 'U' and name = ?";
}
/**
* Compile the query to determine the list of columns.
*
* @param string $table
* @return string
*/
public function compileColumnListing($table)
{
return "select col.name from sys.columns as col
join sys.objects as obj on col.object_id = obj.object_id
where obj.type = 'U' and obj.name = '$table'";
}
/**
* Compile a create table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileCreate(Blueprint $blueprint, Fluent $command)
{
$columns = implode(', ', $this->getColumns($blueprint));
return 'create table '.$this->wrapTable($blueprint)." ($columns)";
}
/**
* Compile a column addition table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileAdd(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'alter table %s add %s',
$this->wrapTable($blueprint),
implode(', ', $this->getColumns($blueprint))
);
}
/**
* Compile a primary key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compilePrimary(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'alter table %s add constraint %s primary key (%s)',
$this->wrapTable($blueprint),
$this->wrap($command->index),
$this->columnize($command->columns)
);
}
/**
* Compile a unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileUnique(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'create unique index %s on %s (%s)',
$this->wrap($command->index),
$this->wrapTable($blueprint),
$this->columnize($command->columns)
);
}
/**
* Compile a plain index key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileIndex(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'create index %s on %s (%s)',
$this->wrap($command->index),
$this->wrapTable($blueprint),
$this->columnize($command->columns)
);
}
/**
* Compile a spatial index key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'create spatial index %s on %s (%s)',
$this->wrap($command->index),
$this->wrapTable($blueprint),
$this->columnize($command->columns)
);
}
/**
* Compile a drop table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDrop(Blueprint $blueprint, Fluent $command)
{
return 'drop table '.$this->wrapTable($blueprint);
}
/**
* Compile a drop table (if exists) command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
{
return sprintf(
'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = %s) drop table %s',
"'".str_replace("'", "''", $this->getTablePrefix().$blueprint->getTable())."'",
$this->wrapTable($blueprint)
);
}
/**
* Compile the SQL needed to drop all tables.
*
* @return string
*/
public function compileDropAllTables()
{
return "EXEC sp_msforeachtable 'DROP TABLE ?'";
}
/**
* Compile a drop column command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
{
$columns = $this->wrapArray($command->columns);
return 'alter table '.$this->wrapTable($blueprint).' drop column '.implode(', ', $columns);
}
/**
* Compile a drop primary key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
{
$index = $this->wrap($command->index);
return "alter table {$this->wrapTable($blueprint)} drop constraint {$index}";
}
/**
* Compile a drop unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
{
$index = $this->wrap($command->index);
return "drop index {$index} on {$this->wrapTable($blueprint)}";
}
/**
* Compile a drop index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
{
$index = $this->wrap($command->index);
return "drop index {$index} on {$this->wrapTable($blueprint)}";
}
/**
* Compile a drop spatial index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
{
return $this->compileDropIndex($blueprint, $command);
}
/**
* Compile a drop foreign key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
{
$index = $this->wrap($command->index);
return "alter table {$this->wrapTable($blueprint)} drop constraint {$index}";
}
/**
* Compile a rename table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileRename(Blueprint $blueprint, Fluent $command)
{
$from = $this->wrapTable($blueprint);
return "sp_rename {$from}, ".$this->wrapTable($command->to);
}
/**
* Compile a rename index command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
{
return sprintf(
"sp_rename N'%s', %s, N'INDEX'",
$this->wrap($blueprint->getTable().'.'.$command->from),
$this->wrap($command->to)
);
}
/**
* Compile the command to enable foreign key constraints.
*
* @return string
*/
public function compileEnableForeignKeyConstraints()
{
return 'EXEC sp_msforeachtable @command1="print \'?\'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all";';
}
/**
* Compile the command to disable foreign key constraints.
*
* @return string
*/
public function compileDisableForeignKeyConstraints()
{
return 'EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";';
}
/**
* Create the column definition for a spatial Geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometry(Fluent $column)
{
return 'geography';
}
/**
* Create the column definition for a spatial Point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePoint(Fluent $column)
{
return 'geography';
}
/**
* Create the column definition for a spatial LineString type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeLineString(Fluent $column)
{
return 'geography';
}
/**
* Create the column definition for a spatial Polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePolygon(Fluent $column)
{
return 'geography';
}
/**
* Create the column definition for a spatial GeometryCollection type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometryCollection(Fluent $column)
{
return 'geography';
}
/**
* Create the column definition for a spatial MultiPoint type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultiPoint(Fluent $column)
{
return 'geography';
}
/**
* Create the column definition for a spatial MultiLineString type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultiLineString(Fluent $column)
{
return 'geography';
}
/**
* Create the column definition for a spatial MultiPolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultiPolygon(Fluent $column)
{
return 'geography';
}
/**
* Wrap a table in keyword identifiers.
*
* @param \Illuminate\Database\Query\Expression|string $table
* @return string
*/
public function wrapTable($table)
{
if ($table instanceof Blueprint && $table->temporary) {
$this->setTablePrefix('#');
}
return parent::wrapTable($table);
}
/**
* Create the column definition for a char type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeChar(Fluent $column)
{
return "nchar({$column->length})";
}
/**
* Create the column definition for a string type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeString(Fluent $column)
{
return "nvarchar({$column->length})";
}
/**
* Create the column definition for a text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeText(Fluent $column)
{
return 'nvarchar(max)';
}
/**
* Create the column definition for a medium text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMediumText(Fluent $column)
{
return 'nvarchar(max)';
}
/**
* Create the column definition for a long text type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeLongText(Fluent $column)
{
return 'nvarchar(max)';
}
/**
* Create the column definition for an integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeInteger(Fluent $column)
{
return 'int';
}
/**
* Create the column definition for a big integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeBigInteger(Fluent $column)
{
return 'bigint';
}
/**
* Create the column definition for a medium integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMediumInteger(Fluent $column)
{
return 'int';
}
/**
* Create the column definition for a tiny integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTinyInteger(Fluent $column)
{
return 'tinyint';
}
/**
* Create the column definition for a small integer type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeSmallInteger(Fluent $column)
{
return 'smallint';
}
/**
* Create the column definition for a float type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeFloat(Fluent $column)
{
return 'float';
}
/**
* Create the column definition for a double type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDouble(Fluent $column)
{
return 'float';
}
/**
* Create the column definition for a decimal type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDecimal(Fluent $column)
{
return "decimal({$column->total}, {$column->places})";
}
/**
* Create the column definition for a boolean type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeBoolean(Fluent $column)
{
return 'bit';
}
/**
* Create the column definition for an enumeration type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeEnum(Fluent $column)
{
return sprintf(
'nvarchar(255) check ("%s" in (%s))',
$column->name,
$this->quoteString($column->allowed)
);
}
/**
* Create the column definition for a json type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeJson(Fluent $column)
{
return 'nvarchar(max)';
}
/**
* Create the column definition for a jsonb type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeJsonb(Fluent $column)
{
return 'nvarchar(max)';
}
/**
* Create the column definition for a date type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDate(Fluent $column)
{
return 'date';
}
/**
* Create the column definition for a date-time type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDateTime(Fluent $column)
{
return $this->typeTimestamp($column);
}
/**
* Create the column definition for a date-time (with time zone) type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeDateTimeTz(Fluent $column)
{
return $this->typeTimestampTz($column);
}
/**
* Create the column definition for a time type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTime(Fluent $column)
{
return $column->precision ? "time($column->precision)" : 'time';
}
/**
* Create the column definition for a time (with time zone) type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTimeTz(Fluent $column)
{
return $this->typeTime($column);
}
/**
* Create the column definition for a timestamp type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTimestamp(Fluent $column)
{
$columnType = $column->precision ? "datetime2($column->precision)" : 'datetime';
return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
}
/**
* Create the column definition for a timestamp (with time zone) type.
*
* @link https://msdn.microsoft.com/en-us/library/bb630289(v=sql.120).aspx
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeTimestampTz(Fluent $column)
{
$columnType = $column->precision ? "datetimeoffset($column->precision)" : 'datetimeoffset';
return $column->useCurrent ? "$columnType default CURRENT_TIMESTAMP" : $columnType;
}
/**
* Create the column definition for a year type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeYear(Fluent $column)
{
return $this->typeInteger($column);
}
/**
* Create the column definition for a binary type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeBinary(Fluent $column)
{
return 'varbinary(max)';
}
/**
* Create the column definition for a uuid type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeUuid(Fluent $column)
{
return 'uniqueidentifier';
}
/**
* Create the column definition for an IP address type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeIpAddress(Fluent $column)
{
return 'nvarchar(45)';
}
/**
* Create the column definition for a MAC address type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMacAddress(Fluent $column)
{
return 'nvarchar(17)';
}
/**
* Get the SQL for a collation column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyCollate(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->collation)) {
return ' collate '.$column->collation;
}
}
/**
* Get the SQL for a nullable column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
{
return $column->nullable ? ' null' : ' not null';
}
/**
* Get the SQL for a default column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->default)) {
return ' default '.$this->getDefaultValue($column->default);
}
}
/**
* Get the SQL for an auto-increment column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
{
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
return ' identity primary key';
}
}
}

View File

@ -1,152 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Schema;
class PostgresBuilder extends Builder
{
/**
* Determine if the given table exists.
*
* @param string $table
* @return bool
*/
public function hasTable($table)
{
[$schema, $table] = $this->parseSchemaAndTable($table);
$table = $this->connection->getTablePrefix().$table;
return count($this->connection->select(
$this->grammar->compileTableExists(),
[$schema, $table]
)) > 0;
}
/**
* Drop all tables from the database.
*
* @return void
*/
public function dropAllTables()
{
$tables = [];
$excludedTables = ['spatial_ref_sys'];
foreach ($this->getAllTables() as $row) {
$row = (array) $row;
$table = reset($row);
if (! in_array($table, $excludedTables)) {
$tables[] = $table;
}
}
if (empty($tables)) {
return;
}
$this->connection->statement(
$this->grammar->compileDropAllTables($tables)
);
}
/**
* Drop all views from the database.
*
* @return void
*/
public function dropAllViews()
{
$views = [];
foreach ($this->getAllViews() as $row) {
$row = (array) $row;
$views[] = reset($row);
}
if (empty($views)) {
return;
}
$this->connection->statement(
$this->grammar->compileDropAllViews($views)
);
}
/**
* Get the column listing for a given table.
*
* @param string $table
* @return array
*/
public function getColumnListing($table)
{
[$schema, $table] = $this->parseSchemaAndTable($table);
$table = $this->connection->getTablePrefix().$table;
$results = $this->connection->select(
$this->grammar->compileColumnListing(),
[$schema, $table]
);
return $this->connection->getPostProcessor()->processColumnListing($results);
}
/**
* Get all of the table names for the database.
*
* @return array
*/
protected function getAllTables()
{
return $this->connection->select(
$this->grammar->compileGetAllTables($this->connection->getConfig('schema'))
);
}
/**
* Get all of the view names for the database.
*
* @return array
*/
protected function getAllViews()
{
return $this->connection->select(
$this->grammar->compileGetAllViews($this->connection->getConfig('schema'))
);
}
/**
* Parse the table name and extract the schema and table.
*
* @param string $table
* @return array
*/
protected function parseSchemaAndTable($table)
{
$table = explode('.', $table);
if (is_array($schema = $this->connection->getConfig('schema'))) {
if (in_array($table[0], $schema)) {
return [array_shift($table), implode('.', $table)];
}
$schema = head($schema);
}
return [$schema ?: 'public', implode('.', $table)];
}
}

View File

@ -1,61 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Schema;
class SQLiteBuilder extends Builder
{
/**
* Drop all tables from the database.
*
* @return void
*/
public function dropAllTables()
{
if ($this->connection->getDatabaseName() !== ':memory:') {
return $this->refreshDatabaseFile();
}
$this->connection->select($this->grammar->compileEnableWriteableSchema());
$this->connection->select($this->grammar->compileDropAllTables());
$this->connection->select($this->grammar->compileDisableWriteableSchema());
$this->connection->select($this->grammar->compileRebuild());
}
/**
* Drop all views from the database.
*
* @return void
*/
public function dropAllViews()
{
$this->connection->select($this->grammar->compileEnableWriteableSchema());
$this->connection->select($this->grammar->compileDropAllViews());
$this->connection->select($this->grammar->compileDisableWriteableSchema());
$this->connection->select($this->grammar->compileRebuild());
}
/**
* Empty the database file.
*
* @return void
*/
public function refreshDatabaseFile()
{
file_put_contents($this->connection->getDatabaseName(), '');
}
}

View File

@ -1,29 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://hyperf.org
* @document https://wiki.hyperf.org
* @contact group@hyperf.org
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Illuminate\Database\Schema;
class SqlServerBuilder extends Builder
{
/**
* Drop all tables from the database.
*
* @return void
*/
public function dropAllTables()
{
$this->disableForeignKeyConstraints();
$this->connection->statement($this->grammar->compileDropAllTables());
$this->enableForeignKeyConstraints();
}
}

View File

@ -134,10 +134,8 @@ class Fluent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
/**
* Convert the fluent instance to an array.
*
* @return array
*/
public function toArray()
public function toArray(): array
{
return $this->attributes;
}

View File

@ -0,0 +1,46 @@
<?php
namespace Hyperf\Utils\Traits;
use BadMethodCallException;
use Error;
use function get_class;
trait ForwardsCalls
{
/**
* Forward a method call to the given object.
*
* @param mixed $object
* @return mixed
* @throws Error
*/
protected function forwardCallTo($object, string $method, array $parameters)
{
try {
return $object->{$method}(...$parameters);
} catch (Error | BadMethodCallException $e) {
$pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[^\(]+)\(\)$~';
if (! preg_match($pattern, $e->getMessage(), $matches)) {
throw $e;
}
if ($matches['class'] !== get_class($object) || $matches['method'] !== $method) {
throw $e;
}
static::throwBadMethodCallException($method);
}
}
/**
* Throw a bad method call exception for the given method.
* @throws BadMethodCallException
*/
protected static function throwBadMethodCallException(string $method): void
{
throw new BadMethodCallException(sprintf('Call to undefined method %s::%s()', static::class, $method));
}
}