Module: Frostlake

Defined in:
lib/frostlake.rb

Defined Under Namespace

Classes: Connection, ConnectionError, Error, QueryError, Result, UsageError

Constant Summary collapse

VERSION =
"0.1.0"
DEFAULT_PORT =
18_082
DSN_PARAMETERS =

Everything the DSN query string may carry. Anything else is a typo, and a typo in schema or read_timeout changes behaviour without saying so.

["ca_file", "open_timeout", "read_timeout", "schema",
"session_idle_limit", "verify_ssl"].freeze
DEFAULT_OPEN_TIMEOUT =

Long enough for a slow query, short enough that an unreachable host fails while someone is still watching.

10
DEFAULT_READ_TIMEOUT =
300
DEFAULT_SESSION_IDLE_LIMIT =

The engine reaps a session after 30 minutes idle. Past that we have to assume ours is gone, because nothing in a response says so.

1800
APPROXIMATE_TYPES =

The engine's binary floating-point types. Every other numeric it reports is fixed-point and keeps its digits.

["FLOAT", "FLOAT4", "FLOAT8", "DOUBLE", "DOUBLE PRECISION", "REAL"].freeze

Class Method Summary collapse

Class Method Details

.connect(dsn, open_timeout: nil, read_timeout: nil, verify_ssl: nil, ca_file: nil, session_idle_limit: nil) ⇒ Object

Connects, verifies the server is reachable via GET /api/health, and applies the database and schema from the DSN. Timeouts are in seconds; verify_ssl and ca_file apply to https DSNs. All four may also be given in the DSN query string, where an explicit argument outranks them.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/frostlake.rb', line 75

def self.connect(dsn, open_timeout: nil, read_timeout: nil, verify_ssl: nil, ca_file: nil,
                 session_idle_limit: nil)
  conn = Connection.new(dsn, open_timeout: open_timeout, read_timeout: read_timeout,
                        verify_ssl: verify_ssl, ca_file: ca_file,
                        session_idle_limit: session_idle_limit)
  begin
    conn.ping
    conn.use_dsn_defaults
  rescue StandardError
    # Nothing usable came of it, so do not leave a session behind.
    conn.close
    raise
  end
  conn
end