fix: Fixing up postgres connection strings (#96)
This commit is contained in:
parent
8d43829bc5
commit
a85eafd58c
1 changed files with 6 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ package postgres
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
|
@ -31,8 +32,11 @@ type DBConnection struct {
|
||||||
func Generate(destDir string, dbConn DBConnection, genTemplate ...template.Template) (err error) {
|
func Generate(destDir string, dbConn DBConnection, genTemplate ...template.Template) (err error) {
|
||||||
defer utils.ErrorCatch(&err)
|
defer utils.ErrorCatch(&err)
|
||||||
|
|
||||||
connectionString := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s %s",
|
if dbConfig.SchemaName == "" {
|
||||||
dbConn.Host, strconv.Itoa(dbConn.Port), dbConn.User, dbConn.Password, dbConn.DBName, dbConn.SslMode, dbConn.Params)
|
dbConfig.SchemaName = "public"
|
||||||
|
}
|
||||||
|
connectionString := fmt.Sprintf("postgresql://%s:%s@%s:%s/%s?sslmode=%s&search_path=%s",
|
||||||
|
dbConn.User, url.QueryEscape(dbConn.Password), dbConn.Host, strconv.Itoa(dbConn.Port), dbConn.DBName, dbConn.SslMode, dbConn.SchemaName)
|
||||||
|
|
||||||
db := openConnection(connectionString)
|
db := openConnection(connectionString)
|
||||||
defer utils.DBClose(db)
|
defer utils.DBClose(db)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue