Class: Baza::Driver::Mysql::Index
- Defined in:
- lib/baza/drivers/mysql/index.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
Instance Method Summary collapse
-
#__object_unique_id__ ⇒ Object
Used to validate in Wref::Map.
- #data ⇒ Object
- #drop ⇒ Object
-
#initialize(args) ⇒ Index
constructor
A new instance of Index.
- #name ⇒ Object
-
#primary? ⇒ Boolean
Returns true if the index is a primary-index.
- #rename(newname) ⇒ Object
- #table ⇒ Object
-
#unique? ⇒ Boolean
Returns true if the index is a unique-index.
Methods inherited from Index
Constructor Details
#initialize(args) ⇒ Index
Returns a new instance of Index.
4 5 6 7 |
# File 'lib/baza/drivers/mysql/index.rb', line 4 def initialize(args) @args = args @columns = [] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
2 3 4 |
# File 'lib/baza/drivers/mysql/index.rb', line 2 def args @args end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
2 3 4 |
# File 'lib/baza/drivers/mysql/index.rb', line 2 def columns @columns end |
Instance Method Details
#__object_unique_id__ ⇒ Object
Used to validate in Wref::Map.
10 11 12 |
# File 'lib/baza/drivers/mysql/index.rb', line 10 def __object_unique_id__ return @args[:data][:Key_name] end |
#data ⇒ Object
47 48 49 50 51 52 |
# File 'lib/baza/drivers/mysql/index.rb', line 47 def data return { name: name, columns: @columns } end |
#drop ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/baza/drivers/mysql/index.rb', line 22 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..index("check that column/key exists") != nil #ignore. else raise e end end end |
#name ⇒ Object
14 15 16 |
# File 'lib/baza/drivers/mysql/index.rb', line 14 def name return @args[:data][:Key_name] end |
#primary? ⇒ Boolean
Returns true if the index is a primary-index.
64 65 66 67 |
# File 'lib/baza/drivers/mysql/index.rb', line 64 def primary? return true if @args[:data][:Key_name] == "PRIMARY" return false end |
#rename(newname) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/baza/drivers/mysql/index.rb', line 37 def rename newname newname = newname.to_sym create_args = data create_args[:name] = newname drop table.create_indexes([create_args]) @args[:data][:Key_name] = newname end |
#table ⇒ Object
18 19 20 |
# File 'lib/baza/drivers/mysql/index.rb', line 18 def table return @args[:db].tables[@args[:table_name]] end |
#unique? ⇒ Boolean
Returns true if the index is a unique-index.
55 56 57 58 59 60 61 |
# File 'lib/baza/drivers/mysql/index.rb', line 55 def unique? if @args[:data][:Index_type] == "UNIQUE" || @args[:data][:Non_unique].to_i == 0 return true else return false end end |