db_cmd

package
v0.0.0-...-cfca2e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenModel = &cobra.Command{
	Use:   "gen-model",
	Short: "A brief description of your command",
	Long:  `A longer description that spans multiple lines and likely contains examples`,
	Run: func(cmd *cobra.Command, args []string) {

		cfg, err := config.NewConfig()
		if err != nil {
			log.Fatalf("Config error: %s", err)
		}

		if viper.GetString("pg_addr") != "" {
			cfg.PG.URL = viper.GetString("pg_addr")
		}

		pwd, _ := os.Getwd()
		g := gen.NewGenerator(gen.Config{
			OutPath: pwd + "/internal/entity/query",
			Mode:    gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface,
		})

		gormdb, err := gorm.Open(postgres.Open(cfg.PG.URL))
		if err != nil {
			fmt.Errorf("gorm.Open err:%s", err.Error())
		}
		g.UseDB(gormdb)
		g.GenerateAllTable()

		g.Execute()

		fmt.Println("gen model success")
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL