-
-
Notifications
You must be signed in to change notification settings - Fork 137
Kotlin API
Although jasync-sql
is mostly written in Kotlin, most of the API's are written so it will be easily used from Java as well as Kotlin.
This page describes API's that are intended to use from Kotlin code.
- ResultSet - operator
invoke
. - RowData - operator
get
andinvoke
, generic casting. -
Configuration
andPoolConfiguration
are data classes, socopy
can be easily used.
Support for suspending invocation is done via SuspendingConnection
interface. This interface is identical to Connection
in the method it has but works with suspend
API instead of CompletableFuture
callback.
For Example:
fun sendQuery(query: String): CompletableFuture<QueryResult>
Has its suspending flavor:
suspend fun sendQuery(query: String): QueryResult
In order to 'move' to coroutines world, use the following extension property on Connection:
val suspendingConnection: SuspendingConnection = connection.asSuspending
Behind the scenes, SuspendingConnection
is a wrapper that delegates all calls to the underlying Connection
and converts the future to suspend method using coroutines extension from the kotlinx.coroutines.
More details here. More examples can be found on Executing Statements.
In case you want to know there was also previous api.
An example Kotlin project (not up to date) can be found here: https://github.com/jasync-sql/jasync-sql/tree/master/samples/ktor