28 lines
508 B
Go
28 lines
508 B
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
var Pool *pgxpool.Pool
|
|
|
|
func ConnectToDB(connection_string string) {
|
|
var err error
|
|
|
|
Pool, err = pgxpool.New(context.Background(), connection_string)
|
|
if err != nil {
|
|
log.Fatalf("Unable to create connection pool: %v", err)
|
|
}
|
|
|
|
// Test the connection
|
|
err = Pool.Ping(context.Background())
|
|
if err != nil {
|
|
log.Fatalf("Unable to ping the database: %v", err)
|
|
}
|
|
|
|
log.Println("Successfully connected to the database")
|
|
}
|