[history/serdha] Improved table updating
This commit is contained in:
parent
acc5aa8af5
commit
afa7ae3ec0
@ -8,8 +8,9 @@ import ru.landgrafhomyak.serdha.api.v0.dml.Select
|
||||
import ru.landgrafhomyak.serdha.api.v0.dml.SelectCreator
|
||||
import ru.landgrafhomyak.serdha.api.v0.dml.Update
|
||||
import ru.landgrafhomyak.serdha.api.v0.dml.UpdateCreator
|
||||
import ru.landgrafhomyak.serdha.api.v0.runtime.Transaction
|
||||
|
||||
public interface ModuleCreator {
|
||||
public interface ModuleCreator : Transaction {
|
||||
public interface CreateTable<TableUserExtension : Any> {
|
||||
public fun createTable(creator: TableCreator<TableUserExtension>): TableUserExtension
|
||||
}
|
||||
@ -55,11 +56,17 @@ public interface ModuleCreator {
|
||||
|
||||
public fun <QueryUserWrapper : Any> createSelect(initializer: CreateSelect<QueryUserWrapper>): Select<QueryUserWrapper>
|
||||
|
||||
public interface CreateInsert<TableUserExtension : Any, QueryUserWrapper : Any> {
|
||||
public fun createInsert(table: Table<TableUserExtension, *>, creator: InsertCreator<TableUserExtension, QueryUserWrapper>): QueryUserWrapper
|
||||
public interface CreateInsertParams<TableUserExtension : Any, QueryUserWrapper : Any> {
|
||||
public fun createInsert(table: Table<TableUserExtension, *>, creator: InsertCreator.InsertParams<TableUserExtension, QueryUserWrapper>): QueryUserWrapper
|
||||
}
|
||||
|
||||
public fun <TableUserExtension : Any, QueryUserWrapper : Any> createInsert(table: Table<TableUserExtension, *>, initializer: CreateInsert<TableUserExtension, QueryUserWrapper>): Insert<QueryUserWrapper>
|
||||
public fun <TableUserExtension : Any, QueryUserWrapper : Any> createInsertParams(table: Table<TableUserExtension, *>, initializer: CreateInsertParams<TableUserExtension, QueryUserWrapper>): Insert.InsertParams<QueryUserWrapper>
|
||||
|
||||
public interface CreateInsertFromQuery<TableUserExtension : Any, QueryUserWrapper : Any> {
|
||||
public fun createInsert(table: Table<TableUserExtension, *>, creator: InsertCreator.InsertFromQuery<TableUserExtension, QueryUserWrapper>): QueryUserWrapper
|
||||
}
|
||||
|
||||
public fun <TableUserExtension : Any, QueryUserWrapper : Any> createInsertFromQuery(table: Table<TableUserExtension, *>, initializer: CreateInsertFromQuery<TableUserExtension, QueryUserWrapper>): Insert.InsertFromQuery<QueryUserWrapper>
|
||||
|
||||
public interface CreateUpdate<TableUserExtension : Any, QueryUserWrapper : Any> {
|
||||
public fun createUpdate(table: Table<TableUserExtension, *>, creator: UpdateCreator<TableUserExtension, QueryUserWrapper>): QueryUserWrapper
|
||||
|
@ -14,11 +14,11 @@ public interface ModuleTemplate<ModuleUserExtension : Any> {
|
||||
}
|
||||
|
||||
public interface CreateModule<ModuleUserExtension : Any> {
|
||||
public fun createModule(rootNs: Namespace, creator: ModuleCreator): ModuleUserExtension
|
||||
public suspend fun createModule(rootNs: Namespace, creator: ModuleCreator): ModuleUserExtension
|
||||
}
|
||||
|
||||
public interface UpgradeModule<OldModuleUserExtension : Any, NewModuleUserExtension : Any> {
|
||||
public fun upgradeModule(oldModule: Module<OldModuleUserExtension>, rootNs: Namespace, updater: ModuleCreator): NewModuleUserExtension
|
||||
public suspend fun upgradeModule(oldModule: Module<OldModuleUserExtension>, rootNs: Namespace, updater: ModuleCreator): NewModuleUserExtension
|
||||
}
|
||||
|
||||
public val versionKey: String
|
||||
|
@ -1,35 +1,53 @@
|
||||
package ru.landgrafhomyak.serdha.api.v0.ddl
|
||||
|
||||
import kotlin.jvm.JvmName
|
||||
import ru.landgrafhomyak.serdha.api.v0.Expression
|
||||
import ru.landgrafhomyak.serdha.api.v0.LowLevelApi
|
||||
|
||||
public interface TableCreator<TableUserExtension : Any> {
|
||||
public val expressionBuilder: Expression.Builder<TableUserExtension>
|
||||
|
||||
/**
|
||||
* Offers column of type [D][type] with `NOT NULL` constraint named [name] and runtime type [RuntimeType].
|
||||
*
|
||||
* @return Descriptor of offered column for future operations.
|
||||
*/
|
||||
public fun <RuntimeType : Any, DatabaseType : ColumnType<RuntimeType>> column(name: String, type: DatabaseType): Column<RuntimeType, DatabaseType, TableUserExtension>
|
||||
public val types: ColumnType.Builder
|
||||
|
||||
public fun <RuntimeType, DatabaseType : ColumnType<RuntimeType>> column(name: String, type: DatabaseType): Column<RuntimeType, DatabaseType, TableUserExtension>
|
||||
|
||||
public fun index(name: String, vararg columns: Column<*, *, TableUserExtension>): Index<TableUserExtension>
|
||||
|
||||
public fun unique(name: String, distinctNulls: Boolean, vararg columns: Column<*, *, TableUserExtension>): UniqueConstraint<TableUserExtension>
|
||||
public fun check(name: String, constraint: Expression<Boolean, ColumnType.BOOLEAN, TableUserExtension>): CheckConstraint<TableUserExtension>
|
||||
public fun uniqueIndex(name: String, distinctNulls: Boolean, vararg columns: Column<*, *, TableUserExtension>): UniqueIndex<TableUserExtension>
|
||||
public fun checkConstraint(name: String, constraint: Expression<Boolean, ColumnType.BOOLEAN, TableUserExtension>): CheckConstraint<TableUserExtension>
|
||||
public fun <RuntimeType : Any, DatabaseType : ColumnType<RuntimeType>> defaultValue(c: Column<RuntimeType, DatabaseType, TableUserExtension>, expr: Expression<RuntimeType, DatabaseType, TableUserExtension>): DefaultConstraint<RuntimeType, DatabaseType, TableUserExtension>
|
||||
|
||||
public fun rowIdColumn(): Column<RowId<TableUserExtension>, ColumnType<RowId<TableUserExtension>>, TableUserExtension>
|
||||
@Suppress("PropertyName")
|
||||
public val rowId_column: Column<RowId<TableUserExtension>, ColumnType<RowId<TableUserExtension>>, TableUserExtension>
|
||||
|
||||
public fun rowIdUniqueConstraint(): UniqueConstraint<TableUserExtension>
|
||||
@Suppress("PropertyName")
|
||||
public val rowId_uniqueConstraint: UniqueIndex<TableUserExtension>
|
||||
|
||||
@Suppress("FunctionName")
|
||||
@LowLevelApi
|
||||
public fun <TargetTableUserWrapper : Any> _foreignKey(
|
||||
fromColumns: Array<Column<*, *, TableUserExtension>>,
|
||||
toTable: Table<TargetTableUserWrapper, *>,
|
||||
toColumns: Array<Column<*, *, TargetTableUserWrapper>>,
|
||||
onUpdate: ForeignKey.OnUpdateAction,
|
||||
onDelete: ForeignKey.OnDeleteAction,
|
||||
): ForeignKey<TableUserExtension, TargetTableUserWrapper>
|
||||
|
||||
@OptIn(LowLevelApi::class)
|
||||
public fun <TargetTableUserWrapper : Any, ColumnType1 : ColumnType<*>> foreignKey(
|
||||
fromColumn: Column<*, ColumnType1, TableUserExtension>,
|
||||
toTable: Table<TargetTableUserWrapper, *>,
|
||||
toColumn: Column<*, ColumnType1, TargetTableUserWrapper>,
|
||||
onUpdate: ForeignKey.OnUpdateAction,
|
||||
onDelete: ForeignKey.OnDeleteAction
|
||||
): ForeignKey<TableUserExtension, TargetTableUserWrapper>
|
||||
onDelete: ForeignKey.OnDeleteAction,
|
||||
): ForeignKey<TableUserExtension, TargetTableUserWrapper> = this._foreignKey(
|
||||
fromColumns = arrayOf(fromColumn),
|
||||
toTable = toTable,
|
||||
toColumns = arrayOf(toColumn),
|
||||
onUpdate = onUpdate,
|
||||
onDelete = onDelete
|
||||
)
|
||||
|
||||
@OptIn(LowLevelApi::class)
|
||||
public fun <TargetTableUserWrapper : Any, ColumnType1 : ColumnType<*>, ColumnType2 : ColumnType<*>> foreignKey(
|
||||
fromColumn1: Column<*, ColumnType1, TableUserExtension>,
|
||||
fromColumn2: Column<*, ColumnType2, TableUserExtension>,
|
||||
@ -37,9 +55,16 @@ public interface TableCreator<TableUserExtension : Any> {
|
||||
toColumn1: Column<*, ColumnType1, TargetTableUserWrapper>,
|
||||
toColumn2: Column<*, ColumnType2, TargetTableUserWrapper>,
|
||||
onUpdate: ForeignKey.OnUpdateAction,
|
||||
onDelete: ForeignKey.OnDeleteAction
|
||||
): ForeignKey<TableUserExtension, TargetTableUserWrapper>
|
||||
onDelete: ForeignKey.OnDeleteAction,
|
||||
): ForeignKey<TableUserExtension, TargetTableUserWrapper> = this._foreignKey(
|
||||
fromColumns = arrayOf(fromColumn1, fromColumn2),
|
||||
toTable = toTable,
|
||||
toColumns = arrayOf(toColumn1, toColumn2),
|
||||
onUpdate = onUpdate,
|
||||
onDelete = onDelete
|
||||
)
|
||||
|
||||
@OptIn(LowLevelApi::class)
|
||||
public fun <TargetTableUserWrapper : Any, ColumnType1 : ColumnType<*>, ColumnType2 : ColumnType<*>, ColumnType3 : ColumnType<*>> foreignKey(
|
||||
fromColumn1: Column<*, ColumnType1, TableUserExtension>,
|
||||
fromColumn2: Column<*, ColumnType2, TableUserExtension>,
|
||||
@ -49,6 +74,12 @@ public interface TableCreator<TableUserExtension : Any> {
|
||||
toColumn2: Column<*, ColumnType2, TargetTableUserWrapper>,
|
||||
toColumn3: Column<*, ColumnType3, TargetTableUserWrapper>,
|
||||
onUpdate: ForeignKey.OnUpdateAction,
|
||||
onDelete: ForeignKey.OnDeleteAction
|
||||
): ForeignKey<TableUserExtension, TargetTableUserWrapper>
|
||||
onDelete: ForeignKey.OnDeleteAction,
|
||||
): ForeignKey<TableUserExtension, TargetTableUserWrapper> = this._foreignKey(
|
||||
fromColumns = arrayOf(fromColumn1, fromColumn2, fromColumn3),
|
||||
toTable = toTable,
|
||||
toColumns = arrayOf(toColumn1, toColumn2, toColumn3),
|
||||
onUpdate = onUpdate,
|
||||
onDelete = onDelete
|
||||
)
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package ru.landgrafhomyak.serdha.api.v0.ddl
|
||||
|
||||
public interface UniqueConstraint<OwnerTableUserWrapper : Any> {
|
||||
public interface UniqueIndex<OwnerTableUserWrapper : Any> {
|
||||
public val name: String
|
||||
public val table: Table<OwnerTableUserWrapper, *>
|
||||
public val columns: List<Column<*, *, OwnerTableUserWrapper>>
|
Loading…
Reference in New Issue
Block a user