From e7cb9d3ed0aae04361d29e0c8434fdcc5d86392c Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Sun, 20 Oct 2024 16:16:00 +0800 Subject: [PATCH 01/70] Add CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b6121bf --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# Change log + +## v0.4.0 / 2024-10-19 + +* fix a bug that an Exposed transaction is required if a query `FieldSet` contains custom functions depending on dialects and no such a transaction is provided +* Add a basic usage guide From 0bca06bfaef2d7b003535217eb4c178b86979b8a Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Sun, 20 Oct 2024 16:19:22 +0800 Subject: [PATCH 02/70] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6121bf..168be6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,5 +2,6 @@ ## v0.4.0 / 2024-10-19 +* bump Exposed to 0.53.0 * fix a bug that an Exposed transaction is required if a query `FieldSet` contains custom functions depending on dialects and no such a transaction is provided * Add a basic usage guide From 7f60a999b1fe665cdf2c6b6e8da73b4b0220cba0 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Mon, 4 Nov 2024 12:21:03 +0800 Subject: [PATCH 03/70] Create kotlin-jvm-ci.yml with our workflow template --- .github/workflows/kotlin-jvm-ci.yml | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/kotlin-jvm-ci.yml diff --git a/.github/workflows/kotlin-jvm-ci.yml b/.github/workflows/kotlin-jvm-ci.yml new file mode 100644 index 0000000..f3135e8 --- /dev/null +++ b/.github/workflows/kotlin-jvm-ci.yml @@ -0,0 +1,45 @@ +name: CI + +on: + push: + branches: [ "*" ] +# pull_request: +# branches: [ "*" ] + +jobs: + check: + + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 8 + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Check with Gradle Wrapper + run: ./gradlew check + + dependency-submission: + + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 8 + uses: actions/setup-java@v4 + with: + java-version: '8' + distribution: 'temurin' + + - name: Generate and submit dependency graph + uses: gradle/actions/dependency-submission@v4 From 16aa23182656c7082297270361475648e003b28e Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Wed, 6 Nov 2024 10:09:23 +0800 Subject: [PATCH 04/70] Configure the Dokka Gradle plugin, its tasks, and the GitHub Actions workflow, with code copied and adapted from "exposed-adt-mapping" A source commit: https://github.com/huanshankeji/exposed-adt-mapping/commit/18800b706e5d5bacd23ca9e20d8389bbef7d2a02 --- .github/workflows/dokka-gh-pages.yml | 61 ++++++++++++++++++++++++++++ build.gradle.kts | 8 ++++ buildSrc/build.gradle.kts | 1 + gradle.properties | 2 + lib/build.gradle.kts | 12 +++++- settings.gradle.kts | 8 ++++ 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/dokka-gh-pages.yml create mode 100644 gradle.properties diff --git a/.github/workflows/dokka-gh-pages.yml b/.github/workflows/dokka-gh-pages.yml new file mode 100644 index 0000000..53c853c --- /dev/null +++ b/.github/workflows/dokka-gh-pages.yml @@ -0,0 +1,61 @@ +name: Deploy the API documentation to GitHub Pages with Dokka + +on: + push: + branches: [ "plugins-release" ] + pull_request: + branches: [ "plugins-release" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Set up JDK 8 + uses: actions/setup-java@v4 + with: + java-version: "8" + distribution: "temurin" + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build the distribution with Gradle Wrapper + run: ./gradlew :dokkaGeneratePublicationHtml + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: build/dokka/html/ + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/build.gradle.kts b/build.gradle.kts index 1241019..7b5b7b8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,11 @@ tasks.wrapper { distributionType = Wrapper.DistributionType.ALL } + +plugins { + id("org.jetbrains.dokka") +} + +dependencies { + dokka(project(":exposed-vertx-sql-client-postgresql")) +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index bf8774c..6a6f9e2 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -19,4 +19,5 @@ dependencies { implementation(kotlin("gradle-plugin", "2.0.10")) implementation("com.huanshankeji:common-gradle-dependencies:0.8.0-20241016") // don't use a snapshot version in a main branch implementation("com.huanshankeji.team:gradle-plugins:0.6.0") // don't use a snapshot version in a main branch + implementation("org.jetbrains.dokka:dokka-gradle-plugin:2.0.0-Beta") } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..4a50b9e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +# for Dokka +org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index baa06d7..2a61c1c 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -1,6 +1,7 @@ plugins { conventions id("com.huanshankeji.benchmark.kotlinx-benchmark-jvm-conventions") + id("org.jetbrains.dokka") } dependencies { @@ -40,4 +41,13 @@ afterEvaluate { } "benchmarksImplementation"(commonDependencies.slf4j.simple()) } -} \ No newline at end of file +} + +dokka { + dokkaSourceSets.all { + sourceLink { + remoteUrl("https://github.com/huanshankeji/exposed-vertx-sql-client/tree/v${version}/lib") + remoteLineSuffix.set("#L") + } + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index f25580d..75fcf49 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,11 @@ rootProject.name = "exposed-vertx-sql-client" include("lib") project(":lib").name = rootProject.name + "-postgresql" + +// for Dokka +@Suppress("UnstableApiUsage") +dependencyResolutionManagement { + repositories { + mavenCentral() + } +} From 45a98bfa38296a821fefa1f882d476b394ee2c9b Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Wed, 6 Nov 2024 11:32:05 +0800 Subject: [PATCH 05/70] Update README.md about the API documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3282176..5322a8f 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Only PostgreSQL with [Reactive PostgreSQL Client](https://vertx.io/docs/vertx-pg ## 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 [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. 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. ### Create a `DatabaseClient` From 9a6fb120cd1bd948c1e47db140407badd7a3b0d4 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Thu, 7 Nov 2024 18:39:19 +0800 Subject: [PATCH 06/70] Use the new `com.huanshankeji.team.dokka.github-dokka-convention` plugin --- buildSrc/build.gradle.kts | 2 +- lib/build.gradle.kts | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 6a6f9e2..507988e 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -18,6 +18,6 @@ dependencies { // With Kotlin 2.0.20, a "Could not parse POM" build error occurs in the JVM projects of some dependent projects. implementation(kotlin("gradle-plugin", "2.0.10")) implementation("com.huanshankeji:common-gradle-dependencies:0.8.0-20241016") // don't use a snapshot version in a main branch - implementation("com.huanshankeji.team:gradle-plugins:0.6.0") // don't use a snapshot version in a main branch + implementation("com.huanshankeji.team:gradle-plugins:0.7.0-SNAPSHOT") // TODO don't use a snapshot version in a main branch implementation("org.jetbrains.dokka:dokka-gradle-plugin:2.0.0-Beta") } diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 2a61c1c..27c95c6 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -1,7 +1,7 @@ plugins { conventions id("com.huanshankeji.benchmark.kotlinx-benchmark-jvm-conventions") - id("org.jetbrains.dokka") + id("com.huanshankeji.team.dokka.github-dokka-convention") } dependencies { @@ -42,12 +42,3 @@ afterEvaluate { "benchmarksImplementation"(commonDependencies.slf4j.simple()) } } - -dokka { - dokkaSourceSets.all { - sourceLink { - remoteUrl("https://github.com/huanshankeji/exposed-vertx-sql-client/tree/v${version}/lib") - remoteLineSuffix.set("#L") - } - } -} From d9eb743952e98b3287c6656b7e27abbe4cd518ac Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Thu, 7 Nov 2024 22:35:10 +0800 Subject: [PATCH 07/70] Create CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 128 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..da80987 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +shreckye@gmail.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. From 3ac08d8da201dbead883cfe95285f95841a5b1bb Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Fri, 8 Nov 2024 00:12:28 +0800 Subject: [PATCH 08/70] Create CONTRIBUTING.md A source commit: https://github.com/huanshankeji/gradle-common/commit/c0118b9ef0c90c75d6426bacde3b2069bc0668a6 --- CONTRIBUTING.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ca714df --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,23 @@ +# Contributing guidelines + +Hello, thank you for your interest in contributing to our project. + +## Issues and Discussions + +You are welcome to submit issues on bugs or feature requests. If you have questions, please ask them in GitHub Discussions. + +## Pull requests + +If you want to contribute to the code of our project, you are welcome to open pull requests. However, it's always a good idea to open a related issue or talk with us in Discussions first. + +## Development + +Please make sure you have a valid JDK installed. Some projects may require multiple JDKs of different versions. The JDK version we use can be found in the [GitHub Actions workflow files](.github/workflows). + +We recommend developing with IntelliJ IDEA. In IntelliJ IDEA, select the correct [Project SDK in Project Structure](https://www.jetbrains.com/help/idea/project-settings-and-structure.html#project-sdk) and it's recommended to set [Gradle JVM](https://www.jetbrains.com/help/idea/gradle-jvm-selection.html#jvm_settings) to "Project SDK". + +Run the `publishToMavenLocal` Gradle task to publish the libraries to your machine's Maven Local Repository so your projects can depend on the changes you have made, run `check` to ensure our limited number of tests pass. + +## Furthur notice + +We are currently a small team with limited effort. While we may not always implement your requested features, merge your pull requests, or do such things in time, you are always welcome to create your own fork and make any changes you like. From c3f1c89fb4eb77ea76f4f9f18363a95c384368d2 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Fri, 8 Nov 2024 10:55:41 +0800 Subject: [PATCH 09/70] Apply the binary compatibility validator Gradle plugin --- build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle.kts b/build.gradle.kts index 7b5b7b8..35587e3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,6 +4,7 @@ tasks.wrapper { plugins { id("org.jetbrains.dokka") + id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.16.3" } dependencies { From ed81cd825c5510c96f75394731006f1619a96d51 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Fri, 8 Nov 2024 10:56:39 +0800 Subject: [PATCH 10/70] Run `apiDump` --- .../exposed-vertx-sql-client-postgresql.api | 227 ++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 lib/api/exposed-vertx-sql-client-postgresql.api diff --git a/lib/api/exposed-vertx-sql-client-postgresql.api b/lib/api/exposed-vertx-sql-client-postgresql.api new file mode 100644 index 0000000..e1da900 --- /dev/null +++ b/lib/api/exposed-vertx-sql-client-postgresql.api @@ -0,0 +1,227 @@ +public abstract interface class com/huanshankeji/exposedvertxsqlclient/ConnectionConfig { + public abstract fun getDatabase ()Ljava/lang/String; + public abstract fun getUserAndRole ()Ljava/lang/String; +} + +public final class com/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket : com/huanshankeji/exposedvertxsqlclient/ConnectionConfig { + public fun (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public synthetic fun (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun getDatabase ()Ljava/lang/String; + public final fun getHost ()Ljava/lang/String; + public final fun getPassword ()Ljava/lang/String; + public final fun getPort ()Ljava/lang/Integer; + public final fun getUser ()Ljava/lang/String; + public fun getUserAndRole ()Ljava/lang/String; +} + +public final class com/huanshankeji/exposedvertxsqlclient/ConnectionConfig$UnixDomainSocketWithPeerAuthentication : com/huanshankeji/exposedvertxsqlclient/ConnectionConfig { + public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public fun getDatabase ()Ljava/lang/String; + public final fun getPath ()Ljava/lang/String; + public final fun getRole ()Ljava/lang/String; + public fun getUserAndRole ()Ljava/lang/String; +} + +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; + public static fun getEntries ()Lkotlin/enums/EnumEntries; + public static fun valueOf (Ljava/lang/String;)Lcom/huanshankeji/exposedvertxsqlclient/ConnectionType; + public static fun values ()[Lcom/huanshankeji/exposedvertxsqlclient/ConnectionType; +} + +public final class com/huanshankeji/exposedvertxsqlclient/DatabaseClient { + public fun (Lio/vertx/sqlclient/SqlClient;Lorg/jetbrains/exposed/sql/Database;ZZ)V + public synthetic fun (Lio/vertx/sqlclient/SqlClient;Lorg/jetbrains/exposed/sql/Database;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun close (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun createTable (Lorg/jetbrains/exposed/sql/Table;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun doExecute (Lorg/jetbrains/exposed/sql/statements/Statement;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun dropTable (Lorg/jetbrains/exposed/sql/Table;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun execute (Lorg/jetbrains/exposed/sql/statements/Statement;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeBatch (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeBatchForVertxSqlClientRowSetSequence (Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeBatchQuery (Lorg/jetbrains/exposed/sql/FieldSet;Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeBatchQuery (Lorg/jetbrains/exposed/sql/FieldSet;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeBatchUpdate (Ljava/lang/Iterable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeExpression (Lkotlin/reflect/KClass;Lorg/jetbrains/exposed/sql/Expression;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeForVertxSqlClientRowSet (Lorg/jetbrains/exposed/sql/statements/Statement;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executePlainSql (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executePlainSqlUpdate (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeQuery (Lorg/jetbrains/exposed/sql/Query;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeQuery (Lorg/jetbrains/exposed/sql/Query;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeSingleOrNoUpdate (Lorg/jetbrains/exposed/sql/statements/Statement;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeSingleUpdate (Lorg/jetbrains/exposed/sql/statements/Statement;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeUpdate (Lorg/jetbrains/exposed/sql/statements/Statement;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun executeWithMapping (Lorg/jetbrains/exposed/sql/statements/Statement;Ljava/util/function/Function;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun exposedTransaction (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public final fun getExposedDatabase ()Lorg/jetbrains/exposed/sql/Database; + public final fun getFieldExpressionSetWithTransaction (Lorg/jetbrains/exposed/sql/FieldSet;)Ljava/util/Set; + public final fun getFieldExpressionSetWithTransaction (Lorg/jetbrains/exposed/sql/Query;)Ljava/util/Set; + public final fun getLogSql ()Z + public final fun getValidateBatch ()Z + public final fun getVertxSqlClient ()Lio/vertx/sqlclient/SqlClient; + public final fun isWorking (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun toExposedResultRowWithTransaction (Lio/vertx/sqlclient/Row;Lorg/jetbrains/exposed/sql/Query;)Lorg/jetbrains/exposed/sql/ResultRow; +} + +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 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; + public static final fun getVertxPgClientPreparedSql (Lorg/jetbrains/exposed/sql/statements/Statement;Lorg/jetbrains/exposed/sql/Transaction;)Ljava/lang/String; + public static final fun getVertxSqlClientArgTuple (Lorg/jetbrains/exposed/sql/statements/Statement;)Lio/vertx/sqlclient/Tuple; + public static final fun singleOrNoResult (Lio/vertx/sqlclient/RowSet;)Ljava/lang/Object; + public static final fun singleOrNoUpdate (I)Z + public static final fun singleResult (Lio/vertx/sqlclient/RowSet;)Ljava/lang/Object; + public static final fun singleStatementArguments (Lorg/jetbrains/exposed/sql/statements/Statement;)Ljava/lang/Iterable; + public static final fun toExposedResultRow (Lio/vertx/sqlclient/Row;Ljava/util/Set;)Lorg/jetbrains/exposed/sql/ResultRow; + public static final fun toExposedResultRow (Lio/vertx/sqlclient/Row;Lorg/jetbrains/exposed/sql/Query;)Lorg/jetbrains/exposed/sql/ResultRow; + 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 final class com/huanshankeji/exposedvertxsqlclient/EvscConfig : com/huanshankeji/exposedvertxsqlclient/IEvscConfig { + public fun (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket;Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig;)V + public fun getExposedConnectionConfig ()Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket; + public fun getVertxSqlClientConnectionConfig ()Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig; +} + +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 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 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 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/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/SingleUpdateException : java/lang/Exception { + public fun (I)V +} + +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 executeInsertIgnore (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun executeSingleColumnSelectQuery (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 executeSingleColumnSelectQuery (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 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 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 selectTableExpression (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 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 batchInsert (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 batchInsertIgnore (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 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 executeQuery (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Query;Lcom/huanshankeji/exposed/datamapping/DataQueryMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun executeVertxSqlClientRowQuery (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 insert (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 insertIgnore (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 select (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 update (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 update$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; +} + From 33f0abd7e0bcaf40ac114bb15d61d39e31fbcaba Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 14 Nov 2024 17:55:26 +0800 Subject: [PATCH 11/70] Run Code Cleanup with IntelliJ IDEA and revert some erroneous or unnecessary changes --- .../benchmark/PreparedSqlGenerationBenchmark.kt | 2 +- .../exposedvertxsqlclient/DatabaseClient.kt | 4 ++-- .../exposedvertxsqlclient/VertxSqlClients.kt | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/PreparedSqlGenerationBenchmark.kt b/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/PreparedSqlGenerationBenchmark.kt index 3110a50..977bec2 100644 --- a/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/PreparedSqlGenerationBenchmark.kt +++ b/lib/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/PreparedSqlGenerationBenchmark.kt @@ -16,7 +16,7 @@ import org.jetbrains.exposed.sql.transactions.transaction class PreparedSqlGenerationBenchmark : WithContainerizedDatabaseBenchmark() { enum class StatementEnum(val statement: Statement<*>) { SelectAll(VarcharTable.selectAll()), - SelectWhere(VarcharTable.select(VarcharTable.id eq 0L)), + SelectWhere(VarcharTable.selectAll().where(VarcharTable.id eq 0L)), Insert(VarcharTable.insertStatement { it[varcharColumn] = "string" }), Update(VarcharTable.updateStatement({ VarcharTable.id eq 0L }) { it[varcharColumn] = "string" diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index f66ac8a..b82985e 100644 --- a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -5,7 +5,7 @@ import com.huanshankeji.collections.singleOrNullIfEmpty import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig.Socket import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig.UnixDomainSocketWithPeerAuthentication import com.huanshankeji.exposedvertxsqlclient.sql.selectExpression -import com.huanshankeji.os.isOSLinux +import com.huanshankeji.os.isCurrentOsLinux import com.huanshankeji.vertx.kotlin.coroutines.coroutineToFuture import com.huanshankeji.vertx.kotlin.sqlclient.executeBatchAwaitForSqlResultSequence import io.vertx.core.Vertx @@ -529,7 +529,7 @@ fun createBetterPgPoolDatabaseClient( ) = createPgPoolDatabaseClient( vertx, - if (isOSLinux()) ConnectionType.UnixDomainSocketWithPeerAuthentication else ConnectionType.Socket, + if (isCurrentOsLinux()) ConnectionType.UnixDomainSocketWithPeerAuthentication else ConnectionType.Socket, localConnectionConfig, extraPgConnectOptions, poolOptions, exposedDatabase diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt index f8feac9..6ec1cc3 100644 --- a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt +++ b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/VertxSqlClients.kt @@ -2,7 +2,7 @@ package com.huanshankeji.exposedvertxsqlclient import com.huanshankeji.Untested import io.vertx.core.Vertx -import io.vertx.kotlin.coroutines.await +import io.vertx.kotlin.coroutines.coAwait import io.vertx.kotlin.sqlclient.poolOptionsOf import io.vertx.pgclient.PgConnectOptions import io.vertx.pgclient.PgConnection @@ -34,7 +34,7 @@ private val pgConnectionConnect: suspend (Vertx?, PgConnectOptions, Nothing?) -> */ suspend fun SqlConnection.executeSetRole(role: String) = - query("SET ROLE $role").execute().await() + query("SET ROLE $role").execute().coAwait() // TODO: use `ConnectionConfig` as the argument directly in all the following functions @@ -82,7 +82,7 @@ suspend fun createSocketPgConnection( createSocketGenericPgClient( vertx, host, port, database, user, password, extraPgConnectOptions, null ) { vertx, pgConnectOptions, _ -> - PgConnection.connect(vertx, pgConnectOptions).await() + PgConnection.connect(vertx, pgConnectOptions).coAwait() } @@ -121,7 +121,7 @@ suspend fun createUnixDomainSocketPgSqlClientAndSetRole( vertx, host, database, extraPgConnectOptions, poolOptions ).apply { // Is this done for all connections? - query("SET ROLE $role").execute().await() + query("SET ROLE $role").execute().coAwait() } fun createPeerAuthenticationUnixDomainSocketPgPool( @@ -144,7 +144,7 @@ fun createPeerAuthenticationUnixDomainSocketPgPoolAndSetRole( // TODO: are exceptions handled? it.executeSetRole(role) /** @see Pool.connectHandler */ - it.close().await() + it.close().coAwait() } } @@ -157,7 +157,7 @@ suspend fun createPeerAuthenticationUnixDomainSocketPgConnectionAndSetRole( createPeerAuthenticationUnixDomainSocketGenericPgClient( vertx, host, database, extraPgConnectOptions, null ) { vertx, pgConnectOptions, _ -> - PgConnection.connect(vertx, pgConnectOptions).await().apply { + PgConnection.connect(vertx, pgConnectOptions).coAwait().apply { executeSetRole(role) } } From de09f995df561df88c0df91f08bf90e0dc899620 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 14 Nov 2024 18:15:41 +0800 Subject: [PATCH 12/70] Review the actual arguments of the type parameter `T` in `UpdateBuilder` and see if there is a need to replace some `UpdateBuilder<*>` with `UpdateBuilder` `T` seems to mean the update count. Currently, there are only `Int` type arguments passed, but it seems reserved for `Long`. From c03ede0a2d85a4fbe55ada8d6e5033313d937243 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 14 Nov 2024 20:52:26 +0800 Subject: [PATCH 13/70] Adapt to the new SELECT DSL Resolve #8 Some functions' signatures are changed so binary compatibility is not maintained. The project version is bumped BTW. --- README.md | 6 ++-- .../main/kotlin/VersionsAndDependencies.kt | 4 +-- .../sql/DatabaseClientSql.kt | 35 +++++-------------- .../mapping/DatabaseClientSqlWithMapper.kt | 14 ++++++++ .../exposedvertxsqlclient/Examples.kt | 2 +- .../exposedvertxsqlclient/MappingExamples.kt | 7 ++-- 6 files changed, 32 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 5322a8f..a7d2213 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ val exampleName1 = databaseClient.select(Examples) { select(Examples.name).where(Examples.id eq 1) }.single()[Examples.name] // This function still depends on the old SELECT DSL and will be updated. val exampleName2 = - databaseClient.selectSingleColumn(Examples, Examples.name) { selectAll().where(Examples.id eq 2) }.single() + databaseClient.selectSingleColumn(Examples, Examples.name) { where(Examples.id eq 2) }.single() val deleteRowCount1 = databaseClient.deleteWhere(Examples) { id eq 1 } assert(deleteRowCount1 == 1) @@ -120,8 +120,8 @@ val episodeIIFilmDetails = FilmDetails(2, "Star Wars: Episode II – Attack of t val filmWithDirectorId = FilmWithDirectorId(filmId, episodeIIFilmDetails) databaseClient.insert(Films, filmWithDirectorId, Mappers.filmWithDirectorId) // insert with the ID -val fullFilms = databaseClient.select(filmsLeftJoinDirectors, Mappers.fullFilm) { - select(Films.filmId inList listOf(1, 2)) // This API still depends on the old SELECT DSL and will be refactored. +val fullFilms = databaseClient.selectWithMapper(filmsLeftJoinDirectors, Mappers.fullFilm) { + where(Films.filmId inList listOf(1, 2)) // This API still depends on the old SELECT DSL and will be refactored. } ``` diff --git a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt index bbeefd8..096a8e3 100644 --- a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt +++ b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt @@ -2,10 +2,10 @@ import com.huanshankeji.CommonDependencies import com.huanshankeji.CommonGradleClasspathDependencies import com.huanshankeji.CommonVersions -val projectVersion = "0.4.0-SNAPSHOT" +val projectVersion = "0.5.0-SNAPSHOT" // don't use a snapshot version in a main branch -val commonVersions = CommonVersions(kotlinCommon = "0.5.1") +val commonVersions = CommonVersions(kotlinCommon = "0.6.0-SNAPSHOT") val commonDependencies = CommonDependencies(commonVersions) val commonGradleClasspathDependencies = CommonGradleClasspathDependencies(commonVersions) diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt index 4d0741a..a6fe966 100644 --- a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt +++ b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt @@ -33,50 +33,33 @@ suspend inline fun DatabaseClient<*>.select( select(columnSet, buildQuery, { this }) -// TODO adapt to the new SELECT DSL or deprecate /** * SQL: `SELECT FROM ;`. * Examples: `SELECT COUNT(*) FROM
;`, `SELECT SUM() FROM
;`. */ @ExperimentalEvscApi -suspend fun DatabaseClient<*>.selectTableExpression( - columnSet: ColumnSet, expression: Expression, buildQuery: FieldSet.() -> Query +suspend fun DatabaseClient<*>.selectColumnSetExpression( + columnSet: ColumnSet, expression: Expression, buildQuery: Query.() -> Query ): RowSet = - select(columnSet, { slice(expression).buildQuery() }, { this[expression] }) + select(columnSet, { select(expression).buildQuery() }, { this[expression] }) // This function with `mapper` is not really useful @ExperimentalEvscApi suspend inline fun DatabaseClient<*>.selectSingleColumn( columnSet: ColumnSet, column: Column, - buildQuery: FieldSet.() -> Query, + buildQuery: Query.() -> Query, crossinline mapper: ColumnT.() -> DataT ): RowSet = - select(columnSet, { slice(column).buildQuery() }, { this[column].mapper() }) - - -@Deprecated("Use `selectSingleColumn`.", ReplaceWith("selectSingleColumn(columnSet, column, buildQuery, mapper)")) -@ExperimentalEvscApi -suspend inline fun DatabaseClient<*>.executeSingleColumnSelectQuery( - columnSet: ColumnSet, column: Column, buildQuery: FieldSet.() -> Query, crossinline mapper: T.() -> R -): RowSet = - selectSingleColumn(columnSet, column, buildQuery, mapper) + select(columnSet, { select(column).buildQuery() }, { this[column].mapper() }) -// TODO adapt to the new SELECT DSL or deprecate suspend fun DatabaseClient<*>.selectSingleColumn( - columnSet: ColumnSet, column: Column, buildQuery: FieldSet.() -> Query -): RowSet = - selectTableExpression(columnSet, column, buildQuery) - -@Deprecated("Use `selectSingleColumn`.", ReplaceWith("selectSingleColumn(columnSet, column, buildQuery)")) -suspend fun DatabaseClient<*>.executeSingleColumnSelectQuery( - columnSet: ColumnSet, column: Column, buildQuery: FieldSet.() -> Query + columnSet: ColumnSet, column: Column, buildQuery: Query.() -> Query ): RowSet = - selectSingleColumn(columnSet, column, buildQuery) + selectColumnSetExpression(columnSet, column, buildQuery) -// TODO adapt to the new SELECT DSL or deprecate suspend fun > DatabaseClient<*>.selectSingleEntityIdColumn( - columnSet: ColumnSet, column: Column>, buildQuery: FieldSet.() -> Query + columnSet: ColumnSet, column: Column>, buildQuery: Query.() -> Query ): RowSet = selectSingleColumn(columnSet, column, buildQuery) { value } @@ -87,7 +70,7 @@ suspend fun > DatabaseClient<*>.selectSingleEntityIdColumn( */ // see: https://github.com/JetBrains/Exposed/issues/621 suspend fun DatabaseClient<*>.selectExpression(clazz: KClass, expression: Expression): T? = - executeForVertxSqlClientRowSet(Table.Dual.slice(expression).selectAll()) + executeForVertxSqlClientRowSet(Table.Dual.select(expression)) .single()[clazz.java, 0] suspend inline fun DatabaseClient<*>.selectExpression(expression: Expression): T = diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt index c6319e5..1827f75 100644 --- a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt +++ b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt @@ -1,6 +1,10 @@ +@file:OptIn(InternalApi::class) + package com.huanshankeji.exposedvertxsqlclient.sql.mapping +import com.huanshankeji.InternalApi import com.huanshankeji.exposed.BuildWhere +import com.huanshankeji.exposed.SELECT_DSL_DEPRECATION_MESSAGE import com.huanshankeji.exposed.datamapping.DataQueryMapper import com.huanshankeji.exposed.datamapping.DataUpdateMapper import com.huanshankeji.exposed.datamapping.updateBuilderSetter @@ -30,12 +34,22 @@ suspend fun DatabaseClient<*>.executeVertxSqlClientRowQuery( ): RowSet = executeWithMapping(query, rowDataQueryMapper::rowToData) +@Deprecated( + SELECT_DSL_DEPRECATION_MESSAGE, + ReplaceWith("this.selectWithMapper(columnSet, dataQueryMapper, buildQuery)") +) @ExperimentalEvscApi suspend fun DatabaseClient<*>.select( columnSet: ColumnSet, dataQueryMapper: DataQueryMapper, buildQuery: FieldSet.() -> Query ) = executeQuery(columnSet.slice(dataQueryMapper.neededColumns).buildQuery(), dataQueryMapper) +@ExperimentalEvscApi +suspend fun DatabaseClient<*>.selectWithMapper( + columnSet: ColumnSet, dataQueryMapper: DataQueryMapper, buildQuery: Query.() -> Query +) = + executeQuery(columnSet.select(dataQueryMapper.neededColumns).buildQuery(), dataQueryMapper) + @ExperimentalEvscApi suspend fun DatabaseClient<*>.insert( table: Table, data: Data, dataUpdateMapper: DataUpdateMapper diff --git a/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index d87ca02..64e3944 100644 --- a/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -66,7 +66,7 @@ suspend fun examples(vertx: Vertx) { databaseClient.select(Examples) { select(Examples.name).where(Examples.id eq 1) }.single()[Examples.name] // This function still depends on the old SELECT DSL and will be updated. val exampleName2 = - databaseClient.selectSingleColumn(Examples, Examples.name) { selectAll().where(Examples.id eq 2) }.single() + databaseClient.selectSingleColumn(Examples, Examples.name) { where(Examples.id eq 2) }.single() val deleteRowCount1 = databaseClient.deleteWhere(Examples) { id eq 1 } assert(deleteRowCount1 == 1) diff --git a/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt b/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt index 4daca30..8f12869 100644 --- a/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt +++ b/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt @@ -3,11 +3,10 @@ package com.huanshankeji.exposedvertxsqlclient import com.huanshankeji.exposed.datamapping.classproperty.PropertyColumnMappingConfig import com.huanshankeji.exposed.datamapping.classproperty.reflectionBasedClassPropertyDataMapper import com.huanshankeji.exposedvertxsqlclient.sql.mapping.insert -import com.huanshankeji.exposedvertxsqlclient.sql.mapping.select +import com.huanshankeji.exposedvertxsqlclient.sql.mapping.selectWithMapper import io.vertx.sqlclient.Pool import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList -import org.jetbrains.exposed.sql.select // copied and adapted from https://github.com/huanshankeji/exposed-adt-mapping/blob/main/lib/src/test/kotlin/com/huanshankeji/exposed/datamapping/classproperty/Examples.kt // Update accordingly to keep the code consistent. @@ -95,7 +94,7 @@ suspend fun mappingExamples(databaseClient: DatabaseClient) { val filmWithDirectorId = FilmWithDirectorId(filmId, episodeIIFilmDetails) databaseClient.insert(Films, filmWithDirectorId, Mappers.filmWithDirectorId) // insert with the ID - val fullFilms = databaseClient.select(filmsLeftJoinDirectors, Mappers.fullFilm) { - select(Films.filmId inList listOf(1, 2)) // This API still depends on the old SELECT DSL and will be refactored. + val fullFilms = databaseClient.selectWithMapper(filmsLeftJoinDirectors, Mappers.fullFilm) { + where(Films.filmId inList listOf(1, 2)) // This API still depends on the old SELECT DSL and will be refactored. } } From f6312945ad4dac97c7fdb9377b390ad922c07920 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 14 Nov 2024 20:54:45 +0800 Subject: [PATCH 14/70] Run `apiDump` and review the changes --- lib/api/exposed-vertx-sql-client-postgresql.api | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/api/exposed-vertx-sql-client-postgresql.api b/lib/api/exposed-vertx-sql-client-postgresql.api index e1da900..75703dc 100644 --- a/lib/api/exposed-vertx-sql-client-postgresql.api +++ b/lib/api/exposed-vertx-sql-client-postgresql.api @@ -180,8 +180,6 @@ public final class com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSqlK 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 executeInsertIgnore (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Table;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun executeSingleColumnSelectQuery (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 executeSingleColumnSelectQuery (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 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; @@ -193,11 +191,11 @@ public final class com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSqlK 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 selectTableExpression (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 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; @@ -217,6 +215,7 @@ public final class com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseCl public static final fun insert (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 insertIgnore (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 select (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 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 update (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 update$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; } From 31629f3b0504f7cb4c9ca62ea2e9809802a2f18b Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 14 Nov 2024 21:53:47 +0800 Subject: [PATCH 15/70] Remove an obsolete TODO that should've been removed in commit c03ede0a2d85a4fbe55ada8d6e5033313d937243 --- .../huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt index a6fe966..3ce0e8f 100644 --- a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt +++ b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt @@ -25,7 +25,6 @@ suspend inline fun DatabaseClient<*>.select( ): RowSet = executeQuery(columnSet.buildQuery(), resultRowMapper) -// TODO adapt to the new SELECT DSL or deprecate suspend inline fun DatabaseClient<*>.select( columnSet: ColumnSet, buildQuery: ColumnSet.() -> Query ): RowSet = From a105a4d648a00d2c260251028756f4cf1861e0a3 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 14 Nov 2024 23:30:35 +0800 Subject: [PATCH 16/70] Rename the SQL DSL functions taking mapper parameters, adding "withMapper" prefixes Resolve #6 Two "delete" functions were mistakenly added in this file and its `com.huanshankeji.exposedvertxsqlclient.sql.mapping` package, and are now moved out into `com.huanshankeji.exposedvertxsqlclient.sql`. A TODO is removed with its content moved into README.md. --- README.md | 9 ++-- .../sql/DatabaseClientSql.kt | 11 +++++ .../mapping/DatabaseClientSqlWithMapper.kt | 47 +++++-------------- .../exposedvertxsqlclient/Examples.kt | 3 -- .../exposedvertxsqlclient/MappingExamples.kt | 8 ++-- 5 files changed, 31 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index a7d2213..ebfb3ea 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,8 @@ withContext(Dispatchers.IO) { #### Core APIs -With these core APIs, you create and execute Exposed `Statement`s. You don't need to learn many new APIs, and the `Statement`s are more composable and easily editable. +With these core APIs, you create and execute Exposed `Statement`s. You don't need to learn many new APIs, and the +`Statement`s are more composable and easily editable. For example, you can move a query into an adapted subquery. ```kotlin // The Exposed `Table` extension functions `insert`, `update`, and `delete` execute eagerly so `insertStatement`, `updateStatement`, `deleteStatement` have to be used. @@ -109,16 +110,16 @@ Please read [that library's basic usage guide](https://github.com/huanshankeji/e ```kotlin val directorId = 1 val director = Director(directorId, "George Lucas") -databaseClient.insert(Directors, director, Mappers.director) +databaseClient.insertWithMapper(Directors, director, Mappers.director) val episodeIFilmDetails = FilmDetails(1, "Star Wars: Episode I – The Phantom Menace", directorId) // insert without the ID since it's `AUTO_INCREMENT` -databaseClient.insert(Films, episodeIFilmDetails, Mappers.filmDetailsWithDirectorId) +databaseClient.insertWithMapper(Films, episodeIFilmDetails, Mappers.filmDetailsWithDirectorId) val filmId = 2 val episodeIIFilmDetails = FilmDetails(2, "Star Wars: Episode II – Attack of the Clones", directorId) val filmWithDirectorId = FilmWithDirectorId(filmId, episodeIIFilmDetails) -databaseClient.insert(Films, filmWithDirectorId, Mappers.filmWithDirectorId) // insert with the ID +databaseClient.insertWithMapper(Films, filmWithDirectorId, Mappers.filmWithDirectorId) // insert with the ID val fullFilms = databaseClient.selectWithMapper(filmsLeftJoinDirectors, Mappers.fullFilm) { where(Films.filmId inList listOf(1, 2)) // This API still depends on the old SELECT DSL and will be refactored. diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt index 3ce0e8f..bcada20 100644 --- a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt +++ b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt @@ -185,3 +185,14 @@ suspend fun > Databa where: BuildWhere? = null, limit: Int? = null, body: T.(UpdateStatement, E) -> Unit ) = batchUpdate(table, data.sortedBy(selector), where, limit, body) + + +suspend fun DatabaseClient<*>.deleteWhere( + table: T, limit: Int? = null, offset: Long? = null, op: T.(ISqlExpressionBuilder) -> Op +) = + executeUpdate(table.deleteWhereStatement(limit, offset, op)) + +suspend fun DatabaseClient<*>.deleteIgnoreWhere( + table: T, limit: Int? = null, offset: Long? = null, op: T.(ISqlExpressionBuilder) -> Op +) = + executeUpdate(table.deleteIgnoreWhereStatement(limit, offset, op)) diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt index 1827f75..2563e6a 100644 --- a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt +++ b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapper.kt @@ -1,63 +1,48 @@ -@file:OptIn(InternalApi::class) - package com.huanshankeji.exposedvertxsqlclient.sql.mapping -import com.huanshankeji.InternalApi import com.huanshankeji.exposed.BuildWhere -import com.huanshankeji.exposed.SELECT_DSL_DEPRECATION_MESSAGE import com.huanshankeji.exposed.datamapping.DataQueryMapper import com.huanshankeji.exposed.datamapping.DataUpdateMapper import com.huanshankeji.exposed.datamapping.updateBuilderSetter -import com.huanshankeji.exposed.deleteIgnoreWhereStatement -import com.huanshankeji.exposed.deleteWhereStatement import com.huanshankeji.exposedvertxsqlclient.DatabaseClient import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi import com.huanshankeji.exposedvertxsqlclient.sql.* import com.huanshankeji.vertx.sqlclient.datamapping.RowDataQueryMapper import io.vertx.sqlclient.RowSet -import org.jetbrains.exposed.sql.* +import org.jetbrains.exposed.sql.ColumnSet +import org.jetbrains.exposed.sql.Query +import org.jetbrains.exposed.sql.Table import org.jetbrains.exposed.sql.statements.UpdateBuilder // TODO move to a separate module -// TODO Note that using these DSLs reduces the composability of statements, for example, when moving a query into a subquery. (this statement can be moved into docs some day) @ExperimentalEvscApi -suspend fun DatabaseClient<*>.executeQuery( +suspend fun DatabaseClient<*>.executeQueryWithMapper( query: Query, dataQueryMapper: DataQueryMapper ): RowSet = executeWithMapping(query) { row -> dataQueryMapper.resultRowToData(row.toExposedResultRowWithTransaction(query)) } @ExperimentalEvscApi -suspend fun DatabaseClient<*>.executeVertxSqlClientRowQuery( +suspend fun DatabaseClient<*>.executeVertxSqlClientRowQueryWithMapper( query: Query, rowDataQueryMapper: RowDataQueryMapper ): RowSet = executeWithMapping(query, rowDataQueryMapper::rowToData) -@Deprecated( - SELECT_DSL_DEPRECATION_MESSAGE, - ReplaceWith("this.selectWithMapper(columnSet, dataQueryMapper, buildQuery)") -) -@ExperimentalEvscApi -suspend fun DatabaseClient<*>.select( - columnSet: ColumnSet, dataQueryMapper: DataQueryMapper, buildQuery: FieldSet.() -> Query -) = - executeQuery(columnSet.slice(dataQueryMapper.neededColumns).buildQuery(), dataQueryMapper) - @ExperimentalEvscApi suspend fun DatabaseClient<*>.selectWithMapper( columnSet: ColumnSet, dataQueryMapper: DataQueryMapper, buildQuery: Query.() -> Query ) = - executeQuery(columnSet.select(dataQueryMapper.neededColumns).buildQuery(), dataQueryMapper) + executeQueryWithMapper(columnSet.select(dataQueryMapper.neededColumns).buildQuery(), dataQueryMapper) @ExperimentalEvscApi -suspend fun DatabaseClient<*>.insert( +suspend fun DatabaseClient<*>.insertWithMapper( table: Table, data: Data, dataUpdateMapper: DataUpdateMapper ) = insert(table, dataUpdateMapper.updateBuilderSetter(data)) @ExperimentalEvscApi -suspend fun DatabaseClient<*>.insertIgnore( +suspend fun DatabaseClient<*>.insertIgnoreWithMapper( table: Table, data: Data, dataUpdateMapper: DataUpdateMapper ) = insertIgnore(table, dataUpdateMapper.updateBuilderSetter(data)) @@ -70,13 +55,13 @@ fun DataUpdateMapper.batchUpdateBuild // TODO: consider removing the table param by adding it to `DataUpdateMapper` @ExperimentalEvscApi -suspend fun DatabaseClient<*>.batchInsert( +suspend fun DatabaseClient<*>.batchInsertWithMapper( table: Table, data: Iterable, dataUpdateMapper: DataUpdateMapper ) = batchInsert(table, data, dataUpdateMapper.batchUpdateBuilderSetter()) @ExperimentalEvscApi -suspend fun DatabaseClient<*>.batchInsertIgnore( +suspend fun DatabaseClient<*>.batchInsertIgnoreWithMapper( table: Table, data: Iterable, dataUpdateMapper: DataUpdateMapper ) = batchInsertIgnore(table, data, dataUpdateMapper.batchUpdateBuilderSetter()) @@ -86,17 +71,7 @@ suspend fun DatabaseClient<*>.batchInsertIgnore( * In most cases you should specify the fields to update in a more detailed way instead of using this function. */ @ExperimentalEvscApi -suspend fun DatabaseClient<*>.update( +suspend fun DatabaseClient<*>.updateWithMapper( table: Table, where: BuildWhere? = null, limit: Int? = null, data: Data, dataUpdateMapper: DataUpdateMapper ) = update(table, where, limit, dataUpdateMapper.updateBuilderSetter(data)) - -suspend fun DatabaseClient<*>.deleteWhere( - table: T, limit: Int? = null, offset: Long? = null, op: T.(ISqlExpressionBuilder) -> Op -) = - executeUpdate(table.deleteWhereStatement(limit, offset, op)) - -suspend fun DatabaseClient<*>.deleteIgnoreWhere( - table: T, limit: Int? = null, offset: Long? = null, op: T.(ISqlExpressionBuilder) -> Op -) = - executeUpdate(table.deleteIgnoreWhereStatement(limit, offset, op)) diff --git a/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index 64e3944..e8d7393 100644 --- a/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -2,15 +2,12 @@ package com.huanshankeji.exposedvertxsqlclient import com.huanshankeji.exposed.* import com.huanshankeji.exposedvertxsqlclient.sql.* -import com.huanshankeji.exposedvertxsqlclient.sql.mapping.deleteIgnoreWhere -import com.huanshankeji.exposedvertxsqlclient.sql.mapping.deleteWhere import io.vertx.core.Vertx import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.jetbrains.exposed.sql.selectAll object Examples : IntIdTable("examples") { val name = varchar("name", 64) diff --git a/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt b/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt index 8f12869..24dac9b 100644 --- a/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt +++ b/lib/src/test/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt @@ -2,7 +2,7 @@ package com.huanshankeji.exposedvertxsqlclient import com.huanshankeji.exposed.datamapping.classproperty.PropertyColumnMappingConfig import com.huanshankeji.exposed.datamapping.classproperty.reflectionBasedClassPropertyDataMapper -import com.huanshankeji.exposedvertxsqlclient.sql.mapping.insert +import com.huanshankeji.exposedvertxsqlclient.sql.mapping.insertWithMapper import com.huanshankeji.exposedvertxsqlclient.sql.mapping.selectWithMapper import io.vertx.sqlclient.Pool import org.jetbrains.exposed.dao.id.IntIdTable @@ -83,16 +83,16 @@ object Mappers { suspend fun mappingExamples(databaseClient: DatabaseClient) { val directorId = 1 val director = Director(directorId, "George Lucas") - databaseClient.insert(Directors, director, Mappers.director) + databaseClient.insertWithMapper(Directors, director, Mappers.director) val episodeIFilmDetails = FilmDetails(1, "Star Wars: Episode I – The Phantom Menace", directorId) // insert without the ID since it's `AUTO_INCREMENT` - databaseClient.insert(Films, episodeIFilmDetails, Mappers.filmDetailsWithDirectorId) + databaseClient.insertWithMapper(Films, episodeIFilmDetails, Mappers.filmDetailsWithDirectorId) val filmId = 2 val episodeIIFilmDetails = FilmDetails(2, "Star Wars: Episode II – Attack of the Clones", directorId) val filmWithDirectorId = FilmWithDirectorId(filmId, episodeIIFilmDetails) - databaseClient.insert(Films, filmWithDirectorId, Mappers.filmWithDirectorId) // insert with the ID + databaseClient.insertWithMapper(Films, filmWithDirectorId, Mappers.filmWithDirectorId) // insert with the ID val fullFilms = databaseClient.selectWithMapper(filmsLeftJoinDirectors, Mappers.fullFilm) { where(Films.filmId inList listOf(1, 2)) // This API still depends on the old SELECT DSL and will be refactored. From 6b1a8721dd1eae5ad229fe12578af4b085b584c6 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 14 Nov 2024 23:32:13 +0800 Subject: [PATCH 17/70] Run `apiDump` --- .../exposed-vertx-sql-client-postgresql.api | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/api/exposed-vertx-sql-client-postgresql.api b/lib/api/exposed-vertx-sql-client-postgresql.api index 75703dc..ee71443 100644 --- a/lib/api/exposed-vertx-sql-client-postgresql.api +++ b/lib/api/exposed-vertx-sql-client-postgresql.api @@ -179,6 +179,10 @@ public final class com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSqlK 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; @@ -203,21 +207,16 @@ public final class com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSqlK } public final class com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseClientSqlWithMapperKt { - public static final fun batchInsert (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 batchInsertIgnore (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 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 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 executeQuery (Lcom/huanshankeji/exposedvertxsqlclient/DatabaseClient;Lorg/jetbrains/exposed/sql/Query;Lcom/huanshankeji/exposed/datamapping/DataQueryMapper;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun executeVertxSqlClientRowQuery (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 insert (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 insertIgnore (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 select (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 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 update (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 update$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 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 { From db344776fdfd8b99d1c91cb70ab4ba780f11fd79 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 14 Nov 2024 23:40:06 +0800 Subject: [PATCH 18/70] Use `TableAwareWithSqlExpressionBuilderBuildWhere`, and run `apiDump` which doesn't make any difference --- .../exposedvertxsqlclient/sql/DatabaseClientSql.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt index bcada20..4d2657a 100644 --- a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt +++ b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt @@ -188,11 +188,11 @@ suspend fun > Databa suspend fun DatabaseClient<*>.deleteWhere( - table: T, limit: Int? = null, offset: Long? = null, op: T.(ISqlExpressionBuilder) -> Op + table: T, limit: Int? = null, offset: Long? = null, op: TableAwareWithSqlExpressionBuilderBuildWhere ) = executeUpdate(table.deleteWhereStatement(limit, offset, op)) suspend fun DatabaseClient<*>.deleteIgnoreWhere( - table: T, limit: Int? = null, offset: Long? = null, op: T.(ISqlExpressionBuilder) -> Op + table: T, limit: Int? = null, offset: Long? = null, op: TableAwareWithSqlExpressionBuilderBuildWhere ) = executeUpdate(table.deleteIgnoreWhereStatement(limit, offset, op)) From eef978fc67fd2dbcadb584aea2c15328db731f15 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 14 Nov 2024 23:52:13 +0800 Subject: [PATCH 19/70] Add some `@see` references in the KDocs for batch execution --- .../exposedvertxsqlclient/DatabaseClient.kt | 5 ++++- .../exposedvertxsqlclient/sql/DatabaseClientSql.kt | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index b82985e..8dddea0 100644 --- a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -290,6 +290,9 @@ class DatabaseClient( suspend fun executeBatchForVertxSqlClientRowSetSequence(statements: Iterable>): Sequence> = executeBatch(statements) { this } + /** + * @see executeBatch + */ @ExperimentalEvscApi suspend inline fun executeBatchQuery( fieldSet: FieldSet, queries: Iterable, crossinline resultRowMapper: ResultRow.() -> Data @@ -310,7 +313,7 @@ class DatabaseClient( */ /** * Executes a batch of update statements, including [InsertStatement] and [UpdateStatement]. - * @see org.jetbrains.exposed.sql.batchInsert + * @see executeBatch * @return a sequence of the update counts of the update statements in the batch. */ suspend fun executeBatchUpdate( diff --git a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt index 4d2657a..a6e0416 100644 --- a/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt +++ b/lib/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt @@ -134,7 +134,9 @@ suspend fun DatabaseClient<*>.selectBatch( ): Sequence> = executeBatchQuery(fieldSet, data.asSequence().map { fieldSet.buildQuery(it) }.asIterable()) - +/** + * @see DatabaseClient.executeBatchUpdate + */ suspend fun DatabaseClient<*>.batchInsert( table: T, data: Iterable, body: T.(InsertStatement, E) -> Unit ) = @@ -143,6 +145,9 @@ suspend fun DatabaseClient<*>.batchInsert( }.asIterable()) .forEach { dbAssert(it == 1) } +/** + * @see DatabaseClient.executeBatchUpdate + */ suspend fun DatabaseClient<*>.batchInsertIgnore( table: T, data: Iterable, body: T.(InsertStatement, E) -> Unit ) = @@ -154,6 +159,7 @@ suspend fun DatabaseClient<*>.batchInsertIgnore( /** * This function is not conventional and it usages are likely to degrade performance. + * @see DatabaseClient.executeBatchUpdate */ @ExperimentalEvscApi suspend fun DatabaseClient<*>.batchInsertSelect( @@ -161,6 +167,10 @@ suspend fun DatabaseClient<*>.batchInsertSelect( ) = executeBatchUpdate(statements) +/** + * @see DatabaseClient.executeBatchUpdate + * @see sortDataAndBatchUpdate + */ suspend fun DatabaseClient<*>.batchUpdate( table: T, data: Iterable, where: BuildWhere? = null, limit: Int? = null, body: T.(UpdateStatement, E) -> Unit ) = @@ -170,6 +180,7 @@ suspend fun DatabaseClient<*>.batchUpdate( /** * @return a sequence indicating whether each update statement is updated in the batch. + * @see batchUpdate */ suspend fun DatabaseClient<*>.batchSingleOrNoUpdate( table: T, data: Iterable, where: BuildWhere? = null, limit: Int? = null, body: T.(UpdateStatement, E) -> Unit @@ -178,6 +189,7 @@ suspend fun DatabaseClient<*>.batchSingleOrNoUpdate( /** * @see sortDataAndExecuteBatch + * @see batchUpdate */ suspend fun > DatabaseClient<*>.sortDataAndBatchUpdate( table: T, From c5347502825cd77711ebeeed28a07819e72081f1 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Fri, 15 Nov 2024 21:52:26 +0800 Subject: [PATCH 20/70] 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 21/70] 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 22/70] 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 23/70] 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 24/70] 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 25/70] 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 26/70] 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 27/70] 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 28/70] 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 29/70] 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 30/70] 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 31/70] 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 32/70] 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 33/70] 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 34/70] 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 35/70] 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 36/70] 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 37/70] 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 38/70] 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 39/70] 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 40/70] 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 41/70] 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 42/70] 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 43/70] 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 44/70] 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 45/70] 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 From 650846815ba3cd3be4a188519215f64af93a042a Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 21 Nov 2024 00:04:34 +0800 Subject: [PATCH 46/70] Remove an unnecessary line break --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index c0cf1f9..34f51fd 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,7 @@ Only PostgreSQL with [Reactive PostgreSQL Client](https://vertx.io/docs/vertx-pg ## 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. +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 From d3739436e686039168e5ac47d9710465b75e0a38 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sun, 24 Nov 2024 13:54:03 +0800 Subject: [PATCH 47/70] Bump Exposed to 0.56.0 --- buildSrc/src/main/kotlin/VersionsAndDependencies.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt index 096a8e3..8014c4d 100644 --- a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt +++ b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt @@ -4,8 +4,8 @@ import com.huanshankeji.CommonVersions val projectVersion = "0.5.0-SNAPSHOT" -// don't use a snapshot version in a main branch -val commonVersions = CommonVersions(kotlinCommon = "0.6.0-SNAPSHOT") +// TODO don't use a snapshot version in a main branch +val commonVersions = CommonVersions(kotlinCommon = "0.6.0-SNAPSHOT", exposed = "0.56.0") val commonDependencies = CommonDependencies(commonVersions) val commonGradleClasspathDependencies = CommonGradleClasspathDependencies(commonVersions) From 5cf8b81992b18e7950c782e6b8e26f326453c0b0 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sun, 24 Nov 2024 14:01:45 +0800 Subject: [PATCH 48/70] Move a TODO and the "exposed-jdbc" dependency to the "postgresql" module --- core/build.gradle.kts | 2 -- postgresql/build.gradle.kts | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index eb0ab79..88efa6b 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -4,8 +4,6 @@ plugins { dependencies { api(commonDependencies.exposed.core()) // TODO: use `implementation` when possible - // 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()) with(commonDependencies.vertx) { diff --git a/postgresql/build.gradle.kts b/postgresql/build.gradle.kts index 0321367..ad2eebd 100644 --- a/postgresql/build.gradle.kts +++ b/postgresql/build.gradle.kts @@ -8,6 +8,8 @@ dependencies { with(commonDependencies.vertx) { implementation(platformStackDepchain()) } // needed implementation(cpnProject(project, ":core")) + // 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")) runtimeOnly(commonDependencies.postgreSql()) implementation(commonDependencies.vertx.moduleWithoutVersion("pg-client")) implementation(commonDependencies.kotlinCommon.core()) // for `Untested` From 853c0ef9165a004089217354c6a7a2b2d233ca66 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sun, 24 Nov 2024 16:10:58 +0800 Subject: [PATCH 49/70] Deprecate `ConnectionType` --- .../com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt index 54d1b56..ca1a73e 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt @@ -1,5 +1,6 @@ package com.huanshankeji.exposedvertxsqlclient +@Deprecated("This class seems no longer used.") enum class ConnectionType { Socket, UnixDomainSocketWithPeerAuthentication } \ No newline at end of file From 62a09a318794d24f77a7dd2cbbd3ac01bf9a64e8 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sun, 24 Nov 2024 17:03:42 +0800 Subject: [PATCH 50/70] Undo the previous commit and add `LocalConnectionConfig.getConnectionConfig` --- .../huanshankeji/exposedvertxsqlclient/ConnectionType.kt | 2 +- .../exposedvertxsqlclient/local/LocalConnectionConfig.kt | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt index ca1a73e..03ff607 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/ConnectionType.kt @@ -1,6 +1,6 @@ package com.huanshankeji.exposedvertxsqlclient -@Deprecated("This class seems no longer used.") +//@Deprecated("This class seems no longer used.") enum class ConnectionType { Socket, UnixDomainSocketWithPeerAuthentication } \ No newline at end of file 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 c4d0e0b..997c52b 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionConfig.kt @@ -1,6 +1,7 @@ package com.huanshankeji.exposedvertxsqlclient.local import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig +import com.huanshankeji.exposedvertxsqlclient.ConnectionType import com.huanshankeji.exposedvertxsqlclient.EvscConfig import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi import com.huanshankeji.net.LOCALHOST @@ -27,6 +28,12 @@ class LocalConnectionConfig( val unixDomainSocketWithPeerAuthenticationConnectionConfig = ConnectionConfig.UnixDomainSocketWithPeerAuthentication(unixDomainSocketPath, user, database) + + fun getConnectionConfig(connectionType: ConnectionType) = + when (connectionType) { + ConnectionType.Socket -> socketConnectionConfig + ConnectionType.UnixDomainSocketWithPeerAuthentication -> unixDomainSocketWithPeerAuthenticationConnectionConfig + } } @ExperimentalEvscApi From b835816c478905d7cc78b5321cb3c67d560fc113 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Mon, 25 Nov 2024 13:51:33 +0800 Subject: [PATCH 51/70] Move the module-wide to `conventions.gradle.kts` --- buildSrc/src/main/kotlin/conventions.gradle.kts | 5 +++++ buildSrc/src/main/kotlin/lib-conventions.gradle.kts | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/kotlin/conventions.gradle.kts b/buildSrc/src/main/kotlin/conventions.gradle.kts index 0015b4b..922292b 100644 --- a/buildSrc/src/main/kotlin/conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/conventions.gradle.kts @@ -1,4 +1,5 @@ import com.huanshankeji.team.repositoriesAddTeamGithubPackagesMavenRegistry +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask plugins { id("com.huanshankeji.team.with-group") @@ -14,3 +15,7 @@ repositoriesAddTeamGithubPackagesMavenRegistry("kotlin-common") kotlin.jvmToolchain(8) version = projectVersion + +tasks.named>("compileKotlin").configure { + compilerOptions.freeCompilerArgs.add("-opt-in=com.huanshankeji.exposedvertxsqlclient.InternalApi") +} diff --git a/buildSrc/src/main/kotlin/lib-conventions.gradle.kts b/buildSrc/src/main/kotlin/lib-conventions.gradle.kts index 30d8936..e679e3d 100644 --- a/buildSrc/src/main/kotlin/lib-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/lib-conventions.gradle.kts @@ -1,6 +1,5 @@ import com.huanshankeji.team.`Shreck Ye` import com.huanshankeji.team.pomForTeamDefaultOpenSource -import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask plugins { id("conventions") @@ -14,7 +13,3 @@ publishing.publications.getByName("maven") { `Shreck Ye`() } } - -tasks.named>("compileKotlin").configure { - compilerOptions.freeCompilerArgs.add("-opt-in=com.huanshankeji.exposedvertxsqlclient.InternalApi") -} From 4d0075da0b2f89375efd88039050d50381f1cd28 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Mon, 25 Nov 2024 16:32:46 +0800 Subject: [PATCH 52/70] Make `DatabaseClient` implement `CoroutineAutoCloseable` --- core/build.gradle.kts | 2 ++ .../huanshankeji/exposedvertxsqlclient/DatabaseClient.kt | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 88efa6b..5b5c918 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -18,4 +18,6 @@ dependencies { implementation(commonDependencies.arrow.core()) implementation(commonDependencies.kotlinCommon.net()) + + api(commonDependencies.kotlinCommon.coroutines()) // Exposed the `use` function } diff --git a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt index 1a55352..ba3b423 100644 --- a/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt +++ b/core/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/DatabaseClient.kt @@ -1,7 +1,9 @@ package com.huanshankeji.exposedvertxsqlclient import arrow.core.* +import com.huanshankeji.ExperimentalApi import com.huanshankeji.collections.singleOrNullIfEmpty +import com.huanshankeji.kotlinx.coroutine.CoroutineAutoCloseable import com.huanshankeji.vertx.kotlin.coroutines.coroutineToFuture import com.huanshankeji.vertx.kotlin.sqlclient.executeBatchAwaitForSqlResultSequence import io.vertx.core.buffer.Buffer @@ -77,15 +79,15 @@ internal val logger = LoggerFactory.getLogger(DatabaseClient::class.java) * * @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) +@OptIn(ExperimentalApi::class) 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 -) { - suspend fun close() { +) : CoroutineAutoCloseable { + override suspend fun close() { vertxSqlClient.close().coAwait() // How to close The Exposed `Database`? } From 4a4705369a3d7f213c77e5f6d5269a0e4ed89920 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Mon, 25 Nov 2024 16:36:31 +0800 Subject: [PATCH 53/70] Run `apiDump` and review the changes --- core/api/exposed-vertx-sql-client-core.api | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/api/exposed-vertx-sql-client-core.api b/core/api/exposed-vertx-sql-client-core.api index 081ca0f..fe39f10 100644 --- a/core/api/exposed-vertx-sql-client-core.api +++ b/core/api/exposed-vertx-sql-client-core.api @@ -34,10 +34,10 @@ public final class com/huanshankeji/exposedvertxsqlclient/ConnectionType : java/ public static fun values ()[Lcom/huanshankeji/exposedvertxsqlclient/ConnectionType; } -public final class com/huanshankeji/exposedvertxsqlclient/DatabaseClient { +public final class com/huanshankeji/exposedvertxsqlclient/DatabaseClient : com/huanshankeji/kotlinx/coroutine/CoroutineAutoCloseable { public fun (Lio/vertx/sqlclient/SqlClient;Lorg/jetbrains/exposed/sql/Database;ZZ)V public synthetic fun (Lio/vertx/sqlclient/SqlClient;Lorg/jetbrains/exposed/sql/Database;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun close (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public fun close (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun createTable (Lorg/jetbrains/exposed/sql/Table;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun doExecute (Lorg/jetbrains/exposed/sql/statements/Statement;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun dropTable (Lorg/jetbrains/exposed/sql/Table;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -130,6 +130,7 @@ public final class com/huanshankeji/exposedvertxsqlclient/local/LocalConnectionC public static final field SOCKET_HOST Ljava/lang/String; 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 getConnectionConfig (Lcom/huanshankeji/exposedvertxsqlclient/ConnectionType;)Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig; public final fun getDatabase ()Ljava/lang/String; public final fun getSocketConnectionConfig ()Lcom/huanshankeji/exposedvertxsqlclient/ConnectionConfig$Socket; public final fun getSocketConnectionPassword ()Ljava/lang/String; From 47d4006569edb7802a4fb6f8db3ec5b43721437d Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Mon, 25 Nov 2024 20:48:42 +0800 Subject: [PATCH 54/70] Add a version of `selectWithMapper` without `buildQuery` --- .../sql/mapping/DatabaseClientSqlWithMapper.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql-dsl-with-mapper/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 index 2563e6a..b45c68e 100644 --- a/sql-dsl-with-mapper/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 @@ -35,6 +35,12 @@ suspend fun DatabaseClient<*>.selectWithMapper( ) = executeQueryWithMapper(columnSet.select(dataQueryMapper.neededColumns).buildQuery(), dataQueryMapper) +@ExperimentalEvscApi +suspend fun DatabaseClient<*>.selectWithMapper( + columnSet: ColumnSet, dataQueryMapper: DataQueryMapper +) = + selectWithMapper(columnSet, dataQueryMapper) { this } + @ExperimentalEvscApi suspend fun DatabaseClient<*>.insertWithMapper( table: Table, data: Data, dataUpdateMapper: DataUpdateMapper From 44ef51474e280cc3962889f713f9454b6849dc25 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Mon, 25 Nov 2024 20:49:13 +0800 Subject: [PATCH 55/70] Run `apiDump` --- .../api/exposed-vertx-sql-client-sql-dsl-with-mapper.api | 1 + 1 file changed, 1 insertion(+) 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 5fff915..89457fe 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 @@ -6,6 +6,7 @@ public final class com/huanshankeji/exposedvertxsqlclient/sql/mapping/DatabaseCl 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/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; From 74dca801429e84f121950d43af0a8e93feb84b1b Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Tue, 26 Nov 2024 11:04:38 +0800 Subject: [PATCH 56/70] Bump "exposed-adt-mapping" to v0.3.0-SNAPSHOT which depends on Exposed v0.56.0 to resolve some binary incompatibilities as found out in internal projects, and update README.md to remind people about the Exposed version --- README.md | 20 ++++++++++++------- .../main/kotlin/VersionsAndDependencies.kt | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 34f51fd..7032a7d 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,18 @@ Only PostgreSQL with [Reactive PostgreSQL Client](https://vertx.io/docs/vertx-pg 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 +## Add to your dependencies + +### The Maven coordinates ```kotlin -"com.huanshankeji:exposed-vertx-sql-client-$module:$evscVersion" +"com.huanshankeji:exposed-vertx-sql-client-$module:$libraryVersion" ``` +### **Important note** + +As Exposed is a library that has not reached stability yet and often has incompatible changes, you are recommended to stick to the same version of Exposed used by this library. The current version is v0.56.0. + ## API documentation See the [hosted API documentation](https://huanshankeji.github.io/exposed-vertx-sql-client/) for the APIs. @@ -31,7 +37,7 @@ Here is a basic usage guide. 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") +implementation("com.huanshankeji:exposed-vertx-sql-client-postgresql:$libraryVersion") ``` ### Since v0.5.0 @@ -39,13 +45,13 @@ implementation("com.huanshankeji:exposed-vertx-sql-client-postgresql:0.4.0") Add the core module to your dependencies with the Gradle build script: ```kotlin -implementation("com.huanshankeji:exposed-vertx-sql-client-core:$evscVersion") +implementation("com.huanshankeji:exposed-vertx-sql-client-core:$libraryVersion") ``` And add an RDBMS module, for example, the PostgreSQL module: ```kotlin -implementation("com.huanshankeji:exposed-vertx-sql-client-postgresql:$evscVersion") +implementation("com.huanshankeji:exposed-vertx-sql-client-postgresql:$libraryVersion") ``` ### Create a `DatabaseClient` @@ -144,7 +150,7 @@ With the extension SQL DSL APIs, your code becomes more concise, but it might be Gradle dependency configuration (only needed since v0.5.0): ```kotlin -implementation("com.huanshankeji:exposed-vertx-sql-client-sql-dsl:$evscVersion") +implementation("com.huanshankeji:exposed-vertx-sql-client-sql-dsl:$libraryVersion") ``` Example code: @@ -176,7 +182,7 @@ Please read [that library's basic usage guide](https://github.com/huanshankeji/e Gradle dependency configuration (only needed since v0.5.0): ```kotlin -implementation("com.huanshankeji:exposed-vertx-sql-client-sql-dsl-with-mapper:$evscVersion") +implementation("com.huanshankeji:exposed-vertx-sql-client-sql-dsl-with-mapper:$libraryVersion") ``` Example code: diff --git a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt index 8014c4d..37b4828 100644 --- a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt +++ b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt @@ -10,5 +10,5 @@ val commonDependencies = CommonDependencies(commonVersions) val commonGradleClasspathDependencies = CommonGradleClasspathDependencies(commonVersions) object DependencyVersions { - val exposedAdtMapping = "0.2.0" + val exposedAdtMapping = "0.3.0-SNAPSHOT" // TODO don't use a snapshot version in a main branch } From 4c64c624c771365c0c9a4f2e5ee63a9e2d30cc12 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Tue, 26 Nov 2024 11:12:49 +0800 Subject: [PATCH 57/70] Give up (maybe temporarily) calling `PgPoolOptions.setUpConventionally` because the following error occurs probably when calling `withTransaction` in an internal project: ``` Cannot acquire a connection on a pipelined pool io.vertx.core.impl.NoStackTraceThrowable: Cannot acquire a connection on a pipelined pool ``` --- .../postgresql/vertx/pgclient/PgClients.kt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt b/postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt index 21542cd..700f748 100644 --- a/postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt +++ b/postgresql/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/postgresql/vertx/pgclient/PgClients.kt @@ -9,7 +9,6 @@ import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.CoConnectHandler import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createGenericSqlClient import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createGenericSqlClientWithBuilder import com.huanshankeji.exposedvertxsqlclient.vertx.sqlclient.createGenericSqlConnection -import com.huanshankeji.vertx.pgclient.setUpConventionally import io.vertx.core.Vertx import io.vertx.pgclient.PgBuilder import io.vertx.pgclient.PgConnectOptions @@ -60,8 +59,6 @@ fun createPgClient( ) /** - * [PgPoolOptions.pipelined] is enabled by default. - * @see PgPoolOptions.setUpConventionally * @see createGenericSqlClient */ fun createPgPool( @@ -76,10 +73,7 @@ fun createPgPool( connectionConfig, PgBuilder.pool(), extraPgConnectOptions, - { - setUpConventionally() - extraPoolOptions() - }, + extraPoolOptions, connectHandlerExtra ) From f2b15f5aa626ff82cf051efcedc7b0d11eb4ae15 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Tue, 26 Nov 2024 19:23:57 +0800 Subject: [PATCH 58/70] Add a some new benchmarks to benchmark awaiting dummy `async`s in `runBlocking` as a comparison for `TransactionBenchmark` --- .../benchmark/coroutine/AwaitAsyncs.kt | 10 ++++++ ...eterizedRunBlockingAwaitAsyncsBenchmark.kt | 34 +++++++++++++++++++ .../RunBlockingAwaitAsyncsBenchmark.kt | 15 ++++++++ 3 files changed, 59 insertions(+) create mode 100644 integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AwaitAsyncs.kt create mode 100644 integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt create mode 100644 integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AwaitAsyncs.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AwaitAsyncs.kt new file mode 100644 index 0000000..46f2931 --- /dev/null +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AwaitAsyncs.kt @@ -0,0 +1,10 @@ +package com.huanshankeji.exposed.benchmark.coroutine + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll + +@Suppress("SuspendFunctionOnCoroutineScope") +internal suspend inline fun CoroutineScope.await1MAasyncs() { + List(1 shl 20) { async {} }.awaitAll() +} diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt new file mode 100644 index 0000000..25d48dd --- /dev/null +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt @@ -0,0 +1,34 @@ +package com.huanshankeji.exposed.benchmark.coroutine + +import com.huanshankeji.exposed.benchmark.AbstractBenchmark +import com.huanshankeji.exposed.benchmark.TransactionBenchmark +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Param +import kotlinx.coroutines.* + +/** + * As a comparison for [TransactionBenchmark]. + */ +class ParameterizedRunBlockingAwaitAsyncsBenchmark : AbstractBenchmark() { + enum class DispatcherArgumentEnum { + Default, IO, SingleThread + } + + @Param + lateinit var dispatcherArgumentEnum: DispatcherArgumentEnum + + @OptIn(ExperimentalCoroutinesApi::class, DelicateCoroutinesApi::class) + val singleThreadContext = newSingleThreadContext("single thread") + + @Benchmark + fun runBlockingAwait1MAsyncsWithDispatcherArgument() = + runBlocking( + when (dispatcherArgumentEnum) { + DispatcherArgumentEnum.Default -> Dispatchers.Default + DispatcherArgumentEnum.IO -> Dispatchers.IO + DispatcherArgumentEnum.SingleThread -> singleThreadContext + } + ) { + await1MAasyncs() + } +} \ No newline at end of file diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt new file mode 100644 index 0000000..598dc0a --- /dev/null +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt @@ -0,0 +1,15 @@ +package com.huanshankeji.exposed.benchmark.coroutine + +import com.huanshankeji.exposed.benchmark.AbstractBenchmark +import com.huanshankeji.exposed.benchmark.TransactionBenchmark +import kotlinx.benchmark.Benchmark +import kotlinx.coroutines.runBlocking + +/** + * As a comparison for [TransactionBenchmark]. + */ +class RunBlockingAwaitAsyncsBenchmark : AbstractBenchmark() { + @Benchmark + fun runBlockingAwait1MAsyncs() = + runBlocking { await1MAasyncs() } +} \ No newline at end of file From 1bdd2cb9b334cb68064c741a7244e62ccf4ce8c9 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Tue, 26 Nov 2024 20:00:31 +0800 Subject: [PATCH 59/70] =?UTF-8?q?Run=20the=20benchmarks=20of=20awaiting=20?= =?UTF-8?q?dummy=20`async`s=20on=20both=20a=20Mac=20with=20M1=20and=20an?= =?UTF-8?q?=20Ubuntu=20PC=20with=20AMD=20Ryzen=E2=84=A2=203900X,=20add=20m?= =?UTF-8?q?ore=20warmup=20and=20measurement=20iterations=20because=20the?= =?UTF-8?q?=20results=20are=20unstable,=20and=20rerun?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The benchmark results of both show that with `runBlocking`: no dispatcher argument > `Dispatchers.Default` > `newSingleThreadContext` > `Dispatchers.IO`. The Mac with a lower Geekbench multi-core score generally outperforms the Ubuntu PC, except for the one with `Dispatchers.IO`, which is interesting. --- .../exposed/benchmark/coroutine/AbstractBenchmark.kt | 11 +++++++++++ .../ParameterizedRunBlockingAwaitAsyncsBenchmark.kt | 1 - .../coroutine/RunBlockingAwaitAsyncsBenchmark.kt | 1 - 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AbstractBenchmark.kt diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AbstractBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AbstractBenchmark.kt new file mode 100644 index 0000000..e8a3ee2 --- /dev/null +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AbstractBenchmark.kt @@ -0,0 +1,11 @@ +package com.huanshankeji.exposed.benchmark.coroutine + +import kotlinx.benchmark.Measurement +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import kotlinx.benchmark.Warmup + +@State(Scope.Benchmark) +@Warmup(time = 1, iterations = 8) +@Measurement(time = 1, iterations = 8) +abstract class AbstractBenchmark \ No newline at end of file diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt index 25d48dd..a606494 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt @@ -1,6 +1,5 @@ package com.huanshankeji.exposed.benchmark.coroutine -import com.huanshankeji.exposed.benchmark.AbstractBenchmark import com.huanshankeji.exposed.benchmark.TransactionBenchmark import kotlinx.benchmark.Benchmark import kotlinx.benchmark.Param diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt index 598dc0a..97baa56 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt @@ -1,6 +1,5 @@ package com.huanshankeji.exposed.benchmark.coroutine -import com.huanshankeji.exposed.benchmark.AbstractBenchmark import com.huanshankeji.exposed.benchmark.TransactionBenchmark import kotlinx.benchmark.Benchmark import kotlinx.coroutines.runBlocking From 8f16886f145225801687ddf717f5fef235c48ded Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Tue, 26 Nov 2024 20:04:23 +0800 Subject: [PATCH 60/70] Move the coroutine benchmark code to another package of its own --- .../exposed/benchmark/TransactionBenchmark.kt | 8 ++++++++ .../coroutines/benchmark}/AbstractBenchmark.kt | 4 +++- .../coroutines/benchmark}/AwaitAsyncs.kt | 2 +- .../ParameterizedRunBlockingAwaitAsyncsBenchmark.kt | 6 +----- .../benchmark}/RunBlockingAwaitAsyncsBenchmark.kt | 6 +----- 5 files changed, 14 insertions(+), 12 deletions(-) rename integrated/src/benchmarks/kotlin/com/huanshankeji/{exposed/benchmark/coroutine => kotlinx/coroutines/benchmark}/AbstractBenchmark.kt (68%) rename integrated/src/benchmarks/kotlin/com/huanshankeji/{exposed/benchmark/coroutine => kotlinx/coroutines/benchmark}/AwaitAsyncs.kt (82%) rename integrated/src/benchmarks/kotlin/com/huanshankeji/{exposed/benchmark/coroutine => kotlinx/coroutines/benchmark}/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt (83%) rename integrated/src/benchmarks/kotlin/com/huanshankeji/{exposed/benchmark/coroutine => kotlinx/coroutines/benchmark}/RunBlockingAwaitAsyncsBenchmark.kt (57%) 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 2a29d3f..858fa47 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/TransactionBenchmark.kt @@ -1,5 +1,7 @@ package com.huanshankeji.exposed.benchmark +import com.huanshankeji.kotlinx.coroutines.benchmark.ParameterizedRunBlockingAwaitAsyncsBenchmark +import com.huanshankeji.kotlinx.coroutines.benchmark.RunBlockingAwaitAsyncsBenchmark import kotlinx.benchmark.* import kotlinx.coroutines.* import org.jetbrains.exposed.sql.Database @@ -33,6 +35,9 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() { private suspend fun CoroutineScope.awaitAsync10KTransactions() = awaitAsync10K { transaction(database) {} } + /** + * Compare with [RunBlockingAwaitAsyncsBenchmark]. + */ @Benchmark fun singleThreadConcurrent10KTransactions() = @OptIn(ExperimentalCoroutinesApi::class, DelicateCoroutinesApi::class) @@ -41,6 +46,9 @@ class TransactionBenchmark : WithContainerizedDatabaseBenchmark() { } + /** + * Compare with [ParameterizedRunBlockingAwaitAsyncsBenchmark]. + */ @Benchmark fun multiThreadConcurrent10KTransactionsWithSharedDatabase() = runBlocking { awaitAsync10KTransactions() } diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AbstractBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt similarity index 68% rename from integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AbstractBenchmark.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt index e8a3ee2..8094582 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AbstractBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt @@ -1,4 +1,6 @@ -package com.huanshankeji.exposed.benchmark.coroutine +// TODO consider moving this package to a module in "kotlin-common" + +package com.huanshankeji.kotlinx.coroutines.benchmark import kotlinx.benchmark.Measurement import kotlinx.benchmark.Scope diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AwaitAsyncs.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AwaitAsyncs.kt similarity index 82% rename from integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AwaitAsyncs.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AwaitAsyncs.kt index 46f2931..fc09983 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/AwaitAsyncs.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AwaitAsyncs.kt @@ -1,4 +1,4 @@ -package com.huanshankeji.exposed.benchmark.coroutine +package com.huanshankeji.kotlinx.coroutines.benchmark import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.async diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt similarity index 83% rename from integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt index a606494..0df816f 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt @@ -1,13 +1,9 @@ -package com.huanshankeji.exposed.benchmark.coroutine +package com.huanshankeji.kotlinx.coroutines.benchmark -import com.huanshankeji.exposed.benchmark.TransactionBenchmark import kotlinx.benchmark.Benchmark import kotlinx.benchmark.Param import kotlinx.coroutines.* -/** - * As a comparison for [TransactionBenchmark]. - */ class ParameterizedRunBlockingAwaitAsyncsBenchmark : AbstractBenchmark() { enum class DispatcherArgumentEnum { Default, IO, SingleThread diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/RunBlockingAwaitAsyncsBenchmark.kt similarity index 57% rename from integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt rename to integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/RunBlockingAwaitAsyncsBenchmark.kt index 97baa56..ce218e7 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/exposed/benchmark/coroutine/RunBlockingAwaitAsyncsBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/RunBlockingAwaitAsyncsBenchmark.kt @@ -1,12 +1,8 @@ -package com.huanshankeji.exposed.benchmark.coroutine +package com.huanshankeji.kotlinx.coroutines.benchmark -import com.huanshankeji.exposed.benchmark.TransactionBenchmark import kotlinx.benchmark.Benchmark import kotlinx.coroutines.runBlocking -/** - * As a comparison for [TransactionBenchmark]. - */ class RunBlockingAwaitAsyncsBenchmark : AbstractBenchmark() { @Benchmark fun runBlockingAwait1MAsyncs() = From 24befd4838e3699df6b394a83df48553c52c76e3 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 27 Nov 2024 09:11:57 +0800 Subject: [PATCH 61/70] Update a TODO --- integrated/build.gradle.kts | 2 ++ .../kotlinx/coroutines/benchmark/AbstractBenchmark.kt | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integrated/build.gradle.kts b/integrated/build.gradle.kts index 9362b8b..4f95b3c 100644 --- a/integrated/build.gradle.kts +++ b/integrated/build.gradle.kts @@ -1,3 +1,5 @@ +// TODO consider moving the code related to only Exposed or Vert.x to "kotlin-common" + import com.huanshankeji.cpnProject plugins { diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt index 8094582..ad52aae 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt @@ -1,5 +1,3 @@ -// TODO consider moving this package to a module in "kotlin-common" - package com.huanshankeji.kotlinx.coroutines.benchmark import kotlinx.benchmark.Measurement From 9de472c456b0ba56060b60d99e95ba0a6cef4aa6 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 27 Nov 2024 10:12:29 +0800 Subject: [PATCH 62/70] Check the instructions on sharing/reusing an Exposed `Database`, and update the example code with 3 different kinds of `SqlClient`s --- README.md | 8 +++++--- .../huanshankeji/exposedvertxsqlclient/Examples.kt | 13 ++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7032a7d..fd5d416 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ val evscConfig = defaultPostgresqlLocalConnectionConfig( ).toPerformantUnixEvscConfig() ``` -Create an Exposed `Database` with the `ConnectionConfig.Socket`, which can be reused for multiple `Verticle`s: +Create an Exposed `Database` with the `ConnectionConfig.Socket`, which can be shared and reused in multiple `Verticle`s: ```kotlin val exposedDatabase = evscConfig.exposedConnectionConfig.exposedDatabaseConnectPostgresql() @@ -82,13 +82,15 @@ val exposedDatabase = evscConfig.exposedConnectionConfig.exposedDatabaseConnectP Create a Vert.x `SqlClient` with the `ConnectionConfig`, preferably in a `Verticle`: ```kotlin -val vertxPool = createPgPool(vertx, evscConfig.vertxSqlClientConnectionConfig) +val sqlClient = createPgClient(vertx, evscConfig.vertxSqlClientConnectionConfig) +val pool = createPgPool(vertx, evscConfig.vertxSqlClientConnectionConfig) +val sqlConnection = createPgClient(vertx, evscConfig.vertxSqlClientConnectionConfig) ``` Create a `Database` with the provided Vert.x `SqlClient` and Exposed `Database`, preferably in a `Verticle`: ```kotlin -val databaseClient = DatabaseClient(vertxPool, exposedDatabase) +val databaseClient = DatabaseClient(vertxSqlClient, exposedDatabase) ``` ### Example table definitions diff --git a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index 5e3b590..d451c09 100644 --- a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -6,6 +6,7 @@ import com.huanshankeji.exposed.* import com.huanshankeji.exposedvertxsqlclient.local.toPerformantUnixEvscConfig import com.huanshankeji.exposedvertxsqlclient.postgresql.exposed.exposedDatabaseConnectPostgresql import com.huanshankeji.exposedvertxsqlclient.postgresql.local.defaultPostgresqlLocalConnectionConfig +import com.huanshankeji.exposedvertxsqlclient.postgresql.vertx.pgclient.createPgClient import com.huanshankeji.exposedvertxsqlclient.postgresql.vertx.pgclient.createPgPool import com.huanshankeji.exposedvertxsqlclient.sql.* import io.vertx.core.Verticle @@ -40,10 +41,16 @@ object Alternative { @OptIn(ExperimentalEvscApi::class) suspend fun examples(vertx: Vertx) { - /** It may be more efficient to use a single shared [Database] to generate SQLs for multiple [DatabaseClient]s/[SqlClient]s in respective [Verticle]s. */ + /** It may be more efficient to reuse a single shared [Database] to generate SQLs in multiple [DatabaseClient]s for [SqlClient]s in respective [Verticle]s. */ val exposedDatabase = evscConfig.exposedConnectionConfig.exposedDatabaseConnectPostgresql() - val vertxPool = createPgPool(vertx, evscConfig.vertxSqlClientConnectionConfig) - val databaseClient = DatabaseClient(vertxPool, exposedDatabase) + + val sqlClient = createPgClient(vertx, evscConfig.vertxSqlClientConnectionConfig) + val pool = createPgPool(vertx, evscConfig.vertxSqlClientConnectionConfig) + val sqlConnection = createPgClient(vertx, evscConfig.vertxSqlClientConnectionConfig) + + val vertxSqlClient = sqlClient + + val databaseClient = DatabaseClient(vertxSqlClient, exposedDatabase) withContext(Dispatchers.IO) { databaseClient.exposedTransaction { From 0ef8aa27d1e86ef024026fb67e868e05484da241 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 27 Nov 2024 10:43:26 +0800 Subject: [PATCH 63/70] Benchmark `Dispatchers.Unconfined` in the benchmarks --- .../benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt index 0df816f..548f16d 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.* class ParameterizedRunBlockingAwaitAsyncsBenchmark : AbstractBenchmark() { enum class DispatcherArgumentEnum { - Default, IO, SingleThread + Default, /*Main,*/ Unconfined, IO, SingleThread } @Param @@ -20,6 +20,8 @@ class ParameterizedRunBlockingAwaitAsyncsBenchmark : AbstractBenchmark() { runBlocking( when (dispatcherArgumentEnum) { DispatcherArgumentEnum.Default -> Dispatchers.Default + //DispatcherArgumentEnum.Main -> Dispatchers.Main + DispatcherArgumentEnum.Unconfined -> Dispatchers.Unconfined DispatcherArgumentEnum.IO -> Dispatchers.IO DispatcherArgumentEnum.SingleThread -> singleThreadContext } From c1ab4a8f576dc6b00dab2f88e10a5e2c9287dbdf Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 27 Nov 2024 11:26:03 +0800 Subject: [PATCH 64/70] Benchmark awaiting heavier computations in the benchmarks Some conclusions: 1. Calling `runBlocking` without a `CoroutineContext` should be equivalent to calling it with `Dispatchers.Unconfined`, both of which run on the original single thread of the caller. 1. Awaiting empty `async`s is dependent on single-core performance. 1. Both `Dispatchers.Default` and `Dispatchers.IO` utilize all the cores for computation. 1. `await` is much heavier on `Dispatchers.IO`. 1. `await` is lightest when calling `runBlocking` without a `CoroutineContext` or on `Dispatchers.Unconfined`. --- .../coroutines/benchmark/AbstractBenchmark.kt | 2 +- ...AbstractRunBlockingAwaitAsyncsBenchmark.kt | 7 +++++ .../coroutines/benchmark/AwaitAsyncs.kt | 15 +++++++++- ...eterizedRunBlockingAwaitAsyncsBenchmark.kt | 29 ++++++++++--------- .../RunBlockingAwaitAsyncsBenchmark.kt | 10 +++++-- 5 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractRunBlockingAwaitAsyncsBenchmark.kt diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt index ad52aae..1220fa9 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractBenchmark.kt @@ -6,6 +6,6 @@ import kotlinx.benchmark.State import kotlinx.benchmark.Warmup @State(Scope.Benchmark) -@Warmup(time = 1, iterations = 8) +@Warmup(time = 1, iterations = 8) // 4 seems not enough @Measurement(time = 1, iterations = 8) abstract class AbstractBenchmark \ No newline at end of file diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractRunBlockingAwaitAsyncsBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractRunBlockingAwaitAsyncsBenchmark.kt new file mode 100644 index 0000000..a85c4c8 --- /dev/null +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AbstractRunBlockingAwaitAsyncsBenchmark.kt @@ -0,0 +1,7 @@ +package com.huanshankeji.kotlinx.coroutines.benchmark + +abstract class AbstractRunBlockingAwaitAsyncsBenchmark : AbstractBenchmark() { + abstract fun runBlockingAwait1mAsyncs() + + abstract fun runBlockingAwait1KAsync1mSums() +} \ No newline at end of file diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AwaitAsyncs.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AwaitAsyncs.kt index fc09983..ebebd26 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AwaitAsyncs.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/AwaitAsyncs.kt @@ -5,6 +5,19 @@ import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll @Suppress("SuspendFunctionOnCoroutineScope") -internal suspend inline fun CoroutineScope.await1MAasyncs() { +internal suspend inline fun CoroutineScope.await1mAsyncs() { List(1 shl 20) { async {} }.awaitAll() } + +internal val `1mSizeList` = List(1 shl 20) { it } + +// It seems the loop get optimized and removed in this function. +@Suppress("SuspendFunctionOnCoroutineScope") +internal suspend inline fun CoroutineScope.await1kAsync1mLoops() { + List(1 shl 10) { async { repeat(1 shl 20) {} } }.awaitAll() +} + +@Suppress("SuspendFunctionOnCoroutineScope") +internal suspend inline fun CoroutineScope.await1kAsync1mSums() { + List(1 shl 10) { async { `1mSizeList`.sum() } }.awaitAll() +} diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt index 548f16d..92239fa 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/ParameterizedRunBlockingAwaitAsyncsBenchmark.kt @@ -4,7 +4,7 @@ import kotlinx.benchmark.Benchmark import kotlinx.benchmark.Param import kotlinx.coroutines.* -class ParameterizedRunBlockingAwaitAsyncsBenchmark : AbstractBenchmark() { +class ParameterizedRunBlockingAwaitAsyncsBenchmark : AbstractRunBlockingAwaitAsyncsBenchmark() { enum class DispatcherArgumentEnum { Default, /*Main,*/ Unconfined, IO, SingleThread } @@ -14,18 +14,21 @@ class ParameterizedRunBlockingAwaitAsyncsBenchmark : AbstractBenchmark() { @OptIn(ExperimentalCoroutinesApi::class, DelicateCoroutinesApi::class) val singleThreadContext = newSingleThreadContext("single thread") + val dispatcher + get() = when (dispatcherArgumentEnum) { + DispatcherArgumentEnum.Default -> Dispatchers.Default + //DispatcherArgumentEnum.Main -> Dispatchers.Main + DispatcherArgumentEnum.Unconfined -> Dispatchers.Unconfined + DispatcherArgumentEnum.IO -> Dispatchers.IO + DispatcherArgumentEnum.SingleThread -> singleThreadContext + } + @Benchmark - fun runBlockingAwait1MAsyncsWithDispatcherArgument() = - runBlocking( - when (dispatcherArgumentEnum) { - DispatcherArgumentEnum.Default -> Dispatchers.Default - //DispatcherArgumentEnum.Main -> Dispatchers.Main - DispatcherArgumentEnum.Unconfined -> Dispatchers.Unconfined - DispatcherArgumentEnum.IO -> Dispatchers.IO - DispatcherArgumentEnum.SingleThread -> singleThreadContext - } - ) { - await1MAasyncs() - } + override fun runBlockingAwait1mAsyncs() = + runBlocking(dispatcher) { await1mAsyncs() } + + @Benchmark + override fun runBlockingAwait1KAsync1mSums() = + runBlocking(dispatcher) { await1kAsync1mSums() } } \ No newline at end of file diff --git a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/RunBlockingAwaitAsyncsBenchmark.kt b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/RunBlockingAwaitAsyncsBenchmark.kt index ce218e7..f0608ce 100644 --- a/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/RunBlockingAwaitAsyncsBenchmark.kt +++ b/integrated/src/benchmarks/kotlin/com/huanshankeji/kotlinx/coroutines/benchmark/RunBlockingAwaitAsyncsBenchmark.kt @@ -3,8 +3,12 @@ package com.huanshankeji.kotlinx.coroutines.benchmark import kotlinx.benchmark.Benchmark import kotlinx.coroutines.runBlocking -class RunBlockingAwaitAsyncsBenchmark : AbstractBenchmark() { +class RunBlockingAwaitAsyncsBenchmark : AbstractRunBlockingAwaitAsyncsBenchmark() { @Benchmark - fun runBlockingAwait1MAsyncs() = - runBlocking { await1MAasyncs() } + override fun runBlockingAwait1mAsyncs() = + runBlocking { await1mAsyncs() } + + @Benchmark + override fun runBlockingAwait1KAsync1mSums() = + runBlocking { await1kAsync1mSums() } } \ No newline at end of file From 0c5fe28a6956edd7bb3a163ad40cdf5c1b472eec Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 27 Nov 2024 12:53:51 +0800 Subject: [PATCH 65/70] Comment out a dependency that's no longer needed --- postgresql/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresql/build.gradle.kts b/postgresql/build.gradle.kts index ad2eebd..cd05fd4 100644 --- a/postgresql/build.gradle.kts +++ b/postgresql/build.gradle.kts @@ -13,5 +13,5 @@ dependencies { runtimeOnly(commonDependencies.postgreSql()) implementation(commonDependencies.vertx.moduleWithoutVersion("pg-client")) implementation(commonDependencies.kotlinCommon.core()) // for `Untested` - implementation(commonDependencies.kotlinCommon.vertx()) // for `PgPoolOptions.setUpConventionally` + //implementation(commonDependencies.kotlinCommon.vertx()) // for `PgPoolOptions.setUpConventionally` } From e0e72655ee0c503a4ef565f062bbf27da8d40792 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 27 Nov 2024 21:24:44 +0800 Subject: [PATCH 66/70] Make wrapping executing blocking Exposed statements in `Dispatchers.IO` not mandatory --- README.md | 8 ++++---- .../com/huanshankeji/exposedvertxsqlclient/Examples.kt | 9 +++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fd5d416..9b12cf6 100644 --- a/README.md +++ b/README.md @@ -108,13 +108,13 @@ val tables = arrayOf(Examples) For example, to create tables: ```kotlin -withContext(Dispatchers.IO) { - databaseClient.exposedTransaction { - SchemaUtils.create(*tables) - } +databaseClient.exposedTransaction { + SchemaUtils.create(*tables) } ``` +If you execute blocking Exposed statements inside `Verticle`s or event loop threads that you shouldn't block, you should use Vert.x `Vertx.executeBlocking` or Coroutines `Dispatchers.IO`. + ### CRUD (DML and DQL) operations with `DatabaseClient` #### Core APIs diff --git a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index d451c09..f0450e1 100644 --- a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -12,8 +12,6 @@ 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 @@ -52,10 +50,9 @@ suspend fun examples(vertx: Vertx) { val databaseClient = DatabaseClient(vertxSqlClient, exposedDatabase) - withContext(Dispatchers.IO) { - databaseClient.exposedTransaction { - SchemaUtils.create(*tables) - } + // put in `Vertx.executeBlocking` or `Dispatchers.IO` if needed + databaseClient.exposedTransaction { + SchemaUtils.create(*tables) } run { From 0ccb6f581fdcaba8d0e31c5d14da18b0ebf1471c Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Thu, 28 Nov 2024 19:24:41 +0800 Subject: [PATCH 67/70] Remove a redundant pair of parentheses --- .../huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-dsl/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt b/sql-dsl/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt index a6e0416..2b47c26 100644 --- a/sql-dsl/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt +++ b/sql-dsl/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/sql/DatabaseClientSql.kt @@ -74,7 +74,7 @@ suspend fun DatabaseClient<*>.selectExpression(clazz: KClass, expre suspend inline fun DatabaseClient<*>.selectExpression(expression: Expression): T = @Suppress("UNCHECKED_CAST") - (selectExpression(T::class as KClass, expression as Expression)) as T + selectExpression(T::class as KClass, expression as Expression) as T @ExperimentalEvscApi suspend fun DatabaseClient<*>.insert(table: T, body: T.(InsertStatement) -> Unit) = From 8e7196f1b2b2866f4aff6bc65bea058b9cc7f7be Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Fri, 29 Nov 2024 22:19:44 +0800 Subject: [PATCH 68/70] Add part of the change log for v0.5.0 A source commit: https://github.com/huanshankeji/exposed-adt-mapping/commit/489fb0b5c5cd17c0768e5be6e80cd80c5c08e925 --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 168be6d..cfcf2d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Change log +## v0.5.0 / 2024-11-29 + +Because of [the Exposed SELECT DSL design changes](https://github.com/JetBrains/Exposed/pull/1916), and also because the old `DatabaseClient` creation APIs were poorly designed and too cumbersome, causing an additional cognitive burden on the users, this release has been completely overhauled. Some old APIs are removed directly because deprecating and delegating them to new ones fills the code base with unused code. Therefore, this release is not source-compatible or binary-compatible with v0.4.0. We are sorry for the inconvenience. From this version on, we will try to maintain source and binary compatibility, deprecating APIs instead of removing them in the foreseeable future. + +Functional changes: + +* ... + +Miscellaneous changes: + +* add API documentation generated by Dokka hosted at +* add CODE_OF_CONDUCT.md and CONTRIBUTING.md +* use the Kotlin binary compatibility validator +* bump Exposed to v0.56.0 + ## v0.4.0 / 2024-10-19 * bump Exposed to 0.53.0 From a6ead337f0e89164371e40234285789c14aa5918 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Fri, 29 Nov 2024 22:33:46 +0800 Subject: [PATCH 69/70] Bump the snapshot dependencies to the stable versions --- buildSrc/build.gradle.kts | 2 +- buildSrc/src/main/kotlin/VersionsAndDependencies.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 507988e..cab0d18 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -18,6 +18,6 @@ dependencies { // With Kotlin 2.0.20, a "Could not parse POM" build error occurs in the JVM projects of some dependent projects. implementation(kotlin("gradle-plugin", "2.0.10")) implementation("com.huanshankeji:common-gradle-dependencies:0.8.0-20241016") // don't use a snapshot version in a main branch - implementation("com.huanshankeji.team:gradle-plugins:0.7.0-SNAPSHOT") // TODO don't use a snapshot version in a main branch + implementation("com.huanshankeji.team:gradle-plugins:0.7.0") // don't use a snapshot version in a main branch implementation("org.jetbrains.dokka:dokka-gradle-plugin:2.0.0-Beta") } diff --git a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt index 37b4828..f784f2d 100644 --- a/buildSrc/src/main/kotlin/VersionsAndDependencies.kt +++ b/buildSrc/src/main/kotlin/VersionsAndDependencies.kt @@ -4,11 +4,11 @@ import com.huanshankeji.CommonVersions val projectVersion = "0.5.0-SNAPSHOT" -// TODO don't use a snapshot version in a main branch -val commonVersions = CommonVersions(kotlinCommon = "0.6.0-SNAPSHOT", exposed = "0.56.0") +// don't use a snapshot version in a main branch +val commonVersions = CommonVersions(kotlinCommon = "0.6.0", exposed = "0.56.0") val commonDependencies = CommonDependencies(commonVersions) val commonGradleClasspathDependencies = CommonGradleClasspathDependencies(commonVersions) object DependencyVersions { - val exposedAdtMapping = "0.3.0-SNAPSHOT" // TODO don't use a snapshot version in a main branch + val exposedAdtMapping = "0.3.0" // don't use a snapshot version in a main branch } From 4616634472a303bdc31d43e2b36299eead899afe Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sat, 30 Nov 2024 00:55:36 +0800 Subject: [PATCH 70/70] Complete the change log for v0.5.0, and review and update the example code removing some outdated comments --- CHANGELOG.md | 29 +++++++++++++++++-- README.md | 9 +++--- .../exposedvertxsqlclient/Examples.kt | 7 ++--- .../exposedvertxsqlclient/MappingExamples.kt | 2 +- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfcf2d3..5b06dda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,36 @@ ## v0.5.0 / 2024-11-29 -Because of [the Exposed SELECT DSL design changes](https://github.com/JetBrains/Exposed/pull/1916), and also because the old `DatabaseClient` creation APIs were poorly designed and too cumbersome, causing an additional cognitive burden on the users, this release has been completely overhauled. Some old APIs are removed directly because deprecating and delegating them to new ones fills the code base with unused code. Therefore, this release is not source-compatible or binary-compatible with v0.4.0. We are sorry for the inconvenience. From this version on, we will try to maintain source and binary compatibility, deprecating APIs instead of removing them in the foreseeable future. +Because of [the Exposed SELECT DSL design changes](https://github.com/JetBrains/Exposed/pull/1916), and also because the old `DatabaseClient` creation APIs were poorly designed and too cumbersome, causing additional cognitive burdens on the users, this release has been completely overhauled. Some old APIs are removed directly because deprecating and delegating them to new ones fills the code base with unused code. Therefore, this release is **not source-compatible or binary-compatible** with v0.4.0. Please do not update unless you have time to adapt to the refactored changes. We are sorry for the inconvenience. From this version on, we will try to maintain source and binary compatibility, deprecating APIs instead of removing them in the foreseeable future. + +Please check out the [updated README](README.md) to upgrade to v0.5.0. Functional changes: -* ... +* adapt to [the Exposed SELECT DSL design changes](https://github.com/JetBrains/Exposed/pull/1916) (resolve #8) +* rename the SQL DSL functions taking mapper parameters, adding "withMapper" prefixes (resolve #6) +* split the library into multiple modules including "core", "postgresql", "sql-dsl", and "sql-dsl-with-mapper" +* generalize the functions with the types `PgPool` and `PgConnection` to work with different RDBMSs, replacing them with `Pool` and `SqlConnection` +* get rid of all usages of `PgPool` which was deprecated in Vert.x 4.5 +* extract some new APIs and move some existing APIs into finer-grained subpackages, including `jdbc`, `exposed`, `vertx.sqlclient`, and `local` in the "core" module, and `postgresql` in the "postgresql" module +* overhaul the APIs related to the creation of Exposed `Database`s, Vert.x SQL clients, and `DatabaseClient`s + + * remove the `create...andSetRole` functions to create Vert.x SQL Clients, with their functionalities merged into the `create...` functions to create Vert.x SQL Clients + + * refactor the Exposed `Database` and Vert.x `SqlClient` creation APIs to be more configurable and straightforward + + * remove the extra shortcut `DatabaseClient` creation APIs such as `createPgPoolDatabaseClient` as they were poorly designed and too cumbersome, causing additional cognitive burdens on the users + + There are too many different combinations with different RDMBSs such as PostgreSQL and MySQL, and different Vert.x SQL Clients such as `SqlClient`, `Pool`, and `SqlConnection`. Therefore we don't provide such shortcut APIs anymore as they are just too cumbersome and cause additional cognitive burdens on the users, and we encourage the library users to create their own (see the updated guide in README.md for instructions). In this way, the Exposed `Databse`s and Vert.x SQL Clients are also more configurable. + +* adopt `EvscConfig` as the single-source-of-truth database client config and no longer prefer local connections + + `LocalConnectionConfig` should be converted to `EvscConfig` or `ConnectionConfig` to be used. + +* mark some APIs as experimental as they are subject to change +* make `DatabaseClient` implement our new `CoroutineAutoCloseable` interface +* add a version of `selectWithMapper` without `buildQuery` +* point out in the usage guide that you are encouraged to share/reuse an Exposed `Database` which generates SQLs among multiple `DatabaseClient`s in multiple verticles, which improves performance as shown in our benchmark results Miscellaneous changes: diff --git a/README.md b/README.md index 9b12cf6..a7d6a14 100644 --- a/README.md +++ b/README.md @@ -137,11 +137,11 @@ val updateRowCount = databaseClient.executeUpdate(Examples.updateStatement({ Examples.id eq 1 }) { it[name] = "AA" }) assert(updateRowCount == 1) -// The Exposed `Table` extension function `select` doesn't execute eagerly so it can be used directly. -val exampleName = databaseClient.executeQuery(Examples.select(Examples.name).where(Examples.id eq 1)) +// The Exposed `Table` extension function `select` doesn't execute eagerly so it can also be used directly. +val exampleName = databaseClient.executeQuery(Examples.selectStatement(Examples.name).where(Examples.id eq 1)) .single()[Examples.name] -databaseClient.executeSingleUpdate(Examples.deleteWhereStatement { Examples.id eq 1 }) // The function `deleteWhereStatement` still depends on the old DSL and will be updated. +databaseClient.executeSingleUpdate(Examples.deleteWhereStatement { id eq 1 }) databaseClient.executeSingleUpdate(Examples.deleteIgnoreWhereStatement { id eq 2 }) ``` @@ -165,7 +165,6 @@ val updateRowCount = databaseClient.update(Examples, { Examples.id eq 1 }) { it[ val exampleName1 = databaseClient.select(Examples) { select(Examples.name).where(Examples.id eq 1) }.single()[Examples.name] -// This function still depends on the old SELECT DSL and will be updated. val exampleName2 = databaseClient.selectSingleColumn(Examples, Examples.name) { where(Examples.id eq 2) }.single() @@ -204,7 +203,7 @@ val filmWithDirectorId = FilmWithDirectorId(filmId, episodeIIFilmDetails) databaseClient.insertWithMapper(Films, filmWithDirectorId, Mappers.filmWithDirectorId) // insert with the ID val fullFilms = databaseClient.selectWithMapper(filmsLeftJoinDirectors, Mappers.fullFilm) { - where(Films.filmId inList listOf(1, 2)) // This API still depends on the old SELECT DSL and will be refactored. + where(Films.filmId inList listOf(1, 2)) } ``` diff --git a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index f0450e1..b57a5e0 100644 --- a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -70,11 +70,11 @@ suspend fun examples(vertx: Vertx) { databaseClient.executeUpdate(Examples.updateStatement({ Examples.id eq 1 }) { it[name] = "AA" }) assert(updateRowCount == 1) - // The Exposed `Table` extension function `select` doesn't execute eagerly so it can be used directly. - val exampleName = databaseClient.executeQuery(Examples.select(Examples.name).where(Examples.id eq 1)) + // The Exposed `Table` extension function `select` doesn't execute eagerly so it can also be used directly. + val exampleName = databaseClient.executeQuery(Examples.selectStatement(Examples.name).where(Examples.id eq 1)) .single()[Examples.name] - databaseClient.executeSingleUpdate(Examples.deleteWhereStatement { Examples.id eq 1 }) // The function `deleteWhereStatement` still depends on the old DSL and will be updated. + databaseClient.executeSingleUpdate(Examples.deleteWhereStatement { id eq 1 }) databaseClient.executeSingleUpdate(Examples.deleteIgnoreWhereStatement { id eq 2 }) } @@ -86,7 +86,6 @@ suspend fun examples(vertx: Vertx) { val exampleName1 = databaseClient.select(Examples) { select(Examples.name).where(Examples.id eq 1) }.single()[Examples.name] - // This function still depends on the old SELECT DSL and will be updated. val exampleName2 = databaseClient.selectSingleColumn(Examples, Examples.name) { where(Examples.id eq 2) }.single() diff --git a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt index 24dac9b..fff5da1 100644 --- a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt +++ b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/MappingExamples.kt @@ -95,6 +95,6 @@ suspend fun mappingExamples(databaseClient: DatabaseClient) { databaseClient.insertWithMapper(Films, filmWithDirectorId, Mappers.filmWithDirectorId) // insert with the ID val fullFilms = databaseClient.selectWithMapper(filmsLeftJoinDirectors, Mappers.fullFilm) { - where(Films.filmId inList listOf(1, 2)) // This API still depends on the old SELECT DSL and will be refactored. + where(Films.filmId inList listOf(1, 2)) } }