MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / SetField

Method SetField

ent/mutation.go:6914–6967  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

6912// the field is not defined in the schema, or if the type mismatched the field
6913// type.
6914func (m *MetadataMutation) SetField(name string, value ent.Value) error {
6915 switch name {
6916 case metadata.FieldCreatedAt:
6917 v, ok := value.(time.Time)
6918 if !ok {
6919 return fmt.Errorf("unexpected type %T for field %s", value, name)
6920 }
6921 m.SetCreatedAt(v)
6922 return nil
6923 case metadata.FieldUpdatedAt:
6924 v, ok := value.(time.Time)
6925 if !ok {
6926 return fmt.Errorf("unexpected type %T for field %s", value, name)
6927 }
6928 m.SetUpdatedAt(v)
6929 return nil
6930 case metadata.FieldDeletedAt:
6931 v, ok := value.(time.Time)
6932 if !ok {
6933 return fmt.Errorf("unexpected type %T for field %s", value, name)
6934 }
6935 m.SetDeletedAt(v)
6936 return nil
6937 case metadata.FieldName:
6938 v, ok := value.(string)
6939 if !ok {
6940 return fmt.Errorf("unexpected type %T for field %s", value, name)
6941 }
6942 m.SetName(v)
6943 return nil
6944 case metadata.FieldValue:
6945 v, ok := value.(string)
6946 if !ok {
6947 return fmt.Errorf("unexpected type %T for field %s", value, name)
6948 }
6949 m.SetValue(v)
6950 return nil
6951 case metadata.FieldFileID:
6952 v, ok := value.(int)
6953 if !ok {
6954 return fmt.Errorf("unexpected type %T for field %s", value, name)
6955 }
6956 m.SetFileID(v)
6957 return nil
6958 case metadata.FieldIsPublic:
6959 v, ok := value.(bool)
6960 if !ok {
6961 return fmt.Errorf("unexpected type %T for field %s", value, name)
6962 }
6963 m.SetIsPublic(v)
6964 return nil
6965 }
6966 return fmt.Errorf("unknown Metadata field %s", name)
6967}
6968
6969// AddedFields returns all numeric fields that were incremented/decremented during
6970// this mutation.

Callers

nothing calls this directly

Calls 7

SetCreatedAtMethod · 0.95
SetUpdatedAtMethod · 0.95
SetDeletedAtMethod · 0.95
SetNameMethod · 0.95
SetValueMethod · 0.95
SetFileIDMethod · 0.95
SetIsPublicMethod · 0.95

Tested by

no test coverage detected