feat: Initialized Project
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user