Module: RailsSqlViews::ConnectionAdapters::PostgreSQLAdapter
- Defined in:
- lib/rails_sql_views/connection_adapters/postgresql_adapter.rb
Instance Method Summary collapse
- #base_tables(name = nil) ⇒ Object (also: #nonview_tables)
-
#supports_views? ⇒ Boolean
Returns true as this adapter supports views.
- #tables_with_views_included(name = nil) ⇒ Object
- #view_select_statement(view, name = nil) ⇒ Object
-
#views(name = nil) ⇒ Object
:nodoc:.
Instance Method Details
#base_tables(name = nil) ⇒ Object Also known as: nonview_tables
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 20 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.
5 6 7 |
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 5 def supports_views? true end |
#tables_with_views_included(name = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 9 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
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 43 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:
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails_sql_views/connection_adapters/postgresql_adapter.rb', line 32 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 |