Initial release
This commit is contained in:
33
database/database.go
Normal file
33
database/database.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var globDatabase *Database
|
||||
|
||||
type Database struct {
|
||||
gormDB *gorm.DB
|
||||
}
|
||||
|
||||
func newDatabaseConnection(dialector gorm.Dialector) (*Database, error) {
|
||||
db, err := gorm.Open(dialector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Database{db}, nil
|
||||
}
|
||||
|
||||
func NewSqlite3Connection(databaseFile string) (*Database, error) {
|
||||
return newDatabaseConnection(sqlite.Open(databaseFile))
|
||||
}
|
||||
|
||||
func GetDB() *Database {
|
||||
return globDatabase
|
||||
}
|
||||
|
||||
func SetGlobDB(database *Database) {
|
||||
globDatabase = database
|
||||
}
|
||||
Reference in New Issue
Block a user