repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
spiral/database | src/DatabaseManager.php | DatabaseManager.addDatabase | public function addDatabase(Database $database)
{
if (isset($this->databases[$database->getName()])) {
throw new DBALException("Database '{$database->getName()}' already exists");
}
$this->databases[$database->getName()] = $database;
} | php | public function addDatabase(Database $database)
{
if (isset($this->databases[$database->getName()])) {
throw new DBALException("Database '{$database->getName()}' already exists");
}
$this->databases[$database->getName()] = $database;
} | [
"public",
"function",
"addDatabase",
"(",
"Database",
"$",
"database",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"databases",
"[",
"$",
"database",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"throw",
"new",
"DBALException",
"(",
"\"Data... | Add new database.
@param Database $database
@throws DBALException | [
"Add",
"new",
"database",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/DatabaseManager.php#L175-L182 | train |
spiral/database | src/DatabaseManager.php | DatabaseManager.driver | public function driver(string $driver): DriverInterface
{
if (isset($this->drivers[$driver])) {
return $this->drivers[$driver];
}
try {
return $this->drivers[$driver] = $this->config->getDriver($driver)->resolve($this->factory);
} catch (ContainerExceptionInterface $e) {
throw new DBALException($e->getMessage(), $e->getCode(), $e);
}
} | php | public function driver(string $driver): DriverInterface
{
if (isset($this->drivers[$driver])) {
return $this->drivers[$driver];
}
try {
return $this->drivers[$driver] = $this->config->getDriver($driver)->resolve($this->factory);
} catch (ContainerExceptionInterface $e) {
throw new DBALException($e->getMessage(), $e->getCode(), $e);
}
} | [
"public",
"function",
"driver",
"(",
"string",
"$",
"driver",
")",
":",
"DriverInterface",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"drivers",
"[",
"$",
"driver",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"drivers",
"[",
"$",
"driver",... | Get driver instance by it's name or automatically create one.
@param string $driver
@return DriverInterface
@throws DBALException | [
"Get",
"driver",
"instance",
"by",
"it",
"s",
"name",
"or",
"automatically",
"create",
"one",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/DatabaseManager.php#L211-L221 | train |
spiral/database | src/DatabaseManager.php | DatabaseManager.addDriver | public function addDriver(string $name, DriverInterface $driver): DatabaseManager
{
if (isset($this->drivers[$name])) {
throw new DBALException("Connection '{$name}' already exists");
}
$this->drivers[$name] = $driver;
return $this;
} | php | public function addDriver(string $name, DriverInterface $driver): DatabaseManager
{
if (isset($this->drivers[$name])) {
throw new DBALException("Connection '{$name}' already exists");
}
$this->drivers[$name] = $driver;
return $this;
} | [
"public",
"function",
"addDriver",
"(",
"string",
"$",
"name",
",",
"DriverInterface",
"$",
"driver",
")",
":",
"DatabaseManager",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"drivers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"DBALEx... | Manually set connection instance.
@param string $name
@param DriverInterface $driver
@return self
@throws DBALException | [
"Manually",
"set",
"connection",
"instance",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/DatabaseManager.php#L232-L241 | train |
spiral/database | src/Driver/Traits/BuilderTrait.php | BuilderTrait.insertQuery | public function insertQuery(string $prefix, string $table = null): InsertQuery
{
return new InsertQuery($this, $this->getCompiler($prefix), $table);
} | php | public function insertQuery(string $prefix, string $table = null): InsertQuery
{
return new InsertQuery($this, $this->getCompiler($prefix), $table);
} | [
"public",
"function",
"insertQuery",
"(",
"string",
"$",
"prefix",
",",
"string",
"$",
"table",
"=",
"null",
")",
":",
"InsertQuery",
"{",
"return",
"new",
"InsertQuery",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"getCompiler",
"(",
"$",
"prefix",
")",
... | Get InsertQuery builder with driver specific query compiler.
@param string $prefix Database specific table prefix, used to quote table names and
build aliases.
@param string|null $table
@return InsertQuery | [
"Get",
"InsertQuery",
"builder",
"with",
"driver",
"specific",
"query",
"compiler",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Traits/BuilderTrait.php#L32-L35 | train |
spiral/database | src/Driver/Traits/BuilderTrait.php | BuilderTrait.selectQuery | public function selectQuery(string $prefix, array $from = [], array $columns = []): SelectQuery
{
return new SelectQuery($this, $this->getCompiler($prefix), $from, $columns);
} | php | public function selectQuery(string $prefix, array $from = [], array $columns = []): SelectQuery
{
return new SelectQuery($this, $this->getCompiler($prefix), $from, $columns);
} | [
"public",
"function",
"selectQuery",
"(",
"string",
"$",
"prefix",
",",
"array",
"$",
"from",
"=",
"[",
"]",
",",
"array",
"$",
"columns",
"=",
"[",
"]",
")",
":",
"SelectQuery",
"{",
"return",
"new",
"SelectQuery",
"(",
"$",
"this",
",",
"$",
"this"... | Get SelectQuery builder with driver specific query compiler.
@param string $prefix Database specific table prefix, used to quote table names and build
aliases.
@param array $from
@param array $columns
@return SelectQuery | [
"Get",
"SelectQuery",
"builder",
"with",
"driver",
"specific",
"query",
"compiler",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Traits/BuilderTrait.php#L46-L49 | train |
spiral/database | src/Driver/Traits/BuilderTrait.php | BuilderTrait.updateQuery | public function updateQuery(
string $prefix,
string $table = null,
array $where = [],
array $values = []
): UpdateQuery {
return new UpdateQuery($this, $this->getCompiler($prefix), $table, $where, $values);
} | php | public function updateQuery(
string $prefix,
string $table = null,
array $where = [],
array $values = []
): UpdateQuery {
return new UpdateQuery($this, $this->getCompiler($prefix), $table, $where, $values);
} | [
"public",
"function",
"updateQuery",
"(",
"string",
"$",
"prefix",
",",
"string",
"$",
"table",
"=",
"null",
",",
"array",
"$",
"where",
"=",
"[",
"]",
",",
"array",
"$",
"values",
"=",
"[",
"]",
")",
":",
"UpdateQuery",
"{",
"return",
"new",
"Update... | Get UpdateQuery builder with driver specific query compiler.
@param string $prefix Database specific table prefix, used to quote table names and
build aliases.
@param string|null $table
@param array $where
@param array $values
@return UpdateQuery | [
"Get",
"UpdateQuery",
"builder",
"with",
"driver",
"specific",
"query",
"compiler",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Traits/BuilderTrait.php#L73-L80 | train |
spiral/database | src/Query/Traits/TokenTrait.php | TokenTrait.createToken | protected function createToken($joiner, array $parameters, &$tokens, callable $wrapper)
{
list($identifier, $valueA, $valueB, $valueC) = $parameters + array_fill(0, 5, null);
if (empty($identifier)) {
//Nothing to do
return;
}
//Where conditions specified in array form
if (is_array($identifier)) {
if (count($identifier) == 1) {
$this->arrayWhere(
$joiner == 'AND' ? Compiler::TOKEN_AND : Compiler::TOKEN_OR,
$identifier,
$tokens,
$wrapper
);
return;
}
$tokens[] = [$joiner, '('];
$this->arrayWhere(Compiler::TOKEN_AND, $identifier, $tokens, $wrapper);
$tokens[] = ['', ')'];
return;
}
if ($identifier instanceof \Closure) {
$tokens[] = [$joiner, '('];
call_user_func($identifier, $this, $joiner, $wrapper);
$tokens[] = ['', ')'];
return;
}
if ($identifier instanceof BuilderInterface) {
//Will copy every parameter from QueryBuilder
$wrapper($identifier);
}
switch (count($parameters)) {
case 1:
//AND|OR [identifier: sub-query]
$tokens[] = [$joiner, $identifier];
break;
case 2:
//AND|OR [identifier] = [valueA]
$tokens[] = [$joiner, [$identifier, '=', $wrapper($valueA)]];
break;
case 3:
if (is_string($valueA)) {
$valueA = strtoupper($valueA);
if (in_array($valueA, ['BETWEEN', 'NOT BETWEEN'])) {
throw new BuilderException('Between statements expects exactly 2 values');
}
}
//AND|OR [identifier] [valueA: OPERATION] [valueA]
$tokens[] = [$joiner, [$identifier, strval($valueA), $wrapper($valueB)]];
break;
case 4:
//BETWEEN or NOT BETWEEN
if (!is_string($valueA) || !in_array(strtoupper($valueA), ['BETWEEN', 'NOT BETWEEN'])) {
throw new BuilderException(
'Only "BETWEEN" or "NOT BETWEEN" can define second comparision value'
);
}
//AND|OR [identifier] [valueA: BETWEEN|NOT BETWEEN] [valueB] [valueC]
$tokens[] = [$joiner, [$identifier, strtoupper($valueA), $wrapper($valueB), $wrapper($valueC)]];
}
} | php | protected function createToken($joiner, array $parameters, &$tokens, callable $wrapper)
{
list($identifier, $valueA, $valueB, $valueC) = $parameters + array_fill(0, 5, null);
if (empty($identifier)) {
//Nothing to do
return;
}
//Where conditions specified in array form
if (is_array($identifier)) {
if (count($identifier) == 1) {
$this->arrayWhere(
$joiner == 'AND' ? Compiler::TOKEN_AND : Compiler::TOKEN_OR,
$identifier,
$tokens,
$wrapper
);
return;
}
$tokens[] = [$joiner, '('];
$this->arrayWhere(Compiler::TOKEN_AND, $identifier, $tokens, $wrapper);
$tokens[] = ['', ')'];
return;
}
if ($identifier instanceof \Closure) {
$tokens[] = [$joiner, '('];
call_user_func($identifier, $this, $joiner, $wrapper);
$tokens[] = ['', ')'];
return;
}
if ($identifier instanceof BuilderInterface) {
//Will copy every parameter from QueryBuilder
$wrapper($identifier);
}
switch (count($parameters)) {
case 1:
//AND|OR [identifier: sub-query]
$tokens[] = [$joiner, $identifier];
break;
case 2:
//AND|OR [identifier] = [valueA]
$tokens[] = [$joiner, [$identifier, '=', $wrapper($valueA)]];
break;
case 3:
if (is_string($valueA)) {
$valueA = strtoupper($valueA);
if (in_array($valueA, ['BETWEEN', 'NOT BETWEEN'])) {
throw new BuilderException('Between statements expects exactly 2 values');
}
}
//AND|OR [identifier] [valueA: OPERATION] [valueA]
$tokens[] = [$joiner, [$identifier, strval($valueA), $wrapper($valueB)]];
break;
case 4:
//BETWEEN or NOT BETWEEN
if (!is_string($valueA) || !in_array(strtoupper($valueA), ['BETWEEN', 'NOT BETWEEN'])) {
throw new BuilderException(
'Only "BETWEEN" or "NOT BETWEEN" can define second comparision value'
);
}
//AND|OR [identifier] [valueA: BETWEEN|NOT BETWEEN] [valueB] [valueC]
$tokens[] = [$joiner, [$identifier, strtoupper($valueA), $wrapper($valueB), $wrapper($valueC)]];
}
} | [
"protected",
"function",
"createToken",
"(",
"$",
"joiner",
",",
"array",
"$",
"parameters",
",",
"&",
"$",
"tokens",
",",
"callable",
"$",
"wrapper",
")",
"{",
"list",
"(",
"$",
"identifier",
",",
"$",
"valueA",
",",
"$",
"valueB",
",",
"$",
"valueC",... | Convert various amount of where function arguments into valid where token.
@param string $joiner Boolean joiner (AND | OR).
@param array $parameters Set of parameters collected from where functions.
@param array $tokens Array to aggregate compiled tokens. Reference.
@param callable $wrapper Callback or closure used to wrap/collect every potential
parameter.
@throws BuilderException
@see AbstractWhere | [
"Convert",
"various",
"amount",
"of",
"where",
"function",
"arguments",
"into",
"valid",
"where",
"token",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/TokenTrait.php#L31-L104 | train |
spiral/database | src/Query/Traits/TokenTrait.php | TokenTrait.arrayWhere | private function arrayWhere(string $grouper, array $where, &$tokens, callable $wrapper)
{
$joiner = ($grouper == Compiler::TOKEN_AND ? 'AND' : 'OR');
foreach ($where as $key => $value) {
$token = strtoupper($key);
//Grouping identifier (@OR, @AND), MongoDB like style
if ($token == Compiler::TOKEN_AND || $token == Compiler::TOKEN_OR) {
$tokens[] = [$joiner, '('];
foreach ($value as $nested) {
if (count($nested) == 1) {
$this->arrayWhere($token, $nested, $tokens, $wrapper);
continue;
}
$tokens[] = [$token == Compiler::TOKEN_AND ? 'AND' : 'OR', '('];
$this->arrayWhere(Compiler::TOKEN_AND, $nested, $tokens, $wrapper);
$tokens[] = ['', ')'];
}
$tokens[] = ['', ')'];
continue;
}
//AND|OR [name] = [value]
if (!is_array($value)) {
$tokens[] = [$joiner, [$key, '=', $wrapper($value)]];
continue;
}
if (count($value) > 1) {
//Multiple values to be joined by AND condition (x = 1, x != 5)
$tokens[] = [$joiner, '('];
$this->builtConditions('AND', $key, $value, $tokens, $wrapper);
$tokens[] = ['', ')'];
} else {
$this->builtConditions($joiner, $key, $value, $tokens, $wrapper);
}
}
return;
} | php | private function arrayWhere(string $grouper, array $where, &$tokens, callable $wrapper)
{
$joiner = ($grouper == Compiler::TOKEN_AND ? 'AND' : 'OR');
foreach ($where as $key => $value) {
$token = strtoupper($key);
//Grouping identifier (@OR, @AND), MongoDB like style
if ($token == Compiler::TOKEN_AND || $token == Compiler::TOKEN_OR) {
$tokens[] = [$joiner, '('];
foreach ($value as $nested) {
if (count($nested) == 1) {
$this->arrayWhere($token, $nested, $tokens, $wrapper);
continue;
}
$tokens[] = [$token == Compiler::TOKEN_AND ? 'AND' : 'OR', '('];
$this->arrayWhere(Compiler::TOKEN_AND, $nested, $tokens, $wrapper);
$tokens[] = ['', ')'];
}
$tokens[] = ['', ')'];
continue;
}
//AND|OR [name] = [value]
if (!is_array($value)) {
$tokens[] = [$joiner, [$key, '=', $wrapper($value)]];
continue;
}
if (count($value) > 1) {
//Multiple values to be joined by AND condition (x = 1, x != 5)
$tokens[] = [$joiner, '('];
$this->builtConditions('AND', $key, $value, $tokens, $wrapper);
$tokens[] = ['', ')'];
} else {
$this->builtConditions($joiner, $key, $value, $tokens, $wrapper);
}
}
return;
} | [
"private",
"function",
"arrayWhere",
"(",
"string",
"$",
"grouper",
",",
"array",
"$",
"where",
",",
"&",
"$",
"tokens",
",",
"callable",
"$",
"wrapper",
")",
"{",
"$",
"joiner",
"=",
"(",
"$",
"grouper",
"==",
"Compiler",
"::",
"TOKEN_AND",
"?",
"'AND... | Convert simplified where definition into valid set of where tokens.
@param string $grouper Grouper type (see self::TOKEN_AND, self::TOKEN_OR).
@param array $where Simplified where definition.
@param array $tokens Array to aggregate compiled tokens. Reference.
@param callable $wrapper Callback or closure used to wrap/collect every potential
parameter.
@throws BuilderException
@see AbstractWhere | [
"Convert",
"simplified",
"where",
"definition",
"into",
"valid",
"set",
"of",
"where",
"tokens",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/TokenTrait.php#L119-L163 | train |
spiral/database | src/Query/Traits/TokenTrait.php | TokenTrait.builtConditions | private function builtConditions(
string $innerJoiner,
string $key,
$where,
&$tokens,
callable $wrapper
) {
foreach ($where as $operation => $value) {
if (is_numeric($operation)) {
throw new BuilderException('Nested conditions should have defined operator');
}
$operation = strtoupper($operation);
if (!in_array($operation, ['BETWEEN', 'NOT BETWEEN'])) {
//AND|OR [name] [OPERATION] [nestedValue]
$tokens[] = [$innerJoiner, [$key, $operation, $wrapper($value)]];
continue;
}
/*
* Between and not between condition described using array of [left, right] syntax.
*/
if (!is_array($value) || count($value) != 2) {
throw new BuilderException(
'Exactly 2 array values are required for between statement'
);
}
$tokens[] = [
//AND|OR [name] [BETWEEN|NOT BETWEEN] [value 1] [value 2]
$innerJoiner,
[$key, $operation, $wrapper($value[0]), $wrapper($value[1])],
];
}
return $tokens;
} | php | private function builtConditions(
string $innerJoiner,
string $key,
$where,
&$tokens,
callable $wrapper
) {
foreach ($where as $operation => $value) {
if (is_numeric($operation)) {
throw new BuilderException('Nested conditions should have defined operator');
}
$operation = strtoupper($operation);
if (!in_array($operation, ['BETWEEN', 'NOT BETWEEN'])) {
//AND|OR [name] [OPERATION] [nestedValue]
$tokens[] = [$innerJoiner, [$key, $operation, $wrapper($value)]];
continue;
}
/*
* Between and not between condition described using array of [left, right] syntax.
*/
if (!is_array($value) || count($value) != 2) {
throw new BuilderException(
'Exactly 2 array values are required for between statement'
);
}
$tokens[] = [
//AND|OR [name] [BETWEEN|NOT BETWEEN] [value 1] [value 2]
$innerJoiner,
[$key, $operation, $wrapper($value[0]), $wrapper($value[1])],
];
}
return $tokens;
} | [
"private",
"function",
"builtConditions",
"(",
"string",
"$",
"innerJoiner",
",",
"string",
"$",
"key",
",",
"$",
"where",
",",
"&",
"$",
"tokens",
",",
"callable",
"$",
"wrapper",
")",
"{",
"foreach",
"(",
"$",
"where",
"as",
"$",
"operation",
"=>",
"... | Build set of conditions for specified identifier.
@param string $innerJoiner Inner boolean joiner.
@param string $key Column identifier.
@param array $where Operations associated with identifier.
@param array $tokens Array to aggregate compiled tokens. Reference.
@param callable $wrapper Callback or closure used to wrap/collect every potential
parameter.
@return array
@throws BuilderException | [
"Build",
"set",
"of",
"conditions",
"for",
"specified",
"identifier",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/TokenTrait.php#L179-L216 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileInsert | public function compileInsert(string $table, array $columns, array $rowsets): string
{
if (empty($columns)) {
throw new CompilerException(
'Unable to build insert statement, columns must be set'
);
}
if (empty($rowsets)) {
throw new CompilerException(
'Unable to build insert statement, at least one value set must be provided'
);
}
//To add needed prefixes (if any)
$table = $this->quote($table, true);
//Compiling list of columns
$columns = $this->prepareColumns($columns);
//Simply joining every rowset
$rowsets = implode(",\n", $rowsets);
return "INSERT INTO {$table} ({$columns})\nVALUES {$rowsets}";
} | php | public function compileInsert(string $table, array $columns, array $rowsets): string
{
if (empty($columns)) {
throw new CompilerException(
'Unable to build insert statement, columns must be set'
);
}
if (empty($rowsets)) {
throw new CompilerException(
'Unable to build insert statement, at least one value set must be provided'
);
}
//To add needed prefixes (if any)
$table = $this->quote($table, true);
//Compiling list of columns
$columns = $this->prepareColumns($columns);
//Simply joining every rowset
$rowsets = implode(",\n", $rowsets);
return "INSERT INTO {$table} ({$columns})\nVALUES {$rowsets}";
} | [
"public",
"function",
"compileInsert",
"(",
"string",
"$",
"table",
",",
"array",
"$",
"columns",
",",
"array",
"$",
"rowsets",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"columns",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"... | Create insert query using table names, columns and rowsets. Must support both - single and
batch inserts.
@param string $table
@param array $columns
@param FragmentInterface[] $rowsets Every rowset has to be convertable into string. Raw data
not allowed!
@return string
@throws CompilerException | [
"Create",
"insert",
"query",
"using",
"table",
"names",
"columns",
"and",
"rowsets",
".",
"Must",
"support",
"both",
"-",
"single",
"and",
"batch",
"inserts",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L102-L126 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileUpdate | public function compileUpdate(string $table, array $updates, array $whereTokens = []): string
{
$table = $this->quote($table, true);
//Preparing update column statement
$updates = $this->prepareUpdates($updates);
//Where statement is optional for update queries
$whereStatement = $this->optional("\nWHERE", $this->compileWhere($whereTokens));
return rtrim("UPDATE {$table}\nSET {$updates} {$whereStatement}");
} | php | public function compileUpdate(string $table, array $updates, array $whereTokens = []): string
{
$table = $this->quote($table, true);
//Preparing update column statement
$updates = $this->prepareUpdates($updates);
//Where statement is optional for update queries
$whereStatement = $this->optional("\nWHERE", $this->compileWhere($whereTokens));
return rtrim("UPDATE {$table}\nSET {$updates} {$whereStatement}");
} | [
"public",
"function",
"compileUpdate",
"(",
"string",
"$",
"table",
",",
"array",
"$",
"updates",
",",
"array",
"$",
"whereTokens",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"table",
",",
"true",... | Create update statement.
@param string $table
@param array $updates
@param array $whereTokens
@return string
@throws CompilerException | [
"Create",
"update",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L139-L150 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileDelete | public function compileDelete(string $table, array $whereTokens = []): string
{
$table = $this->quote($table, true);
//Where statement is optional for delete query (which is weird)
$whereStatement = $this->optional("\nWHERE", $this->compileWhere($whereTokens));
return rtrim("DELETE FROM {$table} {$whereStatement}");
} | php | public function compileDelete(string $table, array $whereTokens = []): string
{
$table = $this->quote($table, true);
//Where statement is optional for delete query (which is weird)
$whereStatement = $this->optional("\nWHERE", $this->compileWhere($whereTokens));
return rtrim("DELETE FROM {$table} {$whereStatement}");
} | [
"public",
"function",
"compileDelete",
"(",
"string",
"$",
"table",
",",
"array",
"$",
"whereTokens",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"table",
",",
"true",
")",
";",
"//Where statement is... | Create delete statement.
@param string $table
@param array $whereTokens
@return string
@throws CompilerException | [
"Create",
"delete",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L162-L170 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileSelect | public function compileSelect(
array $fromTables,
$distinct,
array $columns,
array $joinTokens = [],
array $whereTokens = [],
array $havingTokens = [],
array $grouping = [],
array $ordering = [],
int $limit = 0,
int $offset = 0,
array $unionTokens = []
): string {
//This statement parts should be processed first to define set of table and column aliases
$fromTables = $this->compileTables($fromTables);
$joinsStatement = $this->optional(' ', $this->compileJoins($joinTokens), ' ');
//Distinct flag (if any)
$distinct = $this->optional(' ', $this->compileDistinct($distinct));
//Columns are compiled after table names and joins to ensure aliases and prefixes
$columns = $this->prepareColumns($columns);
//A lot of constrain and other statements
$whereStatement = $this->optional("\nWHERE", $this->compileWhere($whereTokens));
$havingStatement = $this->optional("\nHAVING", $this->compileWhere($havingTokens));
$groupingStatement = $this->optional("\nGROUP BY", $this->compileGrouping($grouping), ' ');
//Union statement has new line at beginning of every union
$unionsStatement = $this->optional("\n", $this->compileUnions($unionTokens));
$orderingStatement = $this->optional("\nORDER BY", $this->compileOrdering($ordering));
$limingStatement = $this->optional("\n", $this->compileLimit($limit, $offset));
//Initial statement have predictable order
$statement = "SELECT{$distinct}\n{$columns}\nFROM {$fromTables}";
$statement .= "{$joinsStatement}{$whereStatement}{$groupingStatement}{$havingStatement}";
$statement .= "{$unionsStatement}{$orderingStatement}{$limingStatement}";
return rtrim($statement);
} | php | public function compileSelect(
array $fromTables,
$distinct,
array $columns,
array $joinTokens = [],
array $whereTokens = [],
array $havingTokens = [],
array $grouping = [],
array $ordering = [],
int $limit = 0,
int $offset = 0,
array $unionTokens = []
): string {
//This statement parts should be processed first to define set of table and column aliases
$fromTables = $this->compileTables($fromTables);
$joinsStatement = $this->optional(' ', $this->compileJoins($joinTokens), ' ');
//Distinct flag (if any)
$distinct = $this->optional(' ', $this->compileDistinct($distinct));
//Columns are compiled after table names and joins to ensure aliases and prefixes
$columns = $this->prepareColumns($columns);
//A lot of constrain and other statements
$whereStatement = $this->optional("\nWHERE", $this->compileWhere($whereTokens));
$havingStatement = $this->optional("\nHAVING", $this->compileWhere($havingTokens));
$groupingStatement = $this->optional("\nGROUP BY", $this->compileGrouping($grouping), ' ');
//Union statement has new line at beginning of every union
$unionsStatement = $this->optional("\n", $this->compileUnions($unionTokens));
$orderingStatement = $this->optional("\nORDER BY", $this->compileOrdering($ordering));
$limingStatement = $this->optional("\n", $this->compileLimit($limit, $offset));
//Initial statement have predictable order
$statement = "SELECT{$distinct}\n{$columns}\nFROM {$fromTables}";
$statement .= "{$joinsStatement}{$whereStatement}{$groupingStatement}{$havingStatement}";
$statement .= "{$unionsStatement}{$orderingStatement}{$limingStatement}";
return rtrim($statement);
} | [
"public",
"function",
"compileSelect",
"(",
"array",
"$",
"fromTables",
",",
"$",
"distinct",
",",
"array",
"$",
"columns",
",",
"array",
"$",
"joinTokens",
"=",
"[",
"]",
",",
"array",
"$",
"whereTokens",
"=",
"[",
"]",
",",
"array",
"$",
"havingTokens"... | Create select statement. Compiler must validly resolve table and column aliases used in
conditions and joins.
@param array $fromTables
@param bool|string $distinct String only for PostgresSQL.
@param array $columns
@param array $joinTokens
@param array $whereTokens
@param array $havingTokens
@param array $grouping
@param array $ordering
@param int $limit
@param int $offset
@param array $unionTokens
@return string
@throws CompilerException | [
"Create",
"select",
"statement",
".",
"Compiler",
"must",
"validly",
"resolve",
"table",
"and",
"column",
"aliases",
"used",
"in",
"conditions",
"and",
"joins",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L192-L233 | train |
spiral/database | src/Driver/Compiler.php | Compiler.prepareUpdates | protected function prepareUpdates(array $updates): string
{
foreach ($updates as $column => &$value) {
if ($value instanceof FragmentInterface) {
$value = $this->prepareFragment($value);
} else {
//Simple value (such condition should never be met since every value has to be
//wrapped using parameter interface)
$value = '?';
}
$value = "{$this->quote($column)} = {$value}";
unset($value);
}
return trim(implode(', ', $updates));
} | php | protected function prepareUpdates(array $updates): string
{
foreach ($updates as $column => &$value) {
if ($value instanceof FragmentInterface) {
$value = $this->prepareFragment($value);
} else {
//Simple value (such condition should never be met since every value has to be
//wrapped using parameter interface)
$value = '?';
}
$value = "{$this->quote($column)} = {$value}";
unset($value);
}
return trim(implode(', ', $updates));
} | [
"protected",
"function",
"prepareUpdates",
"(",
"array",
"$",
"updates",
")",
":",
"string",
"{",
"foreach",
"(",
"$",
"updates",
"as",
"$",
"column",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"FragmentInterface",
")",
"{"... | Prepare column values to be used in UPDATE statement.
@param array $updates
@return string | [
"Prepare",
"column",
"values",
"to",
"be",
"used",
"in",
"UPDATE",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L258-L274 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileTables | protected function compileTables(array $tables): string
{
foreach ($tables as &$table) {
$table = $this->quote($table, true);
unset($table);
}
return implode(', ', $tables);
} | php | protected function compileTables(array $tables): string
{
foreach ($tables as &$table) {
$table = $this->quote($table, true);
unset($table);
}
return implode(', ', $tables);
} | [
"protected",
"function",
"compileTables",
"(",
"array",
"$",
"tables",
")",
":",
"string",
"{",
"foreach",
"(",
"$",
"tables",
"as",
"&",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"table",
",",
"true",
")",
";... | Compile table names statement.
@param array $tables
@return string | [
"Compile",
"table",
"names",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L299-L307 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileJoins | protected function compileJoins(array $joinTokens): string
{
$statement = '';
foreach ($joinTokens as $join) {
$statement .= "\n{$join['type']} JOIN {$this->quote($join['outer'], true)}";
if (!empty($join['alias'])) {
$this->quoter->registerAlias($join['alias'], (string)$join['outer']);
$statement .= " AS " . $this->quote($join['alias']);
}
$statement .= $this->optional("\n ON", $this->compileWhere($join['on']));
}
return $statement;
} | php | protected function compileJoins(array $joinTokens): string
{
$statement = '';
foreach ($joinTokens as $join) {
$statement .= "\n{$join['type']} JOIN {$this->quote($join['outer'], true)}";
if (!empty($join['alias'])) {
$this->quoter->registerAlias($join['alias'], (string)$join['outer']);
$statement .= " AS " . $this->quote($join['alias']);
}
$statement .= $this->optional("\n ON", $this->compileWhere($join['on']));
}
return $statement;
} | [
"protected",
"function",
"compileJoins",
"(",
"array",
"$",
"joinTokens",
")",
":",
"string",
"{",
"$",
"statement",
"=",
"''",
";",
"foreach",
"(",
"$",
"joinTokens",
"as",
"$",
"join",
")",
"{",
"$",
"statement",
".=",
"\"\\n{$join['type']} JOIN {$this->quot... | Compiler joins statement.
@param array $joinTokens
@return string | [
"Compiler",
"joins",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L316-L331 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileUnions | protected function compileUnions(array $unionTokens): string
{
if (empty($unionTokens)) {
return '';
}
$statement = '';
foreach ($unionTokens as $union) {
if (!empty($union[0])) {
//First key is union type, second united query (no need to share compiler)
$statement .= "\nUNION {$union[0]}\n({$union[1]})";
} else {
//No extra space
$statement .= "\nUNION \n({$union[1]})";
}
}
return ltrim($statement, "\n");
} | php | protected function compileUnions(array $unionTokens): string
{
if (empty($unionTokens)) {
return '';
}
$statement = '';
foreach ($unionTokens as $union) {
if (!empty($union[0])) {
//First key is union type, second united query (no need to share compiler)
$statement .= "\nUNION {$union[0]}\n({$union[1]})";
} else {
//No extra space
$statement .= "\nUNION \n({$union[1]})";
}
}
return ltrim($statement, "\n");
} | [
"protected",
"function",
"compileUnions",
"(",
"array",
"$",
"unionTokens",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"unionTokens",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"statement",
"=",
"''",
";",
"foreach",
"(",
"$",
"unionToke... | Compile union statement chunk. Keywords UNION and ALL will be included, this methods will
automatically move every union on new line.
@param array $unionTokens
@return string | [
"Compile",
"union",
"statement",
"chunk",
".",
"Keywords",
"UNION",
"and",
"ALL",
"will",
"be",
"included",
"this",
"methods",
"will",
"automatically",
"move",
"every",
"union",
"on",
"new",
"line",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L341-L359 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileOrdering | protected function compileOrdering(array $ordering): string
{
$result = [];
foreach ($ordering as $order) {
$direction = strtoupper($order[1]);
if (!in_array($direction, ['ASC', 'DESC'])) {
throw new CompilerException("Invalid sorting direction, only ASC and DESC are allowed");
}
$result[] = $this->quote($order[0]) . ' ' . $direction;
}
return implode(', ', $result);
} | php | protected function compileOrdering(array $ordering): string
{
$result = [];
foreach ($ordering as $order) {
$direction = strtoupper($order[1]);
if (!in_array($direction, ['ASC', 'DESC'])) {
throw new CompilerException("Invalid sorting direction, only ASC and DESC are allowed");
}
$result[] = $this->quote($order[0]) . ' ' . $direction;
}
return implode(', ', $result);
} | [
"protected",
"function",
"compileOrdering",
"(",
"array",
"$",
"ordering",
")",
":",
"string",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"ordering",
"as",
"$",
"order",
")",
"{",
"$",
"direction",
"=",
"strtoupper",
"(",
"$",
"order"... | Compile ORDER BY statement.
@param array $ordering
@return string | [
"Compile",
"ORDER",
"BY",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L368-L382 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileGrouping | protected function compileGrouping(array $grouping): string
{
$statement = '';
foreach ($grouping as $identifier) {
$statement .= $this->quote($identifier);
}
return $statement;
} | php | protected function compileGrouping(array $grouping): string
{
$statement = '';
foreach ($grouping as $identifier) {
$statement .= $this->quote($identifier);
}
return $statement;
} | [
"protected",
"function",
"compileGrouping",
"(",
"array",
"$",
"grouping",
")",
":",
"string",
"{",
"$",
"statement",
"=",
"''",
";",
"foreach",
"(",
"$",
"grouping",
"as",
"$",
"identifier",
")",
"{",
"$",
"statement",
".=",
"$",
"this",
"->",
"quote",
... | Compiler GROUP BY statement.
@param array $grouping
@return string | [
"Compiler",
"GROUP",
"BY",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L391-L399 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileLimit | protected function compileLimit(int $limit, int $offset): string
{
if (empty($limit) && empty($offset)) {
return '';
}
$statement = '';
if (!empty($limit)) {
$statement = "LIMIT {$limit} ";
}
if (!empty($offset)) {
$statement .= "OFFSET {$offset}";
}
return trim($statement);
} | php | protected function compileLimit(int $limit, int $offset): string
{
if (empty($limit) && empty($offset)) {
return '';
}
$statement = '';
if (!empty($limit)) {
$statement = "LIMIT {$limit} ";
}
if (!empty($offset)) {
$statement .= "OFFSET {$offset}";
}
return trim($statement);
} | [
"protected",
"function",
"compileLimit",
"(",
"int",
"$",
"limit",
",",
"int",
"$",
"offset",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"limit",
")",
"&&",
"empty",
"(",
"$",
"offset",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"s... | Compile limit statement.
@param int $limit
@param int $offset
@return string | [
"Compile",
"limit",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L409-L425 | train |
spiral/database | src/Driver/Compiler.php | Compiler.compileWhere | protected function compileWhere(array $tokens): string
{
if (empty($tokens)) {
return '';
}
$statement = '';
$activeGroup = true;
foreach ($tokens as $condition) {
//OR/AND keyword
$boolean = $condition[0];
//See AbstractWhere
$context = $condition[1];
//First condition in group/query, no any AND, OR required
if ($activeGroup) {
//Kill AND, OR and etc.
$boolean = '';
//Next conditions require AND or OR
$activeGroup = false;
}
/*
* When context is string it usually represent control keyword/syntax such as opening
* or closing braces.
*/
if (is_string($context)) {
if ($context == '(') {
//New where group.
$activeGroup = true;
}
$statement .= ltrim("{$boolean} {$context} ");
if ($context == ')') {
//We don't need trailing space
$statement = rtrim($statement);
}
continue;
}
if ($context instanceof FragmentInterface) {
//Fragments has to be compiled separately
$statement .= "{$boolean} {$this->prepareFragment($context)} ";
continue;
}
//Now we are operating with "class" where function, where we need 3 variables where(id, =, 1)
if (!is_array($context)) {
throw new CompilerException('Invalid where token, context expected to be an array');
}
/*
* This is "normal" where token which includes identifier, operator and value.
*/
list($identifier, $operator, $value) = $context;
//Identifier can be column name, expression or even query builder
$identifier = $this->quote($identifier);
//Value has to be prepared as well
$placeholder = $this->prepareValue($value);
if ($operator == 'BETWEEN' || $operator == 'NOT BETWEEN') {
//Between statement has additional parameter
$right = $this->prepareValue($context[3]);
$statement .= "{$boolean} {$identifier} {$operator} {$placeholder} AND {$right} ";
continue;
}
//Compiler can switch equal to IN if value points to array (do we need it?)
$operator = $this->prepareOperator($value, $operator);
$statement .= "{$boolean} {$identifier} {$operator} {$placeholder} ";
}
if ($activeGroup) {
throw new CompilerException('Unable to build where statement, unclosed where group');
}
return trim($statement);
} | php | protected function compileWhere(array $tokens): string
{
if (empty($tokens)) {
return '';
}
$statement = '';
$activeGroup = true;
foreach ($tokens as $condition) {
//OR/AND keyword
$boolean = $condition[0];
//See AbstractWhere
$context = $condition[1];
//First condition in group/query, no any AND, OR required
if ($activeGroup) {
//Kill AND, OR and etc.
$boolean = '';
//Next conditions require AND or OR
$activeGroup = false;
}
/*
* When context is string it usually represent control keyword/syntax such as opening
* or closing braces.
*/
if (is_string($context)) {
if ($context == '(') {
//New where group.
$activeGroup = true;
}
$statement .= ltrim("{$boolean} {$context} ");
if ($context == ')') {
//We don't need trailing space
$statement = rtrim($statement);
}
continue;
}
if ($context instanceof FragmentInterface) {
//Fragments has to be compiled separately
$statement .= "{$boolean} {$this->prepareFragment($context)} ";
continue;
}
//Now we are operating with "class" where function, where we need 3 variables where(id, =, 1)
if (!is_array($context)) {
throw new CompilerException('Invalid where token, context expected to be an array');
}
/*
* This is "normal" where token which includes identifier, operator and value.
*/
list($identifier, $operator, $value) = $context;
//Identifier can be column name, expression or even query builder
$identifier = $this->quote($identifier);
//Value has to be prepared as well
$placeholder = $this->prepareValue($value);
if ($operator == 'BETWEEN' || $operator == 'NOT BETWEEN') {
//Between statement has additional parameter
$right = $this->prepareValue($context[3]);
$statement .= "{$boolean} {$identifier} {$operator} {$placeholder} AND {$right} ";
continue;
}
//Compiler can switch equal to IN if value points to array (do we need it?)
$operator = $this->prepareOperator($value, $operator);
$statement .= "{$boolean} {$identifier} {$operator} {$placeholder} ";
}
if ($activeGroup) {
throw new CompilerException('Unable to build where statement, unclosed where group');
}
return trim($statement);
} | [
"protected",
"function",
"compileWhere",
"(",
"array",
"$",
"tokens",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"tokens",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"statement",
"=",
"''",
";",
"$",
"activeGroup",
"=",
"true",
";",
... | Compile where statement.
@param array $tokens
@return string
@throws CompilerException | [
"Compile",
"where",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L436-L522 | train |
spiral/database | src/Driver/Compiler.php | Compiler.prepareFragment | protected function prepareFragment(FragmentInterface $context): string
{
if ($context instanceof BuilderInterface) {
//Nested queries has to be wrapped with braces
return '(' . $context->sqlStatement($this) . ')';
}
if ($context instanceof ExpressionInterface) {
//Fragments does not need braces around them
return $context->sqlStatement($this);
}
return $context->sqlStatement();
} | php | protected function prepareFragment(FragmentInterface $context): string
{
if ($context instanceof BuilderInterface) {
//Nested queries has to be wrapped with braces
return '(' . $context->sqlStatement($this) . ')';
}
if ($context instanceof ExpressionInterface) {
//Fragments does not need braces around them
return $context->sqlStatement($this);
}
return $context->sqlStatement();
} | [
"protected",
"function",
"prepareFragment",
"(",
"FragmentInterface",
"$",
"context",
")",
":",
"string",
"{",
"if",
"(",
"$",
"context",
"instanceof",
"BuilderInterface",
")",
"{",
"//Nested queries has to be wrapped with braces",
"return",
"'('",
".",
"$",
"context"... | Prepare where fragment to be injected into statement.
@param FragmentInterface $context
@return string | [
"Prepare",
"where",
"fragment",
"to",
"be",
"injected",
"into",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Compiler.php#L599-L612 | train |
spiral/database | src/Schema/State.php | State.getPrimaryKeys | public function getPrimaryKeys(): array
{
$primaryColumns = [];
foreach ($this->getColumns() as $column) {
if ($column->getAbstractType() == 'primary' || $column->getAbstractType() == 'bigPrimary') {
if (!in_array($column->getName(), $this->primaryKeys)) {
//Only columns not listed as primary keys already
$primaryColumns[] = $column->getName();
}
}
}
return array_unique(array_merge($this->primaryKeys, $primaryColumns));
} | php | public function getPrimaryKeys(): array
{
$primaryColumns = [];
foreach ($this->getColumns() as $column) {
if ($column->getAbstractType() == 'primary' || $column->getAbstractType() == 'bigPrimary') {
if (!in_array($column->getName(), $this->primaryKeys)) {
//Only columns not listed as primary keys already
$primaryColumns[] = $column->getName();
}
}
}
return array_unique(array_merge($this->primaryKeys, $primaryColumns));
} | [
"public",
"function",
"getPrimaryKeys",
"(",
")",
":",
"array",
"{",
"$",
"primaryColumns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"$",
"column",
"->",
"getAbstractType",... | Method combines primary keys with primary keys automatically calculated based on registered columns.
@return array | [
"Method",
"combines",
"primary",
"keys",
"with",
"primary",
"keys",
"automatically",
"calculated",
"based",
"on",
"registered",
"columns",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/State.php#L101-L114 | train |
spiral/database | src/Schema/State.php | State.forgetColumn | public function forgetColumn(AbstractColumn $column): State
{
foreach ($this->columns as $name => $columnSchema) {
if ($columnSchema == $column) {
unset($this->columns[$name]);
break;
}
}
return $this;
} | php | public function forgetColumn(AbstractColumn $column): State
{
foreach ($this->columns as $name => $columnSchema) {
if ($columnSchema == $column) {
unset($this->columns[$name]);
break;
}
}
return $this;
} | [
"public",
"function",
"forgetColumn",
"(",
"AbstractColumn",
"$",
"column",
")",
":",
"State",
"{",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"as",
"$",
"name",
"=>",
"$",
"columnSchema",
")",
"{",
"if",
"(",
"$",
"columnSchema",
"==",
"$",
"column",... | Drop column from table schema.
@param AbstractColumn $column
@return self | [
"Drop",
"column",
"from",
"table",
"schema",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/State.php#L173-L183 | train |
spiral/database | src/Schema/State.php | State.forgetIndex | public function forgetIndex(AbstractIndex $index)
{
foreach ($this->indexes as $name => $indexSchema) {
if ($indexSchema == $index) {
unset($this->indexes[$name]);
break;
}
}
} | php | public function forgetIndex(AbstractIndex $index)
{
foreach ($this->indexes as $name => $indexSchema) {
if ($indexSchema == $index) {
unset($this->indexes[$name]);
break;
}
}
} | [
"public",
"function",
"forgetIndex",
"(",
"AbstractIndex",
"$",
"index",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"indexes",
"as",
"$",
"name",
"=>",
"$",
"indexSchema",
")",
"{",
"if",
"(",
"$",
"indexSchema",
"==",
"$",
"index",
")",
"{",
"unset"... | Drop index from table schema using it's name or forming columns.
@param AbstractIndex $index | [
"Drop",
"index",
"from",
"table",
"schema",
"using",
"it",
"s",
"name",
"or",
"forming",
"columns",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/State.php#L190-L198 | train |
spiral/database | src/Schema/State.php | State.forgerForeignKey | public function forgerForeignKey(AbstractForeignKey $foreignKey)
{
foreach ($this->foreignKeys as $name => $foreignSchema) {
if ($foreignSchema == $foreignKey) {
unset($this->foreignKeys[$name]);
break;
}
}
} | php | public function forgerForeignKey(AbstractForeignKey $foreignKey)
{
foreach ($this->foreignKeys as $name => $foreignSchema) {
if ($foreignSchema == $foreignKey) {
unset($this->foreignKeys[$name]);
break;
}
}
} | [
"public",
"function",
"forgerForeignKey",
"(",
"AbstractForeignKey",
"$",
"foreignKey",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"foreignKeys",
"as",
"$",
"name",
"=>",
"$",
"foreignSchema",
")",
"{",
"if",
"(",
"$",
"foreignSchema",
"==",
"$",
"foreignK... | Drop foreign key from table schema using it's forming column.
@param AbstractForeignKey $foreignKey | [
"Drop",
"foreign",
"key",
"from",
"table",
"schema",
"using",
"it",
"s",
"forming",
"column",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/State.php#L205-L213 | train |
spiral/database | src/Schema/State.php | State.findIndex | public function findIndex(array $columns): ?AbstractIndex
{
foreach ($this->indexes as $index) {
if ($index->getColumns() == $columns) {
return $index;
}
}
return null;
} | php | public function findIndex(array $columns): ?AbstractIndex
{
foreach ($this->indexes as $index) {
if ($index->getColumns() == $columns) {
return $index;
}
}
return null;
} | [
"public",
"function",
"findIndex",
"(",
"array",
"$",
"columns",
")",
":",
"?",
"AbstractIndex",
"{",
"foreach",
"(",
"$",
"this",
"->",
"indexes",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"index",
"->",
"getColumns",
"(",
")",
"==",
"$",
"colum... | Find index by it's columns or return null.
@param array $columns
@return null|AbstractIndex | [
"Find",
"index",
"by",
"it",
"s",
"columns",
"or",
"return",
"null",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/State.php#L236-L245 | train |
spiral/database | src/Schema/State.php | State.findForeignKey | public function findForeignKey(string $column): ?AbstractForeignKey
{
foreach ($this->foreignKeys as $reference) {
if ($reference->getColumn() == $column) {
return $reference;
}
}
return null;
} | php | public function findForeignKey(string $column): ?AbstractForeignKey
{
foreach ($this->foreignKeys as $reference) {
if ($reference->getColumn() == $column) {
return $reference;
}
}
return null;
} | [
"public",
"function",
"findForeignKey",
"(",
"string",
"$",
"column",
")",
":",
"?",
"AbstractForeignKey",
"{",
"foreach",
"(",
"$",
"this",
"->",
"foreignKeys",
"as",
"$",
"reference",
")",
"{",
"if",
"(",
"$",
"reference",
"->",
"getColumn",
"(",
")",
... | Find foreign key by it's column or return null.
@param string $column
@return null|AbstractForeignKey | [
"Find",
"foreign",
"key",
"by",
"it",
"s",
"column",
"or",
"return",
"null",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/State.php#L253-L262 | train |
spiral/database | src/Schema/State.php | State.remountElements | public function remountElements()
{
$columns = [];
foreach ($this->columns as $column) {
$columns[$column->getName()] = $column;
}
$indexes = [];
foreach ($this->indexes as $index) {
$indexes[$index->getName()] = $index;
}
$foreignKeys = [];
foreach ($this->foreignKeys as $foreignKey) {
$foreignKeys[$foreignKey->getName()] = $foreignKey;
}
$this->columns = $columns;
$this->indexes = $indexes;
$this->foreignKeys = $foreignKeys;
} | php | public function remountElements()
{
$columns = [];
foreach ($this->columns as $column) {
$columns[$column->getName()] = $column;
}
$indexes = [];
foreach ($this->indexes as $index) {
$indexes[$index->getName()] = $index;
}
$foreignKeys = [];
foreach ($this->foreignKeys as $foreignKey) {
$foreignKeys[$foreignKey->getName()] = $foreignKey;
}
$this->columns = $columns;
$this->indexes = $indexes;
$this->foreignKeys = $foreignKeys;
} | [
"public",
"function",
"remountElements",
"(",
")",
"{",
"$",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"as",
"$",
"column",
")",
"{",
"$",
"columns",
"[",
"$",
"column",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
... | Remount elements under their current name. | [
"Remount",
"elements",
"under",
"their",
"current",
"name",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/State.php#L267-L287 | train |
spiral/database | src/Schema/State.php | State.syncState | public function syncState(State $source): self
{
$this->name = $source->name;
$this->primaryKeys = $source->primaryKeys;
$this->columns = [];
foreach ($source->columns as $name => $column) {
$this->columns[$name] = clone $column;
}
$this->indexes = [];
foreach ($source->indexes as $name => $index) {
$this->indexes[$name] = clone $index;
}
$this->foreignKeys = [];
foreach ($source->foreignKeys as $name => $foreignKey) {
$this->foreignKeys[$name] = clone $foreignKey;
}
$this->remountElements();
return $this;
} | php | public function syncState(State $source): self
{
$this->name = $source->name;
$this->primaryKeys = $source->primaryKeys;
$this->columns = [];
foreach ($source->columns as $name => $column) {
$this->columns[$name] = clone $column;
}
$this->indexes = [];
foreach ($source->indexes as $name => $index) {
$this->indexes[$name] = clone $index;
}
$this->foreignKeys = [];
foreach ($source->foreignKeys as $name => $foreignKey) {
$this->foreignKeys[$name] = clone $foreignKey;
}
$this->remountElements();
return $this;
} | [
"public",
"function",
"syncState",
"(",
"State",
"$",
"source",
")",
":",
"self",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"source",
"->",
"name",
";",
"$",
"this",
"->",
"primaryKeys",
"=",
"$",
"source",
"->",
"primaryKeys",
";",
"$",
"this",
"->"... | Re-populate schema elements using other state as source. Elements will be cloned under their
schema name.
@param State $source
@return self | [
"Re",
"-",
"populate",
"schema",
"elements",
"using",
"other",
"state",
"as",
"source",
".",
"Elements",
"will",
"be",
"cloned",
"under",
"their",
"schema",
"name",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/State.php#L297-L320 | train |
spiral/database | src/Schema/AbstractColumn.php | AbstractColumn.getAbstractType | public function getAbstractType(): string
{
foreach ($this->reverseMapping as $type => $candidates) {
foreach ($candidates as $candidate) {
if (is_string($candidate)) {
if (strtolower($candidate) == strtolower($this->type)) {
return $type;
}
continue;
}
if (strtolower($candidate['type']) != strtolower($this->type)) {
continue;
}
foreach ($candidate as $option => $required) {
if ($option == 'type') {
continue;
}
if ($this->{$option} != $required) {
continue 2;
}
}
return $type;
}
}
return 'unknown';
} | php | public function getAbstractType(): string
{
foreach ($this->reverseMapping as $type => $candidates) {
foreach ($candidates as $candidate) {
if (is_string($candidate)) {
if (strtolower($candidate) == strtolower($this->type)) {
return $type;
}
continue;
}
if (strtolower($candidate['type']) != strtolower($this->type)) {
continue;
}
foreach ($candidate as $option => $required) {
if ($option == 'type') {
continue;
}
if ($this->{$option} != $required) {
continue 2;
}
}
return $type;
}
}
return 'unknown';
} | [
"public",
"function",
"getAbstractType",
"(",
")",
":",
"string",
"{",
"foreach",
"(",
"$",
"this",
"->",
"reverseMapping",
"as",
"$",
"type",
"=>",
"$",
"candidates",
")",
"{",
"foreach",
"(",
"$",
"candidates",
"as",
"$",
"candidate",
")",
"{",
"if",
... | DBMS specific reverse mapping must map database specific type into limited set of abstract
types.
@return string | [
"DBMS",
"specific",
"reverse",
"mapping",
"must",
"map",
"database",
"specific",
"type",
"into",
"limited",
"set",
"of",
"abstract",
"types",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractColumn.php#L380-L411 | train |
spiral/database | src/Schema/AbstractColumn.php | AbstractColumn.type | public function type(string $abstract): AbstractColumn
{
if (isset($this->aliases[$abstract])) {
//Make recursive
$abstract = $this->aliases[$abstract];
}
if (!isset($this->mapping[$abstract])) {
throw new SchemaException("Undefined abstract/virtual type '{$abstract}'");
}
//Resetting all values to default state.
$this->size = $this->precision = $this->scale = 0;
$this->enumValues = [];
//Abstract type points to DBMS specific type
if (is_string($this->mapping[$abstract])) {
$this->type = $this->mapping[$abstract];
return $this;
}
//Configuring column properties based on abstractType preferences
foreach ($this->mapping[$abstract] as $property => $value) {
$this->{$property} = $value;
}
return $this;
} | php | public function type(string $abstract): AbstractColumn
{
if (isset($this->aliases[$abstract])) {
//Make recursive
$abstract = $this->aliases[$abstract];
}
if (!isset($this->mapping[$abstract])) {
throw new SchemaException("Undefined abstract/virtual type '{$abstract}'");
}
//Resetting all values to default state.
$this->size = $this->precision = $this->scale = 0;
$this->enumValues = [];
//Abstract type points to DBMS specific type
if (is_string($this->mapping[$abstract])) {
$this->type = $this->mapping[$abstract];
return $this;
}
//Configuring column properties based on abstractType preferences
foreach ($this->mapping[$abstract] as $property => $value) {
$this->{$property} = $value;
}
return $this;
} | [
"public",
"function",
"type",
"(",
"string",
"$",
"abstract",
")",
":",
"AbstractColumn",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"abstract",
"]",
")",
")",
"{",
"//Make recursive",
"$",
"abstract",
"=",
"$",
"this",
"->",... | Give column new abstract type. DBMS specific implementation must map provided type into one
of internal database values.
Attention, changing type of existed columns in some databases has a lot of restrictions like
cross type conversions and etc. Try do not change column type without a reason.
@param string $abstract Abstract or virtual type declared in mapping.
@return self|$this
@throws SchemaException
@todo Support native database types (simply bypass abstractType)! | [
"Give",
"column",
"new",
"abstract",
"type",
".",
"DBMS",
"specific",
"implementation",
"must",
"map",
"provided",
"type",
"into",
"one",
"of",
"internal",
"database",
"values",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractColumn.php#L427-L455 | train |
spiral/database | src/Schema/AbstractColumn.php | AbstractColumn.enum | public function enum($values): AbstractColumn
{
$this->type('enum');
$this->enumValues = array_map('strval', is_array($values) ? $values : func_get_args());
return $this;
} | php | public function enum($values): AbstractColumn
{
$this->type('enum');
$this->enumValues = array_map('strval', is_array($values) ? $values : func_get_args());
return $this;
} | [
"public",
"function",
"enum",
"(",
"$",
"values",
")",
":",
"AbstractColumn",
"{",
"$",
"this",
"->",
"type",
"(",
"'enum'",
")",
";",
"$",
"this",
"->",
"enumValues",
"=",
"array_map",
"(",
"'strval'",
",",
"is_array",
"(",
"$",
"values",
")",
"?",
... | Set column as enum type and specify set of allowed values. Most of drivers will emulate enums
using column constraints.
Examples:
$table->status->enum(['active', 'disabled']);
$table->status->enum('active', 'disabled');
@param string|array $values Enum values (array or comma separated). String values only.
@return self | [
"Set",
"column",
"as",
"enum",
"type",
"and",
"specify",
"set",
"of",
"allowed",
"values",
".",
"Most",
"of",
"drivers",
"will",
"emulate",
"enums",
"using",
"column",
"constraints",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractColumn.php#L500-L506 | train |
spiral/database | src/Schema/AbstractColumn.php | AbstractColumn.string | public function string(int $size = 255): AbstractColumn
{
$this->type('string');
if ($size > 255) {
throw new SchemaException("String size can't exceed 255 characters. Use text instead");
}
if ($size < 0) {
throw new SchemaException('Invalid string length value');
}
$this->size = (int)$size;
return $this;
} | php | public function string(int $size = 255): AbstractColumn
{
$this->type('string');
if ($size > 255) {
throw new SchemaException("String size can't exceed 255 characters. Use text instead");
}
if ($size < 0) {
throw new SchemaException('Invalid string length value');
}
$this->size = (int)$size;
return $this;
} | [
"public",
"function",
"string",
"(",
"int",
"$",
"size",
"=",
"255",
")",
":",
"AbstractColumn",
"{",
"$",
"this",
"->",
"type",
"(",
"'string'",
")",
";",
"if",
"(",
"$",
"size",
">",
"255",
")",
"{",
"throw",
"new",
"SchemaException",
"(",
"\"Strin... | Set column type as string with limited size. Maximum allowed size is 255 bytes, use "text"
abstract types for longer strings.
Strings are perfect type to store email addresses as it big enough to store valid address
and
can be covered with unique index.
@link http://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address
@param int $size Max string length.
@return self|$this
@throws SchemaException | [
"Set",
"column",
"type",
"as",
"string",
"with",
"limited",
"size",
".",
"Maximum",
"allowed",
"size",
"is",
"255",
"bytes",
"use",
"text",
"abstract",
"types",
"for",
"longer",
"strings",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractColumn.php#L523-L538 | train |
spiral/database | src/Schema/AbstractColumn.php | AbstractColumn.decimal | public function decimal(int $precision, int $scale = 0): AbstractColumn
{
$this->type('decimal');
if (empty($precision)) {
throw new SchemaException('Invalid precision value');
}
$this->precision = (int)$precision;
$this->scale = (int)$scale;
return $this;
} | php | public function decimal(int $precision, int $scale = 0): AbstractColumn
{
$this->type('decimal');
if (empty($precision)) {
throw new SchemaException('Invalid precision value');
}
$this->precision = (int)$precision;
$this->scale = (int)$scale;
return $this;
} | [
"public",
"function",
"decimal",
"(",
"int",
"$",
"precision",
",",
"int",
"$",
"scale",
"=",
"0",
")",
":",
"AbstractColumn",
"{",
"$",
"this",
"->",
"type",
"(",
"'decimal'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"precision",
")",
")",
"{",
"th... | Set column type as decimal with specific precision and scale.
@param int $precision
@param int $scale
@return self|$this
@throws SchemaException | [
"Set",
"column",
"type",
"as",
"decimal",
"with",
"specific",
"precision",
"and",
"scale",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractColumn.php#L549-L561 | train |
spiral/database | src/Schema/AbstractColumn.php | AbstractColumn.quoteEnum | protected function quoteEnum(DriverInterface $driver): string
{
$enumValues = [];
foreach ($this->enumValues as $value) {
$enumValues[] = $driver->quote($value);
}
if (!empty($enumValues)) {
return '(' . implode(', ', $enumValues) . ')';
}
return '';
} | php | protected function quoteEnum(DriverInterface $driver): string
{
$enumValues = [];
foreach ($this->enumValues as $value) {
$enumValues[] = $driver->quote($value);
}
if (!empty($enumValues)) {
return '(' . implode(', ', $enumValues) . ')';
}
return '';
} | [
"protected",
"function",
"quoteEnum",
"(",
"DriverInterface",
"$",
"driver",
")",
":",
"string",
"{",
"$",
"enumValues",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"enumValues",
"as",
"$",
"value",
")",
"{",
"$",
"enumValues",
"[",
"]",
"="... | Get database specific enum type definition options.
@param DriverInterface $driver
@return string | [
"Get",
"database",
"specific",
"enum",
"type",
"definition",
"options",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractColumn.php#L694-L706 | train |
spiral/database | src/Schema/AbstractColumn.php | AbstractColumn.quoteDefault | protected function quoteDefault(DriverInterface $driver): string
{
$defaultValue = $this->getDefaultValue();
if ($defaultValue === null) {
return 'NULL';
}
if ($defaultValue instanceof FragmentInterface) {
return $defaultValue->sqlStatement();
}
if ($this->getType() == 'bool') {
return $defaultValue ? 'TRUE' : 'FALSE';
}
if ($this->getType() == 'float') {
return sprintf('%F', $defaultValue);
}
if ($this->getType() == 'int') {
return strval($defaultValue);
}
return strval($driver->quote($defaultValue));
} | php | protected function quoteDefault(DriverInterface $driver): string
{
$defaultValue = $this->getDefaultValue();
if ($defaultValue === null) {
return 'NULL';
}
if ($defaultValue instanceof FragmentInterface) {
return $defaultValue->sqlStatement();
}
if ($this->getType() == 'bool') {
return $defaultValue ? 'TRUE' : 'FALSE';
}
if ($this->getType() == 'float') {
return sprintf('%F', $defaultValue);
}
if ($this->getType() == 'int') {
return strval($defaultValue);
}
return strval($driver->quote($defaultValue));
} | [
"protected",
"function",
"quoteDefault",
"(",
"DriverInterface",
"$",
"driver",
")",
":",
"string",
"{",
"$",
"defaultValue",
"=",
"$",
"this",
"->",
"getDefaultValue",
"(",
")",
";",
"if",
"(",
"$",
"defaultValue",
"===",
"null",
")",
"{",
"return",
"'NUL... | Must return driver specific default value.
@param DriverInterface $driver
@return string | [
"Must",
"return",
"driver",
"specific",
"default",
"value",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractColumn.php#L714-L738 | train |
spiral/database | src/Query/Traits/WhereTrait.php | WhereTrait.where | public function where(...$args): self
{
$this->createToken('AND', $args, $this->whereTokens, $this->whereWrapper());
return $this;
} | php | public function where(...$args): self
{
$this->createToken('AND', $args, $this->whereTokens, $this->whereWrapper());
return $this;
} | [
"public",
"function",
"where",
"(",
"...",
"$",
"args",
")",
":",
"self",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'AND'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"whereTokens",
",",
"$",
"this",
"->",
"whereWrapper",
"(",
")",
")",
";",
"ret... | Simple WHERE condition with various set of arguments.
@param mixed ...$args [(column, value), (column, operator, value)]
@return self|$this
@throws BuilderException
@see AbstractWhere | [
"Simple",
"WHERE",
"condition",
"with",
"various",
"set",
"of",
"arguments",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/WhereTrait.php#L47-L52 | train |
spiral/database | src/Query/Traits/WhereTrait.php | WhereTrait.andWhere | public function andWhere(...$args): self
{
$this->createToken('AND', $args, $this->whereTokens, $this->whereWrapper());
return $this;
} | php | public function andWhere(...$args): self
{
$this->createToken('AND', $args, $this->whereTokens, $this->whereWrapper());
return $this;
} | [
"public",
"function",
"andWhere",
"(",
"...",
"$",
"args",
")",
":",
"self",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'AND'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"whereTokens",
",",
"$",
"this",
"->",
"whereWrapper",
"(",
")",
")",
";",
"... | Simple AND WHERE condition with various set of arguments.
@param mixed ...$args [(column, value), (column, operator, value)]
@return self|$this
@throws BuilderException
@see AbstractWhere | [
"Simple",
"AND",
"WHERE",
"condition",
"with",
"various",
"set",
"of",
"arguments",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/WhereTrait.php#L65-L70 | train |
spiral/database | src/Query/Traits/WhereTrait.php | WhereTrait.orWhere | public function orWhere(...$args): self
{
$this->createToken('OR', $args, $this->whereTokens, $this->whereWrapper());
return $this;
} | php | public function orWhere(...$args): self
{
$this->createToken('OR', $args, $this->whereTokens, $this->whereWrapper());
return $this;
} | [
"public",
"function",
"orWhere",
"(",
"...",
"$",
"args",
")",
":",
"self",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'OR'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"whereTokens",
",",
"$",
"this",
"->",
"whereWrapper",
"(",
")",
")",
";",
"re... | Simple OR WHERE condition with various set of arguments.
@param mixed ...$args [(column, value), (column, operator, value)]
@return self|$this
@throws BuilderException
@see AbstractWhere | [
"Simple",
"OR",
"WHERE",
"condition",
"with",
"various",
"set",
"of",
"arguments",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/WhereTrait.php#L83-L88 | train |
spiral/database | src/Query/Traits/WhereTrait.php | WhereTrait.whereWrapper | private function whereWrapper()
{
return function ($parameter) {
if ($parameter instanceof FragmentInterface) {
//We are only not creating bindings for plan fragments
if (!$parameter instanceof ParameterInterface && !$parameter instanceof BuilderInterface) {
return $parameter;
}
}
if (is_array($parameter)) {
throw new BuilderException('Arrays must be wrapped with Parameter instance');
}
//Wrapping all values with ParameterInterface
if (!$parameter instanceof ParameterInterface && !$parameter instanceof ExpressionInterface) {
$parameter = new Parameter($parameter, Parameter::DETECT_TYPE);
};
//Let's store to sent to driver when needed
$this->whereParameters[] = $parameter;
return $parameter;
};
} | php | private function whereWrapper()
{
return function ($parameter) {
if ($parameter instanceof FragmentInterface) {
//We are only not creating bindings for plan fragments
if (!$parameter instanceof ParameterInterface && !$parameter instanceof BuilderInterface) {
return $parameter;
}
}
if (is_array($parameter)) {
throw new BuilderException('Arrays must be wrapped with Parameter instance');
}
//Wrapping all values with ParameterInterface
if (!$parameter instanceof ParameterInterface && !$parameter instanceof ExpressionInterface) {
$parameter = new Parameter($parameter, Parameter::DETECT_TYPE);
};
//Let's store to sent to driver when needed
$this->whereParameters[] = $parameter;
return $parameter;
};
} | [
"private",
"function",
"whereWrapper",
"(",
")",
"{",
"return",
"function",
"(",
"$",
"parameter",
")",
"{",
"if",
"(",
"$",
"parameter",
"instanceof",
"FragmentInterface",
")",
"{",
"//We are only not creating bindings for plan fragments",
"if",
"(",
"!",
"$",
"p... | Applied to every potential parameter while where tokens generation. Used to prepare and
collect where parameters.
@return \Closure | [
"Applied",
"to",
"every",
"potential",
"parameter",
"while",
"where",
"tokens",
"generation",
".",
"Used",
"to",
"prepare",
"and",
"collect",
"where",
"parameters",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/WhereTrait.php#L116-L140 | train |
spiral/database | src/Driver/SQLServer/SQLServerDriver.php | SQLServerDriver.bindParameters | protected function bindParameters(Statement $statement, array $parameters): Statement
{
foreach ($parameters as $index => $parameter) {
if (is_numeric($index)) {
if ($parameter->getType() == PDO::PARAM_LOB) {
$value = $parameter->getValue();
$statement->bindParam(
$index + 1,
$value,
$parameter->getType(),
0,
PDO::SQLSRV_ENCODING_BINARY
);
continue;
}
//Numeric, @see http://php.net/manual/en/pdostatement.bindparam.php
$statement->bindValue($index + 1, $parameter->getValue(), $parameter->getType());
} else {
//Named
$statement->bindValue($index, $parameter->getValue(), $parameter->getType());
}
}
return $statement;
} | php | protected function bindParameters(Statement $statement, array $parameters): Statement
{
foreach ($parameters as $index => $parameter) {
if (is_numeric($index)) {
if ($parameter->getType() == PDO::PARAM_LOB) {
$value = $parameter->getValue();
$statement->bindParam(
$index + 1,
$value,
$parameter->getType(),
0,
PDO::SQLSRV_ENCODING_BINARY
);
continue;
}
//Numeric, @see http://php.net/manual/en/pdostatement.bindparam.php
$statement->bindValue($index + 1, $parameter->getValue(), $parameter->getType());
} else {
//Named
$statement->bindValue($index, $parameter->getValue(), $parameter->getType());
}
}
return $statement;
} | [
"protected",
"function",
"bindParameters",
"(",
"Statement",
"$",
"statement",
",",
"array",
"$",
"parameters",
")",
":",
"Statement",
"{",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"index",
"=>",
"$",
"parameter",
")",
"{",
"if",
"(",
"is_numeric",
"(... | Bind parameters into statement. SQLServer need encoding to be specified for binary parameters.
@param Statement $statement
@param ParameterInterface[] $parameters Named hash of ParameterInterface.
@return Statement | [
"Bind",
"parameters",
"into",
"statement",
".",
"SQLServer",
"need",
"encoding",
"to",
"be",
"specified",
"for",
"binary",
"parameters",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLServer/SQLServerDriver.php#L104-L129 | train |
spiral/database | src/Driver/SQLServer/SQLServerDriver.php | SQLServerDriver.savepointCreate | protected function savepointCreate(int $level)
{
$this->isProfiling() && $this->getLogger()->info("Transaction: new savepoint 'SVP{$level}'");
$this->execute('SAVE TRANSACTION ' . $this->identifier("SVP{$level}"));
} | php | protected function savepointCreate(int $level)
{
$this->isProfiling() && $this->getLogger()->info("Transaction: new savepoint 'SVP{$level}'");
$this->execute('SAVE TRANSACTION ' . $this->identifier("SVP{$level}"));
} | [
"protected",
"function",
"savepointCreate",
"(",
"int",
"$",
"level",
")",
"{",
"$",
"this",
"->",
"isProfiling",
"(",
")",
"&&",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"\"Transaction: new savepoint 'SVP{$level}'\"",
")",
";",
"$",
"thi... | Create nested transaction save point.
@link http://en.wikipedia.org/wiki/Savepoint
@param int $level Savepoint name/id, must not contain spaces and be valid database
identifier. | [
"Create",
"nested",
"transaction",
"save",
"point",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLServer/SQLServerDriver.php#L139-L143 | train |
spiral/database | src/Table.php | Table.getSchema | public function getSchema(): AbstractTable
{
return $this->database->getDriver(DatabaseInterface::WRITE)->getSchema($this->name,
$this->database->getPrefix());
} | php | public function getSchema(): AbstractTable
{
return $this->database->getDriver(DatabaseInterface::WRITE)->getSchema($this->name,
$this->database->getPrefix());
} | [
"public",
"function",
"getSchema",
"(",
")",
":",
"AbstractTable",
"{",
"return",
"$",
"this",
"->",
"database",
"->",
"getDriver",
"(",
"DatabaseInterface",
"::",
"WRITE",
")",
"->",
"getSchema",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"... | Get modifiable table schema.
@return AbstractTable | [
"Get",
"modifiable",
"table",
"schema",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Table.php#L82-L86 | train |
spiral/database | src/Table.php | Table.insertOne | public function insertOne(array $rowset = []): int
{
return $this->database->insert($this->name)->values($rowset)->run();
} | php | public function insertOne(array $rowset = []): int
{
return $this->database->insert($this->name)->values($rowset)->run();
} | [
"public",
"function",
"insertOne",
"(",
"array",
"$",
"rowset",
"=",
"[",
"]",
")",
":",
"int",
"{",
"return",
"$",
"this",
"->",
"database",
"->",
"insert",
"(",
"$",
"this",
"->",
"name",
")",
"->",
"values",
"(",
"$",
"rowset",
")",
"->",
"run",... | Insert one fieldset into table and return last inserted id.
Example:
$table->insertOne(["name" => "Wolfy-J", "balance" => 10]);
@param array $rowset
@return int
@throws BuilderException | [
"Insert",
"one",
"fieldset",
"into",
"table",
"and",
"return",
"last",
"inserted",
"id",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Table.php#L107-L110 | train |
spiral/database | src/Table.php | Table.insertMultiple | public function insertMultiple(array $columns = [], array $rowsets = [])
{
//No return value
$this->database->insert($this->name)->columns($columns)->values($rowsets)->run();
} | php | public function insertMultiple(array $columns = [], array $rowsets = [])
{
//No return value
$this->database->insert($this->name)->columns($columns)->values($rowsets)->run();
} | [
"public",
"function",
"insertMultiple",
"(",
"array",
"$",
"columns",
"=",
"[",
"]",
",",
"array",
"$",
"rowsets",
"=",
"[",
"]",
")",
"{",
"//No return value",
"$",
"this",
"->",
"database",
"->",
"insert",
"(",
"$",
"this",
"->",
"name",
")",
"->",
... | Perform batch insert into table, every rowset should have identical amount of values matched
with column names provided in first argument. Method will return lastInsertID on success.
Example:
$table->insertMultiple(["name", "balance"], array(["Bob", 10], ["Jack", 20]))
@param array $columns Array of columns.
@param array $rowsets Array of rowsets. | [
"Perform",
"batch",
"insert",
"into",
"table",
"every",
"rowset",
"should",
"have",
"identical",
"amount",
"of",
"values",
"matched",
"with",
"column",
"names",
"provided",
"in",
"first",
"argument",
".",
"Method",
"will",
"return",
"lastInsertID",
"on",
"succes... | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Table.php#L122-L126 | train |
spiral/database | src/Table.php | Table.select | public function select($columns = '*'): SelectQuery
{
return $this->database->select(func_num_args() ? func_get_args() : '*')->from($this->name);
} | php | public function select($columns = '*'): SelectQuery
{
return $this->database->select(func_num_args() ? func_get_args() : '*')->from($this->name);
} | [
"public",
"function",
"select",
"(",
"$",
"columns",
"=",
"'*'",
")",
":",
"SelectQuery",
"{",
"return",
"$",
"this",
"->",
"database",
"->",
"select",
"(",
"func_num_args",
"(",
")",
"?",
"func_get_args",
"(",
")",
":",
"'*'",
")",
"->",
"from",
"(",
... | Get SelectQuery builder with pre-populated from tables.
@param string $columns
@return SelectQuery | [
"Get",
"SelectQuery",
"builder",
"with",
"pre",
"-",
"populated",
"from",
"tables",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Table.php#L145-L148 | train |
spiral/database | src/Schema/AbstractTable.php | AbstractTable.setName | public function setName(string $name): string
{
$this->current->setName($this->prefix . $name);
return $this->getName();
} | php | public function setName(string $name): string
{
$this->current->setName($this->prefix . $name);
return $this->getName();
} | [
"public",
"function",
"setName",
"(",
"string",
"$",
"name",
")",
":",
"string",
"{",
"$",
"this",
"->",
"current",
"->",
"setName",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"getName",
"(",
")",
";"... | Sets table name. Use this function in combination with save to rename table.
@param string $name
@return string Prefixed table name. | [
"Sets",
"table",
"name",
".",
"Use",
"this",
"function",
"in",
"combination",
"with",
"save",
"to",
"rename",
"table",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractTable.php#L185-L190 | train |
spiral/database | src/Schema/AbstractTable.php | AbstractTable.declareDropped | public function declareDropped()
{
if ($this->status == self::STATUS_NEW) {
throw new SchemaException("Unable to drop non existed table");
}
//Declaring as dropped
$this->status = self::STATUS_DECLARED_DROPPED;
} | php | public function declareDropped()
{
if ($this->status == self::STATUS_NEW) {
throw new SchemaException("Unable to drop non existed table");
}
//Declaring as dropped
$this->status = self::STATUS_DECLARED_DROPPED;
} | [
"public",
"function",
"declareDropped",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"status",
"==",
"self",
"::",
"STATUS_NEW",
")",
"{",
"throw",
"new",
"SchemaException",
"(",
"\"Unable to drop non existed table\"",
")",
";",
"}",
"//Declaring as dropped",
"$... | Declare table as dropped, you have to sync table using "save" method in order to apply this
change.
Attention, method will flush declared FKs to ensure that table express no dependecies. | [
"Declare",
"table",
"as",
"dropped",
"you",
"have",
"to",
"sync",
"table",
"using",
"save",
"method",
"in",
"order",
"to",
"apply",
"this",
"change",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractTable.php#L216-L224 | train |
spiral/database | src/Schema/AbstractTable.php | AbstractTable.dropColumn | public function dropColumn(string $column): AbstractTable
{
if (empty($schema = $this->current->findColumn($column))) {
throw new SchemaException("Undefined column '{$column}' in '{$this->getName()}'");
}
//Dropping column from current schema
$this->current->forgetColumn($schema);
return $this;
} | php | public function dropColumn(string $column): AbstractTable
{
if (empty($schema = $this->current->findColumn($column))) {
throw new SchemaException("Undefined column '{$column}' in '{$this->getName()}'");
}
//Dropping column from current schema
$this->current->forgetColumn($schema);
return $this;
} | [
"public",
"function",
"dropColumn",
"(",
"string",
"$",
"column",
")",
":",
"AbstractTable",
"{",
"if",
"(",
"empty",
"(",
"$",
"schema",
"=",
"$",
"this",
"->",
"current",
"->",
"findColumn",
"(",
"$",
"column",
")",
")",
")",
"{",
"throw",
"new",
"... | Drop column by it's name.
@param string $column
@return self
@throws SchemaException | [
"Drop",
"column",
"by",
"it",
"s",
"name",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractTable.php#L510-L520 | train |
spiral/database | src/Schema/AbstractTable.php | AbstractTable.dropIndex | public function dropIndex(array $columns): AbstractTable
{
if (empty($schema = $this->current->findIndex($columns))) {
throw new SchemaException(
"Undefined index ['" . join("', '", $columns) . "'] in '{$this->getName()}'"
);
}
//Dropping index from current schema
$this->current->forgetIndex($schema);
return $this;
} | php | public function dropIndex(array $columns): AbstractTable
{
if (empty($schema = $this->current->findIndex($columns))) {
throw new SchemaException(
"Undefined index ['" . join("', '", $columns) . "'] in '{$this->getName()}'"
);
}
//Dropping index from current schema
$this->current->forgetIndex($schema);
return $this;
} | [
"public",
"function",
"dropIndex",
"(",
"array",
"$",
"columns",
")",
":",
"AbstractTable",
"{",
"if",
"(",
"empty",
"(",
"$",
"schema",
"=",
"$",
"this",
"->",
"current",
"->",
"findIndex",
"(",
"$",
"columns",
")",
")",
")",
"{",
"throw",
"new",
"S... | Drop index by it's forming columns.
@param array $columns
@return self
@throws SchemaException | [
"Drop",
"index",
"by",
"it",
"s",
"forming",
"columns",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractTable.php#L530-L542 | train |
spiral/database | src/Schema/AbstractTable.php | AbstractTable.dropForeignKey | public function dropForeignKey(string $column): AbstractTable
{
if (empty($schema = $this->current->findForeignKey($column))) {
throw new SchemaException("Undefined FK on '{$column}' in '{$this->getName()}'");
}
//Dropping foreign from current schema
$this->current->forgerForeignKey($schema);
return $this;
} | php | public function dropForeignKey(string $column): AbstractTable
{
if (empty($schema = $this->current->findForeignKey($column))) {
throw new SchemaException("Undefined FK on '{$column}' in '{$this->getName()}'");
}
//Dropping foreign from current schema
$this->current->forgerForeignKey($schema);
return $this;
} | [
"public",
"function",
"dropForeignKey",
"(",
"string",
"$",
"column",
")",
":",
"AbstractTable",
"{",
"if",
"(",
"empty",
"(",
"$",
"schema",
"=",
"$",
"this",
"->",
"current",
"->",
"findForeignKey",
"(",
"$",
"column",
")",
")",
")",
"{",
"throw",
"n... | Drop foreign key by it's name.
@param string $column
@return self
@throws SchemaException | [
"Drop",
"foreign",
"key",
"by",
"it",
"s",
"name",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractTable.php#L552-L562 | train |
spiral/database | src/Schema/AbstractTable.php | AbstractTable.setState | public function setState(State $state = null): AbstractTable
{
$this->current = new State($this->initial->getName());
if (!empty($state)) {
$this->current->setName($state->getName());
$this->current->syncState($state);
}
return $this;
} | php | public function setState(State $state = null): AbstractTable
{
$this->current = new State($this->initial->getName());
if (!empty($state)) {
$this->current->setName($state->getName());
$this->current->syncState($state);
}
return $this;
} | [
"public",
"function",
"setState",
"(",
"State",
"$",
"state",
"=",
"null",
")",
":",
"AbstractTable",
"{",
"$",
"this",
"->",
"current",
"=",
"new",
"State",
"(",
"$",
"this",
"->",
"initial",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"!",
"e... | Reset table state to new form.
@param State $state Use null to flush table schema.
@return self|$this | [
"Reset",
"table",
"state",
"to",
"new",
"form",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractTable.php#L584-L594 | train |
spiral/database | src/Schema/AbstractTable.php | AbstractTable.normalizeSchema | protected function normalizeSchema(bool $withForeignKeys = true)
{
// To make sure that no pre-sync modifications will be reflected on current table
$target = clone $this;
// declare all FKs dropped on tables scheduled for removal
if ($this->status === self::STATUS_DECLARED_DROPPED) {
foreach ($target->getForeignKeys() as $fk) {
$target->current->forgerForeignKey($fk);
}
}
/*
* In cases where columns are removed we have to automatically remove related indexes and
* foreign keys.
*/
foreach ($this->getComparator()->droppedColumns() as $column) {
foreach ($target->getIndexes() as $index) {
if (in_array($column->getName(), $index->getColumns())) {
$target->current->forgetIndex($index);
}
}
foreach ($target->getForeignKeys() as $foreign) {
if ($column->getName() == $foreign->getColumn()) {
$target->current->forgerForeignKey($foreign);
}
}
}
//We also have to adjusts indexes and foreign keys
foreach ($this->getComparator()->alteredColumns() as $pair) {
/**
* @var AbstractColumn $initial
* @var AbstractColumn $name
*/
list($name, $initial) = $pair;
foreach ($target->getIndexes() as $index) {
if (in_array($initial->getName(), $index->getColumns())) {
$columns = $index->getColumns();
//Replacing column name
foreach ($columns as &$column) {
if ($column == $initial->getName()) {
$column = $name->getName();
}
unset($column);
}
$targetIndex = $target->initial->findIndex($index->getColumns());
if (!empty($targetIndex)) {
//Target index got renamed or removed.
$targetIndex->columns($columns);
}
$index->columns($columns);
}
}
foreach ($target->getForeignKeys() as $foreign) {
if ($initial->getName() == $foreign->getColumn()) {
$foreign->column($name->getName());
}
}
}
if (!$withForeignKeys) {
foreach ($this->getComparator()->addedForeignKeys() as $foreign) {
//Excluding from creation
$target->current->forgerForeignKey($foreign);
}
}
return $target;
} | php | protected function normalizeSchema(bool $withForeignKeys = true)
{
// To make sure that no pre-sync modifications will be reflected on current table
$target = clone $this;
// declare all FKs dropped on tables scheduled for removal
if ($this->status === self::STATUS_DECLARED_DROPPED) {
foreach ($target->getForeignKeys() as $fk) {
$target->current->forgerForeignKey($fk);
}
}
/*
* In cases where columns are removed we have to automatically remove related indexes and
* foreign keys.
*/
foreach ($this->getComparator()->droppedColumns() as $column) {
foreach ($target->getIndexes() as $index) {
if (in_array($column->getName(), $index->getColumns())) {
$target->current->forgetIndex($index);
}
}
foreach ($target->getForeignKeys() as $foreign) {
if ($column->getName() == $foreign->getColumn()) {
$target->current->forgerForeignKey($foreign);
}
}
}
//We also have to adjusts indexes and foreign keys
foreach ($this->getComparator()->alteredColumns() as $pair) {
/**
* @var AbstractColumn $initial
* @var AbstractColumn $name
*/
list($name, $initial) = $pair;
foreach ($target->getIndexes() as $index) {
if (in_array($initial->getName(), $index->getColumns())) {
$columns = $index->getColumns();
//Replacing column name
foreach ($columns as &$column) {
if ($column == $initial->getName()) {
$column = $name->getName();
}
unset($column);
}
$targetIndex = $target->initial->findIndex($index->getColumns());
if (!empty($targetIndex)) {
//Target index got renamed or removed.
$targetIndex->columns($columns);
}
$index->columns($columns);
}
}
foreach ($target->getForeignKeys() as $foreign) {
if ($initial->getName() == $foreign->getColumn()) {
$foreign->column($name->getName());
}
}
}
if (!$withForeignKeys) {
foreach ($this->getComparator()->addedForeignKeys() as $foreign) {
//Excluding from creation
$target->current->forgerForeignKey($foreign);
}
}
return $target;
} | [
"protected",
"function",
"normalizeSchema",
"(",
"bool",
"$",
"withForeignKeys",
"=",
"true",
")",
"{",
"// To make sure that no pre-sync modifications will be reflected on current table",
"$",
"target",
"=",
"clone",
"$",
"this",
";",
"// declare all FKs dropped on tables sche... | Ensure that no wrong indexes left in table. This method will create AbstracTable
copy in order to prevent cross modifications.
@param bool $withForeignKeys
@return AbstractTable | [
"Ensure",
"that",
"no",
"wrong",
"indexes",
"left",
"in",
"table",
".",
"This",
"method",
"will",
"create",
"AbstracTable",
"copy",
"in",
"order",
"to",
"prevent",
"cross",
"modifications",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractTable.php#L664-L740 | train |
spiral/database | src/Schema/AbstractTable.php | AbstractTable.createIdentifier | protected function createIdentifier(string $type, array $columns): string
{
$name = $this->getName() . '_' . $type . '_' . join('_', $columns) . '_' . uniqid();
if (strlen($name) > 64) {
//Many DBMS has limitations on identifier length
$name = md5($name);
}
return $name;
} | php | protected function createIdentifier(string $type, array $columns): string
{
$name = $this->getName() . '_' . $type . '_' . join('_', $columns) . '_' . uniqid();
if (strlen($name) > 64) {
//Many DBMS has limitations on identifier length
$name = md5($name);
}
return $name;
} | [
"protected",
"function",
"createIdentifier",
"(",
"string",
"$",
"type",
",",
"array",
"$",
"columns",
")",
":",
"string",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'_'",
".",
"$",
"type",
".",
"'_'",
".",
"join",
"(",
"'... | Generate unique name for indexes and foreign keys.
@param string $type
@param array $columns
@return string | [
"Generate",
"unique",
"name",
"for",
"indexes",
"and",
"foreign",
"keys",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractTable.php#L861-L871 | train |
spiral/database | src/Query/Traits/HavingTrait.php | HavingTrait.having | public function having(...$args): self
{
$this->createToken('AND', $args, $this->havingTokens, $this->havingWrapper());
return $this;
} | php | public function having(...$args): self
{
$this->createToken('AND', $args, $this->havingTokens, $this->havingWrapper());
return $this;
} | [
"public",
"function",
"having",
"(",
"...",
"$",
"args",
")",
":",
"self",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'AND'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"havingTokens",
",",
"$",
"this",
"->",
"havingWrapper",
"(",
")",
")",
";",
"... | Simple HAVING condition with various set of arguments.
@param mixed ...$args [(column, value), (column, operator, value)]
@return self|$this
@throws BuilderException
@see AbstractWhere | [
"Simple",
"HAVING",
"condition",
"with",
"various",
"set",
"of",
"arguments",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/HavingTrait.php#L50-L55 | train |
spiral/database | src/Query/Traits/HavingTrait.php | HavingTrait.andHaving | public function andHaving(...$args): self
{
$this->createToken('AND', $args, $this->havingTokens, $this->havingWrapper());
return $this;
} | php | public function andHaving(...$args): self
{
$this->createToken('AND', $args, $this->havingTokens, $this->havingWrapper());
return $this;
} | [
"public",
"function",
"andHaving",
"(",
"...",
"$",
"args",
")",
":",
"self",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'AND'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"havingTokens",
",",
"$",
"this",
"->",
"havingWrapper",
"(",
")",
")",
";",
... | Simple AND HAVING condition with various set of arguments.
@param mixed ...$args [(column, value), (column, operator, value)]
@return self|$this
@throws BuilderException
@see AbstractWhere | [
"Simple",
"AND",
"HAVING",
"condition",
"with",
"various",
"set",
"of",
"arguments",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/HavingTrait.php#L67-L72 | train |
spiral/database | src/Query/Traits/HavingTrait.php | HavingTrait.orHaving | public function orHaving(...$args): self
{
$this->createToken('OR', $args, $this->havingTokens, $this->havingWrapper());
return $this;
} | php | public function orHaving(...$args): self
{
$this->createToken('OR', $args, $this->havingTokens, $this->havingWrapper());
return $this;
} | [
"public",
"function",
"orHaving",
"(",
"...",
"$",
"args",
")",
":",
"self",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'OR'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"havingTokens",
",",
"$",
"this",
"->",
"havingWrapper",
"(",
")",
")",
";",
... | Simple OR HAVING condition with various set of arguments.
@param mixed ...$args [(column, value), (column, operator, value)]
@return self|$this
@throws BuilderException
@see AbstractWhere | [
"Simple",
"OR",
"HAVING",
"condition",
"with",
"various",
"set",
"of",
"arguments",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/HavingTrait.php#L85-L90 | train |
spiral/database | src/Query/Traits/HavingTrait.php | HavingTrait.havingWrapper | private function havingWrapper()
{
return function ($parameter) {
if ($parameter instanceof FragmentInterface) {
//We are only not creating bindings for plan fragments
if (!$parameter instanceof ParameterInterface && !$parameter instanceof BuilderInterface) {
return $parameter;
}
}
if (is_array($parameter)) {
throw new BuilderException('Arrays must be wrapped with Parameter instance');
}
//Wrapping all values with ParameterInterface
if (!$parameter instanceof ParameterInterface && !$parameter instanceof ExpressionInterface) {
$parameter = new Parameter($parameter, Parameter::DETECT_TYPE);
};
//Let's store to sent to driver when needed
$this->havingParameters[] = $parameter;
return $parameter;
};
} | php | private function havingWrapper()
{
return function ($parameter) {
if ($parameter instanceof FragmentInterface) {
//We are only not creating bindings for plan fragments
if (!$parameter instanceof ParameterInterface && !$parameter instanceof BuilderInterface) {
return $parameter;
}
}
if (is_array($parameter)) {
throw new BuilderException('Arrays must be wrapped with Parameter instance');
}
//Wrapping all values with ParameterInterface
if (!$parameter instanceof ParameterInterface && !$parameter instanceof ExpressionInterface) {
$parameter = new Parameter($parameter, Parameter::DETECT_TYPE);
};
//Let's store to sent to driver when needed
$this->havingParameters[] = $parameter;
return $parameter;
};
} | [
"private",
"function",
"havingWrapper",
"(",
")",
"{",
"return",
"function",
"(",
"$",
"parameter",
")",
"{",
"if",
"(",
"$",
"parameter",
"instanceof",
"FragmentInterface",
")",
"{",
"//We are only not creating bindings for plan fragments",
"if",
"(",
"!",
"$",
"... | Applied to every potential parameter while having tokens generation.
@return \Closure | [
"Applied",
"to",
"every",
"potential",
"parameter",
"while",
"having",
"tokens",
"generation",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/HavingTrait.php#L117-L142 | train |
spiral/database | src/Schema/Reflector.php | Reflector.addTable | public function addTable(AbstractTable $table)
{
$this->tables[$table->getName()] = $table;
$this->dependencies[$table->getName()] = $table->getDependencies();
$this->collectDrivers();
} | php | public function addTable(AbstractTable $table)
{
$this->tables[$table->getName()] = $table;
$this->dependencies[$table->getName()] = $table->getDependencies();
$this->collectDrivers();
} | [
"public",
"function",
"addTable",
"(",
"AbstractTable",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"tables",
"[",
"$",
"table",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"table",
";",
"$",
"this",
"->",
"dependencies",
"[",
"$",
"table",
"->",
"getNa... | Add table to the collection.
@param AbstractTable $table | [
"Add",
"table",
"to",
"the",
"collection",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/Reflector.php#L44-L50 | train |
spiral/database | src/Schema/Reflector.php | Reflector.run | public function run()
{
$hasChanges = false;
foreach ($this->tables as $table) {
if (
$table->getComparator()->hasChanges()
|| $table->getStatus() == AbstractTable::STATUS_DECLARED_DROPPED
) {
$hasChanges = true;
break;
}
}
if (!$hasChanges) {
//Nothing to do
return;
}
$this->beginTransaction();
try {
//Drop not-needed foreign keys and alter everything else
$this->dropForeignKeys();
//Drop not-needed indexes
$this->dropIndexes();
//Other changes [NEW TABLES WILL BE CREATED HERE!]
foreach ($this->commitChanges() as $table) {
$table->save(HandlerInterface::CREATE_FOREIGN_KEYS, true);
}
} catch (\Throwable $e) {
$this->rollbackTransaction();
throw $e;
}
$this->commitTransaction();
} | php | public function run()
{
$hasChanges = false;
foreach ($this->tables as $table) {
if (
$table->getComparator()->hasChanges()
|| $table->getStatus() == AbstractTable::STATUS_DECLARED_DROPPED
) {
$hasChanges = true;
break;
}
}
if (!$hasChanges) {
//Nothing to do
return;
}
$this->beginTransaction();
try {
//Drop not-needed foreign keys and alter everything else
$this->dropForeignKeys();
//Drop not-needed indexes
$this->dropIndexes();
//Other changes [NEW TABLES WILL BE CREATED HERE!]
foreach ($this->commitChanges() as $table) {
$table->save(HandlerInterface::CREATE_FOREIGN_KEYS, true);
}
} catch (\Throwable $e) {
$this->rollbackTransaction();
throw $e;
}
$this->commitTransaction();
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"hasChanges",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"tables",
"as",
"$",
"table",
")",
"{",
"if",
"(",
"$",
"table",
"->",
"getComparator",
"(",
")",
"->",
"hasChanges",
"(",
")",
"||... | Synchronize tables.
@throws \Throwable | [
"Synchronize",
"tables",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/Reflector.php#L82-L119 | train |
spiral/database | src/Schema/Reflector.php | Reflector.dropForeignKeys | protected function dropForeignKeys()
{
foreach ($this->sortedTables() as $table) {
if ($table->exists()) {
$table->save(HandlerInterface::DROP_FOREIGN_KEYS, false);
}
}
} | php | protected function dropForeignKeys()
{
foreach ($this->sortedTables() as $table) {
if ($table->exists()) {
$table->save(HandlerInterface::DROP_FOREIGN_KEYS, false);
}
}
} | [
"protected",
"function",
"dropForeignKeys",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sortedTables",
"(",
")",
"as",
"$",
"table",
")",
"{",
"if",
"(",
"$",
"table",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"table",
"->",
"save",
"(",
"Han... | Drop all removed table references. | [
"Drop",
"all",
"removed",
"table",
"references",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/Reflector.php#L124-L131 | train |
spiral/database | src/Schema/Reflector.php | Reflector.dropIndexes | protected function dropIndexes()
{
foreach ($this->sortedTables() as $table) {
if ($table->exists()) {
$table->save(HandlerInterface::DROP_INDEXES, false);
}
}
} | php | protected function dropIndexes()
{
foreach ($this->sortedTables() as $table) {
if ($table->exists()) {
$table->save(HandlerInterface::DROP_INDEXES, false);
}
}
} | [
"protected",
"function",
"dropIndexes",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sortedTables",
"(",
")",
"as",
"$",
"table",
")",
"{",
"if",
"(",
"$",
"table",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"table",
"->",
"save",
"(",
"Handler... | Drop all removed table indexes. | [
"Drop",
"all",
"removed",
"table",
"indexes",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/Reflector.php#L136-L143 | train |
spiral/database | src/Schema/Reflector.php | Reflector.collectDrivers | private function collectDrivers()
{
foreach ($this->tables as $table) {
if (!in_array($table->getDriver(), $this->drivers, true)) {
$this->drivers[] = $table->getDriver();
}
}
} | php | private function collectDrivers()
{
foreach ($this->tables as $table) {
if (!in_array($table->getDriver(), $this->drivers, true)) {
$this->drivers[] = $table->getDriver();
}
}
} | [
"private",
"function",
"collectDrivers",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tables",
"as",
"$",
"table",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"table",
"->",
"getDriver",
"(",
")",
",",
"$",
"this",
"->",
"drivers",
",",
"... | Collecting all involved drivers. | [
"Collecting",
"all",
"involved",
"drivers",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/Reflector.php#L172-L179 | train |
spiral/database | src/Query/UpdateQuery.php | UpdateQuery.set | public function set(string $column, $value): UpdateQuery
{
$this->values[$column] = $value;
return $this;
} | php | public function set(string $column, $value): UpdateQuery
{
$this->values[$column] = $value;
return $this;
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"column",
",",
"$",
"value",
")",
":",
"UpdateQuery",
"{",
"$",
"this",
"->",
"values",
"[",
"$",
"column",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set update value.
@param string $column
@param mixed $value
@return self|$this | [
"Set",
"update",
"value",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/UpdateQuery.php#L110-L115 | train |
spiral/database | src/Schema/AbstractIndex.php | AbstractIndex.columns | public function columns($columns): AbstractIndex
{
if (!is_array($columns)) {
$columns = func_get_args();
}
$this->columns = $columns;
return $this;
} | php | public function columns($columns): AbstractIndex
{
if (!is_array($columns)) {
$columns = func_get_args();
}
$this->columns = $columns;
return $this;
} | [
"public",
"function",
"columns",
"(",
"$",
"columns",
")",
":",
"AbstractIndex",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"columns",
"=",
"func_get_args",
"(",
")",
";",
"}",
"$",
"this",
"->",
"columns",
"=",
"$",
... | Change set of index forming columns. Method must support both array and string parameters.
Example:
$index->columns('key');
$index->columns('key', 'key2');
$index->columns(['key', 'key2']);
@param string|array $columns Columns array or comma separated list of parameters.
@return self | [
"Change",
"set",
"of",
"index",
"forming",
"columns",
".",
"Method",
"must",
"support",
"both",
"array",
"and",
"string",
"parameters",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractIndex.php#L95-L104 | train |
spiral/database | src/Schema/AbstractIndex.php | AbstractIndex.sqlStatement | public function sqlStatement(DriverInterface $driver, bool $includeTable = true): string
{
$statement = [$this->type == self::UNIQUE ? 'UNIQUE INDEX' : 'INDEX'];
$statement[] = $driver->identifier($this->name);
if ($includeTable) {
$statement[] = "ON {$driver->identifier($this->table)}";
}
//Wrapping column names
$columns = implode(', ', array_map([$driver, 'identifier'], $this->columns));
$statement[] = "({$columns})";
return implode(' ', $statement);
} | php | public function sqlStatement(DriverInterface $driver, bool $includeTable = true): string
{
$statement = [$this->type == self::UNIQUE ? 'UNIQUE INDEX' : 'INDEX'];
$statement[] = $driver->identifier($this->name);
if ($includeTable) {
$statement[] = "ON {$driver->identifier($this->table)}";
}
//Wrapping column names
$columns = implode(', ', array_map([$driver, 'identifier'], $this->columns));
$statement[] = "({$columns})";
return implode(' ', $statement);
} | [
"public",
"function",
"sqlStatement",
"(",
"DriverInterface",
"$",
"driver",
",",
"bool",
"$",
"includeTable",
"=",
"true",
")",
":",
"string",
"{",
"$",
"statement",
"=",
"[",
"$",
"this",
"->",
"type",
"==",
"self",
"::",
"UNIQUE",
"?",
"'UNIQUE INDEX'",... | Index sql creation syntax.
@param DriverInterface $driver
@param bool $includeTable Include table ON statement (not required for inline index creation).
@return string | [
"Index",
"sql",
"creation",
"syntax",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractIndex.php#L113-L129 | train |
spiral/database | src/Driver/SQLite/SQLiteHandler.php | SQLiteHandler.requiresRebuild | private function requiresRebuild(AbstractTable $table): bool
{
$comparator = $table->getComparator();
$difference = [
count($comparator->addedColumns()),
count($comparator->droppedColumns()),
count($comparator->alteredColumns()),
count($comparator->addedForeignKeys()),
count($comparator->droppedForeignKeys()),
count($comparator->alteredForeignKeys()),
];
return array_sum($difference) != 0;
} | php | private function requiresRebuild(AbstractTable $table): bool
{
$comparator = $table->getComparator();
$difference = [
count($comparator->addedColumns()),
count($comparator->droppedColumns()),
count($comparator->alteredColumns()),
count($comparator->addedForeignKeys()),
count($comparator->droppedForeignKeys()),
count($comparator->alteredForeignKeys()),
];
return array_sum($difference) != 0;
} | [
"private",
"function",
"requiresRebuild",
"(",
"AbstractTable",
"$",
"table",
")",
":",
"bool",
"{",
"$",
"comparator",
"=",
"$",
"table",
"->",
"getComparator",
"(",
")",
";",
"$",
"difference",
"=",
"[",
"count",
"(",
"$",
"comparator",
"->",
"addedColum... | Rebuild is required when columns or foreign keys are altered.
@param AbstractTable $table
@return bool | [
"Rebuild",
"is",
"required",
"when",
"columns",
"or",
"foreign",
"keys",
"are",
"altered",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLite/SQLiteHandler.php#L138-L153 | train |
spiral/database | src/Driver/SQLite/SQLiteHandler.php | SQLiteHandler.createTemporary | protected function createTemporary(AbstractTable $table): AbstractTable
{
//Temporary table is required to copy data over
$temporary = clone $table;
$temporary->setName('spiral_temp_' . $table->getName() . '_' . uniqid());
//We don't need any indexes in temporary table
foreach ($temporary->getIndexes() as $index) {
$temporary->dropIndex($index->getColumns());
}
$this->createTable($temporary);
return $temporary;
} | php | protected function createTemporary(AbstractTable $table): AbstractTable
{
//Temporary table is required to copy data over
$temporary = clone $table;
$temporary->setName('spiral_temp_' . $table->getName() . '_' . uniqid());
//We don't need any indexes in temporary table
foreach ($temporary->getIndexes() as $index) {
$temporary->dropIndex($index->getColumns());
}
$this->createTable($temporary);
return $temporary;
} | [
"protected",
"function",
"createTemporary",
"(",
"AbstractTable",
"$",
"table",
")",
":",
"AbstractTable",
"{",
"//Temporary table is required to copy data over",
"$",
"temporary",
"=",
"clone",
"$",
"table",
";",
"$",
"temporary",
"->",
"setName",
"(",
"'spiral_temp_... | Temporary table based on parent.
@param AbstractTable $table
@return AbstractTable | [
"Temporary",
"table",
"based",
"on",
"parent",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLite/SQLiteHandler.php#L161-L175 | train |
spiral/database | src/Driver/SQLite/SQLiteHandler.php | SQLiteHandler.copyData | private function copyData(string $source, string $to, array $mapping)
{
$sourceColumns = array_keys($mapping);
$targetColumns = array_values($mapping);
//Preparing mapping
$sourceColumns = array_map([$this, 'identify'], $sourceColumns);
$targetColumns = array_map([$this, 'identify'], $targetColumns);
$query = sprintf(
'INSERT INTO %s (%s) SELECT %s FROM %s',
$this->identify($to),
implode(', ', $targetColumns),
implode(', ', $sourceColumns),
$this->identify($source)
);
$this->run($query);
} | php | private function copyData(string $source, string $to, array $mapping)
{
$sourceColumns = array_keys($mapping);
$targetColumns = array_values($mapping);
//Preparing mapping
$sourceColumns = array_map([$this, 'identify'], $sourceColumns);
$targetColumns = array_map([$this, 'identify'], $targetColumns);
$query = sprintf(
'INSERT INTO %s (%s) SELECT %s FROM %s',
$this->identify($to),
implode(', ', $targetColumns),
implode(', ', $sourceColumns),
$this->identify($source)
);
$this->run($query);
} | [
"private",
"function",
"copyData",
"(",
"string",
"$",
"source",
",",
"string",
"$",
"to",
",",
"array",
"$",
"mapping",
")",
"{",
"$",
"sourceColumns",
"=",
"array_keys",
"(",
"$",
"mapping",
")",
";",
"$",
"targetColumns",
"=",
"array_values",
"(",
"$"... | Copy table data to another location.
@see http://stackoverflow.com/questions/4007014/alter-column-in-sqlite
@param string $source
@param string $to
@param array $mapping (destination => source)
@throws HandlerException | [
"Copy",
"table",
"data",
"to",
"another",
"location",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLite/SQLiteHandler.php#L188-L206 | train |
spiral/database | src/Driver/SQLite/SQLiteHandler.php | SQLiteHandler.createMapping | private function createMapping(AbstractTable $source, AbstractTable $target)
{
$mapping = [];
foreach ($target->getColumns() as $name => $column) {
if ($source->hasColumn($name)) {
$mapping[$name] = $column->getName();
}
}
return $mapping;
} | php | private function createMapping(AbstractTable $source, AbstractTable $target)
{
$mapping = [];
foreach ($target->getColumns() as $name => $column) {
if ($source->hasColumn($name)) {
$mapping[$name] = $column->getName();
}
}
return $mapping;
} | [
"private",
"function",
"createMapping",
"(",
"AbstractTable",
"$",
"source",
",",
"AbstractTable",
"$",
"target",
")",
"{",
"$",
"mapping",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"target",
"->",
"getColumns",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"... | Get mapping between new and initial columns.
@param AbstractTable $source
@param AbstractTable $target
@return array | [
"Get",
"mapping",
"between",
"new",
"and",
"initial",
"columns",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLite/SQLiteHandler.php#L215-L225 | train |
spiral/database | src/Query/Traits/JoinTrait.php | JoinTrait.on | public function on(...$args)
{
$this->createToken(
'AND',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWrapper()
);
return $this;
} | php | public function on(...$args)
{
$this->createToken(
'AND',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWrapper()
);
return $this;
} | [
"public",
"function",
"on",
"(",
"...",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'AND'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"joinTokens",
"[",
"$",
"this",
"->",
"activeJoin",
"]",
"[",
"'on'",
"]",
",",
"$",
"this",
... | Simple ON condition with various set of arguments. Can only be used to link column values
together, no parametric values allowed.
@param mixed ...$args [(column, outer column), (column, operator, outer column)]
@return $this
@throws BuilderException | [
"Simple",
"ON",
"condition",
"with",
"various",
"set",
"of",
"arguments",
".",
"Can",
"only",
"be",
"used",
"to",
"link",
"column",
"values",
"together",
"no",
"parametric",
"values",
"allowed",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/JoinTrait.php#L230-L240 | train |
spiral/database | src/Query/Traits/JoinTrait.php | JoinTrait.andOn | public function andOn(...$args)
{
$this->createToken(
'AND',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWrapper()
);
return $this;
} | php | public function andOn(...$args)
{
$this->createToken(
'AND',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWrapper()
);
return $this;
} | [
"public",
"function",
"andOn",
"(",
"...",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'AND'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"joinTokens",
"[",
"$",
"this",
"->",
"activeJoin",
"]",
"[",
"'on'",
"]",
",",
"$",
"this",... | Simple AND ON condition with various set of arguments. Can only be used to link column values
together, no parametric values allowed.
@param mixed ...$args [(column, outer column), (column, operator, outer column)]
@return $this
@throws BuilderException | [
"Simple",
"AND",
"ON",
"condition",
"with",
"various",
"set",
"of",
"arguments",
".",
"Can",
"only",
"be",
"used",
"to",
"link",
"column",
"values",
"together",
"no",
"parametric",
"values",
"allowed",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/JoinTrait.php#L252-L262 | train |
spiral/database | src/Query/Traits/JoinTrait.php | JoinTrait.orOn | public function orOn(...$args)
{
$this->createToken(
'OR',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWrapper()
);
return $this;
} | php | public function orOn(...$args)
{
$this->createToken(
'OR',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWrapper()
);
return $this;
} | [
"public",
"function",
"orOn",
"(",
"...",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'OR'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"joinTokens",
"[",
"$",
"this",
"->",
"activeJoin",
"]",
"[",
"'on'",
"]",
",",
"$",
"this",
... | Simple OR ON condition with various set of arguments. Can only be used to link column values
together, no parametric values allowed.
@param mixed ...$args [(column, outer column), (column, operator, outer column)]
@return $this
@throws BuilderException | [
"Simple",
"OR",
"ON",
"condition",
"with",
"various",
"set",
"of",
"arguments",
".",
"Can",
"only",
"be",
"used",
"to",
"link",
"column",
"values",
"together",
"no",
"parametric",
"values",
"allowed",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/JoinTrait.php#L274-L284 | train |
spiral/database | src/Query/Traits/JoinTrait.php | JoinTrait.onWhere | public function onWhere(...$args)
{
$this->createToken(
'AND',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWhereWrapper()
);
return $this;
} | php | public function onWhere(...$args)
{
$this->createToken(
'AND',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWhereWrapper()
);
return $this;
} | [
"public",
"function",
"onWhere",
"(",
"...",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'AND'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"joinTokens",
"[",
"$",
"this",
"->",
"activeJoin",
"]",
"[",
"'on'",
"]",
",",
"$",
"this... | Simple ON WHERE condition with various set of arguments. You can use parametric values in
such methods.
@param mixed ...$args [(column, value), (column, operator, value)]
@return $this
@throws BuilderException
@see AbstractWhere | [
"Simple",
"ON",
"WHERE",
"condition",
"with",
"various",
"set",
"of",
"arguments",
".",
"You",
"can",
"use",
"parametric",
"values",
"in",
"such",
"methods",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/JoinTrait.php#L298-L308 | train |
spiral/database | src/Query/Traits/JoinTrait.php | JoinTrait.andOnWhere | public function andOnWhere(...$args)
{
$this->createToken(
'AND',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWhereWrapper()
);
return $this;
} | php | public function andOnWhere(...$args)
{
$this->createToken(
'AND',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWhereWrapper()
);
return $this;
} | [
"public",
"function",
"andOnWhere",
"(",
"...",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'AND'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"joinTokens",
"[",
"$",
"this",
"->",
"activeJoin",
"]",
"[",
"'on'",
"]",
",",
"$",
"t... | Simple AND ON WHERE condition with various set of arguments. You can use parametric values in
such methods.
@param mixed ...$args [(column, value), (column, operator, value)]
@return $this
@throws BuilderException
@see AbstractWhere | [
"Simple",
"AND",
"ON",
"WHERE",
"condition",
"with",
"various",
"set",
"of",
"arguments",
".",
"You",
"can",
"use",
"parametric",
"values",
"in",
"such",
"methods",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/JoinTrait.php#L322-L332 | train |
spiral/database | src/Query/Traits/JoinTrait.php | JoinTrait.orOnWhere | public function orOnWhere(...$args)
{
$this->createToken(
'OR',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWhereWrapper()
);
return $this;
} | php | public function orOnWhere(...$args)
{
$this->createToken(
'OR',
$args,
$this->joinTokens[$this->activeJoin]['on'],
$this->onWhereWrapper()
);
return $this;
} | [
"public",
"function",
"orOnWhere",
"(",
"...",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"createToken",
"(",
"'OR'",
",",
"$",
"args",
",",
"$",
"this",
"->",
"joinTokens",
"[",
"$",
"this",
"->",
"activeJoin",
"]",
"[",
"'on'",
"]",
",",
"$",
"thi... | Simple OR ON WHERE condition with various set of arguments. You can use parametric values in
such methods.
@param mixed ...$args [(column, value), (column, operator, value)]
@return $this
@throws BuilderException
@see AbstractWhere | [
"Simple",
"OR",
"ON",
"WHERE",
"condition",
"with",
"various",
"set",
"of",
"arguments",
".",
"You",
"can",
"use",
"parametric",
"values",
"in",
"such",
"methods",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/JoinTrait.php#L346-L356 | train |
spiral/database | src/Query/Traits/JoinTrait.php | JoinTrait.onWhereWrapper | private function onWhereWrapper()
{
return function ($parameter) {
if ($parameter instanceof FragmentInterface) {
//We are only not creating bindings for plan fragments
if (!$parameter instanceof ParameterInterface && !$parameter instanceof BuilderInterface) {
return $parameter;
}
}
if (is_array($parameter)) {
throw new BuilderException('Arrays must be wrapped with Parameter instance');
}
//Wrapping all values with ParameterInterface
if (!$parameter instanceof ParameterInterface && !$parameter instanceof ExpressionInterface) {
$parameter = new Parameter($parameter, Parameter::DETECT_TYPE);
};
//Let's store to sent to driver when needed
$this->onParameters[] = $parameter;
return $parameter;
};
} | php | private function onWhereWrapper()
{
return function ($parameter) {
if ($parameter instanceof FragmentInterface) {
//We are only not creating bindings for plan fragments
if (!$parameter instanceof ParameterInterface && !$parameter instanceof BuilderInterface) {
return $parameter;
}
}
if (is_array($parameter)) {
throw new BuilderException('Arrays must be wrapped with Parameter instance');
}
//Wrapping all values with ParameterInterface
if (!$parameter instanceof ParameterInterface && !$parameter instanceof ExpressionInterface) {
$parameter = new Parameter($parameter, Parameter::DETECT_TYPE);
};
//Let's store to sent to driver when needed
$this->onParameters[] = $parameter;
return $parameter;
};
} | [
"private",
"function",
"onWhereWrapper",
"(",
")",
"{",
"return",
"function",
"(",
"$",
"parameter",
")",
"{",
"if",
"(",
"$",
"parameter",
"instanceof",
"FragmentInterface",
")",
"{",
"//We are only not creating bindings for plan fragments",
"if",
"(",
"!",
"$",
... | Applied to every potential parameter while ON WHERE tokens generation.
@return \Closure | [
"Applied",
"to",
"every",
"potential",
"parameter",
"while",
"ON",
"WHERE",
"tokens",
"generation",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Query/Traits/JoinTrait.php#L399-L423 | train |
spiral/database | src/Config/DatabaseConfig.php | DatabaseConfig.getDatabases | public function getDatabases(): array
{
$result = [];
foreach (array_keys($this->config['databases'] ?? []) as $database) {
$result[$database] = $this->getDatabase($database);
}
return $result;
} | php | public function getDatabases(): array
{
$result = [];
foreach (array_keys($this->config['databases'] ?? []) as $database) {
$result[$database] = $this->getDatabase($database);
}
return $result;
} | [
"public",
"function",
"getDatabases",
"(",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"config",
"[",
"'databases'",
"]",
"??",
"[",
"]",
")",
"as",
"$",
"database",
")",
"{",
"$"... | Get named list of all databases.
@return DatabasePartial[] | [
"Get",
"named",
"list",
"of",
"all",
"databases",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Config/DatabaseConfig.php#L48-L56 | train |
spiral/database | src/Config/DatabaseConfig.php | DatabaseConfig.getDrivers | public function getDrivers(): array
{
$result = [];
foreach (array_keys($this->config['connections'] ?? $this->config['drivers'] ?? []) as $driver) {
$result[$driver] = $this->getDriver($driver);
}
return $result;
} | php | public function getDrivers(): array
{
$result = [];
foreach (array_keys($this->config['connections'] ?? $this->config['drivers'] ?? []) as $driver) {
$result[$driver] = $this->getDriver($driver);
}
return $result;
} | [
"public",
"function",
"getDrivers",
"(",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"config",
"[",
"'connections'",
"]",
"??",
"$",
"this",
"->",
"config",
"[",
"'drivers'",
"]",
"... | Get names list of all driver connections.
@return Autowire[] | [
"Get",
"names",
"list",
"of",
"all",
"driver",
"connections",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Config/DatabaseConfig.php#L63-L71 | train |
spiral/database | src/Driver/SQLServer/SQLServerHandler.php | SQLServerHandler.alterColumn | public function alterColumn(
AbstractTable $table,
AbstractColumn $initial,
AbstractColumn $column
) {
if (!$initial instanceof SQLServerColumn || !$column instanceof SQLServerColumn) {
throw new SchemaException('SQlServer handler can work only with SQLServer columns');
}
//In SQLServer we have to drop ALL related indexes and foreign keys while
//applying type change... yeah...
$indexesBackup = [];
$foreignBackup = [];
foreach ($table->getIndexes() as $index) {
if (in_array($column->getName(), $index->getColumns())) {
$indexesBackup[] = $index;
$this->dropIndex($table, $index);
}
}
foreach ($table->getForeignKeys() as $foreign) {
if ($column->getName() == $foreign->getColumn()) {
$foreignBackup[] = $foreign;
$this->dropForeignKey($table, $foreign);
}
}
//Column will recreate needed constraints
foreach ($column->getConstraints() as $constraint) {
$this->dropConstrain($table, $constraint);
}
//Rename is separate operation
if ($column->getName() != $initial->getName()) {
$this->renameColumn($table, $initial, $column);
//This call is required to correctly built set of alter operations
$initial->setName($column->getName());
}
foreach ($column->alterOperations($this->driver, $initial) as $operation) {
$this->run("ALTER TABLE {$this->identify($table)} {$operation}");
}
//Restoring indexes and foreign keys
foreach ($indexesBackup as $index) {
$this->createIndex($table, $index);
}
foreach ($foreignBackup as $foreign) {
$this->createForeignKey($table, $foreign);
}
} | php | public function alterColumn(
AbstractTable $table,
AbstractColumn $initial,
AbstractColumn $column
) {
if (!$initial instanceof SQLServerColumn || !$column instanceof SQLServerColumn) {
throw new SchemaException('SQlServer handler can work only with SQLServer columns');
}
//In SQLServer we have to drop ALL related indexes and foreign keys while
//applying type change... yeah...
$indexesBackup = [];
$foreignBackup = [];
foreach ($table->getIndexes() as $index) {
if (in_array($column->getName(), $index->getColumns())) {
$indexesBackup[] = $index;
$this->dropIndex($table, $index);
}
}
foreach ($table->getForeignKeys() as $foreign) {
if ($column->getName() == $foreign->getColumn()) {
$foreignBackup[] = $foreign;
$this->dropForeignKey($table, $foreign);
}
}
//Column will recreate needed constraints
foreach ($column->getConstraints() as $constraint) {
$this->dropConstrain($table, $constraint);
}
//Rename is separate operation
if ($column->getName() != $initial->getName()) {
$this->renameColumn($table, $initial, $column);
//This call is required to correctly built set of alter operations
$initial->setName($column->getName());
}
foreach ($column->alterOperations($this->driver, $initial) as $operation) {
$this->run("ALTER TABLE {$this->identify($table)} {$operation}");
}
//Restoring indexes and foreign keys
foreach ($indexesBackup as $index) {
$this->createIndex($table, $index);
}
foreach ($foreignBackup as $foreign) {
$this->createForeignKey($table, $foreign);
}
} | [
"public",
"function",
"alterColumn",
"(",
"AbstractTable",
"$",
"table",
",",
"AbstractColumn",
"$",
"initial",
",",
"AbstractColumn",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"$",
"initial",
"instanceof",
"SQLServerColumn",
"||",
"!",
"$",
"column",
"instance... | Driver specific column alter command.
@param AbstractTable $table
@param AbstractColumn $initial
@param AbstractColumn $column
@throws SchemaException | [
"Driver",
"specific",
"column",
"alter",
"command",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLServer/SQLServerHandler.php#L46-L99 | train |
spiral/database | src/Driver/SQLServer/Schema/SQLServerColumn.php | SQLServerColumn.alterOperations | public function alterOperations(DriverInterface $driver, AbstractColumn $initial): array
{
$operations = [];
$currentType = [
$this->type,
$this->size,
$this->precision,
$this->scale,
$this->nullable,
];
$initType = [
$initial->type,
$initial->size,
$initial->precision,
$initial->scale,
$initial->nullable,
];
if ($currentType != $initType) {
if ($this->getAbstractType() == 'enum') {
//Getting longest value
$enumSize = $this->size;
foreach ($this->enumValues as $value) {
$enumSize = max($enumSize, strlen($value));
}
$type = "ALTER COLUMN {$driver->identifier($this->getName())} varchar($enumSize)";
$operations[] = $type . ' ' . ($this->nullable ? 'NULL' : 'NOT NULL');
} else {
$type = "ALTER COLUMN {$driver->identifier($this->getName())} {$this->type}";
if (!empty($this->size)) {
$type .= "($this->size)";
} elseif ($this->type == 'varchar' || $this->type == 'varbinary') {
$type .= '(max)';
} elseif (!empty($this->precision)) {
$type .= "($this->precision, $this->scale)";
}
$operations[] = $type . ' ' . ($this->nullable ? 'NULL' : 'NOT NULL');
}
}
//Constraint should be already removed it this moment (see doColumnChange in TableSchema)
if ($this->hasDefaultValue()) {
$operations[] = "ADD CONSTRAINT {$this->defaultConstrain()} "
. "DEFAULT {$this->quoteDefault($driver)} "
. "FOR {$driver->identifier($this->getName())}";
}
//Constraint should be already removed it this moment (see alterColumn in SQLServerHandler)
if ($this->getAbstractType() == 'enum') {
$operations[] = "ADD {$this->enumStatement($driver)}";
}
return $operations;
} | php | public function alterOperations(DriverInterface $driver, AbstractColumn $initial): array
{
$operations = [];
$currentType = [
$this->type,
$this->size,
$this->precision,
$this->scale,
$this->nullable,
];
$initType = [
$initial->type,
$initial->size,
$initial->precision,
$initial->scale,
$initial->nullable,
];
if ($currentType != $initType) {
if ($this->getAbstractType() == 'enum') {
//Getting longest value
$enumSize = $this->size;
foreach ($this->enumValues as $value) {
$enumSize = max($enumSize, strlen($value));
}
$type = "ALTER COLUMN {$driver->identifier($this->getName())} varchar($enumSize)";
$operations[] = $type . ' ' . ($this->nullable ? 'NULL' : 'NOT NULL');
} else {
$type = "ALTER COLUMN {$driver->identifier($this->getName())} {$this->type}";
if (!empty($this->size)) {
$type .= "($this->size)";
} elseif ($this->type == 'varchar' || $this->type == 'varbinary') {
$type .= '(max)';
} elseif (!empty($this->precision)) {
$type .= "($this->precision, $this->scale)";
}
$operations[] = $type . ' ' . ($this->nullable ? 'NULL' : 'NOT NULL');
}
}
//Constraint should be already removed it this moment (see doColumnChange in TableSchema)
if ($this->hasDefaultValue()) {
$operations[] = "ADD CONSTRAINT {$this->defaultConstrain()} "
. "DEFAULT {$this->quoteDefault($driver)} "
. "FOR {$driver->identifier($this->getName())}";
}
//Constraint should be already removed it this moment (see alterColumn in SQLServerHandler)
if ($this->getAbstractType() == 'enum') {
$operations[] = "ADD {$this->enumStatement($driver)}";
}
return $operations;
} | [
"public",
"function",
"alterOperations",
"(",
"DriverInterface",
"$",
"driver",
",",
"AbstractColumn",
"$",
"initial",
")",
":",
"array",
"{",
"$",
"operations",
"=",
"[",
"]",
";",
"$",
"currentType",
"=",
"[",
"$",
"this",
"->",
"type",
",",
"$",
"this... | Generate set of operations need to change column. We are expecting that column constrains
will be dropped separately.
@param DriverInterface $driver
@param AbstractColumn $initial
@return array | [
"Generate",
"set",
"of",
"operations",
"need",
"to",
"change",
"column",
".",
"We",
"are",
"expecting",
"that",
"column",
"constrains",
"will",
"be",
"dropped",
"separately",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLServer/Schema/SQLServerColumn.php#L243-L301 | train |
spiral/database | src/Driver/SQLServer/Schema/SQLServerColumn.php | SQLServerColumn.enumStatement | private function enumStatement(DriverInterface $driver): string
{
$enumValues = [];
foreach ($this->enumValues as $value) {
$enumValues[] = $driver->quote($value);
}
$constrain = $driver->identifier($this->enumConstraint());
$column = $driver->identifier($this->getName());
$enumValues = implode(', ', $enumValues);
return "CONSTRAINT {$constrain} CHECK ({$column} IN ({$enumValues}))";
} | php | private function enumStatement(DriverInterface $driver): string
{
$enumValues = [];
foreach ($this->enumValues as $value) {
$enumValues[] = $driver->quote($value);
}
$constrain = $driver->identifier($this->enumConstraint());
$column = $driver->identifier($this->getName());
$enumValues = implode(', ', $enumValues);
return "CONSTRAINT {$constrain} CHECK ({$column} IN ({$enumValues}))";
} | [
"private",
"function",
"enumStatement",
"(",
"DriverInterface",
"$",
"driver",
")",
":",
"string",
"{",
"$",
"enumValues",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"enumValues",
"as",
"$",
"value",
")",
"{",
"$",
"enumValues",
"[",
"]",
"... | In SQLServer we can emulate enums similar way as in Postgres via column constrain.
@param DriverInterface $driver
@return string | [
"In",
"SQLServer",
"we",
"can",
"emulate",
"enums",
"similar",
"way",
"as",
"in",
"Postgres",
"via",
"column",
"constrain",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLServer/Schema/SQLServerColumn.php#L337-L349 | train |
spiral/database | src/Driver/SQLServer/Schema/SQLServerColumn.php | SQLServerColumn.resolveEnum | private static function resolveEnum(
DriverInterface $driver,
array $schema,
SQLServerColumn $column
) {
$query = 'SELECT object_definition([o].[object_id]) AS [definition], '
. "OBJECT_NAME([o].[object_id]) AS [name]\nFROM [sys].[objects] AS [o]\n"
. "JOIN [sys].[sysconstraints] AS [c] ON [o].[object_id] = [c].[constid]\n"
. "WHERE [type_desc] = 'CHECK_CONSTRAINT' AND [parent_object_id] = ? AND [c].[colid] = ?";
$constraints = $driver->query($query, [$schema['object_id'], $schema['column_id']]);
foreach ($constraints as $constraint) {
$column->enumConstraint = $constraint['name'];
$column->constrainedEnum = true;
$name = preg_quote($driver->identifier($column->getName()));
//We made some assumptions here...
if (preg_match_all(
'/' . $name . '=[\']?([^\']+)[\']?/i',
$constraint['definition'],
$matches
)) {
//Fetching enum values
$column->enumValues = $matches[1];
sort($column->enumValues);
}
}
} | php | private static function resolveEnum(
DriverInterface $driver,
array $schema,
SQLServerColumn $column
) {
$query = 'SELECT object_definition([o].[object_id]) AS [definition], '
. "OBJECT_NAME([o].[object_id]) AS [name]\nFROM [sys].[objects] AS [o]\n"
. "JOIN [sys].[sysconstraints] AS [c] ON [o].[object_id] = [c].[constid]\n"
. "WHERE [type_desc] = 'CHECK_CONSTRAINT' AND [parent_object_id] = ? AND [c].[colid] = ?";
$constraints = $driver->query($query, [$schema['object_id'], $schema['column_id']]);
foreach ($constraints as $constraint) {
$column->enumConstraint = $constraint['name'];
$column->constrainedEnum = true;
$name = preg_quote($driver->identifier($column->getName()));
//We made some assumptions here...
if (preg_match_all(
'/' . $name . '=[\']?([^\']+)[\']?/i',
$constraint['definition'],
$matches
)) {
//Fetching enum values
$column->enumValues = $matches[1];
sort($column->enumValues);
}
}
} | [
"private",
"static",
"function",
"resolveEnum",
"(",
"DriverInterface",
"$",
"driver",
",",
"array",
"$",
"schema",
",",
"SQLServerColumn",
"$",
"column",
")",
"{",
"$",
"query",
"=",
"'SELECT object_definition([o].[object_id]) AS [definition], '",
".",
"\"OBJECT_NAME([... | Resolve enum values if any.
@param DriverInterface $driver
@param array $schema
@param SQLServerColumn $column | [
"Resolve",
"enum",
"values",
"if",
"any",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLServer/Schema/SQLServerColumn.php#L443-L472 | train |
spiral/database | src/Driver/Handler.php | Handler.run | protected function run(string $statement, array $parameters = []): int
{
try {
return $this->driver->execute($statement, $parameters);
} catch (StatementException $e) {
throw new HandlerException($e);
}
} | php | protected function run(string $statement, array $parameters = []): int
{
try {
return $this->driver->execute($statement, $parameters);
} catch (StatementException $e) {
throw new HandlerException($e);
}
} | [
"protected",
"function",
"run",
"(",
"string",
"$",
"statement",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
":",
"int",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"driver",
"->",
"execute",
"(",
"$",
"statement",
",",
"$",
"parameters",
... | Execute statement.
@param string $statement
@param array $parameters
@return int
@throws HandlerException | [
"Execute",
"statement",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Handler.php#L250-L257 | train |
spiral/database | src/Driver/Handler.php | Handler.identify | protected function identify($element): string
{
if (is_string($element)) {
return $this->driver->identifier($element);
}
if (!$element instanceof ElementInterface && !$element instanceof AbstractTable) {
throw new InvalidArgumentException("Invalid argument type");
}
return $this->driver->identifier($element->getName());
} | php | protected function identify($element): string
{
if (is_string($element)) {
return $this->driver->identifier($element);
}
if (!$element instanceof ElementInterface && !$element instanceof AbstractTable) {
throw new InvalidArgumentException("Invalid argument type");
}
return $this->driver->identifier($element->getName());
} | [
"protected",
"function",
"identify",
"(",
"$",
"element",
")",
":",
"string",
"{",
"if",
"(",
"is_string",
"(",
"$",
"element",
")",
")",
"{",
"return",
"$",
"this",
"->",
"driver",
"->",
"identifier",
"(",
"$",
"element",
")",
";",
"}",
"if",
"(",
... | Create element identifier.
@param ElementInterface|AbstractTable|string $element
@return string | [
"Create",
"element",
"identifier",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Handler.php#L265-L276 | train |
spiral/database | src/Driver/Quoter.php | Quoter.expression | protected function expression(string $identifier): string
{
return preg_replace_callback('/([a-z][0-9_a-z\.]*\(?)/i', function ($match) {
$identifier = $match[1];
//Function name
if ($this->hasExpressions($identifier)) {
return $identifier;
}
return $this->quote($identifier);
}, $identifier);
} | php | protected function expression(string $identifier): string
{
return preg_replace_callback('/([a-z][0-9_a-z\.]*\(?)/i', function ($match) {
$identifier = $match[1];
//Function name
if ($this->hasExpressions($identifier)) {
return $identifier;
}
return $this->quote($identifier);
}, $identifier);
} | [
"protected",
"function",
"expression",
"(",
"string",
"$",
"identifier",
")",
":",
"string",
"{",
"return",
"preg_replace_callback",
"(",
"'/([a-z][0-9_a-z\\.]*\\(?)/i'",
",",
"function",
"(",
"$",
"match",
")",
"{",
"$",
"identifier",
"=",
"$",
"match",
"[",
... | Quoting columns and tables in complex expression.
@param string $identifier
@return string | [
"Quoting",
"columns",
"and",
"tables",
"in",
"complex",
"expression",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Quoter.php#L106-L118 | train |
spiral/database | src/Driver/Quoter.php | Quoter.aliasing | protected function aliasing(string $identifier, string $alias, bool $isTable): string
{
$quoted = $this->quote($identifier, $isTable) . ' AS ' . $this->driver->identifier($alias);
if ($isTable && strpos($identifier, '.') === false) {
//We have to apply operation post factum to prevent self aliasing (name AS name)
//when db has prefix, expected: prefix_name as name)
$this->registerAlias($alias, $identifier);
}
return $quoted;
} | php | protected function aliasing(string $identifier, string $alias, bool $isTable): string
{
$quoted = $this->quote($identifier, $isTable) . ' AS ' . $this->driver->identifier($alias);
if ($isTable && strpos($identifier, '.') === false) {
//We have to apply operation post factum to prevent self aliasing (name AS name)
//when db has prefix, expected: prefix_name as name)
$this->registerAlias($alias, $identifier);
}
return $quoted;
} | [
"protected",
"function",
"aliasing",
"(",
"string",
"$",
"identifier",
",",
"string",
"$",
"alias",
",",
"bool",
"$",
"isTable",
")",
":",
"string",
"{",
"$",
"quoted",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"identifier",
",",
"$",
"isTable",
")",
... | Handle "IDENTIFIER AS ALIAS" expression.
@param string $identifier
@param string $alias
@param bool $isTable
@return string | [
"Handle",
"IDENTIFIER",
"AS",
"ALIAS",
"expression",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Quoter.php#L128-L139 | train |
spiral/database | src/Driver/Quoter.php | Quoter.hasExpressions | protected function hasExpressions(string $string): bool
{
foreach (self::STOPS as $symbol) {
if (strpos($string, $symbol) !== false) {
return true;
}
}
return false;
} | php | protected function hasExpressions(string $string): bool
{
foreach (self::STOPS as $symbol) {
if (strpos($string, $symbol) !== false) {
return true;
}
}
return false;
} | [
"protected",
"function",
"hasExpressions",
"(",
"string",
"$",
"string",
")",
":",
"bool",
"{",
"foreach",
"(",
"self",
"::",
"STOPS",
"as",
"$",
"symbol",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"string",
",",
"$",
"symbol",
")",
"!==",
"false",
")... | Check if string has expression markers.
@param string $string
@return bool | [
"Check",
"if",
"string",
"has",
"expression",
"markers",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Quoter.php#L182-L191 | train |
spiral/database | src/Driver/Postgres/Schema/PostgresColumn.php | PostgresColumn.alterOperations | public function alterOperations(DriverInterface $driver, AbstractColumn $initial): array
{
$operations = [];
//To simplify comparation
$currentType = [$this->type, $this->size, $this->precision, $this->scale];
$initialType = [$initial->type, $initial->size, $initial->precision, $initial->scale];
$identifier = $driver->identifier($this->getName());
/*
* This block defines column type and all variations.
*/
if ($currentType != $initialType) {
if ($this->getAbstractType() == 'enum') {
//Getting longest value
$enumSize = $this->size;
foreach ($this->enumValues as $value) {
$enumSize = max($enumSize, strlen($value));
}
$type = "ALTER COLUMN {$identifier} TYPE character varying($enumSize)";
$operations[] = $type;
} else {
$type = "ALTER COLUMN {$identifier} TYPE {$this->type}";
if (!empty($this->size)) {
$type .= "($this->size)";
} elseif (!empty($this->precision)) {
$type .= "($this->precision, $this->scale)";
}
//Required to perform cross conversion
$operations[] = "{$type} USING {$identifier}::{$this->type}";
}
}
//Dropping enum constrain before any operation
if ($initial->getAbstractType() == 'enum' && $this->constrained) {
$operations[] = 'DROP CONSTRAINT ' . $driver->identifier($this->enumConstraint());
}
//Default value set and dropping
if ($initial->defaultValue != $this->defaultValue) {
if (is_null($this->defaultValue)) {
$operations[] = "ALTER COLUMN {$identifier} DROP DEFAULT";
} else {
$operations[] = "ALTER COLUMN {$identifier} SET DEFAULT {$this->quoteDefault($driver)}";
}
}
//Nullable option
if ($initial->nullable != $this->nullable) {
$operations[] = "ALTER COLUMN {$identifier} " . (!$this->nullable ? 'SET' : 'DROP') . ' NOT NULL';
}
if ($this->getAbstractType() == 'enum') {
$enumValues = [];
foreach ($this->enumValues as $value) {
$enumValues[] = $driver->quote($value);
}
$operations[] = "ADD CONSTRAINT {$driver->identifier($this->enumConstraint())} "
. "CHECK ({$identifier} IN (" . implode(', ', $enumValues) . '))';
}
return $operations;
} | php | public function alterOperations(DriverInterface $driver, AbstractColumn $initial): array
{
$operations = [];
//To simplify comparation
$currentType = [$this->type, $this->size, $this->precision, $this->scale];
$initialType = [$initial->type, $initial->size, $initial->precision, $initial->scale];
$identifier = $driver->identifier($this->getName());
/*
* This block defines column type and all variations.
*/
if ($currentType != $initialType) {
if ($this->getAbstractType() == 'enum') {
//Getting longest value
$enumSize = $this->size;
foreach ($this->enumValues as $value) {
$enumSize = max($enumSize, strlen($value));
}
$type = "ALTER COLUMN {$identifier} TYPE character varying($enumSize)";
$operations[] = $type;
} else {
$type = "ALTER COLUMN {$identifier} TYPE {$this->type}";
if (!empty($this->size)) {
$type .= "($this->size)";
} elseif (!empty($this->precision)) {
$type .= "($this->precision, $this->scale)";
}
//Required to perform cross conversion
$operations[] = "{$type} USING {$identifier}::{$this->type}";
}
}
//Dropping enum constrain before any operation
if ($initial->getAbstractType() == 'enum' && $this->constrained) {
$operations[] = 'DROP CONSTRAINT ' . $driver->identifier($this->enumConstraint());
}
//Default value set and dropping
if ($initial->defaultValue != $this->defaultValue) {
if (is_null($this->defaultValue)) {
$operations[] = "ALTER COLUMN {$identifier} DROP DEFAULT";
} else {
$operations[] = "ALTER COLUMN {$identifier} SET DEFAULT {$this->quoteDefault($driver)}";
}
}
//Nullable option
if ($initial->nullable != $this->nullable) {
$operations[] = "ALTER COLUMN {$identifier} " . (!$this->nullable ? 'SET' : 'DROP') . ' NOT NULL';
}
if ($this->getAbstractType() == 'enum') {
$enumValues = [];
foreach ($this->enumValues as $value) {
$enumValues[] = $driver->quote($value);
}
$operations[] = "ADD CONSTRAINT {$driver->identifier($this->enumConstraint())} "
. "CHECK ({$identifier} IN (" . implode(', ', $enumValues) . '))';
}
return $operations;
} | [
"public",
"function",
"alterOperations",
"(",
"DriverInterface",
"$",
"driver",
",",
"AbstractColumn",
"$",
"initial",
")",
":",
"array",
"{",
"$",
"operations",
"=",
"[",
"]",
";",
"//To simplify comparation",
"$",
"currentType",
"=",
"[",
"$",
"this",
"->",
... | Generate set of operations need to change column.
@param DriverInterface $driver
@param AbstractColumn $initial
@return array | [
"Generate",
"set",
"of",
"operations",
"need",
"to",
"change",
"column",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Postgres/Schema/PostgresColumn.php#L229-L296 | train |
spiral/database | src/Driver/Postgres/Schema/PostgresColumn.php | PostgresColumn.resolveConstrains | private static function resolveConstrains(
DriverInterface $driver,
$tableOID,
PostgresColumn $column
) {
$query = "SELECT conname, consrc FROM pg_constraint WHERE conrelid = ? AND contype = 'c' AND "
. "(consrc LIKE ? OR consrc LIKE ? OR consrc LIKE ? OR consrc LIKE ? OR consrc LIKE ? OR consrc LIKE ?)";
$constraints = $driver->query($query, [
$tableOID,
'(' . $column->name . '%',
'("' . $column->name . '%',
'(("' . $column->name . '%',
'(("' . $column->name . '%',
//Postgres magic
$column->name . '::text%',
'%(' . $column->name . ')::text%'
]);
foreach ($constraints as $constraint) {
if (preg_match('/ARRAY\[([^\]]+)\]/', $constraint['consrc'], $matches)) {
$enumValues = explode(',', $matches[1]);
foreach ($enumValues as &$value) {
if (preg_match("/^'?(.*?)'?::(.+)/", trim($value, ' ()'), $matches)) {
//In database: 'value'::TYPE
$value = $matches[1];
}
unset($value);
}
$column->enumValues = $enumValues;
$column->constrainName = $constraint['conname'];
$column->constrained = true;
}
}
} | php | private static function resolveConstrains(
DriverInterface $driver,
$tableOID,
PostgresColumn $column
) {
$query = "SELECT conname, consrc FROM pg_constraint WHERE conrelid = ? AND contype = 'c' AND "
. "(consrc LIKE ? OR consrc LIKE ? OR consrc LIKE ? OR consrc LIKE ? OR consrc LIKE ? OR consrc LIKE ?)";
$constraints = $driver->query($query, [
$tableOID,
'(' . $column->name . '%',
'("' . $column->name . '%',
'(("' . $column->name . '%',
'(("' . $column->name . '%',
//Postgres magic
$column->name . '::text%',
'%(' . $column->name . ')::text%'
]);
foreach ($constraints as $constraint) {
if (preg_match('/ARRAY\[([^\]]+)\]/', $constraint['consrc'], $matches)) {
$enumValues = explode(',', $matches[1]);
foreach ($enumValues as &$value) {
if (preg_match("/^'?(.*?)'?::(.+)/", trim($value, ' ()'), $matches)) {
//In database: 'value'::TYPE
$value = $matches[1];
}
unset($value);
}
$column->enumValues = $enumValues;
$column->constrainName = $constraint['conname'];
$column->constrained = true;
}
}
} | [
"private",
"static",
"function",
"resolveConstrains",
"(",
"DriverInterface",
"$",
"driver",
",",
"$",
"tableOID",
",",
"PostgresColumn",
"$",
"column",
")",
"{",
"$",
"query",
"=",
"\"SELECT conname, consrc FROM pg_constraint WHERE conrelid = ? AND contype = 'c' AND \"",
"... | Resolving enum constrain and converting it into proper enum values set.
@param DriverInterface $driver
@param string|int $tableOID
@param PostgresColumn $column | [
"Resolving",
"enum",
"constrain",
"and",
"converting",
"it",
"into",
"proper",
"enum",
"values",
"set",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Postgres/Schema/PostgresColumn.php#L415-L451 | train |
spiral/database | src/Driver/Postgres/Schema/PostgresColumn.php | PostgresColumn.resolveEnum | private static function resolveEnum(DriverInterface $driver, PostgresColumn $column)
{
$range = $driver->query('SELECT enum_range(NULL::' . $column->type . ')')->fetchColumn(0);
$column->enumValues = explode(',', substr($range, 1, -1));
if (!empty($column->defaultValue)) {
//In database: 'value'::enumType
$column->defaultValue = substr(
$column->defaultValue,
1,
strpos($column->defaultValue, $column->type) - 4
);
}
} | php | private static function resolveEnum(DriverInterface $driver, PostgresColumn $column)
{
$range = $driver->query('SELECT enum_range(NULL::' . $column->type . ')')->fetchColumn(0);
$column->enumValues = explode(',', substr($range, 1, -1));
if (!empty($column->defaultValue)) {
//In database: 'value'::enumType
$column->defaultValue = substr(
$column->defaultValue,
1,
strpos($column->defaultValue, $column->type) - 4
);
}
} | [
"private",
"static",
"function",
"resolveEnum",
"(",
"DriverInterface",
"$",
"driver",
",",
"PostgresColumn",
"$",
"column",
")",
"{",
"$",
"range",
"=",
"$",
"driver",
"->",
"query",
"(",
"'SELECT enum_range(NULL::'",
".",
"$",
"column",
"->",
"type",
".",
... | Resolve native ENUM type if presented.
@param DriverInterface $driver
@param PostgresColumn $column | [
"Resolve",
"native",
"ENUM",
"type",
"if",
"presented",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Postgres/Schema/PostgresColumn.php#L459-L473 | train |
spiral/database | src/Driver/Postgres/PostgresDriver.php | PostgresDriver.getPrimary | public function getPrimary(string $prefix, string $table): ?string
{
$name = $prefix . $table;
if (array_key_exists($name, $this->primaryKeys)) {
return $this->primaryKeys[$name];
}
if (!$this->hasTable($name)) {
throw new DriverException(
"Unable to fetch table primary key, no such table '{$name}' exists"
);
}
$this->primaryKeys[$name] = $this->getSchema($table, $prefix)->getPrimaryKeys();
if (count($this->primaryKeys[$name]) === 1) {
//We do support only single primary key
$this->primaryKeys[$name] = $this->primaryKeys[$name][0];
} else {
$this->primaryKeys[$name] = null;
}
return $this->primaryKeys[$name];
} | php | public function getPrimary(string $prefix, string $table): ?string
{
$name = $prefix . $table;
if (array_key_exists($name, $this->primaryKeys)) {
return $this->primaryKeys[$name];
}
if (!$this->hasTable($name)) {
throw new DriverException(
"Unable to fetch table primary key, no such table '{$name}' exists"
);
}
$this->primaryKeys[$name] = $this->getSchema($table, $prefix)->getPrimaryKeys();
if (count($this->primaryKeys[$name]) === 1) {
//We do support only single primary key
$this->primaryKeys[$name] = $this->primaryKeys[$name][0];
} else {
$this->primaryKeys[$name] = null;
}
return $this->primaryKeys[$name];
} | [
"public",
"function",
"getPrimary",
"(",
"string",
"$",
"prefix",
",",
"string",
"$",
"table",
")",
":",
"?",
"string",
"{",
"$",
"name",
"=",
"$",
"prefix",
".",
"$",
"table",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
... | Get singular primary key associated with desired table. Used to emulate last insert id.
@param string $prefix Database prefix if any.
@param string $table Fully specified table name, including postfix.
@return string|null
@throws DriverException | [
"Get",
"singular",
"primary",
"key",
"associated",
"with",
"desired",
"table",
".",
"Used",
"to",
"emulate",
"last",
"insert",
"id",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/Postgres/PostgresDriver.php#L81-L103 | train |
spiral/database | src/Schema/AbstractForeignKey.php | AbstractForeignKey.references | public function references(
string $table,
string $column = 'id',
bool $forcePrefix = true
): AbstractForeignKey {
$this->foreignTable = ($forcePrefix ? $this->tablePrefix : '') . $table;
$this->foreignKey = $column;
return $this;
} | php | public function references(
string $table,
string $column = 'id',
bool $forcePrefix = true
): AbstractForeignKey {
$this->foreignTable = ($forcePrefix ? $this->tablePrefix : '') . $table;
$this->foreignKey = $column;
return $this;
} | [
"public",
"function",
"references",
"(",
"string",
"$",
"table",
",",
"string",
"$",
"column",
"=",
"'id'",
",",
"bool",
"$",
"forcePrefix",
"=",
"true",
")",
":",
"AbstractForeignKey",
"{",
"$",
"this",
"->",
"foreignTable",
"=",
"(",
"$",
"forcePrefix",
... | Set foreign table name and key local column must reference to. Make sure local and foreign
column types are identical.
@param string $table Foreign table name with or without database prefix (see 3rd
argument).
@param string $column Foreign key name (id by default).
@param bool $forcePrefix When true foreign table will get same prefix as table being
modified.
@return self | [
"Set",
"foreign",
"table",
"name",
"and",
"key",
"local",
"column",
"must",
"reference",
"to",
".",
"Make",
"sure",
"local",
"and",
"foreign",
"column",
"types",
"are",
"identical",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractForeignKey.php#L144-L153 | train |
spiral/database | src/Schema/AbstractForeignKey.php | AbstractForeignKey.onDelete | public function onDelete(string $rule = self::NO_ACTION): AbstractForeignKey
{
$this->deleteRule = strtoupper($rule);
return $this;
} | php | public function onDelete(string $rule = self::NO_ACTION): AbstractForeignKey
{
$this->deleteRule = strtoupper($rule);
return $this;
} | [
"public",
"function",
"onDelete",
"(",
"string",
"$",
"rule",
"=",
"self",
"::",
"NO_ACTION",
")",
":",
"AbstractForeignKey",
"{",
"$",
"this",
"->",
"deleteRule",
"=",
"strtoupper",
"(",
"$",
"rule",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set foreign key delete behaviour.
@param string $rule Possible values: NO ACTION, CASCADE, etc (driver specific).
@return self | [
"Set",
"foreign",
"key",
"delete",
"behaviour",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractForeignKey.php#L161-L166 | train |
spiral/database | src/Schema/AbstractForeignKey.php | AbstractForeignKey.onUpdate | public function onUpdate(string $rule = self::NO_ACTION): AbstractForeignKey
{
$this->updateRule = strtoupper($rule);
return $this;
} | php | public function onUpdate(string $rule = self::NO_ACTION): AbstractForeignKey
{
$this->updateRule = strtoupper($rule);
return $this;
} | [
"public",
"function",
"onUpdate",
"(",
"string",
"$",
"rule",
"=",
"self",
"::",
"NO_ACTION",
")",
":",
"AbstractForeignKey",
"{",
"$",
"this",
"->",
"updateRule",
"=",
"strtoupper",
"(",
"$",
"rule",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set foreign key update behaviour.
@param string $rule Possible values: NO ACTION, CASCADE, etc (driver specific).
@return self | [
"Set",
"foreign",
"key",
"update",
"behaviour",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Schema/AbstractForeignKey.php#L174-L179 | train |
spiral/database | src/Driver/SQLite/Schema/SQLiteForeign.php | SQLiteForeign.compare | public function compare(AbstractForeignKey $initial): bool
{
return $this->getColumn() == $initial->getColumn()
&& $this->getForeignTable() == $initial->getForeignTable()
&& $this->getForeignKey() == $initial->getForeignKey()
&& $this->getUpdateRule() == $initial->getUpdateRule()
&& $this->getDeleteRule() == $initial->getDeleteRule();
} | php | public function compare(AbstractForeignKey $initial): bool
{
return $this->getColumn() == $initial->getColumn()
&& $this->getForeignTable() == $initial->getForeignTable()
&& $this->getForeignKey() == $initial->getForeignKey()
&& $this->getUpdateRule() == $initial->getUpdateRule()
&& $this->getDeleteRule() == $initial->getDeleteRule();
} | [
"public",
"function",
"compare",
"(",
"AbstractForeignKey",
"$",
"initial",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"getColumn",
"(",
")",
"==",
"$",
"initial",
"->",
"getColumn",
"(",
")",
"&&",
"$",
"this",
"->",
"getForeignTable",
"(",
")"... | Name insensitive compare.
@param AbstractForeignKey $initial
@return bool | [
"Name",
"insensitive",
"compare",
"."
] | 93a6010feadf24a41af39c46346737d5c532e57f | https://github.com/spiral/database/blob/93a6010feadf24a41af39c46346737d5c532e57f/src/Driver/SQLite/Schema/SQLiteForeign.php#L52-L59 | train |
gamajo/genesis-theme-toolkit | src/Layouts.php | Layouts.apply | public function apply()
{
if ($this->config->hasKey(self::REGISTER)) {
$registerConfig = $this->config->getSubConfig(self::REGISTER);
$this->register($registerConfig->getArrayCopy());
}
if ($this->config->hasKey(self::UNREGISTER)) {
$unregisterConfig = $this->config->getSubConfig(self::UNREGISTER);
$this->unregister($unregisterConfig->getArrayCopy());
}
if ($this->config->hasKey(self::DEFAULTLAYOUT)) {
$this->setDefault($this->config->getKey(self::DEFAULTLAYOUT));
}
} | php | public function apply()
{
if ($this->config->hasKey(self::REGISTER)) {
$registerConfig = $this->config->getSubConfig(self::REGISTER);
$this->register($registerConfig->getArrayCopy());
}
if ($this->config->hasKey(self::UNREGISTER)) {
$unregisterConfig = $this->config->getSubConfig(self::UNREGISTER);
$this->unregister($unregisterConfig->getArrayCopy());
}
if ($this->config->hasKey(self::DEFAULTLAYOUT)) {
$this->setDefault($this->config->getKey(self::DEFAULTLAYOUT));
}
} | [
"public",
"function",
"apply",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"hasKey",
"(",
"self",
"::",
"REGISTER",
")",
")",
"{",
"$",
"registerConfig",
"=",
"$",
"this",
"->",
"config",
"->",
"getSubConfig",
"(",
"self",
"::",
"REG... | Apply layout registrations and unregistrations. | [
"Apply",
"layout",
"registrations",
"and",
"unregistrations",
"."
] | 051bf78f75f71ebbfdcf3cad2935fd5d5abbc9ff | https://github.com/gamajo/genesis-theme-toolkit/blob/051bf78f75f71ebbfdcf3cad2935fd5d5abbc9ff/src/Layouts.php#L63-L78 | train |
gamajo/genesis-theme-toolkit | src/Layouts.php | Layouts.register | protected function register(array $args)
{
array_walk($args, function (array $value, string $key) {
\genesis_register_layout($key, $value);
});
} | php | protected function register(array $args)
{
array_walk($args, function (array $value, string $key) {
\genesis_register_layout($key, $value);
});
} | [
"protected",
"function",
"register",
"(",
"array",
"$",
"args",
")",
"{",
"array_walk",
"(",
"$",
"args",
",",
"function",
"(",
"array",
"$",
"value",
",",
"string",
"$",
"key",
")",
"{",
"\\",
"genesis_register_layout",
"(",
"$",
"key",
",",
"$",
"val... | Register a new Genesis layout for given keys and values.
@param array $args Keys and their values. | [
"Register",
"a",
"new",
"Genesis",
"layout",
"for",
"given",
"keys",
"and",
"values",
"."
] | 051bf78f75f71ebbfdcf3cad2935fd5d5abbc9ff | https://github.com/gamajo/genesis-theme-toolkit/blob/051bf78f75f71ebbfdcf3cad2935fd5d5abbc9ff/src/Layouts.php#L85-L90 | train |
php-yaoi/php-yaoi | src/Service.php | Service.getInstance | public static function getInstance($identifier = self::PRIMARY)
{
$serviceClassName = get_called_class();
return self::findOrCreateInstance($serviceClassName, $identifier);
} | php | public static function getInstance($identifier = self::PRIMARY)
{
$serviceClassName = get_called_class();
return self::findOrCreateInstance($serviceClassName, $identifier);
} | [
"public",
"static",
"function",
"getInstance",
"(",
"$",
"identifier",
"=",
"self",
"::",
"PRIMARY",
")",
"{",
"$",
"serviceClassName",
"=",
"get_called_class",
"(",
")",
";",
"return",
"self",
"::",
"findOrCreateInstance",
"(",
"$",
"serviceClassName",
",",
"... | Returns client instance
@param string|Service|Settings|Closure $identifier
@return static
@throws Service\Exception
fallback instead default | [
"Returns",
"client",
"instance"
] | 5be99ff5757e11af01ed1cc3dbabf0438100f94e | https://github.com/php-yaoi/php-yaoi/blob/5be99ff5757e11af01ed1cc3dbabf0438100f94e/src/Service.php#L169-L175 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.