Describe the feature

比如业务写dao层的时候,经常函数传进来的是ctx和结构体参数 type A struct { A string filter:"col:a;opr:like" B string filter:"col:b;opr:eq" C int } 是不是可以根据结构体的tag标签定义数据库字段值和判断条件去实现 我看使用Scopes这个api可以实现 实现以后大概长这样 db.Model(&A{}).Scopes(func (db gorm.DB) gorm.DB{ scope := xxx() # 这里做一些逻辑 return db.Where(scope) })

Motivation

可以作为一个特性,方便curd happy

Related Issues

Comment From: Germiniku

The gorm Scopes implementation concatenates the where condition sql according to the tag of the passed struct Describe the feature For example, when a business writes the dao layer, ctx and structure parameters are often passed in by functions type A struct { A string filter:"col:a; opr:like" B string filter:"col:b; opr:eq" C int } Is it possible to define database field values and judgment conditions according to the tag tag of the structure to achieve I see Scopes this api can be achieved This is what it looks like when implemented db.Model(&A{}).Scopes(func (db gorm.DB) gorm.DB{ scope := xxx() # Do some logic here return db.Where(scope) })

Motivation Can be used as a feature to facilitate curd happy

Related Issues

Comment From: kuangshp

似乎要自己去自定义函数实现

Comment From: Germiniku

似乎要自己去自定义函数实现

是的 我实现了一部分 gf

Comment From: github-actions[bot]

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days