Conditions clause was replaced with filters
This commit is contained in:
parent
461f8e0d9c
commit
5bc1f1dfca
@ -2,11 +2,8 @@ package ru.landgrafhomyak.serdha.api.v0.misc
|
|||||||
|
|
||||||
import kotlin.jvm.JvmField
|
import kotlin.jvm.JvmField
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
import kotlinx.datetime.Instant
|
|
||||||
import kotlinx.datetime.LocalDate
|
|
||||||
import kotlinx.datetime.LocalDateTime
|
|
||||||
import kotlinx.datetime.LocalTime
|
|
||||||
import ru.landgrafhomyak.serdha.api.v0.table.RowId
|
import ru.landgrafhomyak.serdha.api.v0.table.RowId
|
||||||
|
import ru.landgrafhomyak.serdha.api.v0.table.Table
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Descriptor of a database type.
|
* Descriptor of a database type.
|
||||||
@ -19,33 +16,32 @@ public interface DatabaseType<@Suppress("unused") RuntimeType> {
|
|||||||
@get:JvmName("name")
|
@get:JvmName("name")
|
||||||
public val name: String
|
public val name: String
|
||||||
|
|
||||||
public abstract class _VirtualType<SRT, WRT : Any>(
|
public abstract class _VirtualType<RT, wRT, wDT : DatabaseType<wRT>>(
|
||||||
@Suppress("MemberVisibilityCanBePrivate") @JvmField
|
@Suppress("MemberVisibilityCanBePrivate") @JvmField
|
||||||
public val wraps: DatabaseType<WRT>
|
public val wraps: wDT
|
||||||
) : DatabaseType<SRT> {
|
) : DatabaseType<RT> {
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
public abstract fun _unwrap(w: WRT): SRT
|
public abstract fun _unwrap(w: wRT): RT
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
public abstract fun _wrap(w: SRT): WRT
|
public abstract fun _wrap(w: RT): wRT
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
public abstract fun _equals(l: SRT, r: SRT): Boolean
|
public abstract fun _equals(l: RT, r: RT): Boolean
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
public abstract fun _compare(l: SRT, r: SRT): Int
|
public abstract fun _compare(l: RT, r: RT): Int
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface _ROW_ID<T : RowId<TargetTableUserWrapper>?, TargetTableUserWrapper : Any> : DatabaseType<T>
|
public interface Nullable<RT : Any, @Suppress("unused") DT : DatabaseType<RT>> : DatabaseType<RT?>
|
||||||
public interface ROW_ID<TargetTableUserWrapper : Any> : _ROW_ID<RowId<TargetTableUserWrapper>, TargetTableUserWrapper>
|
|
||||||
public interface NULLABLE_ROW_ID<TargetTableUserWrapper : Any> : _ROW_ID<RowId<TargetTableUserWrapper>?, TargetTableUserWrapper>
|
public interface ROW_ID<TargetTableUserWrapper : Any> : DatabaseType<RowId<TargetTableUserWrapper>>
|
||||||
|
|
||||||
public interface BOOLEAN : DatabaseType<Boolean>
|
public interface BOOLEAN : DatabaseType<Boolean>
|
||||||
public interface NULLABLE_BOOLEAN : DatabaseType<Boolean?>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Descriptor of a raw binary data type for static type-checking.
|
* Descriptor of a raw binary data type for static type-checking.
|
||||||
* @see DatabaseTypesProvider.BINARY_DATA
|
* @see DatabaseType.Provider.BINARY_DATA
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalUnsignedTypes::class)
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
public interface BINARY_DATA : DatabaseType<UByteArray> {
|
public interface BINARY_DATA : DatabaseType<UByteArray> {
|
||||||
@ -59,4 +55,25 @@ public interface DatabaseType<@Suppress("unused") RuntimeType> {
|
|||||||
*/
|
*/
|
||||||
public val isFixedSize: Boolean
|
public val isFixedSize: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface Provider {
|
||||||
|
@Suppress("INAPPLICABLE_JVM_NAME", "FunctionName")
|
||||||
|
@JvmName("ROW_ID")
|
||||||
|
public fun <TableUserExtension : Any> ROW_ID(table: Table<TableUserExtension, *>): DatabaseType<RowId<TableUserExtension>>
|
||||||
|
|
||||||
|
@Suppress("INAPPLICABLE_JVM_NAME", "PropertyName")
|
||||||
|
@get:JvmName("BOOLEAN")
|
||||||
|
public val BOOLEAN: DatabaseType.BOOLEAN
|
||||||
|
|
||||||
|
@Suppress("INAPPLICABLE_JVM_NAME", "PropertyName")
|
||||||
|
@get:JvmName("BINARY_DATA")
|
||||||
|
public val BINARY_DATA: DatabaseType.BINARY_DATA
|
||||||
|
|
||||||
|
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||||
|
@JvmName("BINARY_DATA")
|
||||||
|
public fun BINARY_DATA(size: UInt, isFixedSize: Boolean): DatabaseType.BINARY_DATA
|
||||||
|
|
||||||
|
public fun <RT : Any, DT : DatabaseType<RT>> nullableOf(notNull: DT): DatabaseType.Nullable<RT, DT>
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
package ru.landgrafhomyak.serdha.api.v0.misc
|
|
||||||
|
|
||||||
import kotlin.jvm.JvmName
|
|
||||||
import ru.landgrafhomyak.serdha.api.v0.table.RowId
|
|
||||||
import ru.landgrafhomyak.serdha.api.v0.table.Table
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provider of database types descriptors.
|
|
||||||
*/
|
|
||||||
@Suppress("FunctionName", "PropertyName")
|
|
||||||
public interface DatabaseTypesProvider {
|
|
||||||
/**
|
|
||||||
* Type of internal row id. Can't be casted to types like integers or pointers.
|
|
||||||
* @param TableUserExtension User's extension type for target table. For static type checking.
|
|
||||||
* @param table Descriptor of table whose row_id type will be obtained.
|
|
||||||
*/
|
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
|
||||||
@JvmName("ROW_ID")
|
|
||||||
public fun <TableUserExtension : Any> ROW_ID(table: Table<TableUserExtension, *>): DatabaseType<RowId<TableUserExtension>>
|
|
||||||
|
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
|
||||||
@JvmName("NULLABLE_ROW_ID")
|
|
||||||
public fun <TableUserExtension : Any> NULLABLE_ROW_ID(table: Table<TableUserExtension, *>): DatabaseType<RowId<TableUserExtension>>
|
|
||||||
|
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
|
||||||
@get:JvmName("BOOLEAN")
|
|
||||||
public val BOOLEAN: DatabaseType.BOOLEAN
|
|
||||||
|
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
|
||||||
@get:JvmName("NULLABLE_BOOLEAN")
|
|
||||||
public val NULLABLE_BOOLEAN: DatabaseType.NULLABLE_BOOLEAN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Descriptor of a raw binary data type without size restrictions (must be controlled by user).
|
|
||||||
*/
|
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
|
||||||
@get:JvmName("BINARY_DATA")
|
|
||||||
public val BINARY_DATA: DatabaseType.BINARY_DATA
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Descriptor of a raw binary data type that can holds maximum [size] bytes.
|
|
||||||
*
|
|
||||||
* @param size Maximum count of bytes that can be stored in the value of this type.
|
|
||||||
* @param isFixedSize If `true`, the type will restrict values with less than [size] bytes.
|
|
||||||
*/
|
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
|
||||||
@JvmName("BINARY_DATA")
|
|
||||||
public fun BINARY_DATA(size: UInt, isFixedSize: Boolean): DatabaseType.BINARY_DATA
|
|
||||||
}
|
|
@ -0,0 +1,20 @@
|
|||||||
|
package ru.landgrafhomyak.serdha.api.v0.misc
|
||||||
|
|
||||||
|
public interface FiltersScope<oqUE : Any> {
|
||||||
|
public fun <RT : Any, DT : DatabaseType<RT>> filterNotNull(nullable: IntermediateColumn<RT?, DatabaseType.Nullable<RT, DT>, oqUE>): IntermediateColumn<RT, DT, oqUE>
|
||||||
|
public fun <RT : Any, DT : DatabaseType<RT>> filterIsNull(nullable: IntermediateColumn<RT?, DatabaseType.Nullable<RT, DT>, oqUE>)
|
||||||
|
|
||||||
|
public enum class ComparisonType {
|
||||||
|
EQUALS,
|
||||||
|
NOT_EQUALS,
|
||||||
|
LESS,
|
||||||
|
LESS_OR_EQUALS,
|
||||||
|
GREATER,
|
||||||
|
GREATER_OR_EQUALS,
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun <RT : Any, DT : DatabaseType<RT>> compareWithParam(column: IntermediateColumn<RT, DT, oqUE>, operator: ComparisonType, param: QueryParam<RT, DT, oqUE>)
|
||||||
|
public fun <RT : Any, DT : DatabaseType<RT>> compareWithConstant(column: IntermediateColumn<RT, DT, oqUE>, operator: ComparisonType, constant: RT)
|
||||||
|
public fun ifTrue(column: IntermediateColumn<Boolean, DatabaseType.BOOLEAN, oqUE>)
|
||||||
|
public fun ifFalse(column: IntermediateColumn<Boolean, DatabaseType.BOOLEAN, oqUE>)
|
||||||
|
}
|
@ -2,7 +2,6 @@ package ru.landgrafhomyak.serdha.api.v0.queries
|
|||||||
|
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.Column
|
import ru.landgrafhomyak.serdha.api.v0.misc.Column
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType
|
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseTypesProvider
|
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.QueryParam
|
import ru.landgrafhomyak.serdha.api.v0.misc.QueryParam
|
||||||
import ru.landgrafhomyak.serdha.api.v0.runtime.InputRow
|
import ru.landgrafhomyak.serdha.api.v0.runtime.InputRow
|
||||||
import ru.landgrafhomyak.serdha.api.v0.table.RowId
|
import ru.landgrafhomyak.serdha.api.v0.table.RowId
|
||||||
@ -16,7 +15,7 @@ public interface DeleteQuery<qUE : Any> : _Query<qUE> {
|
|||||||
public interface Scope<qUE : Any, ttUE : Any> {
|
public interface Scope<qUE : Any, ttUE : Any> {
|
||||||
public val tt: Table<ttUE, *>
|
public val tt: Table<ttUE, *>
|
||||||
|
|
||||||
public val types: DatabaseTypesProvider
|
public val types: DatabaseType.Provider
|
||||||
public fun <RT, DT : DatabaseType<RT>> param(name: String, type: DT): QueryParam<RT, DT, qUE>
|
public fun <RT, DT : DatabaseType<RT>> param(name: String, type: DT): QueryParam<RT, DT, qUE>
|
||||||
|
|
||||||
public var rowToRemove: QueryParam<*, DatabaseType.ROW_ID<ttUE>, qUE>
|
public var rowToRemove: QueryParam<*, DatabaseType.ROW_ID<ttUE>, qUE>
|
||||||
@ -39,7 +38,7 @@ public interface DeleteQuery<qUE : Any> : _Query<qUE> {
|
|||||||
public val tt: Table<ttUE, *>
|
public val tt: Table<ttUE, *>
|
||||||
public val sUExt: sUE
|
public val sUExt: sUE
|
||||||
|
|
||||||
public val types: DatabaseTypesProvider
|
public val types: DatabaseType.Provider
|
||||||
public fun <RT, DT : DatabaseType<RT>> param(name: String, type: DT): QueryParam<RT, DT, qUE>
|
public fun <RT, DT : DatabaseType<RT>> param(name: String, type: DT): QueryParam<RT, DT, qUE>
|
||||||
|
|
||||||
public val selectorParams: InputRow.WithRedirect<sUE, qUE>
|
public val selectorParams: InputRow.WithRedirect<sUE, qUE>
|
||||||
|
@ -3,7 +3,6 @@ package ru.landgrafhomyak.serdha.api.v0.queries
|
|||||||
import ru.landgrafhomyak.serdha.api.v0.misc.Column
|
import ru.landgrafhomyak.serdha.api.v0.misc.Column
|
||||||
import ru.landgrafhomyak.serdha.api.v0.table.Table
|
import ru.landgrafhomyak.serdha.api.v0.table.Table
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType
|
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseTypesProvider
|
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.QueryParam
|
import ru.landgrafhomyak.serdha.api.v0.misc.QueryParam
|
||||||
import ru.landgrafhomyak.serdha.api.v0.runtime.InputRow
|
import ru.landgrafhomyak.serdha.api.v0.runtime.InputRow
|
||||||
import ru.landgrafhomyak.serdha.api.v0.table.UniqueIndex
|
import ru.landgrafhomyak.serdha.api.v0.table.UniqueIndex
|
||||||
@ -19,7 +18,7 @@ public interface InsertQuery<qUE : Any> : _Query<qUE> {
|
|||||||
|
|
||||||
@Suppress("ClassName")
|
@Suppress("ClassName")
|
||||||
public interface _CommonInsertCreatorScope<qUE : Any, ttUE : Any> {
|
public interface _CommonInsertCreatorScope<qUE : Any, ttUE : Any> {
|
||||||
public val types: DatabaseTypesProvider
|
public val types: DatabaseType.Provider
|
||||||
|
|
||||||
public fun onConflictUpdate(u: UniqueIndex<ttUE>, c: (_UpsertClauseScope<qUE, ttUE>) -> Unit)
|
public fun onConflictUpdate(u: UniqueIndex<ttUE>, c: (_UpsertClauseScope<qUE, ttUE>) -> Unit)
|
||||||
public fun onConflictThrow(u: UniqueIndex<ttUE>)
|
public fun onConflictThrow(u: UniqueIndex<ttUE>)
|
||||||
|
@ -4,8 +4,8 @@ import ru.landgrafhomyak.serdha.api.v0.misc.BuiltinExpressionsProvider
|
|||||||
import ru.landgrafhomyak.serdha.api.v0.misc.Column
|
import ru.landgrafhomyak.serdha.api.v0.misc.Column
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.IntermediateColumn
|
import ru.landgrafhomyak.serdha.api.v0.misc.IntermediateColumn
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType
|
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseTypesProvider
|
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.Expression
|
import ru.landgrafhomyak.serdha.api.v0.misc.Expression
|
||||||
|
import ru.landgrafhomyak.serdha.api.v0.misc.FiltersScope
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.QueryParam
|
import ru.landgrafhomyak.serdha.api.v0.misc.QueryParam
|
||||||
import ru.landgrafhomyak.serdha.api.v0.runtime.InputRow
|
import ru.landgrafhomyak.serdha.api.v0.runtime.InputRow
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ public interface SelectQuery<qUE : Any> : _Query<qUE> {
|
|||||||
|
|
||||||
@Suppress("ClassName")
|
@Suppress("ClassName")
|
||||||
public interface _CommonSelectCreatorScope<qUE : Any> {
|
public interface _CommonSelectCreatorScope<qUE : Any> {
|
||||||
public val types: DatabaseTypesProvider
|
public val types: DatabaseType.Provider
|
||||||
public fun <RT, DT : DatabaseType<RT>> queryParam(name: String, type: DT): QueryParam<RT, DT, qUE>
|
public fun <RT, DT : DatabaseType<RT>> queryParam(name: String, type: DT): QueryParam<RT, DT, qUE>
|
||||||
public fun <RT, DT : DatabaseType<RT>> paramAsColumn(param: QueryParam<RT, DT, qUE>): IntermediateColumn<RT, DT, qUE>
|
public fun <RT, DT : DatabaseType<RT>> paramAsColumn(param: QueryParam<RT, DT, qUE>): IntermediateColumn<RT, DT, qUE>
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public interface SelectQuery<qUE : Any> : _Query<qUE> {
|
|||||||
output: Expression.OutputLinker<eUE, qUE>
|
output: Expression.OutputLinker<eUE, qUE>
|
||||||
)
|
)
|
||||||
|
|
||||||
public fun where(column: IntermediateColumn<Boolean, DatabaseType.BOOLEAN, qUE>)
|
public val filters: FiltersScope<qUE>
|
||||||
public fun orderBy(order: Order, vararg column: IntermediateColumn<*, *, qUE>)
|
public fun orderBy(order: Order, vararg column: IntermediateColumn<*, *, qUE>)
|
||||||
|
|
||||||
public var limit: UInt
|
public var limit: UInt
|
||||||
|
@ -3,7 +3,6 @@ package ru.landgrafhomyak.serdha.api.v0.queries
|
|||||||
import ru.landgrafhomyak.serdha.api.v0.misc.Column
|
import ru.landgrafhomyak.serdha.api.v0.misc.Column
|
||||||
import ru.landgrafhomyak.serdha.api.v0.table.Table
|
import ru.landgrafhomyak.serdha.api.v0.table.Table
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType
|
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseTypesProvider
|
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.QueryParam
|
import ru.landgrafhomyak.serdha.api.v0.misc.QueryParam
|
||||||
import ru.landgrafhomyak.serdha.api.v0.runtime.InputRow
|
import ru.landgrafhomyak.serdha.api.v0.runtime.InputRow
|
||||||
|
|
||||||
@ -15,7 +14,7 @@ public interface UpdateQuery<qUE : Any> : _Query<qUE> {
|
|||||||
public interface Scope<qUE : Any, ttUE : Any> {
|
public interface Scope<qUE : Any, ttUE : Any> {
|
||||||
public val tt: Table<ttUE, *>
|
public val tt: Table<ttUE, *>
|
||||||
|
|
||||||
public val types: DatabaseTypesProvider
|
public val types: DatabaseType.Provider
|
||||||
public fun <RT, DT : DatabaseType<RT>> param(name: String, type: DT): QueryParam<RT, DT, qUE>
|
public fun <RT, DT : DatabaseType<RT>> param(name: String, type: DT): QueryParam<RT, DT, qUE>
|
||||||
|
|
||||||
public var rowToUpdate: QueryParam<*, DatabaseType.ROW_ID<ttUE>, qUE>
|
public var rowToUpdate: QueryParam<*, DatabaseType.ROW_ID<ttUE>, qUE>
|
||||||
@ -42,7 +41,7 @@ public interface UpdateQuery<qUE : Any> : _Query<qUE> {
|
|||||||
public val tt: Table<ttUE, *>
|
public val tt: Table<ttUE, *>
|
||||||
public val sUExt: sUE
|
public val sUExt: sUE
|
||||||
|
|
||||||
public val types: DatabaseTypesProvider
|
public val types: DatabaseType.Provider
|
||||||
public fun <RT, DT : DatabaseType<RT>> param(name: String, type: DT): QueryParam<RT, DT, qUE>
|
public fun <RT, DT : DatabaseType<RT>> param(name: String, type: DT): QueryParam<RT, DT, qUE>
|
||||||
|
|
||||||
public val selectorParams: InputRow.WithRedirect<sUE, qUE>
|
public val selectorParams: InputRow.WithRedirect<sUE, qUE>
|
||||||
@ -71,7 +70,7 @@ public interface UpdateQuery<qUE : Any> : _Query<qUE> {
|
|||||||
public interface Scope<qUE : Any, ttUE : Any> {
|
public interface Scope<qUE : Any, ttUE : Any> {
|
||||||
public val tt: Table<ttUE, *>
|
public val tt: Table<ttUE, *>
|
||||||
|
|
||||||
public val types: DatabaseTypesProvider
|
public val types: DatabaseType.Provider
|
||||||
public fun <RT, DT : DatabaseType<RT>> inputColumn(name: String, type: DT): QueryParam<RT, DT, qUE>
|
public fun <RT, DT : DatabaseType<RT>> inputColumn(name: String, type: DT): QueryParam<RT, DT, qUE>
|
||||||
|
|
||||||
public var rowToUpdate: QueryParam<*, DatabaseType.ROW_ID<ttUE>, qUE>
|
public var rowToUpdate: QueryParam<*, DatabaseType.ROW_ID<ttUE>, qUE>
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package ru.landgrafhomyak.serdha.api.v0.table
|
package ru.landgrafhomyak.serdha.api.v0.table
|
||||||
|
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.BuiltinExpressionsProvider
|
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.Column
|
import ru.landgrafhomyak.serdha.api.v0.misc.Column
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType
|
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseType
|
||||||
import ru.landgrafhomyak.serdha.api.v0.misc.DatabaseTypesProvider
|
|
||||||
|
|
||||||
public interface CreateTableScope<TableUserExtension : Any> {
|
public interface CreateTableScope<TableUserExtension : Any> {
|
||||||
public val types: DatabaseTypesProvider
|
public val types: DatabaseType.Provider
|
||||||
|
|
||||||
public fun <RT, DT : DatabaseType<RT>> column(name: String, type: DT): Column<RT, DT, TableUserExtension>
|
public fun <RT, DT : DatabaseType<RT>> column(name: String, type: DT): Column<RT, DT, TableUserExtension>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user