Class: Scenic::Adapters::Mysql
- Inherits:
-
Object
- Object
- Scenic::Adapters::Mysql
- Defined in:
- lib/scenic/adapters/mysql.rb,
lib/scenic/adapters/mysql/views.rb,
lib/scenic/adapters/mysql/errors.rb,
lib/scenic/adapters/mysql/indexes.rb,
lib/scenic/adapters/mysql/connection.rb
Overview
An adapter for managing Mysql views.
These methods are used internally by Scenic and are not intended for direct use. Methods that alter database schema are intended to be called via Statements, while #refresh_materialized_view is called via Scenic.database.
The methods are documented here for insight into specifics of how Scenic integrates with Mysql and the responsibilities of Scenic::Adapters.
Defined Under Namespace
Classes: ConcurrentRefreshesNotSupportedError, Connection, Indexes, MaterializedViewsNotSupportedError, Views
Instance Method Summary collapse
-
#create_materialized_view(_name, _sql_definition) ⇒ void
materialized views.
-
#create_view(name, sql_definition) ⇒ void
Creates a view in the database.
-
#drop_materialized_view(_name) ⇒ void
materialized views.
-
#drop_view(name) ⇒ void
Drops the named view from the database.
-
#initialize(connectable = ActiveRecord::Base) ⇒ Mysql
constructor
Creates an instance of the Scenic Mysql adapter.
-
#refresh_materialized_view(_name, _concurrently: false) ⇒ void
materialized views.
-
#replace_view(name, sql_definition) ⇒ void
Replaces a view in the database using ‘CREATE OR REPLACE VIEW`.
-
#update_materialized_view(_name, _sql_definition) ⇒ void
materialized views.
-
#update_view(name, sql_definition) ⇒ void
Updates a view in the database.
-
#views ⇒ Array<Scenic::View>
Returns an array of views in the database.
Constructor Details
#initialize(connectable = ActiveRecord::Base) ⇒ Mysql
Creates an instance of the Scenic Mysql adapter.
Postgres is the default adapter for Scenic. To use this Mysql adapter, follow the example bellow
35 36 37 |
# File 'lib/scenic/adapters/mysql.rb', line 35 def initialize(connectable = ActiveRecord::Base) @connectable = connectable end |
Instance Method Details
#create_materialized_view(_name, _sql_definition) ⇒ void
This method returns an undefined value.
materialized views.
122 123 124 |
# File 'lib/scenic/adapters/mysql.rb', line 122 def create_materialized_view(_name, _sql_definition) raise MaterializedViewsNotSupportedError end |
#create_view(name, sql_definition) ⇒ void
This method returns an undefined value.
Creates a view in the database.
This is typically called in a migration via Statements#create_view.
57 58 59 |
# File 'lib/scenic/adapters/mysql.rb', line 57 def create_view(name, sql_definition) execute "CREATE VIEW #{quote_table_name(name)} AS #{sql_definition};" end |
#drop_materialized_view(_name) ⇒ void
This method returns an undefined value.
materialized views.
139 140 141 |
# File 'lib/scenic/adapters/mysql.rb', line 139 def drop_materialized_view(_name) raise MaterializedViewsNotSupportedError end |
#drop_view(name) ⇒ void
This method returns an undefined value.
Drops the named view from the database
This is typically called in a migration via Statements#drop_view.
114 115 116 |
# File 'lib/scenic/adapters/mysql.rb', line 114 def drop_view(name) execute "DROP VIEW #{quote_table_name(name)};" end |
#refresh_materialized_view(_name, _concurrently: false) ⇒ void
This method returns an undefined value.
materialized views.
148 149 150 |
# File 'lib/scenic/adapters/mysql.rb', line 148 def refresh_materialized_view(_name, _concurrently: false) raise MaterializedViewsNotSupportedError end |
#replace_view(name, sql_definition) ⇒ void
This method returns an undefined value.
Replaces a view in the database using ‘CREATE OR REPLACE VIEW`.
This results in a ‘CREATE OR REPLACE VIEW`. Most of the time the explicitness of the two step process used in #update_view is preferred to `CREATE OR REPLACE VIEW` because the former ensures that the view you are trying to update did, in fact, already exist. Additionally, `CREATE OR REPLACE VIEW` is allowed only to add new columns to the end of an existing view schema. Existing columns cannot be re-ordered, removed, or have their types changed. Drop and create overcomes this limitation as well.
However, when there is a tangled dependency tree ‘CREATE OR REPLACE VIEW` can be preferable.
This is typically called in a migration via Statements#replace_view.
103 104 105 |
# File 'lib/scenic/adapters/mysql.rb', line 103 def replace_view(name, sql_definition) execute "CREATE OR REPLACE VIEW #{quote_table_name(name)} AS #{sql_definition};" end |
#update_materialized_view(_name, _sql_definition) ⇒ void
This method returns an undefined value.
materialized views.
130 131 132 |
# File 'lib/scenic/adapters/mysql.rb', line 130 def update_materialized_view(_name, _sql_definition) raise MaterializedViewsNotSupportedError end |
#update_view(name, sql_definition) ⇒ void
This method returns an undefined value.
Updates a view in the database.
This results in a #drop_view followed by a #create_view. The explicitness of that two step process is preferred to ‘CREATE OR REPLACE VIEW` because the former ensures that the view you are trying to update did, in fact, already exist. Additionally, `CREATE OR REPLACE VIEW` is allowed only to add new columns to the end of an existing view schema. Existing columns cannot be re-ordered, removed, or have their types changed. Drop and create overcomes this limitation as well.
This is typically called in a migration via Statements#update_view.
77 78 79 80 |
# File 'lib/scenic/adapters/mysql.rb', line 77 def update_view(name, sql_definition) drop_view(name) create_view(name, sql_definition) end |