Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add db_service flag #189

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading