Class: ActiveRecord::View::Introspection::Postgres

Inherits:
Abstract
  • Object
show all
Defined in:
lib/activerecord/view/introspection/postgres.rb

Constant Summary collapse

REGCLASS =
Arel.sql 'regclass'
PG_TRUE =
Arel.sql 'true'
PG_FALSE =
Arel.sql 'false'
NOT_A_VIEW =
Arel::Nodes.build_quoted 'Not a view'

Instance Method Summary collapse

Methods inherited from Abstract

#arel_cast, #arel_fn, #arel_quoted, #arel_quoted?, #default_connection, #definition_for, #inspect, #process_view_definition, #select_manager, #views

Instance Method Details

#catch_undefined_tableObject

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.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/activerecord/view/introspection/postgres.rb', line 31

def catch_undefined_table
  yield
rescue ActiveRecord::StatementInvalid => e
  if e.original_exception.kind_of? PG::UndefinedTable
    raise e if raise_error?

    nil
  else
    # :nocov:
    raise e
    # :nocov:
  end
end

#fetch_view_definition_query(view_name, **options) ⇒ Object



12
13
14
# File 'lib/activerecord/view/introspection/postgres.rb', line 12

def fetch_view_definition_query(view_name, **options)
  select_manager.project nullify_if_not_view pg_get_viewdef(view_name, **options)
end

#nullify_if_not_view(expression) ⇒ Arel::Nodes::NamedFunction

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.

Returns:

  • (Arel::Nodes::NamedFunction)


26
27
28
# File 'lib/activerecord/view/introspection/postgres.rb', line 26

def nullify_if_not_view(expression)
  arel_fn 'NULLIF', expression, NOT_A_VIEW
end

#pg_get_viewdef(view_name, pretty: false, **options) ⇒ Arel::Nodes::NamedFunction

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.

Returns:

  • (Arel::Nodes::NamedFunction)


18
19
20
21
22
# File 'lib/activerecord/view/introspection/postgres.rb', line 18

def pg_get_viewdef(view_name, pretty: false, **options)
  pretty_bool = pretty ? PG_TRUE : PG_FALSE

  arel_fn 'pg_get_viewdef', arel_cast(view_name, REGCLASS), pretty_bool
end