From 4b1c9347511e6c8f305f5baf346c5063cff6609d Mon Sep 17 00:00:00 2001 From: Patrick O'brien Date: Fri, 2 Sep 2016 11:22:56 +1000 Subject: [PATCH] Remove pointers to L, not needed * Add no-tests flag --- config.go | 1 + main.go | 2 ++ sqlboiler.go | 28 +++++++++++---------- templates/00_struct.tpl | 2 +- templates/06_relationship_to_one_eager.tpl | 2 +- templates/07_relationship_to_many_eager.tpl | 2 +- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/config.go b/config.go index 5463754..cefe7ed 100644 --- a/config.go +++ b/config.go @@ -7,6 +7,7 @@ type Config struct { OutFolder string BaseDir string ExcludeTables []string + NoTests bool NoHooks bool NoAutoTimestamps bool diff --git a/main.go b/main.go index d7497ab..d44d3dc 100644 --- a/main.go +++ b/main.go @@ -65,6 +65,7 @@ func main() { rootCmd.PersistentFlags().StringP("basedir", "b", "", "The base directory has the templates and templates_test folders") rootCmd.PersistentFlags().StringSliceP("exclude", "x", nil, "Tables to be excluded from the generated package") rootCmd.PersistentFlags().BoolP("debug", "d", false, "Debug mode prints stack traces on error") + rootCmd.PersistentFlags().BoolP("no-tests", "", false, "Disable generated go test files") rootCmd.PersistentFlags().BoolP("no-hooks", "", false, "Disable hooks feature for your models") rootCmd.PersistentFlags().BoolP("no-auto-timestamps", "", false, "Disable automatic timestamps for created_at/updated_at") @@ -106,6 +107,7 @@ func preRun(cmd *cobra.Command, args []string) error { DriverName: driverName, OutFolder: viper.GetString("output"), PkgName: viper.GetString("pkgname"), + NoTests: viper.GetBool("no-tests"), NoHooks: viper.GetBool("no-hooks"), NoAutoTimestamps: viper.GetBool("no-auto-timestamps"), } diff --git a/sqlboiler.go b/sqlboiler.go index 4d17322..0a3e5a7 100644 --- a/sqlboiler.go +++ b/sqlboiler.go @@ -91,7 +91,7 @@ func (s *State) Run(includeTests bool) error { return errors.Wrap(err, "singleton template output") } - if includeTests { + if !s.Config.NoTests && includeTests { if err := generateTestMainOutput(s, singletonData); err != nil { return errors.Wrap(err, "unable to generate TestMain output") } @@ -124,7 +124,7 @@ func (s *State) Run(includeTests bool) error { } // Generate the test templates - if includeTests { + if !s.Config.NoTests && includeTests { if err := generateTestOutput(s, data); err != nil { return errors.Wrap(err, "unable to generate test output") } @@ -159,19 +159,21 @@ func (s *State) initTemplates() error { return err } - s.TestTemplates, err = loadTemplates(filepath.Join(basePath, templatesTestDirectory)) - if err != nil { - return err - } + if !s.Config.NoTests { + s.TestTemplates, err = loadTemplates(filepath.Join(basePath, templatesTestDirectory)) + if err != nil { + return err + } - s.SingletonTestTemplates, err = loadTemplates(filepath.Join(basePath, templatesSingletonTestDirectory)) - if err != nil { - return err - } + s.SingletonTestTemplates, err = loadTemplates(filepath.Join(basePath, templatesSingletonTestDirectory)) + if err != nil { + return err + } - s.TestMainTemplate, err = loadTemplate(filepath.Join(basePath, templatesTestMainDirectory), s.Config.DriverName+"_main.tpl") - if err != nil { - return err + s.TestMainTemplate, err = loadTemplate(filepath.Join(basePath, templatesTestMainDirectory), s.Config.DriverName+"_main.tpl") + if err != nil { + return err + } } return nil diff --git a/templates/00_struct.tpl b/templates/00_struct.tpl index 3d73ac5..756930a 100644 --- a/templates/00_struct.tpl +++ b/templates/00_struct.tpl @@ -13,7 +13,7 @@ type {{$modelName}} struct { {{- if .Table.IsJoinTable -}} {{- else}} R *{{$modelNameCamel}}R `boil:"-" json:"-" toml:"-" yaml:"-"` - L *{{$modelNameCamel}}L `boil:"-" json:"-" toml:"-" yaml:"-"` + L {{$modelNameCamel}}L `boil:"-" json:"-" toml:"-" yaml:"-"` {{end -}} } diff --git a/templates/06_relationship_to_one_eager.tpl b/templates/06_relationship_to_one_eager.tpl index 5be2021..016eaf6 100644 --- a/templates/06_relationship_to_one_eager.tpl +++ b/templates/06_relationship_to_one_eager.tpl @@ -6,7 +6,7 @@ {{- $slice := printf "%sSlice" .LocalTable.NameGo -}} // Load{{.Function.Name}} allows an eager lookup of values, cached into the // loaded structs of the objects. -func (t *{{$varNameSingular}}L) Load{{.Function.Name}}(e boil.Executor, singular bool, {{$arg}} interface{}) error { +func ({{$varNameSingular}}L) Load{{.Function.Name}}(e boil.Executor, singular bool, {{$arg}} interface{}) error { var slice []*{{.LocalTable.NameGo}} var object *{{.LocalTable.NameGo}} diff --git a/templates/07_relationship_to_many_eager.tpl b/templates/07_relationship_to_many_eager.tpl index aa054d2..f544382 100644 --- a/templates/07_relationship_to_many_eager.tpl +++ b/templates/07_relationship_to_many_eager.tpl @@ -12,7 +12,7 @@ {{- $slice := printf "%sSlice" $txt.LocalTable.NameGo -}} // Load{{$txt.Function.Name}} allows an eager lookup of values, cached into the // loaded structs of the objects. -func (t *{{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singular bool, {{$arg}} interface{}) error { +func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singular bool, {{$arg}} interface{}) error { var slice []*{{$txt.LocalTable.NameGo}} var object *{{$txt.LocalTable.NameGo}}