-
Notifications
You must be signed in to change notification settings - Fork 545
Closed
Description
Currently SQL Delight is using JDBC or other blocking drivers
Jasync has async MySQL / PostgreSQL drivers which although it's using annoying Joda time, works great otherwise
(there is a ticket there somewhere to replace Joda Time with Java Time)
Converting Joda Time is not difficult either
when (value) {
is java.lang.Integer -> {
return value.toInt() as T
}
is java.lang.Long -> {
return value.toLong() as T
}
is org.joda.time.LocalDateTime -> {
val utc = value.toDateTime(DateTimeZone.UTC);
val secondsSinceEpoch: Long = utc.millis / 1000
val milliSeconds: Long = utc.millis - (secondsSinceEpoch * 1000)
val javaTime = LocalDateTime.ofEpochSecond(
secondsSinceEpoch,
milliSeconds.toInt() * 1000000,
ZoneOffset.UTC
)
return javaTime as T
}
Jasync returns a Future and can easily be converted to a Coroutine allowing non-blocking queries
suspend fun Connection.execute(query: String, vararg values: Any?): QueryResult {
return if (values.isEmpty()) {
this.sendQuery(query).await()
} else {
this.sendPreparedStatement(query, values.asList().toMutableList()).await()
}
}
suspend fun ConnectionPool<*>.executeAsync(query: String, vararg values: Any?): Deferred<QueryResult> {
return if (values.isEmpty()) {
this.sendQuery(query).asDeferred()
} else {
this.sendPreparedStatement(query, values.asList().toMutableList()).asDeferred()
}
}