entc/gen: merge ivanvanderbyl:add-json-type-to-entql (#1112)

* Generate JSON types for entql

* Correctly normalize name of json type in generated code

* Override interface types for entql wheres

* Actually call correct method

* Implement better interface name stringer

* Define JsonP in template

* Cleanup and fix tests

* Remove extra json predicates

* Remove JSON predicates and use BytesP

* Regenerate

* Update entc/gen/template/dialect/sql/entql.tmpl

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

* Update entql/internal/gen.go

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

* Fix comment

* all: regenerate assets

Co-authored-by: Ivan Vanderbyl <ivanvanderbyl@gmail.com>
Co-authored-by: Ivan Vanderbyl <ivanvanderbyl@users.noreply.github.com>
This commit is contained in:
Ariel Mashraki
2021-01-01 16:06:10 +02:00
committed by GitHub
parent 4a1ac1eef1
commit 069793dd03
13 changed files with 197 additions and 11 deletions

View File

@@ -118,7 +118,10 @@ type predicateAdder interface {
{{ range $f := $n.Fields }}
{{ $type := $f.Type.Type.String }}
{{ $iface := print (pascal $type) "P" }}
{{ if $f.IsTime }}{{ $iface = "TimeP" }}{{ else if $f.IsBytes }}{{ $iface = "BytesP" }}{{ else if $f.IsUUID }}{{ $iface = "ValueP" }}{{ end }}
{{- if $f.IsTime }}{{ $iface = "TimeP" }}
{{- else if or $f.IsBytes $f.IsJSON }}{{ $iface = "BytesP" }}
{{- else if $f.IsUUID }}{{ $iface = "ValueP" }}
{{- end }}
// Where{{ $f.StructField }} applies the entql {{ $type }} predicate on the {{ $f.Name }} field.
func (f *{{ $filter }}) Where{{ $f.StructField }}(p entql.{{ $iface }}) {
f.Where(p.Field({{ $n.Package }}.{{ $f.Constant }}))