Created
October 13, 2021 12:34
-
-
Save almokhtarbr/8d73d15ff5093bf79a138cbac286f5ce to your computer and use it in GitHub Desktop.
This file contains 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 characters
gem 'pg' | |
require 'pg' | |
def with_db | |
db = PG.connect( | |
dbname: 'dbname', | |
user: 'user', | |
password: 'password' | |
) | |
begin | |
yield db | |
ensure | |
db.close | |
end | |
end | |
sql = File.open('path/to/your_sql.sql', 'rb') { |file| file.read } | |
with_db do |db| | |
begin | |
db.exec(sql) | |
rescue PG::Error | |
##### | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment