a guest Sep 23rd, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require "pg"
  3. begin
  4.   con = PG.connect(dbname: 'postgres')
  5.   con.exec('CREATE DATABASE app_db')
  6.   con_app = PG.connect(dbname: 'app_db')
  7.   con_app.exec('DROP TABLE IF EXISTS Names')
  8.   con_app.exec('CREATE TABLE Names(Id INTEGER, Name VARCHAR(20))')
  9.   con_app.exec("INSERT INTO Names VALUES(1, 'SomeName')")
  10.   result = con_app.exec('SELECT * FROM Names')
  11.   result.each { |name| puts "#{name['id']}, #{name['name']}" }
  12.   con_app.exec('DROP TABLE Names')
  13.   con_app&.close
  14.   con.exec('DROP DATABASE app_db')
  15.   con&.close
  16. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand