SetField sets the value of a field with the given name. It returns an error if the field is not defined in the schema, or if the type mismatched the field type.
(name string, value ent.Value)
| 10663 | // the field is not defined in the schema, or if the type mismatched the field |
| 10664 | // type. |
| 10665 | func (m *MetaMutation) SetField(name string, value ent.Value) error { |
| 10666 | switch name { |
| 10667 | case meta.FieldCreatedAt: |
| 10668 | v, ok := value.(time.Time) |
| 10669 | if !ok { |
| 10670 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 10671 | } |
| 10672 | m.SetCreatedAt(v) |
| 10673 | return nil |
| 10674 | case meta.FieldUpdatedAt: |
| 10675 | v, ok := value.(time.Time) |
| 10676 | if !ok { |
| 10677 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 10678 | } |
| 10679 | m.SetUpdatedAt(v) |
| 10680 | return nil |
| 10681 | case meta.FieldKey: |
| 10682 | v, ok := value.(string) |
| 10683 | if !ok { |
| 10684 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 10685 | } |
| 10686 | m.SetKey(v) |
| 10687 | return nil |
| 10688 | case meta.FieldValue: |
| 10689 | v, ok := value.(string) |
| 10690 | if !ok { |
| 10691 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 10692 | } |
| 10693 | m.SetValue(v) |
| 10694 | return nil |
| 10695 | case meta.FieldAlertMetas: |
| 10696 | v, ok := value.(int) |
| 10697 | if !ok { |
| 10698 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 10699 | } |
| 10700 | m.SetAlertMetas(v) |
| 10701 | return nil |
| 10702 | } |
| 10703 | return fmt.Errorf("unknown Meta field %s", name) |
| 10704 | } |
| 10705 | |
| 10706 | // AddedFields returns all numeric fields that were incremented/decremented during |
| 10707 | // this mutation. |
nothing calls this directly
no test coverage detected