Module: Spectacles::SchemaStatements::PostgreSQLAdapter

Includes:
AbstractAdapter
Defined in:
lib/spectacles/schema_statements/postgresql_adapter.rb

Instance Method Summary collapse

Methods included from AbstractAdapter

#create_view, #create_view_statement, #drop_view, #drop_view_statement, #view_exists?

Instance Method Details

#view_build_query(view, name = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/spectacles/schema_statements/postgresql_adapter.rb', line 19

def view_build_query(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:



8
9
10
11
12
13
14
15
16
17
# File 'lib/spectacles/schema_statements/postgresql_adapter.rb', line 8

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
  
  execute(q, name).map { |row| row['table_name'] }
end