class CsvFastImporter::Database::Queryable
Inherit from this class to create new custom database implementation Do not forget to call .identifier_quote_character
Public Class Methods
identifier_quote_character(character)
click to toggle source
Character used around identifiers (table or column name) to handle special characters
# File lib/csv_fast_importer/database/queryable.rb, line 13 def self.identifier_quote_character(character) define_method "identify" do |identifier| character + identifier + character end end
new(connection)
click to toggle source
# File lib/csv_fast_importer/database/queryable.rb, line 8 def initialize(connection) @connection = connection end
Public Instance Methods
connection()
click to toggle source
# File lib/csv_fast_importer/database/queryable.rb, line 23 def connection @connection.raw_connection end
delete_all(table)
click to toggle source
# File lib/csv_fast_importer/database/queryable.rb, line 41 def delete_all(table) execute "DELETE FROM #{identify(table)}" end
execute(query)
click to toggle source
# File lib/csv_fast_importer/database/queryable.rb, line 27 def execute(query) @connection.execute query end
identify(table_or_column)
click to toggle source
# File lib/csv_fast_importer/database/queryable.rb, line 19 def identify(table_or_column) raise '#identify method not available. #identifier_quote_character is certainly missing' end
query(query)
click to toggle source
# File lib/csv_fast_importer/database/queryable.rb, line 31 def query(query) @connection.select_value query end
transaction() { || ... }
click to toggle source
# File lib/csv_fast_importer/database/queryable.rb, line 35 def transaction @connection.transaction do yield end end
truncate(table)
click to toggle source
# File lib/csv_fast_importer/database/queryable.rb, line 45 def truncate(table) execute "TRUNCATE TABLE #{identify(table)}" end