class Prostore::Connection

Overview

High-level handle bundling a DB::Database pool with a chosen Adapter.

Per-connection session setup (e.g. PRAGMA foreign_keys = ON for SQLite, ADR-0012) is installed via DB::Database#setup_connection so every connection acquired from the pool is initialized.

Connection delegates #exec, #scalar, #query_one, #query_one?, #query_each, and #transaction directly to the underlying pool, so callers can use conn.exec(...) rather than conn.db.exec(...).

Defined in:

prostore/connection.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(db : DB::Database, adapter : Adapter::Base, url : String) #

[View source]
def self.open(url : String) : Connection #

[View source]

Instance Method Detail

def adapter : Adapter::Base #

[View source]
def close : Nil #

[View source]
def db : DB::Database #

[View source]
def exec(query : String, *args_, args : Array | Nil = nil) : DB::ExecResult #

[View source]
def query_each(query : String, *args_, args : Array | Nil = nil, & : DB::ResultSet -> Nil) : Nil #

[View source]
def query_one(query : String, *args_, args : Array | Nil = nil, & : DB::ResultSet -> T) forall T #

[View source]
def query_one?(query : String, *args_, args : Array | Nil = nil, & : DB::ResultSet -> T) forall T #

[View source]
def scalar(query : String, *args_, args : Array | Nil = nil) #

[View source]
def transaction(& : DB::Transaction -> T) forall T #

[View source]
def url : String #

[View source]
def with_connection(&) #

Acquire a single connection and yield it. The runner uses this to keep all bootstrap / migration DDL on one connection so that nested operations don't deadlock the pool.


[View source]