gormmom is the native language programming engine that breaks down language barriers in database development. As the smart tag generation engine of the GORM ecosystem, it empowers teams worldwide to write database models in native languages while automatically generating database-compatible GORM tags and column names.
🎯 Language Liberation: Code in Chinese, Arabic, Japanese, and various languages - gormmom bridges the gap between human expression and database requirements.
// ❌ Common approach: Developers constrained to English naming
type User struct {
ID uint `gorm:"primaryKey"`
Username string `gorm:"column:username;uniqueIndex"`
Email string `gorm:"column:email;index"`
Age int `gorm:"column:age"`
PhoneNumber string `gorm:"column:phone_number"`
Address string `gorm:"column:address"`
Status string `gorm:"column:status;index"`
}
// ✅ GORMMOM: Program in native language!
type T用户 struct {
ID uint `gorm:"primaryKey"`
U用户名 string `gorm:"uniqueIndex"`
E邮箱 string `gorm:"index"`
A年龄 int `gorm:""`
D电话 string `gorm:""`
J住所 string `gorm:""`
S状态 string `gorm:"index"`
}
func (*T用户) TableName() string {
return "users" // Database-compatible table name
}
type T用戶 struct {
ID uint `gorm:"primaryKey"`
U用戶名 string `gorm:"uniqueIndex"`
E郵箱 string `gorm:"index"`
A年齡 int `gorm:""`
D電話 string `gorm:""`
J住所 string `gorm:""`
S狀態 string `gorm:"index"`
}
func (*T用戶) TableName() string {
return "users"
}
type Tユーザー struct {
ID uint `gorm:"primaryKey"`
Uユーザー名 string `gorm:"uniqueIndex"`
Eメール string `gorm:"index"`
A年齢 int `gorm:""`
D電話 string `gorm:""`
J住所 string `gorm:""`
Sステータス string `gorm:"index"`
}
func (*Tユーザー) TableName() string {
return "users"
}
type T사용자 struct {
ID uint `gorm:"primaryKey"`
U사용자명 string `gorm:"uniqueIndex"`
E이메일 string `gorm:"index"`
A나이 int `gorm:""`
J전화 string `gorm:""`
J주소 string `gorm:""`
S상태 string `gorm:"index"`
}
func (*T사용자) TableName() string {
return "users"
}
┌─────────────────────────────────────────────────────────────────────┐
│ GORM Type-Safe Ecosystem │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ gormzhcn │ │ gormmom │ │ gormrepo │ │
│ │ Chinese API │───▶│ Native Lang │───▶│ Package │─────┐ │
│ │ Localize │ │ Smart Tags │ │ Pattern │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ │ │ │ │
│ │ ▼ ▼ │
│ │ ┌─────────────┐ ┌─────────────┐ │
│ │ │ gormcngen │ │Application │ │
│ │ │Code Generate│─────────────▶│Custom Code │ │
│ │ │AST Operation│ │ │ │
│ │ └─────────────┘ └─────────────┘ │
│ │ │ ▲ │
│ │ ▼ │ │
│ └────────────▶┌─────────────┐◄─────────────────────┘ │
│ │ GORMCNM │ │
│ │ FOUNDATION │ │
│ │ Type-Safe │ │
│ │ Core Logic │ │
│ └─────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────┐ │
│ │ GORM │ │
│ │ Database │ │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
GORMMOM is the native language bridge that enables worldwide teams to participate in the type-safe GORM ecosystem.
go get github.com/yyle88/gormmom
- Unicode compatible: Chinese, Japanese, Korean, and other languages
- Smart mapping: Native names to database-safe column names
- Deterministic output: Consistent generation across runs
- Go export rules: Uppercase prefixes (e.g.,
U用户名
,Uユーザー名
)
- Auto GORM tags:
column
,index
,uniqueIndex
and more - Naming patterns:
snake_case
,camelCase
, custom formats - Index management: Descriptive names with auto-generation
- Tag preservation: Maintains existing tags while adding new ones
- Struct naming: Start with uppercase
type T用户
(Go export rules) - TableName() method: Required to avoid
regexp does not match
errors - Two-pass generation: First run updates tags, second run generates methods
// Configuration is done via Options in test file:
options := gormmom.NewOptions()
// Various configuration options available
// With gormcngen:
options := gormcngen.NewOptions().
WithColumnClassExportable(true). // Export T用户Columns
WithColumnsMethodRecvName("T"). // Method name
WithColumnsCheckFieldType(true) // Type checking
Gormmom works through test files to generate database tags and type-safe methods. See the examples directories with complete working examples.
Standard Approach | GORMMOM Approach |
---|---|
❌ Foreign language fields | ✅ Native language fields |
❌ Lost business context | ✅ Business semantics preserved |
❌ Translation overhead | ✅ Direct domain modeling |
❌ Context disconnect | ✅ Natural alignment |
❌ Team communication gaps | ✅ Unified understanding |
type T用户 struct {
ID uint `gorm:"primaryKey"`
U用户名 string `gorm:"uniqueIndex"`
E邮箱 string `gorm:"index"`
A年龄 int `gorm:""`
D电话 string `gorm:""`
J住所 string `gorm:""`
S状态 string `gorm:"index"`
}
func (*T用户) TableName() string {
return "users"
}
Create a test file to run the generation process. See examples directories with complete setup.
# Step 1: Generate GORM tags for native language fields
go test -v -run TestGen/GenGormMom
# Step 2: Generate type-safe column methods
go test -v -run TestGen/GenGormCnm
var user T用户
cls := user.Columns()
err := db.Where(cls.U用户名.Eq("张三")).First(&user).Error
// The struct now has database-compatible tags
// Use it with standard GORM operations
db.AutoMigrate(&T用户{})
// Create records
user := T用户{U用户名: "张三", E邮箱: "zhang@example.com", A年龄: 25, D电话: "13800138000", J住所: "北京市海淀区", S状态: "活跃"}
db.Create(&user)
// Operations with type-safe columns
var users []T用户
cls := (&T用户{}).Columns()
db.Where(cls.A年龄.Gt(18)).Find(&users)
MIT License. See LICENSE.
Contributions are welcome! Report bugs, suggest features, and contribute code:
- 🐛 Found a bug? Open an issue on GitHub with reproduction steps
- 💡 Have a feature idea? Create an issue to discuss the suggestion
- 📖 Documentation confusing? Report it so we can improve
- 🚀 Need new features? Share your use cases to help us understand requirements
- ⚡ Performance issue? Help us optimize by reporting slow operations
- 🔧 Configuration problem? Ask questions about complex setups
- 📢 Follow project progress? Watch the repo for new releases and features
- 🌟 Success stories? Share how this package improved your workflow
- 💬 General feedback? All suggestions and comments are welcome
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage interface).
- Clone: Clone the forked project (
git clone https://github.com/yourname/repo-name.git
). - Navigate: Navigate to the cloned project (
cd repo-name
) - Branch: Create a feature branch (
git checkout -b feature/xxx
). - Code: Implement your changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...
) and follow Go code style conventions - Documentation: Update documentation for user-facing changes and use meaningful commit messages
- Stage: Stage changes (
git add .
) - Commit: Commit changes (
git commit -m "Add feature xxx"
) ensuring backward compatible code - Push: Push to the branch (
git push origin feature/xxx
). - PR: Open a pull request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
Welcome to contribute to this project by submitting pull requests and reporting issues.
Project Support:
- ⭐ Give GitHub stars if this project helps you
- 🤝 Share with teammates and (golang) programming friends
- 📝 Write tech blogs about development tools and workflows - we provide content writing support
- 🌟 Join the ecosystem - committed to supporting open source and the (golang) development scene
Happy Coding with this package! 🎉