Class: JDBCHelper::SequenceWrapper
- Inherits:
-
ObjectWrapper
- Object
- ObjectWrapper
- JDBCHelper::SequenceWrapper
- Defined in:
- lib/jdbc-helper/wrapper/sequence_wrapper.rb
Overview
conn.sequence(:my_seq).drop!
Instance Attribute Summary
Attributes inherited from ObjectWrapper
Instance Method Summary collapse
-
#create!(value = 1, increment_by = 1) ⇒ JDBCHelper::SequenceWrapper
Creates the sequence.
-
#currval ⇒ Fixnum
Returns the incremented value of the sequence.
-
#drop! ⇒ JDBCHelper::SequenceWrapper
Drops the sequence.
-
#nextval ⇒ Fixnum
Increments the sequence and returns the value.
-
#reset!(value = 1, increment_by = 1) ⇒ JDBCHelper::SequenceWrapper
Recreates the sequence.
Methods inherited from ObjectWrapper
Constructor Details
This class inherits a constructor from JDBCHelper::ObjectWrapper
Instance Method Details
#create!(value = 1, increment_by = 1) ⇒ JDBCHelper::SequenceWrapper
Creates the sequence. Cannot be undone.
51 52 53 54 55 56 |
# File 'lib/jdbc-helper/wrapper/sequence_wrapper.rb', line 51 def create! value = 1, increment_by = 1 create = JDBCHelper::SQL.check( "create sequence #{name} start with #{value} increment by #{increment_by}") @connection.update(create) self end |
#currval ⇒ Fixnum
Returns the incremented value of the sequence
26 27 28 |
# File 'lib/jdbc-helper/wrapper/sequence_wrapper.rb', line 26 def currval @connection.query("select #{name}.currval from dual")[0][0].to_i end |
#drop! ⇒ JDBCHelper::SequenceWrapper
Drops the sequence. Cannot be undone.
42 43 44 45 |
# File 'lib/jdbc-helper/wrapper/sequence_wrapper.rb', line 42 def drop! @connection.update("drop sequence #{name}") self end |
#nextval ⇒ Fixnum
Increments the sequence and returns the value
20 21 22 |
# File 'lib/jdbc-helper/wrapper/sequence_wrapper.rb', line 20 def nextval @connection.query("select #{name}.nextval from dual")[0][0].to_i end |
#reset!(value = 1, increment_by = 1) ⇒ JDBCHelper::SequenceWrapper
Recreates the sequence. Cannot be undone.
34 35 36 37 38 |
# File 'lib/jdbc-helper/wrapper/sequence_wrapper.rb', line 34 def reset! value = 1, increment_by = 1 drop! rescue nil create! value, increment_by self end |