Skip to content

Commit c65a34e

Browse files
authored
Allow the user to pass in their own stdlib.OptionOpenDB to the underlying postgres driver. (#322)
1 parent bc1ffc0 commit c65a34e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

postgres.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Config struct {
3131
PreferSimpleProtocol bool
3232
WithoutReturning bool
3333
Conn gorm.ConnPool
34+
OptionOpenDB []stdlib.OptionOpenDB
3435
}
3536

3637
var (
@@ -102,10 +103,9 @@ func (dialector Dialector) Initialize(db *gorm.DB) (err error) {
102103
config.DefaultQueryExecMode = pgx.QueryExecModeSimpleProtocol
103104
}
104105
result := timeZoneMatcher.FindStringSubmatch(dialector.Config.DSN)
105-
var options []stdlib.OptionOpenDB
106106
if len(result) > 2 {
107107
config.RuntimeParams["timezone"] = result[2]
108-
options = append(options, stdlib.OptionAfterConnect(func(ctx context.Context, conn *pgx.Conn) error {
108+
dialector.OptionOpenDB = append(dialector.OptionOpenDB, stdlib.OptionAfterConnect(func(ctx context.Context, conn *pgx.Conn) error {
109109
loc, tzErr := time.LoadLocation(result[2])
110110
if tzErr != nil {
111111
return tzErr
@@ -118,7 +118,7 @@ func (dialector Dialector) Initialize(db *gorm.DB) (err error) {
118118
return nil
119119
}))
120120
}
121-
db.ConnPool = stdlib.OpenDB(*config, options...)
121+
db.ConnPool = stdlib.OpenDB(*config, dialector.OptionOpenDB...)
122122
}
123123
return
124124
}

0 commit comments

Comments
 (0)