Skip to content

Instantly share code, notes, and snippets.

@satooshi
Last active January 1, 2019 12:52
Show Gist options
  • Select an option

  • Save satooshi/bfe4c01ac48a5f2b80db7cf4fba42a03 to your computer and use it in GitHub Desktop.

Select an option

Save satooshi/bfe4c01ac48a5f2b80db7cf4fba42a03 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment