infoalloggi-monorepo/apps/backend/queries/queries.go
Marco Pedone 2725098203 Refactor database handling and queries
- Updated DbHandler to accept configuration parameters instead of using environment variables directly.
- Moved database queries from handler.go to a dedicated queries package for better organization and separation of concerns.
- Implemented error handling in query functions to provide more informative error messages.
- Refactored image handling to utilize the new queries package for database interactions.
- Cleaned up unused code and comments across various files.
- Improved overall code readability and maintainability.
2025-08-22 10:11:07 +02:00

34 lines
510 B
Go

package queries
import (
"backend/db"
"os"
"github.com/joho/godotenv"
)
var (
Db *db.DbHandler
)
func init() {
_ = godotenv.Load(".env")
Db = db.NewDbHandler(db.Configs{
Host: os.Getenv("PGHOST"),
Dbname: os.Getenv("POSTGRES_DB"),
Port: os.Getenv("PGPORT"),
User: os.Getenv("POSTGRES_USER"),
Password: os.Getenv("POSTGRES_PASSWORD"),
})
}
func HealthCheck() bool {
if Db == nil || Db.Dbpool == nil {
return false
}
err := Db.Dbpool.Ping(Db.Ctx)
return err == nil
}