Sha256: a219ee3ea5274d4beb61efaf0650e82d6e8765968f0dd2739ffa91263b7ef19a

Contents?: true

Size: 657 Bytes

Versions: 3

Compression:

Stored size: 657 Bytes

Contents

class Baza::Driver::Pg::Index < Baza::Index
  attr_reader :name

  def initialize(args)
    @db = args.fetch(:db)
    @data = args.fetch(:data)
    @name = @data.fetch(:indexname)
  end

  def table
    @db.tables[table_name]
  end

  def table_name
    @data.fetch(:tablename)
  end

  def unique?
    @data.fetch(:indexdef).include?(" UNIQUE ")
  end

  def primary?
    name == "#{table_name}_pkey"
  end

  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

  def columns
    @data.fetch(:indexdef).match(/\((.+)\)\Z/)[1].split(/\s*,\s/)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
baza-0.0.38 lib/baza/driver/pg/index.rb
baza-0.0.37 lib/baza/driver/pg/index.rb
baza-0.0.36 lib/baza/driver/pg/index.rb