mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
24 lines
387 B
Go
24 lines
387 B
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"github.com/memohai/memoh/internal/config"
|
|
)
|
|
|
|
func Open(ctx context.Context, cfg config.PostgresConfig) (*pgxpool.Pool, error) {
|
|
dsn := fmt.Sprintf(
|
|
"postgres://%s:%s@%s:%d/%s?sslmode=%s",
|
|
cfg.User,
|
|
cfg.Password,
|
|
cfg.Host,
|
|
cfg.Port,
|
|
cfg.Database,
|
|
cfg.SSLMode,
|
|
)
|
|
return pgxpool.New(ctx, dsn)
|
|
}
|