Skip to content

Commit

Permalink
fix: refactor some code
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Simon committed May 2, 2023
1 parent a5fd565 commit 9e31a14
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 67 deletions.
17 changes: 2 additions & 15 deletions generate_code_filter_model.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,17 @@
{{ reserveImport "github.com/fasibio/autogql/runtimehelper" }}

{{$methodeName := "ExtendsDatabaseQuery"}}

const extendsDatabaseFieldNameFormat string = "%[2]s.%[1]s%[3]s%[1]s"

{{- $root := .}}

type ParentObject interface {
TableName() string
PrimaryKeyName() string
}


{{- range $objectName, $object := .Handler.List.Objects }}
{{- if $object.HasSqlDirective}}


func (d *{{$object.Name}}FiltersInput) TableName() string {
return "{{$object.Name | snakecase}}"
}

func (d *{{$object.Name}}FiltersInput) PrimaryKeyName() string {
return "{{$root.PrimaryKeyOfObject $object.Name}}"
}


func (d *{{$object.Name}}FiltersInput) {{$methodeName}}(db *gorm.DB, alias string,deep bool, blackList map[string]struct{}) []runtimehelper.ConditionElement {
res := make([]runtimehelper.ConditionElement, 0)
if d.And != nil {
Expand Down Expand Up @@ -55,7 +43,7 @@ func (d *{{$object.Name}}FiltersInput) {{$methodeName}}(db *gorm.DB, alias strin
{{- if or $entity.IsPrimitive $entity.GqlTypeObj.HasSqlDirective $entity.IsEnum }}
if d.{{$entityGoName}} != nil {
{{- if or $entity.IsPrimitive $entity.IsEnum }}
res = append(res, d.{{$entityGoName}}.{{$methodeName}}(db, fmt.Sprintf("%[2]s.%[1]s%[3]s%[1]s",runtimehelper.GetQuoteChar(db), alias,"{{snakecase $entityGoName}}"),true,blackList)...)
res = append(res, d.{{$entityGoName}}.{{$methodeName}}(db, fmt.Sprintf(extendsDatabaseFieldNameFormat,runtimehelper.GetQuoteChar(db), alias,"{{snakecase $entityGoName}}"),true,blackList)...)
{{- else }}
{{- if $entity.HasMany2ManyDirective}}
tableName := db.Config.NamingStrategy.TableName("{{$root.GetGoFieldTypeName $objectName $entity }}")
Expand Down Expand Up @@ -222,7 +210,6 @@ func (d *IntFilterInput) ExtendsDatabaseQuery(db *gorm.DB, fieldName string, dee

if d.NotIn != nil {
res = append(res, runtimehelper.NotIn(fieldName,d.NotIn))
}

if d.NotNull != nil && *d.NotNull {
Expand Down
81 changes: 29 additions & 52 deletions testservice/graph/model/models_filter_autogql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e31a14

Please sign in to comment.