Package-level declarations

Types

Link copied to clipboard

Main entry point to the data layer, offering a consistent API for database interaction.

Link copied to clipboard
sealed class DataResult<out T>

Container for a database operation result, which can end in success or failure. Replaces the exception mechanism, forcing explicit handling of both cases.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.PROPERTY])
annotation class MapKey(val name: String)

Annotation used to specify a custom key for a property during object to/from map conversion.

Link copied to clipboard
data class QueryFragment(val sql: String, val params: Map<String, Any?> = emptyMap())

Simple container for an SQL query fragment and its parameters.

Link copied to clipboard
interface QueryOperations

Defines the contract for basic database operations (CRUD and raw queries).

Functions

Link copied to clipboard
fun <R, T : R> DataResult<T>.getOrElse(onFailure: (Throwable) -> R): R

Returns the value if the result is Success, or computes a default value from the error if it is Failure.

Link copied to clipboard

Returns the value if the result is Success, or throws an exception if it is Failure.

Link copied to clipboard
fun List<QueryFragment>.join(separator: String, prefix: String = "", postfix: String = "", addParenthesis: Boolean = true): QueryFragment

Joins a list of fragments into one, working analogously to standard joinToString, but with parameter merging support.

Link copied to clipboard
inline fun <T, R> DataResult<T>.map(transform: (T) -> R): DataResult<R>

Transforms the value inside DataResult.Success, leaving DataResult.Failure unchanged.

Link copied to clipboard

Executes an action if the result is Failure, without modifying the original error.

Link copied to clipboard
fun <T> DataResult<T>.onSuccess(action: (T) -> Unit): DataResult<T>

Executes an action if the result is Success, without modifying the original value.

Link copied to clipboard
inline fun <T : Any> Map<String, Any?>.toDataObject(): T

Converts a map (typically a database row) to a data class instance.

fun <T : Any> Map<String, Any?>.toDataObject(kClass: KClass<T>): T
Link copied to clipboard
fun <T : Any> T.toMap(vararg excludeKeys: String): Map<String, Any?>

Converts a data class object to a map, where keys are property names (or values from @MapKey annotation), and values are the property values.

Link copied to clipboard
fun validateValue(value: Any?, targetType: KType): Any?

Validates whether a runtime value matches the expected Kotlin type.

Link copied to clipboard

Creates QueryFragment from this SQL in String and param

Link copied to clipboard
infix fun String.withParams(params: Map<String, Any?>): QueryFragment

Creates QueryFragment from this SQL in String and params map