Help us shape the future of Go! Take the 2026 Go Developer Survey

postgres

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package postgres is the PostgreSQL provider for the database package: it constructs the connection pool over pgx's database/sql adapter and supplies the postgres dialect. The pgx dependency lives in this sub-module's go.mod, so it enters a consumer's graph only when this package is imported — once, at the composition root.

Construction

New builds the pool from a finalized database.Config without I/O: it composes a postgres:// URL with net/url from the host, port (defaulting to 5432), name, user, and Options, parses it eagerly with pgx.ParseConfig — a malformed config is a construction error, not a first-query surprise — and then sets the password and connect timeout as fields on the parsed config. The password never enters the composed URL, so no character in it can break or leak through the connection string. An empty user falls back to pgx's default, the OS username. Options keys that name connection fields (host, port, user, password, dbname, database, connect_timeout) are rejected; values pgx cannot parse, such as an invalid sslmode, fail with the parse error.

The result is a *database.DB: lifecycle wiring, readiness, and everything else the base package offers come with it, and the Provider constant supports typed selection in the composition root.

Dialect

The dialect names itself "postgres", renders bind placeholders as $1, $2, …, and returns driver errors unchanged; classification of constraint violations arrives with the write path.

Index

Constants

View Source
const Provider database.Provider = "postgres"

Provider is this sub-module's typed selection constant.

Variables

This section is empty.

Functions

func New

func New(cfg database.Config) (*database.DB, error)

New constructs the connection pool from a finalized config and wraps it with the postgres dialect via database.New. It performs no I/O; see the package documentation for the composition and its guarantees. An unfinalized config panics with the fix named.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL