Skip to content

Instantly share code, notes, and snippets.

@gonzaga
Created July 26, 2016 14:50
Show Gist options
  • Save gonzaga/e19b5fbafa23a7701226d281a0d35762 to your computer and use it in GitHub Desktop.
Save gonzaga/e19b5fbafa23a7701226d281a0d35762 to your computer and use it in GitHub Desktop.
Useful scripts
ARModel.where(id: []).each do |b|
puts "INSERT INTO models"
puts "(#{b.attributes.keys.join(',')})"
values = b.attributes.values.map do |v|
if v.nil?
'NULL'
else
if v.is_a?(String)
'"' + v.to_s + '"'
elsif v.is_a?(Time)
'"' + v.strftime("%Y-%m-%d %H:%M:%S") + '"'
elsif v.is_a?(Date)
'"' + v.strftime("%Y-%m-%d") + '"'
else
v
end
end
end
puts "VALUES(#{values.join(',')});"
end;nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment