Class: ActiveRecord::Turntable::Sequencer::Mysql
Instance Method Summary
collapse
class_for, #sequence_name, sequence_name
Constructor Details
#initialize(options = {}) ⇒ Mysql
Returns a new instance of Mysql.
9
10
11
12
|
# File 'lib/active_record/turntable/sequencer/mysql.rb', line 9
def initialize(options = {})
@options = options
@shard = SeqShard.new(@options[:connection].to_s)
end
|
Instance Method Details
#connection ⇒ Object
14
15
16
|
# File 'lib/active_record/turntable/sequencer/mysql.rb', line 14
def connection
@shard.connection
end
|
#current_sequence_value(sequence_name) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/active_record/turntable/sequencer/mysql.rb', line 31
def current_sequence_value(sequence_name)
conn = connection
conn.execute "UPDATE #{conn.quote_table_name(sequence_name)} SET id=LAST_INSERT_ID(id)"
res = conn.execute("SELECT LAST_INSERT_ID()")
current_id = res.first.first.to_i
current_id
end
|
#next_sequence_value(sequence_name) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/active_record/turntable/sequencer/mysql.rb', line 22
def next_sequence_value(sequence_name)
conn = connection
conn.execute "UPDATE #{conn.quote_table_name(sequence_name)} SET id=LAST_INSERT_ID(id+1)"
res = conn.execute("SELECT LAST_INSERT_ID()")
new_id = res.first.first.to_i
raise SequenceNotFoundError if new_id.zero?
new_id
end
|
#release! ⇒ Object
18
19
20
|
# File 'lib/active_record/turntable/sequencer/mysql.rb', line 18
def release!
@shard.connection_pool.clear_all_connections!
end
|