Skip to content

Commit

Permalink
Check the instructions on sharing/reusing an Exposed Database, and …
Browse files Browse the repository at this point in the history
…update the example code with 3 different kinds of `SqlClient`s
  • Loading branch information
ShreckYe committed Nov 27, 2024
1 parent 24befd4 commit 9de472c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9de472c

Please sign in to comment.