Skip to content

Commit

Permalink
add CurrentDate function (#1463) / SQLServer fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapac committed Jul 18, 2022
1 parent c005db9 commit fd2aecf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jetbrains.exposed.sql.javatime
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.Function
import org.jetbrains.exposed.sql.vendors.MysqlDialect
import org.jetbrains.exposed.sql.vendors.SQLServerDialect
import org.jetbrains.exposed.sql.vendors.currentDialect
import java.time.Duration
import java.time.Instant
Expand Down Expand Up @@ -35,6 +36,7 @@ object CurrentDate : Function<LocalDate>(JavaLocalDateColumnType.INSTANCE) {
override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder {
+when (currentDialect) {
is MysqlDialect -> "CURRENT_DATE()"
is SQLServerDialect -> "GETDATE()"
else -> "CURRENT_DATE"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jetbrains.exposed.sql.jodatime
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.Function
import org.jetbrains.exposed.sql.vendors.MysqlDialect
import org.jetbrains.exposed.sql.vendors.SQLServerDialect
import org.jetbrains.exposed.sql.vendors.currentDialect
import org.joda.time.DateTime

Expand All @@ -26,6 +27,7 @@ object CurrentDate : Function<DateTime>(DateColumnType(false)) {
override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder {
+when (currentDialect) {
is MysqlDialect -> "CURRENT_DATE()"
is SQLServerDialect -> "GETDATE()"
else -> "CURRENT_DATE"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.datetime.LocalDateTime
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.Function
import org.jetbrains.exposed.sql.vendors.MysqlDialect
import org.jetbrains.exposed.sql.vendors.SQLServerDialect
import org.jetbrains.exposed.sql.vendors.currentDialect
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
Expand Down Expand Up @@ -39,10 +40,11 @@ object CurrentDateTime : Function<LocalDateTime>(KotlinLocalDateTimeColumnType.I
operator fun invoke() = this
}

object CurrentDate : Function<LocalDate>(KotlinLocalDateTimeColumnType.INSTANCE) {
object CurrentDate : Function<LocalDate>(KotlinLocalDateColumnType.INSTANCE) {
override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder {
+when (currentDialect) {
is MysqlDialect -> "CURRENT_DATE()"
is SQLServerDialect -> "GETDATE()"
else -> "CURRENT_DATE"
}
}
Expand Down

0 comments on commit fd2aecf

Please sign in to comment.