Barograph.Rows (barograph v0.2.0)

Copy Markdown View Source

Drains a prepared statement into a list of rows.

Exqlite.Sqlite3.step/2 returns :done | :busy | {:row, row} | {:error, reason}. :busy and {:error, reason} can both surface after a statement has already yielded rows — a lock timeout or a disk I/O error mid-scan, not just on the first step. The naive Stream.repeatedly(&step/2) |> Stream.take_while(&match?({:row, _}, &1)) idiom treats those identically to :done, silently returning whatever rows were collected so far as if the query had succeeded. fetch_all/2 and fetch_all!/2 distinguish a genuine end-of-results from a failure instead.

Summary

Functions

Returns {:ok, rows}, or {:error, reason} if a step fails before :done.

Like fetch_all/2, but raises on :busy or {:error, reason}.

Functions

fetch_all(conn, statement)

@spec fetch_all(Exqlite.Sqlite3.db(), Exqlite.Sqlite3.statement()) ::
  {:ok, [Exqlite.Sqlite3.row()]} | {:error, term()}

Returns {:ok, rows}, or {:error, reason} if a step fails before :done.

fetch_all!(conn, statement)

Like fetch_all/2, but raises on :busy or {:error, reason}.