feat: 实现 PostgreSQL 连接池
- 新增 internal/store/db.go - 实现 NewPostgresPool(ctx, dsn) 创建连接池 - 添加 pgx/v5 依赖 - 最大连接数设置为 10
This commit is contained in:
17
backend/internal/store/db.go
Normal file
17
backend/internal/store/db.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user