github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/buffalo/model/templates/models.go.tmpl (about)

     1  package models
     2  
     3  import (
     4  	"bytes"
     5  	"log"
     6  	base "{{.}}"
     7  	
     8  	"github.com/gobuffalo/envy"
     9  	"github.com/gobuffalo/pop/v5"
    10  )
    11  
    12  // Loading connections from database.yml in the pop.Connections
    13  // variable for later usage.
    14  func init() {
    15  	bf, err := base.Config.Find("database.yml")
    16  	if err != nil {
    17  		log.Fatal(err)
    18  	}
    19  
    20  	err = pop.LoadFrom(bytes.NewReader(bf))
    21  	if err != nil {
    22  		log.Fatal(err)
    23  	}
    24  }
    25  
    26  // DB returns the DB connection for the current environment.
    27  func DB() *pop.Connection {
    28  	c, err := pop.Connect(envy.Get("GO_ENV", "development"))
    29  	if err != nil {
    30  		log.Fatal(err)
    31  	}
    32  
    33  	return c
    34  }