class CQL::Postgres::Pool

Overview

Bounded set of connections shared by many fibers. #checkout waits (up to checkout_timeout) for a free slot; #release returns the connection, or drops it if it is closed or still inside a transaction. Idle connections that sat unused for health_check_after are pinged before being handed out.

Included Modules

Defined in:

postgres/pool.cr

Constant Summary

MIN_PING_BUDGET = 50.milliseconds

A health check with less time left than this is not worth a round trip.

Constructors

Instance Method Summary

Constructor Detail

def self.new(config : Config, options : Options = Options.from(config)) #

[View source]

Instance Method Detail

def checkout : Connection #

[View source]
def close : Nil #

[View source]
def closed? : Bool #

[View source]
def config : Config #

[View source]
def discard(connection : DB::Connection) : Nil #

The connection is gone for good (closed, or dropped by #release).


[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 options : Options #

[View source]
def release(connection : DB::Connection) : Nil #

Returns a checked-out connection. Release each checkout exactly once: a second release after the connection was lent to someone else would return that other lease.


[View source]
def stats : Stats #

[View source]
def warm_up : self #

Startup only, before fibers check out: opens min_size connections up front, so the first requests do not pay for connecting and a wrong URL fails at startup. They are not refilled when retired later; the pool then grows on demand.


[View source]
def with_connection(& : Connection -> T) : T forall T #

Checks a connection out for the block and always returns it.


[View source]