Something unclear to me when using SQLDelight with...
# squarelibraries
b
Something unclear to me when using SQLDelight with
generateAsync.set(true)
. Any call to
driver.executeQuery()
should be migrated to
driver.awaitQuery()
, right? But this doesn't seem to work with a non-async driver such as the JDBC one on the JVM. For instance I'm doing this:
Copy code
driver.awaitQuery(
  null,
  "PRAGMA $versionPragma",
  { cursor ->
    // The cursor is already closed here
    if (cursor.next().await()) {
      cursor.getLong(0)
    } else {
      null
    }
  },
  0
)
using the debugger I can see that my lambda is called after the statement has already been closed which obviously cannot work. I must be missing something obvious? 🤔 Other extensions like
awaitAsOneOrNull()
seem to work as expected.
j
You're not missing anything
Async generation is only for async drivers
b
Interesting! Is there an idiomatic way to execute arbitrary queries that works for both sync and async?
Copy code
Query(
      0, 
      arrayOf(), 
      driver, 
      "", 
      "", 
      "my query") { cursor ->
     // ...
  }.awaitAsList()
This works, but seems a bit awkward maybe?