Skip to content

Commit

Permalink
Export exec sql method
Browse files Browse the repository at this point in the history
  • Loading branch information
hirocaster committed Aug 27, 2015
1 parent c268a01 commit f272b18
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/active_record/sharding/sequencer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f272b18

Please sign in to comment.