pgx

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 6 Imported by: 0

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 the Postgres DSN for cfg. BuildDSN 返回 cfg 的 Postgres DSN。

func NewPool

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

NewPool returns a pgx connection pool. Call NewPool(ctx, Config{...}). NewPool 返回 pgx 连接池。 调用 NewPool(ctx, Config{...})。

Example / 示例:

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

func Ping

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

Ping checks pool connectivity. Ping 检查连接池连通性。

Types

type Config

type Config struct {
	Host            string
	Port            int
	User            string
	Password        string
	Database        string
	SSLMode         string
	MaxConns        int
	MinConns        int
	MaxConnLifetime time.Duration
	// ConnectTimeout limits each connection attempt. Non-positive values use five seconds.
	// ConnectTimeout 限制每次连接尝试;非正值使用五秒。
	ConnectTimeout time.Duration
}

Config configures NewPool. Config 配置 NewPool。

Jump to

Keyboard shortcuts

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