Skip to content

Commit

Permalink
add db_service flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wubin1989 committed Feb 7, 2024
1 parent 0d430da commit 69caa4c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var dbDsn string
var dbOrm string
var dbSoft string
var dbGrpc bool
var dbService bool
var dbTablePrefix string
var dbTableGlob string
var module bool
Expand Down Expand Up @@ -43,6 +44,7 @@ var initCmd = &cobra.Command{
Orm: dbOrm,
Soft: dbSoft,
Grpc: dbGrpc,
Service: dbService,
}
if stringutils.IsNotEmpty(dbConf.Driver) && stringutils.IsNotEmpty(dbConf.Dsn) {
options = append(options, svc.WithDbConfig(&dbConf))
Expand All @@ -69,6 +71,7 @@ func init() {
initCmd.Flags().StringVar(&dbDsn, "db_dsn", "", `Specify database connection url`)
initCmd.Flags().StringVar(&dbSoft, "db_soft", "deleted_at", `Specify database soft delete column name`)
initCmd.Flags().BoolVar(&dbGrpc, "db_grpc", false, `If true, grpc code will also be generated`)
initCmd.Flags().BoolVar(&dbService, "db_service", true, `If false, service will not be generated, and db_grpc will be ignored. Only dao layer code will be generated.`)
initCmd.Flags().StringVar(&dbTablePrefix, "db_table_prefix", "", `table prefix or schema name for pg`)
initCmd.Flags().StringVar(&dbTableGlob, "db_table_glob", "", `used to filter glob-matched tables`)
initCmd.Flags().StringVar(&naming, "case", "lowerCamel", `protobuf message field and json tag case, only support "lowerCamel" and "snake"`)
Expand Down
7 changes: 7 additions & 0 deletions cmd/internal/svc/codegen/database/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type IOrmGenerator interface {
fix()
Initialize(conf OrmGeneratorConfig)
GenService()
GenDao()
}

var _ IOrmGenerator = (*AbstractBaseGenerator)(nil)
Expand All @@ -74,6 +75,12 @@ type AbstractBaseGenerator struct {
ConfigPackage string
}

func (b *AbstractBaseGenerator) GenDao() {
b.dto()
b.orm()
b.goModTidy()
}

func (b *AbstractBaseGenerator) fix() {
b.impl.fix()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/internal/svc/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type DbConfig struct {
Orm string
Soft string
Grpc bool
Service bool
}

func (receiver *Svc) SetWatcher(w *watcher.Watcher) {
Expand Down Expand Up @@ -192,7 +193,11 @@ func (receiver *Svc) Init() {
Soft: receiver.DbConfig.Soft,
Grpc: receiver.DbConfig.Grpc,
})
gen.GenService()
if receiver.DbConfig.Service {
gen.GenService()
} else {
gen.GenDao()
}
} else if !receiver.module {
if stringutils.IsEmpty(receiver.DocPath) {
matches, _ := filepath.Glob(filepath.Join(receiver.dir, "*_openapi3.json"))
Expand Down

0 comments on commit 69caa4c

Please sign in to comment.