2021-02-13 02:49:36 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-03-17 23:14:24 +00:00
|
|
|
"os"
|
2021-02-13 02:49:36 +00:00
|
|
|
"context"
|
2021-03-17 23:14:24 +00:00
|
|
|
"log"
|
2025-01-28 16:34:33 +00:00
|
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v4/pgxpool"
|
2021-02-13 02:49:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var pool *pgxpool.Pool
|
|
|
|
|
|
|
|
func getDbPool() *pgxpool.Pool {
|
|
|
|
// Setup Database
|
2025-01-28 16:34:33 +00:00
|
|
|
dburl := fmt.Sprintf("postgres://%s:%s@%s/%s", os.Getenv("POSTGRES_USER"), os.Getenv("POSTGRES_PASSWORD"), os.Getenv("POSTGRES_HOSTNAME"), os.Getenv("POSTGRES_DB"))
|
2025-01-24 21:30:25 +00:00
|
|
|
pool, err := pgxpool.Connect(context.Background(), dburl)
|
2021-02-13 02:49:36 +00:00
|
|
|
if err != nil {
|
2021-03-17 23:14:24 +00:00
|
|
|
log.Fatal("Unable to connect to database:", err)
|
2021-02-13 02:49:36 +00:00
|
|
|
}
|
|
|
|
return pool
|
|
|
|
}
|