@@ -31,31 +31,27 @@ import com.intellij.openapi.application.ApplicationManager
31
31
import com.intellij.openapi.editor.ex.EditorEx
32
32
import com.intellij.openapi.fileEditor.FileEditorManager
33
33
import com.intellij.openapi.project.Project
34
- import com.intellij.openapi.util.Disposer
35
34
import com.intellij.psi.PsiManager
36
35
import com.intellij.sql.psi.SqlPsiFacade
37
36
import com.intellij.testFramework.LightVirtualFile
38
37
import java.util.concurrent.CompletableFuture
39
38
40
39
object DatabaseSchemaAssistant {
41
- fun getDataSources (project : Project ): List <DbDataSource > {
42
- return DbPsiFacade .getInstance(project).dataSources.toList()
43
- }
40
+ fun getDataSources (project : Project ): List <DbDataSource > = DbPsiFacade .getInstance(project).dataSources.toList()
44
41
45
- fun getAllRawDatasource (project : Project ): List <RawDataSource > {
42
+ fun allRawDatasource (project : Project ): List <RawDataSource > {
46
43
val dbPsiFacade = DbPsiFacade .getInstance(project)
47
44
return dbPsiFacade.dataSources.map { dataSource ->
48
45
dbPsiFacade.getDataSourceManager(dataSource).dataSources
49
46
}.flatten()
50
47
}
51
48
52
49
fun getDatabase (project : Project , dbName : String ): RawDataSource ? {
53
- return getAllRawDatasource (project).firstOrNull { it.name == dbName }
50
+ return allRawDatasource (project).firstOrNull { it.name == dbName }
54
51
}
55
52
56
53
fun getAllTables (project : Project ): List <DasTable > {
57
- val rawDataSources = getAllRawDatasource(project)
58
- return rawDataSources.map {
54
+ return allRawDatasource(project).map {
59
55
val schemaName = it.name.substringBeforeLast(' @' )
60
56
DasUtil .getTables(it).filter { table ->
61
57
table.kind == ObjectKind .TABLE && (table.dasParent?.name == schemaName || isSQLiteTable(it, table))
@@ -76,7 +72,7 @@ object DatabaseSchemaAssistant {
76
72
val file = LightVirtualFile (" temp.sql" , sql)
77
73
val psiFile = PsiManager .getInstance(project).findFile(file)!!
78
74
79
- val dataSource = getAllRawDatasource (project).firstOrNull()
75
+ val dataSource = allRawDatasource (project).firstOrNull()
80
76
? : throw IllegalArgumentException (" ShireError[Database]: No database found" )
81
77
82
78
val execOptions = DatabaseSettings .getSettings().execOptions.last()
@@ -98,7 +94,7 @@ object DatabaseSchemaAssistant {
98
94
99
95
override fun addRows (context : GridDataRequest .Context , rows : MutableList <out GridRow >) {
100
96
super .addRows(context, rows)
101
- result + = rows;
97
+ result + = rows
102
98
// / TODO: fix this use result.size instead of rows.size
103
99
if (rows.size < 100 ) {
104
100
future.complete(result.toString())
@@ -191,6 +187,6 @@ object DatabaseSchemaAssistant {
191
187
" ${column.name} : ${column.dasType.toDataType()} "
192
188
}.joinToString(" , " )
193
189
194
- return " TableName: ${table.name} Columns: { $columns }"
190
+ return " TableName: ${table.name} , Columns: { $columns }"
195
191
}
196
192
}
0 commit comments