Skip to content

Commit 0ddf85b

Browse files
committed
Use plugin instead of db lib to open database.
1 parent 4607fe3 commit 0ddf85b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

model.gb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
require "db"
2-
31
db_user = ENV["POSTGRES_USER"] || "postgres"
42
db_name = ENV["POSTGRES_DB"] || "goby_test"
53
db_host = ENV["POSTGRES_HOST"] || "0.0.0.0"
64

7-
PG = DB.open("postgres", String.fmt("user=%s dbname=%s host=%s sslmode=disable", db_user, db_name, db_host))
5+
require "plugin"
6+
7+
plugin = Plugin.generate("db") do |p|
8+
p.import_pkg("", "database/sql")
9+
p.import_pkg("_", "github.com/lib/pq")
10+
p.link_function("sql", "Open")
11+
end
12+
13+
conn, err = plugin.go_func("Open", "postgres", String.fmt("user=%s dbname=%s host=%s sslmode=disable", db_user, db_name, db_host))
14+
15+
if err
16+
puts(err.go_func("Error"))
17+
return nil
18+
end
19+
20+
PG = conn
821

922
PG.run("create table if not exists list_items (
1023
id serial primary key,

0 commit comments

Comments
 (0)