Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into refactor-geRawSql
Browse files Browse the repository at this point in the history
vjik authored Nov 26, 2023
2 parents 06a48b7 + f06cf26 commit 5d7dd21
Showing 4 changed files with 11 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,9 @@
- Enh #778: Deprecate unnecessary argument `$rawSql` of `AbstractCommand::internalExecute()` (@Tigrov)
- Enh #785: Refactor `AbstractCommand::getRawSql()` (@Tigrov)
- Bug #785: Fix bug of `AbstractCommand::getRawSql()` when a param value is `Stringable` object (@Tigrov)
- Enh #786: Refactor `AbstractSchema::getDataType()` (@Tigrov)
- Enh #784: Specify result type of `ConstraintSchemaInterface::getTableIndexes()` method to `IndexConstraint[]` (@vjik)
- Enh #784: Remove unused code in `AbstractSchema::getTableIndexes()` (@vjik)

## 1.2.0 November 12, 2023

2 changes: 1 addition & 1 deletion src/Constraint/ConstraintSchemaInterface.php
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ public function getTableForeignKeys(string $name, bool $refresh = false): array;
* @param string $name Table name. The table name may contain a schema name if any. Don't quote the table name.
* @param bool $refresh Whether to reload the information, even if it's found in the cache.
*
* @return array The information metadata for the indexes of the named table.
* @return IndexConstraint[] The information metadata for the indexes of the named table.
*/
public function getTableIndexes(string $name, bool $refresh = false): array;

2 changes: 0 additions & 2 deletions src/QueryBuilder/AbstractDMLQueryBuilder.php
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@

use JsonException;
use Yiisoft\Db\Constraint\Constraint;
use Yiisoft\Db\Constraint\IndexConstraint;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidConfigException;
@@ -335,7 +334,6 @@ private function getTableUniqueColumnNames(string $name, array $columns, array &
$constraints[] = $primaryKey;
}

/** @psalm-var IndexConstraint[] $tableIndexes */
$tableIndexes = $this->schema->getTableIndexes($name);

foreach ($tableIndexes as $constraint) {
19 changes: 7 additions & 12 deletions src/Schema/AbstractSchema.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
use Yiisoft\Db\Command\DataType;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Constraint\Constraint;
use Yiisoft\Db\Constraint\IndexConstraint;
use Yiisoft\Db\Exception\NotSupportedException;

use function array_change_key_case;
@@ -95,7 +96,7 @@ abstract protected function loadTableForeignKeys(string $tableName): array;
*
* @param string $tableName The table name.
*
* @return array The indexes for the given table.
* @return IndexConstraint[] The indexes for the given table.
*/
abstract protected function loadTableIndexes(string $tableName): array;

@@ -133,19 +134,14 @@ public function getDefaultSchema(): string|null

public function getDataType(mixed $data): int
{
/** @psalm-var array<string, int> $typeMap */
$typeMap = [
return match (gettype($data)) {
// php type => SQL data type
SchemaInterface::PHP_TYPE_BOOLEAN => DataType::BOOLEAN,
SchemaInterface::PHP_TYPE_INTEGER => DataType::INTEGER,
SchemaInterface::PHP_TYPE_STRING => DataType::STRING,
SchemaInterface::PHP_TYPE_RESOURCE => DataType::LOB,
SchemaInterface::PHP_TYPE_NULL => DataType::NULL,
];

$type = gettype($data);

return $typeMap[$type] ?? DataType::STRING;
default => DataType::STRING,
};
}

public function getRawTableName(string $name): string
@@ -261,9 +257,8 @@ public function getTableForeignKeys(string $name, bool $refresh = false): array
*/
public function getTableIndexes(string $name, bool $refresh = false): array
{
/** @psalm-var mixed $tableIndexes */
$tableIndexes = $this->getTableMetadata($name, SchemaInterface::INDEXES, $refresh);
return is_array($tableIndexes) ? $tableIndexes : [];
/** @var IndexConstraint[] */
return $this->getTableMetadata($name, SchemaInterface::INDEXES, $refresh);
}

/**

0 comments on commit 5d7dd21

Please sign in to comment.