All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.babyfish.jimmer.sql.kt.KSqlClientExtensions.kt Maven / Gradle / Ivy

There is a newer version: 0.9.35
Show newest version
package org.babyfish.jimmer.sql.kt

import org.babyfish.jimmer.sql.association.Association
import org.babyfish.jimmer.sql.kt.ast.expression.constant
import org.babyfish.jimmer.sql.kt.ast.query.KMutableRootQuery
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1

fun  KSqlClient.exists(
    type: KClass,
    block: KMutableRootQuery.() -> Unit = {}
): Boolean = queries.forEntity(type) {
    block()
    select(constant(1))
}.limit(1).execute().isNotEmpty()

fun  KSqlClient.listExists(
    prop: KProperty1>,
    block: KMutableRootQuery>.() -> Unit
): Boolean = queries.forList(prop) {
    block()
    select(constant(1))
}.limit(1).execute().isNotEmpty()

fun  KSqlClient.refExists(
    prop: KProperty1,
    block: KMutableRootQuery>.() -> Unit
): Boolean = queries.forReference(prop) {
    block()
    select(constant(1))
}.limit(1).execute().isNotEmpty()