Module Sequel::Postgres::EnumDatabaseMethods
In: lib/sequel/extensions/pg_enum.rb

Methods enabling Database object integration with enum types.

Methods

Public Class methods

Parse the available enum values when loading this extension into your database.

[Source]

    # File lib/sequel/extensions/pg_enum.rb, line 61
61:       def self.extended(db)
62:         db.send(:parse_enum_labels)
63:       end

Public Instance methods

Run the SQL to add the given value to the existing enum type. Options:

:after :Add the new value after this existing value.
:before :Add the new value before this existing value.
:if_not_exists :Do not raise an error if the value already exists in the enum.

[Source]

    # File lib/sequel/extensions/pg_enum.rb, line 70
70:       def add_enum_value(enum, value, opts=OPTS)
71:         sql = "ALTER TYPE #{quote_schema_table(enum)} ADD VALUE#{' IF NOT EXISTS' if opts[:if_not_exists]} #{literal(value.to_s)}"
72:         if v = opts[:before]
73:           sql << " BEFORE #{literal(v.to_s)}"
74:         elsif v = opts[:after]
75:           sql << " AFTER #{literal(v.to_s)}"
76:         end
77:         run sql
78:         parse_enum_labels
79:         nil
80:       end

Run the SQL to create an enum type with the given name and values.

[Source]

    # File lib/sequel/extensions/pg_enum.rb, line 83
83:       def create_enum(enum, values)
84:         sql = "CREATE TYPE #{quote_schema_table(enum)} AS ENUM (#{values.map{|v| literal(v.to_s)}.join(', ')})"
85:         run sql
86:         parse_enum_labels
87:         nil
88:       end

Run the SQL to drop the enum type with the given name. Options:

:if_exists :Do not raise an error if the enum type does not exist
:cascade :Also drop other objects that depend on the enum type

[Source]

    # File lib/sequel/extensions/pg_enum.rb, line 94
94:       def drop_enum(enum, opts=OPTS)
95:         sql = "DROP TYPE#{' IF EXISTS' if opts[:if_exists]} #{quote_schema_table(enum)}#{' CASCADE' if opts[:cascade]}"
96:         run sql
97:         parse_enum_labels
98:         nil
99:       end

[Validate]