Skip to content

Commit cc1a90a

Browse files
committed
Take DATABASE_URL env for pg connection
1 parent 90646b7 commit cc1a90a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

plugin.gb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ db_user = ENV["POSTGRES_USER"] || "postgres"
1212
db_name = ENV["POSTGRES_DB"] || "goby_test"
1313
db_host = ENV["POSTGRES_HOST"] || "0.0.0.0"
1414

15+
pg_host = ENV["DATABASE_URL"]
16+
17+
if pg_host.nil?
18+
pg_host = String.fmt("user=%s dbname=%s host=%s sslmode=disable", db_user, db_name, db_host)
19+
end
20+
1521
# Open PG connection using sqlx package's Open function
16-
conn, err = plugin.go_func("Open", "postgres", String.fmt("user=%s dbname=%s host=%s sslmode=disable", db_user, db_name, db_host))
22+
conn, err = plugin.go_func("Open", "postgres", pg_host)
1723

1824
if err
1925
puts(err.go_func("Error"))

0 commit comments

Comments
 (0)