Sha256: c9d150f8a314631ac13bdb7d7735abe6df41c72b0f47c63d62f3909d2aa3ece6

Contents?: true

Size: 1.04 KB

Versions: 16

Compression:

Stored size: 1.04 KB

Contents

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

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

  def name
    @data.fetch(:name)
  end

  def table_name
    @args.fetch(:table_name)
  end

  def table
    @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])
    @data[:name] = newname
  end

  def data
    {
      name: name,
      unique: unique?,
      columns: @columns
    }
  end

  def column_names
    @columns
  end

  def unique?
    @data.fetch(:unique).to_i == 1
  end

  def reload
    data = nil
    @db.query("PRAGMA index_list(`#{@db.escape_table(name)}`)") do |d_indexes|
      next unless d_indexes.fetch(:name) == name
      data = d_indexes
      break
    end

    raise Baza::Errors::IndexNotFound unless data
    @data = data
    self
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
baza-0.0.35 lib/baza/driver/sqlite3/index.rb
baza-0.0.34 lib/baza/driver/sqlite3/index.rb
baza-0.0.33 lib/baza/driver/sqlite3/index.rb
baza-0.0.32 lib/baza/driver/sqlite3/index.rb
baza-0.0.31 lib/baza/driver/sqlite3/index.rb
baza-0.0.30 lib/baza/driver/sqlite3/index.rb
baza-0.0.29 lib/baza/driver/sqlite3/index.rb
baza-0.0.28 lib/baza/driver/sqlite3/index.rb
baza-0.0.27 lib/baza/driver/sqlite3/index.rb
baza-0.0.26 lib/baza/driver/sqlite3/index.rb
baza-0.0.25 lib/baza/driver/sqlite3/index.rb
baza-0.0.24 lib/baza/driver/sqlite3/index.rb
baza-0.0.23 lib/baza/driver/sqlite3/index.rb
baza-0.0.22 lib/baza/driver/sqlite3/index.rb
baza-0.0.21 lib/baza/driver/sqlite3/index.rb
baza-0.0.20 lib/baza/drivers/sqlite3/index.rb