module CQL::Postgres::QueryStreaming

Overview

#stream for an executor that lends one Connection per call (AsyncEngine) or owns one (TransactionScope): the rows of a query, or of SQL with arguments, as a DB::ResultSet that fetches fetch_size rows at a time. Telemetry sees one statement whose duration is the whole stream. See Session#stream for early stops, errors, cancel and timeouts.

engine = CQL::Postgres::AsyncEngine.connect(ENV["DATABASE_URL"])
engine.stream(User.query.where(active: true), fetch_size: 500) do |rows|
  rows.each { puts rows.read(Int64) } # the model's columns, id first
end

Direct including types

Defined in:

postgres/query_streaming.cr

Instance Method Summary

Instance Method Detail

def stream(query : String, args : Array(DB::Any) = [] of ::DB::Any, fetch_size : Int32 = 1000, timeout : Time::Span | Nil = nil, & : DB::ResultSet -> T) : T forall T #

[View source]
def stream(query : Q, fetch_size : Int32 = 1000, timeout : Time::Span | Nil = nil, & : DB::ResultSet -> T) : T forall Q, T #

[View source]