Skip to content

Async I/O and coroutines

Every query API in sqlx4k is a suspend function that returns a Result: execute, fetchAll, begin, transaction { } and the generated repository methods suspend instead of blocking the calling thread, and report failures through the Result instead of throwing. Database calls therefore compose with the rest of your coroutine code, from async and withTimeout to structured concurrency, and the I/O underneath is non-blocking on every platform.

This guide covers the core API, shared by every driver:

  • Connection pool: configuring the pool, and acquiring connections.
  • Running queries: execute, executeWithResult, fetchAll, fetch and prepared statements.
  • Mapping rows: row mappers and custom value converters.
  • Transactions: transactions, savepoints and TransactionContext.
  • Migrations: running and validating database migrations.

For the generated repositories, see Code generation.