postgleam/stream
Stream query results in chunks using portal suspension (Execute with a row limit), so large result sets never sit in memory all at once.
Values
pub fn fetch_chunk(
state: connection.ConnectionState,
prepared: connection.PreparedStatement,
registry: dict.Dict(Int, codec.Codec),
max_rows: Int,
timeout: Int,
) -> Result(
#(connection.StreamChunk, connection.ConnectionState),
error.Error,
)
Fetch a single chunk of rows from an already-bound portal.
pub fn fold(
state: connection.ConnectionState,
prepared: connection.PreparedStatement,
params: List(option.Option(value.Value)),
registry: dict.Dict(Int, codec.Codec),
max_rows: Int,
timeout: Int,
initial: acc,
f: fn(acc, List(option.Option(value.Value))) -> acc,
) -> Result(
#(#(acc, String), connection.ConnectionState),
error.Error,
)
Fold over a query’s rows, fetching max_rows at a time. Only one chunk is
held in memory. Returns the final accumulator and the command tag.
pub fn stream_query(
state: connection.ConnectionState,
prepared: connection.PreparedStatement,
params: List(option.Option(value.Value)),
registry: dict.Dict(Int, codec.Codec),
max_rows: Int,
timeout: Int,
) -> Result(
#(connection.ExtendedQueryResult, connection.ConnectionState),
error.Error,
)
Fetch all rows in chunks of max_rows and return them together.
Prefer fold for large results; this collects everything in memory.