Skip to content

Commit

Permalink
Remove GetDBURI and cached connection string (#1900)
Browse files Browse the repository at this point in the history
  • Loading branch information
evankanderson authored Dec 11, 2023
1 parent 7acaf81 commit 52b5da8
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions internal/config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,13 @@ type DatabaseConfig struct {
Password string `mapstructure:"dbpass" default:"postgres"`
Name string `mapstructure:"dbname" default:"minder"`
SSLMode string `mapstructure:"sslmode" default:"disable"`

// connection string
connString string
}

// GetDBURI returns the database URI
func (c *DatabaseConfig) GetDBURI() string {
c.connString = fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s",
c.User, url.QueryEscape(c.Password), c.Host, c.Port, c.Name, c.SSLMode)

return c.connString
}

// GetDBConnection returns a connection to the database
func (c *DatabaseConfig) GetDBConnection(ctx context.Context) (*sql.DB, string, error) {
uri := c.GetDBURI()
uri := fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s",
c.User, url.QueryEscape(c.Password), c.Host, c.Port, c.Name, c.SSLMode)

conn, err := splunksql.Open("postgres", uri)
if err != nil {
return nil, "", err
Expand Down

0 comments on commit 52b5da8

Please sign in to comment.