Skip to content

Commit

Permalink
fix: fix dyngen template
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Dec 24, 2024
1 parent 9783092 commit def2652
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions cmd/dyngen/command/template/dal_gorm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (b {{$stName}}) GetByFilter(ctx context.Context, q *{{$queryPrefix}}Get{{$s

err := b.db.Model(&{{$mdName}}{}).
Scopes(funcs...).
Scopes(get{{$stName}}Filter(q)).
Scopes(get{{$stName}}ByFilter(q)).
Take(&row).Error
if err != nil {
return nil, err
Expand Down Expand Up @@ -152,7 +152,7 @@ func (b {{$stName}}) ExistByFilter(ctx context.Context, q *{{$queryPrefix}}Exist

func (b {{$stName}}) Count(ctx context.Context, q *{{$queryPrefix}}List{{$stName}}ByFilter) (total int64, err error) {
err = b.db.Model(&{{$mdName}}{}).
Scopes(list{{$stName}}Filter(q)).
Scopes(list{{$stName}}ByFilter(q)).
Count(&total).Error
return total, err
}
Expand All @@ -161,7 +161,7 @@ func (b {{$stName}}) List(ctx context.Context, q *{{$queryPrefix}}List{{$stName}
var rows []*{{$mdName}}

err := b.db.Model(&{{$mdName}}{}).
Scopes(list{{$stName}}Filter(q), Limit(q.Page, q.PerPage)).
Scopes(list{{$stName}}ByFilter(q), Limit(q.Page, q.PerPage)).
Find(&rows).Error
return rows, err
}
Expand All @@ -171,7 +171,7 @@ func (b {{$stName}}) ListPage(ctx context.Context, q *{{$queryPrefix}}List{{$stN
var rows []*{{$mdName}}

db := b.db.Model(&{{$mdName}}{}).
Scopes(list{{$stName}}Filter(q))
Scopes(list{{$stName}}ByFilter(q))

err := db.Count(&total).Error
if err != nil {
Expand Down Expand Up @@ -217,7 +217,7 @@ func delete{{$stName}}ByFilter(q *{{$queryPrefix}}Delete{{$stName}}ByFilter) fun
}
}

func get{{$stName}}Filter(q *{{$queryPrefix}}Get{{$stName}}ByFilter) func(db *gorm.DB) *gorm.DB {
func get{{$stName}}ByFilter(q *{{$queryPrefix}}Get{{$stName}}ByFilter) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
{{- range $f := $e.Fields}}
{{- if and (ne $f.GoName "CreatedAt") (ne $f.GoName "UpdatedAt") (ne $f.GoName "DeletedAt")}}
Expand All @@ -238,7 +238,7 @@ func get{{$stName}}Filter(q *{{$queryPrefix}}Get{{$stName}}ByFilter) func(db *go
}
}

func list{{$stName}}Filter(q *{{$queryPrefix}}List{{$stName}}ByFilter) func(db *gorm.DB) *gorm.DB {
func list{{$stName}}ByFilter(q *{{$queryPrefix}}List{{$stName}}ByFilter) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
{{- range $f := $e.Fields}}
{{- if and (ne $f.GoName "CreatedAt") (ne $f.GoName "UpdatedAt") (ne $f.GoName "DeletedAt")}}
Expand Down
12 changes: 6 additions & 6 deletions cmd/dyngen/command/template/dal_rapier.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (b {{$stName}}) GetByFilter(ctx context.Context, q *{{$queryPrefix}}Get{{$s
return ref.New_Executor(b.db).Model().
SelectExpr(ref.Select_Expr()...).
Scopes(funcs...).
Scopes(get{{$stName}}Filter(ref, q)).
Scopes(get{{$stName}}ByFilter(ref, q)).
TakeOne()
}

Expand Down Expand Up @@ -141,7 +141,7 @@ func (b {{$stName}}) ExistByFilter(ctx context.Context, q *{{$queryPrefix}}Exist
func (b {{$stName}}) Count(ctx context.Context, q *{{$queryPrefix}}List{{$stName}}ByFilter) (total int64, err error) {
ref := {{$repoPrefix}}Ref_{{$stName}}()
return ref.New_Executor(b.db).Model().
Scopes(list{{$stName}}Filter(ref, q)).
Scopes(list{{$stName}}ByFilter(ref, q)).
Count()
}

Expand All @@ -150,15 +150,15 @@ func (b {{$stName}}) List(ctx context.Context, q *{{$queryPrefix}}List{{$stName}
ref := {{$repoPrefix}}Ref_{{$stName}}()
return ref.New_Executor(b.db).Model().
SelectExpr(ref.Select_Expr()...).
Scopes(list{{$stName}}Filter(ref, q), Limit(q.Page, q.PerPage)).
Scopes(list{{$stName}}ByFilter(ref, q), Limit(q.Page, q.PerPage)).
FindAll()
}

func (b {{$stName}}) ListPage(ctx context.Context, q *{{$queryPrefix}}List{{$stName}}ByFilter) ([]*{{$mdName}}, int64, error) {
ref := {{$repoPrefix}}Ref_{{$stName}}()
return ref.New_Executor(b.db).Model().
SelectExpr(ref.Select_Expr()...).
Scopes(list{{$stName}}Filter(ref, q)).
Scopes(list{{$stName}}ByFilter(ref, q)).
FindAllPaginate(q.Page, q.PerPage)
}

Expand Down Expand Up @@ -191,7 +191,7 @@ func delete{{$stName}}ByFilter(ref *{{$repoPrefix}}{{$stName}}_Native, q *{{$que
}
}

func get{{$stName}}Filter(ref *{{$repoPrefix}}{{$stName}}_Native, q *{{$queryPrefix}}Get{{$stName}}ByFilter) func(db *gorm.DB) *gorm.DB {
func get{{$stName}}ByFilter(ref *{{$repoPrefix}}{{$stName}}_Native, q *{{$queryPrefix}}Get{{$stName}}ByFilter) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
{{- range $f := $e.Fields}}
{{- if and (ne $f.GoName "CreatedAt") (ne $f.GoName "UpdatedAt") (ne $f.GoName "DeletedAt")}}
Expand All @@ -212,7 +212,7 @@ func get{{$stName}}Filter(ref *{{$repoPrefix}}{{$stName}}_Native, q *{{$queryPre
}
}

func list{{$stName}}Filter(ref *{{$repoPrefix}}{{$stName}}_Native, q *{{$queryPrefix}}List{{$stName}}ByFilter) func(db *gorm.DB) *gorm.DB {
func list{{$stName}}ByFilter(ref *{{$repoPrefix}}{{$stName}}_Native, q *{{$queryPrefix}}List{{$stName}}ByFilter) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
{{- range $f := $e.Fields}}
{{- if and (ne $f.GoName "CreatedAt") (ne $f.GoName "UpdatedAt") (ne $f.GoName "DeletedAt")}}
Expand Down

0 comments on commit def2652

Please sign in to comment.