package database

import (
	"tg-mc/conf"

	"github.com/glebarez/sqlite"
	"github.com/joho/godotenv"
	"github.com/sirupsen/logrus"
	"gorm.io/gorm"
)

func initSqlite() {
	var err error
	godotenv.Load()

	dbPath := conf.GetBotSettings().DBPath
	db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
	if err != nil {
		logrus.Panic(err, "Initializing DB Error")
	}
	CloseDB(db)
}

func GetSqlite() *gorm.DB {
	dbPath := conf.GetBotSettings().DBPath
	db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
	if err != nil {
		return nil
	}
	return db
}
