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
-
#create_sequence(options = {}) ⇒ Object
Description Create a sequence.
-
#create_sequence_if_necessary(options = {}) ⇒ Object
Description Create a sequence without raising any exception.
-
#drop_all_sequences ⇒ Object
Description Drop all sequences.
-
#drop_sequence(options = {}) ⇒ Object
Description Drop a sequence.
-
#drop_sequence_if_necessary(options = {}) ⇒ Object
Description Drop a sequence without raising any exception.
-
#get_sequences ⇒ Object
Retrieve all sequences.
-
#sequence_exists?(options = {}) ⇒ Boolean
Ask for a sequence returning true or false.
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 ( = {} ) , parse_sequence sql = sql_for_creating_sequence( ) logger.warn sql if @sequence_logging query sql rescue adapter_specific_exception => ex raise SequenceCreateError.new(ex.) 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 ( = {} ) create_sequence rescue SequenceCreateError => ex; end |
#drop_all_sequences ⇒ Object
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.) 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 ( = {} ) , sql = sql_for_dropping_sequence( ) logger.warn sql if @sequence_logging query sql rescue adapter_specific_exception => ex raise SequenceDropError.new(ex.) 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 ( = {} ) drop_sequence rescue SequenceDropError; end |
#get_sequences ⇒ Object
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.) end |
#sequence_exists?(options = {}) ⇒ Boolean
Ask for a sequence returning true or false
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? ( = {} ) , sql = sql_for_sequence_exists?( ) logger.warn sql if @sequence_logging query sql result.rows > 0 rescue adapter_specific_exception => ex raise SequenceListError.new(ex.) end |