Created
July 26, 2016 14:50
-
-
Save gonzaga/e19b5fbafa23a7701226d281a0d35762 to your computer and use it in GitHub Desktop.
Useful scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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