diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/Expression.kt b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/Expression.kt index c36f3d2..44ab21f 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/Expression.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/Expression.kt @@ -6,15 +6,15 @@ public interface Expression, public interface Builder { public fun > equals( left: Expression, - right: Expression + right: Expression, ): Expression public fun isNull( - e: Expression<*, *, OwnerBuilderUserExtension>, + e: Expression<*, ColumnType.Nullable<*, *>, OwnerBuilderUserExtension>, ): Expression public fun isNotNull( - e: Expression<*, *, OwnerBuilderUserExtension>, + e: Expression<*, ColumnType.Nullable<*, *>, OwnerBuilderUserExtension>, ): Expression } } \ No newline at end of file diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/ddl/ColumnType.kt b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/ddl/ColumnType.kt index 7caadad..e340724 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/ddl/ColumnType.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/ddl/ColumnType.kt @@ -1,141 +1,96 @@ package ru.landgrafhomyak.serdha.api.v0.ddl -import kotlin.jvm.JvmStatic +import kotlin.jvm.JvmField import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalDateTime import kotlinx.datetime.LocalTime -@Suppress("ClassName") -public abstract class ColumnType { - public abstract val typeName: String +@OptIn(ExperimentalUnsignedTypes::class) +@Suppress("ClassName", "RemoveRedundantQualifierName") +public interface ColumnType<@Suppress("unused") RuntimeType> { + public val typeName: String - abstract override fun toString(): String + @Suppress("FunctionName", "PropertyName") + public interface Builder { + public fun ROW_ID(): ColumnType> - public sealed class _StandardType : ColumnType() { - override fun toString(): String = "" + public val BOOLEAN: ColumnType.BOOLEAN + + public val INT_S8: ColumnType.INT_S8 + + public val INT_U8: ColumnType.INT_U8 + + public val INT_S16: ColumnType.INT_S16 + + public val INT_U16: ColumnType.INT_U16 + + public val INT_S32: ColumnType.INT_S32 + + public val INT_U32: ColumnType.INT_U32 + + public val INT_S64: ColumnType.INT_S64 + + public val INT_U64: ColumnType.INT_U64 + + public val LOCAL_DATE: ColumnType.LOCAL_DATE + + public val LOCAL_TIME: ColumnType.LOCAL_TIME + + public val LOCAL_DATETIME: ColumnType.LOCAL_DATETIME + + public val INSTANT: ColumnType.INSTANT + + public val FLOAT_32: ColumnType.FLOAT_32 + + public val FLOAT_64: ColumnType.FLOAT_64 + + public val STRING: ColumnType.STRING + public fun STRING(size: UInt): ColumnType.STRING + + public val BYTE_ARRAY: ColumnType.BYTE_ARRAY + public fun BYTE_ARRAY(size: UInt): ColumnType.BYTE_ARRAY + + public fun > nullableOf(d: D): Nullable } - public abstract class _VirtualType(@Suppress("MemberVisibilityCanBePrivate") public val wraps: ColumnType) { - override fun toString(): String = "" - } + public abstract class _VirtualType(@Suppress("MemberVisibilityCanBePrivate") @JvmField public val wraps: ColumnType) - public class NULLABLE(@Suppress("MemberVisibilityCanBePrivate") public val notNullType: ColumnType) : _StandardType() { - init { - if (this.notNullType is NULLABLE<*>) - throw IllegalArgumentException("Type can't be nullable twice") - } + public interface Nullable> : ColumnType - override val typeName: String = this.notNullType.typeName + "?" - } + public interface ROW_ID : ColumnType> - public object ROW_ID : _StandardType>() { - override val typeName: String get() = "ROW_ID" - } + public interface BOOLEAN : ColumnType - public object BOOLEAN : _StandardType() { - override val typeName: String get() = "BOOLEAN" - } + public interface INT_S8 : ColumnType - public object INT_S8 : _StandardType() { - override val typeName: String get() = "INT_S8" - } + public interface INT_U8 : ColumnType - public object INT_U8 : _StandardType() { - override val typeName: String get() = "INT_U8" - } + public interface INT_S16 : ColumnType - public object INT_S16 : _StandardType() { - override val typeName: String get() = "INT_S16" - } + public interface INT_U16 : ColumnType - public object INT_U16 : _StandardType() { - override val typeName: String get() = "INT_U16" - } + public interface INT_S32 : ColumnType - public object INT_S32 : _StandardType() { - override val typeName: String get() = "INT_S32" - } + public interface INT_U32 : ColumnType - public object INT_U32 : _StandardType() { - override val typeName: String get() = "INT_U32" - } + public interface INT_S64 : ColumnType - public object INT_S64 : _StandardType() { - override val typeName: String get() = "INT_S64" - } + public interface INT_U64 : ColumnType - public object INT_U64 : _StandardType() { - override val typeName: String get() = "INT_U64" - } + public interface LOCAL_DATE : ColumnType - public object LOCAL_DATE : _StandardType() { - override val typeName: String get() = "LOCAL_DATE" - } + public interface LOCAL_TIME : ColumnType - public object LOCAL_TIME : _StandardType() { - override val typeName: String get() = "LOCAL_TIME" - } + public interface LOCAL_DATETIME : ColumnType - public object LOCAL_DATETIME : _StandardType() { - override val typeName: String get() = "LOCAL_DATETIME" - } + public interface INSTANT : ColumnType - public object INSTANT : _StandardType() { - override val typeName: String get() = "INSTANT" - } + public interface FLOAT_32 : ColumnType - public object FLOAT_32 : _StandardType() { - override val typeName: String get() = "FLOAT_32" - } + public interface FLOAT_64 : ColumnType - public object FLOAT_64 : _StandardType() { - override val typeName: String get() = "FLOAT_64" - } + public interface STRING : ColumnType - public class STRING internal constructor( - private val _size: UInt - ) : _StandardType() { - override val typeName: String = if (this._size == 0u) "STRING" else "STRING(${this._size})" - - public val size: UInt? get() = if (this._size == 0u) null else this._size - } - - public class BYTE_ARRAY internal constructor( - private val _size: UInt - ) : _StandardType() { - override val typeName: String = if (this._size == 0u) "BYTE_ARRAY" else "BYTE_ARRAY(${this._size})" - - public val size: UInt? get() = if (this._size == 0u) null else this._size - } - - public companion object DSL { - @Suppress("RemoveRedundantQualifierName") - @JvmStatic - public val STRING: STRING = ColumnType.STRING(0u) - - @Suppress("RemoveRedundantQualifierName") - @JvmStatic - public fun STRING(size: UInt): STRING { - if (size == 0u) - throw IllegalArgumentException("Size of string can't be 0") - return ColumnType.STRING(size) - } - - @Suppress("RemoveRedundantQualifierName") - @JvmStatic - public val BYTE_ARRAY: BYTE_ARRAY = ColumnType.BYTE_ARRAY(0u) - - @Suppress("RemoveRedundantQualifierName") - @JvmStatic - public fun BYTE_ARRAY(size: UInt): BYTE_ARRAY { - if (size == 0u) - throw IllegalArgumentException("Size of byte array can't be 0") - return ColumnType.BYTE_ARRAY(size) - } - - @Suppress("FunctionName", "UNCHECKED_CAST", "RemoveRedundantQualifierName") - @JvmStatic - public fun ROW_ID(): ColumnType> = ColumnType.ROW_ID as ColumnType> - } + public interface BYTE_ARRAY : ColumnType } diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/ddl/TableCreator.kt b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/ddl/TableCreator.kt index 46f5a63..be4fd17 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/ddl/TableCreator.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/ddl/TableCreator.kt @@ -6,6 +6,8 @@ import ru.landgrafhomyak.serdha.api.v0.Expression public interface TableCreator { public val expressionBuilder: Expression.Builder + public val types: ColumnType.Builder + /** * Offers column of type [D][type] with `NOT NULL` constraint named [name] and runtime type [RuntimeType]. * @@ -27,7 +29,7 @@ public interface TableCreator { toTable: Table, toColumn: Column<*, ColumnType1, TargetTableUserWrapper>, onUpdate: ForeignKey.OnUpdateAction, - onDelete: ForeignKey.OnDeleteAction + onDelete: ForeignKey.OnDeleteAction, ): ForeignKey public fun , ColumnType2 : ColumnType<*>> foreignKey( @@ -37,7 +39,7 @@ public interface TableCreator { toColumn1: Column<*, ColumnType1, TargetTableUserWrapper>, toColumn2: Column<*, ColumnType2, TargetTableUserWrapper>, onUpdate: ForeignKey.OnUpdateAction, - onDelete: ForeignKey.OnDeleteAction + onDelete: ForeignKey.OnDeleteAction, ): ForeignKey public fun , ColumnType2 : ColumnType<*>, ColumnType3 : ColumnType<*>> foreignKey( @@ -49,6 +51,6 @@ public interface TableCreator { toColumn2: Column<*, ColumnType2, TargetTableUserWrapper>, toColumn3: Column<*, ColumnType3, TargetTableUserWrapper>, onUpdate: ForeignKey.OnUpdateAction, - onDelete: ForeignKey.OnDeleteAction + onDelete: ForeignKey.OnDeleteAction, ): ForeignKey } \ No newline at end of file diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/dml/_CommonQueryMethods.kt b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/dml/_CommonQueryMethods.kt index 07a2d6d..daac7a9 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/dml/_CommonQueryMethods.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/serdha/api/v0/dml/_CommonQueryMethods.kt @@ -8,6 +8,8 @@ import ru.landgrafhomyak.serdha.api.v0.runtime.ParametersSetter @Suppress("ClassName") public interface _CommonQueryMethods { + public val types: ColumnType.Builder + public fun selectTable(t: Table): SelectedTable public interface CanBeSubquery<@Suppress("unused") SelectedQueryUserExtension : Any>