Last active
January 1, 2019 12:52
-
-
Save satooshi/bfe4c01ac48a5f2b80db7cf4fba42a03 to your computer and use it in GitHub Desktop.
Revisions
-
satooshi revised this gist
Jan 1, 2019 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,11 +4,11 @@ DB.open "postgres://postgres:postgres@localhost:5432/blog_development" do |db| db.transaction do |tx| conn = tx.connection pp conn.scalar "select count(*) from articles" # => 5 pp conn.exec "insert into articles (title, url, markdown, created_at, updated_at) values ('title', 'url', 'markdown', now(), now())" pp db.scalar "select count(*) from articles" # => 5 (because this established another connection) pp conn.scalar "select count(*) from articles" # => 6 tx.rollback pp conn.scalar "select count(*) from articles" # => 5 (rollbacked properly) end end -
satooshi created this gist
Jan 1, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ require "pg" DB.open "postgres://postgres:postgres@localhost:5432/blog_development" do |db| db.transaction do |tx| conn = tx.connection pp conn.scalar "select count(*) from articles" pp conn.exec "insert into articles (title, url, markdown, created_at, updated_at) values ('title', 'url', 'markdown', now(), now())" pp db.scalar "select count(*) from articles" pp conn.scalar "select count(*) from articles" tx.rollback pp conn.scalar "select count(*) from articles" end end