initial commit

This commit is contained in:
2026-04-02 01:52:41 -04:00
commit 571aab64bb
10 changed files with 611 additions and 0 deletions

38
db.go Normal file
View File

@@ -0,0 +1,38 @@
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/jackc/pgx/v5/pgxpool"
)
var pool *pgxpool.Pool
func getDbPool() *pgxpool.Pool {
// Construct the connection string
// Note: Ensure your Docker Compose env vars match these keys!
dburl := fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=disable",
os.Getenv("POSTGRES_USER"),
os.Getenv("POSTGRES_PASSWORD"),
os.Getenv("POSTGRES_HOSTNAME"),
os.Getenv("POSTGRES_DB"),
)
var err error
// Use pgxpool.New instead of Connect for v5
pool, err = pgxpool.New(context.Background(), dburl)
if err != nil {
log.Fatalf("Unable to create connection pool: %v", err)
}
// Ping the database to verify the connection is actually live
err = pool.Ping(context.Background())
if err != nil {
log.Fatalf("Unable to ping database: %v", err)
}
return pool
}