Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. require "pg"
  2.  
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement