Skip to content

Commit

Permalink
feat: added db schema to postgres template (#245)
Browse files Browse the repository at this point in the history
* feat: added db schema to postgres template
  • Loading branch information
ashupednekar authored Jun 12, 2024
1 parent 60a726e commit 1750ccf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/template/dbdriver/files/env/postgres.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ DB_PORT=5432
DB_DATABASE=blueprint
DB_USERNAME=melkey
DB_PASSWORD=password1234
DB_SCHEMA=public
3 changes: 2 additions & 1 deletion cmd/template/dbdriver/files/service/postgres.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
username = os.Getenv("DB_USERNAME")
port = os.Getenv("DB_PORT")
host = os.Getenv("DB_HOST")
schema = os.Getenv("DB_SCHEMA")
dbInstance *service
)

Expand All @@ -42,7 +43,7 @@ func New() Service {
if dbInstance != nil {
return dbInstance
}
connStr := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=disable", username, password, host, port, database)
connStr := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=disable&search_path=%s", username, password, host, port, database, schema)
db, err := sql.Open("pgx", connStr)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 1750ccf

Please sign in to comment.