refactor(curd): 更新 GORM 预加载函数签名
- 将 ClearFieldPage 方法中的预加载函数参数从 func(db gorm.PreloadBuilder) error 更新为 func(db *gorm.DB) *gorm.DB - 将 ClearFieldList 方法中的预加载函数参数从 func(db gorm.PreloadBuilder) error 更新为 func(db *gorm.DB) *gorm.DB - 将 ClearFieldOne 方法中的预加载函数参数从 func(db gorm.PreloadBuilder) error 更新为 func(db *gorm.DB) *gorm.DB - 将 FindPri 方法中的预加载函数参数从 func(db gorm.PreloadBuilder) error 更新为 func(db *gorm.DB) *gorm.DB - 将 First 方法中的预加载函数参数从 func(db gorm.PreloadBuilder) error 更新为 func(db *gorm.DB) *gorm.DB - 将 All 方法中的预加载函数参数从 func(db gorm.PreloadBuilder) error 更新为 func(db *gorm.DB) *gorm.DB - 将 Paginate 方法中的预加载函数参数从 func(db gorm.PreloadBuilder) error 更新为 func(db *gorm.DB) *gorm.DB - 更新 .idea/GOHCache.xml 中文件修改时间戳main v1.0.1014
parent
1a33330214
commit
de8348e424
|
|
@ -242,7 +242,7 @@
|
|||
<entry key="file://$PROJECT_DIR$/crud/curd.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1772675013830" />
|
||||
<option name="lastModified" value="1772676907769" />
|
||||
<option name="schema">
|
||||
<list>
|
||||
<option value="Paginate" />
|
||||
|
|
|
|||
14
crud/curd.go
14
crud/curd.go
|
|
@ -212,7 +212,7 @@ func (c Crud[R]) ClearField(req any, delField []string, subField ...map[string]a
|
|||
}
|
||||
|
||||
// ClearFieldPage -------------------------- 原ClearFieldPage对应实现:清理参数+分页查询 --------------------------
|
||||
func (c Crud[R]) ClearFieldPage(ctx ctx, req any, delField []string, where any, page *Paginate, order any, with map[string]func(db gorm.PreloadBuilder) error) (items []*R, total int64, err error) {
|
||||
func (c Crud[R]) ClearFieldPage(ctx ctx, req any, delField []string, where any, page *Paginate, order any, with map[string]func(db *gorm.DB) *gorm.DB) (items []*R, total int64, err error) {
|
||||
// 1. 清理请求参数
|
||||
filterMap := c.ClearField(req, delField)
|
||||
|
||||
|
|
@ -253,7 +253,7 @@ func (c Crud[R]) ClearFieldPage(ctx ctx, req any, delField []string, where any,
|
|||
}
|
||||
|
||||
// ClearFieldList -------------------------- 原ClearFieldList对应实现:清理参数+列表查询(不分页) --------------------------
|
||||
func (c Crud[R]) ClearFieldList(ctx ctx, req any, delField []string, where any, order any, with map[string]func(db gorm.PreloadBuilder) error) (items []*R, err error) {
|
||||
func (c Crud[R]) ClearFieldList(ctx ctx, req any, delField []string, where any, order any, with map[string]func(db *gorm.DB) *gorm.DB) (items []*R, err error) {
|
||||
filterMap := c.ClearField(req, delField)
|
||||
db := c.Dao.Ctx(ctx).Model(new(R))
|
||||
|
||||
|
|
@ -274,7 +274,7 @@ func (c Crud[R]) ClearFieldList(ctx ctx, req any, delField []string, where any,
|
|||
}
|
||||
|
||||
// ClearFieldOne -------------------------- 原ClearFieldOne对应实现:清理参数+单条查询 --------------------------
|
||||
func (c Crud[R]) ClearFieldOne(ctx ctx, req any, delField []string, where any, order any, with map[string]func(db gorm.PreloadBuilder) error) (item *R, err error) {
|
||||
func (c Crud[R]) ClearFieldOne(ctx ctx, req any, delField []string, where any, order any, with map[string]func(db *gorm.DB) *gorm.DB) (item *R, err error) {
|
||||
item = new(R)
|
||||
filterMap := c.ClearField(req, delField)
|
||||
db := c.Dao.Ctx(ctx).Model(item)
|
||||
|
|
@ -378,7 +378,7 @@ func (c Crud[R]) ArrayField(ctx ctx, where any, field any) []interface{} {
|
|||
}
|
||||
|
||||
// FindPri -------------------------- 原FindPri对应实现:按主键查询单条记录 --------------------------
|
||||
func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with map[string]func(db gorm.PreloadBuilder) error) (model *R) {
|
||||
func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with map[string]func(db *gorm.DB) *gorm.DB) (model *R) {
|
||||
model = new(R)
|
||||
db := c.Dao.Ctx(ctx).Model(model)
|
||||
pk := c.Dao.PrimaryKey()
|
||||
|
|
@ -401,7 +401,7 @@ func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with map[string]func(db gorm.P
|
|||
}
|
||||
|
||||
// -------------------------- 原First对应实现:按条件查询第一条记录 --------------------------
|
||||
func (c Crud[R]) First(ctx ctx, where any, order any, with map[string]func(db gorm.PreloadBuilder) error) (model *R) {
|
||||
func (c Crud[R]) First(ctx ctx, where any, order any, with map[string]func(db *gorm.DB) *gorm.DB) (model *R) {
|
||||
model = new(R)
|
||||
db := c.Dao.Ctx(ctx).Model(model)
|
||||
|
||||
|
|
@ -435,7 +435,7 @@ func (c Crud[R]) Exists(ctx ctx, where any) (exists bool) {
|
|||
}
|
||||
|
||||
// -------------------------- 原All对应实现:查询所有符合条件的记录 --------------------------
|
||||
func (c Crud[R]) All(ctx ctx, where any, order any, with map[string]func(db gorm.PreloadBuilder) error) (items []*R) {
|
||||
func (c Crud[R]) All(ctx ctx, where any, order any, with map[string]func(db *gorm.DB) *gorm.DB) (items []*R) {
|
||||
db := c.Dao.Ctx(ctx).Model(new(R))
|
||||
|
||||
if with != nil {
|
||||
|
|
@ -500,7 +500,7 @@ func (c Crud[R]) UpdatePri(ctx ctx, primaryKey any, data any) (count int64) {
|
|||
}
|
||||
|
||||
// -------------------------- 原Paginate对应实现:分页查询 --------------------------
|
||||
func (c Crud[R]) Paginate(ctx context.Context, where any, p Paginate, with map[string]func(db gorm.PreloadBuilder) error, order any) (items []*R, total int64) {
|
||||
func (c Crud[R]) Paginate(ctx context.Context, where any, p Paginate, with map[string]func(db *gorm.DB) *gorm.DB, order any) (items []*R, total int64) {
|
||||
db := c.Dao.Ctx(ctx).Model(new(R))
|
||||
|
||||
// 1. 构建查询条件
|
||||
|
|
|
|||
Loading…
Reference in New Issue