Sha256: ff3a8a655de50e28d9b8953507a8cb8f1ee5babbe3a176fd13dc2aabbb5d4794
Contents?: true
Size: 823 Bytes
Versions: 5
Compression:
Stored size: 823 Bytes
Contents
module ActiveRecord module PGEnum module PostgreSQLAdapter # Helper method used by the monkeypatch internals. Provides a hash of ENUM types as they exist currently. # # Example: # # { "foo_type" => ["foo", "bar", "baz"] } def enum_types res = exec_query(<<-SQL.strip_heredoc, "SCHEMA").cast_values SELECT t.typname AS enum_name, string_agg(e.enumlabel, ' ' ORDER BY e.enumsortorder) AS enum_value FROM pg_type t JOIN pg_enum e ON t.oid = e.enumtypid JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = 'public' GROUP BY enum_name SQL res.inject({}) do |memo, (name, values)| memo[name] = values.split(" ") memo end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems