package storage

import (
	"database/sql"
	"os"

	"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/logger"
	_ "modernc.org/sqlite"
)

var path = os.Getenv("DB_PATH")

var params = "?_journal_mode=WAL&_busy_timeout=5000&_synchronous=NORMAL&_cache_size=2000&_foreign_keys=ON"

func CreateTables(db *sql.DB) error {
	logger := logger.New(false)
	_, err := db.Exec(Migrations)
	if err != nil {
		logger.Error(err.Error())
		return err
	}

	return nil
}

func OpenSession() (*sql.DB, error) {
	db, err := sql.Open("sqlite", path+params)
	if err != nil {
		return nil, err
	}
	return db, nil
}
