From ae184cd52c9101874c0a4691fcfeaeff665f2d52 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Sat, 3 Aug 2019 20:25:01 +0200 Subject: [PATCH] feature: add name into Query object --- .../fr/postgresjson/connexion/EmbedExecutable.kt | 1 + src/main/kotlin/fr/postgresjson/connexion/Function.kt | 2 ++ src/main/kotlin/fr/postgresjson/connexion/Query.kt | 2 +- src/main/kotlin/fr/postgresjson/connexion/Requester.kt | 10 +++++++--- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/fr/postgresjson/connexion/EmbedExecutable.kt b/src/main/kotlin/fr/postgresjson/connexion/EmbedExecutable.kt index 7818fdf..59437c8 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/EmbedExecutable.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/EmbedExecutable.kt @@ -7,6 +7,7 @@ import fr.postgresjson.entity.EntityI interface EmbedExecutable { val connection: Connection override fun toString(): String + val name: String /* Select One */ /** diff --git a/src/main/kotlin/fr/postgresjson/connexion/Function.kt b/src/main/kotlin/fr/postgresjson/connexion/Function.kt index ed69eca..4d42538 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Function.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Function.kt @@ -10,6 +10,8 @@ class Function(val definition: Function, override val connection: Connection): E return definition.name } + override val name: String = definition.name + /* Select One */ /** diff --git a/src/main/kotlin/fr/postgresjson/connexion/Query.kt b/src/main/kotlin/fr/postgresjson/connexion/Query.kt index 692c802..5bdce80 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Query.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Query.kt @@ -5,7 +5,7 @@ import com.github.jasync.sql.db.QueryResult import fr.postgresjson.entity.EntityI -class Query(private val sql: String, override val connection: Connection): EmbedExecutable { +class Query(override val name: String, private val sql: String, override val connection: Connection): EmbedExecutable { override fun toString(): String { return sql } diff --git a/src/main/kotlin/fr/postgresjson/connexion/Requester.kt b/src/main/kotlin/fr/postgresjson/connexion/Requester.kt index 72d04ba..96588d3 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Requester.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Requester.kt @@ -8,13 +8,13 @@ class Requester( private val queries: MutableMap = mutableMapOf(), private val functions: MutableMap = mutableMapOf() ) { - fun addQuery(name: String, query: Query): Requester { - queries[name] = query + fun addQuery(query: Query): Requester { + queries[query.name] = query return this } fun addQuery(name: String, sql: String): Requester { - queries[name] = Query(sql, connection) + addQuery(Query(name, sql, connection)) return this } @@ -28,6 +28,10 @@ class Requester( return this } + fun getQueries(): List { + return queries.map { it.value } + } + fun addFunction(definition: DefinitionFunction): Requester { functions[definition.name] = Function(definition, connection) return this