- Notifications
You must be signed in to change notification settings - Fork0
License
udaan-com/r2dbi
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
R2Dbi is a Kotlin library inspired byJDBI and built on Reactive Relational Database Connectivity (R2DBC) SPI.R2DBC bringsReactive Programming APIs to relational databases. R2DBI simplifies database operations by offering adeclarative style similar toJDBI SqlObjects.It provides easy-to-use interfaces for executingSQL queries
and mappingdata
toobjects
.
While primarily designed for Kotlin, it may also work with Java, although it hasn't been tested yet.R2dbi started out to be used in declarative mode (ie define an annotatedinterface
). The fluent interface is stillbeing developed and hence not ready to use. It is available to experiment and play with.
R2Dbi is licensed under the commercial friendlyApache 2.0 license.
define the SQL to execute and the shape of the results - by creating an annotatedinterface
.
importkotlinx.coroutines.flow.Flowimportorg.reactivestreams.Publisherimportreactor.core.publisher.Flux// Declare the API using annotations on a Java interfaceinterfaceUserDao {// Using kotlinx.coroutines.flow.Flow @SqlQuery("SELECT 1")fungetOne():Flow<Long> @SqlQuery("SELECT * FROM 'user' where name = :name")funfindUser(@Bind("name")name:String):Flow<User>;// Using reactor.core.publisher.Flux @SqlQuery("SELECT * FROM 'user'")fungetAllUsers():Flux<User>;}
This library supports bothkotlinx.coroutines.flow.Flow
andorg.reactivestreams.Publisher
/reactor.core.publisher.Flux
as the return type. Note that no other return type (especially blocking) is supported.
You look atTestQueryDao.kt andTestDynamicInterfaceBase.kt to checkoutmore examples.
🚧
Before utilizing this library, it's crucial to grasp the fundamentals of Coroutines and Project Reactor.
For Instance, without subscribing to aPublisher
or attempting to materialize a value of aFlow
, the underlying SQL query won't execute.
TODO