From 50723c881110324432855a36a6ee5bb507ca034d Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Mon, 27 Jan 2025 02:48:15 +0300 Subject: [PATCH] 'UPDATE' and 'DELETE' queries with set by-hand rowid --- .../serdha/api/v0/queries/DeleteQuery.kt | 40 +++++++++++++++- .../serdha/api/v0/queries/UpdateQuery.kt | 47 +++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/queries/DeleteQuery.kt b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/queries/DeleteQuery.kt index f91f73a..0baaf49 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/queries/DeleteQuery.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/queries/DeleteQuery.kt @@ -5,12 +5,33 @@ import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseTypesProvider import ru.landgrafhomyak.serdha.api.v0.misc.QueryParam import ru.landgrafhomyak.serdha.api.v0.runtime.InputRow +import ru.landgrafhomyak.serdha.api.v0.table.RowId import ru.landgrafhomyak.serdha.api.v0.table.Table public interface DeleteQuery : _Query { + public interface SingleRow : DeleteQuery, _Query.Params2Table { + public interface Creator { + public fun createDeleteSingleRowWithReturning(table: Table, creator: Scope): QueryUserExtension + + public interface Scope { + public val types: DatabaseTypesProvider + public fun > param(name: String, type: DT): QueryParam + + public var rowToRemove: QueryParam<*, DatabaseType.ROW_ID, QueryUserExtension> + + public fun > returnRemovedValue(name: String, column: Column): Column + public fun > returnParam(name: String, column: QueryParam): Column + + public fun ifNoRowSkip() + public fun ifNoRowJustReturn() + public fun ifNoRowThrow() + } + } + } + public interface FromSubquery : DeleteQuery, _Query.Params2Table { public interface Creator { - public fun createDeleteWithReturning(table: Table, creator: Scope): QueryUserExtension + public fun createDeleteFromSubqueryWithReturning(table: Table, creator: Scope): QueryUserExtension public interface Scope { public val types: DatabaseTypesProvider @@ -22,6 +43,23 @@ public interface DeleteQuery : _Query> returnFromSubquery(name: String, column: Column): Column public fun > returnRemovedValue(name: String, column: Column): Column public fun > returnParam(name: String, column: QueryParam): Column + + public fun ifNoRowSkip() + public fun ifNoRowJustReturn() + public fun ifNoRowThrow() + } + } + } + + public interface MultipleRows : DeleteQuery, _Query.Table2Void { + public interface Creator { + public fun createMultipleRows(table: Table, creator: Scope): QueryUserExtension + + public interface Scope { + public val rowsToRemove: QueryParam, DatabaseType.ROW_ID, QueryUserExtension> + + public fun ifNoRowSkip() + public fun ifNoRowThrow() } } } diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/queries/UpdateQuery.kt b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/queries/UpdateQuery.kt index a76515e..f85dee9 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/queries/UpdateQuery.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/queries/UpdateQuery.kt @@ -8,6 +8,30 @@ import ru.landgrafhomyak.serdha.api.v0.misc.QueryParam import ru.landgrafhomyak.serdha.api.v0.runtime.InputRow public interface UpdateQuery : _Query { + public interface SingleRow : UpdateQuery, _Query.Params2Table { + public interface Creator { + public fun createUpdateSingleWithReturning(table: Table, creator: Scope): QueryUserExtension + + public interface Scope { + public val types: DatabaseTypesProvider + public fun > param(name: String, type: DT): QueryParam + + public var rowToUpdate: QueryParam<*, DatabaseType.ROW_ID, QueryUserExtension> + + public fun > updateColumnWithOldValue(dst: Column, src: Column) + public fun > updateColumnWithParam(dst: Column, src: QueryParam) + + public fun > returnOldValue(name: String, column: Column): Column + public fun > returnNewValue(name: String, column: Column): Column + public fun > returnParam(name: String, param: QueryParam): Column + + public fun ifNoRowSkip() + public fun ifNoRowJustReturn() + public fun ifNoRowThrow() + } + } + } + public interface FromSubquery : UpdateQuery, _Query.Params2Table { public interface Creator { public fun createUpdateFromSubqueryWithReturning(table: Table, creator: Scope): QueryUserExtension @@ -27,6 +51,29 @@ public interface UpdateQuery : _Query> returnOldValue(name: String, column: Column): Column public fun > returnNewValue(name: String, column: Column): Column public fun > returnParam(name: String, param: QueryParam): Column + + public fun ifNoRowSkip() + public fun ifNoRowJustReturn() + public fun ifNoRowThrow() + } + } + } + + public interface MultipleRows : UpdateQuery, _Query.Table2Void { + public interface Creator { + public fun createUpdateMultipleRows(table: Table, creator: Scope): QueryUserExtension + + public interface Scope { + public val types: DatabaseTypesProvider + public fun > param(name: String, type: DT): QueryParam + + public var rowToUpdate: QueryParam<*, DatabaseType.ROW_ID, QueryUserExtension> + + public fun > updateColumnWithOldValue(dst: Column, src: Column) + public fun > updateColumnWithParam(dst: Column, src: QueryParam) + + public fun ifNoRowSkip() + public fun ifNoRowThrow() } } }