findIndexesNamesInUse method
Index names are unique per table: the ones of table (also the
indexes that TableScheme.indexes ignores, e.g. prefix indexes).
Implementation
@override
FutureOr<Map<String, String?>?> findIndexesNamesInUse(
String table,
Iterable<String> indexesNames,
) {
var names = indexesNames
.map((n) => "'${n.replaceAll("'", "''")}'")
.join(', ');
if (names.isEmpty) return <String, String?>{};
var sql =
"SELECT DISTINCT INDEX_NAME AS index_name "
"FROM information_schema.STATISTICS "
"WHERE TABLE_SCHEMA = DATABASE() "
"AND TABLE_NAME = '${table.replaceAll("'", "''")}' "
"AND INDEX_NAME IN ($names)";
return executeWithPool(
(connection) => connection
.query(sql)
.then(
(results) => <String, String?>{
for (var row in results) row['index_name'].toString(): table,
},
),
);
}