Skip to content

Commit e54ce64

Browse files
committed
Update dialect support
1 parent 4bfbe62 commit e54ce64

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

api/surf-database-r2dbc.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ public final class dev/slne/surf/database/DatabaseApi {
55
}
66

77
public final class dev/slne/surf/database/DatabaseApi$Companion {
8-
public final fun create (Lio/r2dbc/spi/ConnectionFactory;Lnet/kyori/adventure/text/logger/slf4j/ComponentLogger;Lorg/slf4j/event/Level;Lkotlin/jvm/functions/Function1;)Ldev/slne/surf/database/DatabaseApi;
8+
public final fun create (Lio/r2dbc/spi/ConnectionFactory;Lorg/jetbrains/exposed/v1/core/vendors/DatabaseDialect;Lnet/kyori/adventure/text/logger/slf4j/ComponentLogger;Lorg/slf4j/event/Level;Lkotlin/jvm/functions/Function1;)Ldev/slne/surf/database/DatabaseApi;
99
public final fun create (Ljava/nio/file/Path;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ldev/slne/surf/database/DatabaseApi;
10-
public static synthetic fun create$default (Ldev/slne/surf/database/DatabaseApi$Companion;Lio/r2dbc/spi/ConnectionFactory;Lnet/kyori/adventure/text/logger/slf4j/ComponentLogger;Lorg/slf4j/event/Level;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ldev/slne/surf/database/DatabaseApi;
10+
public static synthetic fun create$default (Ldev/slne/surf/database/DatabaseApi$Companion;Lio/r2dbc/spi/ConnectionFactory;Lorg/jetbrains/exposed/v1/core/vendors/DatabaseDialect;Lnet/kyori/adventure/text/logger/slf4j/ComponentLogger;Lorg/slf4j/event/Level;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ldev/slne/surf/database/DatabaseApi;
1111
public static synthetic fun create$default (Ldev/slne/surf/database/DatabaseApi$Companion;Ljava/nio/file/Path;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ldev/slne/surf/database/DatabaseApi;
1212
}
1313

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ kotlin.stdlib.default.dependency=false
33
org.gradle.parallel=true
44
#org.gradle.caching=true
55
#org.gradle.configureondemand=true
6-
version=2.0.1
6+
version=2.0.2

src/main/kotlin/dev/slne/surf/database/DatabaseApi.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import io.r2dbc.postgresql.PostgresqlConnectionFactory
1111
import io.r2dbc.spi.ConnectionFactory
1212
import io.r2dbc.spi.IsolationLevel
1313
import net.kyori.adventure.text.logger.slf4j.ComponentLogger
14+
import org.jetbrains.exposed.v1.core.vendors.DatabaseDialect
1415
import org.jetbrains.exposed.v1.core.vendors.MariaDBDialect
1516
import org.jetbrains.exposed.v1.core.vendors.PostgreSQLDialect
1617
import org.jetbrains.exposed.v1.r2dbc.R2dbcDatabase
@@ -115,8 +116,14 @@ class DatabaseApi internal constructor(val database: R2dbcDatabase) {
115116
val logger = ComponentLogger.logger(caller)
116117
val logLevel = config.logLevel
117118

119+
val dialect = when (databaseType) {
120+
DatabaseType.MARIADB -> MariaDBDialect()
121+
DatabaseType.POSTGRESQL -> PostgreSQLDialect()
122+
}
123+
118124
return create(
119125
connectionFactory = pool,
126+
dialect = dialect,
120127
logger = logger,
121128
logLevel = logLevel,
122129
configCustomizer = configCustomizer
@@ -131,21 +138,19 @@ class DatabaseApi internal constructor(val database: R2dbcDatabase) {
131138
* [create(Path, String, R2dbcDatabaseConfig.Builder.() -> Unit)] for normal usage.
132139
*
133140
* @param connectionFactory The factory to connect with (e.g., testcontainers, in-memory, custom pool).
141+
* @param dialect The database dialect to use (e.g., MariaDB, Postgres).
142+
* @param logger Optional logger for Exposed's SQL logging (defaults to a logger named "DatabaseApi").
143+
* @param logLevel Optional log level for Exposed's SQL logging (
134144
* @param configCustomizer Optional customization hook for Exposed's [R2dbcDatabaseConfig].
135145
*/
136146
@TestOnlyDatabaseApi
137147
fun create(
138148
connectionFactory: ConnectionFactory,
149+
dialect: DatabaseDialect,
139150
logger: ComponentLogger = ComponentLogger.logger("DatabaseApi"),
140151
logLevel: Level = Level.DEBUG,
141152
configCustomizer: R2dbcDatabaseConfig.Builder.() -> Unit = {}
142153
): DatabaseApi {
143-
val dialect = when (connectionFactory) {
144-
is MariadbConnectionFactory -> MariaDBDialect()
145-
is PostgresqlConnectionFactory -> PostgreSQLDialect()
146-
else -> throw IllegalArgumentException("Unsupported ConnectionFactory type: ${connectionFactory::class.java.name}")
147-
}
148-
149154
val database = R2dbcDatabase.connect(connectionFactory, R2dbcDatabaseConfig {
150155
explicitDialect = dialect
151156
sqlLogger = ComponentSqlLogger(logger, logLevel)

0 commit comments

Comments
 (0)