Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MySQL #18

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions mysql/api/exposed-vertx-sql-client-postgresql.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public final class com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClientKt {
public static final fun withPgTransaction (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabasesKt {
public static final fun exposedDatabaseConnectPostgresql (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/exposed/sql/DatabaseConfig;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/exposed/sql/Database;
public static synthetic fun exposedDatabaseConnectPostgresql$default (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/exposed/sql/DatabaseConfig;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/Database;
public static final fun exposedDatabaseConnectPostgresqlWithParameterConnectionConfig (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/exposed/sql/DatabaseConfig;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/exposed/sql/Database;
public static synthetic fun exposedDatabaseConnectPostgresqlWithParameterConnectionConfig$default (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/exposed/sql/DatabaseConfig;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/Database;
}

public final class com/huanshankeji/exposedvertxsqlclient/postgresql/local/LocalConnectionConfigKt {
public static final field DEFAULT_POSTGRESQL_UNIX_DOMAIN_SOCKET_PATH Ljava/lang/String;
public static final fun defaultPostgresqlLocalConnectionConfig (Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lcom/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig;
public static synthetic fun defaultPostgresqlLocalConnectionConfig$default (Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lcom/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig;
}

public final class com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClientsKt {
public static final fun createGenericPgClientWithBuilder (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lio/vertx/sqlclient/ClientBuilder;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lio/vertx/sqlclient/SqlClient;
public static final fun createPgClient (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lio/vertx/sqlclient/SqlClient;
public static synthetic fun createPgClient$default (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lio/vertx/sqlclient/SqlClient;
public static final fun createPgConnection (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun createPgConnection$default (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun createPgPool (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lio/vertx/sqlclient/Pool;
public static synthetic fun createPgPool$default (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lio/vertx/sqlclient/Pool;
}

15 changes: 15 additions & 0 deletions mysql/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import com.huanshankeji.cpnProject

plugins {
`lib-conventions`
}

dependencies {
with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed
implementation(cpnProject(project, ":core"))

runtimeOnly(commonDependencies.postgreSql()) // TODO change to the MySQL JDBC dependency
implementation(commonDependencies.vertx.moduleWithoutVersion("mysql-client"))
implementation(commonDependencies.kotlinCommon.core()) // for `Untested`
implementation(commonDependencies.kotlinCommon.vertx()) // for `PgPoolOptions.setUpConventionally` // TODO check if this is necessary for MySQL, and remove if not
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.huanshankeji.exposedvertxsqlclient.postgresql

import com.huanshankeji.exposedvertxsqlclient.DatabaseClient
import com.huanshankeji.exposedvertxsqlclient.withTypedTransaction
import io.vertx.pgclient.PgConnection
import io.vertx.sqlclient.Pool

suspend fun <T> DatabaseClient<Pool>.withPgTransaction(function: suspend (DatabaseClient<PgConnection>) -> T): T =
withTypedTransaction(function)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.huanshankeji.exposedvertxsqlclient.postgresql.exposed

import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig
import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi
import com.huanshankeji.exposedvertxsqlclient.exposed.exposedDatabaseConnect
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.DatabaseConfig
import org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager
import org.jetbrains.exposed.sql.transactions.TransactionManager
import java.sql.Connection

/**
* @see exposedDatabaseConnect
*/
@ExperimentalEvscApi
fun ConnectionConfig.Socket.exposedDatabaseConnectMysql(
setupConnection: (Connection) -> Unit = {},
databaseConfig: DatabaseConfig? = null,
manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it) }
) =
exposedDatabaseConnect(
"mysql", "com.mysql.cj.jdbc.Driver", setupConnection, databaseConfig, manager
)

@ExperimentalEvscApi
@JvmName("exposedDatabaseConnectPostgresqlWithParameterConnectionConfig")
fun exposedDatabaseConnectMysql(
socketConnectionConfig: ConnectionConfig.Socket,
setupConnection: (Connection) -> Unit = {},
databaseConfig: DatabaseConfig? = null,
manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it) }
) =
socketConnectionConfig.exposedDatabaseConnectMysql(setupConnection, databaseConfig, manager)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.huanshankeji.exposedvertxsqlclient.postgresql.local

import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi
import com.huanshankeji.exposedvertxsqlclient.local.LocalConnectionConfig

// TODO consider moving to "kotlin-common"

const val DEFAULT_POSTGRESQL_UNIX_DOMAIN_SOCKET_PATH = "/var/run/postgresql"

@ExperimentalEvscApi
fun defaultPostgresqlLocalConnectionConfig(
socketConnectionPort: Int? = null, user: String, socketConnectionPassword: String, database: String
) =
LocalConnectionConfig(
socketConnectionPort, DEFAULT_POSTGRESQL_UNIX_DOMAIN_SOCKET_PATH, user, socketConnectionPassword, database
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
@file:OptIn(ExperimentalEvscApi::class)

package com.huanshankeji.exposedvertxsqlclient.postgresql.vertx.pgclient

import com.huanshankeji.Untested
import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig
import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi
import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.CoConnectHandler
import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createGenericSqlClient
import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createGenericSqlClientWithBuilder
import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createGenericSqlConnection
import com.huanshankeji.vertx.pgclient.setUpConventionally
import io.vertx.core.Vertx
import io.vertx.pgclient.PgBuilder
import io.vertx.pgclient.PgConnectOptions
import io.vertx.pgclient.PgConnection
import io.vertx.pgclient.impl.PgPoolOptions
import io.vertx.sqlclient.ClientBuilder
import io.vertx.sqlclient.Pool
import io.vertx.sqlclient.SqlClient

/**
* @see createGenericSqlClient
*/
// made not inline anymore for easier debugging
@ExperimentalEvscApi
fun <SqlClientT : SqlClient, ClientBuilderT : ClientBuilder<SqlClientT>> createGenericPgClientWithBuilder(
vertx: Vertx?,
connectionConfig: ConnectionConfig,
clientBuilder: ClientBuilderT,
extraPgConnectOptions: PgConnectOptions.() -> Unit,
extraPgPoolOptions: PgPoolOptions.() -> Unit,
connectHandlerExtra: CoConnectHandler
): SqlClientT =
createGenericSqlClientWithBuilder(
vertx,
connectionConfig,
clientBuilder,
PgConnectOptions(),
extraPgConnectOptions,
extraPgPoolOptions,
connectHandlerExtra,
PgPoolOptions()
)

fun createPgClient(
vertx: Vertx?,
connectionConfig: ConnectionConfig,
extraPgConnectOptions: PgConnectOptions.() -> Unit = {},
extraPoolOptions: PgPoolOptions.() -> Unit = {},
connectHandlerExtra: CoConnectHandler = null,
): SqlClient =
createGenericPgClientWithBuilder(
vertx,
connectionConfig,
PgBuilder.client(),
extraPgConnectOptions,
extraPoolOptions,
connectHandlerExtra
)

/**
* [PgPoolOptions.pipelined] is enabled by default.
* @see PgPoolOptions.setUpConventionally
* @see createGenericSqlClient
*/
fun createPgPool(
vertx: Vertx?,
connectionConfig: ConnectionConfig,
extraPgConnectOptions: PgConnectOptions.() -> Unit = {},
extraPoolOptions: PgPoolOptions.() -> Unit = {},
connectHandlerExtra: CoConnectHandler = null,
): Pool =
createGenericPgClientWithBuilder(
vertx,
connectionConfig,
PgBuilder.pool(),
extraPgConnectOptions,
{
setUpConventionally()
extraPoolOptions()
},
connectHandlerExtra
)

/**
* @see createGenericSqlClient
*/
@Untested
suspend fun createPgConnection(
vertx: Vertx?,
connectionConfig: ConnectionConfig,
extraPgConnectOptions: PgConnectOptions.() -> Unit = {},
connectHandlerExtra: CoConnectHandler = null
): PgConnection =
createGenericSqlConnection(
vertx,
connectionConfig,
PgConnection::connect,
PgConnectOptions(),
extraPgConnectOptions,
connectHandlerExtra
)
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ rootProject.name = "exposed-vertx-sql-client"
include("core")
include("sql-dsl")
include("sql-dsl-with-mapper")
include("mysql")
include("postgresql")
include("integrated")

Expand Down
Loading