Module: Imparcial::Driver::AbstractExpression::Sequence

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

Overview

It’s important to be aware that some databases don’t support sequences. Databases like Mysql, need to override those methods.

Instance Method Summary collapse

Instance Method Details

#create_sequence(options = {}) ⇒ Object

Description

Create a sequence.

Usage

abstract_adapter.create_sequence :sequence_name => ‘seq_id’, :increment_by => 2

Options

  • :sequence_name

  • :start_with

  • :min_value

  • :max_value

  • :increment_by

  • :cache

  • :cycle

Returning

nothing



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/imparcial/driver/abstract/expression/sequence.rb', line 61

def create_sequence ( options = {} )          
      
  check_options expected_options_for_creating_sequence, options
  
  parse_sequence options            

  sql = sql_for_creating_sequence( options )
  
  logger.warn sql if @sequence_logging
  
  query sql
    
rescue adapter_specific_exception => ex
  
  raise SequenceCreateError.new(ex.message)           
 
end

#create_sequence_if_necessary(options = {}) ⇒ Object

Description

Create a sequence without raising any exception.

Usage

abstract_adapter.create_sequence_if_necessary :sequence_name => ‘seq_id’

Options

  • :sequence_name

  • :start_with

  • :min_value

  • :max_value

  • :increment_by

  • :cache

  • :cycle

Returning

nothing



97
98
99
100
101
# File 'lib/imparcial/driver/abstract/expression/sequence.rb', line 97

def create_sequence_if_necessary ( options = {} )
  
  create_sequence options

rescue SequenceCreateError => ex; end

#drop_all_sequencesObject

Description

Drop all sequences.

Usage

abstract_adapter.drop_all_sequences

Options

no options

Returning

nothing



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/imparcial/driver/abstract/expression/sequence.rb', line 177

def drop_all_sequences
            
  for sequence in get_sequences
  
    sql = sql_for_dropping_sequence( :sequence_name => sequence )
    
    logger.warn sql if @sequence_logging
    
    query sql
  
  end
            
rescue adapter_specific_exception => ex

  raise SequenceError.new(ex.message)
  
end

#drop_sequence(options = {}) ⇒ Object

Description

Drop a sequence.

Usage

abstract_adapter.drop_sequence :sequence_name => ‘seq_id’

Options

  • :sequence_name

Returning

nothing



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/imparcial/driver/abstract/expression/sequence.rb', line 131

def drop_sequence ( options = {} )

  check_options expected_options_for_dropping_sequence, options

  sql = sql_for_dropping_sequence( options )
  
  logger.warn sql if @sequence_logging
  
  query sql
                
rescue adapter_specific_exception => ex
  
  raise SequenceDropError.new(ex.message)
          
end

#drop_sequence_if_necessary(options = {}) ⇒ Object

Description

Drop a sequence without raising any exception.

Usage

abstract_adapter.drop_sequence :sequence_name => ‘seq_id’

Options

  • :sequence_name

Returning

nothing



159
160
161
162
163
# File 'lib/imparcial/driver/abstract/expression/sequence.rb', line 159

def drop_sequence_if_necessary ( options = {} )           
      
  drop_sequence options
  
rescue SequenceDropError; end

#get_sequencesObject

Retrieve all sequences. Similar to retrive_tables.



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/imparcial/driver/abstract/expression/sequence.rb', line 233

def get_sequences
      
  sql = sql_for_getting_sequences
    
  logger.warn sql if @sequence_logging
    
  query sql
  
  sequences = []

  result.fetch do |name|
 
    sequences << name.value

  end

  sequences
  
rescue adapter_specific_exception => ex
  
  raise SequenceListError.new(ex.message)

end

#sequence_exists?(options = {}) ⇒ Boolean

Ask for a sequence returning true or false

Returns:

  • (Boolean)


213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/imparcial/driver/abstract/expression/sequence.rb', line 213

def sequence_exists? ( options = {} )    
      
  check_options expected_options_for_verifying_sequence_existance, options      
      
  sql = sql_for_sequence_exists?( options )
    
  logger.warn sql if @sequence_logging
    
  query sql            
  
  result.rows > 0
  
rescue adapter_specific_exception => ex
  
  raise SequenceListError.new(ex.message)  
      
end