Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Split modules, completely overhaul the client creation APIs, and decouple PostgreSQL, our SQL DSL APIs, and our mapper SQL DSL APIs #16

Merged
merged 27 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c534750
Create modules/subprojects to split code into, and move the example a…
ShreckYe Nov 15, 2024
58f65e3
Run `apiDump` and remove the old dumped "exposed-vertx-sql-client-pos…
ShreckYe Nov 15, 2024
e101fc8
Add an additional dependency on the "core" module for the benchmark c…
ShreckYe Nov 15, 2024
7b0fc9f
Generalize the functions in "DatabaseClient.kt" using `PgPool` and `P…
ShreckYe Nov 15, 2024
e959812
Get rid of usages of `PgPool` which was deprecated in 4.5
ShreckYe Nov 15, 2024
dfd0d3b
Initially overhaul and reorganize the APIs
ShreckYe Nov 16, 2024
6b1547e
Move "VertxSqlClients.kt"
ShreckYe Nov 17, 2024
21d34c5
Move code related only to PostgreSQL into the `postgresql` subpackage
ShreckYe Nov 17, 2024
603dbb7
Remove a TODO which was already achieved in commit dfd0d3b5762b044c37…
ShreckYe Nov 17, 2024
fdc2023
Completely overhaul the client creation APIs
ShreckYe Nov 19, 2024
198ebf2
Update README.md
ShreckYe Nov 19, 2024
d4773cd
Remove the factory interfaces which are not needed any more with the …
ShreckYe Nov 19, 2024
496c354
Remove default arguments in the `createGeneric...` functions because …
ShreckYe Nov 19, 2024
82b23fa
Extract a `withCoConnectHandle` extension function
ShreckYe Nov 19, 2024
cecd5be
Move a TODO
ShreckYe Nov 19, 2024
d0e1f3e
Add a "sql-dsl" module
ShreckYe Nov 19, 2024
ef6d3d1
Move some code to https://github.com/huanshankeji/kotlin-common
ShreckYe Nov 19, 2024
daf69d7
Resolve a build issue in the `benchmarks` source set of the "integrat…
ShreckYe Nov 19, 2024
2d7b2a5
Move all the code in the package `postgresql` into the "postgresql" m…
ShreckYe Nov 19, 2024
59a26a6
Move the code that belongs to the modules "sql-dsl" and "sql-dsl-with…
ShreckYe Nov 19, 2024
6eb83a7
Run `apiDump` and ensure that `check` is successful
ShreckYe Nov 19, 2024
263cc5c
Print the number of processors and add a comment in `multiThreadMulti…
ShreckYe Nov 19, 2024
210529d
Add `multiThreadConcurrent10KTransactionsWithThreadLocalDatabases` an…
ShreckYe Nov 19, 2024
3715550
Fix a bug that `awaitAny` is used
ShreckYe Nov 19, 2024
920627f
Make `CoroutineScope` the receiver in `awaitAsync10KTransactions` and…
ShreckYe Nov 19, 2024
9a93c0e
Merge branch 'improve-benchmark' into split-modules-and-decouple
ShreckYe Nov 19, 2024
90dc927
Update README.md corresponding to the split modules
ShreckYe Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 85 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,82 @@

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`

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 socketConnectionConfig =
ConnectionConfig.Socket("localhost", user = "user", password = "password", database = "database")
val exposedDatabase = exposedDatabaseConnectPostgreSql(socketConnectionConfig)
val databaseClient = createPgPoolDatabaseClient(
vertx, socketConnectionConfig, exposedDatabase = exposedDatabase
)
val evscConfig = defaultPostgresqlLocalConnectionConfig(
user = "user",
socketConnectionPassword = "password",
database = "database"
).toPerformantUnixEvscConfig()
```

Create an Exposed `Database` with the `ConnectionConfig.Socket`, 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 databaseClient = DatabaseClient(vertxPool, exposedDatabase)
```

### Example table definitions
Expand Down Expand Up @@ -83,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" }
Expand All @@ -97,16 +162,26 @@ 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 }
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")
Expand Down
12 changes: 1 addition & 11 deletions buildSrc/src/main/kotlin/conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,9 +14,3 @@ repositoriesAddTeamGithubPackagesMavenRegistry("kotlin-common")
kotlin.jvmToolchain(8)

version = projectVersion

publishing.publications.getByName<MavenPublication>("maven") {
pomForTeamDefaultOpenSource(project, "Exposed Vert.x SQL Client", "Exposed on top of Vert.x Reactive SQL Client") {
`Shreck Ye`()
}
}
20 changes: 20 additions & 0 deletions buildSrc/src/main/kotlin/lib-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import com.huanshankeji.team.`Shreck Ye`
import com.huanshankeji.team.pomForTeamDefaultOpenSource
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

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<MavenPublication>("maven") {
pomForTeamDefaultOpenSource(project, "Exposed Vert.x SQL Client", "Exposed on top of Vert.x Reactive SQL Client") {
`Shreck Ye`()
}
}

tasks.named<KotlinCompilationTask<*>>("compileKotlin").configure {
compilerOptions.freeCompilerArgs.add("-opt-in=com.huanshankeji.exposedvertxsqlclient.InternalApi")
}
Loading
Loading