This repository has been archived by the owner on Aug 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
87 lines (77 loc) · 2.33 KB
/
models.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"go/build"
"log"
"os"
"strings"
"github.com/volatiletech/sqlboiler/importers"
"github.com/spf13/cobra"
"github.com/volatiletech/sqlboiler/boilingcore"
"github.com/volatiletech/sqlboiler/drivers"
_ "github.com/volatiletech/sqlboiler/queries/qm"
)
var (
flagConfigFile string
cmdState *boilingcore.State
cmdConfig *boilingcore.Config
)
var modelsCmd = &cobra.Command{
Use: "models",
Short: "sqlboiler",
Run: func(cmd *cobra.Command, args []string) {
gopath := os.Getenv("GOPATH")
if gopath == "" {
gopath = build.Default.GOPATH
}
driverName := "psql"
driverPath := fmt.Sprintf("%s/bin/sqlboiler-%s", gopath, driverName)
drivers.RegisterBinary(driverName, driverPath)
cmdConfig = &boilingcore.Config{
DriverName: driverName,
OutFolder: "api/db/models",
PkgName: "models",
//Debug: true,
AddGlobal: true,
//AddPanic: viper.GetBool("add-panic-variants"),
NoContext: true,
NoTests: true,
//NoHooks: viper.GetBool("no-hooks"),
//NoRowsAffected: viper.GetBool("no-rows-affected"),
//NoAutoTimestamps: viper.GetBool("no-auto-timestamps"),
//Wipe: viper.GetBool("wipe"),
//StructTagCasing: strings.ToLower(viper.GetString("struct-tag-casing")), // camel | snake
//TemplateDirs: viper.GetStringSlice("templates"),
//Tags: viper.GetStringSlice("tag"),
//Replacements: viper.GetStringSlice("replace"),
//Aliases: boilingcore.ConvertAliases(viper.Get("aliases")),
//TypeReplaces: boilingcore.ConvertTypeReplace(viper.Get("types")),
}
if cmdConfig.Debug {
fmt.Fprintln(os.Stderr, "using driver:", driverPath)
}
// Configure the driver
cmdConfig.DriverConfig = map[string]interface{}{
"host": "localhost",
"whitelist": []string{"users", "user_providers"},
//"blacklist": viper.GetStringSlice(driverName + ".blacklist"),
}
sdbSource := strings.Split(source, " ")
for _, value := range sdbSource {
svalue := strings.Split(value, "=")
if svalue[0] == "password" {
svalue[0] = "pass"
}
cmdConfig.DriverConfig[svalue[0]] = svalue[1]
}
cmdConfig.Imports = importers.NewDefaultImports()
cmdState, err := boilingcore.New(cmdConfig)
if err != nil {
log.Fatal(err)
}
err = cmdState.Run()
if err != nil {
log.Fatal(err)
}
},
}