Skip to content

Instantly share code, notes, and snippets.

@rintaun
Last active December 15, 2015 02:19
Show Gist options
  • Save rintaun/5186914 to your computer and use it in GitHub Desktop.
Save rintaun/5186914 to your computer and use it in GitHub Desktop.
DB.transaction do # BEGIN;
User.new do |user|
user.name = 'rintaun'
user.password = 'somebullshit' # I use this for all my passwords. Oh no! Now you know! D:
user.save # INSERT;
end
User.new do |user|
user.name = 'rintaun' # this is a unique column, so this whole thing will obviously fail!
user.password = 'areallysecurepassword'
user.save # INSERT; -- Error
end
end # ROLLBACK;
# SELECT COUNT(*) FROM users; -- 0
DB.transaction do # BEGIN;
User.new do |user|
user.name = 'rintaun'
user.password = 'somebullshit' # I use this for all my passwords. Oh no! Now you know! D:
user.save # INSERT; COMMIT; -- LOLOL
end
User.new do |user|
user.name = 'rintaun' # this is a unique column, so this whole thing will obviously fail!
user.password = 'areallysecurepassword'
user.save # INSERT; -- Error
end
end # ROLLBACK; -- No transaction
# SELECT COUNT(*) FROM users; -- 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment