Skip to content

Fewer boilerplate on call-sites with these helper methods #14

@cies

Description

@cies

In #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:

Image

The code that makes this:

inline fun <reified T> TerpalDriver.runQuery(stmt: Statement) =
  runBlocking { this@runQuery.run(stmt.queryOf<T>()) }
inline fun <reified T> TerpalDriver.streamQuery(stmt: Statement) =
  runBlocking { this@streamQuery.stream(stmt.queryOf<T>()) }
inline fun <reified T> TerpalDriver.runRawQuery(stmt: Statement) =
  runBlocking { this@runRawQuery.runRaw(stmt.queryOf<T>()) }
fun TerpalDriver.runAction(stmt: Statement) =
  runBlocking { this@runAction.run(stmt.action()) }
inline fun <reified T> TerpalDriver.runActionReturning(stmt: Statement) =
  runBlocking { this@runActionReturning.run(stmt.actionReturning<T>()) }
fun TerpalDriver.runBatchAction(stmt: Statement) =
  runBlocking { this@runBatchAction.run(stmt.action()) }
inline fun <reified T> TerpalDriver.runBatchActionReturning(stmt: Statement) =
  runBlocking { this@runBatchActionReturning.run(stmt.actionReturning<T>()) }
inline fun <reified T> TerpalDriver.streamBatchActionReturning(stmt: Statement) =
  runBlocking { this@streamBatchActionReturning.stream(stmt.actionReturning<T>()) }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions