Sha256: 7ec76b3e88a7da1b9af0bcfafdc0d7b6e0effb5a01601b5aaf8bdb9a3a3c983a

Contents?: true

Size: 777 Bytes

Versions: 4

Compression:

Stored size: 777 Bytes

Contents

class Baza::Driver::Sqlite3::Index < Baza::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,
      unique: unique?,
      columns: @columns
    }
  end

  def column_names
    @columns
  end

  def unique?
    @args[:data][:unique].to_i == 1
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
baza-0.0.19 lib/baza/drivers/sqlite3/index.rb
baza-0.0.18 lib/baza/drivers/sqlite3/index.rb
baza-0.0.17 include/drivers/sqlite3/sqlite3_index.rb
baza-0.0.16 include/drivers/sqlite3/sqlite3_index.rb