module Sequel::Postgres::EnumDatabaseMethods

  1. lib/sequel/extensions/pg_enum.rb

Methods enabling Database object integration with enum types.

Public Class methods

extended(db)

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

[show source]
   # File lib/sequel/extensions/pg_enum.rb
78 def self.extended(db)
79   db.instance_exec do
80     @enum_labels = {}
81     parse_enum_labels
82   end
83 end

Public Instance methods

add_enum_value(enum, value, opts=OPTS)

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.

[show source]
   # File lib/sequel/extensions/pg_enum.rb
90 def add_enum_value(enum, value, opts=OPTS)
91   sql = String.new
92   sql << "ALTER TYPE #{quote_schema_table(enum)} ADD VALUE#{' IF NOT EXISTS' if opts[:if_not_exists]} #{literal(value.to_s)}"
93   if v = opts[:before]
94     sql << " BEFORE #{literal(v.to_s)}"
95   elsif v = opts[:after]
96     sql << " AFTER #{literal(v.to_s)}"
97   end
98   _process_enum_change_sql(sql)
99 end
create_enum(enum, values)

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

[show source]
    # File lib/sequel/extensions/pg_enum.rb
102 def create_enum(enum, values)
103   _process_enum_change_sql("CREATE TYPE #{quote_schema_table(enum)} AS ENUM (#{values.map{|v| literal(v.to_s)}.join(', ')})")
104 end
drop_enum(enum, opts=OPTS)

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

[show source]
    # File lib/sequel/extensions/pg_enum.rb
122 def drop_enum(enum, opts=OPTS)
123   _process_enum_change_sql("DROP TYPE#{' IF EXISTS' if opts[:if_exists]} #{quote_schema_table(enum)}#{' CASCADE' if opts[:cascade]}")
124 end
rename_enum(enum, new_name)

Run the SQL to rename the enum type with the given name to the another given name.

[show source]
    # File lib/sequel/extensions/pg_enum.rb
108 def rename_enum(enum, new_name)
109   _process_enum_change_sql("ALTER TYPE #{quote_schema_table(enum)} RENAME TO #{quote_schema_table(new_name)}")
110 end
rename_enum_value(enum, old_name, new_name)

Run the SQL to rename the enum value with the given name to the another given name.

[show source]
    # File lib/sequel/extensions/pg_enum.rb
114 def rename_enum_value(enum, old_name, new_name)
115   _process_enum_change_sql("ALTER TYPE #{quote_schema_table(enum)} RENAME VALUE #{literal(old_name.to_s)} TO #{literal(new_name.to_s)}")
116 end