Clean the request process

Remove paginated
Remove Entity classes
Add Annotation for serialize object
rename selectOne/selectMultiple to execute
This commit is contained in:
2023-04-06 21:03:15 +02:00
parent 7d39dcf248
commit a7e66ab8b5
31 changed files with 380 additions and 1212 deletions

View File

@@ -1,106 +1,37 @@
package fr.postgresjson.connexion
import com.fasterxml.jackson.core.type.TypeReference
import fr.postgresjson.entity.EntityI
/* Update */
import kotlin.jvm.Throws
/**
* Update [EntityI] with one entity as argument
* Select with unnamed parameters
*/
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(
@Throws(DataNotFoundException::class)
inline fun <reified R : Any> ExecutableRaw.execute(
sql: String,
values: List<Any?> = emptyList(),
noinline block: SelectCallback<R> = {}
): List<R> =
select(sql, object : TypeReference<List<R>>() {}, values, block)
): R? =
execute(sql, object : TypeReference<R>() {}, values, block)
/**
* Select Multiple [EntityI] with [Map] of parameters
* Select with named parameters
*/
inline fun <reified R : EntityI> Executable.select(
@Throws(DataNotFoundException::class)
inline fun <reified R : Any> ExecutableRaw.execute(
sql: String,
values: Map<String, Any?>,
noinline block: SelectCallback<R> = {}
): List<R> =
select(sql, object : TypeReference<List<R>>() {}, values, block)
): R? =
execute(sql, object : TypeReference<R>() {}, values, block)
/**
* Select Multiple [EntityI] with multiple [Pair] of parameters
* Select with named parameters
*/
inline fun <reified R : EntityI> Executable.select(
@Throws(DataNotFoundException::class)
inline fun <reified R : Any> ExecutableRaw.execute(
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)
): R? =
execute(sql, object : TypeReference<R>() {}, values = values, block)