Documentation
¶
Overview ¶
Package db @notice Opens the Postgres pool luima's resolvers query through.
@dev One function, because connecting is the only part of the data layer that is the same in every application. Everything else is your models and the crud package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
Connect @notice Opens the pool the resolvers query through and proves it works.
@dev Two things about pg.ParseURL that the connection string has to respect:
- It rejects any query parameter other than sslmode, application_name and connect_timeout, with "pg: options other than ... are not supported". pgx-style tuning such as ?default_query_exec_mode=simple_protocol is therefore a startup failure here, not a no-op.
- With sslmode absent it returns &tls.Config{InsecureSkipVerify: true}, so a managed Postgres connects over TLS with nothing to configure — and nothing verified. ?sslmode=verify-full is what verifies it.
Both postgres:// and postgresql:// schemes parse.
Unlike the server this was lifted from, Connect returns its error rather than calling log.Fatal, and takes the URL rather than reading os.Getenv: a library must not kill the caller's process, choose their logging, or read configuration behind their back. Write log.Fatal(err) at the call site if that is what you want.
@param url a postgres:// or postgresql:// connection string @return *pg.DB a live pool, already proven with a round trip; nil on error @return error a parse failure, or the ping failure with the pool already closed
Types ¶
This section is empty.