terpal-sql
terpal-sql copied to clipboard
Fewer boilerplate on call-sites with these helper methods
In https://github.com/ExoQuery/terpal-sql/issues/11 I outline that I do not need coroutines, and how I removed the runBlocking { ... } calls from the call-sites.
Now I've gone a bit further in cleaning up the call-sites, and I create this issue in order to share the approach (maybe it's valuable to others).
Here a before and after of what the call-site looks like:
The code that makes this:
inline fun <reified T> TerpalDriver.runQuery(stmt: Statement) =
runBlocking { [email protected](stmt.queryOf<T>()) }
inline fun <reified T> TerpalDriver.streamQuery(stmt: Statement) =
runBlocking { [email protected](stmt.queryOf<T>()) }
inline fun <reified T> TerpalDriver.runRawQuery(stmt: Statement) =
runBlocking { [email protected](stmt.queryOf<T>()) }
fun TerpalDriver.runAction(stmt: Statement) =
runBlocking { [email protected](stmt.action()) }
inline fun <reified T> TerpalDriver.runActionReturning(stmt: Statement) =
runBlocking { [email protected](stmt.actionReturning<T>()) }
fun TerpalDriver.runBatchAction(stmt: Statement) =
runBlocking { [email protected](stmt.action()) }
inline fun <reified T> TerpalDriver.runBatchActionReturning(stmt: Statement) =
runBlocking { [email protected](stmt.actionReturning<T>()) }
inline fun <reified T> TerpalDriver.streamBatchActionReturning(stmt: Statement) =
runBlocking { [email protected](stmt.actionReturning<T>()) }