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

postgres

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Offset

func Offset(pageParam int64, pageSize uint64) uint64

func PageSize

func PageSize(sizeParam int64) uint64

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps a pgxpool.Pool for PostgreSQL access.

func NewClient

func NewClient(cfg Config, logger *slog.Logger, tracer trace.Tracer) (*Client, error)

NewClient creates a new PostgreSQL client backed by a pgxpool.Pool.

func (*Client) Begin

func (c *Client) Begin(ctx context.Context) (pgx.Tx, error)

Begin starts a new transaction

func (*Client) Builder

func (c *Client) Builder() sq.StatementBuilderType

Builder returns a pre-configured squirrel StatementBuilderType for Postgres ($ placeholders)

func (*Client) Close

func (c *Client) Close()

Close closes the pgxpool connection pool

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, query string, args ...interface{}) (pgconn.CommandTag, error)

Exec executes a query without returning any rows

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping verifies a connection to the database is still alive

func (*Client) Query

func (c *Client) Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)

Query executes a query that returns rows

func (*Client) QueryRow

func (c *Client) QueryRow(ctx context.Context, query string, args ...interface{}) pgx.Row

QueryRow executes a query that is expected to return at most one row

type Config

type Config struct {
	Host            string
	Port            int
	User            string
	Password        string
	DBName          string
	SSLMode         string
	MaxOpenConns    int32
	MaxIdleConns    int32
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
	ConnectTimeout  time.Duration
}

Config holds PostgreSQL client configuration

func (*Config) DSN

func (c *Config) DSN() string

DSN builds the PostgreSQL connection string (Data Source Name)

type DBClientInterface

type DBClientInterface interface {
	// Query executes a query that returns rows
	Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
	// QueryRow executes a query that returns at most one row
	QueryRow(ctx context.Context, query string, args ...interface{}) pgx.Row
	// Exec executes a query without returning any rows
	Exec(ctx context.Context, query string, args ...interface{}) (pgconn.CommandTag, error)
	// Begin starts a new transaction
	Begin(ctx context.Context) (pgx.Tx, error)
	// Builder returns a pre-configured squirrel StatementBuilderType for Postgres ($N placeholders)
	Builder() sq.StatementBuilderType
	// Ping verifies the connection to the database is still alive
	Ping(ctx context.Context) error
	// Close closes the connection pool
	Close()
}

DBClientInterface defines the interface for database operations using pgx native types.

Jump to

Keyboard shortcuts

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