27 lines
522 B
Go
27 lines
522 B
Go
|
//go:build pq
|
||
|
// +build pq
|
||
|
|
||
|
package postgresql
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"database/sql"
|
||
|
"time"
|
||
|
|
||
|
"git.hexq.cn/tiglog/mydb/internal/sqladapter"
|
||
|
_ "github.com/lib/pq"
|
||
|
)
|
||
|
|
||
|
func (*database) OpenDSN(sess sqladapter.Session, dsn string) (*sql.DB, error) {
|
||
|
connURL, err := ParseURL(dsn)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if tz := connURL.Options["timezone"]; tz != "" {
|
||
|
loc, _ := time.LoadLocation(tz)
|
||
|
ctx := context.WithValue(sess.Context(), "timezone", loc)
|
||
|
sess.SetContext(ctx)
|
||
|
}
|
||
|
return sql.Open("postgres", dsn)
|
||
|
}
|