Skip to content

yyle88/gormmom

Repository files navigation

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

gormmom

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.


CHINESE README

中文说明


Features

  • 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.

Installation

go get github.com/yyle88/gormmom

Usage Example

Original Code (Native Language Programming)

type Example struct {
    V证号 string `gorm:"primaryKey"`
    V姓名 string `gorm:"index"`
    V年龄 int    `gorm:"unique"`
    V性别 bool   `gorm:"column:sex;uniqueIndex" mom:"mcp:S63"`
}

Generated Code (Automatic GORM Tag Generation)

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;"`
}

Gorm Select Usage(Select with gorm repo)

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))
})

Configuration Options

  • 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.

Design Ideas

README OLD DOC


License

MIT License. See LICENSE.


Contributing

Contributions are welcome! To contribute:

  1. Fork the repo on GitHub (using the webpage interface).
  2. Clone the forked project (git clone https://github.com/yourname/repo-name.git).
  3. Navigate to the cloned project (cd repo-name)
  4. Create a feature branch (git checkout -b feature/xxx).
  5. Stage changes (git add .)
  6. Commit changes (git commit -m "Add feature xxx").
  7. Push to the branch (git push origin feature/xxx).
  8. Open a pull request on GitHub (on the GitHub webpage).

Please ensure tests pass and include relevant documentation updates.


Support

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!!!

GitHub Stars

starring

About

Empowering Native Language Programming, Simplifying GORM Tag Generation

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published