node-api/common/db.go

26 lines
436 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
db, err = gorm.Open("sqlite3", "/var/lib/node-api/rosti.db")
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
}