Skip to content

Commit

Permalink
Added support for just time columns
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicSquid committed Sep 21, 2023
1 parent e52818c commit 1d52920
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ open class MappedColumnBuilder(column: Column, private val columnMapping: String
"char", "varchar", "text" -> String::class
"date" -> dateTimeProvider.dateClass
"datetime" -> dateTimeProvider.dateTimeClass
"time" -> dateTimeProvider.timeClass
in customMappings -> Class.forName(customMappings[functionCall]!!.columnPropertyClassName).kotlin
else -> throw UnparseableExposedCallException("Unable to determine type of expression $functionCall and generate column.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.math.BigDecimal
import java.sql.Blob
import java.sql.Clob
import java.sql.Date
import java.sql.Time
import java.sql.Timestamp
import java.util.*
import kotlin.reflect.KClass
Expand Down Expand Up @@ -137,6 +138,9 @@ data class ColumnInfo(val column: Column, private val data: TableBuilderData) {
Clob::class.javaObjectType -> initializeColumnParameters(String::class, getExposedFunction("text"))
Blob::class.javaObjectType -> initializeColumnParameters(ExposedBlob::class, getExposedFunction("blob"))
UUID::class.javaObjectType -> initializeColumnParameters(UUID::class, getExposedFunction("uuid"))
Time::class.javaObjectType, dateTimeProvider.timeClass.javaObjectType ->
initializeColumnParameters(dateTimeProvider.timeClass, dateTimeProvider.timeTableFun())

Date::class.javaObjectType, dateTimeProvider.dateClass.javaObjectType ->
initializeColumnParameters(dateTimeProvider.dateClass, dateTimeProvider.dateTableFun())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import kotlin.reflect.KFunction
interface DateTimeProvider {
val dateClass: KClass<*>
val dateTimeClass: KClass<*>
val timeClass: KClass<*>
fun <S> dateTableFun(): KFunction<Column<S>>
fun <S> dateTimeTableFun(): KFunction<Column<S>>
fun <S> timeTableFun(): KFunction<Column<S>>
}

fun getDateTimeProviderFromConfig(name: String?) = when (name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.javatime.date
import org.jetbrains.exposed.sql.javatime.datetime
import org.jetbrains.exposed.sql.javatime.time
import org.joda.time.LocalTime
import java.time.LocalDate
import java.time.LocalDateTime
import kotlin.reflect.KClass
Expand All @@ -13,6 +15,7 @@ import kotlin.reflect.KFunction
object JavaDateTimeProvider : DateTimeProvider {
override val dateClass: KClass<LocalDate> = LocalDate::class
override val dateTimeClass: KClass<LocalDateTime> = LocalDateTime::class
override val timeClass: KClass<LocalTime> = LocalTime::class

override fun <S> dateTableFun(): KFunction<Column<S>> {
return Table::date as KFunction<Column<S>>
Expand All @@ -22,4 +25,8 @@ object JavaDateTimeProvider : DateTimeProvider {
return Table::datetime as KFunction<Column<S>>
}

override fun <S> timeTableFun(): KFunction<Column<S>> {
return Table::time as KFunction<Column<S>>
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package dev.epicsquid.exposed.gradle.time

import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.javatime.time
import org.jetbrains.exposed.sql.jodatime.date
import org.jetbrains.exposed.sql.jodatime.datetime
import org.joda.time.LocalDate
import org.joda.time.LocalDateTime
import org.joda.time.LocalTime
import kotlin.reflect.KClass
import kotlin.reflect.KFunction

@Suppress("UNCHECKED_CAST")
object JodaDateTimeProvider : DateTimeProvider {
override val dateClass: KClass<LocalDate> = LocalDate::class
override val dateTimeClass: KClass<LocalDateTime> = LocalDateTime::class
override val timeClass: KClass<LocalTime> = LocalTime::class

override fun <S> dateTableFun(): KFunction<Column<S>> {
return Table::date as KFunction<Column<S>>
Expand All @@ -22,4 +25,7 @@ object JodaDateTimeProvider : DateTimeProvider {
return Table::datetime as KFunction<Column<S>>
}

override fun <S> timeTableFun(): KFunction<Column<S>> {
return Table::datetime as KFunction<Column<S>>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package dev.epicsquid.exposed.gradle.time
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.LocalTime
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.kotlin.datetime.date
import org.jetbrains.exposed.sql.kotlin.datetime.datetime
import org.jetbrains.exposed.sql.kotlin.datetime.time
import org.jetbrains.exposed.sql.kotlin.datetime.timestamp
import kotlin.reflect.KClass
import kotlin.reflect.KFunction
Expand All @@ -15,6 +17,7 @@ import kotlin.reflect.KFunction
object KotlinDateTimeProvider : DateTimeProvider {
override val dateClass: KClass<LocalDate> = LocalDate::class
override val dateTimeClass: KClass<Instant> = Instant::class
override val timeClass: KClass<LocalTime> = LocalTime::class

override fun <S> dateTableFun(): KFunction<Column<S>> {
return Table::date as KFunction<Column<S>>
Expand All @@ -24,4 +27,7 @@ object KotlinDateTimeProvider : DateTimeProvider {
return Table::timestamp as KFunction<Column<S>>
}

override fun <S> timeTableFun(): KFunction<Column<S>> {
return Table::time as KFunction<Column<S>>
}
}

0 comments on commit 1d52920

Please sign in to comment.