Module: RailsSqlViews::ConnectionAdapters::PostgreSQLAdapter

Defined in:
lib/rails_sql_views/connection_adapters/postgresql_adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 4

def self.included(base)
  base.alias_method_chain :tables, :views_included
end

Instance Method Details

#base_tables(name = nil) ⇒ Object Also known as: nonview_tables



23
24
25
26
27
28
29
30
31
32
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 23

def base_tables(name = nil)
  q = <<-SQL
  SELECT table_name, table_type
    FROM information_schema.tables
   WHERE table_schema IN (#{schemas})
     AND table_type = 'BASE TABLE'
  SQL
  
  query(q, name).map { |row| row[0] }
end

#supports_views?Boolean

Returns true as this adapter supports views.

Returns:

  • (Boolean)


8
9
10
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 8

def supports_views?
  true
end

#tables_with_views_included(name = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 12

def tables_with_views_included(name = nil)
  q = <<-SQL
  SELECT table_name, table_type
    FROM information_schema.tables
   WHERE table_schema IN (#{schemas})
     AND table_type IN ('BASE TABLE', 'VIEW')
  SQL

  query(q, name).map { |row| row[0] }
end

#view_select_statement(view, name = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 46

def view_select_statement(view, name = nil)
  q = <<-SQL
  SELECT view_definition
    FROM information_schema.views 
   WHERE table_catalog = (SELECT catalog_name FROM information_schema.information_schema_catalog_name)
     AND table_schema IN (#{schemas})
     AND table_name = '#{view}'
  SQL
  
  select_value(q, name) or raise "No view called #{view} found"
end

#views(name = nil) ⇒ Object

:nodoc:



35
36
37
38
39
40
41
42
43
44
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 35

def views(name = nil) #:nodoc:
  q = <<-SQL
  SELECT table_name, table_type
    FROM information_schema.tables
   WHERE table_schema IN (#{schemas})
     AND table_type = 'VIEW'
  SQL
  
  query(q, name).map { |row| row[0] }
end