Extract Reified method to Extension
Add update method
This commit is contained in:
@@ -5,8 +5,23 @@ import com.github.jasync.sql.db.QueryResult
|
||||
import fr.postgresjson.entity.EntityI
|
||||
|
||||
interface Executable {
|
||||
|
||||
/* Select One */
|
||||
|
||||
/**
|
||||
* Update [EntityI] with one entity as argument
|
||||
*/
|
||||
fun <R : EntityI> update(
|
||||
sql: String,
|
||||
typeReference: TypeReference<R>,
|
||||
value: R,
|
||||
block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
selectOne(sql, typeReference, listOf(value), block)
|
||||
|
||||
/**
|
||||
* Select One [EntityI] with [List] of parameters
|
||||
*/
|
||||
fun <R : EntityI> selectOne(
|
||||
sql: String,
|
||||
typeReference: TypeReference<R>,
|
||||
@@ -14,6 +29,9 @@ interface Executable {
|
||||
block: SelectOneCallback<R> = {}
|
||||
): R?
|
||||
|
||||
/**
|
||||
* Select One [EntityI] with [Map] of parameters
|
||||
*/
|
||||
fun <R : EntityI> selectOne(
|
||||
sql: String,
|
||||
typeReference: TypeReference<R>,
|
||||
@@ -21,8 +39,22 @@ interface Executable {
|
||||
block: SelectOneCallback<R> = {}
|
||||
): R?
|
||||
|
||||
/**
|
||||
* Select One [EntityI] with multiple [Pair] of parameters
|
||||
*/
|
||||
fun <R : EntityI> selectOne(
|
||||
sql: String,
|
||||
typeReference: TypeReference<R>,
|
||||
vararg values: Pair<String, Any?>,
|
||||
block: SelectOneCallback<R> = {}
|
||||
): R? =
|
||||
selectOne(sql, typeReference, values.toMap(), block)
|
||||
|
||||
/* Select Multiples */
|
||||
|
||||
/**
|
||||
* Select Multiple [EntityI] with [List] of parameters
|
||||
*/
|
||||
fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
@@ -30,6 +62,9 @@ interface Executable {
|
||||
block: SelectCallback<R> = {}
|
||||
): List<R>
|
||||
|
||||
/**
|
||||
* Select Multiple [EntityI] with [Map] of parameters
|
||||
*/
|
||||
fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
@@ -37,8 +72,22 @@ interface Executable {
|
||||
block: SelectCallback<R> = {}
|
||||
): List<R>
|
||||
|
||||
/**
|
||||
* Select Multiple [EntityI] with multiple [Pair] of parameters
|
||||
*/
|
||||
fun <R : EntityI> select(
|
||||
sql: String,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
vararg values: Pair<String, Any?>,
|
||||
block: SelectCallback<R> = {}
|
||||
): List<R> =
|
||||
select(sql, typeReference, values.toMap(), block)
|
||||
|
||||
/* Select Paginated */
|
||||
|
||||
/**
|
||||
* Select Paginated [EntityI] with [Map] of parameters
|
||||
*/
|
||||
fun <R : EntityI> select(
|
||||
sql: String,
|
||||
page: Int,
|
||||
@@ -48,8 +97,31 @@ interface Executable {
|
||||
block: SelectPaginatedCallback<R> = {}
|
||||
): Paginated<R>
|
||||
|
||||
/**
|
||||
* Select Paginated [EntityI] with multiple [Pair] of parameters
|
||||
*/
|
||||
fun <R : EntityI> select(
|
||||
sql: String,
|
||||
page: Int,
|
||||
limit: Int,
|
||||
typeReference: TypeReference<List<R>>,
|
||||
vararg values: Pair<String, Any?>,
|
||||
block: SelectPaginatedCallback<R> = {}
|
||||
): Paginated<R> =
|
||||
select(sql, page, limit, typeReference, values.toMap(), block)
|
||||
|
||||
fun <R : EntityI> exec(sql: String, value: R): QueryResult = exec(sql, listOf(value))
|
||||
fun exec(sql: String, values: List<Any?> = emptyList()): QueryResult
|
||||
fun exec(sql: String, values: Map<String, Any?>): QueryResult
|
||||
fun exec(sql: String, vararg values: Pair<String, Any?>): QueryResult = exec(sql, values.toMap())
|
||||
|
||||
fun <R : EntityI> perform(sql: String, value: R) { perform(sql, listOf(value)) }
|
||||
fun perform(sql: String, values: List<Any?>) { exec(sql, values) }
|
||||
fun perform(sql: String, values: Map<String, Any?>) { exec(sql, values) }
|
||||
fun perform(sql: String, vararg values: Pair<String, Any?>) = perform(sql, values.toMap())
|
||||
|
||||
fun <R : EntityI> sendQuery(sql: String, value: R): Int = sendQuery(sql, listOf(value))
|
||||
fun sendQuery(sql: String, values: List<Any?> = emptyList()): Int
|
||||
fun sendQuery(sql: String, values: Map<String, Any?>): Int
|
||||
fun sendQuery(sql: String, vararg values: Pair<String, Any?>): Int = sendQuery(sql, values.toMap())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user