improve-tests #28
@@ -49,6 +49,9 @@ class Connection(
|
|||||||
|
|
||||||
fun <A> inTransaction(f: (Connection) -> CompletableFuture<A>) = connect().inTransaction(f)
|
fun <A> inTransaction(f: (Connection) -> CompletableFuture<A>) = connect().inTransaction(f)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select One [EntityI] with [List] of parameters
|
||||||
|
*/
|
||||||
override fun <R : EntityI> selectOne(
|
override fun <R : EntityI> selectOne(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
@@ -66,13 +69,9 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R : EntityI> selectOne(
|
/**
|
||||||
sql: String,
|
* Select One [EntityI] with named parameters
|
||||||
values: List<Any?> = emptyList(),
|
*/
|
||||||
noinline block: SelectOneCallback<R> = {}
|
|
||||||
): R? =
|
|
||||||
selectOne(sql, object : TypeReference<R>() {}, values, block)
|
|
||||||
|
|
||||||
override fun <R : EntityI> selectOne(
|
override fun <R : EntityI> selectOne(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<R>,
|
typeReference: TypeReference<R>,
|
||||||
@@ -84,13 +83,11 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R : EntityI> selectOne(
|
/* Select Multiples */
|
||||||
sql: String,
|
|
||||||
values: Map<String, Any?>,
|
|
||||||
noinline block: SelectOneCallback<R> = {}
|
|
||||||
): R? =
|
|
||||||
selectOne(sql, object : TypeReference<R>() {}, values, block)
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select multiple [EntityI] with [List] of parameters
|
||||||
|
*/
|
||||||
override fun <R : EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
@@ -108,13 +105,25 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R : EntityI> select(
|
/**
|
||||||
|
* Select multiple [EntityI] with [Map] of parameters
|
||||||
|
*/
|
||||||
|
override fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
values: List<Any?> = emptyList(),
|
typeReference: TypeReference<List<R>>,
|
||||||
noinline block: SelectCallback<R> = {}
|
values: Map<String, Any?>,
|
||||||
): List<R> =
|
block: (QueryResult, List<R>) -> Unit
|
||||||
select(sql, object : TypeReference<List<R>>() {}, values, block)
|
): List<R> {
|
||||||
|
return replaceArgs(sql, values) {
|
||||||
|
select(this.sql, typeReference, this.parameters, block)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Select Paginated */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select Multiple [EntityI] with pagination
|
||||||
|
*/
|
||||||
override fun <R : EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
sql: String,
|
sql: String,
|
||||||
page: Int,
|
page: Int,
|
||||||
@@ -150,33 +159,6 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified R : EntityI> select(
|
|
||||||
sql: String,
|
|
||||||
page: Int,
|
|
||||||
limit: Int,
|
|
||||||
values: Map<String, Any?> = emptyMap(),
|
|
||||||
noinline block: SelectPaginatedCallback<R> = {}
|
|
||||||
): Paginated<R> =
|
|
||||||
select(sql, page, limit, object : TypeReference<List<R>>() {}, values, block)
|
|
||||||
|
|
||||||
override fun <R : EntityI> select(
|
|
||||||
sql: String,
|
|
||||||
typeReference: TypeReference<List<R>>,
|
|
||||||
values: Map<String, Any?>,
|
|
||||||
block: (QueryResult, List<R>) -> Unit
|
|
||||||
): List<R> {
|
|
||||||
return replaceArgs(sql, values) {
|
|
||||||
select(this.sql, typeReference, this.parameters, block)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <reified R : EntityI> select(
|
|
||||||
sql: String,
|
|
||||||
values: Map<String, Any?>,
|
|
||||||
noinline block: SelectCallback<R> = {}
|
|
||||||
): List<R> =
|
|
||||||
select(sql, object : TypeReference<List<R>>() {}, values, block)
|
|
||||||
|
|
||||||
override fun exec(sql: String, values: List<Any?>): QueryResult {
|
override fun exec(sql: String, values: List<Any?>): QueryResult {
|
||||||
val compiledValues = compileArgs(values)
|
val compiledValues = compileArgs(values)
|
||||||
return stopwatchQuery(sql, compiledValues) {
|
return stopwatchQuery(sql, compiledValues) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import fr.postgresjson.entity.EntityI
|
|||||||
|
|
||||||
interface Executable {
|
interface Executable {
|
||||||
|
|
||||||
/* Select One */
|
/* Update */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update [EntityI] with one entity as argument
|
* Update [EntityI] with one entity as argument
|
||||||
@@ -19,6 +19,8 @@ interface Executable {
|
|||||||
): R? =
|
): R? =
|
||||||
selectOne(sql, typeReference, listOf(value), block)
|
selectOne(sql, typeReference, listOf(value), block)
|
||||||
|
|
||||||
|
/* Select One */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select One [EntityI] with [List] of parameters
|
* Select One [EntityI] with [List] of parameters
|
||||||
*/
|
*/
|
||||||
|
|||||||
106
src/main/kotlin/fr/postgresjson/connexion/ExecutableReified.kt
Normal file
106
src/main/kotlin/fr/postgresjson/connexion/ExecutableReified.kt
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
package fr.postgresjson.connexion
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference
|
||||||
|
import fr.postgresjson.entity.EntityI
|
||||||
|
|
||||||
|
/* Update */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update [EntityI] with one entity as argument
|
||||||
|
*/
|
||||||
|
inline fun <reified R : EntityI> Executable.update(
|
||||||
|
sql: String,
|
||||||
|
value: R,
|
||||||
|
noinline block: SelectOneCallback<R> = {}
|
||||||
|
): R? =
|
||||||
|
update(sql, object : TypeReference<R>() {}, value, block)
|
||||||
|
|
||||||
|
/* Select One */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select One [EntityI] with [List] of parameters
|
||||||
|
*/
|
||||||
|
inline fun <reified R : EntityI> Executable.selectOne(
|
||||||
|
sql: String,
|
||||||
|
values: List<Any?> = emptyList(),
|
||||||
|
noinline block: SelectOneCallback<R> = {}
|
||||||
|
): R? =
|
||||||
|
selectOne(sql, object : TypeReference<R>() {}, values, block)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select One [EntityI] with [Map] of parameters
|
||||||
|
*/
|
||||||
|
inline fun <reified R : EntityI> Executable.selectOne(
|
||||||
|
sql: String,
|
||||||
|
values: Map<String, Any?>,
|
||||||
|
noinline block: SelectOneCallback<R> = {}
|
||||||
|
): R? =
|
||||||
|
selectOne(sql, object : TypeReference<R>() {}, values, block)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select One [EntityI] with multiple [Pair] of parameters
|
||||||
|
*/
|
||||||
|
inline fun <reified R : EntityI> Executable.selectOne(
|
||||||
|
sql: String,
|
||||||
|
vararg values: Pair<String, Any?>,
|
||||||
|
noinline block: SelectOneCallback<R> = {}
|
||||||
|
): R? =
|
||||||
|
selectOne(sql, object : TypeReference<R>() {}, values = values, block)
|
||||||
|
|
||||||
|
/* Select Multiples */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select Multiple [EntityI] with [List] of parameters
|
||||||
|
*/
|
||||||
|
inline fun <reified R : EntityI> Executable.select(
|
||||||
|
sql: String,
|
||||||
|
values: List<Any?> = emptyList(),
|
||||||
|
noinline block: SelectCallback<R> = {}
|
||||||
|
): List<R> =
|
||||||
|
select(sql, object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select Multiple [EntityI] with [Map] of parameters
|
||||||
|
*/
|
||||||
|
inline fun <reified R : EntityI> Executable.select(
|
||||||
|
sql: String,
|
||||||
|
values: Map<String, Any?>,
|
||||||
|
noinline block: SelectCallback<R> = {}
|
||||||
|
): List<R> =
|
||||||
|
select(sql, object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select Multiple [EntityI] with multiple [Pair] of parameters
|
||||||
|
*/
|
||||||
|
inline fun <reified R : EntityI> Executable.select(
|
||||||
|
sql: String,
|
||||||
|
vararg values: Pair<String, Any?>,
|
||||||
|
noinline block: SelectCallback<R> = {}
|
||||||
|
): List<R> =
|
||||||
|
select(sql, object : TypeReference<List<R>>() {}, values = values, block)
|
||||||
|
|
||||||
|
/* Select Paginated */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select Paginated [EntityI] with [Map] of parameters
|
||||||
|
*/
|
||||||
|
inline fun <reified R : EntityI> Executable.select(
|
||||||
|
sql: String,
|
||||||
|
page: Int,
|
||||||
|
limit: Int,
|
||||||
|
values: Map<String, Any?> = emptyMap(),
|
||||||
|
noinline block: SelectPaginatedCallback<R> = {}
|
||||||
|
): Paginated<R> =
|
||||||
|
select(sql, page, limit, object : TypeReference<List<R>>() {}, values, block)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select Paginated [EntityI] with multiple [Pair] of parameters
|
||||||
|
*/
|
||||||
|
inline fun <reified R : EntityI> Executable.select(
|
||||||
|
sql: String,
|
||||||
|
page: Int,
|
||||||
|
limit: Int,
|
||||||
|
vararg values: Pair<String, Any?>,
|
||||||
|
noinline block: SelectPaginatedCallback<R> = {}
|
||||||
|
): Paginated<R> =
|
||||||
|
select(sql, page, limit, object : TypeReference<List<R>>() {}, values = values, block)
|
||||||
@@ -12,16 +12,6 @@ class Function(val definition: Function, override val connection: Connection) :
|
|||||||
|
|
||||||
override val name: String = definition.name
|
override val name: String = definition.name
|
||||||
|
|
||||||
/**
|
|
||||||
* Update [EntityI]
|
|
||||||
*/
|
|
||||||
override fun <R : EntityI> update(
|
|
||||||
typeReference: TypeReference<R>,
|
|
||||||
value: R,
|
|
||||||
block: (QueryResult, R?) -> Unit
|
|
||||||
): R? =
|
|
||||||
connection.update(compileSql(value), typeReference, value, block)
|
|
||||||
|
|
||||||
/* Select One */
|
/* Select One */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,16 +9,6 @@ class Query(override val name: String, private val sql: String, override val con
|
|||||||
return sql
|
return sql
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update [EntityI]
|
|
||||||
*/
|
|
||||||
override fun <R : EntityI> update(
|
|
||||||
typeReference: TypeReference<R>,
|
|
||||||
value: R,
|
|
||||||
block: (QueryResult, R?) -> Unit
|
|
||||||
): R? =
|
|
||||||
connection.update(sql, typeReference, value, block)
|
|
||||||
|
|
||||||
/* Select One */
|
/* Select One */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,6 +43,9 @@ class Query(override val name: String, private val sql: String, override val con
|
|||||||
): List<R> =
|
): List<R> =
|
||||||
connection.select(sql, typeReference, values, block)
|
connection.select(sql, typeReference, values, block)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select multiple [EntityI] with [Map] of parameters
|
||||||
|
*/
|
||||||
override fun <R : EntityI> select(
|
override fun <R : EntityI> select(
|
||||||
typeReference: TypeReference<List<R>>,
|
typeReference: TypeReference<List<R>>,
|
||||||
values: Map<String, Any?>,
|
values: Map<String, Any?>,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package fr.postgresjson.migration
|
|||||||
|
|
||||||
import com.github.jasync.sql.db.postgresql.exceptions.GenericDatabaseException
|
import com.github.jasync.sql.db.postgresql.exceptions.GenericDatabaseException
|
||||||
import fr.postgresjson.connexion.Connection
|
import fr.postgresjson.connexion.Connection
|
||||||
|
import fr.postgresjson.connexion.selectOne
|
||||||
import fr.postgresjson.migration.Migration.Action
|
import fr.postgresjson.migration.Migration.Action
|
||||||
import fr.postgresjson.migration.Migration.Status
|
import fr.postgresjson.migration.Migration.Status
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package fr.postgresjson.migration
|
package fr.postgresjson.migration
|
||||||
|
|
||||||
import fr.postgresjson.connexion.Connection
|
import fr.postgresjson.connexion.Connection
|
||||||
|
import fr.postgresjson.connexion.selectOne
|
||||||
import fr.postgresjson.entity.Entity
|
import fr.postgresjson.entity.Entity
|
||||||
import fr.postgresjson.migration.Migration.Action
|
import fr.postgresjson.migration.Migration.Action
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package fr.postgresjson
|
package fr.postgresjson
|
||||||
|
|
||||||
import fr.postgresjson.connexion.Paginated
|
import fr.postgresjson.connexion.Paginated
|
||||||
|
import fr.postgresjson.connexion.select
|
||||||
|
import fr.postgresjson.connexion.selectOne
|
||||||
import fr.postgresjson.entity.Parameter
|
import fr.postgresjson.entity.Parameter
|
||||||
import fr.postgresjson.entity.UuidEntity
|
import fr.postgresjson.entity.UuidEntity
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
|
|||||||
Reference in New Issue
Block a user