MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / DBWithoutMigration

Method DBWithoutMigration

api/pkg/di/container.go:310–332  ·  view source on GitHub ↗

DBWithoutMigration creates an instance of gorm.DB if it has not been created already

()

Source from the content-addressed store, hash-verified

308
309// DBWithoutMigration creates an instance of gorm.DB if it has not been created already
310func (container *Container) DBWithoutMigration() (db *gorm.DB) {
311 if container.db != nil {
312 return container.db
313 }
314
315 container.logger.Debug(fmt.Sprintf("creating %T", db))
316
317 config := &gorm.Config{
318 TranslateError: true,
319 Logger: container.GormLogger(),
320 }
321
322 db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL")), config)
323 if err != nil {
324 container.logger.Fatal(err)
325 }
326 container.db = db
327
328 if err = db.Use(tracing.NewPlugin()); err != nil {
329 container.logger.Fatal(stacktrace.Propagate(err, "cannot use GORM tracing plugin"))
330 }
331 return container.db
332}
333
334// DB creates an instance of gorm.DB if it has not been created already
335func (container *Container) DB() (db *gorm.DB) {

Callers

nothing calls this directly

Calls 3

GormLoggerMethod · 0.95
DebugMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected