package util

import (
	"log"
	"os"

	"github.com/go-redis/redis"
	"github.com/jmoiron/sqlx"
)

func GetDBConnection() (*sqlx.DB, error) {
	//os.Setenv("DB_CONFIG", "root:Innoknights@19@(109.106.255.67:3306)/bpmsdb")

	db, err := sqlx.Connect("mysql", os.Getenv("DB_CONFIG"))
	//log.Println(db.Ma)
	log.Println("BPMS: GeneralUtility: GetDBConnection: Established DB connection")
	if err != nil {
		return nil, err
	} else {
		return db, nil
	}
}

func GetRedisConnection() *redis.Client {
	redisDb := redis.NewClient(&redis.Options{
		Addr:     "185.201.9.20:6379",
		Password: "",
		DB:       0})
	log.Println("BPMS: GeneralUtility: GetRedisConnection: Established redis connection")
	return redisDb
}
