class CQL::Postgres::Connection

Overview

A crystal-db connection over a wire Session: what Executor#exec_query yields, so every CQL statement type runs on it unchanged.

Defined in:

postgres/connection.cr

Constant Summary

DRIVER_NAME = "postgres"

Constructors

Instance Method Summary

Constructor Detail

def self.new(session : CQL::Postgres::Session, options : DB::Connection::Options = ::DB::Connection::Options.new(prepared_statements_cache: false)) #

[View source]
def self.open(config : Config, options : DB::Connection::Options = ::DB::Connection::Options.new(prepared_statements_cache: false)) : Connection #

crystal-db's own per-connection statement-wrapper cache is off: the session already keeps a bounded cache of prepared statements.


[View source]

Instance Method Detail

def build_prepared_statement(query) : DB::Statement #
Description copied from class DB::Connection

:nodoc:


[View source]
def build_unprepared_statement(query) : DB::Statement #
Description copied from class DB::Connection

:nodoc:


[View source]
def cancel : Nil #

[View source]
def clear_handlers : Nil #

Per-borrower state (notice and notification handlers) does not outlive a checkout.


[View source]
def closed? : Bool #

A connection whose session was dropped (after a network error, a protocol error or a timeout) is closed for good, even if nobody called close.


[View source]
def copy_in(sql : String, & : CopyIn -> ) : Int64 #

[View source]
def copy_in_binary(sql : String, types : Array(UInt32), & : BinaryCopy::Writer -> ) : Int64 #

[View source]
def copy_out(sql : String, & : Bytes -> ) : Int64 #

[View source]
def copy_out_binary(sql : String, types : Array(UInt32), &on_row : Array(Types::Value) -> ) : Int64 #

[View source]
def driver_name : String #

crystal-db 0.15 requires it: the name the driver is registered with.


[View source]
def exec_all(sql : String) : Nil #

Runs a script of several statements; no rows come back.


[View source]
def in_transaction? : Bool #

[View source]
def inspect(io : IO) : Nil #
Description copied from class Reference

Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>

[View source]
def on_notice(&handler : Hash(Char, String) -> ) : Nil #

[View source]
def on_notification(&handler : Notification -> ) : Nil #

[View source]
def ping(timeout : Time::Span = CQL::Postgres::Session::PING_TIMEOUT) : Bool #

[View source]
def pipeline(statements : Array(Tuple(String, Array(Types::Param)))) : Array(Result | ServerError) #

Several statements, one network round trip. See Session#pipeline.


[View source]
def session : CQL::Postgres::Session #

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

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

Runs a query and yields a result set that reads rows from the server fetch_size at a time, so a large result is never held whole. The connection is busy until the block returns; stopping early is fine. See Session#stream for the details, including the timeout.

engine = CQL::Postgres::AsyncEngine.connect(ENV["DATABASE_URL"])
engine.with_connection do |connection|
  connection.stream("SELECT id, name FROM users WHERE age > $1", 18, fetch_size: 500) do |rows|
    rows.each { puts "#{rows.read(Int64)} #{rows.read(String)}" }
  end
end

[View source]