abstract class Marten::DB::Connection::Base

Overview

Abstract base class for a database connection.

A database connection provides the main interface allowing to interact with the underlying database. Subclasses must define a set of function allowing to define backend-specifics such as statements, operators, etc.

Direct Known Subclasses

Defined in:

marten/db/connection/base.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(config : Conf::GlobalSettings::Database) #

[View source]

Instance Method Detail

def alias : String #

Returns the DB alias of the considered connection.


[View source]
def build_sql(&) #

Allows to conveniently build a SQL statement by yielding an array of nillable strings.


[View source]
abstract def distinct_clause_for(columns : Array(String)) : String #

Returns a distinct clause to remove duplicates from a query's results.

If column names are specified, only these specific columns will be checked to identify duplicates.


[View source]
def id : String #

Returns the identifier of the connection.


[View source]
abstract def insert(table_name : String, values : Hash(String, ::DB::Any), pk_field_to_fetch : String | Nil = nil) : ::DB::Any #

Allows to insert a new row in a specific table.


[View source]
abstract def left_operand_for(id : String, predicate) : String #

Returns the left operand to use for specific query predicate.

Most of the time the initial ID will be left intact but depending on the connection implementation and the considered predicate type (eg. "istartswith"), specific SQL functions could be applied on the column ID.


[View source]
abstract def limit_value(value : Int | Nil) : Int32 | Int64 | Nil | UInt32 | UInt64 #

Returns a compatible value to use in the context of a LIMIT statement for the database at hand.


[View source]
abstract def max_name_size : Int32 #

Returns the maximum size for table names, column names or index / constraint names.


[View source]
def observe_transaction_commit(block : -> Nil) #

Registers a proc to be called when the current transaction is committed to the databse.

This method has no effect if it is called outside of a transaction block.


[View source]
def observe_transaction_rollback(block : -> Nil) #

Registers a proc to be called when the current transaction is rolled back.

This method has no effect if it is called outside of a transaction block.


[View source]
def open(&) #

Provides a database entrypoint to the block.

If this method is called in an existing transaction, the connection associated with this transaction will be used instead.


[View source]
abstract def operator_for(predicate) : String #

Returns the operator to use for a specific query predicate.


[View source]
abstract def parameter_id_for_ordered_argument(number : Int) : String #

Returns the parameterized identifier for an ordered argument.

This method takes the number of the argument which is aimed to be part of an array of ordered SQL arguments.


[View source]
def quote(name : String | Symbol) : String #

Allows to quote a specific name (such as a table name or column ID) for the database at hand.


[View source]
abstract def quote_char : Char #

Returns the quote character to use to quote table names, columns, etc.


[View source]
def sanitize_like_pattern(pattern : String) : String #

Escapes special characters from a pattern aimed at being used in the context of a LIKE statement.


[View source]
abstract def scheme : String #

Returns the scheme to consider for the underlying database backend.


[View source]
def test_database? #

Returns true if the current database was explicitly configured for the test environment.

The only way this method can return true is when the database name was explicitly set in a configuration targetting the test environment.


[View source]
def transaction(&) #

Open a transaction.

Atomicity will be ensured for the database operations performed inside the block. Note that any existing transaction will be used in case of nested calls to this method.


[View source]
abstract def update(table_name : String, values : Hash(String, ::DB::Any), pk_column_name : String, pk_value : ::DB::Any) : Nil #

Allows to update an existing row in a specific table.


[View source]