Sha256: 5872d9b8af5e327c0559e697c127f0f95c71efdddd17252332d5fb5c1bfa4741

Contents?: true

Size: 875 Bytes

Versions: 1

Compression:

Stored size: 875 Bytes

Contents

class Baza::Driver::Sqlite3::Indexes
  def initialize(args)
    @args = args
  end
end

class Baza::Driver::Sqlite3::Indexes::Index
  attr_reader :args, :columns

  def initialize(args)
    @args = args
    @columns = []
    @db = args[:db]
  end

  def name
    return @args[:data][:name]
  end

  def table_name
    return @args[:table_name]
  end

  def table
    return @db.tables[table_name]
  end

  def drop
    @db.query("DROP INDEX `#{name}`")
  end

  def rename newname
    newname = newname.to_sym

    create_args = data
    create_args[:name] = newname

    drop
    table.create_indexes([create_args])
    @args[:data][:name] = newname
  end

  def data
    return {
      name: name,
      columns: @columns
    }
  end

  def column_names
    @columns
  end

  def to_s
    "#<Baza::Driver::Sqlite3::Index name: \"#{name}\", columns: #{@columns}>"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
baza-0.0.14 include/drivers/sqlite3/sqlite3_indexes.rb