feat: 实现 PostgreSQL 连接池

- 新增 internal/store/db.go
- 实现 NewPostgresPool(ctx, dsn) 创建连接池
- 添加 pgx/v5 依赖
- 最大连接数设置为 10
This commit is contained in:
hhs
2026-06-14 16:41:50 +08:00
parent 4b30e67c2e
commit 0edafbbf8a
3 changed files with 38 additions and 6 deletions

View File

@@ -0,0 +1,17 @@
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)
}