abstract class Jennifer::Adapter::Base

Included Modules

Extended Modules

Direct Known Subclasses

Defined in:

jennifer/adapter/base.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Jennifer::Adapter::ResultParsers

read_column(rs, column) read_column, result_to_array_by_names(rs, names : Array(String)) result_to_array_by_names, result_to_hash(rs) result_to_hash

Instance methods inherited from module Jennifer::Adapter::Transactions

begin_transaction begin_transaction, current_transaction current_transaction, rollback_transaction rollback_transaction, subscribe_on_commit(block : -> Bool) subscribe_on_commit, subscribe_on_rollback(block : -> Bool) subscribe_on_rollback, transaction(&) transaction, under_transaction? under_transaction?, with_connection(&) with_connection, with_manual_connection(&) with_manual_connection

Constructor Detail

def self.new(config : Config) #

[View source]

Class Method Detail

def self.foreign_key_name(from_table, to_table = nil, column = nil, name : String? = nil) : String #

Generates foreign key name for given tables.


[View source]
def self.join_table_name(table1 : String | Symbol, table2 : String | Symbol) #

Generates name for join table.


[View source]
def self.t(field : Nil) #

filter out value; should be refactored


[View source]
def self.t(field : String) #

[View source]
def self.t(field) #

[View source]

Instance Method Detail

def bulk_insert(table : String, fields : Array(String), values : Array(ArgsType)) #

[View source]
def bulk_insert(collection : Array(Model::Base)) #

[View source]
abstract def column_exists?(table, name) #

Returns whether column of table with name exists.

# Check a column exists
column_exists?(:suppliers, :name)

[View source]
abstract def command_interface #

[View source]
def config : Config #

[View source]
def connection_string(type : ConnectionType) #

[View source]
def count(query : QueryBuilder::Query) #

[View source]
def create_database #

[View source]
def database_exists? #

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

[View source]
def db_connection(&) #

Yields to block connection to the database main schema.


[View source]
abstract def default_type_size(name) #

[View source]
def delete(query : QueryBuilder::Query) #

[View source]
def drop_database #

[View source]
def exec(query : String, args : ArgsType = [] of DBAny) : DB::ExecResult #

[View source]
def exists?(query : QueryBuilder::Query) : Bool #

[View source]
abstract def explain(q) #

[View source]
abstract def foreign_key_exists?(from_table, to_table = nil, column = nil, name : String? = nil) : Bool #

Checks to see if a foreign key exists on a table for a given foreign key definition.

# Checks to see if a foreign key exists.
adapter.foreign_key_exists?(:accounts, :branches)

# Checks to see if a foreign key on a specified column exists.
adapter.foreign_key_exists?(:accounts, column: :owner_id)

# Checks to see if a foreign key with a custom name exists.
adapter.foreign_key_exists?(:accounts, name: "special_fk_name")

[View source]
def generate_schema #

[View source]
def index_exists?(table, fields : Array) #

Returns whether index for the *table` with name or fields exists.

# Check an index exists
adapter.index_exists?(:suppliers, :company_id)

# Check an index on multiple columns exists
adapter.index_exists?(:suppliers, [:company_id, :company_type])

# Check an index with a custom name exists
adapter.index_exists?(:suppliers, "idx_company_id")

[View source]
abstract def index_exists?(table, name : String) #

[View source]
abstract def insert(obj : Model::Base) #

[View source]
def load_schema #

[View source]
def log_query(query : String, args : Enumerable, &) #

[View source]
def log_query(query : String, &) #

[View source]
def max_bind_vars_count #

[View source]
def parse_query(q : String, args : ArgsType) #

[View source]
def parse_query(q : String) #

[View source]
def prepare #

[View source]
def query(query : String, args : ArgsType = [] of DBAny, &) #

[View source]
def query_array(_query : String, klass : T.class, field_count : Int32 = 1) forall T #

[View source]
def ready_to_migrate! #

[View source]
def refresh_materialized_view(name) #

[View source]
def scalar(query : String, args : ArgsType = [] of DBAny) #

[View source]
abstract def schema_processor #

[View source]
abstract def sql_generator #

[View source]
abstract def table_column_count(table) #

[View source]
abstract def table_exists?(table) #

Returns where table with given table name exists.

adapter.table_exists?(:developers)

[View source]
abstract def tables_column_count(tables : Array(String)) #

[View source]
abstract def translate_type(name) #

Translates symbol data type name to database-specific data type.


[View source]
def truncate(klass : Class) #

[View source]
def truncate(table_name : String) #

[View source]
def upsert(table : String, fields : Array(String), values : Array(ArgsType), unique_fields : Array, on_conflict : Hash) #

[View source]
def upsert(collection : Array(Model::Base), unique_fields : Array, definition : Hash = {} of Nil => Nil) #

[View source]
abstract def view_exists?(name) : Bool #

Check whether view with given name exists.

adapter.view_exists?(:youth_contacts)

[View source]
abstract def with_table_lock(table : String, type : String = "default", &block : DB::Transaction -> Void) #

[View source]