Class: ActiveRecord::ConnectionAdapters::PostgreSQLMaterializedViewDefinition
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQLMaterializedViewDefinition
- Includes:
- PostgreSQLExtensions::Utils
- Defined in:
- lib/active_record/postgresql_extensions/materialized_views.rb
Overview
Creates a PostgreSQL materialized view definition. This class isn’t really meant to be used directly. Instead, see PostgreSQLAdapter#create_materialized_view for usage.
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(base, name, query, options = {}) ⇒ PostgreSQLMaterializedViewDefinition
constructor
:nodoc:.
-
#to_sql ⇒ Object
(also: #to_s)
:nodoc:.
Methods included from PostgreSQLExtensions::Utils
#hash_or_array_of_hashes, #options_from_hash_or_string, #strip_heredoc
Constructor Details
#initialize(base, name, query, options = {}) ⇒ PostgreSQLMaterializedViewDefinition
:nodoc:
163 164 165 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 163 def initialize(base, name, query, = {}) #:nodoc: @base, @name, @query, @options = base, name, query, end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
161 162 163 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 161 def base @base end |
#name ⇒ Object
Returns the value of attribute name.
161 162 163 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 161 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
161 162 163 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 161 def @options end |
#query ⇒ Object
Returns the value of attribute query.
161 162 163 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 161 def query @query end |
Instance Method Details
#to_sql ⇒ Object Also known as: to_s
:nodoc:
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 167 def to_sql #:nodoc: sql = "CREATE MATERIALIZED VIEW #{base.quote_view_name(name)} " if [:columns] sql << '(' << Array.wrap([:columns]).collect do |c| base.quote_column_name(c) end.join(', ') << ') ' end sql << "WITH (#{([:with_options])}) " if [:with_options].present? sql << "TABLESPACE #{base.quote_tablespace([:tablespace])} " if [:tablespace] sql << "AS #{query}" sql << " WITH NO DATA" if .key?(:with_data) && ![:with_data] "#{sql};" end |