Module: RailsSqlViews::ConnectionAdapters::MysqlAdapter
- Defined in:
- lib/rails_sql_views/connection_adapters/mysql_adapter.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#base_tables(name = nil) ⇒ Object
(also: #nonview_tables)
:nodoc:.
- #structure_dump ⇒ Object
-
#supports_views? ⇒ Boolean
Returns true as this adapter supports views.
-
#view_select_statement(view, name = nil) ⇒ Object
Get the view select statement for the specified table.
-
#views(name = nil) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 |
# File 'lib/rails_sql_views/connection_adapters/mysql_adapter.rb', line 4 def self.included(base) if base.private_method_defined?(:supports_views?) base.send(:public, :supports_views?) end end |
Instance Method Details
#base_tables(name = nil) ⇒ Object Also known as: nonview_tables
:nodoc:
15 16 17 18 19 |
# File 'lib/rails_sql_views/connection_adapters/mysql_adapter.rb', line 15 def base_tables(name = nil) #:nodoc: tables = [] execute("SHOW FULL TABLES WHERE TABLE_TYPE='BASE TABLE'").each{|row| tables << row[0]} tables end |
#structure_dump ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rails_sql_views/connection_adapters/mysql_adapter.rb', line 28 def structure_dump structure = "" base_tables.each do |table| structure += select_one("SHOW CREATE TABLE #{quote_table_name(table)}")["Create Table"] + ";\n\n" end views.each do |view| structure += select_one("SHOW CREATE VIEW #{quote_table_name(view)}")["Create View"] + ";\n\n" end return structure end |
#supports_views? ⇒ Boolean
Returns true as this adapter supports views.
11 12 13 |
# File 'lib/rails_sql_views/connection_adapters/mysql_adapter.rb', line 11 def supports_views? true end |
#view_select_statement(view, name = nil) ⇒ Object
Get the view select statement for the specified table.
42 43 44 45 46 47 48 49 50 |
# File 'lib/rails_sql_views/connection_adapters/mysql_adapter.rb', line 42 def view_select_statement(view, name=nil) begin execute("SHOW CREATE VIEW #{view}", name).each do |row| return convert_statement(row[1]) if row[0] == view end rescue ActiveRecord::StatementInvalid => e raise "No view called #{view} found" end end |
#views(name = nil) ⇒ Object
:nodoc:
22 23 24 25 26 |
# File 'lib/rails_sql_views/connection_adapters/mysql_adapter.rb', line 22 def views(name = nil) #:nodoc: views = [] execute("SHOW FULL TABLES WHERE TABLE_TYPE='VIEW'").each{|row| views << row[0]} views end |