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 7
def initialize(connection)
  @connection = connection
end

Public Instance Methods

all() click to toggle source

All of the views that this connection has defined. Mysql will return these views ordered by name. Difference from the original Postgres adapter:

Mysql2 gem only watches one schema at a time.

This will not include materialized views as these are not supported by mysql.

@return [Array<Scenic::View>]

# File lib/scenic/adapters/mysql/views.rb, line 20
def all
  views_from_mysql.map(&method(:to_scenic_view))
end

Private Instance Methods

to_scenic_view(result) click to toggle source
# File lib/scenic/adapters/mysql/views.rb, line 36
def to_scenic_view(result)
  Scenic::View.new(
    name: result['TABLE_NAME'],
    definition: result['VIEW_DEFINITION'].strip,
    materialized: false
  )
end
views_from_mysql() click to toggle source
# File lib/scenic/adapters/mysql/views.rb, line 28
        def views_from_mysql
          ActiveRecord::Base.connection.exec_query(<<-SQL)
                        SELECT TABLE_NAME, VIEW_DEFINITION, TABLE_SCHEMA
                            FROM information_schema.VIEWS
                              WHERE TABLE_SCHEMA = DATABASE();
          SQL
        end