Class: Lhm::Connection::ActiveRecordConnection

Inherits:
Object
  • Object
show all
Includes:
SqlHelper
Defined in:
lib/lhm/connection.rb

Instance Method Summary collapse

Methods included from SqlHelper

#annotation, #idx_name, #idx_spec, #version_string

Constructor Details

#initialize(adapter) ⇒ ActiveRecordConnection

Returns a new instance of ActiveRecordConnection.



85
86
87
88
# File 'lib/lhm/connection.rb', line 85

def initialize(adapter)
  @adapter       = adapter
  @database_name = @adapter.current_database
end

Instance Method Details

#current_databaseObject



103
104
105
# File 'lib/lhm/connection.rb', line 103

def current_database
  @database_name
end

#destination_create(origin) ⇒ Object



127
128
129
130
131
132
# File 'lib/lhm/connection.rb', line 127

def destination_create(origin)
  original    = %{CREATE TABLE `#{ origin.name }`}
  replacement = %{CREATE TABLE `#{ origin.destination_name }`}

  sql(origin.ddl.gsub(original, replacement))
end

#execute(sql) ⇒ Object



134
135
136
# File 'lib/lhm/connection.rb', line 134

def execute(sql)
  @adapter.execute(sql)
end

#select_all(sql) ⇒ Object



111
112
113
# File 'lib/lhm/connection.rb', line 111

def select_all(sql)
  @adapter.select_all(sql)
end

#select_one(sql) ⇒ Object



115
116
117
# File 'lib/lhm/connection.rb', line 115

def select_one(sql)
  @adapter.select_one(sql)
end

#select_value(sql) ⇒ Object



123
124
125
# File 'lib/lhm/connection.rb', line 123

def select_value(sql)
  @adapter.select_value(sql)
end

#select_values(sql) ⇒ Object



119
120
121
# File 'lib/lhm/connection.rb', line 119

def select_values(sql)
  @adapter.select_values(sql)
end

#show_create(table_name) ⇒ Object



96
97
98
99
100
101
# File 'lib/lhm/connection.rb', line 96

def show_create(table_name)
  sql = "show create table `#{ table_name }`"
  specification = nil
  execute(sql).each { |row| specification = row.last }
  specification
end

#sql(statements) ⇒ Object



90
91
92
93
94
# File 'lib/lhm/connection.rb', line 90

def sql(statements)
  [statements].flatten.each do |statement|
    execute(tagged(statement))
  end
end

#table_exists?(table_name) ⇒ Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/lhm/connection.rb', line 138

def table_exists?(table_name)
  @adapter.table_exists?(table_name)
end

#update(sql) ⇒ Object



107
108
109
# File 'lib/lhm/connection.rb', line 107

def update(sql)
  @adapter.update(sql)
end