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)
| 12200 | // the field is not defined in the schema, or if the type mismatched the field |
| 12201 | // type. |
| 12202 | func (m *ShareMutation) SetField(name string, value ent.Value) error { |
| 12203 | switch name { |
| 12204 | case share.FieldCreatedAt: |
| 12205 | v, ok := value.(time.Time) |
| 12206 | if !ok { |
| 12207 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 12208 | } |
| 12209 | m.SetCreatedAt(v) |
| 12210 | return nil |
| 12211 | case share.FieldUpdatedAt: |
| 12212 | v, ok := value.(time.Time) |
| 12213 | if !ok { |
| 12214 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 12215 | } |
| 12216 | m.SetUpdatedAt(v) |
| 12217 | return nil |
| 12218 | case share.FieldDeletedAt: |
| 12219 | v, ok := value.(time.Time) |
| 12220 | if !ok { |
| 12221 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 12222 | } |
| 12223 | m.SetDeletedAt(v) |
| 12224 | return nil |
| 12225 | case share.FieldPassword: |
| 12226 | v, ok := value.(string) |
| 12227 | if !ok { |
| 12228 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 12229 | } |
| 12230 | m.SetPassword(v) |
| 12231 | return nil |
| 12232 | case share.FieldViews: |
| 12233 | v, ok := value.(int) |
| 12234 | if !ok { |
| 12235 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 12236 | } |
| 12237 | m.SetViews(v) |
| 12238 | return nil |
| 12239 | case share.FieldDownloads: |
| 12240 | v, ok := value.(int) |
| 12241 | if !ok { |
| 12242 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 12243 | } |
| 12244 | m.SetDownloads(v) |
| 12245 | return nil |
| 12246 | case share.FieldExpires: |
| 12247 | v, ok := value.(time.Time) |
| 12248 | if !ok { |
| 12249 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 12250 | } |
| 12251 | m.SetExpires(v) |
| 12252 | return nil |
| 12253 | case share.FieldRemainDownloads: |
| 12254 | v, ok := value.(int) |
| 12255 | if !ok { |
| 12256 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 12257 | } |
| 12258 | m.SetRemainDownloads(v) |
| 12259 | return nil |
nothing calls this directly
no test coverage detected