Sha256: 796b04f7b37c2d3bd20435932e078508e411e83632027cbcd03eb2d4e4f77ae7
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
# Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias # Schmidt module Lhm module SqlHelper extend self def annotation "/* large hadron migration */" end def idx_name(table_name, cols) column_names = column_definition(cols).map(&:first) "index_#{ table_name }_on_#{ column_names.join("_and_") }" end def idx_spec(cols) column_definition(cols).map do |name, length| "`#{ name }`#{ length }" end.join(', ') end def table?(table_name) connection.table_exists?(table_name) end def sql(statements) [statements].flatten.each do |statement| connection.execute(tagged(statement)) end rescue ActiveRecord::StatementInvalid, Mysql::Error => e error e.message end def update(statements) [statements].flatten.inject(0) do |memo, statement| memo += connection.update(tagged(statement)) end rescue ActiveRecord::StatementInvalid, Mysql::Error => e error e.message end private def tagged(statement) "#{ statement } #{ SqlHelper.annotation }" end def column_definition(cols) Array(cols).map do |column| column.to_s.match(/`?([^\(]+)`?(\([^\)]+\))?/).captures end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
lhm-1.0.3 | lib/lhm/sql_helper.rb |
lhm-1.0.2 | lib/lhm/sql_helper.rb |
lhm-1.0.0.rc7 | lib/lhm/sql_helper.rb |