@@ -17,7 +17,6 @@ import (
1717
1818// DBConnectionFactory is a database connection factory on postgres with gorp
1919type DBConnectionFactory struct {
20- DBDriver string
2120 DBRole string
2221 DBUser string
2322 DBPassword string
@@ -75,7 +74,6 @@ func Init(ctx context.Context, user, role, password, name, schema, host string,
7574 }
7675
7776 f := & DBConnectionFactory {
78- DBDriver : "postgres" ,
7977 DBRole : role ,
8078 DBUser : user ,
8179 DBPassword : password ,
@@ -121,7 +119,13 @@ func Init(ctx context.Context, user, role, password, name, schema, host string,
121119 // connect_timeout in seconds
122120 // statement_timeout in milliseconds
123121 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+
125129 if err != nil {
126130 f .Database = nil
127131 log .Error (ctx , "cannot open database: %s" , err )
@@ -154,7 +158,7 @@ func Init(ctx context.Context, user, role, password, name, schema, host string,
154158}
155159
156160func (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 )
158162 if f .DBSchema != "public" {
159163 dsn += fmt .Sprintf (" search_path=%s" , f .DBSchema )
160164 }
0 commit comments