feat(gdb): Allow to set table field metadata and allow to generate table fields registration code when generating dao#4460
Merged
hailaz merged 7 commits intogogf:masterfrom Oct 15, 2025
Conversation
- 添加 TablePath 和 TplDaoTablePath 配置选项- 新增 GenTable 命令行参数控制是否生成表文件 - 实现 generateTable 函数用于生成表结构代码 - 扩展模板变量支持 TplTableFields - 更新单元测试以包含新的配置选项 - 在 Core 中增加 SetTableFields 方法用于设置表字段缓存
- 在生成 DAO 文件时,使用 strconv.Quote 替代手动拼接字符串- 确保字段名、类型、键、额外信息和注释正确转义- 提高代码可读性和安全性,避免潜在的语法错误
…tTableFields,和ClearTableFields保持一样的使用方式
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to the GoFrame CLI tool to generate table field metadata definitions and allow setting table field metadata in the database core. This enables pre-caching of table structure information to improve compatibility with MySQL-compatible databases and provide performance benefits.
Key changes:
- Added
SetTableFieldsmethod to database core for setting table field metadata - Added new table generation functionality to the DAO generator with configurable options
- Created template for generating table field definition files with registration functions
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| database/gdb/gdb_core.go | Adds SetTableFields method for caching table field metadata |
| cmd/gf/internal/consts/consts_gen_dao_template_table.go | Defines template for generating table field definition files |
| cmd/gf/internal/cmd/gendao/gendao_tag.go | Adds configuration constants for table generation feature |
| cmd/gf/internal/cmd/gendao/gendao_table.go | Implements table generation logic and field definition formatting |
| cmd/gf/internal/cmd/gendao/gendao.go | Integrates table generation into main DAO generation flow |
| cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go | Updates test cases to include new GenTable configuration |
| cmd/gf/internal/cmd/cmd_z_unit_gen_dao_issue_test.go | Updates additional test cases for GenTable configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- 将字段排序注释从中文"升序"改为英文"asc"- 移除模板文件中未使用的"g"包导入- 统一代码风格以提高可读性
hailaz
approved these changes
Oct 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gdb在第一次查询时会拉取一次table的fields meta信息,为后续orm的字段过滤和时间特性服务,gen dao时已经获得了table的所有fields meta,提供一个生成table的功能,允许客户自行决定是否生成,是否注入已知表结构缓存到指定db实例。mysql的二开数据库在获取fields meta时无法和mysql保持一致的问题。gdb.ToSQL()方法。生成的示例目录

生成的示例代码