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)
|
||
|
|
}
|