abstract class DB::Connection

Overview

Database driver implementors must subclass Connection.

Represents one active connection to a database.

Users should never instantiate a Connection manually. Use DB#open or Database#connection.

Refer to QueryMethods for documentation about querying the database through this connection.

Note to implementors

The connection must be initialized in #initialize and closed in #do_close.

Override #build_statement method in order to return a prepared Statement to allow querying. See also Statement to define how the statements are executed.

If at any give moment the connection is lost a DB::ConnectionLost should be raised. This will allow the connection pool to try to reconnect or use another connection if available.

Included Modules

Defined in:

db/connection.cr

Class Method Summary

Instance Method Summary

Instance methods inherited from module DB::QueryMethods

exec(query, *args) exec, query(query, *args)
query(query, *args, &block)
query
, query_all(query, *args, &block : ResultSet -> U) : Array(U)
query_all(query, *args, as types : Tuple)
query_all(query, *args, as type : Class)
query_all
, query_one(query, *args, &block : ResultSet -> U) : U
query_one(query, *args, as types : Tuple)
query_one(query, *args, as type : Class)
query_one
, query_one?(query, *args, &block : ResultSet -> U) : U?
query_one?(query, *args, as types : Tuple)
query_one?(query, *args, as type : Class)
query_one?
, scalar(query, *args) scalar

Instance methods inherited from module DB::Disposable

close close, closed? closed?

Class Method Detail

def self.new(database : Database) #

[View source]

Instance Method Detail

abstract def build_statement(query) : Statement #

[View source]