Skip to content

Commit

Permalink
Merge pull request #215 from prusnak/psql-unix-prefix
Browse files Browse the repository at this point in the history
Enable "unix:" prefix for PostgreSQL connection string
  • Loading branch information
kiwiidb authored Jul 22, 2022
2 parents c6a56b5 + 487524c commit 2bdd71c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
func Open(dsn string) (*bun.DB, error) {
var db *bun.DB
switch {
case strings.HasPrefix(dsn, "postgres"):
case strings.HasPrefix(dsn, "postgres://") || strings.HasPrefix(dsn, "postgresql://") || strings.HasPrefix(dsn, "unix://"):
dbConn := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))
db = bun.NewDB(dbConn, pgdialect.New())
default:
return nil, fmt.Errorf("Invalid database connection string %s, only postgres is supported", dsn)
return nil, fmt.Errorf("Invalid database connection string %s, only (postgres|postgresql|unix):// is supported", dsn)
}

db.AddQueryHook(bundebug.NewQueryHook(
Expand Down

0 comments on commit 2bdd71c

Please sign in to comment.