Skip to content

Commit

Permalink
refactor(database): improve schema listing logic and cleanup
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
phodal committed Jan 19, 2025
1 parent af668ee commit 7f9c251
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,6 @@ project(":goland") {
intellijPlatform {
intellijIde(prop("ideaVersion"))
intellijPlugins(prop("goPlugin").split(',').map(String::trim).filter(String::isNotEmpty))

testFramework(TestFrameworkType.Bundled)
}

implementation(project(":core"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S

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

ApplicationManager.getApplication().invokeAndWait {
ApplicationManager.getApplication().invokeLater {
if (filePatches.isEmpty()) {
AutoDevNotifications.error(myProject, "PatchProcessor: no patches found")
return@invokeAndWait
return@invokeLater
}

filePatches.forEachIndexed { _, patch ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package cc.unitmesh.database.provider

import cc.unitmesh.database.provider.DatabaseFunction.values
import cc.unitmesh.database.util.DatabaseSchemaAssistant
import cc.unitmesh.database.util.DatabaseSchemaAssistant.getTableColumn
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
import com.intellij.database.model.DasTable
import com.intellij.database.model.RawDataSource
import com.intellij.database.util.DasUtil
import com.intellij.database.util.DbUtil
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project

Expand Down Expand Up @@ -47,11 +47,19 @@ class DatabaseFunctionProvider : ToolchainFunctionProvider {
}

private fun listSchemas(args: List<Any>, project: Project): Any {
return DatabaseSchemaAssistant.allRawDatasource(project).map {
DasUtil.getTables(it).toList().map<DasTable, String> {
val dataSources = DbUtil.getDataSources(project)
if (dataSources.isEmpty) return ""

return dataSources.mapNotNull {
val tableSchema = DasUtil.getTables(it).toList().mapNotNull<DasTable, String> {
if (it.dasParent?.name == "information_schema") return@mapNotNull null
getTableColumn(it)
}
}.flatten()

if (tableSchema.isEmpty()) return@mapNotNull null
val name = it.name.substringBeforeLast('@')
"DATABASE NAME: ${name};\n${tableSchema.joinToString("\n")}"
}.joinToString("\n")
}

private fun executeTableFunction(args: List<Any>, project: Project): Any {
Expand Down Expand Up @@ -98,6 +106,7 @@ class DatabaseFunctionProvider : ToolchainFunctionProvider {
val sqlQuery = args.first()
return DatabaseSchemaAssistant.executeSqlQuery(project, sqlQuery as String)
}

private fun executeColumnFunction(args: List<Any>, project: Project): Any {
if (args.isEmpty()) {
val allTables = DatabaseSchemaAssistant.getAllTables(project)
Expand Down

0 comments on commit 7f9c251

Please sign in to comment.