class Scenic::Adapters::Mysql::Views
Fetches defined views from the mysql connection. @api private
Attributes
connection[R]
Public Class Methods
new(connection)
click to toggle source
# File lib/scenic/adapters/mysql/views.rb, line 8 def initialize(connection) @connection = connection end
Public Instance Methods
all()
click to toggle source
All of the views that this connection has defined.
This will include materialized views if those are supported by the connection.
@return [Array<Scenic::View>]
# File lib/scenic/adapters/mysql/views.rb, line 22 def all views_from_mysql.map(&method(:to_scenic_view)) end
current_database()
click to toggle source
# File lib/scenic/adapters/mysql/views.rb, line 12 def current_database @connection.current_database end
Private Instance Methods
scrub_view_def(view_def)
click to toggle source
Sometimes MySQL will include the database name in view definitions. This scrubs it out.
# File lib/scenic/adapters/mysql/views.rb, line 51 def scrub_view_def(view_def) view_def.strip.gsub(/([\`]*#{current_database}[\`]*\.)/i, '') end
to_scenic_view(result)
click to toggle source
# File lib/scenic/adapters/mysql/views.rb, line 38 def to_scenic_view(result) table_name, view_def = result Scenic::View.new( name: table_name, definition: scrub_view_def(view_def), materialized: false ) end
views_from_mysql()
click to toggle source
# File lib/scenic/adapters/mysql/views.rb, line 30 def views_from_mysql connection.select_rows(<<-SQL) SELECT table_name, view_definition FROM information_schema.views WHERE table_schema = SCHEMA() SQL end