Class: Baza::Driver::Sqlite3::Index

Inherits:
Index
  • Object
show all
Defined in:
lib/baza/drivers/sqlite3/index.rb

Direct Known Subclasses

Baza::Driver::Sqlite3Java::Index

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Index

#inspect, #to_s

Constructor Details

#initialize(args) ⇒ Index

Returns a new instance of Index.



4
5
6
7
8
# File 'lib/baza/drivers/sqlite3/index.rb', line 4

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



2
3
4
# File 'lib/baza/drivers/sqlite3/index.rb', line 2

def args
  @args
end

#columnsObject (readonly)

Returns the value of attribute columns.



2
3
4
# File 'lib/baza/drivers/sqlite3/index.rb', line 2

def columns
  @columns
end

Instance Method Details

#column_namesObject



45
46
47
# File 'lib/baza/drivers/sqlite3/index.rb', line 45

def column_names
  @columns
end

#dataObject



37
38
39
40
41
42
43
# File 'lib/baza/drivers/sqlite3/index.rb', line 37

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

#dropObject



22
23
24
# File 'lib/baza/drivers/sqlite3/index.rb', line 22

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

#nameObject



10
11
12
# File 'lib/baza/drivers/sqlite3/index.rb', line 10

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

#rename(newname) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/baza/drivers/sqlite3/index.rb', line 26

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

#tableObject



18
19
20
# File 'lib/baza/drivers/sqlite3/index.rb', line 18

def table
  return @db.tables[table_name]
end

#table_nameObject



14
15
16
# File 'lib/baza/drivers/sqlite3/index.rb', line 14

def table_name
  return @args[:table_name]
end

#unique?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/baza/drivers/sqlite3/index.rb', line 49

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