package service

import (
	"git.markbailey.dev/cervers/ptpp/lib/database"
	"sync"
)

var (
	db    interface{}
	dlock = &sync.Mutex{}
)

type SDB struct{}

func NewSDB() *SDB {
	return &SDB{}
}

func (s *SDB) Name() string {
	return "db"
}

func (s *SDB) Use() interface{} {
	if db == nil {
		dlock.Lock()
		defer dlock.Unlock()

		db = database.ChooseDB()
	}

	return db
}
