Skip to content

Commit

Permalink
Reuse timezone regexp (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
moredure committed Mar 25, 2022
1 parent 5156d7e commit cd3fc52
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion postgres.go
Expand Up @@ -40,6 +40,8 @@ func (dialector Dialector) Name() string {
return "postgres"
}

var timeZoneMatcher = regexp.MustCompile("(time_zone|TimeZone)=(.*?)($|&| )")

func (dialector Dialector) Initialize(db *gorm.DB) (err error) {
// register callbacks
callbacks.RegisterDefaultCallbacks(db, &callbacks.Config{
Expand All @@ -62,7 +64,7 @@ func (dialector Dialector) Initialize(db *gorm.DB) (err error) {
if dialector.Config.PreferSimpleProtocol {
config.PreferSimpleProtocol = true
}
result := regexp.MustCompile("(time_zone|TimeZone)=(.*?)($|&| )").FindStringSubmatch(dialector.Config.DSN)
result := timeZoneMatcher.FindStringSubmatch(dialector.Config.DSN)
if len(result) > 2 {
config.RuntimeParams["timezone"] = result[2]
}
Expand Down

0 comments on commit cd3fc52

Please sign in to comment.