Filo.StmtResult (Filo v0.2.0)

Copy Markdown View Source

The result of executing a single statement, encoded to a Hrana StmtResult.

A host executor fills this struct with native Elixir values; encode/1 produces the Hrana wire form — rows as Filo.Value maps, last_insert_rowid as a string (Hrana carries i64 as a string), and the replication_index / query_duration_ms fields the protocol expects.

cols may be bare column-name strings or %{name: ..., decltype: ...} maps.

Summary

Functions

Decodes a Hrana StmtResult map back into a Filo.StmtResult — the inverse of encode/2, for Filo.Client.

Encodes a Filo.StmtResult into a Hrana StmtResult map.

Types

col()

@type col() :: String.t() | %{name: String.t() | nil, decltype: String.t() | nil}

t()

@type t() :: %Filo.StmtResult{
  affected_row_count: non_neg_integer(),
  cols: [col()],
  last_insert_rowid: integer() | nil,
  rows: [[Filo.Value.native()]],
  rows_read: non_neg_integer(),
  rows_written: non_neg_integer()
}

Functions

decode(result)

@spec decode(map()) :: t()

Decodes a Hrana StmtResult map back into a Filo.StmtResult — the inverse of encode/2, for Filo.Client.

Rows come back as native terms via Filo.Value.decode/1, last_insert_rowid parses from its wire string, and columns keep the %{name:, decltype:} shape.

encode(result, opts \\ [])

@spec encode(
  t(),
  keyword()
) :: map()

Encodes a Filo.StmtResult into a Hrana StmtResult map.

With rows: :json, "rows" is a Jason.Fragment holding ONE pre-encoded, flattened binary instead of the list-of-maps-of-tagged-maps: built where the result lives (the stream/socket process), so an HTTP reply crosses the process boundary as a refc binary reference instead of a deep structural copy, and the outer Jason.encode splices it without re-walking the row data. JSON transports only — the protobuf paths keep the default :maps form they can traverse.