TableConstructor moved into Table
This commit is contained in:
parent
f1bd010c62
commit
9d2c04a2ad
@ -22,18 +22,18 @@ public class Namespace(
|
||||
return Table(this, this._formatTableName(this._allocName(name)))
|
||||
}
|
||||
|
||||
public fun <tUE : Any> table(name: String, constructor: TableConstructor<tUE>): tUE {
|
||||
public fun <tUE : Any> table(name: String, constructor: Table.Constructor<tUE>): tUE {
|
||||
val table = this.table(name)
|
||||
return constructor.createTable(table, TableConstructor.Scope(table))
|
||||
return constructor.createTable(table, Table.Constructor.Scope(table))
|
||||
}
|
||||
|
||||
public fun <tUE : Any> table(name: String, constructor: (table: Table, members: TableConstructor.Scope) -> tUE): tUE =
|
||||
public fun <tUE : Any> table(name: String, constructor: (table: Table, members: Table.Constructor.Scope) -> tUE): tUE =
|
||||
this.table(name, DefaultTableConstructorWrapper(constructor))
|
||||
|
||||
public val path: List<String> = this._path.asList()
|
||||
|
||||
private class DefaultTableConstructorWrapper<tUE : Any>(private val fn: (table: Table, members: TableConstructor.Scope) -> tUE) : TableConstructor<tUE> {
|
||||
override fun createTable(table: Table, members: TableConstructor.Scope): tUE = this.fn(table, members)
|
||||
private class DefaultTableConstructorWrapper<tUE : Any>(private val fn: (table: Table, members: Table.Constructor.Scope) -> tUE) : Table.Constructor<tUE> {
|
||||
override fun createTable(table: Table, members: Table.Constructor.Scope): tUE = this.fn(table, members)
|
||||
}
|
||||
|
||||
public companion object {
|
||||
|
@ -8,4 +8,33 @@ public class Table(
|
||||
public val asSqlString: String = "\'${this.name}\'"
|
||||
|
||||
override fun toString(): String = this.asSqlReference
|
||||
|
||||
public interface Constructor<TableUserExtension : Any> {
|
||||
public fun createTable(table: Table, members: Scope): TableUserExtension
|
||||
|
||||
public class Scope internal constructor(private val _table: Table) {
|
||||
private val _usedNames = HashSet<String>()
|
||||
|
||||
private fun _allocName(name: String): String {
|
||||
if (!this._usedNames.add(name))
|
||||
throw IllegalArgumentException("Name duplication: $name")
|
||||
return name
|
||||
}
|
||||
|
||||
public fun column(name: String, type: String): Column =
|
||||
Column(this._table, this._allocName(name), type)
|
||||
|
||||
public fun column(name: String, referenceType: String, declarationType: String): Column =
|
||||
Column(this._table, this._allocName(name), referenceType, declarationType)
|
||||
|
||||
public fun index(name: String): NamedTableMember =
|
||||
NamedTableMember(this._table, this._allocName(name))
|
||||
|
||||
public fun uniqueIndex(name: String): NamedTableMember =
|
||||
NamedTableMember(this._table, this._allocName(name))
|
||||
|
||||
public fun checkConstraint(name: String): NamedTableMember =
|
||||
NamedTableMember(this._table, this._allocName(name))
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package ru.landgrafhomyak.db.raw_sql_skeleton
|
||||
|
||||
|
||||
public interface TableConstructor<TableUserExtension : Any> {
|
||||
public fun createTable(table: Table, members: Scope): TableUserExtension
|
||||
|
||||
public class Scope internal constructor(private val _table: Table) {
|
||||
private val _usedNames = HashSet<String>()
|
||||
|
||||
private fun _allocName(name: String): String {
|
||||
if (!this._usedNames.add(name))
|
||||
throw IllegalArgumentException("Name duplication: $name")
|
||||
return name
|
||||
}
|
||||
|
||||
public fun column(name: String, type: String): Column =
|
||||
Column(this._table, this._allocName(name), type)
|
||||
|
||||
public fun column(name: String, referenceType: String, declarationType: String): Column =
|
||||
Column(this._table, this._allocName(name), referenceType, declarationType)
|
||||
|
||||
public fun index(name: String): NamedTableMember =
|
||||
NamedTableMember(this._table, this._allocName(name))
|
||||
|
||||
public fun uniqueIndex(name: String): NamedTableMember =
|
||||
NamedTableMember(this._table, this._allocName(name))
|
||||
|
||||
public fun checkConstraint(name: String): NamedTableMember =
|
||||
NamedTableMember(this._table, this._allocName(name))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user