jet
jet copied to clipboard
postgres connection via unix socket
Is your feature request related to a problem? Please describe.
When using a locally install postgresql on linux machine, i would like to connect via unix socket to postgresql. Usually this is done by using string "postgresql://username@/database". It does not work with jet, it shows an error that password is missing.
Describe the solution you'd like
Since in normal use for golang app, connection string to unix socket works just fine, it would be good to have the same for go-jet.
Additional benefit is that on local machine no ports have to be open in this case.
Could you share the error message.
m@aio:~/Projects/myproject$ /home/m/go/bin/jet -dsn="postgresql://m@/projectdb" -schema="public" -path="./.gen
Connecting to postgres database...
Error trace:
- failed to open db connection:
- failed to ping database:
- pq:
- password authentication failed for user "m"
in the same app, i open a pgxpool connection via following:
pgxpool.New(context.Background(), cfg.Db.Dsn)
cfg.Db.Dsn is
postgresql://m@/projectdb
figured it out, it doesnt work with "normal" dns string: it has to use source and dns together
./jet -source=postgres -dsn="user=myuser password=. host=/var/run/postgresql port=5432 dbname=mydbname" -path="./jet"
Parsing of "postgresql://xxxxxxxxx" string seems to not work. Anyway, pq supports unix socket, but in a different form:
host - The host to connect to. Values that start with / are for unix domain sockets. (default is localhost)
Code location is here.
func network(o values) (string, string) {
host := o["host"]
// UNIX domain sockets are either represented by an (absolute) file system
// path or they live in the abstract name space (starting with an @).
if filepath.IsAbs(host) || strings.HasPrefix(host, "@") {
sockPath := filepath.Join(host, ".s.PGSQL."+o["port"])
return "unix", sockPath
}
return "tcp", net.JoinHostPort(host, o["port"])
}