Sha256: ebe39bb5af9b8eeeec72e839e974c600b79a9c58303ebbd15fda922d8ce06447

Contents?: true

Size: 839 Bytes

Versions: 5

Compression:

Stored size: 839 Bytes

Contents

module SchemaPlus::Views
  module ActiveRecord
    module ConnectionAdapters
      module PostgresqlAdapter

        def views(name = nil) #:nodoc:
          sql = <<-SQL
            SELECT viewname
              FROM pg_views
            WHERE schemaname = ANY (current_schemas(false))
            AND viewname NOT LIKE 'pg\_%'
          SQL
          sql += " AND schemaname != 'postgis'" if adapter_name == 'PostGIS'
          query(sql, name).map { |row| row[0] }
        end

        def view_definition(view_name, name = nil) #:nodoc:
          result = query(<<-SQL, name)
        SELECT pg_get_viewdef(oid)
          FROM pg_class
         WHERE relkind = 'v'
           AND relname = '#{view_name}'
          SQL
          row = result.first
          row.first.chomp(';') unless row.nil?
        end

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
schema_plus_views-0.2.3 lib/schema_plus/views/active_record/connection_adapters/postgresql_adapter.rb
schema_plus_views-0.2.2 lib/schema_plus/views/active_record/connection_adapters/postgresql_adapter.rb
schema_plus_views-0.2.1 lib/schema_plus/views/active_record/connection_adapters/postgresql_adapter.rb
schema_plus_views-0.2.0 lib/schema_plus/views/active_record/connection_adapters/postgresql_adapter.rb
schema_plus_views-0.1.0 lib/schema_plus/views/active_record/connection_adapters/postgresql_adapter.rb