class Baza::Driver::Pg::Index

Attributes

name[R]

Public Class Methods

new(args) click to toggle source
# File lib/baza/driver/pg/index.rb, line 4
def initialize(args)
  @db = args.fetch(:db)
  @data = args.fetch(:data)
  @name = @data.fetch(:indexname)
end

Public Instance Methods

columns() click to toggle source
# File lib/baza/driver/pg/index.rb, line 32
def columns
  @data.fetch(:indexdef).match(/\((.+)\)\Z/)[1].split(/\s*,\s/)
end
primary?() click to toggle source
# File lib/baza/driver/pg/index.rb, line 22
def primary?
  name == "#{table_name}_pkey"
end
rename(new_name) click to toggle source
# File lib/baza/driver/pg/index.rb, line 26
def rename(new_name)
  @db.query("ALTER INDEX #{@db.quote_index(name)} RENAME TO #{@db.quote_index(new_name)}")
  @name = new_name.to_s
  self
end
table() click to toggle source
# File lib/baza/driver/pg/index.rb, line 10
def table
  @db.tables[table_name]
end
table_name() click to toggle source
# File lib/baza/driver/pg/index.rb, line 14
def table_name
  @data.fetch(:tablename)
end
unique?() click to toggle source
# File lib/baza/driver/pg/index.rb, line 18
def unique?
  @data.fetch(:indexdef).include?(" UNIQUE ")
end