Class: KnjDB_mysql::Indexes::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Index

Returns a new instance of Index.



10
11
12
13
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 10

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

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



8
9
10
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 8

def columns
  @columns
end

Instance Method Details

#__object_unique_id__Object

Used to validate in Knj::Wrap_map.



16
17
18
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 16

def __object_unique_id__
  return @args[:data][:Key_name]
end

#dataObject



43
44
45
46
47
48
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 43

def data
  return {
    "name" => name,
    "columns" => @columns
  }
end

#dropObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 28

def drop
  sql = "DROP INDEX `#{self.name}` ON `#{self.table.name}`"
  
  begin
    @args[:db].query(sql)
  rescue => e
    #The index has already been dropped - ignore.
    if e.message.index("check that column/key exists") != nil
      #ignore.
    else
      raise e
    end
  end
end

#nameObject



20
21
22
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 20

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

#tableObject



24
25
26
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 24

def table
  return @args[:db].tables[@args[:table_name]]
end

#to_sObject

Inspect crashes if this is not present? - knj.



60
61
62
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 60

def to_s
  return "#<#{self.class.name}>"
end

#unique?Boolean

Returns true if the index is a unique-index.

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb', line 51

def unique?
  if @args[:data][:Index_type] == "UNIQUE"
    return true
  else
    return false
  end
end