31 строка
450 B
Go
31 строка
450 B
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/fatih/structs"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func init() {
|
|
structs.DefaultTagName = "json"
|
|
}
|
|
|
|
// db Gorm DB
|
|
var db *gorm.DB
|
|
|
|
// DB provides functionality.
|
|
func DB() *gorm.DB {
|
|
return db.WithContext(context.TODO())
|
|
}
|
|
|
|
// SetDB provides functionality.
|
|
func SetDB(newDb *gorm.DB) {
|
|
db = newDb
|
|
}
|
|
|
|
// IsDBAvailable returns true if the database has been initialized
|
|
func IsDBAvailable() bool {
|
|
return db != nil
|
|
}
|