Skip to content

Commit 66880e2

Browse files
committed
refactor(database): change return type to String and format output
Updated `listSchemas` and `executeTableFunction` methods to return `String` instead of `Any`. Formatted table results using `joinToString` for consistent output.
1 parent d8b8c0d commit 66880e2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class DatabaseFunctionProvider : ToolchainFunctionProvider {
4040
}
4141
}
4242

43-
private fun listSchemas(args: List<Any>, project: Project): Any {
43+
private fun listSchemas(args: List<Any>, project: Project): String {
4444
val dataSources = DbUtil.getDataSources(project)
4545
if (dataSources.isEmpty) return "[Database]: No database found"
4646

@@ -60,11 +60,13 @@ class DatabaseFunctionProvider : ToolchainFunctionProvider {
6060
return dataItems.joinToString("\n")
6161
}
6262

63-
private fun executeTableFunction(args: List<Any>, project: Project): Any {
63+
private fun executeTableFunction(args: List<Any>, project: Project): String {
6464
if (args.isEmpty()) {
6565
val dataSource = DatabaseSchemaAssistant.allRawDatasource(project).firstOrNull()
6666
?: return "[Database]: No database found"
67-
return DatabaseSchemaAssistant.getTableByDataSource(dataSource)
67+
return DatabaseSchemaAssistant.getTableByDataSource(dataSource).joinToString("\n") {
68+
it.toString()
69+
}
6870
}
6971

7072
val dbName = args.first()
@@ -97,7 +99,9 @@ class DatabaseFunctionProvider : ToolchainFunctionProvider {
9799
return "[Database]: Table not found"
98100
}
99101

100-
return result
102+
return result.joinToString("\n") {
103+
it.toString()
104+
}
101105
}
102106

103107
private fun executeSqlFunction(args: List<Any>, project: Project): Any {

0 commit comments

Comments
 (0)