diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/db/raw_sql_skeleton/Namespace.kt b/src/commonMain/kotlin/ru/landgrafhomyak/db/raw_sql_skeleton/Namespace.kt index 70cb351..d0a3c49 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/db/raw_sql_skeleton/Namespace.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/db/raw_sql_skeleton/Namespace.kt @@ -1,26 +1,31 @@ package ru.landgrafhomyak.db.raw_sql_skeleton public class Namespace( - public val _name: String, - private val path: Array + public val name: String, + private val _path: Array ) { - private val usedNames = HashSet() + private val _usedNames = HashSet() - public fun subnamespace(name: String): Namespace { - if (name in this.usedNames) - throw IllegalArgumentException("Name is already used: $name") - this.usedNames.add(name) - return Namespace(name, this.path + this._name) + private fun _allocName(name: String): String { + if (!this._usedNames.add(name)) + throw IllegalArgumentException("Name duplication: $name") + return name } + private fun _formatTableName(name: String) = this._path.joinToString(prefix = "::", separator = "::", postfix = "::${this.name}::${name}") + + public fun subnamespace(name: String): Namespace = + Namespace(this._allocName(name), this._path + this.name) + + public fun table(name: String): Table { - if (name in this.usedNames) - throw IllegalArgumentException("Name is already used: $name") - this.usedNames.add(name) - - return Table(this, this.formatTableName(name)) + return Table(this, this._formatTableName(this._allocName(name))) } - public val _path: List = this.path.asList() - private fun formatTableName(name: String) = this.path.joinToString(prefix = "::", separator = "::", postfix = "::${this._name}::${name}") + public fun table(name: String, constructor: TableConstructor): tUE { + val table = this.table(name) + return constructor.createTable(table, TableConstructor.Scope(table)) + } + + public val path: List = this._path.asList() } \ No newline at end of file