Sha256: 7da027f14ec566831ebce31e8c306594822549a32649f99e0f73b8ede8dfd176

Contents?: true

Size: 1.95 KB

Versions: 20

Compression:

Stored size: 1.95 KB

Contents

module RailsSqlViews
  module ConnectionAdapters
    module PostgreSQLAdapter
      def self.included(base)
<<<<<<< HEAD
        base.alias_method_chain :tables, :views_included unless method_defined?(:tables_with_views_included)
=======
        base.alias_method_chain :tables, :views_included
>>>>>>> Make tests pass again for PostgreSQL and MySQL adapters.
      end
      # Returns true as this adapter supports views.
      def supports_views?
        true
      end
      
      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
      
      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
      alias nonview_tables base_tables
      
      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

      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

      private
        
      def schemas
        schema_search_path.split(/,/).map { |p| quote(p) }.join(',')
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 7 rubygems

Version Path
mereghost-rails_sql_views-0.8.6 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
robdimarco_rails_sql_views-0.9.0 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
qubole_rails_sql_views-0.10.3 lib/qubole_rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
qubole_rails_sql_views-0.10.1 lib/qubole_rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
qubole_rails_sql_views-0.10.0 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
mereghost-rails_sql_views-0.8.5 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
mereghost-rails_sql_views-0.8.3 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
mereghost-rails_sql_views-0.8.2 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
mereghost-rails_sql_views-0.8.1 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
lunks-rails_sql_views-0.9.2 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
ctreatma-rails_sql_views-0.9.1 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
ctreatma-rails_sql_views-0.9.0 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
molo-0.7.6 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
molo-0.7.5 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
molo-0.7.4 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
molo-0.7.3 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
molo-0.7.2 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
molo-0.7.1 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
molo-0.7.0 vendor/rails_sql_views/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig
rails_sql_views-0.8.0 lib/rails_sql_views/connection_adapters/postgresql_adapter.rb.orig