Skip to content

Commit

Permalink
Update MySQLClients.kt but some problems may be raised, thus a furthe…
Browse files Browse the repository at this point in the history
…r discussion required
  • Loading branch information
waste-of-kindergarten committed Jan 18, 2025
1 parent d4ddc19 commit bf1b0d3
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.huanshankeji.exposed.benchmark

import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig
import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgresql
import com.huanshankeji.exposedvertxsqlclient.mysql.exposed.exposedDatabaseConnectPostgresql
import kotlinx.benchmark.Scope
import kotlinx.benchmark.Setup
import kotlinx.benchmark.State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package com.huanshankeji.exposedvertxsqlclient

import com.huanshankeji.exposed.*
import com.huanshankeji.exposedvertxsqlclient.local.toPerformantUnixEvscConfig
import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgresql
import com.huanshankeji.exposedvertxsqlclient.postgresql.local.defaultPostgresqlLocalConnectionConfig
import com.huanshankeji.exposedvertxsqlclient.postgresql.vertx.pgclient.createPgPool
import com.huanshankeji.exposedvertxsqlclient.mysql.exposed.exposedDatabaseConnectPostgresql
import com.huanshankeji.exposedvertxsqlclient.mysql.local.defaultPostgresqlLocalConnectionConfig
import com.huanshankeji.exposedvertxsqlclient.mysql.vertx.mysqlclient.createPgPool
import com.huanshankeji.exposedvertxsqlclient.sql.*
import io.vertx.core.Verticle
import io.vertx.core.Vertx
Expand Down
28 changes: 28 additions & 0 deletions mysql/api/exposed-vertx-sql-client-mysql.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public final class com/huanshankeji/exposedvertxsqlclient/mysql/DatabaseClientKt {
public static final fun withSQLTransaction (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class com/huanshankeji/exposedvertxsqlclient/mysql/exposed/ExposedDatabasesKt {
public static final fun exposedDatabaseConnectMySQL (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 exposedDatabaseConnectMySQL$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 exposedDatabaseConnectMySQLWithParameterConnectionConfig (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 exposedDatabaseConnectMySQLWithParameterConnectionConfig$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/mysql/local/LocalConnectionConfigKt {
public static final field DEFAULT_MYSQL_UNIX_DOMAIN_SOCKET_PATH Ljava/lang/String;
public static final fun defaultMySQLLocalConnectionConfig (Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lcom/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig;
public static synthetic fun defaultMySQLLocalConnectionConfig$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/mysql/vertx/mysqlclient/MySQLClientsKt {
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;
public static final fun setUpConventionally (Lio/vertx/mysqlclient/impl/MySQLPoolOptions;)V
}

27 changes: 0 additions & 27 deletions mysql/api/exposed-vertx-sql-client-postgresql.api

This file was deleted.

6 changes: 4 additions & 2 deletions mysql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ plugins {
dependencies {
with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed
implementation(cpnProject(project, ":core"))

runtimeOnly(commonDependencies.postgreSql()) // TODO change to the MySQL JDBC dependency
//runtimeOnly(commonDependencies.postgreSql()) // TODO change to the MySQL JDBC dependency
// cannot modify commonDependencies?
//runtimeOnly();
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
// this seems to be needed as mentioned in vertx-mysql-client
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.huanshankeji.exposedvertxsqlclient.mysql

import com.huanshankeji.exposedvertxsqlclient.DatabaseClient
import com.huanshankeji.exposedvertxsqlclient.withTypedTransaction
import io.vertx.sqlclient.Pool
import io.vertx.sqlclient.SqlConnection

suspend fun <T> DatabaseClient<Pool>.withSQLTransaction(function: suspend (DatabaseClient<SqlConnection>) -> T): T =
withTypedTransaction(function)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.huanshankeji.exposedvertxsqlclient.postgresql.exposed
package com.huanshankeji.exposedvertxsqlclient.mysql.exposed

import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig
import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi
Expand All @@ -13,7 +13,7 @@ import java.sql.Connection
* @see exposedDatabaseConnect
*/
@ExperimentalEvscApi
fun ConnectionConfig.Socket.exposedDatabaseConnectMysql(
fun ConnectionConfig.Socket.exposedDatabaseConnectMySQL(
setupConnection: (Connection) -> Unit = {},
databaseConfig: DatabaseConfig? = null,
manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it) }
Expand All @@ -23,11 +23,11 @@ fun ConnectionConfig.Socket.exposedDatabaseConnectMysql(
)

@ExperimentalEvscApi
@JvmName("exposedDatabaseConnectPostgresqlWithParameterConnectionConfig")
@JvmName("exposedDatabaseConnectMySQLWithParameterConnectionConfig")
fun exposedDatabaseConnectMysql(
socketConnectionConfig: ConnectionConfig.Socket,
setupConnection: (Connection) -> Unit = {},
databaseConfig: DatabaseConfig? = null,
manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it) }
) =
socketConnectionConfig.exposedDatabaseConnectMysql(setupConnection, databaseConfig, manager)
socketConnectionConfig.exposedDatabaseConnectMySQL(setupConnection, databaseConfig, manager)
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.huanshankeji.exposedvertxsqlclient.postgresql.local
package com.huanshankeji.exposedvertxsqlclient.mysql.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"
const val DEFAULT_MYSQL_UNIX_DOMAIN_SOCKET_PATH = "/var/run/mysql"

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

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

import com.huanshankeji.Untested
import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig
Expand All @@ -11,13 +11,16 @@ import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createGenericSqlCl
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
import io.vertx.mysqlclient.MySQLBuilder
import io.vertx.mysqlclient.MySQLConnection
// import io.vertx.mysqlclient.MySQLPool --deprecated
import io.vertx.mysqlclient.MySQLConnectOptions
import io.vertx.mysqlclient.impl.MySQLPoolOptions
import io.vertx.sqlclient.PoolOptions


/**
* @see createGenericSqlClient
Expand All @@ -28,32 +31,32 @@ fun <SqlClientT : SqlClient, ClientBuilderT : ClientBuilder<SqlClientT>> createG
vertx: Vertx?,
connectionConfig: ConnectionConfig,
clientBuilder: ClientBuilderT,
extraPgConnectOptions: PgConnectOptions.() -> Unit,
extraPgPoolOptions: PgPoolOptions.() -> Unit,
extraPgConnectOptions: MySQLConnectOptions.() -> Unit,
extraPgPoolOptions: MySQLPoolOptions.() -> Unit,
connectHandlerExtra: CoConnectHandler
): SqlClientT =
createGenericSqlClientWithBuilder(
vertx,
connectionConfig,
clientBuilder,
PgConnectOptions(),
MySQLConnectOptions(),
extraPgConnectOptions,
extraPgPoolOptions,
connectHandlerExtra,
PgPoolOptions()
MySQLPoolOptions(PoolOptions()) // remain to verify
)

fun createPgClient(
vertx: Vertx?,
connectionConfig: ConnectionConfig,
extraPgConnectOptions: PgConnectOptions.() -> Unit = {},
extraPoolOptions: PgPoolOptions.() -> Unit = {},
extraPgConnectOptions: MySQLConnectOptions.() -> Unit = {},
extraPoolOptions: MySQLPoolOptions.() -> Unit = {},
connectHandlerExtra: CoConnectHandler = null,
): SqlClient =
createGenericPgClientWithBuilder(
vertx,
connectionConfig,
PgBuilder.client(),
MySQLBuilder.client(),
extraPgConnectOptions,
extraPoolOptions,
connectHandlerExtra
Expand All @@ -67,14 +70,14 @@ fun createPgClient(
fun createPgPool(
vertx: Vertx?,
connectionConfig: ConnectionConfig,
extraPgConnectOptions: PgConnectOptions.() -> Unit = {},
extraPoolOptions: PgPoolOptions.() -> Unit = {},
extraPgConnectOptions: MySQLConnectOptions.() -> Unit = {},
extraPoolOptions: MySQLPoolOptions.() -> Unit = {},
connectHandlerExtra: CoConnectHandler = null,
): Pool =
createGenericPgClientWithBuilder(
vertx,
connectionConfig,
PgBuilder.pool(),
MySQLBuilder.pool(),
extraPgConnectOptions,
{
setUpConventionally()
Expand All @@ -83,21 +86,24 @@ fun createPgPool(
connectHandlerExtra
)

// temporarily added, maybe moved into kotlin-common
public fun io.vertx.mysqlclient.impl.MySQLPoolOptions.setUpConventionally(): kotlin.Unit { /* compiled code */ }

/**
* @see createGenericSqlClient
*/
@Untested
suspend fun createPgConnection(
vertx: Vertx?,
connectionConfig: ConnectionConfig,
extraPgConnectOptions: PgConnectOptions.() -> Unit = {},
extraPgConnectOptions: MySQLConnectOptions.() -> Unit = {},
connectHandlerExtra: CoConnectHandler = null
): PgConnection =
): MySQLConnection =
createGenericSqlConnection(
vertx,
connectionConfig,
PgConnection::connect,
PgConnectOptions(),
MySQLConnection::connect,
MySQLConnectOptions(),
extraPgConnectOptions,
connectHandlerExtra
)

This file was deleted.

Loading

0 comments on commit bf1b0d3

Please sign in to comment.