- 新增 internal/store/db.go - 实现 NewPostgresPool(ctx, dsn) 创建连接池 - 添加 pgx/v5 依赖 - 最大连接数设置为 10
18 lines
340 B
Go
18 lines
340 B
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// NewPostgresPool 创建 PostgreSQL 连接池。
|
|
func NewPostgresPool(ctx context.Context, dsn string) (*pgxpool.Pool, error) {
|
|
cfg, err := pgxpool.ParseConfig(dsn)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
cfg.MaxConns = 10
|
|
return pgxpool.NewWithConfig(ctx, cfg)
|
|
}
|