github.com/sotirispl/buffalo@v0.11.1/generators/soda/soda.go (about) 1 package soda 2 3 import ( 4 "github.com/gobuffalo/makr" 5 sg "github.com/gobuffalo/pop/soda/cmd/generate" 6 ) 7 8 // Run the soda generator 9 func (sd Generator) Run(root string, data makr.Data) error { 10 g := makr.New() 11 defer g.Fmt(root) 12 13 should := func(data makr.Data) bool { 14 return sd.App.WithPop 15 } 16 17 f := makr.NewFile("models/models.go", nModels) 18 f.Should = should 19 g.Add(f) 20 21 f = makr.NewFile("models/models_test.go", nModelsTest) 22 f.Should = should 23 g.Add(f) 24 25 f = makr.NewFile("grifts/db.go", nSeedGrift) 26 f.Should = should 27 g.Add(f) 28 29 c := makr.NewCommand(makr.GoGet("github.com/gobuffalo/pop/...")) 30 c.Should = should 31 g.Add(c) 32 33 g.Add(&makr.Func{ 34 Should: should, 35 Runner: func(rootPath string, data makr.Data) error { 36 data["dialect"] = sd.Dialect 37 return sg.GenerateConfig("./database.yml", data) 38 }, 39 }) 40 41 return g.Run(root, data) 42 } 43 44 const nModels = `package models 45 46 import ( 47 "log" 48 49 "github.com/gobuffalo/envy" 50 "github.com/gobuffalo/pop" 51 ) 52 53 // DB is a connection to your database to be used 54 // throughout your application. 55 var DB *pop.Connection 56 57 func init() { 58 var err error 59 env := envy.Get("GO_ENV", "development") 60 DB, err = pop.Connect(env) 61 if err != nil { 62 log.Fatal(err) 63 } 64 pop.Debug = env == "development" 65 } 66 ` 67 68 const nModelsTest = `package models_test 69 70 import ( 71 "testing" 72 73 "github.com/gobuffalo/suite" 74 ) 75 76 type ModelSuite struct { 77 *suite.Model 78 } 79 80 func Test_ModelSuite(t *testing.T) { 81 as := &ModelSuite{suite.NewModel()} 82 suite.Run(t, as) 83 }` 84 85 const nSeedGrift = `package grifts 86 87 import ( 88 "github.com/markbates/grift/grift" 89 ) 90 91 var _ = grift.Namespace("db", func() { 92 93 grift.Desc("seed", "Seeds a database") 94 grift.Add("seed", func(c *grift.Context) error { 95 // Add DB seeding stuff here 96 return nil 97 }) 98 99 })`