Skip to content

Commit

Permalink
Move await* to upper class ExecutableQuery (#3524)
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhbd committed Sep 22, 2022
1 parent 69da730 commit 76a6f9a
Showing 1 changed file with 4 additions and 4 deletions.
@@ -1,19 +1,19 @@
package app.cash.sqldelight.async.coroutines

import app.cash.sqldelight.Query
import app.cash.sqldelight.ExecutableQuery

suspend fun <T : Any> Query<T>.awaitAsList(): List<T> = execute { cursor ->
suspend fun <T : Any> ExecutableQuery<T>.awaitAsList(): List<T> = execute { cursor ->
val result = mutableListOf<T>()
while (cursor.next()) result.add(mapper(cursor))
result
}.await()

suspend fun <T : Any> Query<T>.awaitAsOne(): T {
suspend fun <T : Any> ExecutableQuery<T>.awaitAsOne(): T {
return awaitAsOneOrNull()
?: throw NullPointerException("ResultSet returned null for $this")
}

suspend fun <T : Any> Query<T>.awaitAsOneOrNull(): T? = execute { cursor ->
suspend fun <T : Any> ExecutableQuery<T>.awaitAsOneOrNull(): T? = execute { cursor ->
if (!cursor.next()) return@execute null
val value = mapper(cursor)
check(!cursor.next()) { "ResultSet returned more than 1 row for $this" }
Expand Down

0 comments on commit 76a6f9a

Please sign in to comment.