postgres

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT, MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postgres is the PostgreSQL database driver: from the variables it declares, it opens a connection pool on the application's database and the resource client over it. An application embeds Settings in its configuration and calls Open, and names no database vendor in its own code; moving to another database swaps this import for that database's driver (resource/database/spanner). Bound under the neutral alias database (database "github.com/impulseframework/impulse/resource/database/postgres"), with the settings embedded as database.Settings and the driver opened by database.Open, the swap is the import line alone.

The driver opens the pool and wraps resource.NewPostgresClient; what the resource client itself can do on PostgreSQL is the resource package's to complete.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct {
	// ResourceClient is the resource client over the database: what the generated
	// handlers read and write through.
	ResourceClient *resource.PostgresClient
	// Pool is the connection pool the resource client is built over, for what else the
	// application runs on the database.
	Pool *pgxpool.Pool
}

Driver is what Open built: the pool over the database and the resource client over it, closed together.

func Open

func Open(ctx context.Context, s Settings, opts ...resource.ClientOption) (*Driver, error)

Open opens a connection pool on the database the settings name and checks it answers, so a wrong host, role or password fails the start and not the first request, then builds the resource client over the pool, with the file stores the options wire on it (resource.WithFileStore, resource.WithNamedFileStore), the options the Spanner driver's Open takes.

func (*Driver) Close

func (d *Driver) Close()

Close closes the pool, and with it every connection the resource client held.

type Settings

type Settings struct {
	// Host is the server's host name or address, or the directory holding its Unix
	// socket (/cloudsql/<connection name> on Cloud Run).
	Host string `env:"APP_POSTGRES_HOST,required"`
	// Port is the server's port.
	Port string `env:"APP_POSTGRES_PORT,default=5432"`
	// Database is the database on the server.
	Database string `env:"APP_POSTGRES_DATABASE,required"`
	// User is the role the application connects as.
	User string `env:"APP_POSTGRES_USER,required"`
	// Password is the role's password, a secret that belongs in a secret store and never
	// in a committed file; empty where the server authenticates the connection another
	// way (the peer of a Unix socket, IAM on Cloud SQL).
	Password string `env:"APP_POSTGRES_PASSWORD"`
	// SSLMode is how the connection is protected, as PostgreSQL spells it (disable,
	// allow, prefer, require, verify-ca, verify-full): require unless set, and disable
	// against a local container.
	SSLMode string `env:"APP_POSTGRES_SSL_MODE,default=require"`
}

Settings are the variables the driver reads, where the database is and how the application connects, declared on the application's configuration by embedding, so the stack and the development environment render them from the declaration. The declaration the tools read is declaration.Settings, in the package beside this one, which holds nothing of the driver.

Directories

Path Synopsis
Package declaration publishes the declaration of the PostgreSQL database driver's settings struct for the tools that read an application embedding it without loading its packages (impulse's checks, bedrock's stack): what postgres.Settings declares, in the shape the cloud package defines.
Package declaration publishes the declaration of the PostgreSQL database driver's settings struct for the tools that read an application embedding it without loading its packages (impulse's checks, bedrock's stack): what postgres.Settings declares, in the shape the cloud package defines.

Jump to

Keyboard shortcuts

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