From c5347502825cd77711ebeeed28a07819e72081f1 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Fri, 15 Nov 2024 21:52:26 +0800 Subject: [PATCH 01/26] Create modules/subprojects to split code into, and move the example and benchmark code into the module "integrated" IntelliJ IDEA Code Analysis shows there are 5 errors. --- .../src/main/kotlin/conventions.gradle.kts | 12 +------- .../main/kotlin/lib-conventions.gradle.kts | 15 ++++++++++ .../exposed-vertx-sql-client-postgresql.api | 0 {lib => core}/build.gradle.kts | 19 ++----------- .../exposedvertxsqlclient/ConnectionConfig.kt | 0 .../exposedvertxsqlclient/ConnectionType.kt | 0 .../exposedvertxsqlclient/DatabaseClient.kt | 0 .../exposedvertxsqlclient/EvscConfig.kt | 0 .../ExperimentalEvscApi.kt | 0 .../exposedvertxsqlclient/ExposedDatabases.kt | 0 .../LocalConnectionConfig.kt | 0 .../exposedvertxsqlclient/VertxSqlClients.kt | 0 .../ClassPropertyMapping.kt | 0 .../sql/DatabaseClientSql.kt | 0 .../mapping/DatabaseClientSqlWithMapper.kt | 0 .../datamapping/RowDataQueryMapper.kt | 0 integrated/README.md | 3 ++ integrated/build.gradle.kts | 28 +++++++++++++++++++ .../exposed/benchmark/AbstractBenchmark.kt | 0 .../exposed/benchmark/EmptyBenchmark.kt | 0 .../PreparedSqlGenerationBenchmark.kt | 0 .../exposed/benchmark/StatementBenchmark.kt | 0 .../exposed/benchmark/TransactionBenchmark.kt | 0 .../WithContainerizedDatabaseBenchmark.kt | 0 .../exposed/benchmark/table/Tables.kt | 0 .../exposedvertxsqlclient/Examples.kt | 0 .../exposedvertxsqlclient/MappingExamples.kt | 0 postgresql/build.gradle.kts | 13 +++++++++ settings.gradle.kts | 14 ++++++++-- sql-dsl-with-mapper/build.gradle.kts | 10 +++++++ 30 files changed, 85 insertions(+), 29 deletions(-) create mode 100644 buildSrc/src/main/kotlin/lib-conventions.gradle.kts rename {lib => core}/api/exposed-vertx-sql-client-postgresql.api (100%) rename {lib => core}/build.gradle.kts (70%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/EvscConfig.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExperimentalEvscApi.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExposedDatabases.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt (100%) rename {lib => core}/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt (100%) create mode 100644 integrated/README.md create mode 100644 integrated/build.gradle.kts rename {lib => integrated}/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/AbstractBenchmark.kt (100%) rename {lib => integrated}/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/EmptyBenchmark.kt (100%) rename {lib => integrated}/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/PreparedSqlGenerationBenchmark.kt (100%) rename {lib => integrated}/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/StatementBenchmark.kt (100%) rename {lib => integrated}/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt (100%) rename {lib => integrated}/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt (100%) rename {lib => integrated}/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/table/Tables.kt (100%) rename {lib => integrated}/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt (100%) rename {lib => integrated}/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt (100%) create mode 100644 postgresql/build.gradle.kts create mode 100644 sql-dsl-with-mapper/build.gradle.kts diff --git a/buildSrc/src/main/kotlin/conventions.gradle.kts b/buildSrc/src/main/kotlin/conventions.gradle.kts index adb9b61..0015b4b 100644 --- a/buildSrc/src/main/kotlin/conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/conventions.gradle.kts @@ -1,12 +1,8 @@ -import com.huanshankeji.team.`Shreck Ye` -import com.huanshankeji.team.pomForTeamDefaultOpenSource import com.huanshankeji.team.repositoriesAddTeamGithubPackagesMavenRegistry -import org.gradle.kotlin.dsl.repositories plugins { id("com.huanshankeji.team.with-group") - id("com.huanshankeji.kotlin-jvm-library-sonatype-ossrh-publish-conventions") - id("com.huanshankeji.team.default-github-packages-maven-publish") + kotlin("jvm") } repositories { @@ -18,9 +14,3 @@ repositoriesAddTeamGithubPackagesMavenRegistry("kotlin-common") kotlin.jvmToolchain(8) version = projectVersion - -publishing.publications.getByName("maven") { - pomForTeamDefaultOpenSource(project, "Exposed Vert.x SQL Client", "Exposed on top of Vert.x Reactive SQL Client") { - `Shreck Ye`() - } -} diff --git a/buildSrc/src/main/kotlin/lib-conventions.gradle.kts b/buildSrc/src/main/kotlin/lib-conventions.gradle.kts new file mode 100644 index 0000000..e679e3d --- /dev/null +++ b/buildSrc/src/main/kotlin/lib-conventions.gradle.kts @@ -0,0 +1,15 @@ +import com.huanshankeji.team.`Shreck Ye` +import com.huanshankeji.team.pomForTeamDefaultOpenSource + +plugins { + id("conventions") + id("com.huanshankeji.kotlin-jvm-library-sonatype-ossrh-publish-conventions") + id("com.huanshankeji.team.default-github-packages-maven-publish") + id("com.huanshankeji.team.dokka.github-dokka-convention") +} + +publishing.publications.getByName("maven") { + pomForTeamDefaultOpenSource(project, "Exposed Vert.x SQL Client", "Exposed on top of Vert.x Reactive SQL Client") { + `Shreck Ye`() + } +} diff --git a/lib/api/exposed-vertx-sql-client-postgresql.api b/core/api/exposed-vertx-sql-client-postgresql.api similarity index 100% rename from lib/api/exposed-vertx-sql-client-postgresql.api rename to core/api/exposed-vertx-sql-client-postgresql.api diff --git a/lib/build.gradle.kts b/core/build.gradle.kts similarity index 70% rename from lib/build.gradle.kts rename to core/build.gradle.kts index 27c95c6..1cb9160 100644 --- a/lib/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,7 +1,5 @@ plugins { - conventions - id("com.huanshankeji.benchmark.kotlinx-benchmark-jvm-conventions") - id("com.huanshankeji.team.dokka.github-dokka-convention") + `lib-conventions` } dependencies { @@ -9,7 +7,7 @@ dependencies { // TODO: remove the Exposed JDBC dependency and the PostgresSQL dependency when there is no need to to generate SQLs with an Exposed transaction runtimeOnly(commonDependencies.exposed.module("jdbc")) api(commonDependencies.kotlinCommon.exposed()) - implementation("com.huanshankeji:exposed-adt-mapping:${DependencyVersions.exposedAdtMapping}") + implementation("com.huanshankeji:exposed-adt-mapping:${DependencyVersions.exposedAdtMapping}") // TODO remove when code is moved out with(commonDependencies.vertx) { implementation(platformStackDepchain()) @@ -25,20 +23,9 @@ dependencies { implementation(commonDependencies.kotlinCommon.net()) } - +// TODO remove when code is moved out // for PostgreSQL dependencies { runtimeOnly(commonDependencies.postgreSql()) implementation(commonDependencies.vertx.moduleWithoutVersion("pg-client")) } - -afterEvaluate { -// for the benchmarks - dependencies { - with(commonDependencies.testContainers) { - "benchmarksImplementation"(platformBom()) - "benchmarksImplementation"(postgreSql) - } - "benchmarksImplementation"(commonDependencies.slf4j.simple()) - } -} diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/EvscConfig.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/EvscConfig.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/EvscConfig.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/EvscConfig.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExperimentalEvscApi.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExperimentalEvscApi.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExperimentalEvscApi.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExperimentalEvscApi.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExposedDatabases.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExposedDatabases.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExposedDatabases.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExposedDatabases.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt diff --git a/lib/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt b/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt similarity index 100% rename from lib/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt rename to core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt diff --git a/integrated/README.md b/integrated/README.md new file mode 100644 index 0000000..64e0db5 --- /dev/null +++ b/integrated/README.md @@ -0,0 +1,3 @@ +# The integrated module + +This module includes tests, benchmarks, and examples. diff --git a/integrated/build.gradle.kts b/integrated/build.gradle.kts new file mode 100644 index 0000000..1806076 --- /dev/null +++ b/integrated/build.gradle.kts @@ -0,0 +1,28 @@ +import com.huanshankeji.cpnProject + +plugins { + conventions + id("com.huanshankeji.benchmark.kotlinx-benchmark-jvm-conventions") +} + +dependencies { + with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed + + implementation(cpnProject(project, ":core")) + + testImplementation("com.huanshankeji:exposed-adt-mapping:${DependencyVersions.exposedAdtMapping}") + testImplementation(cpnProject(project, ":sql-dsl-with-mapper")) +} + +afterEvaluate { +// for the benchmarks + dependencies { + "benchmarksImplementation"(cpnProject(project, ":postgresql")) + + with(commonDependencies.testContainers) { + "benchmarksImplementation"(platformBom()) + "benchmarksImplementation"(postgreSql) + } + "benchmarksImplementation"(commonDependencies.slf4j.simple()) + } +} diff --git a/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/AbstractBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/AbstractBenchmark.kt similarity index 100% rename from lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/AbstractBenchmark.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/AbstractBenchmark.kt diff --git a/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/EmptyBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/EmptyBenchmark.kt similarity index 100% rename from lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/EmptyBenchmark.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/EmptyBenchmark.kt diff --git a/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/PreparedSqlGenerationBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/PreparedSqlGenerationBenchmark.kt similarity index 100% rename from lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/PreparedSqlGenerationBenchmark.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/PreparedSqlGenerationBenchmark.kt diff --git a/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/StatementBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/StatementBenchmark.kt similarity index 100% rename from lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/StatementBenchmark.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/StatementBenchmark.kt diff --git a/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt similarity index 100% rename from lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt diff --git a/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt similarity index 100% rename from lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt diff --git a/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/table/Tables.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/table/Tables.kt similarity index 100% rename from lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/table/Tables.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/table/Tables.kt diff --git a/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt similarity index 100% rename from lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt rename to integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt diff --git a/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt b/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt similarity index 100% rename from lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt rename to integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt diff --git a/postgresql/build.gradle.kts b/postgresql/build.gradle.kts new file mode 100644 index 0000000..f23dd0d --- /dev/null +++ b/postgresql/build.gradle.kts @@ -0,0 +1,13 @@ +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")) +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 75fcf49..e5c9abd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,16 @@ rootProject.name = "exposed-vertx-sql-client" -include("lib") -project(":lib").name = rootProject.name + "-postgresql" + +include("core") +include("sql-dsl-with-mapper") +include("postgresql") +include("integrated") + +fun ProjectDescriptor.setProjectConcatenatedNames(prefix: String) { + name = prefix + name + for (child in children) + child.setProjectConcatenatedNames("$name-") +} +rootProject.setProjectConcatenatedNames("") // for Dokka @Suppress("UnstableApiUsage") diff --git a/sql-dsl-with-mapper/build.gradle.kts b/sql-dsl-with-mapper/build.gradle.kts new file mode 100644 index 0000000..c83f97f --- /dev/null +++ b/sql-dsl-with-mapper/build.gradle.kts @@ -0,0 +1,10 @@ +import com.huanshankeji.cpnProject + +plugins { + `lib-conventions` +} + +dependencies { + with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed + implementation(cpnProject(project, ":core")) +} From 58f65e3432ddf5c543d34e7b727c23330df090fe Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Fri, 15 Nov 2024 21:54:33 +0800 Subject: [PATCH 02/26] Run `apiDump` and remove the old dumped "exposed-vertx-sql-client-postgresql.api" file --- ...ql-client-postgresql.api => exposed-vertx-sql-client-core.api} | 0 integrated/api/exposed-vertx-sql-client-integrated.api | 0 postgresql/api/exposed-vertx-sql-client-postgresql.api | 0 .../api/exposed-vertx-sql-client-sql-dsl-with-mapper.api | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename core/api/{exposed-vertx-sql-client-postgresql.api => exposed-vertx-sql-client-core.api} (100%) create mode 100644 integrated/api/exposed-vertx-sql-client-integrated.api create mode 100644 postgresql/api/exposed-vertx-sql-client-postgresql.api create mode 100644 sql-dsl-with-mapper/api/exposed-vertx-sql-client-sql-dsl-with-mapper.api diff --git a/core/api/exposed-vertx-sql-client-postgresql.api b/core/api/exposed-vertx-sql-client-core.api similarity index 100% rename from core/api/exposed-vertx-sql-client-postgresql.api rename to core/api/exposed-vertx-sql-client-core.api diff --git a/integrated/api/exposed-vertx-sql-client-integrated.api b/integrated/api/exposed-vertx-sql-client-integrated.api new file mode 100644 index 0000000..e69de29 diff --git a/postgresql/api/exposed-vertx-sql-client-postgresql.api b/postgresql/api/exposed-vertx-sql-client-postgresql.api new file mode 100644 index 0000000..e69de29 diff --git a/sql-dsl-with-mapper/api/exposed-vertx-sql-client-sql-dsl-with-mapper.api b/sql-dsl-with-mapper/api/exposed-vertx-sql-client-sql-dsl-with-mapper.api new file mode 100644 index 0000000..e69de29 From e101fc8d4ecc7c7ca2536e48b768eca3082400d6 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sat, 16 Nov 2024 02:19:34 +0800 Subject: [PATCH 03/26] Add an additional dependency on the "core" module for the benchmark code to resolve --- integrated/build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integrated/build.gradle.kts b/integrated/build.gradle.kts index 1806076..6441b27 100644 --- a/integrated/build.gradle.kts +++ b/integrated/build.gradle.kts @@ -17,6 +17,8 @@ dependencies { afterEvaluate { // for the benchmarks dependencies { + // The benchmarks run and "check" passes but the code doesn't resolve without this dependency TODO remove if not needed one day + "benchmarksImplementation"(cpnProject(project, ":core")) "benchmarksImplementation"(cpnProject(project, ":postgresql")) with(commonDependencies.testContainers) { From 7b0fc9f475b9e5c025d9809bd47cc46516d36d90 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sat, 16 Nov 2024 02:46:18 +0800 Subject: [PATCH 04/26] Generalize the functions in "DatabaseClient.kt" using `PgPool` and `PgConnection` for different DBs, replacing them with `Pool` and `Connection` A new `withTypedTransaction` function is added and `withPgTransaction` is moved into the `postgresql` package. --- .../exposedvertxsqlclient/DatabaseClient.kt | 33 +++++++++---------- .../postgresql/DatabaseClient.kt | 9 +++++ 2 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index 8dddea0..acf1e90 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -13,7 +13,6 @@ import io.vertx.core.buffer.Buffer import io.vertx.kotlin.coroutines.coAwait import io.vertx.kotlin.sqlclient.poolOptionsOf import io.vertx.pgclient.PgConnectOptions -import io.vertx.pgclient.PgConnection import io.vertx.pgclient.PgPool import io.vertx.sqlclient.* import kotlinx.coroutines.coroutineScope @@ -387,20 +386,20 @@ fun Int.singleOrNoUpdate() = * When using this function, it's recommended to name the lambda parameter the same as the outer receiver so that the outer [DatabaseClient] is shadowed, * and so that you don't call the outer [DatabaseClient] without a transaction by accident. */ -suspend fun DatabaseClient.withTransaction(function: suspend (DatabaseClient) -> T): T = +suspend fun DatabaseClient.withTransaction(function: suspend (DatabaseClient) -> T): T = coroutineScope { vertxSqlClient.withTransaction { coroutineToFuture { function(DatabaseClient(it, exposedDatabase)) } }.coAwait() } -suspend fun DatabaseClient.withPgTransaction(function: suspend (DatabaseClient) -> T): T = +suspend fun DatabaseClient.withTypedTransaction(function: suspend (DatabaseClient) -> T): T = withTransaction { @Suppress("UNCHECKED_CAST") - function(it as DatabaseClient) + function(it as DatabaseClient) } -suspend fun DatabaseClient.withTransactionCommitOrRollback(function: suspend (DatabaseClient) -> Option): Option { +suspend fun DatabaseClient.withTransactionCommitOrRollback(function: suspend (DatabaseClient) -> Option): Option { val transaction = vertxSqlClient.begin().coAwait() return try { val result = function(this) @@ -417,21 +416,21 @@ suspend fun DatabaseClient.withTransactionCommitOrRollback(fu val savepointNameRegex = Regex("\\w+") -private suspend fun DatabaseClient.savepoint(savepointName: String) = +private suspend fun DatabaseClient.savepoint(savepointName: String) = executePlainSqlUpdate("SAVEPOINT \"$savepointName\"").also { dbAssert(it == 0) } -private suspend fun DatabaseClient.rollbackToSavepoint(savepointName: String) = +private suspend fun DatabaseClient.rollbackToSavepoint(savepointName: String) = executePlainSqlUpdate("ROLLBACK TO SAVEPOINT \"$savepointName\"").also { dbAssert(it == 0) } -private suspend fun DatabaseClient.releaseSavepoint(savepointName: String) = +private suspend fun DatabaseClient.releaseSavepoint(savepointName: String) = executePlainSqlUpdate("RELEASE SAVEPOINT \"$savepointName\"").also { dbAssert(it == 0) } /** - * Currently only available for PostgreSQL. + * Not tested yet on DBs other than PostgreSQL. * A savepoint destroys one with the same name so be careful. */ -suspend fun DatabaseClient.withSavepointAndRollbackIfThrowsOrLeft( - savepointName: String, function: suspend (DatabaseClient) -> Either +suspend fun DatabaseClient.withSavepointAndRollbackIfThrowsOrLeft( + savepointName: String, function: suspend (DatabaseClient) -> Either ): Either { // Prepared query seems not to work here. @@ -451,18 +450,18 @@ suspend fun DatabaseClient.withSavepointAndR } } -suspend fun DatabaseClient.withSavepointAndRollbackIfThrows( - savepointName: String, function: suspend (DatabaseClient) -> T +suspend fun DatabaseClient.withSavepointAndRollbackIfThrows( + savepointName: String, function: suspend (DatabaseClient) -> T ): T = withSavepointAndRollbackIfThrowsOrLeft(savepointName) { function(it).right() }.getOrElse { throw AssertionError() } -suspend fun DatabaseClient.withSavepointAndRollbackIfThrowsOrNone( - savepointName: String, function: suspend (DatabaseClient) -> Option +suspend fun DatabaseClient.withSavepointAndRollbackIfThrowsOrNone( + savepointName: String, function: suspend (DatabaseClient) -> Option ): Option = withSavepointAndRollbackIfThrowsOrLeft(savepointName) { function(it).toEither { } }.getOrNone() -suspend fun DatabaseClient.withSavepointAndRollbackIfThrowsOrFalse( - savepointName: String, function: suspend (DatabaseClient) -> Boolean +suspend fun DatabaseClient.withSavepointAndRollbackIfThrowsOrFalse( + savepointName: String, function: suspend (DatabaseClient) -> Boolean ): Boolean = withSavepointAndRollbackIfThrowsOrLeft(savepointName) { if (function(it)) Unit.right() else Unit.left() }.isRight() diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt new file mode 100644 index 0000000..54ea5d2 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt @@ -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 DatabaseClient.withPgTransaction(function: suspend (DatabaseClient) -> T): T = + withTypedTransaction(function) From e95981226b7bb48879b80083eb3f6ccba9670d35 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sat, 16 Nov 2024 03:41:02 +0800 Subject: [PATCH 05/26] Get rid of usages of `PgPool` which was deprecated in 4.5 --- .../exposedvertxsqlclient/DatabaseClient.kt | 5 ++--- .../exposedvertxsqlclient/VertxSqlClients.kt | 22 +++++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index acf1e90..988bcda 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -13,7 +13,6 @@ import io.vertx.core.buffer.Buffer import io.vertx.kotlin.coroutines.coAwait import io.vertx.kotlin.sqlclient.poolOptionsOf import io.vertx.pgclient.PgConnectOptions -import io.vertx.pgclient.PgPool import io.vertx.sqlclient.* import kotlinx.coroutines.coroutineScope import org.jetbrains.exposed.dao.id.EntityID @@ -473,7 +472,7 @@ fun createPgPoolDatabaseClient( vertxSqlClientConnectionConfig: ConnectionConfig, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf(), exposedDatabase: Database -): DatabaseClient = +): DatabaseClient = DatabaseClient( with(vertxSqlClientConnectionConfig) { when (this) { @@ -494,7 +493,7 @@ fun createPgPoolDatabaseClient( vertxSqlClientConnectionConfig: ConnectionConfig, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf(), exposedSocketConnectionConfig: Socket -): DatabaseClient = +): DatabaseClient = createPgPoolDatabaseClient( vertx, vertxSqlClientConnectionConfig, extraPgConnectOptions, poolOptions, exposedDatabaseConnectPostgreSql(exposedSocketConnectionConfig) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt index 6ec1cc3..dce1ddd 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt @@ -55,11 +55,16 @@ inline fun createSocketGenericPgClient( return create(vertx, pgConnectOptions, poolOptions) } +private const val PG_CLIENT_DEPRECATED_MESSAGE = + "The dependent `PgPool` is deprecated. Just use `Pool` with `pipelined` enabled, which is the difference between `PgPool.client` and `PgPool.pool` as I have found out." + +@Deprecated(PG_CLIENT_DEPRECATED_MESSAGE, ReplaceWith("createSocketPgPool")) fun createSocketPgSqlClient( vertx: Vertx?, host: String, port: Int?, database: String, user: String, password: String, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() ): SqlClient = + @Suppress("DEPRECATION") createSocketGenericPgClient( vertx, host, port, database, user, password, extraPgConnectOptions, poolOptions, PgPool::client ) @@ -68,9 +73,9 @@ fun createSocketPgPool( vertx: Vertx?, host: String, port: Int?, database: String, user: String, password: String, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() -): PgPool = - createSocketGenericPgClient( - vertx, host, port, database, user, password, extraPgConnectOptions, poolOptions, PgPool::pool +): Pool = + createSocketGenericPgClient( + vertx, host, port, database, user, password, extraPgConnectOptions, poolOptions, Pool::pool ) @Untested @@ -103,15 +108,18 @@ inline fun createPeerAuthenticationUnixDom return create(vertx, pgConnectOptions, poolOptions) } +@Deprecated(PG_CLIENT_DEPRECATED_MESSAGE, ReplaceWith("createPeerAuthenticationUnixDomainSocketPgPool")) fun createPeerAuthenticationUnixDomainSocketPgSqlClient( vertx: Vertx?, unixDomainSocketPath: String, database: String, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() ): SqlClient = + @Suppress("DEPRECATION") createPeerAuthenticationUnixDomainSocketGenericPgClient( vertx, unixDomainSocketPath, database, extraPgConnectOptions, poolOptions, PgPool::client ) +@Deprecated(PG_CLIENT_DEPRECATED_MESSAGE, ReplaceWith("createPeerAuthenticationUnixDomainSocketPgPoolAndSetRole")) suspend fun createUnixDomainSocketPgSqlClientAndSetRole( vertx: Vertx?, host: String, database: String, role: String, @@ -128,16 +136,16 @@ fun createPeerAuthenticationUnixDomainSocketPgPool( vertx: Vertx?, unixDomainSocketPath: String, database: String, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() -): PgPool = - createPeerAuthenticationUnixDomainSocketGenericPgClient( - vertx, unixDomainSocketPath, database, extraPgConnectOptions, poolOptions, PgPool::pool +): Pool = + createPeerAuthenticationUnixDomainSocketGenericPgClient( + vertx, unixDomainSocketPath, database, extraPgConnectOptions, poolOptions, Pool::pool ) fun createPeerAuthenticationUnixDomainSocketPgPoolAndSetRole( vertx: Vertx?, host: String, database: String, role: String, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() -): PgPool = +): Pool = createPeerAuthenticationUnixDomainSocketPgPool(vertx, host, database, extraPgConnectOptions, poolOptions) .connectHandler { CoroutineScope(Dispatchers.Unconfined).launch { From dfd0d3b5762b044c3776cbe098ee3869e57004e0 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sat, 16 Nov 2024 22:42:18 +0800 Subject: [PATCH 06/26] Initially overhaul and reorganize the APIs Major changes: 1. move some code to finer-grained subpackages 1. initially overhaul the APIs related to the creation of Vert.x SQL clients and `DatabaseClient`s The `create...andSetRole` functions are removed, and their functionalities are merged into the `create...` functions. 1. add TODOs as guidance for the remaining work --- .../exposedvertxsqlclient/ConnectionConfig.kt | 6 + .../exposedvertxsqlclient/DatabaseClient.kt | 39 ++- .../exposedvertxsqlclient/VertxSqlClients.kt | 237 ++++++++---------- .../{ => local}/LocalConnectionConfig.kt | 8 +- .../exposed}/ExposedDatabases.kt | 3 +- .../vertx/sqlclient/SqlConnectOptions.kt | 24 ++ .../vertx/sqlclient/SqlConnection.kt | 12 + .../sqlclient/SqlConnectionInitialization.kt | 32 +++ .../WithContainerizedDatabaseBenchmark.kt | 2 +- .../exposedvertxsqlclient/Examples.kt | 1 + 10 files changed, 199 insertions(+), 165 deletions(-) rename core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/{ => local}/LocalConnectionConfig.kt (71%) rename core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/{ => postgresql/exposed}/ExposedDatabases.kt (74%) create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectOptions.kt create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnection.kt create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt index 09c7365..6c27162 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt @@ -1,5 +1,8 @@ package com.huanshankeji.exposedvertxsqlclient +import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.setRole + +// TODO make it not sealed with some common methods, for example, `SqlConnectOptions.setFrom` sealed interface ConnectionConfig { val userAndRole: String val database: String @@ -14,6 +17,9 @@ sealed interface ConnectionConfig { override val userAndRole: String get() = user } + /** + * @see setRole + */ class UnixDomainSocketWithPeerAuthentication( val path: String, val role: String, diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index 988bcda..96f6385 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -3,7 +3,8 @@ package com.huanshankeji.exposedvertxsqlclient import arrow.core.* import com.huanshankeji.collections.singleOrNullIfEmpty import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig.Socket -import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig.UnixDomainSocketWithPeerAuthentication +import com.huanshankeji.exposedvertxsqlclient.local.LocalConnectionConfig +import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgreSql import com.huanshankeji.exposedvertxsqlclient.sql.selectExpression import com.huanshankeji.os.isCurrentOsLinux import com.huanshankeji.vertx.kotlin.coroutines.coroutineToFuture @@ -11,14 +12,13 @@ import com.huanshankeji.vertx.kotlin.sqlclient.executeBatchAwaitForSqlResultSequ import io.vertx.core.Vertx import io.vertx.core.buffer.Buffer import io.vertx.kotlin.coroutines.coAwait -import io.vertx.kotlin.sqlclient.poolOptionsOf import io.vertx.pgclient.PgConnectOptions +import io.vertx.pgclient.impl.PgPoolOptions import io.vertx.sqlclient.* import kotlinx.coroutines.coroutineScope import org.jetbrains.exposed.dao.id.EntityID import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.Query -import org.jetbrains.exposed.sql.Transaction import org.jetbrains.exposed.sql.statements.InsertStatement import org.jetbrains.exposed.sql.statements.Statement import org.jetbrains.exposed.sql.statements.UpdateStatement @@ -100,7 +100,7 @@ class DatabaseClient( fun exposedTransaction(statement: ExposedTransaction.() -> T) = transaction(exposedDatabase, statement) - private fun Statement<*>.prepareSqlAndLogIfNeeded(transaction: Transaction) = + private fun Statement<*>.prepareSqlAndLogIfNeeded(transaction: ExposedTransaction) = prepareSQL(transaction).also { if (logSql) logger.info("Prepared SQL: $it.") } @@ -464,38 +464,29 @@ suspend fun DatabaseClient.with ): Boolean = withSavepointAndRollbackIfThrowsOrLeft(savepointName) { if (function(it)) Unit.right() else Unit.left() }.isRight() -// TODO: use `ConnectionConfig` as the argument directly + +// TODO move to the `postgresql` package // can be used for a shared Exposed `Database` among `DatabaseClient`s fun createPgPoolDatabaseClient( vertx: Vertx?, vertxSqlClientConnectionConfig: ConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf(), + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, exposedDatabase: Database ): DatabaseClient = DatabaseClient( - with(vertxSqlClientConnectionConfig) { - when (this) { - is Socket -> - createSocketPgPool(vertx, host, port, database, user, password, extraPgConnectOptions, poolOptions) - - is UnixDomainSocketWithPeerAuthentication -> - createPeerAuthenticationUnixDomainSocketPgPoolAndSetRole( - vertx, path, database, role, extraPgConnectOptions, poolOptions - ) - } - }, + createPgPool(vertx, vertxSqlClientConnectionConfig, extraPgConnectOptions, extraPgPoolOptions), exposedDatabase ) fun createPgPoolDatabaseClient( vertx: Vertx?, vertxSqlClientConnectionConfig: ConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf(), + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, exposedSocketConnectionConfig: Socket ): DatabaseClient = createPgPoolDatabaseClient( - vertx, vertxSqlClientConnectionConfig, extraPgConnectOptions, poolOptions, + vertx, vertxSqlClientConnectionConfig, extraPgConnectOptions, extraPgPoolOptions, exposedDatabaseConnectPostgreSql(exposedSocketConnectionConfig) ) @@ -503,7 +494,7 @@ fun createPgPoolDatabaseClient( fun createPgPoolDatabaseClient( vertx: Vertx?, vertxSqlClientConnectionType: ConnectionType, localConnectionConfig: LocalConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf(), + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, exposedDatabase: Database? = null ) = with(localConnectionConfig) { @@ -514,24 +505,24 @@ fun createPgPoolDatabaseClient( if (exposedDatabase === null) createPgPoolDatabaseClient( - vertx, connectionConfig, extraPgConnectOptions, poolOptions, socketConnectionConfig + vertx, connectionConfig, extraPgConnectOptions, extraPgPoolOptions, socketConnectionConfig ) else createPgPoolDatabaseClient( - vertx, connectionConfig, extraPgConnectOptions, poolOptions, exposedDatabase + vertx, connectionConfig, extraPgConnectOptions, extraPgPoolOptions, exposedDatabase ) } fun createBetterPgPoolDatabaseClient( vertx: Vertx?, localConnectionConfig: LocalConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf(), + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, exposedDatabase: Database? = null ) = createPgPoolDatabaseClient( vertx, if (isCurrentOsLinux()) ConnectionType.UnixDomainSocketWithPeerAuthentication else ConnectionType.Socket, localConnectionConfig, - extraPgConnectOptions, poolOptions, + extraPgConnectOptions, extraPgPoolOptions, exposedDatabase ) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt index dce1ddd..3cbe4e2 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt @@ -1,171 +1,134 @@ package com.huanshankeji.exposedvertxsqlclient import com.huanshankeji.Untested +import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.connectHandler +import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.initConnection +import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.setFrom import io.vertx.core.Vertx import io.vertx.kotlin.coroutines.coAwait -import io.vertx.kotlin.sqlclient.poolOptionsOf +import io.vertx.pgclient.PgBuilder import io.vertx.pgclient.PgConnectOptions import io.vertx.pgclient.PgConnection -import io.vertx.pgclient.PgPool -import io.vertx.sqlclient.Pool -import io.vertx.sqlclient.PoolOptions -import io.vertx.sqlclient.SqlClient -import io.vertx.sqlclient.SqlConnection -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch +import io.vertx.pgclient.impl.PgPoolOptions +import io.vertx.sqlclient.* -@PublishedApi -internal inline fun createPgConnectOptions( - mainPgConnectOptions: PgConnectOptions.() -> Unit = {}, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, -): PgConnectOptions = - PgConnectOptions().apply { - cachePreparedStatements = true // This improves performance greatly so it's enabled by default. - mainPgConnectOptions() - extraPgConnectOptions() - } - -/* -// An extracted common `create` argument for `PgConnection`, but a suspend function has an incompatible type. -private val pgConnectionConnect: suspend (Vertx?, PgConnectOptions, Nothing?) -> PgConnection = { vertx, pgConnectOptions, _ -> - PgConnection.connect(vertx, pgConnectOptions).await() -} -*/ - -suspend fun SqlConnection.executeSetRole(role: String) = - query("SET ROLE $role").execute().coAwait() - -// TODO: use `ConnectionConfig` as the argument directly in all the following functions - -inline fun createSocketGenericPgClient( - vertx: Vertx?, - host: String, port: Int?, database: String, user: String, password: String, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptionsT, - create: (Vertx?, PgConnectOptions, PoolOptionsT) -> Client -): Client { - val pgConnectOptions = createPgConnectOptions({ - this.host = host - port?.let { this.port = it } - this.database = database - this.user = user - this.password = password - }, extraPgConnectOptions) - - return create(vertx, pgConnectOptions, poolOptions) -} +// TODO move into the `vertx.sqlclient` subpackage and rename to `SqlClients.kt` -private const val PG_CLIENT_DEPRECATED_MESSAGE = - "The dependent `PgPool` is deprecated. Just use `Pool` with `pipelined` enabled, which is the difference between `PgPool.client` and `PgPool.pool` as I have found out." -@Deprecated(PG_CLIENT_DEPRECATED_MESSAGE, ReplaceWith("createSocketPgPool")) -fun createSocketPgSqlClient( +/** + * [SqlConnectOptions.cachePreparedStatements] improves performance greatly (tested on PostgreSQL) so it's enabled by default. TODO see below + */ +inline fun createGenericSqlClient( vertx: Vertx?, - host: String, port: Int?, database: String, user: String, password: String, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() -): SqlClient = - @Suppress("DEPRECATION") - createSocketGenericPgClient( - vertx, host, port, database, user, password, extraPgConnectOptions, poolOptions, PgPool::client - ) - -fun createSocketPgPool( - vertx: Vertx?, - host: String, port: Int?, database: String, user: String, password: String, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() -): Pool = - createSocketGenericPgClient( - vertx, host, port, database, user, password, extraPgConnectOptions, poolOptions, Pool::pool - ) - -@Untested -suspend fun createSocketPgConnection( - vertx: Vertx?, - host: String, port: Int?, database: String, user: String, password: String, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {} -): PgConnection = - createSocketGenericPgClient( - vertx, host, port, database, user, password, extraPgConnectOptions, null - ) { vertx, pgConnectOptions, _ -> - PgConnection.connect(vertx, pgConnectOptions).coAwait() + connectionConfig: ConnectionConfig, + sqlConnectOptionsFromConstructor: SqlConnectOptionsT, + extraPgConnectOptions: SqlConnectOptionsT.() -> Unit = {}, + poolOptionsFromConstructor: PoolOptionsT, + extraPoolOptions: PoolOptionsT.() -> Unit = {}, + create: (Vertx?, SqlConnectOptionsT, PoolOptionsT) -> SqlClientT +): SqlClientT { + val pgConnectOptions = sqlConnectOptionsFromConstructor.apply { + // TODO consider extracting this into a conventional config and move to "kotlin-common", decoupling it from this library + cachePreparedStatements = true + setFrom(connectionConfig) + extraPgConnectOptions() } + return create(vertx, pgConnectOptions, poolOptionsFromConstructor.apply(extraPoolOptions)) +} -inline fun createPeerAuthenticationUnixDomainSocketGenericPgClient( - vertx: Vertx?, - unixDomainSocketPath: String, database: String, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptionsT, - create: (Vertx?, PgConnectOptions, PoolOptionsT) -> Client -): Client { - val pgConnectOptions = createPgConnectOptions( - { - host = unixDomainSocketPath - this.database = database - user = System.getProperty("user.name") - }, extraPgConnectOptions - ) - return create(vertx, pgConnectOptions, poolOptions) -} +// TODO move to the `postgresql` package -@Deprecated(PG_CLIENT_DEPRECATED_MESSAGE, ReplaceWith("createPeerAuthenticationUnixDomainSocketPgPool")) -fun createPeerAuthenticationUnixDomainSocketPgSqlClient( +inline fun createGenericPgClient( vertx: Vertx?, - unixDomainSocketPath: String, database: String, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() -): SqlClient = - @Suppress("DEPRECATION") - createPeerAuthenticationUnixDomainSocketGenericPgClient( - vertx, unixDomainSocketPath, database, extraPgConnectOptions, poolOptions, PgPool::client + connectionConfig: ConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, + pgPoolOptionsFromConstructor: PgPoolOptionsT, + extraPgPoolOptions: PgPoolOptionsT.() -> Unit = {}, + create: (Vertx?, PgConnectOptions, PgPoolOptionsT) -> SqlClientT +): SqlClientT = + createGenericSqlClient( + vertx, + connectionConfig, + PgConnectOptions(), + extraPgConnectOptions, + pgPoolOptionsFromConstructor, + extraPgPoolOptions, + create ) -@Deprecated(PG_CLIENT_DEPRECATED_MESSAGE, ReplaceWith("createPeerAuthenticationUnixDomainSocketPgPoolAndSetRole")) -suspend fun createUnixDomainSocketPgSqlClientAndSetRole( +fun createPgClient( vertx: Vertx?, - host: String, database: String, role: String, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() + connectionConfig: ConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, + extraPoolOptions: PgPoolOptions.() -> Unit = {}, + connectHandlerExtra: ((SqlConnection) -> Unit)? = null, // TODO add to `createGenericSqlClient` ): SqlClient = - createPeerAuthenticationUnixDomainSocketPgSqlClient( - vertx, host, database, extraPgConnectOptions, poolOptions - ).apply { - // Is this done for all connections? - query("SET ROLE $role").execute().coAwait() + createGenericPgClient( + vertx, + connectionConfig, + extraPgConnectOptions, + PgPoolOptions(), + extraPoolOptions + ) { vertx, database, options -> + PgBuilder.client() + .apply { + using(vertx) + connectingTo(database) + with(options) + // TODO move to an overload of `createGenericSqlClient` + val connectHandler = connectionConfig.connectHandler(connectHandlerExtra) + connectHandler?.let { withConnectHandler(it) } + } + .build() } -fun createPeerAuthenticationUnixDomainSocketPgPool( +/** + * [PgPoolOptions.pipelined] is enabled by default. + */ +fun createPgPool( vertx: Vertx?, - unixDomainSocketPath: String, database: String, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() -): Pool = - createPeerAuthenticationUnixDomainSocketGenericPgClient( - vertx, unixDomainSocketPath, database, extraPgConnectOptions, poolOptions, Pool::pool - ) - -fun createPeerAuthenticationUnixDomainSocketPgPoolAndSetRole( - vertx: Vertx?, - host: String, database: String, role: String, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, poolOptions: PoolOptions = poolOptionsOf() + connectionConfig: ConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, + extraPoolOptions: PgPoolOptions.() -> Unit = {}, + connectHandlerExtra: ((SqlConnection) -> Unit)? = null, // TODO add to `createGenericSqlClient` ): Pool = - createPeerAuthenticationUnixDomainSocketPgPool(vertx, host, database, extraPgConnectOptions, poolOptions) - .connectHandler { - CoroutineScope(Dispatchers.Unconfined).launch { - // TODO: are exceptions handled? - it.executeSetRole(role) - /** @see Pool.connectHandler */ - it.close().coAwait() - } + createGenericPgClient( + vertx, + connectionConfig, + extraPgConnectOptions, + PgPoolOptions(), + { + // TODO consider extracting this into a conventional config and move to "kotlin-common", decoupling it from this library + isPipelined = true + extraPoolOptions() } + ) { vertx, database, options -> + PgBuilder.pool() + .apply { + using(vertx) + connectingTo(database) + with(options) + // TODO move to an overload of `createGenericSqlClient` + val connectHandler = connectionConfig.connectHandler(connectHandlerExtra) + connectHandler?.let { withConnectHandler(it) } + } + .build() + } + +// TODO `createPgClient` @Untested -suspend fun createPeerAuthenticationUnixDomainSocketPgConnectionAndSetRole( +suspend fun createPgConnection( vertx: Vertx?, - host: String, database: String, role: String, + connectionConfig: ConnectionConfig.Socket, extraPgConnectOptions: PgConnectOptions.() -> Unit = {} ): PgConnection = - createPeerAuthenticationUnixDomainSocketGenericPgClient( - vertx, host, database, extraPgConnectOptions, null + createGenericPgClient( + vertx, connectionConfig, extraPgConnectOptions, null ) { vertx, pgConnectOptions, _ -> - PgConnection.connect(vertx, pgConnectOptions).coAwait().apply { - executeSetRole(role) + PgConnection.connect(vertx, pgConnectOptions).coAwait().also { + connectionConfig.initConnection(it) } } diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig.kt similarity index 71% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig.kt index dbfd61c..50598cd 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig.kt @@ -1,8 +1,12 @@ -package com.huanshankeji.exposedvertxsqlclient +package com.huanshankeji.exposedvertxsqlclient.local +import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig +import com.huanshankeji.exposedvertxsqlclient.EvscConfig +import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi import com.huanshankeji.net.LOCALHOST -// TODO: move to a separate package and consider adding a prefix word such as "default" or "conventional" as this class is not general enough +// TODO consider adding a prefix word such as "conventional" as this class is not general enough +// TODO consider refactoring this class into a function / functions to reduce the cognitive complexity /** * A kind of connection config that can produce both a [ConnectionConfig.Socket] and a [ConnectionConfig.UnixDomainSocketWithPeerAuthentication] * to connect to a local database server. diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExposedDatabases.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt similarity index 74% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExposedDatabases.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt index 85dd82a..69d2af5 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExposedDatabases.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt @@ -1,5 +1,6 @@ -package com.huanshankeji.exposedvertxsqlclient +package com.huanshankeji.exposedvertxsqlclient.postgresql.exposed +import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig import org.jetbrains.exposed.sql.Database fun exposedDatabaseConnectPostgreSql(socketConnectionConfig: ConnectionConfig.Socket) = diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectOptions.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectOptions.kt new file mode 100644 index 0000000..59384a0 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectOptions.kt @@ -0,0 +1,24 @@ +package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient + +import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig +import io.vertx.sqlclient.SqlConnectOptions + +fun SqlConnectOptions.setFrom(connectionConfig: ConnectionConfig.Socket) { + host = connectionConfig.host + connectionConfig.port?.let { port = it } + database = connectionConfig.database + user = connectionConfig.user + password = connectionConfig.password +} + +fun SqlConnectOptions.setFrom(connectionConfig: ConnectionConfig.UnixDomainSocketWithPeerAuthentication) { + host = connectionConfig.path + database = connectionConfig.database + user = System.getProperty("user.name") +} + +fun SqlConnectOptions.setFrom(connectionConfig: ConnectionConfig) = + when (connectionConfig) { + is ConnectionConfig.Socket -> setFrom(connectionConfig) + is ConnectionConfig.UnixDomainSocketWithPeerAuthentication -> setFrom(connectionConfig) + } diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnection.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnection.kt new file mode 100644 index 0000000..0490eb3 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnection.kt @@ -0,0 +1,12 @@ +package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient + +import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi +import io.vertx.kotlin.coroutines.coAwait +import io.vertx.sqlclient.SqlConnection + +// TODO consider using prepared statements +// TODO assert and return `Unit` +// TODO consider moving to "kotlin-common" +@ExperimentalEvscApi +suspend fun SqlConnection.setRole(role: String) = + query("SET ROLE $role").execute().coAwait() diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt new file mode 100644 index 0000000..375c196 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt @@ -0,0 +1,32 @@ +package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient + +import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig +import io.vertx.core.Handler +import io.vertx.kotlin.coroutines.coAwait +import io.vertx.sqlclient.Pool +import io.vertx.sqlclient.SqlConnection +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +suspend fun ConnectionConfig.initConnection(sqlConnection: SqlConnection) { + when (this) { + is ConnectionConfig.Socket -> Unit // do nothing + is ConnectionConfig.UnixDomainSocketWithPeerAuthentication -> sqlConnection.setRole(role) + } +} + +// TODO make `extra` `suspend` +fun ConnectionConfig.connectHandler(extra: ((SqlConnection) -> Unit)?): Handler? = + when (this) { + is ConnectionConfig.Socket -> extra?.let { Handler { it(it) } } + is ConnectionConfig.UnixDomainSocketWithPeerAuthentication -> Handler { + CoroutineScope(Dispatchers.Unconfined).launch { + // TODO: are exceptions handled? + it.setRole(role) + extra?.let { extra -> extra(it) } + /** @see Pool.connectHandler */ + it.close().coAwait() + } + } + } diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt index 9c9cb8d..275e326 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt @@ -1,7 +1,7 @@ package com.huanshankeji.exposed.benchmark import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig -import com.huanshankeji.exposedvertxsqlclient.exposedDatabaseConnectPostgreSql +import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgreSql import kotlinx.benchmark.Scope import kotlinx.benchmark.Setup import kotlinx.benchmark.State diff --git a/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index e8d7393..f1d5567 100644 --- a/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -1,6 +1,7 @@ package com.huanshankeji.exposedvertxsqlclient import com.huanshankeji.exposed.* +import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgreSql import com.huanshankeji.exposedvertxsqlclient.sql.* import io.vertx.core.Vertx import kotlinx.coroutines.Dispatchers From 6b1547ecbdd1daac138ffb7eb8939c7ac29d870e Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sun, 17 Nov 2024 19:15:27 +0800 Subject: [PATCH 07/26] Move "VertxSqlClients.kt" --- .../huanshankeji/exposedvertxsqlclient/DatabaseClient.kt | 1 + .../sqlclient/SqlClients.kt} | 9 ++------- 2 files changed, 3 insertions(+), 7 deletions(-) rename core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/{VertxSqlClients.kt => vertx/sqlclient/SqlClients.kt} (92%) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index 96f6385..f636ff2 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -6,6 +6,7 @@ import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig.Socket import com.huanshankeji.exposedvertxsqlclient.local.LocalConnectionConfig import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgreSql import com.huanshankeji.exposedvertxsqlclient.sql.selectExpression +import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createPgPool import com.huanshankeji.os.isCurrentOsLinux import com.huanshankeji.vertx.kotlin.coroutines.coroutineToFuture import com.huanshankeji.vertx.kotlin.sqlclient.executeBatchAwaitForSqlResultSequence diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt similarity index 92% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt rename to core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt index 3cbe4e2..903ab77 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt @@ -1,9 +1,7 @@ -package com.huanshankeji.exposedvertxsqlclient +package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient import com.huanshankeji.Untested -import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.connectHandler -import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.initConnection -import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.setFrom +import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig import io.vertx.core.Vertx import io.vertx.kotlin.coroutines.coAwait import io.vertx.pgclient.PgBuilder @@ -12,9 +10,6 @@ import io.vertx.pgclient.PgConnection import io.vertx.pgclient.impl.PgPoolOptions import io.vertx.sqlclient.* -// TODO move into the `vertx.sqlclient` subpackage and rename to `SqlClients.kt` - - /** * [SqlConnectOptions.cachePreparedStatements] improves performance greatly (tested on PostgreSQL) so it's enabled by default. TODO see below */ From 21d34c5388f09cf1d91bff37682328eb3799ef47 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sun, 17 Nov 2024 19:25:12 +0800 Subject: [PATCH 08/26] Move code related only to PostgreSQL into the `postgresql` subpackage --- .../exposedvertxsqlclient/DatabaseClient.kt | 70 ----------- .../postgresql/DatabaseClient.kt | 72 ++++++++++++ .../postgresql/vertx/pgclient/PgClients.kt | 109 ++++++++++++++++++ .../vertx/sqlclient/SqlClients.kt | 106 +---------------- .../exposedvertxsqlclient/Examples.kt | 1 + 5 files changed, 185 insertions(+), 173 deletions(-) create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index f636ff2..f917dbf 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -2,19 +2,12 @@ package com.huanshankeji.exposedvertxsqlclient import arrow.core.* import com.huanshankeji.collections.singleOrNullIfEmpty -import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig.Socket -import com.huanshankeji.exposedvertxsqlclient.local.LocalConnectionConfig -import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgreSql import com.huanshankeji.exposedvertxsqlclient.sql.selectExpression -import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createPgPool -import com.huanshankeji.os.isCurrentOsLinux import com.huanshankeji.vertx.kotlin.coroutines.coroutineToFuture import com.huanshankeji.vertx.kotlin.sqlclient.executeBatchAwaitForSqlResultSequence -import io.vertx.core.Vertx import io.vertx.core.buffer.Buffer import io.vertx.kotlin.coroutines.coAwait import io.vertx.pgclient.PgConnectOptions -import io.vertx.pgclient.impl.PgPoolOptions import io.vertx.sqlclient.* import kotlinx.coroutines.coroutineScope import org.jetbrains.exposed.dao.id.EntityID @@ -464,66 +457,3 @@ suspend fun DatabaseClient.with savepointName: String, function: suspend (DatabaseClient) -> Boolean ): Boolean = withSavepointAndRollbackIfThrowsOrLeft(savepointName) { if (function(it)) Unit.right() else Unit.left() }.isRight() - - -// TODO move to the `postgresql` package - -// can be used for a shared Exposed `Database` among `DatabaseClient`s -fun createPgPoolDatabaseClient( - vertx: Vertx?, - vertxSqlClientConnectionConfig: ConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, - exposedDatabase: Database -): DatabaseClient = - DatabaseClient( - createPgPool(vertx, vertxSqlClientConnectionConfig, extraPgConnectOptions, extraPgPoolOptions), - exposedDatabase - ) - -fun createPgPoolDatabaseClient( - vertx: Vertx?, - vertxSqlClientConnectionConfig: ConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, - exposedSocketConnectionConfig: Socket -): DatabaseClient = - createPgPoolDatabaseClient( - vertx, vertxSqlClientConnectionConfig, extraPgConnectOptions, extraPgPoolOptions, - exposedDatabaseConnectPostgreSql(exposedSocketConnectionConfig) - ) - -/** It may be more efficient to use a single shared [Database] to generate SQLs for multiple [DatabaseClient]s/[SqlClient]s. */ -fun createPgPoolDatabaseClient( - vertx: Vertx?, - vertxSqlClientConnectionType: ConnectionType, localConnectionConfig: LocalConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, - exposedDatabase: Database? = null -) = - with(localConnectionConfig) { - val connectionConfig = when (vertxSqlClientConnectionType) { - ConnectionType.Socket -> socketConnectionConfig - ConnectionType.UnixDomainSocketWithPeerAuthentication -> unixDomainSocketWithPeerAuthenticationConnectionConfig - } - - if (exposedDatabase === null) - createPgPoolDatabaseClient( - vertx, connectionConfig, extraPgConnectOptions, extraPgPoolOptions, socketConnectionConfig - ) - else - createPgPoolDatabaseClient( - vertx, connectionConfig, extraPgConnectOptions, extraPgPoolOptions, exposedDatabase - ) - } - -fun createBetterPgPoolDatabaseClient( - vertx: Vertx?, - localConnectionConfig: LocalConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, - exposedDatabase: Database? = null -) = - createPgPoolDatabaseClient( - vertx, - if (isCurrentOsLinux()) ConnectionType.UnixDomainSocketWithPeerAuthentication else ConnectionType.Socket, - localConnectionConfig, - extraPgConnectOptions, extraPgPoolOptions, - exposedDatabase - ) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt index 54ea5d2..ea8d094 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt @@ -1,9 +1,81 @@ package com.huanshankeji.exposedvertxsqlclient.postgresql +import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig +import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig.Socket +import com.huanshankeji.exposedvertxsqlclient.ConnectionType import com.huanshankeji.exposedvertxsqlclient.DatabaseClient +import com.huanshankeji.exposedvertxsqlclient.local.LocalConnectionConfig +import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgreSql +import com.huanshankeji.exposedvertxsqlclient.postgresql.vertx.pgclient.createPgPool import com.huanshankeji.exposedvertxsqlclient.withTypedTransaction +import com.huanshankeji.os.isCurrentOsLinux +import io.vertx.core.Vertx +import io.vertx.pgclient.PgConnectOptions import io.vertx.pgclient.PgConnection +import io.vertx.pgclient.impl.PgPoolOptions import io.vertx.sqlclient.Pool +import io.vertx.sqlclient.SqlClient +import org.jetbrains.exposed.sql.Database + +// can be used for a shared Exposed `Database` among `DatabaseClient`s +fun createPgPoolDatabaseClient( + vertx: Vertx?, + vertxSqlClientConnectionConfig: ConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, + exposedDatabase: Database +): DatabaseClient = + DatabaseClient( + createPgPool(vertx, vertxSqlClientConnectionConfig, extraPgConnectOptions, extraPgPoolOptions), + exposedDatabase + ) + +fun createPgPoolDatabaseClient( + vertx: Vertx?, + vertxSqlClientConnectionConfig: ConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, + exposedSocketConnectionConfig: Socket +): DatabaseClient = + createPgPoolDatabaseClient( + vertx, vertxSqlClientConnectionConfig, extraPgConnectOptions, extraPgPoolOptions, + exposedDatabaseConnectPostgreSql(exposedSocketConnectionConfig) + ) + +/** It may be more efficient to use a single shared [Database] to generate SQLs for multiple [DatabaseClient]s/[SqlClient]s. */ +fun createPgPoolDatabaseClient( + vertx: Vertx?, + vertxSqlClientConnectionType: ConnectionType, localConnectionConfig: LocalConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, + exposedDatabase: Database? = null +) = + with(localConnectionConfig) { + val connectionConfig = when (vertxSqlClientConnectionType) { + ConnectionType.Socket -> socketConnectionConfig + ConnectionType.UnixDomainSocketWithPeerAuthentication -> unixDomainSocketWithPeerAuthenticationConnectionConfig + } + + if (exposedDatabase === null) + createPgPoolDatabaseClient( + vertx, connectionConfig, extraPgConnectOptions, extraPgPoolOptions, socketConnectionConfig + ) + else + createPgPoolDatabaseClient( + vertx, connectionConfig, extraPgConnectOptions, extraPgPoolOptions, exposedDatabase + ) + } + +fun createBetterPgPoolDatabaseClient( + vertx: Vertx?, + localConnectionConfig: LocalConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, + exposedDatabase: Database? = null +) = + createPgPoolDatabaseClient( + vertx, + if (isCurrentOsLinux()) ConnectionType.UnixDomainSocketWithPeerAuthentication else ConnectionType.Socket, + localConnectionConfig, + extraPgConnectOptions, extraPgPoolOptions, + exposedDatabase + ) suspend fun DatabaseClient.withPgTransaction(function: suspend (DatabaseClient) -> T): T = withTypedTransaction(function) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt new file mode 100644 index 0000000..3035479 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt @@ -0,0 +1,109 @@ +package com.huanshankeji.exposedvertxsqlclient.postgresql.vertx.pgclient + +import com.huanshankeji.Untested +import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig +import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.connectHandler +import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createGenericSqlClient +import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.initConnection +import io.vertx.core.Vertx +import io.vertx.kotlin.coroutines.coAwait +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.Pool +import io.vertx.sqlclient.SqlClient +import io.vertx.sqlclient.SqlConnection + +inline fun createGenericPgClient( + vertx: Vertx?, + connectionConfig: ConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, + pgPoolOptionsFromConstructor: PgPoolOptionsT, + extraPgPoolOptions: PgPoolOptionsT.() -> Unit = {}, + create: (Vertx?, PgConnectOptions, PgPoolOptionsT) -> SqlClientT +): SqlClientT = + createGenericSqlClient( + vertx, + connectionConfig, + PgConnectOptions(), + extraPgConnectOptions, + pgPoolOptionsFromConstructor, + extraPgPoolOptions, + create + ) + +fun createPgClient( + vertx: Vertx?, + connectionConfig: ConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, + extraPoolOptions: PgPoolOptions.() -> Unit = {}, + connectHandlerExtra: ((SqlConnection) -> Unit)? = null, // TODO add to `createGenericSqlClient` +): SqlClient = + createGenericPgClient( + vertx, + connectionConfig, + extraPgConnectOptions, + PgPoolOptions(), + extraPoolOptions + ) { vertx, database, options -> + PgBuilder.client() + .apply { + using(vertx) + connectingTo(database) + with(options) + // TODO move to an overload of `createGenericSqlClient` + val connectHandler = connectionConfig.connectHandler(connectHandlerExtra) + connectHandler?.let { withConnectHandler(it) } + } + .build() + } + +/** + * [PgPoolOptions.pipelined] is enabled by default. + */ +fun createPgPool( + vertx: Vertx?, + connectionConfig: ConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, + extraPoolOptions: PgPoolOptions.() -> Unit = {}, + connectHandlerExtra: ((SqlConnection) -> Unit)? = null, // TODO add to `createGenericSqlClient` +): Pool = + createGenericPgClient( + vertx, + connectionConfig, + extraPgConnectOptions, + PgPoolOptions(), + { + // TODO consider extracting this into a conventional config and move to "kotlin-common", decoupling it from this library + isPipelined = true + extraPoolOptions() + } + ) { vertx, database, options -> + PgBuilder.pool() + .apply { + using(vertx) + connectingTo(database) + with(options) + // TODO move to an overload of `createGenericSqlClient` + val connectHandler = connectionConfig.connectHandler(connectHandlerExtra) + connectHandler?.let { withConnectHandler(it) } + } + .build() + } + +// TODO `createPgClient` + +@Untested +suspend fun createPgConnection( + vertx: Vertx?, + connectionConfig: ConnectionConfig.Socket, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {} +): PgConnection = + createGenericPgClient( + vertx, connectionConfig, extraPgConnectOptions, null + ) { vertx, pgConnectOptions, _ -> + PgConnection.connect(vertx, pgConnectOptions).coAwait().also { + connectionConfig.initConnection(it) + } + } diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt index 903ab77..76fc484 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt @@ -1,14 +1,10 @@ package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient -import com.huanshankeji.Untested import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig import io.vertx.core.Vertx -import io.vertx.kotlin.coroutines.coAwait -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.* +import io.vertx.sqlclient.PoolOptions +import io.vertx.sqlclient.SqlClient +import io.vertx.sqlclient.SqlConnectOptions /** * [SqlConnectOptions.cachePreparedStatements] improves performance greatly (tested on PostgreSQL) so it's enabled by default. TODO see below @@ -31,99 +27,3 @@ inline fun createGenericPgClient( - vertx: Vertx?, - connectionConfig: ConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, - pgPoolOptionsFromConstructor: PgPoolOptionsT, - extraPgPoolOptions: PgPoolOptionsT.() -> Unit = {}, - create: (Vertx?, PgConnectOptions, PgPoolOptionsT) -> SqlClientT -): SqlClientT = - createGenericSqlClient( - vertx, - connectionConfig, - PgConnectOptions(), - extraPgConnectOptions, - pgPoolOptionsFromConstructor, - extraPgPoolOptions, - create - ) - -fun createPgClient( - vertx: Vertx?, - connectionConfig: ConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, - extraPoolOptions: PgPoolOptions.() -> Unit = {}, - connectHandlerExtra: ((SqlConnection) -> Unit)? = null, // TODO add to `createGenericSqlClient` -): SqlClient = - createGenericPgClient( - vertx, - connectionConfig, - extraPgConnectOptions, - PgPoolOptions(), - extraPoolOptions - ) { vertx, database, options -> - PgBuilder.client() - .apply { - using(vertx) - connectingTo(database) - with(options) - // TODO move to an overload of `createGenericSqlClient` - val connectHandler = connectionConfig.connectHandler(connectHandlerExtra) - connectHandler?.let { withConnectHandler(it) } - } - .build() - } - -/** - * [PgPoolOptions.pipelined] is enabled by default. - */ -fun createPgPool( - vertx: Vertx?, - connectionConfig: ConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, - extraPoolOptions: PgPoolOptions.() -> Unit = {}, - connectHandlerExtra: ((SqlConnection) -> Unit)? = null, // TODO add to `createGenericSqlClient` -): Pool = - createGenericPgClient( - vertx, - connectionConfig, - extraPgConnectOptions, - PgPoolOptions(), - { - // TODO consider extracting this into a conventional config and move to "kotlin-common", decoupling it from this library - isPipelined = true - extraPoolOptions() - } - ) { vertx, database, options -> - PgBuilder.pool() - .apply { - using(vertx) - connectingTo(database) - with(options) - // TODO move to an overload of `createGenericSqlClient` - val connectHandler = connectionConfig.connectHandler(connectHandlerExtra) - connectHandler?.let { withConnectHandler(it) } - } - .build() - } - -// TODO `createPgClient` - -@Untested -suspend fun createPgConnection( - vertx: Vertx?, - connectionConfig: ConnectionConfig.Socket, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {} -): PgConnection = - createGenericPgClient( - vertx, connectionConfig, extraPgConnectOptions, null - ) { vertx, pgConnectOptions, _ -> - PgConnection.connect(vertx, pgConnectOptions).coAwait().also { - connectionConfig.initConnection(it) - } - } diff --git a/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index f1d5567..6330e98 100644 --- a/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -1,6 +1,7 @@ package com.huanshankeji.exposedvertxsqlclient import com.huanshankeji.exposed.* +import com.huanshankeji.exposedvertxsqlclient.postgresql.createPgPoolDatabaseClient import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgreSql import com.huanshankeji.exposedvertxsqlclient.sql.* import io.vertx.core.Vertx From 603dbb7b5039692b42aa3918f21671617cb225f0 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sun, 17 Nov 2024 19:37:16 +0800 Subject: [PATCH 09/26] Remove a TODO which was already achieved in commit dfd0d3b5762b044c3776cbe098ee3869e57004e0 --- .../postgresql/vertx/pgclient/PgClients.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt index 3035479..05fd5c6 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt @@ -92,8 +92,6 @@ fun createPgPool( .build() } -// TODO `createPgClient` - @Untested suspend fun createPgConnection( vertx: Vertx?, From fdc20233959dd2ae05a4e0978d4d10b886addb8d Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Tue, 19 Nov 2024 23:14:47 +0800 Subject: [PATCH 10/26] Completely overhaul the client creation APIs 1. move code related to `PostgreSQL` into the `postgreql` package 1. refactor the Vert.x `SqlClient` and Exposed `Database` creation APIs to be more configurable and straightforward 1. extract some common functions for JDBC, Exposed, and Vert.x 1. move the example code into the `main` source set 1. remove the extra `DatabaseClient` creation APIs `create*DatabaseClient` 1. adopt `EvscConfig` as the single-source-of-truth client config 1. add some more TODOs 1. update the example code README.md correspondingly --- README.md | 38 ++++++- .../exposedvertxsqlclient/ConnectionConfig.kt | 6 +- .../exposedvertxsqlclient/DatabaseClient.kt | 24 +++- .../DatabaseClientFactory.kt | 12 ++ .../exposedvertxsqlclient/EvscConfig.kt | 3 +- .../exposed/ExposedDatabaseFactory.kt | 8 ++ .../exposed/ExposedDatabases.kt | 35 ++++++ .../exposedvertxsqlclient/jdbc/JdbcUrls.kt | 7 ++ .../local/LocalConnectionConfig.kt | 13 ++- .../postgresql/DatabaseClient.kt | 72 ------------ .../postgresql/exposed/ExposedDatabases.kt | 37 +++++-- .../postgresql/local/LocalConnectionConfig.kt | 16 +++ .../postgresql/vertx/pgclient/PgClients.kt | 104 +++++++++--------- .../vertx/sqlclient/SqlClients.kt | 90 +++++++++++++-- .../vertx/sqlclient/SqlConnection.kt | 4 +- .../sqlclient/SqlConnectionInitialization.kt | 26 ++++- .../vertx/sqlclient/VertxSqlClientFactory.kt | 8 ++ .../kotlin/com/huanshankeji/jdbc/JdbcUrls.kt | 6 + .../vertx/pgclient/PgPoolOptions.kt | 12 ++ .../vertx/sqlclient/SqlConnectOptions.kt | 12 ++ integrated/build.gradle.kts | 5 +- .../WithContainerizedDatabaseBenchmark.kt | 7 +- .../exposedvertxsqlclient/Examples.kt | 33 ++++-- .../exposedvertxsqlclient/MappingExamples.kt | 0 24 files changed, 394 insertions(+), 184 deletions(-) create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClientFactory.kt create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabaseFactory.kt create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabases.kt create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/jdbc/JdbcUrls.kt create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/local/LocalConnectionConfig.kt create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/VertxSqlClientFactory.kt create mode 100644 core/src/main/kotlin/com/huanshankeji/jdbc/JdbcUrls.kt create mode 100644 core/src/main/kotlin/com/huanshankeji/vertx/pgclient/PgPoolOptions.kt create mode 100644 core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/SqlConnectOptions.kt rename integrated/src/{test => main}/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt (71%) rename integrated/src/{test => main}/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt (100%) diff --git a/README.md b/README.md index ebfb3ea..a210fcb 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,39 @@ Here is a basic usage guide. This project currently serves our own use, therefor ### Create a `DatabaseClient` +Create an `EvscConfig` as the single source of truth: + +```kotlin +val evscConfig = ConnectionConfig.Socket("localhost", user = "user", password = "password", database = "database") + .toUniversalEvscConfig() +``` + +Local alternative with Unix domain socket: + +```kotlin +val evscConfig = defaultPostgresqlLocalConnectionConfig( + user = "user", + socketConnectionPassword = "password", + database = "database" +).toPerformantUnixEvscConfig() +``` + +Create an Exposed `Database` with the `ConnectionConfig`, which can be reused for multiple `Verticle`s: + +```kotlin +val exposedDatabase = evscConfig.exposedConnectionConfig.exposedDatabaseConnectPostgresql() +``` + +Create a Vert.x `SqlClient` with the `ConnectionConfig`, preferably in a `Verticle`: + +```kotlin +val vertxPool = createPgPool(vertx, evscConfig.vertxSqlClientConnectionConfig) +``` + +Create a `Database` with the provided Vert.x `SqlClient` and Exposed `Database`, preferably in a `Verticle`: + ```kotlin -val socketConnectionConfig = - ConnectionConfig.Socket("localhost", user = "user", password = "password", database = "database") -val exposedDatabase = exposedDatabaseConnectPostgreSql(socketConnectionConfig) -val databaseClient = createPgPoolDatabaseClient( - vertx, socketConnectionConfig, exposedDatabase = exposedDatabase -) +val databaseClient = DatabaseClient(vertxPool, exposedDatabase) ``` ### Example table definitions diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt index 6c27162..cfbb80a 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionConfig.kt @@ -2,7 +2,6 @@ package com.huanshankeji.exposedvertxsqlclient import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.setRole -// TODO make it not sealed with some common methods, for example, `SqlConnectOptions.setFrom` sealed interface ConnectionConfig { val userAndRole: String val database: String @@ -27,4 +26,7 @@ sealed interface ConnectionConfig { ) : ConnectionConfig { override val userAndRole: String get() = role } -} \ No newline at end of file +} + +fun ConnectionConfig.Socket.toUniversalEvscConfig() = + EvscConfig(this, this) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index f917dbf..2fdb279 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -77,12 +77,13 @@ internal val logger = LoggerFactory.getLogger(DatabaseClient::class.java) /** * A wrapper client around Vert.x [SqlClient] for queries and an Exposed [Database] to generate SQLs working around the limitations of Exposed. * - * @param validateBatch whether to validate whether the batch statements have the same generated prepared SQL. + * @param validateBatch whether to validate whether the batch statements have the same generated prepared SQL. It's recommended to keep this enabled for tests but disabled for production. */ @OptIn(ExperimentalEvscApi::class) -class DatabaseClient( - val vertxSqlClient: VertxSqlClient, +class DatabaseClient( + val vertxSqlClient: VertxSqlClientT, val exposedDatabase: Database, + // TODO consider adding a `isProduction` parameter whose default depends on the runtime val validateBatch: Boolean = true, val logSql: Boolean = false ) { @@ -91,6 +92,8 @@ class DatabaseClient( // How to close The Exposed `Database`? } + // TODO consider splitting into 2, one with `readOnly` set to true and isolation level `NONE` / READ UNCOMMITED for SQL generation, and a normal one for Exposed execution + // TODO also consider adding the 2 parameters `transactionIsolation` and `readOnly` with default arguments fun exposedTransaction(statement: ExposedTransaction.() -> T) = transaction(exposedDatabase, statement) @@ -115,7 +118,12 @@ class DatabaseClient( */ @Deprecated( "This function does not support analyzing dependencies among tables. Since this action is not frequently needed we can adopt the blocking approach. Use Exposed `SchemaUtils` and create multiple tables in batch instead, temporarily.", - ReplaceWith("exposedTransaction { SchemaUtils.create(table) }", "org.jetbrains.exposed.sql.SchemaUtils") + ReplaceWith( + "withContext(Dispatchers.IO) { exposedTransaction { SchemaUtils.create(table) } }", + "kotlinx.coroutines.withContext", + "kotlinx.coroutines.Dispatchers", + "org.jetbrains.exposed.sql.SchemaUtils" + ) ) suspend fun createTable(table: Table) = executePlainSqlUpdate(exposedTransaction { @@ -125,7 +133,13 @@ class DatabaseClient( @Deprecated( "This function does not support analyzing dependencies among tables. Since this action is not frequently needed we can adopt the blocking approach. Use Exposed `SchemaUtils` and drop multiple tables in batch instead, temporarily.", - ReplaceWith("exposedTransaction { SchemaUtils.drop(table) }", "org.jetbrains.exposed.sql.SchemaUtils") + // TODO `Dispatchers.IO` + ReplaceWith( + "withContext(Dispatchers.IO) { exposedTransaction { SchemaUtils.drop(table) } }", + "kotlinx.coroutines.withContext", + "kotlinx.coroutines.Dispatchers", + "org.jetbrains.exposed.sql.SchemaUtils" + ) ) suspend fun dropTable(table: Table) = executePlainSqlUpdate(exposedTransaction { diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClientFactory.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClientFactory.kt new file mode 100644 index 0000000..289df4d --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClientFactory.kt @@ -0,0 +1,12 @@ +package com.huanshankeji.exposedvertxsqlclient + +import com.huanshankeji.exposedvertxsqlclient.exposed.ExposedDatabaseFactory +import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.VertxSqlClientFactory +import io.vertx.sqlclient.SqlClient + +// TODO remove, unnecessary abstraction as a user can just call the `DatabaseClient` constructor +@ExperimentalEvscApi +interface DatabaseClientFactory : + VertxSqlClientFactory, ExposedDatabaseFactory { + fun createDatabaseClient(): DatabaseClient +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/EvscConfig.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/EvscConfig.kt index fae1efb..fcb66e2 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/EvscConfig.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/EvscConfig.kt @@ -6,8 +6,9 @@ interface IEvscConfig { val vertxSqlClientConnectionConfig: ConnectionConfig } +// TODO add a type parameter for `exposedConnectionConfig` to better support RDBMSs that don't support Unix domain sockets /** - * This API is not used in the factory function parameter types yet. TODO + * This API is not used in the factory function parameter types yet. */ @ExperimentalEvscApi class EvscConfig( diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabaseFactory.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabaseFactory.kt new file mode 100644 index 0000000..21283b4 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabaseFactory.kt @@ -0,0 +1,8 @@ +package com.huanshankeji.exposedvertxsqlclient.exposed + +import org.jetbrains.exposed.sql.Database + +// TODO remove +interface ExposedDatabaseFactory { + fun databaseConnect(): Database +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabases.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabases.kt new file mode 100644 index 0000000..c9c4b92 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabases.kt @@ -0,0 +1,35 @@ +package com.huanshankeji.exposedvertxsqlclient.exposed + +import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig +import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi +import com.huanshankeji.exposedvertxsqlclient.jdbc.jdbcUrl +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 + +/** + * Further configurations such as [setupConnection], [databaseConfig], and [manager] are most likely not needed + * because the Exposed [Database] is mostly only used for table creation and SQL generation. + */ +@ExperimentalEvscApi +fun ConnectionConfig.Socket.exposedDatabaseConnect( + rdbms: String, + driver: String, + setupConnection: (Connection) -> Unit = {}, + databaseConfig: DatabaseConfig? = null, + manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it) } +) = + Database.connect(jdbcUrl(rdbms), driver, user, password, setupConnection, databaseConfig, manager) + +@ExperimentalEvscApi +fun exposedDatabaseConnect( + rdbms: String, + socketConnectionConfig: ConnectionConfig.Socket, + driver: String, + setupConnection: (Connection) -> Unit = {}, + databaseConfig: DatabaseConfig? = null, + manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it) } +) = + socketConnectionConfig.exposedDatabaseConnect(rdbms, driver, setupConnection, databaseConfig, manager) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/jdbc/JdbcUrls.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/jdbc/JdbcUrls.kt new file mode 100644 index 0000000..be8bcdd --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/jdbc/JdbcUrls.kt @@ -0,0 +1,7 @@ +package com.huanshankeji.exposedvertxsqlclient.jdbc + +import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig +import com.huanshankeji.jdbc.jdbcUrl + +fun ConnectionConfig.Socket.jdbcUrl(rdbms: String) = + jdbcUrl(rdbms, host, port, database) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig.kt index 50598cd..c4d0e0b 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig.kt @@ -11,17 +11,22 @@ import com.huanshankeji.net.LOCALHOST * A kind of connection config that can produce both a [ConnectionConfig.Socket] and a [ConnectionConfig.UnixDomainSocketWithPeerAuthentication] * to connect to a local database server. */ -class LocalConnectionConfig(val database: String, val user: String, val socketConnectionPassword: String) { +class LocalConnectionConfig( + val socketConnectionPort: Int? = null, + val unixDomainSocketPath: String, + val user: String, + val socketConnectionPassword: String, + val database: String +) { companion object { - const val UNIX_DOMAIN_SOCKET_PATH = "/var/run/postgresql" const val SOCKET_HOST = LOCALHOST } val socketConnectionConfig = - ConnectionConfig.Socket(SOCKET_HOST, null, user, socketConnectionPassword, database) + ConnectionConfig.Socket(SOCKET_HOST, socketConnectionPort, user, socketConnectionPassword, database) val unixDomainSocketWithPeerAuthenticationConnectionConfig = - ConnectionConfig.UnixDomainSocketWithPeerAuthentication(UNIX_DOMAIN_SOCKET_PATH, user, database) + ConnectionConfig.UnixDomainSocketWithPeerAuthentication(unixDomainSocketPath, user, database) } @ExperimentalEvscApi diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt index ea8d094..54ea5d2 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt @@ -1,81 +1,9 @@ package com.huanshankeji.exposedvertxsqlclient.postgresql -import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig -import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig.Socket -import com.huanshankeji.exposedvertxsqlclient.ConnectionType import com.huanshankeji.exposedvertxsqlclient.DatabaseClient -import com.huanshankeji.exposedvertxsqlclient.local.LocalConnectionConfig -import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgreSql -import com.huanshankeji.exposedvertxsqlclient.postgresql.vertx.pgclient.createPgPool import com.huanshankeji.exposedvertxsqlclient.withTypedTransaction -import com.huanshankeji.os.isCurrentOsLinux -import io.vertx.core.Vertx -import io.vertx.pgclient.PgConnectOptions import io.vertx.pgclient.PgConnection -import io.vertx.pgclient.impl.PgPoolOptions import io.vertx.sqlclient.Pool -import io.vertx.sqlclient.SqlClient -import org.jetbrains.exposed.sql.Database - -// can be used for a shared Exposed `Database` among `DatabaseClient`s -fun createPgPoolDatabaseClient( - vertx: Vertx?, - vertxSqlClientConnectionConfig: ConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, - exposedDatabase: Database -): DatabaseClient = - DatabaseClient( - createPgPool(vertx, vertxSqlClientConnectionConfig, extraPgConnectOptions, extraPgPoolOptions), - exposedDatabase - ) - -fun createPgPoolDatabaseClient( - vertx: Vertx?, - vertxSqlClientConnectionConfig: ConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, - exposedSocketConnectionConfig: Socket -): DatabaseClient = - createPgPoolDatabaseClient( - vertx, vertxSqlClientConnectionConfig, extraPgConnectOptions, extraPgPoolOptions, - exposedDatabaseConnectPostgreSql(exposedSocketConnectionConfig) - ) - -/** It may be more efficient to use a single shared [Database] to generate SQLs for multiple [DatabaseClient]s/[SqlClient]s. */ -fun createPgPoolDatabaseClient( - vertx: Vertx?, - vertxSqlClientConnectionType: ConnectionType, localConnectionConfig: LocalConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, - exposedDatabase: Database? = null -) = - with(localConnectionConfig) { - val connectionConfig = when (vertxSqlClientConnectionType) { - ConnectionType.Socket -> socketConnectionConfig - ConnectionType.UnixDomainSocketWithPeerAuthentication -> unixDomainSocketWithPeerAuthenticationConnectionConfig - } - - if (exposedDatabase === null) - createPgPoolDatabaseClient( - vertx, connectionConfig, extraPgConnectOptions, extraPgPoolOptions, socketConnectionConfig - ) - else - createPgPoolDatabaseClient( - vertx, connectionConfig, extraPgConnectOptions, extraPgPoolOptions, exposedDatabase - ) - } - -fun createBetterPgPoolDatabaseClient( - vertx: Vertx?, - localConnectionConfig: LocalConnectionConfig, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, - exposedDatabase: Database? = null -) = - createPgPoolDatabaseClient( - vertx, - if (isCurrentOsLinux()) ConnectionType.UnixDomainSocketWithPeerAuthentication else ConnectionType.Socket, - localConnectionConfig, - extraPgConnectOptions, extraPgPoolOptions, - exposedDatabase - ) suspend fun DatabaseClient.withPgTransaction(function: suspend (DatabaseClient) -> T): T = withTypedTransaction(function) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt index 69d2af5..c17199d 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt @@ -1,14 +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 -fun exposedDatabaseConnectPostgreSql(socketConnectionConfig: ConnectionConfig.Socket) = - with(socketConnectionConfig) { - Database.connect( - "jdbc:postgresql://$host${port?.let { ":$it" } ?: ""}/$database", - "org.postgresql.Driver", - user = user, - password = password - ) - } +/** + * @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) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/local/LocalConnectionConfig.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/local/LocalConnectionConfig.kt new file mode 100644 index 0000000..6187485 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/local/LocalConnectionConfig.kt @@ -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 + ) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt index 05fd5c6..0bad400 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt @@ -1,36 +1,46 @@ +@file:OptIn(ExperimentalEvscApi::class) + package com.huanshankeji.exposedvertxsqlclient.postgresql.vertx.pgclient import com.huanshankeji.Untested import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig -import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.connectHandler +import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi +import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.ConnectHandlerExtra import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createGenericSqlClient -import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.initConnection +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.kotlin.coroutines.coAwait 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.sqlclient.SqlConnection -inline fun createGenericPgClient( +/** + * @see createGenericSqlClient + */ +// made not inline anymore for easier debugging +@ExperimentalEvscApi +fun > createGenericPgClientWithBuilder( vertx: Vertx?, connectionConfig: ConnectionConfig, + clientBuilder: ClientBuilderT, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, - pgPoolOptionsFromConstructor: PgPoolOptionsT, - extraPgPoolOptions: PgPoolOptionsT.() -> Unit = {}, - create: (Vertx?, PgConnectOptions, PgPoolOptionsT) -> SqlClientT + extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, + connectHandlerExtra: ConnectHandlerExtra = null ): SqlClientT = - createGenericSqlClient( + createGenericSqlClientWithBuilder( vertx, connectionConfig, + clientBuilder, PgConnectOptions(), extraPgConnectOptions, - pgPoolOptionsFromConstructor, extraPgPoolOptions, - create + connectHandlerExtra, + PgPoolOptions() ) fun createPgClient( @@ -38,70 +48,56 @@ fun createPgClient( connectionConfig: ConnectionConfig, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPoolOptions: PgPoolOptions.() -> Unit = {}, - connectHandlerExtra: ((SqlConnection) -> Unit)? = null, // TODO add to `createGenericSqlClient` + connectHandlerExtra: ConnectHandlerExtra = null, ): SqlClient = - createGenericPgClient( + createGenericPgClientWithBuilder( vertx, connectionConfig, + PgBuilder.client(), extraPgConnectOptions, - PgPoolOptions(), - extraPoolOptions - ) { vertx, database, options -> - PgBuilder.client() - .apply { - using(vertx) - connectingTo(database) - with(options) - // TODO move to an overload of `createGenericSqlClient` - val connectHandler = connectionConfig.connectHandler(connectHandlerExtra) - connectHandler?.let { withConnectHandler(it) } - } - .build() - } + 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: ((SqlConnection) -> Unit)? = null, // TODO add to `createGenericSqlClient` + connectHandlerExtra: ConnectHandlerExtra = null, ): Pool = - createGenericPgClient( + createGenericPgClientWithBuilder( vertx, connectionConfig, + PgBuilder.pool(), extraPgConnectOptions, - PgPoolOptions(), { - // TODO consider extracting this into a conventional config and move to "kotlin-common", decoupling it from this library - isPipelined = true + setUpConventionally() extraPoolOptions() - } - ) { vertx, database, options -> - PgBuilder.pool() - .apply { - using(vertx) - connectingTo(database) - with(options) - // TODO move to an overload of `createGenericSqlClient` - val connectHandler = connectionConfig.connectHandler(connectHandlerExtra) - connectHandler?.let { withConnectHandler(it) } - } - .build() - } + }, + connectHandlerExtra + ) +/** + * @see createGenericSqlClient + */ @Untested suspend fun createPgConnection( vertx: Vertx?, - connectionConfig: ConnectionConfig.Socket, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {} + connectionConfig: ConnectionConfig, + extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, + connectHandlerExtra: ConnectHandlerExtra = null ): PgConnection = - createGenericPgClient( - vertx, connectionConfig, extraPgConnectOptions, null - ) { vertx, pgConnectOptions, _ -> - PgConnection.connect(vertx, pgConnectOptions).coAwait().also { - connectionConfig.initConnection(it) - } - } + createGenericSqlConnection( + vertx, + connectionConfig, + PgConnection::connect, + PgConnectOptions(), + extraPgConnectOptions, + connectHandlerExtra + ) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt index 76fc484..d98f044 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt @@ -1,29 +1,97 @@ package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig +import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi +import com.huanshankeji.vertx.sqlclient.setUpConventionally +import io.vertx.core.Future import io.vertx.core.Vertx -import io.vertx.sqlclient.PoolOptions -import io.vertx.sqlclient.SqlClient -import io.vertx.sqlclient.SqlConnectOptions +import io.vertx.kotlin.coroutines.coAwait +import io.vertx.sqlclient.* /** - * [SqlConnectOptions.cachePreparedStatements] improves performance greatly (tested on PostgreSQL) so it's enabled by default. TODO see below + * Exposed generates prepared statements and [SqlConnectOptions.cachePreparedStatements] improves performance greatly (tested on PostgreSQL) + * so it's enabled by default. */ +@ExperimentalEvscApi +// made inline for possible suspend calls +// TODO consider removing the default arguments so we don't forget to pass them in this library's functions inline fun createGenericSqlClient( vertx: Vertx?, connectionConfig: ConnectionConfig, sqlConnectOptionsFromConstructor: SqlConnectOptionsT, - extraPgConnectOptions: SqlConnectOptionsT.() -> Unit = {}, + extraSqlConnectOptions: SqlConnectOptionsT.() -> Unit = {}, poolOptionsFromConstructor: PoolOptionsT, extraPoolOptions: PoolOptionsT.() -> Unit = {}, - create: (Vertx?, SqlConnectOptionsT, PoolOptionsT) -> SqlClientT + noinline connectHandlerExtra: ConnectHandlerExtra = null, + create: (Vertx?, SqlConnectOptionsT, PoolOptionsT, ConnectHandlerExtra) -> SqlClientT ): SqlClientT { - val pgConnectOptions = sqlConnectOptionsFromConstructor.apply { - // TODO consider extracting this into a conventional config and move to "kotlin-common", decoupling it from this library - cachePreparedStatements = true + val sqlConnectOptions = sqlConnectOptionsFromConstructor.apply { + setUpConventionally() setFrom(connectionConfig) - extraPgConnectOptions() + extraSqlConnectOptions() } - return create(vertx, pgConnectOptions, poolOptionsFromConstructor.apply(extraPoolOptions)) + return create(vertx, sqlConnectOptions, poolOptionsFromConstructor.apply(extraPoolOptions), connectHandlerExtra) } + +/** + * @see createGenericSqlClient + */ +@ExperimentalEvscApi +// made not inline anymore for easier debugging +fun > createGenericSqlClientWithBuilder( + vertx: Vertx?, + connectionConfig: ConnectionConfig, + clientBuilder: ClientBuilderT, + sqlConnectOptionsFromConstructor: SqlConnectOptionsT, + extraSqlConnectOptions: SqlConnectOptionsT.() -> Unit = {}, + extraPoolOptions: PoolOptionsT.() -> Unit = {}, + connectHandlerExtra: ConnectHandlerExtra = null, + poolOptionsFromConstructor: PoolOptionsT +): SqlClientT = + @Suppress("NAME_SHADOWING") + createGenericSqlClient( + vertx, + connectionConfig, + sqlConnectOptionsFromConstructor, + extraSqlConnectOptions, + poolOptionsFromConstructor, + extraPoolOptions, + connectHandlerExtra + ) { vertx, database, options, connectHandlerExtra -> + clientBuilder.apply { + using(vertx) + connectingTo(database) + with(options) + val connectHandler = connectionConfig.getConnectHandler(connectHandlerExtra) + connectHandler?.let { withConnectHandler(it) } + }.build() + } + +/** + * @see createGenericSqlClient + */ +@ExperimentalEvscApi +// made not inline anymore for easier debugging +suspend fun createGenericSqlConnection( + vertx: Vertx?, + connectionConfig: ConnectionConfig, + sqlConnectionConnect: (Vertx?, SqlConnectOptionsT) -> Future, + sqlConnectOptionsFromConstructor: SqlConnectOptionsT, + extraSqlConnectOptions: SqlConnectOptionsT.() -> Unit = {}, + connectHandlerExtra: ConnectHandlerExtra = null +): SqlConnectionT = + @Suppress("NAME_SHADOWING") + createGenericSqlClient( + vertx, + connectionConfig, + sqlConnectOptionsFromConstructor, + extraSqlConnectOptions, + null, + {}, + connectHandlerExtra + ) { vertx, database, _, connectHandlerExtra -> + sqlConnectionConnect(vertx, database).coAwait().also { + connectionConfig.initConnection(it, connectHandlerExtra) + } + } diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnection.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnection.kt index 0490eb3..1b4983d 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnection.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnection.kt @@ -1,12 +1,12 @@ package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient -import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi +import com.huanshankeji.ExperimentalApi import io.vertx.kotlin.coroutines.coAwait import io.vertx.sqlclient.SqlConnection // TODO consider using prepared statements // TODO assert and return `Unit` // TODO consider moving to "kotlin-common" -@ExperimentalEvscApi +@ExperimentalApi suspend fun SqlConnection.setRole(role: String) = query("SET ROLE $role").execute().coAwait() diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt index 375c196..3f82d0c 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt @@ -9,17 +9,35 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -suspend fun ConnectionConfig.initConnection(sqlConnection: SqlConnection) { +/** + * Extra initialization on [SqlConnection] in addition to [setRole] for [ConnectionConfig.UnixDomainSocketWithPeerAuthentication]. + */ +typealias ConnectHandlerExtra = (suspend (SqlConnection) -> Unit)? +typealias ExtensionConnectHandlerExtra = (suspend SqlConnection.() -> Unit)? + +fun ExtensionConnectHandlerExtra.toWithParameterFunction(): ConnectHandlerExtra = + this + +suspend fun ConnectionConfig.initConnection(sqlConnection: SqlConnection, extra: ConnectHandlerExtra) { when (this) { is ConnectionConfig.Socket -> Unit // do nothing is ConnectionConfig.UnixDomainSocketWithPeerAuthentication -> sqlConnection.setRole(role) } + extra?.let { it(sqlConnection) } } -// TODO make `extra` `suspend` -fun ConnectionConfig.connectHandler(extra: ((SqlConnection) -> Unit)?): Handler? = +fun ConnectionConfig.getConnectHandler(extra: ConnectHandlerExtra): Handler? = when (this) { - is ConnectionConfig.Socket -> extra?.let { Handler { it(it) } } + is ConnectionConfig.Socket -> extra?.let { + // TODO extract a common `coConnectHandler` + Handler { + CoroutineScope(Dispatchers.Unconfined).launch { + it(it) + it.close().coAwait() + } + } + } + is ConnectionConfig.UnixDomainSocketWithPeerAuthentication -> Handler { CoroutineScope(Dispatchers.Unconfined).launch { // TODO: are exceptions handled? diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/VertxSqlClientFactory.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/VertxSqlClientFactory.kt new file mode 100644 index 0000000..afefc14 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/VertxSqlClientFactory.kt @@ -0,0 +1,8 @@ +package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient + +import io.vertx.sqlclient.SqlClient + +// TODO remove +interface VertxSqlClientFactory { + fun buildSqlClient(): SqlClientT +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/huanshankeji/jdbc/JdbcUrls.kt b/core/src/main/kotlin/com/huanshankeji/jdbc/JdbcUrls.kt new file mode 100644 index 0000000..4b938e0 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/jdbc/JdbcUrls.kt @@ -0,0 +1,6 @@ +// TODO move to "kotlin-common" + +package com.huanshankeji.jdbc + +fun jdbcUrl(rdbms: String, host: String, port: Int?, database: String) = + "jdbc:$rdbms://$host${port?.let { ":$it" } ?: ""}/$database" diff --git a/core/src/main/kotlin/com/huanshankeji/vertx/pgclient/PgPoolOptions.kt b/core/src/main/kotlin/com/huanshankeji/vertx/pgclient/PgPoolOptions.kt new file mode 100644 index 0000000..a3c5a10 --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/vertx/pgclient/PgPoolOptions.kt @@ -0,0 +1,12 @@ +// TODO move to "kotlin-common" + +package com.huanshankeji.vertx.pgclient + +import io.vertx.pgclient.impl.PgPoolOptions + +/** + * Optimized for throughput. + */ +fun PgPoolOptions.setUpConventionally() { + isPipelined = true +} diff --git a/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/SqlConnectOptions.kt b/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/SqlConnectOptions.kt new file mode 100644 index 0000000..ad3f47a --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/SqlConnectOptions.kt @@ -0,0 +1,12 @@ +// TODO move to "kotlin-common" + +package com.huanshankeji.vertx.sqlclient + +import io.vertx.sqlclient.SqlConnectOptions + +/** + * Optimized for throughput. + */ +fun SqlConnectOptions.setUpConventionally() { + cachePreparedStatements = true +} diff --git a/integrated/build.gradle.kts b/integrated/build.gradle.kts index 6441b27..192f94b 100644 --- a/integrated/build.gradle.kts +++ b/integrated/build.gradle.kts @@ -10,8 +10,9 @@ dependencies { implementation(cpnProject(project, ":core")) - testImplementation("com.huanshankeji:exposed-adt-mapping:${DependencyVersions.exposedAdtMapping}") - testImplementation(cpnProject(project, ":sql-dsl-with-mapper")) + // for the examples + implementation("com.huanshankeji:exposed-adt-mapping:${DependencyVersions.exposedAdtMapping}") + implementation(cpnProject(project, ":sql-dsl-with-mapper")) } afterEvaluate { diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt index 275e326..51e21c7 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/WithContainerizedDatabaseBenchmark.kt @@ -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.postgresql.exposed.exposedDatabaseConnectPostgresql import kotlinx.benchmark.Scope import kotlinx.benchmark.Setup import kotlinx.benchmark.State @@ -16,9 +16,8 @@ class WithContainerizedDatabaseBenchmark : AbstractBenchmark() { lateinit var database: Database fun databaseConnect() = - exposedDatabaseConnectPostgreSql(with(postgreSQLContainer) { - ConnectionConfig.Socket(host, firstMappedPort, username, password, databaseName) - }) + with(postgreSQLContainer) { ConnectionConfig.Socket(host, firstMappedPort, username, password, databaseName) } + .exposedDatabaseConnectPostgresql() @Setup fun setUp() { diff --git a/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt similarity index 71% rename from integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt rename to integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index 6330e98..a87bb29 100644 --- a/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -1,13 +1,20 @@ +@file:OptIn(ExperimentalEvscApi::class) + package com.huanshankeji.exposedvertxsqlclient import com.huanshankeji.exposed.* -import com.huanshankeji.exposedvertxsqlclient.postgresql.createPgPoolDatabaseClient -import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgreSql +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.sql.* +import io.vertx.core.Verticle import io.vertx.core.Vertx +import io.vertx.sqlclient.SqlClient import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.jetbrains.exposed.dao.id.IntIdTable +import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq @@ -17,14 +24,24 @@ object Examples : IntIdTable("examples") { val tables = arrayOf(Examples) +val evscConfig = ConnectionConfig.Socket("localhost", user = "user", password = "password", database = "database") + .toUniversalEvscConfig() + +object Alternative { + // Unix domain socket alternative + val evscConfig = defaultPostgresqlLocalConnectionConfig( + user = "user", + socketConnectionPassword = "password", + database = "database" + ).toPerformantUnixEvscConfig() +} + @OptIn(ExperimentalEvscApi::class) suspend fun examples(vertx: Vertx) { - val socketConnectionConfig = - ConnectionConfig.Socket("localhost", user = "user", password = "password", database = "database") - val exposedDatabase = exposedDatabaseConnectPostgreSql(socketConnectionConfig) - val databaseClient = createPgPoolDatabaseClient( - vertx, socketConnectionConfig, exposedDatabase = exposedDatabase - ) + /** It may be more efficient to use a single shared [Database] to generate SQLs for multiple [DatabaseClient]s/[SqlClient]s in respective [Verticle]s. */ + val exposedDatabase = evscConfig.exposedConnectionConfig.exposedDatabaseConnectPostgresql() + val vertxPool = createPgPool(vertx, evscConfig.vertxSqlClientConnectionConfig) + val databaseClient = DatabaseClient(vertxPool, exposedDatabase) withContext(Dispatchers.IO) { databaseClient.exposedTransaction { diff --git a/integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt similarity index 100% rename from integrated/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt rename to integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt From 198ebf2584410eb5209c23985ee015263b0a2198 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 01:48:57 +0800 Subject: [PATCH 11/26] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a210fcb..b5ab998 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ val evscConfig = defaultPostgresqlLocalConnectionConfig( ).toPerformantUnixEvscConfig() ``` -Create an Exposed `Database` with the `ConnectionConfig`, which can be reused for multiple `Verticle`s: +Create an Exposed `Database` with the `ConnectionConfig.Socket`, which can be reused for multiple `Verticle`s: ```kotlin val exposedDatabase = evscConfig.exposedConnectionConfig.exposedDatabaseConnectPostgresql() From d4773cdedc70ca990dd243326ac22dab018e33e6 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 01:52:50 +0800 Subject: [PATCH 12/26] Remove the factory interfaces which are not needed any more with the current API design --- .../exposedvertxsqlclient/DatabaseClientFactory.kt | 12 ------------ .../exposed/ExposedDatabaseFactory.kt | 8 -------- .../vertx/sqlclient/VertxSqlClientFactory.kt | 8 -------- 3 files changed, 28 deletions(-) delete mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClientFactory.kt delete mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabaseFactory.kt delete mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/VertxSqlClientFactory.kt diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClientFactory.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClientFactory.kt deleted file mode 100644 index 289df4d..0000000 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClientFactory.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.huanshankeji.exposedvertxsqlclient - -import com.huanshankeji.exposedvertxsqlclient.exposed.ExposedDatabaseFactory -import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.VertxSqlClientFactory -import io.vertx.sqlclient.SqlClient - -// TODO remove, unnecessary abstraction as a user can just call the `DatabaseClient` constructor -@ExperimentalEvscApi -interface DatabaseClientFactory : - VertxSqlClientFactory, ExposedDatabaseFactory { - fun createDatabaseClient(): DatabaseClient -} \ No newline at end of file diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabaseFactory.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabaseFactory.kt deleted file mode 100644 index 21283b4..0000000 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabaseFactory.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.huanshankeji.exposedvertxsqlclient.exposed - -import org.jetbrains.exposed.sql.Database - -// TODO remove -interface ExposedDatabaseFactory { - fun databaseConnect(): Database -} \ No newline at end of file diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/VertxSqlClientFactory.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/VertxSqlClientFactory.kt deleted file mode 100644 index afefc14..0000000 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/VertxSqlClientFactory.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient - -import io.vertx.sqlclient.SqlClient - -// TODO remove -interface VertxSqlClientFactory { - fun buildSqlClient(): SqlClientT -} \ No newline at end of file From 496c3547a7e393e8632f2b1d0ce7853271568a5f Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 02:07:35 +0800 Subject: [PATCH 13/26] Remove default arguments in the `createGeneric...` functions because users usually don't call them directly and by doing this we don't forget to pass arguments in a caller --- .../postgresql/vertx/pgclient/PgClients.kt | 6 +++--- .../vertx/sqlclient/SqlClients.kt | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt index 0bad400..6a03574 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt @@ -28,9 +28,9 @@ fun > createG vertx: Vertx?, connectionConfig: ConnectionConfig, clientBuilder: ClientBuilderT, - extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, - extraPgPoolOptions: PgPoolOptions.() -> Unit = {}, - connectHandlerExtra: ConnectHandlerExtra = null + extraPgConnectOptions: PgConnectOptions.() -> Unit, + extraPgPoolOptions: PgPoolOptions.() -> Unit, + connectHandlerExtra: ConnectHandlerExtra ): SqlClientT = createGenericSqlClientWithBuilder( vertx, diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt index d98f044..a7a2992 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt @@ -19,10 +19,10 @@ inline fun Unit = {}, + extraSqlConnectOptions: SqlConnectOptionsT.() -> Unit, poolOptionsFromConstructor: PoolOptionsT, - extraPoolOptions: PoolOptionsT.() -> Unit = {}, - noinline connectHandlerExtra: ConnectHandlerExtra = null, + extraPoolOptions: PoolOptionsT.() -> Unit, + noinline connectHandlerExtra: ConnectHandlerExtra, create: (Vertx?, SqlConnectOptionsT, PoolOptionsT, ConnectHandlerExtra) -> SqlClientT ): SqlClientT { val sqlConnectOptions = sqlConnectOptionsFromConstructor.apply { @@ -44,9 +44,9 @@ fun Unit = {}, - extraPoolOptions: PoolOptionsT.() -> Unit = {}, - connectHandlerExtra: ConnectHandlerExtra = null, + extraSqlConnectOptions: SqlConnectOptionsT.() -> Unit, + extraPoolOptions: PoolOptionsT.() -> Unit, + connectHandlerExtra: ConnectHandlerExtra, poolOptionsFromConstructor: PoolOptionsT ): SqlClientT = @Suppress("NAME_SHADOWING") @@ -78,8 +78,8 @@ suspend fun Future, sqlConnectOptionsFromConstructor: SqlConnectOptionsT, - extraSqlConnectOptions: SqlConnectOptionsT.() -> Unit = {}, - connectHandlerExtra: ConnectHandlerExtra = null + extraSqlConnectOptions: SqlConnectOptionsT.() -> Unit, + connectHandlerExtra: ConnectHandlerExtra ): SqlConnectionT = @Suppress("NAME_SHADOWING") createGenericSqlClient( From 82b23fa12836e3f543809592e6029e1407b1d3b0 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 02:18:43 +0800 Subject: [PATCH 14/26] Extract a `withCoConnectHandle` extension function --- .../postgresql/vertx/pgclient/PgClients.kt | 10 +++--- .../vertx/sqlclient/SqlClients.kt | 13 ++++---- .../sqlclient/SqlConnectionInitialization.kt | 33 +++++-------------- .../vertx/sqlclient/ClientBuilder.kt | 24 ++++++++++++++ 4 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt index 6a03574..21542cd 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt @@ -5,7 +5,7 @@ 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.ConnectHandlerExtra +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 @@ -30,7 +30,7 @@ fun > createG clientBuilder: ClientBuilderT, extraPgConnectOptions: PgConnectOptions.() -> Unit, extraPgPoolOptions: PgPoolOptions.() -> Unit, - connectHandlerExtra: ConnectHandlerExtra + connectHandlerExtra: CoConnectHandler ): SqlClientT = createGenericSqlClientWithBuilder( vertx, @@ -48,7 +48,7 @@ fun createPgClient( connectionConfig: ConnectionConfig, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPoolOptions: PgPoolOptions.() -> Unit = {}, - connectHandlerExtra: ConnectHandlerExtra = null, + connectHandlerExtra: CoConnectHandler = null, ): SqlClient = createGenericPgClientWithBuilder( vertx, @@ -69,7 +69,7 @@ fun createPgPool( connectionConfig: ConnectionConfig, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, extraPoolOptions: PgPoolOptions.() -> Unit = {}, - connectHandlerExtra: ConnectHandlerExtra = null, + connectHandlerExtra: CoConnectHandler = null, ): Pool = createGenericPgClientWithBuilder( vertx, @@ -91,7 +91,7 @@ suspend fun createPgConnection( vertx: Vertx?, connectionConfig: ConnectionConfig, extraPgConnectOptions: PgConnectOptions.() -> Unit = {}, - connectHandlerExtra: ConnectHandlerExtra = null + connectHandlerExtra: CoConnectHandler = null ): PgConnection = createGenericSqlConnection( vertx, diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt index a7a2992..2e79cb5 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClients.kt @@ -3,6 +3,7 @@ package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi import com.huanshankeji.vertx.sqlclient.setUpConventionally +import com.huanshankeji.vertx.sqlclient.withCoConnectHandler import io.vertx.core.Future import io.vertx.core.Vertx import io.vertx.kotlin.coroutines.coAwait @@ -22,8 +23,8 @@ inline fun Unit, poolOptionsFromConstructor: PoolOptionsT, extraPoolOptions: PoolOptionsT.() -> Unit, - noinline connectHandlerExtra: ConnectHandlerExtra, - create: (Vertx?, SqlConnectOptionsT, PoolOptionsT, ConnectHandlerExtra) -> SqlClientT + noinline connectHandlerExtra: CoConnectHandler, + create: (Vertx?, SqlConnectOptionsT, PoolOptionsT, CoConnectHandler) -> SqlClientT ): SqlClientT { val sqlConnectOptions = sqlConnectOptionsFromConstructor.apply { setUpConventionally() @@ -46,7 +47,7 @@ fun Unit, extraPoolOptions: PoolOptionsT.() -> Unit, - connectHandlerExtra: ConnectHandlerExtra, + connectHandlerExtra: CoConnectHandler, poolOptionsFromConstructor: PoolOptionsT ): SqlClientT = @Suppress("NAME_SHADOWING") @@ -63,8 +64,8 @@ fun Future, sqlConnectOptionsFromConstructor: SqlConnectOptionsT, extraSqlConnectOptions: SqlConnectOptionsT.() -> Unit, - connectHandlerExtra: ConnectHandlerExtra + connectHandlerExtra: CoConnectHandler ): SqlConnectionT = @Suppress("NAME_SHADOWING") createGenericSqlClient( diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt index 3f82d0c..ca7c0f1 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt @@ -1,24 +1,18 @@ package com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig -import io.vertx.core.Handler -import io.vertx.kotlin.coroutines.coAwait -import io.vertx.sqlclient.Pool import io.vertx.sqlclient.SqlConnection -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch /** * Extra initialization on [SqlConnection] in addition to [setRole] for [ConnectionConfig.UnixDomainSocketWithPeerAuthentication]. */ -typealias ConnectHandlerExtra = (suspend (SqlConnection) -> Unit)? -typealias ExtensionConnectHandlerExtra = (suspend SqlConnection.() -> Unit)? +typealias CoConnectHandler = (suspend (SqlConnection) -> Unit)? +typealias ExtensionCoConnectHandler = (suspend SqlConnection.() -> Unit)? -fun ExtensionConnectHandlerExtra.toWithParameterFunction(): ConnectHandlerExtra = +fun ExtensionCoConnectHandler.toWithParameterFunction(): CoConnectHandler = this -suspend fun ConnectionConfig.initConnection(sqlConnection: SqlConnection, extra: ConnectHandlerExtra) { +suspend fun ConnectionConfig.initConnection(sqlConnection: SqlConnection, extra: CoConnectHandler) { when (this) { is ConnectionConfig.Socket -> Unit // do nothing is ConnectionConfig.UnixDomainSocketWithPeerAuthentication -> sqlConnection.setRole(role) @@ -26,25 +20,14 @@ suspend fun ConnectionConfig.initConnection(sqlConnection: SqlConnection, extra: extra?.let { it(sqlConnection) } } -fun ConnectionConfig.getConnectHandler(extra: ConnectHandlerExtra): Handler? = +fun ConnectionConfig.getCoConnectHandler(extra: CoConnectHandler): CoConnectHandler = when (this) { - is ConnectionConfig.Socket -> extra?.let { - // TODO extract a common `coConnectHandler` - Handler { - CoroutineScope(Dispatchers.Unconfined).launch { - it(it) - it.close().coAwait() - } - } - } - - is ConnectionConfig.UnixDomainSocketWithPeerAuthentication -> Handler { - CoroutineScope(Dispatchers.Unconfined).launch { + is ConnectionConfig.Socket -> extra + is ConnectionConfig.UnixDomainSocketWithPeerAuthentication -> { + { // TODO: are exceptions handled? it.setRole(role) extra?.let { extra -> extra(it) } - /** @see Pool.connectHandler */ - it.close().coAwait() } } } diff --git a/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt b/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt new file mode 100644 index 0000000..ab6bf7e --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt @@ -0,0 +1,24 @@ +// TODO move to "kotlin-common" + +package com.huanshankeji.vertx.sqlclient + +import io.vertx.kotlin.coroutines.coAwait +import io.vertx.sqlclient.ClientBuilder +import io.vertx.sqlclient.Pool +import io.vertx.sqlclient.SqlConnection +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +/** + * A coroutine variant of [ClientBuilder.withConnectHandler]. + * You don't need to call [SqlConnection.close] in [handler]. + */ +fun ClientBuilder<*>.withCoConnectHandler(handler: suspend (SqlConnection) -> Unit) = + withConnectHandler { + CoroutineScope(Dispatchers.Unconfined).launch { + handler(it) + /** @see Pool.connectHandler */ + it.close().coAwait() + } + } From cecd5be2e26bb6ca5c2b1ade2362fd2deeb844c9 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 02:24:09 +0800 Subject: [PATCH 15/26] Move a TODO --- .../vertx/sqlclient/SqlConnectionInitialization.kt | 1 - .../kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt index ca7c0f1..c228c6a 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitialization.kt @@ -25,7 +25,6 @@ fun ConnectionConfig.getCoConnectHandler(extra: CoConnectHandler): CoConnectHand is ConnectionConfig.Socket -> extra is ConnectionConfig.UnixDomainSocketWithPeerAuthentication -> { { - // TODO: are exceptions handled? it.setRole(role) extra?.let { extra -> extra(it) } } diff --git a/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt b/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt index ab6bf7e..ef3c8fc 100644 --- a/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt +++ b/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.launch fun ClientBuilder<*>.withCoConnectHandler(handler: suspend (SqlConnection) -> Unit) = withConnectHandler { CoroutineScope(Dispatchers.Unconfined).launch { + // TODO What happens when there are exceptions in `handler`? Are they correctly propagated? handler(it) /** @see Pool.connectHandler */ it.close().coAwait() From d0e1f3ee518a80be7a93230244c59955b4134860 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 02:26:24 +0800 Subject: [PATCH 16/26] Add a "sql-dsl" module --- settings.gradle.kts | 1 + sql-dsl/build.gradle.kts | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 sql-dsl/build.gradle.kts diff --git a/settings.gradle.kts b/settings.gradle.kts index e5c9abd..3b86ea5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,7 @@ rootProject.name = "exposed-vertx-sql-client" include("core") +include("sql-dsl") include("sql-dsl-with-mapper") include("postgresql") include("integrated") diff --git a/sql-dsl/build.gradle.kts b/sql-dsl/build.gradle.kts new file mode 100644 index 0000000..c83f97f --- /dev/null +++ b/sql-dsl/build.gradle.kts @@ -0,0 +1,10 @@ +import com.huanshankeji.cpnProject + +plugins { + `lib-conventions` +} + +dependencies { + with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed + implementation(cpnProject(project, ":core")) +} From ef6d3d1f581da697030e4f8c9ce2d8a40a6034c1 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 02:35:04 +0800 Subject: [PATCH 17/26] Move some code to https://github.com/huanshankeji/kotlin-common The corresponding commit: https://github.com/huanshankeji/kotlin-common/commit/1b93c185e51b4cdb3368d2813484f62022e518d9 --- .../kotlin/com/huanshankeji/jdbc/JdbcUrls.kt | 6 ----- .../vertx/pgclient/PgPoolOptions.kt | 12 --------- .../vertx/sqlclient/ClientBuilder.kt | 25 ------------------- .../vertx/sqlclient/SqlConnectOptions.kt | 12 --------- 4 files changed, 55 deletions(-) delete mode 100644 core/src/main/kotlin/com/huanshankeji/jdbc/JdbcUrls.kt delete mode 100644 core/src/main/kotlin/com/huanshankeji/vertx/pgclient/PgPoolOptions.kt delete mode 100644 core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt delete mode 100644 core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/SqlConnectOptions.kt diff --git a/core/src/main/kotlin/com/huanshankeji/jdbc/JdbcUrls.kt b/core/src/main/kotlin/com/huanshankeji/jdbc/JdbcUrls.kt deleted file mode 100644 index 4b938e0..0000000 --- a/core/src/main/kotlin/com/huanshankeji/jdbc/JdbcUrls.kt +++ /dev/null @@ -1,6 +0,0 @@ -// TODO move to "kotlin-common" - -package com.huanshankeji.jdbc - -fun jdbcUrl(rdbms: String, host: String, port: Int?, database: String) = - "jdbc:$rdbms://$host${port?.let { ":$it" } ?: ""}/$database" diff --git a/core/src/main/kotlin/com/huanshankeji/vertx/pgclient/PgPoolOptions.kt b/core/src/main/kotlin/com/huanshankeji/vertx/pgclient/PgPoolOptions.kt deleted file mode 100644 index a3c5a10..0000000 --- a/core/src/main/kotlin/com/huanshankeji/vertx/pgclient/PgPoolOptions.kt +++ /dev/null @@ -1,12 +0,0 @@ -// TODO move to "kotlin-common" - -package com.huanshankeji.vertx.pgclient - -import io.vertx.pgclient.impl.PgPoolOptions - -/** - * Optimized for throughput. - */ -fun PgPoolOptions.setUpConventionally() { - isPipelined = true -} diff --git a/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt b/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt deleted file mode 100644 index ef3c8fc..0000000 --- a/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/ClientBuilder.kt +++ /dev/null @@ -1,25 +0,0 @@ -// TODO move to "kotlin-common" - -package com.huanshankeji.vertx.sqlclient - -import io.vertx.kotlin.coroutines.coAwait -import io.vertx.sqlclient.ClientBuilder -import io.vertx.sqlclient.Pool -import io.vertx.sqlclient.SqlConnection -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch - -/** - * A coroutine variant of [ClientBuilder.withConnectHandler]. - * You don't need to call [SqlConnection.close] in [handler]. - */ -fun ClientBuilder<*>.withCoConnectHandler(handler: suspend (SqlConnection) -> Unit) = - withConnectHandler { - CoroutineScope(Dispatchers.Unconfined).launch { - // TODO What happens when there are exceptions in `handler`? Are they correctly propagated? - handler(it) - /** @see Pool.connectHandler */ - it.close().coAwait() - } - } diff --git a/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/SqlConnectOptions.kt b/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/SqlConnectOptions.kt deleted file mode 100644 index ad3f47a..0000000 --- a/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/SqlConnectOptions.kt +++ /dev/null @@ -1,12 +0,0 @@ -// TODO move to "kotlin-common" - -package com.huanshankeji.vertx.sqlclient - -import io.vertx.sqlclient.SqlConnectOptions - -/** - * Optimized for throughput. - */ -fun SqlConnectOptions.setUpConventionally() { - cachePreparedStatements = true -} From daf69d759ad512cc427c89a2c0260136034c18ef Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 02:39:42 +0800 Subject: [PATCH 18/26] Resolve a build issue in the `benchmarks` source set of the "integrated" module ```text Execution failed for task ':exposed-vertx-sql-client-integrated:compileBenchmarksKotlin'. > Could not resolve all files for configuration ':exposed-vertx-sql-client-integrated:benchmarksCompileClasspath'. > Could not resolve all dependencies for configuration ':exposed-vertx-sql-client-integrated:benchmarksCompileClasspath'. > Could not find io.vertx:vertx-sql-client:. Required by: project :exposed-vertx-sql-client-integrated > project :exposed-vertx-sql-client-core ``` --- integrated/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/integrated/build.gradle.kts b/integrated/build.gradle.kts index 192f94b..0c7ada2 100644 --- a/integrated/build.gradle.kts +++ b/integrated/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { afterEvaluate { // for the benchmarks dependencies { + with(commonDependencies.vertx) { "benchmarksImplementation"(platformStackDepchain()) } // needed // The benchmarks run and "check" passes but the code doesn't resolve without this dependency TODO remove if not needed one day "benchmarksImplementation"(cpnProject(project, ":core")) "benchmarksImplementation"(cpnProject(project, ":postgresql")) From 2d7b2a575b1e7ba8ab0bc157a49e35f34ca5cc07 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 03:09:05 +0800 Subject: [PATCH 19/26] Move all the code in the package `postgresql` into the "postgresql" module --- integrated/build.gradle.kts | 4 ++-- postgresql/build.gradle.kts | 2 ++ .../exposedvertxsqlclient/postgresql/DatabaseClient.kt | 0 .../postgresql/exposed/ExposedDatabases.kt | 0 .../postgresql/local/LocalConnectionConfig.kt | 0 .../postgresql/vertx/pgclient/PgClients.kt | 0 6 files changed, 4 insertions(+), 2 deletions(-) rename {core => postgresql}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt (100%) rename {core => postgresql}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt (100%) rename {core => postgresql}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/local/LocalConnectionConfig.kt (100%) rename {core => postgresql}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt (100%) diff --git a/integrated/build.gradle.kts b/integrated/build.gradle.kts index 0c7ada2..9362b8b 100644 --- a/integrated/build.gradle.kts +++ b/integrated/build.gradle.kts @@ -9,8 +9,8 @@ dependencies { with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed implementation(cpnProject(project, ":core")) - - // for the examples + implementation(cpnProject(project, ":postgresql")) + implementation(cpnProject(project, ":sql-dsl")) implementation("com.huanshankeji:exposed-adt-mapping:${DependencyVersions.exposedAdtMapping}") implementation(cpnProject(project, ":sql-dsl-with-mapper")) } diff --git a/postgresql/build.gradle.kts b/postgresql/build.gradle.kts index f23dd0d..0321367 100644 --- a/postgresql/build.gradle.kts +++ b/postgresql/build.gradle.kts @@ -10,4 +10,6 @@ dependencies { runtimeOnly(commonDependencies.postgreSql()) implementation(commonDependencies.vertx.moduleWithoutVersion("pg-client")) + implementation(commonDependencies.kotlinCommon.core()) // for `Untested` + implementation(commonDependencies.kotlinCommon.vertx()) // for `PgPoolOptions.setUpConventionally` } diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt b/postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt similarity index 100% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt rename to postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/DatabaseClient.kt diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt b/postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt similarity index 100% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt rename to postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/exposed/ExposedDatabases.kt diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/local/LocalConnectionConfig.kt b/postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/local/LocalConnectionConfig.kt similarity index 100% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/local/LocalConnectionConfig.kt rename to postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/local/LocalConnectionConfig.kt diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt b/postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt similarity index 100% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt rename to postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt From 59a26a6ccb1071f32057e53d2f22802f204b8c14 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 04:08:08 +0800 Subject: [PATCH 20/26] Move the code that belongs to the modules "sql-dsl" and "sql-dsl-with-mapper" into these modules Miscellaneous changes: 1. remove the PostgreSQL dependencies in the "core" module 1. add and use the `@InternalApi` opt-in annotation 1. update `executeExpression` to throw since the core module doesn't depend on the "sql-dsl" module anymore 1. add an example of `DatabaseClient.selectExpression` with `exists` in the example code --- README.md | 2 ++ .../src/main/kotlin/lib-conventions.gradle.kts | 5 +++++ core/build.gradle.kts | 8 -------- .../exposedvertxsqlclient/DatabaseClient.kt | 16 +++++++--------- .../exposedvertxsqlclient/InternalApi.kt | 5 +++++ .../exposedvertxsqlclient/Examples.kt | 4 ++++ sql-dsl-with-mapper/build.gradle.kts | 3 +++ .../classpropertymapping/ClassPropertyMapping.kt | 8 +++++--- .../sql/mapping/DatabaseClientSqlWithMapper.kt | 0 .../sqlclient/datamapping/RowDataQueryMapper.kt | 0 sql-dsl/build.gradle.kts | 2 ++ .../sql/DatabaseClientSql.kt | 0 12 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt rename {core => sql-dsl-with-mapper}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt (73%) rename {core => sql-dsl-with-mapper}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt (100%) rename {core => sql-dsl-with-mapper}/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt (100%) rename {core => sql-dsl}/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt (100%) diff --git a/README.md b/README.md index b5ab998..479b0cf 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,8 @@ val exampleName1 = val exampleName2 = databaseClient.selectSingleColumn(Examples, Examples.name) { where(Examples.id eq 2) }.single() +val examplesExist = databaseClient.selectExpression(exists(Examples.selectAll())) + val deleteRowCount1 = databaseClient.deleteWhere(Examples) { id eq 1 } assert(deleteRowCount1 == 1) val deleteRowCount2 = databaseClient.deleteIgnoreWhere(Examples) { id eq 2 } diff --git a/buildSrc/src/main/kotlin/lib-conventions.gradle.kts b/buildSrc/src/main/kotlin/lib-conventions.gradle.kts index e679e3d..30d8936 100644 --- a/buildSrc/src/main/kotlin/lib-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/lib-conventions.gradle.kts @@ -1,5 +1,6 @@ import com.huanshankeji.team.`Shreck Ye` import com.huanshankeji.team.pomForTeamDefaultOpenSource +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask plugins { id("conventions") @@ -13,3 +14,7 @@ publishing.publications.getByName("maven") { `Shreck Ye`() } } + +tasks.named>("compileKotlin").configure { + compilerOptions.freeCompilerArgs.add("-opt-in=com.huanshankeji.exposedvertxsqlclient.InternalApi") +} diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 1cb9160..eb0ab79 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -7,7 +7,6 @@ dependencies { // TODO: remove the Exposed JDBC dependency and the PostgresSQL dependency when there is no need to to generate SQLs with an Exposed transaction runtimeOnly(commonDependencies.exposed.module("jdbc")) api(commonDependencies.kotlinCommon.exposed()) - implementation("com.huanshankeji:exposed-adt-mapping:${DependencyVersions.exposedAdtMapping}") // TODO remove when code is moved out with(commonDependencies.vertx) { implementation(platformStackDepchain()) @@ -22,10 +21,3 @@ dependencies { implementation(commonDependencies.kotlinCommon.net()) } - -// TODO remove when code is moved out -// for PostgreSQL -dependencies { - runtimeOnly(commonDependencies.postgreSql()) - implementation(commonDependencies.vertx.moduleWithoutVersion("pg-client")) -} diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index 2fdb279..1a55352 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -2,12 +2,10 @@ package com.huanshankeji.exposedvertxsqlclient import arrow.core.* import com.huanshankeji.collections.singleOrNullIfEmpty -import com.huanshankeji.exposedvertxsqlclient.sql.selectExpression import com.huanshankeji.vertx.kotlin.coroutines.coroutineToFuture import com.huanshankeji.vertx.kotlin.sqlclient.executeBatchAwaitForSqlResultSequence import io.vertx.core.buffer.Buffer import io.vertx.kotlin.coroutines.coAwait -import io.vertx.pgclient.PgConnectOptions import io.vertx.sqlclient.* import kotlinx.coroutines.coroutineScope import org.jetbrains.exposed.dao.id.EntityID @@ -65,8 +63,8 @@ fun String.toVertxPgClientPreparedSql(): String { fun Statement<*>.getVertxPgClientPreparedSql(transaction: ExposedTransaction) = prepareSQL(transaction).toVertxPgClientPreparedSql() - -internal fun dbAssert(b: Boolean) { +@InternalApi +fun dbAssert(b: Boolean) { if (!b) throw AssertionError() } @@ -103,7 +101,7 @@ class DatabaseClient( } suspend fun executePlainSql(sql: String): RowSet = - /** Use [SqlClient.preparedQuery] here because of [PgConnectOptions.setCachePreparedStatements]. */ + /** Use [SqlClient.preparedQuery] here because of [SqlConnectOptions.setCachePreparedStatements]. */ vertxSqlClient.preparedQuery(sql).execute().coAwait() suspend fun executePlainSqlUpdate(sql: String): Int = @@ -211,20 +209,20 @@ class DatabaseClient( @Deprecated( - "Use `selectExpression` instead`", + "Use `selectExpression` in the \"sql-dsl\" module instead.", ReplaceWith( "selectExpression(clazz, expression)", "com.huanshankeji.exposedvertxsqlclient.sql.selectExpression" ) ) suspend fun executeExpression(clazz: KClass, expression: Expression): T? = - selectExpression(clazz, expression) + throw NotImplementedError() @Deprecated( - "Use `selectExpression` instead`", + "Use `selectExpression` in the \"sql-dsl\" module instead.", ReplaceWith("selectExpression(expression)", "com.huanshankeji.exposedvertxsqlclient.sql.selectExpression") ) suspend inline fun executeExpression(expression: Expression): T = - selectExpression(expression) + throw NotImplementedError() suspend fun isWorking(): Boolean = try { diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt new file mode 100644 index 0000000..62a302c --- /dev/null +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt @@ -0,0 +1,5 @@ +package com.huanshankeji.exposedvertxsqlclient + +@RequiresOptIn("This API is internal in the Exposed Vert.x SQL Client library.") +@Retention(AnnotationRetention.BINARY) +annotation class InternalApi \ No newline at end of file diff --git a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index a87bb29..5e3b590 100644 --- a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -17,6 +17,8 @@ import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.exists +import org.jetbrains.exposed.sql.selectAll object Examples : IntIdTable("examples") { val name = varchar("name", 64) @@ -84,6 +86,8 @@ suspend fun examples(vertx: Vertx) { val exampleName2 = databaseClient.selectSingleColumn(Examples, Examples.name) { where(Examples.id eq 2) }.single() + val examplesExist = databaseClient.selectExpression(exists(Examples.selectAll())) + val deleteRowCount1 = databaseClient.deleteWhere(Examples) { id eq 1 } assert(deleteRowCount1 == 1) val deleteRowCount2 = databaseClient.deleteIgnoreWhere(Examples) { id eq 2 } diff --git a/sql-dsl-with-mapper/build.gradle.kts b/sql-dsl-with-mapper/build.gradle.kts index c83f97f..92d9e90 100644 --- a/sql-dsl-with-mapper/build.gradle.kts +++ b/sql-dsl-with-mapper/build.gradle.kts @@ -7,4 +7,7 @@ plugins { dependencies { with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed implementation(cpnProject(project, ":core")) + implementation(cpnProject(project, ":sql-dsl")) + + implementation("com.huanshankeji:exposed-adt-mapping:${DependencyVersions.exposedAdtMapping}") // for `updateBuilderSetter`, `DataQueryMapper` and `DataUpdateMapper` } diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt b/sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt similarity index 73% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt rename to sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt index 784ede4..64b4d63 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt +++ b/sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ClassPropertyMapping.kt @@ -6,18 +6,20 @@ import com.huanshankeji.vertx.sqlclient.datamapping.RowDataQueryMapper import io.vertx.sqlclient.Row import kotlin.reflect.KClass +// TODO all definitions are made private because they are not complete yet + /** * @see ClassPropertyColumnMappings */ // since Kotlin 2.0.0: "'Nothing' property type can't be specified with type alias." -typealias ClassPropertyColumnIndexMappings = Unit // TODO +private typealias ClassPropertyColumnIndexMappings = Unit // TODO -typealias VertxSqlClientRowDataQueryMapper = RowDataQueryMapper +private typealias VertxSqlClientRowDataQueryMapper = RowDataQueryMapper /** * @see ReflectionBasedClassPropertyDataMapper */ -class ReflectionBasedClassPropertyIndexVertxSqlClientRowDataQueryMapper( +private class ReflectionBasedClassPropertyIndexVertxSqlClientRowDataQueryMapper( val clazz: KClass, val classPropertyColumnIndexMappings: ClassPropertyColumnIndexMappings ) : RowDataQueryMapper { diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt b/sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt similarity index 100% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt rename to sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt diff --git a/core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt b/sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt similarity index 100% rename from core/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt rename to sql-dsl-with-mapper/src/main/kotlin/com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper.kt diff --git a/sql-dsl/build.gradle.kts b/sql-dsl/build.gradle.kts index c83f97f..febf3bb 100644 --- a/sql-dsl/build.gradle.kts +++ b/sql-dsl/build.gradle.kts @@ -7,4 +7,6 @@ plugins { dependencies { with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed implementation(cpnProject(project, ":core")) + + compileOnly(commonDependencies.kotlinCommon.vertx()) // for `sortDataAndExecuteBatch` } diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt b/sql-dsl/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt similarity index 100% rename from core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt rename to sql-dsl/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt From 6eb83a7bfbedc60f16ff9acaf1c3b7b8463d7858 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 04:13:17 +0800 Subject: [PATCH 21/26] Run `apiDump` and ensure that `check` is successful --- core/api/exposed-vertx-sql-client-core.api | 158 ++++++------------ .../exposed-vertx-sql-client-integrated.api | 62 +++++++ .../exposed-vertx-sql-client-postgresql.api | 27 +++ ...d-vertx-sql-client-sql-dsl-with-mapper.api | 17 ++ .../api/exposed-vertx-sql-client-sql-dsl.api | 35 ++++ 5 files changed, 193 insertions(+), 106 deletions(-) create mode 100644 sql-dsl/api/exposed-vertx-sql-client-sql-dsl.api diff --git a/core/api/exposed-vertx-sql-client-core.api b/core/api/exposed-vertx-sql-client-core.api index ee71443..081ca0f 100644 --- a/core/api/exposed-vertx-sql-client-core.api +++ b/core/api/exposed-vertx-sql-client-core.api @@ -22,6 +22,10 @@ public final class com/huanshankeji/exposedvertxsqlclient/ConnectionConfig$UnixD public fun getUserAndRole ()Ljava/lang/String; } +public final class com/huanshankeji/exposedvertxsqlclient/ConnectionConfigKt { + public static final fun toUniversalEvscConfig (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;)Lcom/huanshankeji/exposedvertxsqlclient/EvscConfig; +} + public final class com/huanshankeji/exposedvertxsqlclient/ConnectionType : java/lang/Enum { public static final field Socket Lcom/huanshankeji/exposedvertxsqlclient/ConnectionType; public static final field UnixDomainSocketWithPeerAuthentication Lcom/huanshankeji/exposedvertxsqlclient/ConnectionType; @@ -65,14 +69,7 @@ public final class com/huanshankeji/exposedvertxsqlclient/DatabaseClient { } public final class com/huanshankeji/exposedvertxsqlclient/DatabaseClientKt { - public static final fun createBetterPgPoolDatabaseClient (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lorg/jetbrains/exposed/sql/Database;)Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient; - public static synthetic fun createBetterPgPoolDatabaseClient$default (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lorg/jetbrains/exposed/sql/Database;ILjava/lang/Object;)Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient; - public static final fun createPgPoolDatabaseClient (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;)Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient; - public static final fun createPgPoolDatabaseClient (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lorg/jetbrains/exposed/sql/Database;)Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient; - public static final fun createPgPoolDatabaseClient (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionType;Lcom/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lorg/jetbrains/exposed/sql/Database;)Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient; - public static synthetic fun createPgPoolDatabaseClient$default (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;ILjava/lang/Object;)Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient; - public static synthetic fun createPgPoolDatabaseClient$default (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lorg/jetbrains/exposed/sql/Database;ILjava/lang/Object;)Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient; - public static synthetic fun createPgPoolDatabaseClient$default (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionType;Lcom/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lorg/jetbrains/exposed/sql/Database;ILjava/lang/Object;)Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient; + public static final fun dbAssert (Z)V public static final fun getFieldExpressionSet (Lorg/jetbrains/exposed/sql/FieldSet;)Ljava/util/Set; public static final fun getFieldExpressionSet (Lorg/jetbrains/exposed/sql/Query;)Ljava/util/Set; public static final fun getSavepointNameRegex ()Lkotlin/text/Regex; @@ -87,13 +84,13 @@ public final class com/huanshankeji/exposedvertxsqlclient/DatabaseClientKt { public static final fun toVertxPgClientPreparedSql (Ljava/lang/String;)Ljava/lang/String; public static final fun toVertxTuple (Ljava/lang/Iterable;)Lio/vertx/sqlclient/Tuple; public static final fun types (Ljava/lang/Iterable;)Ljava/util/List; - public static final fun withPgTransaction (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun withSavepointAndRollbackIfThrows (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun withSavepointAndRollbackIfThrowsOrFalse (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun withSavepointAndRollbackIfThrowsOrLeft (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun withSavepointAndRollbackIfThrowsOrNone (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun withTransaction (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun withTransactionCommitOrRollback (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun withTypedTransaction (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } public final class com/huanshankeji/exposedvertxsqlclient/EvscConfig : com/huanshankeji/exposedvertxsqlclient/IEvscConfig { @@ -105,121 +102,70 @@ public final class com/huanshankeji/exposedvertxsqlclient/EvscConfig : com/huans public abstract interface annotation class com/huanshankeji/exposedvertxsqlclient/ExperimentalEvscApi : java/lang/annotation/Annotation { } -public final class com/huanshankeji/exposedvertxsqlclient/ExposedDatabasesKt { - public static final fun exposedDatabaseConnectPostgreSql (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;)Lorg/jetbrains/exposed/sql/Database; -} - public abstract interface class com/huanshankeji/exposedvertxsqlclient/IEvscConfig { public abstract fun getExposedConnectionConfig ()Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket; public abstract fun getVertxSqlClientConnectionConfig ()Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig; } -public final class com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig { - public static final field Companion Lcom/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig$Companion; +public abstract interface annotation class com/huanshankeji/exposedvertxsqlclient/InternalApi : java/lang/annotation/Annotation { +} + +public final class com/huanshankeji/exposedvertxsqlclient/SingleUpdateException : java/lang/Exception { + public fun (I)V +} + +public final class com/huanshankeji/exposedvertxsqlclient/exposed/ExposedDatabasesKt { + public static final fun exposedDatabaseConnect (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/exposed/sql/DatabaseConfig;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/exposed/sql/Database; + public static final fun exposedDatabaseConnect (Ljava/lang/String;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/exposed/sql/DatabaseConfig;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/exposed/sql/Database; + public static synthetic fun exposedDatabaseConnect$default (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/exposed/sql/DatabaseConfig;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/exposed/sql/Database; + public static synthetic fun exposedDatabaseConnect$default (Ljava/lang/String;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;Ljava/lang/String;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/jdbc/JdbcUrlsKt { + public static final fun jdbcUrl (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;Ljava/lang/String;)Ljava/lang/String; +} + +public final class com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig { + public static final field Companion Lcom/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig$Companion; public static final field SOCKET_HOST Ljava/lang/String; - public static final field UNIX_DOMAIN_SOCKET_PATH Ljava/lang/String; - public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public fun (Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public synthetic fun (Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun getDatabase ()Ljava/lang/String; public final fun getSocketConnectionConfig ()Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket; public final fun getSocketConnectionPassword ()Ljava/lang/String; + public final fun getSocketConnectionPort ()Ljava/lang/Integer; + public final fun getUnixDomainSocketPath ()Ljava/lang/String; public final fun getUnixDomainSocketWithPeerAuthenticationConnectionConfig ()Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$UnixDomainSocketWithPeerAuthentication; public final fun getUser ()Ljava/lang/String; } -public final class com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig$Companion { +public final class com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig$Companion { } -public final class com/huanshankeji/exposedvertxsqlclient/LocalConnectionConfigKt { - public static final fun toPerformantUnixEvscConfig (Lcom/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig;)Lcom/huanshankeji/exposedvertxsqlclient/EvscConfig; - public static final fun toUniversalEvscConfig (Lcom/huanshankeji/exposedvertxsqlclient/LocalConnectionConfig;)Lcom/huanshankeji/exposedvertxsqlclient/EvscConfig; +public final class com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfigKt { + public static final fun toPerformantUnixEvscConfig (Lcom/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig;)Lcom/huanshankeji/exposedvertxsqlclient/EvscConfig; + public static final fun toUniversalEvscConfig (Lcom/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig;)Lcom/huanshankeji/exposedvertxsqlclient/EvscConfig; } -public final class com/huanshankeji/exposedvertxsqlclient/SingleUpdateException : java/lang/Exception { - public fun (I)V +public final class com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlClientsKt { + public static final fun createGenericSqlClient (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lio/vertx/sqlclient/SqlConnectOptions;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function4;)Lio/vertx/sqlclient/SqlClient; + public static final fun createGenericSqlClientWithBuilder (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lio/vertx/sqlclient/ClientBuilder;Lio/vertx/sqlclient/SqlConnectOptions;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lio/vertx/sqlclient/PoolOptions;)Lio/vertx/sqlclient/SqlClient; + public static final fun createGenericSqlConnection (Lio/vertx/core/Vertx;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function2;Lio/vertx/sqlclient/SqlConnectOptions;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + +public final class com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectOptionsKt { + public static final fun setFrom (Lio/vertx/sqlclient/SqlConnectOptions;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;)V + public static final fun setFrom (Lio/vertx/sqlclient/SqlConnectOptions;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$UnixDomainSocketWithPeerAuthentication;)V + public static final fun setFrom (Lio/vertx/sqlclient/SqlConnectOptions;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;)V +} + +public final class com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionInitializationKt { + public static final fun getCoConnectHandler (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; + public static final fun initConnection (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;Lio/vertx/sqlclient/SqlConnection;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun toWithParameterFunction (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; } -public final class com/huanshankeji/exposedvertxsqlclient/VertxSqlClientsKt { - public static final fun createPeerAuthenticationUnixDomainSocketGenericPgClient (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lkotlin/jvm/functions/Function3;)Ljava/lang/Object; - public static synthetic fun createPeerAuthenticationUnixDomainSocketGenericPgClient$default (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun createPeerAuthenticationUnixDomainSocketPgConnectionAndSetRole (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun createPeerAuthenticationUnixDomainSocketPgConnectionAndSetRole$default (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun createPeerAuthenticationUnixDomainSocketPgPool (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;)Lio/vertx/pgclient/PgPool; - public static synthetic fun createPeerAuthenticationUnixDomainSocketPgPool$default (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;ILjava/lang/Object;)Lio/vertx/pgclient/PgPool; - public static final fun createPeerAuthenticationUnixDomainSocketPgPoolAndSetRole (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;)Lio/vertx/pgclient/PgPool; - public static synthetic fun createPeerAuthenticationUnixDomainSocketPgPoolAndSetRole$default (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;ILjava/lang/Object;)Lio/vertx/pgclient/PgPool; - public static final fun createPeerAuthenticationUnixDomainSocketPgSqlClient (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;)Lio/vertx/sqlclient/SqlClient; - public static synthetic fun createPeerAuthenticationUnixDomainSocketPgSqlClient$default (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;ILjava/lang/Object;)Lio/vertx/sqlclient/SqlClient; - public static final fun createPgConnectOptions (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/vertx/pgclient/PgConnectOptions; - public static synthetic fun createPgConnectOptions$default (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/vertx/pgclient/PgConnectOptions; - public static final fun createSocketGenericPgClient (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lkotlin/jvm/functions/Function3;)Ljava/lang/Object; - public static synthetic fun createSocketGenericPgClient$default (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun createSocketPgConnection (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun createSocketPgConnection$default (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun createSocketPgPool (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;)Lio/vertx/pgclient/PgPool; - public static synthetic fun createSocketPgPool$default (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;ILjava/lang/Object;)Lio/vertx/pgclient/PgPool; - public static final fun createSocketPgSqlClient (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;)Lio/vertx/sqlclient/SqlClient; - public static synthetic fun createSocketPgSqlClient$default (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;ILjava/lang/Object;)Lio/vertx/sqlclient/SqlClient; - public static final fun createUnixDomainSocketPgSqlClientAndSetRole (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun createUnixDomainSocketPgSqlClientAndSetRole$default (Lio/vertx/core/Vertx;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lio/vertx/sqlclient/PoolOptions;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun executeSetRole (Lio/vertx/sqlclient/SqlConnection;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public final class com/huanshankeji/exposedvertxsqlclient/classpropertymapping/ReflectionBasedClassPropertyIndexVertxSqlClientRowDataQueryMapper : com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper { - public fun (Lkotlin/reflect/KClass;Lkotlin/Unit;)V - public final fun getClassPropertyColumnIndexMappings ()Lkotlin/Unit; - public final fun getClazz ()Lkotlin/reflect/KClass; - public fun rowToData (Lio/vertx/sqlclient/Row;)Ljava/lang/Object; -} - -public final class com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSqlKt { - public static final fun batchInsert (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun batchInsertIgnore (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun batchInsertSelect (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun batchSingleOrNoUpdate (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun batchSingleOrNoUpdate$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun batchUpdate (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun batchUpdate$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun deleteIgnoreWhere (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun deleteIgnoreWhere$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun deleteWhere (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun deleteWhere$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun executeInsertIgnore (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun insert (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun insertIgnore (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun insertIgnoreSelect (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/AbstractQuery;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun insertIgnoreSelect$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/AbstractQuery;Ljava/util/List;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun insertIgnoreSingle (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun insertSelect (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/AbstractQuery;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun insertSelect$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/AbstractQuery;Ljava/util/List;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun insertSingle (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun select (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun select (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun selectBatch (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/FieldSet;Lkotlin/jvm/functions/Function2;Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun selectColumnSetExpression (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lorg/jetbrains/exposed/sql/Expression;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun selectExpression (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lkotlin/reflect/KClass;Lorg/jetbrains/exposed/sql/Expression;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun selectSingleColumn (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lorg/jetbrains/exposed/sql/Column;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun selectSingleColumn (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lorg/jetbrains/exposed/sql/Column;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun selectSingleEntityIdColumn (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lorg/jetbrains/exposed/sql/Column;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun sortDataAndBatchUpdate (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun sortDataAndBatchUpdate$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public static final fun update (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun update$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; -} - -public final class com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapperKt { - public static final fun batchInsertIgnoreWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun batchInsertWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun batchUpdateBuilderSetter (Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;)Lkotlin/jvm/functions/Function3; - public static final fun executeQueryWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Query;Lcom/huanshankeji/exposed/datamapping/DataQueryMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun executeVertxSqlClientRowQueryWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Query;Lcom/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun insertIgnoreWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Object;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun insertWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Object;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun selectWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lcom/huanshankeji/exposed/datamapping/DataQueryMapper;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun updateWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Ljava/lang/Object;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static synthetic fun updateWithMapper$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Ljava/lang/Object;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper { - public abstract fun rowToData (Lio/vertx/sqlclient/Row;)Ljava/lang/Object; +public final class com/huanshankeji/exposedvertxsqlclient/vertx/sqlclient/SqlConnectionKt { + public static final fun setRole (Lio/vertx/sqlclient/SqlConnection;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } diff --git a/integrated/api/exposed-vertx-sql-client-integrated.api b/integrated/api/exposed-vertx-sql-client-integrated.api index e69de29..a422a43 100644 --- a/integrated/api/exposed-vertx-sql-client-integrated.api +++ b/integrated/api/exposed-vertx-sql-client-integrated.api @@ -0,0 +1,62 @@ +public final class com/huanshankeji/exposedvertxsqlclient/Alternative { + public static final field INSTANCE Lcom/huanshankeji/exposedvertxsqlclient/Alternative; + public final fun getEvscConfig ()Lcom/huanshankeji/exposedvertxsqlclient/EvscConfig; +} + +public final class com/huanshankeji/exposedvertxsqlclient/Director { + public fun (ILjava/lang/String;)V + public final fun getDirectorId ()I + public final fun getName ()Ljava/lang/String; +} + +public final class com/huanshankeji/exposedvertxsqlclient/Directors : org/jetbrains/exposed/dao/id/IntIdTable { + public static final field INSTANCE Lcom/huanshankeji/exposedvertxsqlclient/Directors; + public final fun getDirectorId ()Lorg/jetbrains/exposed/sql/Column; + public final fun getName ()Lorg/jetbrains/exposed/sql/Column; +} + +public final class com/huanshankeji/exposedvertxsqlclient/Examples : org/jetbrains/exposed/dao/id/IntIdTable { + public static final field INSTANCE Lcom/huanshankeji/exposedvertxsqlclient/Examples; + public final fun getName ()Lorg/jetbrains/exposed/sql/Column; +} + +public final class com/huanshankeji/exposedvertxsqlclient/ExamplesKt { + public static final fun examples (Lio/vertx/core/Vertx;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun getEvscConfig ()Lcom/huanshankeji/exposedvertxsqlclient/EvscConfig; + public static final fun getTables ()[Lcom/huanshankeji/exposedvertxsqlclient/Examples; +} + +public final class com/huanshankeji/exposedvertxsqlclient/Film { + public fun (ILcom/huanshankeji/exposedvertxsqlclient/FilmDetails;)V + public final fun getFilmDetails ()Lcom/huanshankeji/exposedvertxsqlclient/FilmDetails; + public final fun getFilmId ()I +} + +public final class com/huanshankeji/exposedvertxsqlclient/FilmDetails { + public fun (ILjava/lang/String;Ljava/lang/Object;)V + public final fun getDirector ()Ljava/lang/Object; + public final fun getName ()Ljava/lang/String; + public final fun getSequelId ()I +} + +public final class com/huanshankeji/exposedvertxsqlclient/Films : org/jetbrains/exposed/dao/id/IntIdTable { + public static final field INSTANCE Lcom/huanshankeji/exposedvertxsqlclient/Films; + public final fun getDirectorId ()Lorg/jetbrains/exposed/sql/Column; + public final fun getFilmId ()Lorg/jetbrains/exposed/sql/Column; + public final fun getName ()Lorg/jetbrains/exposed/sql/Column; + public final fun getSequelId ()Lorg/jetbrains/exposed/sql/Column; +} + +public final class com/huanshankeji/exposedvertxsqlclient/Mappers { + public static final field INSTANCE Lcom/huanshankeji/exposedvertxsqlclient/Mappers; + public final fun getDirector ()Lcom/huanshankeji/exposed/datamapping/classproperty/ReflectionBasedClassPropertyDataMapper; + public final fun getFilmDetailsWithDirectorId ()Lcom/huanshankeji/exposed/datamapping/classproperty/ReflectionBasedClassPropertyDataMapper; + public final fun getFilmWithDirectorId ()Lcom/huanshankeji/exposed/datamapping/classproperty/ReflectionBasedClassPropertyDataMapper; + public final fun getFullFilm ()Lcom/huanshankeji/exposed/datamapping/classproperty/ReflectionBasedClassPropertyDataMapper; +} + +public final class com/huanshankeji/exposedvertxsqlclient/MappingExamplesKt { + public static final fun getFilmsLeftJoinDirectors ()Lorg/jetbrains/exposed/sql/Join; + public static final fun mappingExamples (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + diff --git a/postgresql/api/exposed-vertx-sql-client-postgresql.api b/postgresql/api/exposed-vertx-sql-client-postgresql.api index e69de29..4926d01 100644 --- a/postgresql/api/exposed-vertx-sql-client-postgresql.api +++ b/postgresql/api/exposed-vertx-sql-client-postgresql.api @@ -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; +} + diff --git a/sql-dsl-with-mapper/api/exposed-vertx-sql-client-sql-dsl-with-mapper.api b/sql-dsl-with-mapper/api/exposed-vertx-sql-client-sql-dsl-with-mapper.api index e69de29..5fff915 100644 --- a/sql-dsl-with-mapper/api/exposed-vertx-sql-client-sql-dsl-with-mapper.api +++ b/sql-dsl-with-mapper/api/exposed-vertx-sql-client-sql-dsl-with-mapper.api @@ -0,0 +1,17 @@ +public final class com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapperKt { + public static final fun batchInsertIgnoreWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun batchInsertWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun batchUpdateBuilderSetter (Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;)Lkotlin/jvm/functions/Function3; + public static final fun executeQueryWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Query;Lcom/huanshankeji/exposed/datamapping/DataQueryMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun executeVertxSqlClientRowQueryWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Query;Lcom/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun insertIgnoreWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Object;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun insertWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Object;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun selectWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lcom/huanshankeji/exposed/datamapping/DataQueryMapper;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun updateWithMapper (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Ljava/lang/Object;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun updateWithMapper$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Ljava/lang/Object;Lcom/huanshankeji/exposed/datamapping/DataUpdateMapper;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class com/huanshankeji/vertx/sqlclient/datamapping/RowDataQueryMapper { + public abstract fun rowToData (Lio/vertx/sqlclient/Row;)Ljava/lang/Object; +} + diff --git a/sql-dsl/api/exposed-vertx-sql-client-sql-dsl.api b/sql-dsl/api/exposed-vertx-sql-client-sql-dsl.api new file mode 100644 index 0000000..b6a5654 --- /dev/null +++ b/sql-dsl/api/exposed-vertx-sql-client-sql-dsl.api @@ -0,0 +1,35 @@ +public final class com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSqlKt { + public static final fun batchInsert (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun batchInsertIgnore (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun batchInsertSelect (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun batchSingleOrNoUpdate (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun batchSingleOrNoUpdate$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun batchUpdate (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun batchUpdate$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun deleteIgnoreWhere (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun deleteIgnoreWhere$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun deleteWhere (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun deleteWhere$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Integer;Ljava/lang/Long;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun executeInsertIgnore (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun insert (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun insertIgnore (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun insertIgnoreSelect (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/AbstractQuery;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun insertIgnoreSelect$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/AbstractQuery;Ljava/util/List;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun insertIgnoreSingle (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun insertSelect (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/AbstractQuery;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun insertSelect$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lorg/jetbrains/exposed/sql/AbstractQuery;Ljava/util/List;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun insertSingle (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun select (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun select (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun selectBatch (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/FieldSet;Lkotlin/jvm/functions/Function2;Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun selectColumnSetExpression (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lorg/jetbrains/exposed/sql/Expression;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun selectExpression (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lkotlin/reflect/KClass;Lorg/jetbrains/exposed/sql/Expression;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun selectSingleColumn (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lorg/jetbrains/exposed/sql/Column;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun selectSingleColumn (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lorg/jetbrains/exposed/sql/Column;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun selectSingleEntityIdColumn (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/ColumnSet;Lorg/jetbrains/exposed/sql/Column;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun sortDataAndBatchUpdate (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun sortDataAndBatchUpdate$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static final fun update (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun update$default (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function1;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; +} + From 263cc5c6d7ea7b1a0be02ed68b7df5965d0d534a Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 04:40:33 +0800 Subject: [PATCH 22/26] Print the number of processors and add a comment in `multiThreadMultiConnectionEach10KLocalTransactions` --- .../huanshankeji/exposed/benchmark/TransactionBenchmark.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt index 928295c..e2183c0 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt @@ -57,7 +57,10 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() { @Benchmark fun multiThreadMultiConnectionEach10KLocalTransactions() { - List(Runtime.getRuntime().availableProcessors()) { + // Note that on a device with heterogeneous architecture some threads may finish earlier than others. + List(Runtime.getRuntime().availableProcessors().also { + println("Number of processors: $it") + }) { thread { val database = databaseConnect() repeat(`10K`) { transaction(database) {} } From 210529d7c845f1d7a24287e32c11b333161128a3 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 05:49:57 +0800 Subject: [PATCH 23/26] Add `multiThreadConcurrent10KTransactionsWithThreadLocalDatabases` and `multiThreadConcurrent10KTransactionsWithImplicitThreadLocalDatabases` into the benchmark code, fix `singleThreadConcurrent10KTransactions` which actually runs on multiple threads instead of one BTW, and improve `multiThreadConcurrent10KTransactionsWithSharedDatabase` BTW --- .../exposed/benchmark/TransactionBenchmark.kt | 63 ++++++++++++++----- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt index e2183c0..cf9c0bd 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt @@ -1,13 +1,13 @@ package com.huanshankeji.exposed.benchmark import com.huanshankeji.kotlinx.coroutine.awaitAny -import kotlinx.benchmark.Benchmark -import kotlinx.benchmark.Scope -import kotlinx.benchmark.State +import kotlinx.benchmark.* import kotlinx.coroutines.* +import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction import org.jetbrains.exposed.sql.transactions.experimental.suspendedTransactionAsync import org.jetbrains.exposed.sql.transactions.transaction +import java.util.concurrent.Executors import kotlin.concurrent.thread @State(Scope.Benchmark) @@ -32,17 +32,16 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() { } @Benchmark - fun singleThreadConcurrent10KTransactions() = runBlocking { - awaitAsync10KTransactions() - } + fun singleThreadConcurrent10KTransactions() = + @OptIn(ExperimentalCoroutinesApi::class, DelicateCoroutinesApi::class) + runBlocking(newSingleThreadContext("single thread")) { + awaitAsync10KTransactions() + } @Benchmark - fun multiThreadConcurrent10KTransactions() = runBlocking { - withContext(Dispatchers.Default) { - awaitAsync10KTransactions() - } - } + fun multiThreadConcurrent10KTransactionsWithSharedDatabase() = + runBlocking { awaitAsync10KTransactions() } @Benchmark @@ -55,12 +54,15 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() { List(`10K`) { suspendedTransactionAsync(db = database) {} }.awaitAny() } + private fun numProcessors() = + Runtime.getRuntime().availableProcessors().also { + println("Number of processors: $it") + } + @Benchmark fun multiThreadMultiConnectionEach10KLocalTransactions() { // Note that on a device with heterogeneous architecture some threads may finish earlier than others. - List(Runtime.getRuntime().availableProcessors().also { - println("Number of processors: $it") - }) { + List(numProcessors()) { thread { val database = databaseConnect() repeat(`10K`) { transaction(database) {} } @@ -69,4 +71,37 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() { it.join() } } + + + val databaseThreadLocal = ThreadLocal() + lateinit var dispatcherWithThreadLocalDatabases: ExecutorCoroutineDispatcher + + @Setup + fun setUpThreadLocalDatabases() { + dispatcherWithThreadLocalDatabases = Executors.newFixedThreadPool(numProcessors()) { + Thread { + it.run() + databaseThreadLocal.set(databaseConnect()) + } + }.asCoroutineDispatcher() + } + + @TearDown + fun teardownDispatcherWithThreadLocalDatabases() { + dispatcherWithThreadLocalDatabases.close() + } + + @Benchmark + fun multiThreadConcurrent10KTransactionsWithThreadLocalDatabases() { + runBlocking(dispatcherWithThreadLocalDatabases) { + List(`10K`) { async { transaction(databaseThreadLocal.get()) {} } }.awaitAll() + } + } + + @Benchmark + fun multiThreadConcurrent10KTransactionsWithImplicitThreadLocalDatabases() { + runBlocking(dispatcherWithThreadLocalDatabases) { + List(`10K`) { async { transaction {} } }.awaitAll() + } + } } \ No newline at end of file From 3715550f6f5dfda78678a33e7008b67d6253d53b Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 05:51:22 +0800 Subject: [PATCH 24/26] Fix a bug that `awaitAny` is used --- .../com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt index cf9c0bd..82303b8 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt @@ -1,6 +1,5 @@ package com.huanshankeji.exposed.benchmark -import com.huanshankeji.kotlinx.coroutine.awaitAny import kotlinx.benchmark.* import kotlinx.coroutines.* import org.jetbrains.exposed.sql.Database @@ -51,7 +50,7 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() { @Benchmark fun _10KSuspendedTransactionAsyncs() = runBlocking { - List(`10K`) { suspendedTransactionAsync(db = database) {} }.awaitAny() + List(`10K`) { suspendedTransactionAsync(db = database) {} }.awaitAll() } private fun numProcessors() = From 920627f9e8713ec203c96584ac3783cfb1b1770d Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 06:00:35 +0800 Subject: [PATCH 25/26] Make `CoroutineScope` the receiver in `awaitAsync10KTransactions` and extract `awaitAsync10K` --- .../exposed/benchmark/TransactionBenchmark.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt index 82303b8..2a29d3f 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt @@ -25,10 +25,13 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() { repeat(`10K`) { transaction(database) {} } } - private suspend fun awaitAsync10KTransactions() = - coroutineScope { - List(`10K`) { async { transaction(database) {} } }.awaitAll() - } + @Suppress("SuspendFunctionOnCoroutineScope") + private suspend inline fun CoroutineScope.awaitAsync10K(crossinline block: () -> Unit) = + List(`10K`) { async { block() } }.awaitAll() + + @Suppress("SuspendFunctionOnCoroutineScope") + private suspend fun CoroutineScope.awaitAsync10KTransactions() = + awaitAsync10K { transaction(database) {} } @Benchmark fun singleThreadConcurrent10KTransactions() = @@ -93,14 +96,14 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() { @Benchmark fun multiThreadConcurrent10KTransactionsWithThreadLocalDatabases() { runBlocking(dispatcherWithThreadLocalDatabases) { - List(`10K`) { async { transaction(databaseThreadLocal.get()) {} } }.awaitAll() + awaitAsync10K { transaction(databaseThreadLocal.get()) {} } } } @Benchmark fun multiThreadConcurrent10KTransactionsWithImplicitThreadLocalDatabases() { runBlocking(dispatcherWithThreadLocalDatabases) { - List(`10K`) { async { transaction {} } }.awaitAll() + awaitAsync10K { transaction {} } } } } \ No newline at end of file From 90dc927dddda614e14f6a09bce6d30e2539b9d3c Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 20 Nov 2024 18:05:27 +0800 Subject: [PATCH 26/26] Update README.md corresponding to the split modules --- README.md | 55 +++++++++++++++++-- .../ExperimentalEvscApi.kt | 2 +- .../exposedvertxsqlclient/InternalApi.kt | 2 +- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 479b0cf..c0cf1f9 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,46 @@ Only PostgreSQL with [Reactive PostgreSQL Client](https://vertx.io/docs/vertx-pg-client/java/) is currently supported. +## Experimental + +This library is experimental now. The APIs are subject to change (especially those marked with +`@ExperimentalEvscApi`), the tests are incomplete, and please expect bugs and report them. + ## Maven coordinate ```kotlin -"com.huanshankeji:exposed-vertx-sql-client-postgresql:$version" +"com.huanshankeji:exposed-vertx-sql-client-$module:$evscVersion" ``` +## API documentation + +See the [hosted API documentation](https://huanshankeji.github.io/exposed-vertx-sql-client/) for the APIs. + ## Basic usage guide -Here is a basic usage guide. This project currently serves our own use, therefore, there are temporarily no detailed docs, APIs are experimental, tests are incomplete, and please expect bugs. To learn more in addition to the guide below, see the [hosted API documentation](https://huanshankeji.github.io/exposed-vertx-sql-client/), and see [DatabaseClient.kt](lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt) and [DatabaseClientSql.kt](lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt) for the major APIs. +Here is a basic usage guide. + +### Before v0.5.0 + +Add the PostgreSQL module, which was the only module, to your dependencies with the Gradle build script: + +```kotlin +implementation("com.huanshankeji:exposed-vertx-sql-client-postgresql:0.4.0") +``` + +### Since v0.5.0 + +Add the core module to your dependencies with the Gradle build script: + +```kotlin +implementation("com.huanshankeji:exposed-vertx-sql-client-core:$evscVersion") +``` + +And add an RDBMS module, for example, the PostgreSQL module: + +```kotlin +implementation("com.huanshankeji:exposed-vertx-sql-client-postgresql:$evscVersion") +``` ### Create a `DatabaseClient` @@ -109,7 +140,15 @@ databaseClient.executeSingleUpdate(Examples.deleteIgnoreWhereStatement { id eq 2 #### Extension SQL DSL APIs -With these extension APIs, your code becomes more concise, but it might be more difficult when you need to compose statements or edit the code: +With the extension SQL DSL APIs, your code becomes more concise, but it might be more difficult when you need to compose statements or edit the code. + +Gradle dependency configuration (only needed since v0.5.0): + +```kotlin +implementation("com.huanshankeji:exposed-vertx-sql-client-sql-dsl:$evscVersion") +``` + +Example code: ```kotlin databaseClient.insert(Examples) { it[name] = "A" } @@ -131,10 +170,18 @@ val deleteRowCount2 = databaseClient.deleteIgnoreWhere(Examples) { id eq 2 } assert(deleteRowCount2 == 1) ``` -#### APIs using [Exposed GADT mapping](https://github.com/huanshankeji/exposed-adt-mapping) +#### Extension SQL DSL APIs with [Exposed GADT mapping](https://github.com/huanshankeji/exposed-adt-mapping) Please read [that library's basic usage guide](https://github.com/huanshankeji/exposed-adt-mapping?tab=readme-ov-file#basic-usage-guide) first. Here are examples of this library that correspond to [that library's CRUD operations](https://github.com/huanshankeji/exposed-adt-mapping?tab=readme-ov-file#crud-operations). +Gradle dependency configuration (only needed since v0.5.0): + +```kotlin +implementation("com.huanshankeji:exposed-vertx-sql-client-sql-dsl-with-mapper:$evscVersion") +``` + +Example code: + ```kotlin val directorId = 1 val director = Director(directorId, "George Lucas") diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExperimentalEvscApi.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExperimentalEvscApi.kt index a63caa0..668e4c0 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExperimentalEvscApi.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ExperimentalEvscApi.kt @@ -2,7 +2,7 @@ package com.huanshankeji.exposedvertxsqlclient import kotlin.annotation.AnnotationTarget.* -@RequiresOptIn("This API is experimental in the Exposed Vert.x SQL Client library.", RequiresOptIn.Level.WARNING) +@RequiresOptIn("This API is experimental. It may be changed in the future without notice.", RequiresOptIn.Level.WARNING) @Retention(AnnotationRetention.BINARY) // The ones commented out are what I think may be used in very few use cases. @Target( diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt index 62a302c..cbe7d6d 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/InternalApi.kt @@ -1,5 +1,5 @@ package com.huanshankeji.exposedvertxsqlclient -@RequiresOptIn("This API is internal in the Exposed Vert.x SQL Client library.") +@RequiresOptIn("This API is internal in the Exposed Vert.x SQL Client library. It may be changed in the future without notice.") @Retention(AnnotationRetention.BINARY) annotation class InternalApi \ No newline at end of file