forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
soda_generators.go
64 lines (51 loc) · 1.19 KB
/
soda_generators.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cmd
import (
"github.com/markbates/gentronics"
"github.com/markbates/pop/soda/cmd/generate"
)
func newSodaGenerator() *gentronics.Generator {
g := gentronics.New()
should := func(data gentronics.Data) bool {
if _, ok := data["withPop"]; ok {
return ok
}
return false
}
f := gentronics.NewFile("models/models.go", nModels)
f.Should = should
g.Add(f)
c := gentronics.NewCommand(goGet("github.com/markbates/pop/..."))
c.Should = should
g.Add(c)
c = gentronics.NewCommand(goInstall("github.com/markbates/pop/soda"))
c.Should = should
g.Add(c)
g.Add(&gentronics.Func{
Should: should,
Runner: func(rootPath string, data gentronics.Data) error {
data["dialect"] = data["dbType"]
return generate.GenerateConfig("./database.yml", data)
},
})
return g
}
const nModels = `package models
import (
"log"
"os"
"github.com/markbates/going/defaults"
"github.com/markbates/pop"
)
// DB is a connection to your database to be used
// throughout your application.
var DB *pop.Connection
func init() {
var err error
env := defaults.String(os.Getenv("GO_ENV"), "development")
DB, err = pop.Connect(env)
if err != nil {
log.Fatal(err)
}
pop.Debug = env == "development"
}
`