Empowering Native Language Programming, Simplifying GORM Tag Generation
gormmom
is a tool designed to automatically generate GORM tags, aimed at helping developers program in their native language while simplifying the process of defining GORM tags. The tool processes struct fields and automatically generates GORM-compliant tags, ensuring field names follow specific naming conventions.
- Automatic GORM Tag Generation: Automatically generates GORM tags for struct fields, such as
column
,index
,unique
, etc. - Native Language Programming Support: Allows developers to define struct fields in their native language (e.g., Chinese), reducing the difficulty of understanding business.
go get github.com/yyle88/gormmom
type Example struct {
V证号 string `gorm:"primaryKey"`
V姓名 string `gorm:"index"`
V年龄 int `gorm:"unique"`
V性别 bool `gorm:"column:sex;uniqueIndex" mom:"mcp:S63"`
}
type Example struct {
V证号 string `gorm:"column:v_c18b_f753;primaryKey" mom:"mcp:s63;"`
V姓名 string `gorm:"column:v_d359_0d54;index:idx_example_v_d359_0d54" mom:"mcp:s63;idx:cnm;"`
V年龄 int `gorm:"column:v_745e_849f;unique" mom:"mcp:s63;"`
V性别 bool `gorm:"column:V_2760_2B52;uniqueIndex:udx_example_V_2760_2B52" mom:"mcp:S63;udx:cnm;"`
}
example, err := repo.Repo(caseDB).First(func(db *gorm.DB, cls *exampleColumns) *gorm.DB {
return db.Where(cls.V名称.Eq(name))
})
results, err := repo.Repo(caseDB).Find(func(db *gorm.DB, cls *exampleColumns) *gorm.DB {
return db.Where(cls.V名称.In(names))
})
- mcp: Configures the naming convention for database column names.
- idx: Configures the naming convention for single-column indexes.
- udx: Configures the naming convention for single-column unique indexes.
MIT License. See LICENSE.
Contributions are welcome! To contribute:
- Fork the repo on GitHub (using the webpage interface).
- Clone the forked project (
git clone https://github.com/yourname/repo-name.git
). - Navigate to the cloned project (
cd repo-name
) - Create a feature branch (
git checkout -b feature/xxx
). - Stage changes (
git add .
) - Commit changes (
git commit -m "Add feature xxx"
). - Push to the branch (
git push origin feature/xxx
). - Open a pull request on GitHub (on the GitHub webpage).
Please ensure tests pass and include relevant documentation updates.
Welcome to contribute to this project by submitting pull requests and reporting issues.
If you find this package valuable, give me some stars on GitHub! Thank you!!!
Thank you for your support!
Happy Coding with gormmom
! 🎉
Give me stars. Thank you!!!