class BigRecord::ConnectionAdapters::AbstractAdapter

All the concrete database adapters follow the interface laid down in this class. You can use this interface directly by borrowing the database connection from the Base with BigRecord::Base#connection.

Most of the methods in the adapter are useful during migrations. Most notably, SchemaStatements#create_table, SchemaStatements#drop_table, SchemaStatements#add_index, SchemaStatements#remove_index, SchemaStatements#add_column, SchemaStatements#change_column and SchemaStatements#remove_column are very useful.

Public Instance Methods

active?() click to toggle source

Is this connection active and ready to perform queries?

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 79
def active?
  @active != false
end
adapter_name() click to toggle source

Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 29
def adapter_name
  'Abstract'
end
create_table(table_name, column_families) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 164
def create_table(table_name, column_families)
  raise NotImplementedError
end
delete(table_name, row) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 150
def delete(table_name, row)
  raise NotImplementedError
end
delete_all(table_name) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 154
def delete_all(table_name)
  raise NotImplementedError
end
disable_referential_integrity() { || ... } click to toggle source

Override to turn off referential integrity while executing +&block+

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 72
def disable_referential_integrity(&block)
  yield
end
disconnect!() click to toggle source

Close this connection

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 89
def disconnect!
  @active = false
end
drop_table(table_name) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 168
def drop_table(table_name)
  raise NotImplementedError
end
get(table_name, row, column, options={}) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 130
def get(table_name, row, column, options={})
  raise NotImplementedError
end
get_columns(table_name, row, columns, options={}) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 138
def get_columns(table_name, row, columns, options={})
  raise NotImplementedError
end
get_columns_raw(table_name, row, columns, options={}) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 134
def get_columns_raw(table_name, row, columns, options={})
  raise NotImplementedError
end
get_consecutive_rows(table_name, start_row, limit, columns, stop_row = nil) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 146
def get_consecutive_rows(table_name, start_row, limit, columns, stop_row = nil)
  raise NotImplementedError
end
get_consecutive_rows_raw(table_name, start_row, limit, columns, stop_row = nil) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 142
def get_consecutive_rows_raw(table_name, start_row, limit, columns, stop_row = nil)
  raise NotImplementedError
end
get_raw(table_name, row, column, options={}) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 126
def get_raw(table_name, row, column, options={})
  raise NotImplementedError
end
prefetch_primary_key?(table_name = nil) click to toggle source

Should primary key values be selected from their corresponding sequence before the insert statement? If true, next_sequence_value is called before each insert to set the record's primary key. This is false for all adapters but Firebird.

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 53
def prefetch_primary_key?(table_name = nil)
  false
end
quote_table_name(name) click to toggle source

Override to return the quoted table name if the database needs it

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 65
def quote_table_name(name)
  name
end
raw_connection() click to toggle source

Provides access to the underlying database connection. Useful for when you need to call a proprietary method such as postgresql's lo_* methods

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 112
def raw_connection
  @connection
end
reconnect!() click to toggle source

Close this connection and open a new one in its place.

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 84
def reconnect!
  @active = true
end
requires_reloading?() click to toggle source

Returns true if its safe to reload the connection between requests for development mode. This is not the case for Ruby/MySQL and it's not necessary for any adapters except SQLite.

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 95
def requires_reloading?
  false
end
supports_count_distinct?() click to toggle source

Does this adapter support using DISTINCT within COUNT? This is true for all adapters except sqlite.

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 41
def supports_count_distinct?
  false
end
supports_ddl_transactions?() click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 45
def supports_ddl_transactions?
  false
end
supports_migrations?() click to toggle source

Does this adapter support migrations? Backend specific, as the abstract adapter always returns false.

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 35
def supports_migrations?
  false
end
table_exists?(table_name) click to toggle source

SCHEMA STATEMENTS ========================================

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 160
def table_exists?(table_name)
  raise NotImplementedError
end
update(table_name, row, values, timestamp) click to toggle source
# File lib/big_record/connection_adapters/abstract_adapter.rb, line 122
def update(table_name, row, values, timestamp)
  raise NotImplementedError
end
update_raw(table_name, row, values, timestamp) click to toggle source

DATABASE STATEMENTS ======================================

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 118
def update_raw(table_name, row, values, timestamp)
  raise NotImplementedError
end
verify!(timeout) click to toggle source

Lazily verify this connection, calling active? only if it hasn't been called for timeout seconds.

# File lib/big_record/connection_adapters/abstract_adapter.rb, line 101
def verify!(timeout)
  now = Time.now.to_i
  if (now - @last_verification) > timeout
    reconnect! unless active?
    @last_verification = now
  end
end