https://kotlinlang.org logo
#komapper
Title
# komapper
d

dave08

01/17/2023, 11:27 AM
Is there any way to use an existing Jasync connection to start a R2dbc komapper connection? We have a service we want to gradually migrate to Komapper and we don't want to have an extra connection pool open to the databases...
t

Toshihiro Nakamura

01/17/2023, 11:52 AM
Try to wrap your existing connection with ConnectionFactory:
Copy code
val connectionFactory = object : ConnectionFactory {
    override fun create(): Publisher<out Connection> {
        // return existing connection
    }

    override fun getMetadata(): ConnectionFactoryMetadata {
        // ...
    }
}
val db = R2dbcDatabase(connectionFactory, H2R2dbcDialect())
d

dave08

01/17/2023, 11:54 AM
How do I do this with a JASync connection? (I'm really not too familiar with r2dbc api, and the docs are almost inexistant...)
t

Toshihiro Nakamura

01/17/2023, 12:04 PM
I am not familiar with JASync; doesn’t JASync Connection provide io.r2dbc.spi.Connection? You can convert io.r2dbc.spi.Connection to Publisher<out Connection> as followings:
Copy code
flowOf(connection).asPublisher()
It has it's own connection object w/o r2dbc
10 Views