Add postgres support #135
26
pkg/db/db.go
26
pkg/db/db.go
|
@ -137,25 +137,15 @@ func parsePostgreSQLHostPort(info string) (string, string) {
|
|||
}
|
||||
|
||||
|
||||
func initPostgresEngine() (engine *xorm.Engine, err error) {
|
||||
var connStr string
|
||||
host, port := parsePostgreSQLHostPort(config.DatabaseHost.GetString())
|
||||
if strings.HasPrefix(config.DatabaseHost.GetString(), "/") { // looks like a unix socket
|
||||
connStr = fmt.Sprintf("postgres://%s:%s@:%s/%s?sslmode=%s&host=%s",
|
||||
url.PathEscape(config.DatabaseUser.GetString()),
|
||||
url.PathEscape(config.DatabasePassword.GetString()),
|
||||
port,
|
||||
config.DatabaseDatabase.GetString(),
|
||||
config.DatabaseSslMode.GetString(),
|
||||
host)
|
||||
} else {
|
||||
connStr = fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s",
|
||||
url.PathEscape(config.DatabaseUser.GetString()),
|
||||
url.PathEscape(config.DatabasePassword.GetString()),
|
||||
host,
|
||||
port,
|
||||
config.DatabaseDatabase.GetString(),
|
||||
config.DatabaseSslMode.GetString())
|
||||
}
|
||||
connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s",
|
||||
host,
|
||||
port,
|
||||
jtojnar
commented
Why not just use the Why not just use the `attr=name` format instead of URI format? Or use this one for both UNIX socket and TCP connection? This only needs to be used for UNIX sockets because URI hostnames cannot contain `/` but the other way around is fine.
konrad
commented
Good point. What do think would be better suited, using the same for both or using the Good point. What do think would be better suited, using the same for both or using the `attr=name` format?
jtojnar
commented
I think I think `attr=%s` is clearer.
konrad
commented
Then lets change it. Then lets change it.
|
||||
url.PathEscape(config.DatabaseUser.GetString()),
|
||||
url.PathEscape(config.DatabasePassword.GetString()),
|
||||
config.DatabaseDatabase.GetString(),
|
||||
config.DatabaseSslMode.GetString(),
|
||||
)
|
||||
jtojnar
commented
I am not sure if these flags are needed. I am not sure if these flags are needed.
jtojnar
commented
I am not sure if these flags are needed. I am not sure if these flags are needed.
konrad
commented
I'd say yes, since the max number of open connections can be a limiting factor for performance. I'd say yes, since the max number of open connections can be a limiting factor for performance.
|
||||
|
||||
engine, err = xorm.NewEngine("postgres", connStr)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue
We will probably need to allow passing the rest of the options. The Go library recommended by xorm decided to stray from libpq’s defaults and forces
sslmode=required
, which fails on my laptop where I do not have TLS set up.Or maybe we can just accept raw connection string?
I'd say we probably should add a setting for
sslmode
.