https://github.com/tbe/pqparser
A helper library to support libpq style connection strings for go-pg
https://github.com/tbe/pqparser
go golang postgres postgresql
Last synced: about 1 year ago
JSON representation
A helper library to support libpq style connection strings for go-pg
- Host: GitHub
- URL: https://github.com/tbe/pqparser
- Owner: tbe
- License: bsd-2-clause
- Created: 2019-07-21T12:16:31.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-23T11:27:02.000Z (almost 7 years ago)
- Last Synced: 2025-04-01T20:31:35.888Z (about 1 year ago)
- Topics: go, golang, postgres, postgresql
- Language: Go
- Size: 18.6 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pqparser
A helper library to support libpq style connection strings for go-pg
## Why?
[go-pg][1] does have a very limited support for URI style DSN's. The goal of this library is,
to support the full feature set of [libpq][2]'s connection strings.
## Usage
```go
package main
import (
"gitlab.com/tbe/pqparser"
"github.com/go-pg/pg"
)
func main() {
options,err := pqparser.Parse("postgres://%2Fvar%2Flib%2Fpostgresql/dbname")
if err != nil {
panic(err)
}
db := pg.Connect(options)
...
}
```
For full documentation about the behavior of `Parse`, see the [`libpq` documenation][2]
## Limitations
In difference to `libpq`, we use a TCP connection to `localhost` if no hostname is given.
`libpq` has a default socket path, but we don't know where the socket could be found.
Currently, there are a few features that are not implemented.
### `keepalive*` settings
As go-pq does not have support for keepalive settings, we ignore these parameters.
### `sslcompression`
I'm not sure if it is possible to implement this without dark hacks.
### `requirepeer`
This may be implemented later. We could implement this by overriding the `Dialer` function.
### `krbsrvname` and `gsslib`
There is no support for this authentication methods in go-pg.
### `service`
Could be implemented later. PR's welcome
### `sslmode`
Expect `verify-full`, all sslmodes skip the host verification at the moment.
### `sslrootcert` and `sslcrl`
Should be simple to implement, but the work is not done yet
[1]: https://github.com/go-pg/pg
[2]: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING