@@ -42,7 +42,6 @@ import com.github.mgramin.sqlboot.sql.select.wrappers.RestSelectQuery
4242import com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator
4343import com.google.gson.Gson
4444import com.google.gson.JsonObject
45- import com.google.gson.JsonParser
4645import org.apache.commons.lang3.StringUtils.strip
4746import reactor.core.publisher.Flux
4847
@@ -66,14 +65,16 @@ class SqlResourceType(
6665 return simpleSelectQuery.columns().keys
6766 .filter { v -> v.startsWith(" @" ) }
6867 .map { v -> strip(v, " @" ) }
68+ .ifEmpty { listOf (simpleSelectQuery.columns().keys.first()) }
6969 }
7070
7171 override fun read (uri : Uri ): Flux <DbResource > {
72- simpleSelectQuery.properties()
72+ val specificDialect = simpleSelectQuery.properties()[ " dialect " ]
7373 return Flux .merge(
7474 connections
7575 .map { connection ->
76- return @map createQuery(uri, connection).execute(hashMapOf(" uri" to uri))
76+ return @map createQuery(uri, connection, specificDialect
77+ ? : connection.dialect()).execute(hashMapOf(" uri" to uri))
7778 .map<Map <String , Any >? > {
7879 val toMutableMap = it.toMutableMap()
7980 toMutableMap[" database" ] = connection.name()
@@ -85,10 +86,14 @@ class SqlResourceType(
8586 val path = o!! .entries
8687 .filter { v -> v.key.startsWith(" @" ) }
8788 .map { it.value.toString() }
88- val name = path[path.size - 1 ]
8989 val headers = o.entries
9090 .map { strip(it.key, " @" ) to it.value }
9191 .toMap()
92+ val name = if (path.isEmpty()) {
93+ headers.asSequence().first().key
94+ } else {
95+ path[path.size - 1 ]
96+ }
9297 DbResourceImpl (name, this , DbUri (headers[" database" ].toString(), this .name(), path), headers) as DbResource
9398 }
9499 }
@@ -104,19 +109,21 @@ class SqlResourceType(
104109 jsonObject.addProperty(" name" , name())
105110 jsonObject.addProperty(" aliases" , aliases().toString())
106111 jsonObject.addProperty(" query" , simpleSelectQuery.query())
112+ jsonObject.add(" query_properties" , Gson ().toJsonTree(simpleSelectQuery.properties()))
107113 jsonObject.add(" metadata" , Gson ().toJsonTree(metaData(FakeUri ())))
108114 return jsonObject
109115 }
110116
111- private fun createQuery (uri : Uri , connection : DbConnection ): SelectQuery {
117+ private fun createQuery (uri : Uri , connection : DbConnection , specificDialect : String ): SelectQuery {
112118 val properties = simpleSelectQuery.properties()
113- val baseQuery = PaginatedSelectQuery (
114- OrderedSelectQuery (
115- simpleSelectQuery,
116- uri.orderedColumns()),
117- uri,
118- dialects.first { it.name() == connection.dialect() }.paginationQueryTemplate()
119- )
119+ val paginationQueryTemplate = dialects.first { it.name() == specificDialect }.paginationQueryTemplate()
120+ val baseQuery =
121+ PaginatedSelectQuery (
122+ OrderedSelectQuery (
123+ simpleSelectQuery,
124+ uri.orderedColumns()),
125+ uri,
126+ paginationQueryTemplate)
120127 return if (properties[" executor" ] == " http" ) {
121128 RestSelectQuery (
122129 baseQuery,
0 commit comments