node-api/common/db.go

28 lines
451 B
Go
Raw Normal View History

2020-07-08 22:09:19 +00:00
package common
import (
"log"
"github.com/jinzhu/gorm"
// This is line from GORM documentation that imports database dialect
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
var db *gorm.DB
func init() {
var err error
2021-04-25 22:57:05 +00:00
config := GetConfig()
db, err = gorm.Open("sqlite3", config.DatabasePath)
2020-07-08 22:09:19 +00:00
if err != nil {
log.Fatalln(err)
}
}
// GetDBConnection returns opened connection to the database
func GetDBConnection() *gorm.DB {
return db
}