Skip to content

Commit

Permalink
Add the MySQL module with the "mysql" directory copied from the "post…
Browse files Browse the repository at this point in the history
…gresql" directory
  • Loading branch information
ShreckYe committed Nov 20, 2024
1 parent 90dc927 commit ce50f6d
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 0 deletions.
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())
implementation(commonDependencies.vertx.moduleWithoutVersion("pg-client"))
implementation(commonDependencies.kotlinCommon.core()) // for `Untested`
implementation(commonDependencies.kotlinCommon.vertx()) // for `PgPoolOptions.setUpConventionally`
}
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.exposedDatabaseConnectPostgresql(
setupConnection: (Connection) -> Unit = {},
databaseConfig: DatabaseConfig? = null,
manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it) }
) =
exposedDatabaseConnect(
"postgresql", "org.postgresql.Driver", setupConnection, databaseConfig, manager
)

@ExperimentalEvscApi
@JvmName("exposedDatabaseConnectPostgresqlWithParameterConnectionConfig")
fun exposedDatabaseConnectPostgresql(
socketConnectionConfig: ConnectionConfig.Socket,
setupConnection: (Connection) -> Unit = {},
databaseConfig: DatabaseConfig? = null,
manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it) }
) =
socketConnectionConfig.exposedDatabaseConnectPostgresql(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

0 comments on commit ce50f6d

Please sign in to comment.