From f272b188fc87f3cc678587476ef9897ea64bf989 Mon Sep 17 00:00:00 2001 From: hirocaster Date: Thu, 27 Aug 2015 16:31:23 +0900 Subject: [PATCH] Export exec sql method --- lib/active_record/sharding/sequencer.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/active_record/sharding/sequencer.rb b/lib/active_record/sharding/sequencer.rb index 050ee0c..57e8fb9 100644 --- a/lib/active_record/sharding/sequencer.rb +++ b/lib/active_record/sharding/sequencer.rb @@ -20,16 +20,16 @@ def use_sequencer(name) end def current_sequence_id - connection = sequencer_repository.fetch(sequencer_name).connection - connection.execute "UPDATE `#{sequencer_config.table_name}` SET id = LAST_INSERT_ID(id)" - res = connection.execute "SELECT LAST_INSERT_ID()" - new_id = res.first.first.to_i - new_id + execute_sql "id" end def next_sequence_id + execute_sql "id +1" + end + + def execute_sql(last_insert_id_args) connection = sequencer_repository.fetch(sequencer_name).connection - connection.execute "UPDATE `#{sequencer_config.table_name}` SET id = LAST_INSERT_ID(id +1)" + connection.execute "UPDATE `#{sequencer_config.table_name}` SET id = LAST_INSERT_ID(#{last_insert_id_args})" res = connection.execute "SELECT LAST_INSERT_ID()" new_id = res.first.first.to_i new_id