Add postgres support #135

Merged
konrad merged 26 commits from jtojnar/api:pgsql into master 2020-02-16 21:42:05 +00:00
1 changed files with 2 additions and 2 deletions
Showing only changes of commit f3cd4d9ee8 - Show all commits

View File

@ -140,7 +140,7 @@ 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/%ssslmode=%s&host=%s",
connStr = fmt.Sprintf("postgres://%s:%s@:%s/%s?sslmode=%s&host=%s",

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.

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.

Good point. What do think would be better suited, using the same for both or using the attr=name format?

Good point. What do think would be better suited, using the same for both or using the `attr=name` format?

I think attr=%s is clearer.

I think `attr=%s` is clearer.

Then lets change it.

Then lets change it.
url.PathEscape(config.DatabaseUser.GetString()),
url.PathEscape(config.DatabasePassword.GetString()),
port,
@ -148,7 +148,7 @@ func initPostgresEngine() (engine *xorm.Engine, err error) {
config.DatabaseSslMode.GetString(),

I am not sure if these flags are needed.

I am not sure if these flags are needed.

I am not sure if these flags are needed.

I am not sure if these flags are needed.

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.
host)
} else {
connStr = fmt.Sprintf("postgres://%s:%s@%s:%s/%ssslmode=%s",
connStr = fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s",
url.PathEscape(config.DatabaseUser.GetString()),
url.PathEscape(config.DatabasePassword.GetString()),
host,