busybar / pkg / database / database.go
database.go
Raw
package database

import (
	"context"
	"log"

	"github.com/danielrhuynh/busybar/pkg/config"

	"github.com/Masterminds/squirrel"
	"github.com/jackc/pgx/v5/pgxpool"
)

var DB *pgxpool.Pool
var PSQL squirrel.StatementBuilderType

func init() {
	var err error
	DB, err = pgxpool.New(context.Background(), config.Config.DatabaseURL)
	if err != nil {
		log.Fatalf("Error connecting to database: %v", err)
	}

	PSQL = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)
}