Class: Lhm::Connection::ActiveRecordConnection
- Inherits:
-
Object
- Object
- Lhm::Connection::ActiveRecordConnection
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
Returns a new instance of ActiveRecordConnection.
93
94
95
96
|
# File 'lib/lhm/connection.rb', line 93
def initialize(adapter)
@adapter = adapter
@database_name = @adapter.current_database
end
|
Instance Method Details
#current_database ⇒ Object
111
112
113
|
# File 'lib/lhm/connection.rb', line 111
def current_database
@database_name
end
|
#destination_create(origin) ⇒ Object
135
136
137
138
139
140
|
# File 'lib/lhm/connection.rb', line 135
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
142
143
144
|
# File 'lib/lhm/connection.rb', line 142
def execute(sql)
@adapter.execute(sql)
end
|
#quote_value(value) ⇒ Object
150
151
152
|
# File 'lib/lhm/connection.rb', line 150
def quote_value(value)
@adapter.quote(value)
end
|
#select_all(sql) ⇒ Object
119
120
121
|
# File 'lib/lhm/connection.rb', line 119
def select_all(sql)
@adapter.select_all(sql)
end
|
#select_one(sql) ⇒ Object
123
124
125
|
# File 'lib/lhm/connection.rb', line 123
def select_one(sql)
@adapter.select_one(sql)
end
|
#select_value(sql) ⇒ Object
131
132
133
|
# File 'lib/lhm/connection.rb', line 131
def select_value(sql)
@adapter.select_value(sql)
end
|
#select_values(sql) ⇒ Object
127
128
129
|
# File 'lib/lhm/connection.rb', line 127
def select_values(sql)
@adapter.select_values(sql)
end
|
#show_create(table_name) ⇒ Object
104
105
106
107
108
109
|
# File 'lib/lhm/connection.rb', line 104
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
98
99
100
101
102
|
# File 'lib/lhm/connection.rb', line 98
def sql(statements)
[statements].flatten.each do |statement|
execute(tagged(statement))
end
end
|
#table_exists?(table_name) ⇒ Boolean
146
147
148
|
# File 'lib/lhm/connection.rb', line 146
def table_exists?(table_name)
@adapter.table_exists?(table_name)
end
|
#update(sql) ⇒ Object
115
116
117
|
# File 'lib/lhm/connection.rb', line 115
def update(sql)
@adapter.update(sql)
end
|