From 592c5f373256e1afdd6a443cd7afc3917ae25bb3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 14 Jan 2023 20:17:57 +0600 Subject: [PATCH] Column extensions eqOrIsNull and neqOrIsNotNull --- CHANGELOG.md | 2 ++ .../repos/exposed/ColumnEqOrNull.kt | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/ColumnEqOrNull.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index eb88cd2b971..24e11781c26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ * `Ktor`: * `Client`: * All clients repos got opportunity to customize their flows + * `Exposed`: + * Extensions `eqOrIsNull` and `neqOrIsNotNull` for `Column` ## 0.16.5 diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/ColumnEqOrNull.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/ColumnEqOrNull.kt new file mode 100644 index 00000000000..29bc98f6251 --- /dev/null +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/ColumnEqOrNull.kt @@ -0,0 +1,23 @@ +package dev.inmo.micro_utils.repos.exposed + +import org.jetbrains.exposed.sql.Column +import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNotNull +import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNull +import org.jetbrains.exposed.sql.SqlExpressionBuilder.neq + +fun Column.eqOrIsNull( + value: T? +) = if (value == null) { + isNull() +} else { + eq(value) +} + +fun Column.neqOrIsNotNull( + value: T? +) = if (value == null) { + isNotNull() +} else { + neq(value) +}