Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ConfigCmd = &cobra.Command{ Use: "config", Short: "Generates a database.yml file for your project.", PersistentPreRun: func(c *cobra.Command, args []string) {}, RunE: func(cmd *cobra.Command, args []string) error { cflag := cmd.Flag("config") cflagVal := "" if cflag != nil { cflagVal = cflag.Value.String() } cfgFile := defaults.String(cflagVal, "database.yml") run := genny.WetRunner(context.Background()) pwd, _ := os.Getwd() g, err := config.New(&config.Options{ Root: pwd, Prefix: filepath.Base(pwd), FileName: cfgFile, Dialect: dialect, }) if err != nil { return err } run.With(g) return run.Run() }, }
ConfigCmd is the command to generate pop config files
View Source
var FizzCmd = &cobra.Command{ Use: "fizz [name]", Aliases: []string{"migration"}, Short: "Generates Up/Down migrations for your database using fizz.", RunE: func(cmd *cobra.Command, args []string) error { name := "" if len(args) > 0 { name = args[0] } var ( atts attrs.Attrs err error ) if len(args) > 1 { atts, err = attrs.ParseArgs(args[1:]...) if err != nil { return err } } run := genny.WetRunner(context.Background()) lg := logger.New(logger.DebugLevel) run.Logger = lg p := cmd.Flag("path") path := "" if p != nil { path = p.Value.String() } if len(atts) == 0 { g, err := cempty.New(&cempty.Options{ TableName: name, Path: path, Type: "fizz", }) if err != nil { return err } run.With(g) } else { g, err := ctable.New(&ctable.Options{ TableName: name, Path: path, Type: "fizz", Attrs: atts, }) if err != nil { return err } run.With(g) } return run.Run() }, }
FizzCmd generates a new fizz migration
View Source
var ModelCmd = &cobra.Command{ Use: "model [name]", Aliases: []string{"m"}, Short: "Generates a model for your database", RunE: func(cmd *cobra.Command, args []string) error { name := "" if len(args) > 0 { name = args[0] } var ( atts attrs.Attrs err error ) if len(args) > 1 { atts, err = attrs.ParseArgs(args[1:]...) if err != nil { return err } } run := genny.WetRunner(context.Background()) lg := logger.New(logger.DebugLevel) run.Logger = lg g, err := gmodel.New(&gmodel.Options{ Name: name, Attrs: atts, Path: modelCmdConfig.ModelPath, Encoding: modelCmdConfig.StructTag, ForceDefaultID: true, ForceDefaultTimestamps: true, }) if err != nil { return err } run.With(g) if !modelCmdConfig.SkipMigration { p := cmd.Flag("path") path := "" if p != nil { path = p.Value.String() } e := cmd.Flag("env") var translator fizz.Translator if modelCmdConfig.MigrationType == "sql" { db, err := pop.Connect(e.Value.String()) if err != nil { return err } translator = db.Dialect.FizzTranslator() } g, err = ctable.New(&ctable.Options{ TableName: name, Attrs: atts, Path: path, Type: modelCmdConfig.MigrationType, Translator: translator, ForceDefaultID: true, ForceDefaultTimestamps: true, }) if err != nil { return err } run.With(g) } return run.Run() }, }
ModelCmd is the cmd to generate a model
View Source
var SQLCmd = &cobra.Command{ Use: "sql [name]", Short: "Generates Up/Down migrations for your database using SQL.", RunE: func(cmd *cobra.Command, args []string) error { name := "" if len(args) > 0 { name = args[0] } var ( atts attrs.Attrs err error ) if len(args) > 1 { atts, err = attrs.ParseArgs(args[1:]...) if err != nil { return err } } run := genny.WetRunner(context.Background()) lg := logger.New(logger.DebugLevel) run.Logger = lg p := cmd.Flag("path") path := "" if p != nil { path = p.Value.String() } e := cmd.Flag("env") type nameable interface { Name() string } var translator nameable db, err := pop.Connect(e.Value.String()) if err != nil { return err } t := db.Dialect.FizzTranslator() if tn, ok := t.(nameable); ok { translator = tn } else { return errors.New("invalid fizz translator") } if len(atts) == 0 { g, err := cempty.New(&cempty.Options{ TableName: name, Path: path, Type: "sql", Translator: translator, }) if err != nil { return err } run.With(g) } else { g, err := ctable.New(&ctable.Options{ TableName: name, Path: path, Type: "sql", Attrs: atts, Translator: t, }) if err != nil { return err } run.With(g) } return run.Run() }, }
SQLCmd generates a SQL migration
Functions ¶
func Config ¶
Config generates pop configuration files. Deprecated: use github.com/gobuffalo/pop/genny/config instead.
func GenerateConfig
deprecated
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.