Source File
connection.go
Belonging Package
github.com/limanmys/render-engine/internal/database
package database
import (
)
var once sync.Once
var connection *gorm.DB
// Connection creates singleton pattern to connect to database only once and keep it in memory
func () *gorm.DB {
once.Do(func() {
connection = initialize()
})
return connection
}
// initialize Initializes database connection
func initialize() *gorm.DB {
switch helpers.Env("DB_CONNECTION", "pgsql") {
case "pgsql":
return initializePostgres()
case "mysql":
return initializeMysql()
default:
logger.Sugar().Fatalln("You must specify a database driver. Choices are 'postgres' or 'mysql'")
return nil
}
}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |