Table's constructor and upgrade moved from top level scope into 'Table' interface

This commit is contained in:
Andrew Golovashevich 2025-05-09 04:20:26 +03:00
parent 89c83c219f
commit 815acda773
7 changed files with 72 additions and 75 deletions

View File

@ -6,7 +6,6 @@ import ru.landgrafhomyak.db.skeleton1.api.statement.RawStatement
import ru.landgrafhomyak.db.skeleton1.api.statement._Statement import ru.landgrafhomyak.db.skeleton1.api.statement._Statement
import ru.landgrafhomyak.db.skeleton1.api.table.Table import ru.landgrafhomyak.db.skeleton1.api.table.Table
import ru.landgrafhomyak.db.skeleton1.api.runtime.InputRow import ru.landgrafhomyak.db.skeleton1.api.runtime.InputRow
import ru.landgrafhomyak.db.skeleton1.api.table.TableConstructor
public interface CreateModuleScope<mUE : Any, RK : Any> { public interface CreateModuleScope<mUE : Any, RK : Any> {
@ -17,7 +16,7 @@ public interface CreateModuleScope<mUE : Any, RK : Any> {
public fun <tUE : Any> createTable( public fun <tUE : Any> createTable(
lifeTime: Table.LifeTime = Table.LifeTime.DATABASE_SCOPE, lifeTime: Table.LifeTime = Table.LifeTime.DATABASE_SCOPE,
namespace: Namespace<mUE, RK> = this.rootNs, namespace: Namespace<mUE, RK> = this.rootNs,
name: String, initializer: TableConstructor<tUE, RK> name: String, initializer: Table.Constructor<tUE, RK>
): Table<tUE, mUE, RK> ): Table<tUE, mUE, RK>
public fun moduleScopedObject(namespace: Namespace<mUE, RK> = this.rootNs, name: String): ModuleScopedObject<mUE, RK> public fun moduleScopedObject(namespace: Namespace<mUE, RK> = this.rootNs, name: String): ModuleScopedObject<mUE, RK>

View File

@ -5,7 +5,6 @@ import ru.landgrafhomyak.db.skeleton1.api.statement.RawStatement
import ru.landgrafhomyak.db.skeleton1.api.statement._Statement import ru.landgrafhomyak.db.skeleton1.api.statement._Statement
import ru.landgrafhomyak.db.skeleton1.api.runtime.InputRow import ru.landgrafhomyak.db.skeleton1.api.runtime.InputRow
import ru.landgrafhomyak.db.skeleton1.api.table.Table import ru.landgrafhomyak.db.skeleton1.api.table.Table
import ru.landgrafhomyak.db.skeleton1.api.table.TableUpgrade
public interface UpgradeModuleScope<nmUE : Any, omUE : Any, RK : Any> : CreateModuleScope<nmUE, RK> { public interface UpgradeModuleScope<nmUE : Any, omUE : Any, RK : Any> : CreateModuleScope<nmUE, RK> {
@ -15,23 +14,23 @@ public interface UpgradeModuleScope<nmUE : Any, omUE : Any, RK : Any> : CreateMo
public fun <tUE : Any> keepAndRenameTable(table: Table<tUE, omUE, RK>, newNamespace: Namespace<nmUE, RK>): Table<tUE, nmUE, RK> public fun <tUE : Any> keepAndRenameTable(table: Table<tUE, omUE, RK>, newNamespace: Namespace<nmUE, RK>): Table<tUE, nmUE, RK>
public fun <tUE : Any> keepAndRenameTable(table: Table<tUE, omUE, RK>, newNamespace: Namespace<nmUE, RK>, newName: String): Table<tUE, nmUE, RK> public fun <tUE : Any> keepAndRenameTable(table: Table<tUE, omUE, RK>, newNamespace: Namespace<nmUE, RK>, newName: String): Table<tUE, nmUE, RK>
public fun <ntUE : Any, otUE : Any> upgradeTable(oldTable: Table<otUE, omUE, RK>, upgrade: TableUpgrade<ntUE, otUE, RK>): Table<ntUE, nmUE, RK> public fun <ntUE : Any, otUE : Any> upgradeTable(oldTable: Table<otUE, omUE, RK>, upgrade: Table.Upgrade<ntUE, otUE, RK>): Table<ntUE, nmUE, RK>
public fun <ntUE : Any, otUE : Any> upgradeAndRenameTable( public fun <ntUE : Any, otUE : Any> upgradeAndRenameTable(
table: Table<otUE, omUE, RK>, table: Table<otUE, omUE, RK>,
newName: String, newName: String,
upgrade: TableUpgrade<ntUE, otUE, RK> upgrade: Table.Upgrade<ntUE, otUE, RK>
): Table<ntUE, nmUE, RK> ): Table<ntUE, nmUE, RK>
public fun <ntUE : Any, otUE : Any> upgradeAndRenameTable( public fun <ntUE : Any, otUE : Any> upgradeAndRenameTable(
table: Table<otUE, omUE, RK>, table: Table<otUE, omUE, RK>,
newNamespace: Namespace<nmUE, RK>, newNamespace: Namespace<nmUE, RK>,
upgrade: TableUpgrade<ntUE, otUE, RK> upgrade: Table.Upgrade<ntUE, otUE, RK>
): Table<ntUE, nmUE, RK> ): Table<ntUE, nmUE, RK>
public fun <ntUE : Any, otUE : Any> upgradeAndRenameTable( public fun <ntUE : Any, otUE : Any> upgradeAndRenameTable(
table: Table<otUE, omUE, RK>, table: Table<otUE, omUE, RK>,
newNamespace: Namespace<nmUE, RK>, newNamespace: Namespace<nmUE, RK>,
upgrade: TableUpgrade<ntUE, otUE, RK>, upgrade: Table.Upgrade<ntUE, otUE, RK>,
newName: String newName: String
): Table<ntUE, nmUE, RK> ): Table<ntUE, nmUE, RK>
@ -49,7 +48,7 @@ public interface UpgradeModuleScope<nmUE : Any, omUE : Any, RK : Any> : CreateMo
public fun <ntUE : Any, otUE : Any> importAndUpgradeTable( public fun <ntUE : Any, otUE : Any> importAndUpgradeTable(
namespace: Namespace<nmUE, RK> = this.rootNs, name: String, namespace: Namespace<nmUE, RK> = this.rootNs, name: String,
table: Table<otUE, *, RK>, table: Table<otUE, *, RK>,
upgrade: TableUpgrade<ntUE, otUE, RK> upgrade: Table.Upgrade<ntUE, otUE, RK>
): Table<ntUE, nmUE, RK> ): Table<ntUE, nmUE, RK>
public fun <smUE : Any> keepModule(module: Module<smUE, RK>): Module<smUE, RK> public fun <smUE : Any> keepModule(module: Module<smUE, RK>): Module<smUE, RK>

View File

@ -36,4 +36,12 @@ public interface Table<UE : Any, mUE : Any, RUNTIME_KEY : Any> {
@Suppress("INAPPLICABLE_JVM_NAME") @Suppress("INAPPLICABLE_JVM_NAME")
@get:JvmName("getLifeTime") @get:JvmName("getLifeTime")
public val lifeTime: LifeTime public val lifeTime: LifeTime
public interface Constructor<tUE : Any, RK : Any> {
public fun createTable(context: TableConstructorScope<tUE, RK>): tUE
}
public interface Upgrade<tnUE : Any, toUE : Any, RK : Any> {
public fun upgradeTable(oldTable: toUE, context: TableUpgradeScope<tnUE, toUE, RK>): tnUE
}
} }

View File

@ -1,28 +0,0 @@
package ru.landgrafhomyak.db.skeleton1.api.table
import ru.landgrafhomyak.db.skeleton1.api.LowLevelApi
import ru.landgrafhomyak.db.skeleton1.api.DatabaseType
import ru.landgrafhomyak.db.skeleton1.api.statement.RawStatement
import ru.landgrafhomyak.db.skeleton1.api.statement._Statement
import ru.landgrafhomyak.db.skeleton1.api.runtime.InputRow
public interface TableConstructor<tUE : Any, RK : Any> {
public fun createTable(context: Scope<tUE, RK>): tUE
public interface Scope<tUE : Any, RK : Any> {
public fun <RT> column(name: String, type: DatabaseType.ImplementationsProvider<RT>, manualCreate: Boolean = false): Column<RT, tUE, RK>
public fun <RT, ttUE : Any> columnWithBoundType(name: String, foreign: Column<RT, ttUE, RK>): Column<RT, tUE, RK>
public fun tableScopedObject(name: String): TableScopedObject<tUE, RK>
public fun addAlterStatement(stmt: _Statement.Void2Void<*, RK>)
public fun addAlterStatement(stmt: RawStatement.Void2Void.ImplementationsProvider<*>)
@LowLevelApi
public fun <sUE : Any> _addAlterStatement(stmt: _Statement.Void2Void<sUE, RK>): InputRow._Scope<sUE, RK, Unit>
@LowLevelApi
public fun <sUE : Any> _addAlterStatement(stmt: RawStatement.Params2Void.ImplementationsProvider<sUE>): InputRow._Scope<sUE, RK, Unit>
}
}

View File

@ -0,0 +1,24 @@
package ru.landgrafhomyak.db.skeleton1.api.table
import ru.landgrafhomyak.db.skeleton1.api.LowLevelApi
import ru.landgrafhomyak.db.skeleton1.api.DatabaseType
import ru.landgrafhomyak.db.skeleton1.api.statement.RawStatement
import ru.landgrafhomyak.db.skeleton1.api.statement._Statement
import ru.landgrafhomyak.db.skeleton1.api.runtime.InputRow
public interface TableConstructorScope<tUE : Any, RK : Any> {
public fun <RT> column(name: String, type: DatabaseType.ImplementationsProvider<RT>, manualCreate: Boolean = false): Column<RT, tUE, RK>
public fun <RT, ttUE : Any> columnWithBoundType(name: String, foreign: Column<RT, ttUE, RK>): Column<RT, tUE, RK>
public fun tableScopedObject(name: String): TableScopedObject<tUE, RK>
public fun addAlterStatement(stmt: _Statement.Void2Void<*, RK>)
public fun addAlterStatement(stmt: RawStatement.Void2Void.ImplementationsProvider<*>)
@LowLevelApi
public fun <sUE : Any> _addAlterStatement(stmt: _Statement.Void2Void<sUE, RK>): InputRow._Scope<sUE, RK, Unit>
@LowLevelApi
public fun <sUE : Any> _addAlterStatement(stmt: RawStatement.Params2Void.ImplementationsProvider<sUE>): InputRow._Scope<sUE, RK, Unit>
}

View File

@ -1,39 +0,0 @@
package ru.landgrafhomyak.db.skeleton1.api.table
import ru.landgrafhomyak.db.skeleton1.api.LowLevelApi
import ru.landgrafhomyak.db.skeleton1.api.statement.RawStatement
import ru.landgrafhomyak.db.skeleton1.api.statement._Statement
import ru.landgrafhomyak.db.skeleton1.api.runtime.InputRow
public interface TableUpgrade<tnUE : Any, toUE : Any, RK : Any> {
public fun upgradeTable(oldTable: toUE, context: Scope<tnUE, toUE, RK>): tnUE
public interface Scope<tnUE : Any, toUE : Any, RK : Any> : TableConstructor.Scope<tnUE, RK> {
public fun <RT> keepColumn(c: Column<RT, toUE, RK>): Column<RT, tnUE, RK>
public fun <RT> renameColumn(c: Column<RT, toUE, RK>, newName: String): Column<RT, tnUE, RK>
public fun removeColumn(c: Column<*, toUE, RK>)
public fun <RT> removeColumnAfterUpgrade(c: Column<RT, toUE, RK>): Column<RT, tnUE, RK>
public fun <RT> keepColumnWithBoundType(c: Column<RT, toUE, RK>): Column<RT, tnUE, RK>
public fun <RT> unbindAndKeepColumnWithBoundType(c: Column<RT, toUE, RK>): Column<RT, tnUE, RK>
public fun <RT> renameColumnWithBoundType(c: Column<RT, toUE, RK>, newName: String): Column<RT, tnUE, RK>
public fun <RT> unbindAndRenameColumnWithBoundType(c: Column<RT, toUE, RK>, newName: String): Column<RT, tnUE, RK>
public fun removeColumnWithBoundType(c: Column<*, toUE, RK>)
public fun <RT> removeColumnWithBoundTypeAfterUpgrade(c: Column<RT, toUE, RK>): Column<RT, tnUE, RK>
public fun keepTableScopedObject(obj: TableScopedObject<toUE, RK>): TableScopedObject<tnUE, RK>
public fun renameTableScopedObject(obj: TableScopedObject<toUE, RK>, newName: String): TableScopedObject<tnUE, RK>
public fun removeTableScopedObject(obj: TableScopedObject<toUE, RK>): TableScopedObject<tnUE, RK>
public fun addAlterStatementAfterUpgrade(stmt: _Statement.Void2Void<*, RK>)
public fun addAlterStatementAfterUpgrade(stmt: RawStatement.Void2Void.ImplementationsProvider<*>)
@LowLevelApi
public fun <sUE : Any> _addAlterStatementAfterUpgrade(stmt: _Statement.Params2Void<sUE, RK>): InputRow._Scope<sUE, RK, Unit>
@LowLevelApi
public fun <sUE : Any> _addAlterStatementAfterUpgrade(stmt: RawStatement.Params2Void.ImplementationsProvider<sUE>): InputRow._Scope<sUE, RK, Unit>
}
}

View File

@ -0,0 +1,34 @@
package ru.landgrafhomyak.db.skeleton1.api.table
import ru.landgrafhomyak.db.skeleton1.api.LowLevelApi
import ru.landgrafhomyak.db.skeleton1.api.statement.RawStatement
import ru.landgrafhomyak.db.skeleton1.api.statement._Statement
import ru.landgrafhomyak.db.skeleton1.api.runtime.InputRow
public interface TableUpgradeScope<tnUE : Any, toUE : Any, RK : Any> : TableConstructorScope<tnUE, RK> {
public fun <RT> keepColumn(c: Column<RT, toUE, RK>): Column<RT, tnUE, RK>
public fun <RT> renameColumn(c: Column<RT, toUE, RK>, newName: String): Column<RT, tnUE, RK>
public fun removeColumn(c: Column<*, toUE, RK>)
public fun <RT> removeColumnAfterUpgrade(c: Column<RT, toUE, RK>): Column<RT, tnUE, RK>
public fun <RT> keepColumnWithBoundType(c: Column<RT, toUE, RK>): Column<RT, tnUE, RK>
public fun <RT> unbindAndKeepColumnWithBoundType(c: Column<RT, toUE, RK>): Column<RT, tnUE, RK>
public fun <RT> renameColumnWithBoundType(c: Column<RT, toUE, RK>, newName: String): Column<RT, tnUE, RK>
public fun <RT> unbindAndRenameColumnWithBoundType(c: Column<RT, toUE, RK>, newName: String): Column<RT, tnUE, RK>
public fun removeColumnWithBoundType(c: Column<*, toUE, RK>)
public fun <RT> removeColumnWithBoundTypeAfterUpgrade(c: Column<RT, toUE, RK>): Column<RT, tnUE, RK>
public fun keepTableScopedObject(obj: TableScopedObject<toUE, RK>): TableScopedObject<tnUE, RK>
public fun renameTableScopedObject(obj: TableScopedObject<toUE, RK>, newName: String): TableScopedObject<tnUE, RK>
public fun removeTableScopedObject(obj: TableScopedObject<toUE, RK>): TableScopedObject<tnUE, RK>
public fun addAlterStatementAfterUpgrade(stmt: _Statement.Void2Void<*, RK>)
public fun addAlterStatementAfterUpgrade(stmt: RawStatement.Void2Void.ImplementationsProvider<*>)
@LowLevelApi
public fun <sUE : Any> _addAlterStatementAfterUpgrade(stmt: _Statement.Params2Void<sUE, RK>): InputRow._Scope<sUE, RK, Unit>
@LowLevelApi
public fun <sUE : Any> _addAlterStatementAfterUpgrade(stmt: RawStatement.Params2Void.ImplementationsProvider<sUE>): InputRow._Scope<sUE, RK, Unit>
}