Module: ActiveRecord::View::Integration::SchemaMethods

Extended by:
Utility, ActiveSupport::Concern
Defined in:
lib/activerecord/view/integration/schema_methods.rb

Constant Summary collapse

CREATE_VIEW_FMT =
cleanup <<-SQL
CREATE%<or_replace>s VIEW %<name>s AS %<body>s
SQL
DROP_VIEW_FMT =
cleanup <<-SQL
DROP VIEW%<if_exists>s %<name>s%<restriction>s
SQL
CREATE_MATERIALIZED_VIEW_FMT =
cleanup <<-SQL
CREATE%<or_replace>s MATERIALIZED VIEW %<name>s AS %<body>s %<with_data>s
SQL
DROP_MATERIALIZED_VIEW_FMT =
cleanup <<-SQL
DROP MATERIALIZED VIEW%<if_exists>s %<name>s%<restriction>s
SQL
MATERIALIZED_VIEW_ADAPTERS =
%w[PostgreSQL PostGIS]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utility

cleanup

Class Method Details

.quote_table_name(name) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Stub method for tests.

Parameters:

  • name (String)

Returns:

  • (String)


171
172
173
# File 'lib/activerecord/view/integration/schema_methods.rb', line 171

def quote_table_name(name)
  %["#{name}"]
end

Instance Method Details

#create_materialized_view(name, body = nil, force: false, **kwargs, &block) ⇒ void

This method returns an undefined value.

Create a materialized view.

Only valid on Postgres.

Parameters:

  • name (#to_s)
  • body (String, #to_sql) (defaults to: nil)
  • replace (Boolean)
  • with_data (Boolean)

    Whether the materialized view should be automatically populated on create.



54
55
56
57
58
59
60
# File 'lib/activerecord/view/integration/schema_methods.rb', line 54

def create_materialized_view(name, body = nil, force: false, **kwargs, &block)
  supports_materialized_view!

  drop_materialized_view(name) if force && table_exists?(name)

  execute build_create_materialized_view_query(name, body, **kwargs, &block)
end

#create_view(name, body = nil, force: false, **kwargs, &block) ⇒ void

This method returns an undefined value.

Create a SQL view.

Parameters:

  • name (#to_s)
  • body (String, #to_sql) (defaults to: nil)
  • replace (Boolean)
  • sqlite3 (Boolean)

    whether this should be built for SQLite3 (SQLite3 does not support ‘OR REPLACE` syntax)



30
31
32
33
34
35
36
# File 'lib/activerecord/view/integration/schema_methods.rb', line 30

def create_view(name, body = nil, force: false, **kwargs, &block)
  kwargs[:sqlite3] = !!(adapter_name =~ /sqlite/i)

  drop_view(name) if force && table_exists?(name)

  execute build_create_view_query(name, body, **kwargs, &block)
end

#drop_materialized_view(name, **kwargs) ⇒ void

This method returns an undefined value.

Drop a materialized view.

Only valid on Postgres.



68
69
70
71
72
# File 'lib/activerecord/view/integration/schema_methods.rb', line 68

def drop_materialized_view(name, **kwargs)
  supports_materialized_view!

  execute build_drop_materialized_view_query(name, **kwargs)
end

#drop_view(name, **kwargs) ⇒ void

This method returns an undefined value.

Drop a SQL view.



42
43
44
45
46
# File 'lib/activerecord/view/integration/schema_methods.rb', line 42

def drop_view(name, **kwargs)
  kwargs[:sqlite3] = !!(adapter_name =~ /sqlite/i)

  execute build_drop_view_query(name, **kwargs)
end