Class: Baza::Driver::Sqlite3::Index
- Inherits:
-
Index
- Object
- Index
- Baza::Driver::Sqlite3::Index
show all
- Defined in:
- lib/baza/driver/sqlite3/index.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Index
#inspect, #to_param, #to_s
#model_name, #to_model
Constructor Details
#initialize(args) ⇒ Index
Returns a new instance of Index.
4
5
6
7
8
9
|
# File 'lib/baza/driver/sqlite3/index.rb', line 4
def initialize(args)
@args = args
@data = args.delete(:data)
@columns = []
@db = args[:db]
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
2
3
4
|
# File 'lib/baza/driver/sqlite3/index.rb', line 2
def args
@args
end
|
#columns ⇒ Object
Returns the value of attribute columns.
2
3
4
|
# File 'lib/baza/driver/sqlite3/index.rb', line 2
def columns
@columns
end
|
Instance Method Details
#column_names ⇒ Object
46
47
48
|
# File 'lib/baza/driver/sqlite3/index.rb', line 46
def column_names
@columns
end
|
#data ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/baza/driver/sqlite3/index.rb', line 38
def data
{
name: name,
unique: unique?,
columns: @columns
}
end
|
#drop ⇒ Object
23
24
25
|
# File 'lib/baza/driver/sqlite3/index.rb', line 23
def drop
@db.query("DROP INDEX `#{name}`")
end
|
#name ⇒ Object
11
12
13
|
# File 'lib/baza/driver/sqlite3/index.rb', line 11
def name
@data.fetch(:name)
end
|
#reload ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/baza/driver/sqlite3/index.rb', line 54
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
|
#rename(newname) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/baza/driver/sqlite3/index.rb', line 27
def rename(newname)
newname = newname.to_sym
create_args = data
create_args[:name] = newname
drop
table.create_indexes([create_args])
@data[:name] = newname
end
|
#table ⇒ Object
19
20
21
|
# File 'lib/baza/driver/sqlite3/index.rb', line 19
def table
@db.tables[table_name]
end
|
#table_name ⇒ Object
15
16
17
|
# File 'lib/baza/driver/sqlite3/index.rb', line 15
def table_name
@args.fetch(:table_name)
end
|
#unique? ⇒ Boolean
50
51
52
|
# File 'lib/baza/driver/sqlite3/index.rb', line 50
def unique?
@data.fetch(:unique).to_i == 1
end
|