node-api/common/db.go
2020-07-09 00:09:19 +02:00

26 lines
418 B
Go

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", "rosti.db")
if err != nil {
log.Fatalln(err)
}
}
// GetDBConnection returns opened connection to the database
func GetDBConnection() *gorm.DB {
return db
}