File tree Expand file tree Collapse file tree 4 files changed +29
-13
lines changed Expand file tree Collapse file tree 4 files changed +29
-13
lines changed Original file line number Diff line number Diff line change 11
11
run-tests :
12
12
strategy :
13
13
matrix :
14
- go : ['1.19 ']
14
+ go : ['1.20 ']
15
15
platform : [ubuntu-latest]
16
16
runs-on : ubuntu-latest
17
17
Original file line number Diff line number Diff line change 1
1
module gorm.io/driver/postgres
2
2
3
- go 1.19
3
+ go 1.20
4
4
5
5
require (
6
- github.com/jackc/pgx/v5 v5.5.5
6
+ github.com/jackc/pgx/v5 v5.6.0
7
7
gorm.io/gorm v1.25.10
8
8
)
9
9
10
10
require (
11
11
github.com/jackc/pgpassfile v1.0.0 // indirect
12
- github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
13
- github.com/jackc/puddle/v2 v2.2.1 // indirect
12
+ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
13
+ github.com/jackc/puddle/v2 v2.2.2 // indirect
14
14
github.com/jinzhu/inflection v1.0.0 // indirect
15
15
github.com/jinzhu/now v1.1.5 // indirect
16
16
golang.org/x/crypto v0.31.0 // indirect
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
2
2
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c =
3
3
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM =
4
4
github.com/jackc/pgpassfile v1.0.0 /go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg =
5
- github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk =
6
- github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a /go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM =
7
- github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw =
8
- github.com/jackc/pgx/v5 v5.5.5 /go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A =
9
- github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk =
10
- github.com/jackc/puddle/v2 v2.2.1 /go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4 =
5
+ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo =
6
+ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 /go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM =
7
+ github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY =
8
+ github.com/jackc/pgx/v5 v5.6.0 /go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw =
9
+ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo =
10
+ github.com/jackc/puddle/v2 v2.2.2 /go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4 =
11
11
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E =
12
12
github.com/jinzhu/inflection v1.0.0 /go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc =
13
13
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ =
Original file line number Diff line number Diff line change 1
1
package postgres
2
2
3
3
import (
4
+ "context"
4
5
"database/sql"
5
6
"fmt"
6
7
"regexp"
7
8
"strconv"
8
9
"strings"
10
+ "time"
9
11
10
12
"github.com/jackc/pgx/v5"
13
+ "github.com/jackc/pgx/v5/pgtype"
11
14
"github.com/jackc/pgx/v5/stdlib"
12
15
"gorm.io/gorm"
13
16
"gorm.io/gorm/callbacks"
@@ -31,7 +34,7 @@ type Config struct {
31
34
}
32
35
33
36
var (
34
- timeZoneMatcher = regexp .MustCompile ("(time_zone|TimeZone)=(.*?)($|&| )" )
37
+ timeZoneMatcher = regexp .MustCompile ("(time_zone|TimeZone|timezone )=(.*?)($|&| )" )
35
38
defaultIdentifierLength = 63 //maximum identifier length for postgres
36
39
)
37
40
@@ -99,10 +102,23 @@ func (dialector Dialector) Initialize(db *gorm.DB) (err error) {
99
102
config .DefaultQueryExecMode = pgx .QueryExecModeSimpleProtocol
100
103
}
101
104
result := timeZoneMatcher .FindStringSubmatch (dialector .Config .DSN )
105
+ var options []stdlib.OptionOpenDB
102
106
if len (result ) > 2 {
103
107
config .RuntimeParams ["timezone" ] = result [2 ]
108
+ options = append (options , stdlib .OptionAfterConnect (func (ctx context.Context , conn * pgx.Conn ) error {
109
+ loc , tzErr := time .LoadLocation (result [2 ])
110
+ if tzErr != nil {
111
+ return tzErr
112
+ }
113
+ conn .TypeMap ().RegisterType (& pgtype.Type {
114
+ Name : "timestamp" ,
115
+ OID : pgtype .TimestampOID ,
116
+ Codec : & pgtype.TimestampCodec {ScanLocation : loc },
117
+ })
118
+ return nil
119
+ }))
104
120
}
105
- db .ConnPool = stdlib .OpenDB (* config )
121
+ db .ConnPool = stdlib .OpenDB (* config , options ... )
106
122
}
107
123
return
108
124
}
You can’t perform that action at this time.
0 commit comments