Class: BigRecord::ConnectionAdapters::AbstractAdapter
- Inherits:
-
Object
- Object
- BigRecord::ConnectionAdapters::AbstractAdapter
- Includes:
- DatabaseStatements, Quoting
- Defined in:
- lib/big_record/connection_adapters/abstract_adapter.rb
Overview
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 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.
Direct Known Subclasses
Constant Summary
- @@row_even =
true
Instance Method Summary
-
- (Boolean) active?
Is this connection active and ready to perform queries?.
-
- (Object) adapter_name
Returns the human-readable name of the adapter.
- - (Object) create_table(table_name, column_families)
- - (Object) delete(table_name, row)
- - (Object) delete_all(table_name)
-
- (Object) disable_referential_integrity(&block)
Override to turn off referential integrity while executing &block.
-
- (Object) disconnect!
Close this connection.
- - (Object) drop_table(table_name)
- - (Object) get(table_name, row, column, options = {})
- - (Object) get_columns(table_name, row, columns, options = {})
- - (Object) get_columns_raw(table_name, row, columns, options = {})
- - (Object) get_consecutive_rows(table_name, start_row, limit, columns, stop_row = nil)
- - (Object) get_consecutive_rows_raw(table_name, start_row, limit, columns, stop_row = nil)
- - (Object) get_raw(table_name, row, column, options = {})
-
- (AbstractAdapter) initialize(connection, logger = nil)
constructor
:nodoc:.
-
- (Boolean) prefetch_primary_key?(table_name = nil)
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.
-
- (Object) quote_table_name(name)
Override to return the quoted table name if the database needs it.
-
- (Object) raw_connection
Provides access to the underlying database connection.
-
- (Object) reconnect!
Close this connection and open a new one in its place.
-
- (Boolean) requires_reloading?
Returns true if its safe to reload the connection between requests for development mode.
-
- (Object) reset_runtime
:nodoc:.
-
- (Boolean) supports_count_distinct?
Does this adapter support using DISTINCT within COUNT? This is true for all adapters except sqlite.
- - (Boolean) supports_ddl_transactions?
-
- (Boolean) supports_migrations?
Does this adapter support migrations? Backend specific, as the abstract adapter always returns false.
-
- (Boolean) table_exists?(table_name)
SCHEMA STATEMENTS ========================================.
- - (Object) update(table_name, row, values, timestamp)
-
- (Object) update_raw(table_name, row, values, timestamp)
DATABASE STATEMENTS ======================================.
-
- (Object) verify!(timeout)
Lazily verify this connection, calling active? only if it hasn’t been called for timeout seconds.
Methods included from Quoting
#quote, #quote_column_name, #quote_string, #quoted_date, #quoted_false, #quoted_true
Methods included from DatabaseStatements
Constructor Details
- (AbstractAdapter) initialize(connection, logger = nil)
:nodoc:
21 22 23 24 25 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 21 def initialize(connection, logger = nil) #:nodoc: @connection, @logger = connection, logger @runtime = 0 @last_verification = 0 end |
Instance Method Details
- (Boolean) active?
Is this connection active and ready to perform queries?
79 80 81 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 79 def active? @active != false end |
- (Object) adapter_name
Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.
29 30 31 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 29 def adapter_name 'Abstract' end |
- (Object) create_table(table_name, column_families)
164 165 166 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 164 def create_table(table_name, column_families) raise NotImplementedError end |
- (Object) delete(table_name, row)
150 151 152 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 150 def delete(table_name, row) raise NotImplementedError end |
- (Object) delete_all(table_name)
154 155 156 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 154 def delete_all(table_name) raise NotImplementedError end |
- (Object) disable_referential_integrity(&block)
Override to turn off referential integrity while executing &block
72 73 74 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 72 def disable_referential_integrity(&block) yield end |
- (Object) disconnect!
Close this connection
89 90 91 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 89 def disconnect! @active = false end |
- (Object) drop_table(table_name)
168 169 170 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 168 def drop_table(table_name) raise NotImplementedError end |
- (Object) get(table_name, row, column, options = {})
130 131 132 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 130 def get(table_name, row, column, ={}) raise NotImplementedError end |
- (Object) get_columns(table_name, row, columns, options = {})
138 139 140 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 138 def get_columns(table_name, row, columns, ={}) raise NotImplementedError end |
- (Object) get_columns_raw(table_name, row, columns, options = {})
134 135 136 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 134 def get_columns_raw(table_name, row, columns, ={}) raise NotImplementedError end |
- (Object) get_consecutive_rows(table_name, start_row, limit, columns, stop_row = nil)
146 147 148 |
# 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 |
- (Object) get_consecutive_rows_raw(table_name, start_row, limit, columns, stop_row = nil)
142 143 144 |
# 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 |
- (Object) get_raw(table_name, row, column, options = {})
126 127 128 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 126 def get_raw(table_name, row, column, ={}) raise NotImplementedError end |
- (Boolean) prefetch_primary_key?(table_name = nil)
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.
53 54 55 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 53 def prefetch_primary_key?(table_name = nil) false end |
- (Object) quote_table_name(name)
Override to return the quoted table name if the database needs it
65 66 67 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 65 def quote_table_name(name) name end |
- (Object) raw_connection
Provides access to the underlying database connection. Useful for when you need to call a proprietary method such as postgresql’s lo_* methods
112 113 114 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 112 def raw_connection @connection end |
- (Object) reconnect!
Close this connection and open a new one in its place.
84 85 86 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 84 def reconnect! @active = true end |
- (Boolean) requires_reloading?
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.
95 96 97 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 95 def requires_reloading? false end |
- (Object) reset_runtime
:nodoc:
57 58 59 60 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 57 def reset_runtime rt, @runtime = @runtime, 0 rt end |
- (Boolean) supports_count_distinct?
Does this adapter support using DISTINCT within COUNT? This is true for all adapters except sqlite.
41 42 43 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 41 def supports_count_distinct? false end |
- (Boolean) supports_ddl_transactions?
45 46 47 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 45 def supports_ddl_transactions? false end |
- (Boolean) supports_migrations?
Does this adapter support migrations? Backend specific, as the abstract adapter always returns false.
35 36 37 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 35 def supports_migrations? false end |
- (Boolean) table_exists?(table_name)
SCHEMA STATEMENTS ========================================
160 161 162 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 160 def table_exists?(table_name) raise NotImplementedError end |
- (Object) update(table_name, row, values, timestamp)
122 123 124 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 122 def update(table_name, row, values, ) raise NotImplementedError end |
- (Object) update_raw(table_name, row, values, timestamp)
DATABASE STATEMENTS ======================================
118 119 120 |
# File 'lib/big_record/connection_adapters/abstract_adapter.rb', line 118 def update_raw(table_name, row, values, ) raise NotImplementedError end |
- (Object) verify!(timeout)
Lazily verify this connection, calling active? only if it hasn’t been called for timeout seconds.
101 102 103 104 105 106 107 |
# 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 |