func TestFunctions(t *testing.T) { s := &schema.Schema{} err := json.Unmarshal([]byte(testdata.TestDataFull), s) s = s.Resolve(s) sts, err := (&Generator{}).Generate(common.NewContext(), s) common.TestEquals(t, nil, err) for i, s := range sts { common.TestEquals(t, expecteds[i], string(s.Content)) } }
func TestClients(t *testing.T) { s := &schema.Schema{} if err := json.Unmarshal([]byte(testdata.JSON1), s); err != nil { t.Fatal(err.Error()) } s = s.Resolve(s) sts, err := (&Generator{}).Generate(common.NewContext(), s) common.TestEquals(t, nil, err) for i, s := range sts { common.TestEquals(t, expecteds[i], string(s.Content)) } }
func TestStatements(t *testing.T) { s := &schema.Schema{} if err := json.Unmarshal([]byte(testdata.TestDataFull), s); err != nil { t.Fatal(err.Error()) } s = s.Resolve(s) sts, err := (&Generator{}).Generate(common.NewContext(), s) equals(t, nil, err) for _, s := range sts { if strings.HasSuffix(s.Path, "profile_statements.go") { equals(t, expected, string(s.Content)) } } }
func main() { conf := &Config{} loader := multiconfig.MultiLoader( &multiconfig.TagLoader{}, // assign default values &multiconfig.FlagLoader{}, // read flag params &multiconfig.EnvironmentLoader{}, ) if err := loader.Load(conf); err != nil { log.Fatalf("config read err: %s", err.Error()) } if err := (&multiconfig.RequiredValidator{}).Validate(conf); err != nil { log.Fatalf("validation err: %s", err.Error()) } c := common.NewContext() c.Config.Schema = conf.Schema c.Config.Target = conf.Target s, err := common.Read(c.Config.Schema) if err != nil { log.Fatalf("schema read err: %s", err.Error()) } s = s.Resolve(s) req := &common.Req{ Schema: s, Context: c, } res := &common.Res{} err = conf.DDL.Generate(req, res) if err != nil { log.Fatal("geneddl err: %s", err.Error()) } if err := common.WriteOutput(res.Output); err != nil { log.Fatal("output write err: %s", err.Error()) } log.Println("module created with success") }
func main() { conf := &Config{} loader := multiconfig.MultiLoader( &multiconfig.TagLoader{}, // assign default values &multiconfig.FlagLoader{}, // read flag params &multiconfig.EnvironmentLoader{}, ) if err := loader.Load(conf); err != nil { log.Fatalf("config read err: %s", err.Error()) } if err := (&multiconfig.RequiredValidator{}).Validate(conf); err != nil { log.Fatalf("validation err: %s", err.Error()) } c := common.NewContext() c.Config.Schema = conf.Schema c.Config.Target = conf.Target s, err := common.Read(conf.Schema) if err != nil { log.Fatalf("schema read err: %s", err.Error()) } output, err := conf.Struct.Generate(c, s) if err != nil { log.Fatal("genestruct err: %s", err.Error()) } if err := common.WriteOutput(output); err != nil { log.Fatal("output write err: %s", err.Error()) } log.Println("module created with success") }
func main() { conf := &Config{} loader := multiconfig.MultiLoader( &multiconfig.TagLoader{}, // assign default values &multiconfig.FlagLoader{}, // read flag params ) if err := loader.Load(conf); err != nil { log.Fatalf("config read err:", err.Error()) } if err := (&multiconfig.RequiredValidator{}).Validate(conf); err != nil { log.Fatalf("validation err: %s", err.Error()) } c := common.NewContext() c.Config.Schema = conf.Schema c.Config.Target = conf.Target c.FieldNameFunc = geneddl.GetFieldNameFunc(conf.DDL.FieldNameCase) s, err := common.Read(c.Config.Schema) if err != nil { log.Fatalf("schema read err: %s", err.Error()) } s.Resolve(s) // // generate sql definitions // c.Config.Target = conf.Target + "db" + "/" output, err := conf.DDL.Generate(c, s) if err != nil { log.Fatal("geneddl err: %s", err.Error()) } if err := common.WriteOutput(output); err != nil { log.Fatal("output write err: %s", err.Error()) } // // generate models // c.Config.Target = conf.Target + "models" + "/" output, err = conf.Models.Generate(c, s) if err != nil { log.Fatalf("err while generating models", err.Error()) } if err := common.WriteOutput(output); err != nil { log.Fatal("output write err: %s", err.Error()) } // // generate rowsscanner // c.Config.Target = conf.Target + "models" + "/" output, err = conf.Rows.Generate(c, s) if err != nil { log.Fatalf("err while generating rows", err.Error()) } if err := common.WriteOutput(output); err != nil { log.Fatal("output write err: %s", err.Error()) } // // generate crud statements // c.Config.Target = conf.Target + "models" + "/" output, err = conf.Statements.Generate(c, s) if err != nil { log.Fatalf("err while generating crud statements", err.Error()) } if err := common.WriteOutput(output); err != nil { log.Fatal("output write err: %s", err.Error()) } // // generate errors // c.Config.Target = conf.Target + "errors" + "/" output, err = conf.Errors.Generate(c, s) if err != nil { log.Fatalf("err while generating errors", err.Error()) } if err := common.WriteOutput(output); err != nil { log.Fatal("output write err: %s", err.Error()) } // // generate main file // c.Config.Target = conf.Target + "cmd" + "/" output, err = conf.Mainfile.Generate(c, s) if err != nil { log.Fatalf("err while generating main file", err.Error()) } if err := common.WriteOutput(output); err != nil { log.Fatal("output write err: %s", err.Error()) } // // generate clients // c.Config.Target = conf.Target + "workers" + "/" output, err = conf.Clients.Generate(c, s) if err != nil { log.Fatalf("err while generating clients", err.Error()) } if err := common.WriteOutput(output); err != nil { log.Fatal("output write err: %s", err.Error()) } // // generate exported functions // c.Config.Target = conf.Target + "workers" + "/" output, err = conf.Functions.Generate(c, s) if err != nil { log.Fatalf("err while generating clients", err.Error()) } if err := common.WriteOutput(output); err != nil { log.Fatal("output write err: %s", err.Error()) } log.Println("module created with success") }