2025-01-16 13:48:05 +01:00
|
|
|
package persistence
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2025-01-17 20:51:50 +01:00
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
2025-01-16 13:48:05 +01:00
|
|
|
)
|
|
|
|
|
2025-01-17 20:51:50 +01:00
|
|
|
func NewConnection() (*pgxpool.Pool, error) {
|
2025-01-16 13:48:05 +01:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
|
|
|
defer cancel()
|
|
|
|
|
2025-01-17 20:51:50 +01:00
|
|
|
conn, err := pgxpool.New(ctx, os.Getenv("ORBIS_POSTGRES_DB"))
|
2025-01-16 13:48:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to connect to orbis postgres database: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return conn, nil
|
|
|
|
}
|