protected function JsonItemTest::getTableIndexes in JSON Field 8
Adds primary key, unique keys, and index information to the schema.
Parameters
\Drupal\Core\Database\Connection $connection: The database connection to use.
string $table: The table to find indexes for.
array &$definition: The schema definition to modify.
1 call to JsonItemTest::getTableIndexes()
- JsonItemTest::getTableSchema in tests/
src/ Kernel/ JsonItemTest.php
File
- tests/
src/ Kernel/ JsonItemTest.php, line 247
Class
- JsonItemTest
- @coversDefaultClass \Drupal\json_field\Plugin\Field\FieldType\JSONItem
Namespace
Drupal\Tests\json_field\KernelCode
protected function getTableIndexes(Connection $connection, $table, &$definition) {
// Note, this query doesn't support ordering, so that is worked around
// below by keying the array on Seq_in_index.
$query = $connection
->query("SHOW INDEX FROM {" . $table . "}");
while (($row = $query
->fetchAssoc()) !== FALSE) {
$index_name = $row['Key_name'];
$column = $row['Column_name'];
// Key the arrays by the index sequence for proper ordering (start at 0).
$order = $row['Seq_in_index'] - 1;
// If specified, add length to the index.
if ($row['Sub_part']) {
$column = [
$column,
$row['Sub_part'],
];
}
if ($index_name === 'PRIMARY') {
$definition['primary key'][$order] = $column;
}
elseif ($row['Non_unique'] == 0) {
$definition['unique keys'][$index_name][$order] = $column;
}
else {
$definition['indexes'][$index_name][$order] = $column;
}
}
}