Class: ActiveRecord::ConnectionAdapters::AbstractAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/adapter_extensions/connection_adapters/abstract_adapter.rb

Overview

Extensions to the AbstractAdapter. In some cases a default implementation is provided, in others it is adapter-dependent and the method will raise a NotImplementedError if the adapter does not implement that method

Direct Known Subclasses

MysqlAdapter, PostgreSQLAdapter, SQLServerAdapter

Instance Method Summary collapse

Instance Method Details

#add_select_into_table(new_table_name, sql_query) ⇒ Object

Add a chunk of SQL to the given query that will create a new table and execute the select into that table.

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/adapter_extensions/connection_adapters/abstract_adapter.rb', line 32

def add_select_into_table(new_table_name, sql_query)
  raise NotImplementedError, "add_select_into_table is an abstract method"
end

#bulk_load(file, table_name, options = {}) ⇒ Object

Bulk loading interface. Load the data from the specified file into the given table. Note that options will be adapter-dependent.

Raises:

  • (ArgumentError)


15
16
17
18
19
# File 'lib/adapter_extensions/connection_adapters/abstract_adapter.rb', line 15

def bulk_load(file, table_name, options={})
  raise ArgumentError, "#{file} does not exist" unless File.exist?(file)
  raise ArgumentError, "#{table_name} does not exist" unless tables.include?(table_name)
  do_bulk_load(file, table_name, options)
end

#support_select_into_table?Boolean

SQL select into statement constructs a new table from the results of a select. It is used to select data from a table and create a new table with its result set at the same time. Note that this method name does not necessarily match the implementation. E.g. MySQL's version of this is 'CREATE TABLE ... AS SELECT ...'

Returns:

  • (Boolean)


26
27
28
# File 'lib/adapter_extensions/connection_adapters/abstract_adapter.rb', line 26

def support_select_into_table?
  false
end

#truncate(table_name) ⇒ Object

Truncate the specified table



9
10
11
# File 'lib/adapter_extensions/connection_adapters/abstract_adapter.rb', line 9

def truncate(table_name)
  execute("TRUNCATE TABLE #{table_name}")
end