pgx

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 6 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 pgx provides pgx pool helpers for Postgres. Package pgx 提供 Postgres 的 pgx 连接池辅助。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDSN

func BuildDSN(cfg Config) (string, error)

BuildDSN returns a Postgres DSN. BuildDSN 返回 Postgres DSN。

func NewPool

func NewPool(ctx context.Context, cfg Config) (*pgxpool.Pool, error)

NewPool creates a pgx connection pool. NewPool 创建 pgx 连接池。

Example / 示例:

pool, _ := pgx.NewPool(ctx, pgx.Config{Host: "localhost", Port: 5432, User: "app", Name: "db"})

func Ping

func Ping(ctx context.Context, pool *pgxpool.Pool) error

Ping performs a lightweight health check against the pool. Ping 对连接池执行轻量健康检查。

Types

type Config

type Config struct {
	Host            string
	Port            int
	User            string
	Password        string
	Name            string
	SSLMode         string
	MaxConns        int
	MinConns        int
	MaxConnLifetime time.Duration
	ConnectTimeout  time.Duration
}

Config holds Postgres connection settings. Config 包含 Postgres 连接配置。

Jump to

Keyboard shortcuts

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