# File lib/rails_db/adapters/base_adapter.rb, line 73 def self.primary_key(table_name) connection.primary_key(table_name) end
class RailsDb::Adapters::BaseAdapter
Constants
- MULTI_STATEMENT_HELP_TEXT
Public Class Methods
Source
# File lib/rails_db/adapters/base_adapter.rb, line 48 def self.adapter_name 'base' end
Source
# File lib/rails_db/adapters/base_adapter.rb, line 69 def self.count(table_name) select("SELECT COUNT(*) FROM #{table_name}")[0].rows.flatten.last.to_i end
Source
# File lib/rails_db/adapters/base_adapter.rb, line 60 def self.delete(table_name, pk_name, pk_id) case pk_id when Integer then execute("DELETE FROM #{table_name} WHERE #{pk_name} = #{pk_id};") else execute("DELETE FROM #{table_name} WHERE #{pk_name} = '#{pk_id}';") end end
Source
# File lib/rails_db/adapters/base_adapter.rb, line 28 def self.exec_query(sql) t0 = Time.now results = nil execute_with_sandbox_if_needed do results = connection.exec_query(sql) end execution_time = Time.now - t0 [results, execution_time] end
Source
# File lib/rails_db/adapters/base_adapter.rb, line 20 def self.execute(sql) t0 = Time.now execute_with_sandbox_if_needed do connection.execute(sql) end Time.now - t0 end
Source
# File lib/rails_db/adapters/base_adapter.rb, line 9 def self.execute_with_sandbox_if_needed if RailsDb.sandbox ActiveRecord::Base.transaction do yield raise ActiveRecord::Rollback end else yield end end
Source
# File lib/rails_db/adapters/base_adapter.rb, line 44 def self.explain(sql) BaseAdapter.exec_query(sql) end
Source
# File lib/rails_db/adapters/base_adapter.rb, line 77 def self.indexes(table_name) connection.indexes(table_name) end
Source
# File lib/rails_db/adapters/base_adapter.rb, line 83 def self.multiple_execute(sql, divider = ";\n") sql.split(divider).each do |statement| execute_with_sandbox_if_needed do connection.execute(statement) end end end
Source
Source
# File lib/rails_db/adapters/base_adapter.rb, line 40 def self.select(sql) BaseAdapter.exec_query(sql) end
Source
# File lib/rails_db/adapters/base_adapter.rb, line 56 def self.truncate(table_name) execute("TRUNCATE TABLE #{table_name};") end