From 8b46386fa09b4793b2cecbb1fa04de59ec92d1a1 Mon Sep 17 00:00:00 2001 From: wsfuyibing Date: Wed, 21 Aug 2024 19:21:24 +0800 Subject: [PATCH] debug: do not add column package for service --- db/commands/common.go | 9 +++++---- db/commands/gen_model/provider.go | 2 +- db/commands/gen_service/provider.go | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/db/commands/common.go b/db/commands/common.go index 4cc6e28..6cab639 100644 --- a/db/commands/common.go +++ b/db/commands/common.go @@ -65,7 +65,7 @@ func (o *Common) BuildScript(command *console.Command) string { // ListTable // returns a list for tables in a database. -func (o *Common) ListTable(ctx context.Context, command *console.Command) (tables []*base.Table, err error) { +func (o *Common) ListTable(ctx context.Context, command *console.Command, addColumnPkg bool) (tables []*base.Table, err error) { var ( all bool list []*base.Table @@ -126,7 +126,7 @@ func (o *Common) ListTable(ctx context.Context, command *console.Command) (table // table fields. o.FormatTable(command, table) for _, column := range table.Columns { - o.FormatColumn(command, table, column) + o.FormatColumn(command, table, column, addColumnPkg) // Bind primary on table. if column.IsPrimaryKey { @@ -317,7 +317,7 @@ func (o *Common) RegisterDatabase() error { }) } -func (o *Common) FormatColumn(command *console.Command, table *base.Table, column *base.Column) { +func (o *Common) FormatColumn(command *console.Command, table *base.Table, column *base.Column, addColumnPkg bool) { // Bind relation of a table. column.Table = table @@ -346,7 +346,7 @@ func (o *Common) FormatColumn(command *console.Command, table *base.Table, colum column.ExportType = convert.Type // Append package. - if column.ExportPkg != "" { + if addColumnPkg && column.ExportPkg != "" { table.Add(column.ExportPkg) } } @@ -387,4 +387,5 @@ func (o *Common) FormatTableAsService(table *base.Table) { table.Add(`context`) table.Add(`gitee.com/go-libs/db-xorm/db`) + table.Add(fmt.Sprintf(`%s%s/%s`, o.ModuleName, o.ModuleFolder, o.ModelPath)) } diff --git a/db/commands/gen_model/provider.go b/db/commands/gen_model/provider.go index e9e9072..52e8c79 100644 --- a/db/commands/gen_model/provider.go +++ b/db/commands/gen_model/provider.go @@ -70,7 +70,7 @@ func (o *Provider) Run(ctx context.Context, container *console.Container, comman // Return error // if tables list failed. - if tables, err = o.common.ListTable(ctx, command); err != nil { + if tables, err = o.common.ListTable(ctx, command, true); err != nil { return } diff --git a/db/commands/gen_service/provider.go b/db/commands/gen_service/provider.go index 6226681..d848773 100644 --- a/db/commands/gen_service/provider.go +++ b/db/commands/gen_service/provider.go @@ -71,7 +71,7 @@ func (o *Provider) Run(ctx context.Context, container *console.Container, comman // Return error // if tables list failed. - if tables, err = o.common.ListTable(ctx, command); err != nil { + if tables, err = o.common.ListTable(ctx, command, false); err != nil { return } -- Gitee