Skip to content

Commit 7f9c251

Browse files
committed
refactor(database): improve schema listing logic and cleanup
- Replace `DatabaseSchemaAssistant.allRawDatasource` with `DbUtil.getDataSources` for schema listing. - Filter out `information_schema` tables and handle empty schemas. - Format schema output with database name and table details. - Remove unused import and test framework configuration. - Change `invokeAndWait` to `invokeLater` in `DiffLangSketch` for better UI responsiveness.
1 parent af668ee commit 7f9c251

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,6 @@ project(":goland") {
522522
intellijPlatform {
523523
intellijIde(prop("ideaVersion"))
524524
intellijPlugins(prop("goPlugin").split(',').map(String::trim).filter(String::isNotEmpty))
525-
526-
testFramework(TestFrameworkType.Bundled)
527525
}
528526

529527
implementation(project(":core"))

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/patch/DiffLangSketch.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S
5353

5454
mainPanel.border = JBUI.Borders.compound(JBUI.Borders.empty(0, 10))
5555

56-
ApplicationManager.getApplication().invokeAndWait {
56+
ApplicationManager.getApplication().invokeLater {
5757
if (filePatches.isEmpty()) {
5858
AutoDevNotifications.error(myProject, "PatchProcessor: no patches found")
59-
return@invokeAndWait
59+
return@invokeLater
6060
}
6161

6262
filePatches.forEachIndexed { _, patch ->

exts/ext-database/src/main/kotlin/cc/unitmesh/database/provider/DatabaseFunctionProvider.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package cc.unitmesh.database.provider
22

3-
import cc.unitmesh.database.provider.DatabaseFunction.values
43
import cc.unitmesh.database.util.DatabaseSchemaAssistant
54
import cc.unitmesh.database.util.DatabaseSchemaAssistant.getTableColumn
65
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
76
import com.intellij.database.model.DasTable
87
import com.intellij.database.model.RawDataSource
98
import com.intellij.database.util.DasUtil
9+
import com.intellij.database.util.DbUtil
1010
import com.intellij.openapi.diagnostic.logger
1111
import com.intellij.openapi.project.Project
1212

@@ -47,11 +47,19 @@ class DatabaseFunctionProvider : ToolchainFunctionProvider {
4747
}
4848

4949
private fun listSchemas(args: List<Any>, project: Project): Any {
50-
return DatabaseSchemaAssistant.allRawDatasource(project).map {
51-
DasUtil.getTables(it).toList().map<DasTable, String> {
50+
val dataSources = DbUtil.getDataSources(project)
51+
if (dataSources.isEmpty) return ""
52+
53+
return dataSources.mapNotNull {
54+
val tableSchema = DasUtil.getTables(it).toList().mapNotNull<DasTable, String> {
55+
if (it.dasParent?.name == "information_schema") return@mapNotNull null
5256
getTableColumn(it)
5357
}
54-
}.flatten()
58+
59+
if (tableSchema.isEmpty()) return@mapNotNull null
60+
val name = it.name.substringBeforeLast('@')
61+
"DATABASE NAME: ${name};\n${tableSchema.joinToString("\n")}"
62+
}.joinToString("\n")
5563
}
5664

5765
private fun executeTableFunction(args: List<Any>, project: Project): Any {
@@ -98,6 +106,7 @@ class DatabaseFunctionProvider : ToolchainFunctionProvider {
98106
val sqlQuery = args.first()
99107
return DatabaseSchemaAssistant.executeSqlQuery(project, sqlQuery as String)
100108
}
109+
101110
private fun executeColumnFunction(args: List<Any>, project: Project): Any {
102111
if (args.isEmpty()) {
103112
val allTables = DatabaseSchemaAssistant.getAllTables(project)

0 commit comments

Comments
 (0)