Skip to content

Commit d2d2320

Browse files
authored
fix: sort table list by name in MongoDb, BigQuery, DynamoDB, MySql. In other DB driver, the table list is already sorted (#554)
1 parent 1e64430 commit d2d2320

4 files changed

Lines changed: 9 additions & 7 deletions

File tree

Plugins/BigQueryDriverPlugin/BigQueryPluginDriver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ internal final class BigQueryPluginDriver: PluginDatabaseDriver, @unchecked Send
394394
tableType = "TABLE"
395395
}
396396
return PluginTableInfo(name: entry.tableReference.tableId, type: tableType)
397-
}
397+
}.sorted { $0.name.localizedCaseInsensitiveCompare($1.name) == .orderedAscending }
398398
}
399399

400400
func fetchColumns(table: String, schema: String?) async throws -> [PluginColumnInfo] {

Plugins/DynamoDBDriverPlugin/DynamoDBPluginDriver.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,10 @@ internal final class DynamoDBPluginDriver: PluginDatabaseDriver, @unchecked Send
280280
} while lastEvaluated != nil
281281

282282
Self.logger.debug("fetchTables found \(allTableNames.count) tables")
283-
return allTableNames.map { name in
284-
PluginTableInfo(name: name, type: "TABLE")
285-
}
283+
return allTableNames.sorted { $0.localizedCaseInsensitiveCompare($1) == .orderedAscending }
284+
.map { name in
285+
PluginTableInfo(name: name, type: "TABLE")
286+
}
286287
} catch {
287288
Self.logger.error("fetchTables error: \(error.localizedDescription)")
288289
throw error

Plugins/MongoDBDriverPlugin/MongoDBPluginDriver.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ final class MongoDBPluginDriver: PluginDatabaseDriver {
194194
}
195195

196196
let collections = try await conn.listCollections(database: currentDb)
197-
return collections.map { PluginTableInfo(name: $0, type: "table", rowCount: nil) }
197+
return collections.sorted(by: { $0.localizedCaseInsensitiveCompare($1) == .orderedAscending })
198+
.map { PluginTableInfo(name: $0, type: "table", rowCount: nil) }
198199
}
199200

200201
func fetchColumns(table: String, schema: String?) async throws -> [PluginColumnInfo] {

Plugins/MySQLDriverPlugin/MySQLPluginDriver.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ final class MySQLPluginDriver: PluginDatabaseDriver, @unchecked Sendable {
177177
func fetchTables(schema: String?) async throws -> [PluginTableInfo] {
178178
let result = try await execute(query: "SHOW FULL TABLES")
179179

180-
return result.rows.compactMap { row in
180+
return result.rows.compactMap { row -> PluginTableInfo? in
181181
guard let name = row[safe: 0] ?? nil else { return nil }
182182
let typeStr = (row[safe: 1] ?? nil) ?? "BASE TABLE"
183183
let type = typeStr.contains("VIEW") ? "VIEW" : "TABLE"
184184
return PluginTableInfo(name: name, type: type)
185-
}
185+
}.sorted { $0.name.localizedCaseInsensitiveCompare($1.name) == .orderedAscending }
186186
}
187187

188188
func fetchColumns(table: String, schema: String?) async throws -> [PluginColumnInfo] {

0 commit comments

Comments
 (0)