Sha256: 8d247a44a37bedf0b28b2b783b2abb0553fb1216b32718cc3483375f204b964d

Contents?: true

Size: 858 Bytes

Versions: 3

Compression:

Stored size: 858 Bytes

Contents

# Features of Scenic not available in v1.7.0
class Scenic::Adapters::Postgres
  # True if supplied relation name is populated. Useful for checking the
  # state of materialized views which may error if created `WITH NO DATA`
  # and used before they are refreshed. True for all other relation types.
  #
  # @param name The name of the relation
  #
  # @raise [MaterializedViewsNotSupportedError] if the version of Postgres
  #   in use does not support materialized views.
  #
  # @return [boolean]
  def populated?(name)
    raise_unless_materialized_views_supported

    schemaless_name = name.split(".").last

    sql = "SELECT relispopulated FROM pg_class WHERE relname = '#{schemaless_name}'"
    relations = execute(sql)

    if relations.count.positive?
      relations.first["relispopulated"].in?(["t", true])
    else
      false
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
searchcraft-0.5.2 lib/ext/scenic/adapters/postgres.rb
searchcraft-0.5.1 lib/ext/scenic/adapters/postgres.rb
searchcraft-0.5.0 lib/ext/scenic/adapters/postgres.rb