Module: Imparcial::Driver::AbstractExpression::Index

Included in:
Imparcial::Driver::AbstractExpression
Defined in:
lib/imparcial/driver/abstract/expression/index.rb

Instance Method Summary collapse

Instance Method Details

#create_index(options = {}) ⇒ Object

Description

Create an index.

Usage

abstract_adapter.create_index :index_name => ‘idx’, :table_name = ‘person’ ,:column_name => :id

Options

  • :index_name

  • :table_name

  • :column_name

  • :index_type

Returning

nothing



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/imparcial/driver/abstract/expression/index.rb', line 41

def create_index ( options = {} )
  
  check_options expected_options_for_creating_index, options
   
  sql = sql_for_creating_index( options )
    
  logger.warn sql if @index_logging
  
  query sql            
    
rescue adapter_specific_exception => ex
  
  raise IndexCreateError.new(ex.message)

end

#drop_all_indexes(options = {}) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/imparcial/driver/abstract/expression/index.rb', line 97

def drop_all_indexes ( options = {} )

  check_options expected_options_for_dropping_all_indexes, options

  for index in get_indexes(:table_name => options[:table_name])

    drop_index :table_name => index[:table], :index_name => index[:name]          
  
  end
  
end

#drop_index(options = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/imparcial/driver/abstract/expression/index.rb', line 73

def drop_index ( options = {} )
  
  check_options expected_options_for_dropping_index, options
  
  sql = sql_for_dropping_index( options )
  
  logger.warn sql if @index_logging
  
  query sql
  
rescue adapter_specific_exception => ex

  raise IndexDropError.new(ex.message)
  
end

#expected_options_for_dropping_all_indexesObject



89
90
91
92
93
# File 'lib/imparcial/driver/abstract/expression/index.rb', line 89

def expected_options_for_dropping_all_indexes
  
  {:table_name => :required}
  
end

#get_indexes(options = {}) ⇒ Object

Description

Get metadata about all indexes.

Usage

abstract_adapter.retrieve_indexes

Options

No options

Returning

an array with hashes.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/imparcial/driver/abstract/expression/index.rb', line 137

def get_indexes ( options = {} )

  check_options expected_options_for_getting_indexes, options

  sql = sql_for_getting_indexes options
  
  logger.warn sql if @index_logging
  
  query sql
  
  indexes = []
  
  result.fetch do |table, column, index|
    
    indexes << {:table => table.value,:column => column.value,:name => index.value}
    
  end
  
  indexes
  
rescue adapter_specific_exception => ex

  raise IndexListError.new(ex.message)             
  
end

#index_exists?(options = {}) ⇒ Boolean

Description

Verify if a given index exists.

Usage

abstract_adapter.retrieve_indexes

Options

No options

Returning

true or false.

Returns:

  • (Boolean)


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/imparcial/driver/abstract/expression/index.rb', line 185

def index_exists? ( options = {} )
  
  check_options expected_options_for_verifying_index_existance, options

  sql = sql_for_index_exists?( options )
  
  logger.warn sql if @index_logging
  
  query sql
  
  result.rows > 0
  
rescue adapter_specific_exception => ex

  raise IndexDropError.new(ex.message)             
  
end