@@ -17,7 +17,6 @@ import (
17
17
18
18
// DBConnectionFactory is a database connection factory on postgres with gorp
19
19
type DBConnectionFactory struct {
20
- DBDriver string
21
20
DBRole string
22
21
DBUser string
23
22
DBPassword string
@@ -75,7 +74,6 @@ func Init(ctx context.Context, user, role, password, name, schema, host string,
75
74
}
76
75
77
76
f := & DBConnectionFactory {
78
- DBDriver : "postgres" ,
79
77
DBRole : role ,
80
78
DBUser : user ,
81
79
DBPassword : password ,
@@ -121,7 +119,13 @@ func Init(ctx context.Context, user, role, password, name, schema, host string,
121
119
// connect_timeout in seconds
122
120
// statement_timeout in milliseconds
123
121
dsn := f .dsn ()
124
- f .Database , err = sql .Open (f .DBDriver , dsn )
122
+ connector , err := pq .NewConnector (dsn )
123
+ if err != nil {
124
+ log .Error (ctx , "cannot open database: %s" , err )
125
+ return nil , sdk .WithStack (err )
126
+ }
127
+ f .Database = sql .OpenDB (connector )
128
+
125
129
if err != nil {
126
130
f .Database = nil
127
131
log .Error (ctx , "cannot open database: %s" , err )
@@ -154,7 +158,7 @@ func Init(ctx context.Context, user, role, password, name, schema, host string,
154
158
}
155
159
156
160
func (f * DBConnectionFactory ) dsn () string {
157
- dsn := fmt .Sprintf ("user=%s password=%s dbname=%s host=%s port=%d sslmode=%s connect_timeout=%d" , f .DBUser , f .DBPassword , f .DBName , f .DBHost , f .DBPort , f .DBSSLMode , f .DBConnectTimeout )
161
+ dsn := fmt .Sprintf ("user=%s password='%s' dbname=%s host=%s port=%d sslmode=%s connect_timeout=%d" , f .DBUser , f .DBPassword , f .DBName , f .DBHost , f .DBPort , f .DBSSLMode , f .DBConnectTimeout )
158
162
if f .DBSchema != "public" {
159
163
dsn += fmt .Sprintf (" search_path=%s" , f .DBSchema )
160
164
}
0 commit comments