mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
schema/field: json type support (#38)
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/38 Only `IsNil` and `NotNil` predicates are supported this moment Reviewed By: alexsn Differential Revision: D17444976 fbshipit-source-id: 37336fa0bc7749af995933baee2e23bb7366dd78
This commit is contained in:
committed by
Facebook Github Bot
parent
83d0063437
commit
c3955a08f1
@@ -27,7 +27,13 @@ func ({{ $receiver }} *{{ $.Name }}) FromRows(rows *sql.Rows) error {
|
||||
}
|
||||
{{ $receiver }}.ID = {{ if $.ID.IsString }}strconv.Itoa({{ $scan }}.ID){{ else }}{{ $scan }}.ID{{ end }}
|
||||
{{- range $_, $f := $.Fields }}
|
||||
{{- if $f.Nillable }}
|
||||
{{- if $f.IsJSON }}
|
||||
if value := {{ $scan }}.{{ pascal $f.Name }}; len(value) > 0 {
|
||||
if err := json.Unmarshal(value, &{{ $receiver }}.{{ pascal $f.Name }}); err != nil {
|
||||
return fmt.Errorf("unmarshal field {{ $f.Name }}: %v", err)
|
||||
}
|
||||
}
|
||||
{{- else if $f.Nillable }}
|
||||
{{- if $f.IsTime }}
|
||||
{{ $receiver }}.{{ pascal $f.Name }} = &{{ $scan }}.{{ pascal $f.Name }}
|
||||
{{- else }}
|
||||
|
||||
Reference in New Issue
Block a user