feature add exec method
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
package fr.postgresjson.connexion
|
package fr.postgresjson.connexion
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference
|
import com.fasterxml.jackson.core.type.TypeReference
|
||||||
|
import com.github.jasync.sql.db.QueryResult
|
||||||
import com.github.jasync.sql.db.pool.ConnectionPool
|
import com.github.jasync.sql.db.pool.ConnectionPool
|
||||||
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
|
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
|
||||||
import com.github.jasync.sql.db.postgresql.PostgreSQLConnectionBuilder
|
import com.github.jasync.sql.db.postgresql.PostgreSQLConnectionBuilder
|
||||||
import fr.postgresjson.Serializer
|
import fr.postgresjson.Serializer
|
||||||
import fr.postgresjson.entity.EntityI
|
import fr.postgresjson.entity.EntityI
|
||||||
|
import java.util.concurrent.CompletableFuture
|
||||||
|
|
||||||
class Connection(
|
class Connection(
|
||||||
private val database: String,
|
private val database: String,
|
||||||
@@ -50,6 +52,10 @@ class Connection(
|
|||||||
|
|
||||||
inline fun <T, reified R : List<EntityI<T?>?>> select(sql: String, values: List<Any?> = emptyList()): R = select(sql, object : TypeReference<R>() {}, values)
|
inline fun <T, reified R : List<EntityI<T?>?>> select(sql: String, values: List<Any?> = emptyList()): R = select(sql, object : TypeReference<R>() {}, values)
|
||||||
|
|
||||||
|
fun exec(sql: String, values: List<Any?> = emptyList()): CompletableFuture<QueryResult> {
|
||||||
|
return connect().sendPreparedStatement(sql, compileArgs(values))
|
||||||
|
}
|
||||||
|
|
||||||
private fun compileArgs(values: List<Any?>): List<Any?> {
|
private fun compileArgs(values: List<Any?>): List<Any?> {
|
||||||
return values.map {
|
return values.map {
|
||||||
if (it is EntityI<*>) {
|
if (it is EntityI<*>) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package fr.postgresjson
|
package fr.postgresjson
|
||||||
|
|
||||||
|
import com.github.jasync.sql.db.util.isCompleted
|
||||||
import fr.postgresjson.connexion.Connection
|
import fr.postgresjson.connexion.Connection
|
||||||
import fr.postgresjson.entity.IdEntity
|
import fr.postgresjson.entity.IdEntity
|
||||||
import org.junit.jupiter.api.Assertions.*
|
import org.junit.jupiter.api.Assertions.*
|
||||||
@@ -63,4 +64,12 @@ class ConnectionTest(): TestAbstract() {
|
|||||||
assertTrue(obj!!.id == 1)
|
assertTrue(obj!!.id == 1)
|
||||||
assertTrue(obj.name == "myName")
|
assertTrue(obj.name == "myName")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun callExec() {
|
||||||
|
val o = ObjTest("myName")
|
||||||
|
val future = connection.exec("select json_build_object('id', 1, 'name', ?::json->>'name')", listOf(o))
|
||||||
|
future.join()
|
||||||
|
assertTrue(future.isCompleted)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user