Class/Module Index [+]

Quicksearch

Sequel::Postgres::EnumDatabaseMethods

Methods enabling Database object integration with enum types.

Public Class Methods

extended(db) click to toggle source

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

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

Public Instance Methods

add_enum_value(enum, value, opts=OPTS) click to toggle source

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.

# File lib/sequel/extensions/pg_enum.rb, line 60
def add_enum_value(enum, value, opts=OPTS)
  sql = "ALTER TYPE #{quote_schema_table(enum)} ADD VALUE#{' IF NOT EXISTS' if opts[:if_not_exists]} #{literal(value.to_s)}"
  if v = opts[:before]
    sql << " BEFORE #{literal(v.to_s)}"
  elsif v = opts[:after]
    sql << " AFTER #{literal(v.to_s)}"
  end
  run sql
  parse_enum_labels
  nil
end
create_enum(enum, values) click to toggle source

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

# File lib/sequel/extensions/pg_enum.rb, line 73
def create_enum(enum, values)
  sql = "CREATE TYPE #{quote_schema_table(enum)} AS ENUM (#{values.map{|v| literal(v.to_s)}.join(', ')})"
  run sql
  parse_enum_labels
  nil
end
drop_enum(enum, opts=OPTS) click to toggle source

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.