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

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