// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "sync" "time" "code.icod.de/dalu/ka/ent/category" "code.icod.de/dalu/ka/ent/post" "code.icod.de/dalu/ka/ent/predicate" "code.icod.de/dalu/ka/ent/profile" "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeCategory = "Category" TypePost = "Post" TypeProfile = "Profile" ) // CategoryMutation represents an operation that mutates the Category nodes in the graph. type CategoryMutation struct { config op Op typ string id *uuid.UUID created_at *time.Time updated_at *time.Time title *string description *string clearedFields map[string]struct{} posts map[uuid.UUID]struct{} removedposts map[uuid.UUID]struct{} clearedposts bool done bool oldValue func(context.Context) (*Category, error) predicates []predicate.Category } var _ ent.Mutation = (*CategoryMutation)(nil) // categoryOption allows management of the mutation configuration using functional options. type categoryOption func(*CategoryMutation) // newCategoryMutation creates new mutation for the Category entity. func newCategoryMutation(c config, op Op, opts ...categoryOption) *CategoryMutation { m := &CategoryMutation{ config: c, op: op, typ: TypeCategory, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withCategoryID sets the ID field of the mutation. func withCategoryID(id uuid.UUID) categoryOption { return func(m *CategoryMutation) { var ( err error once sync.Once value *Category ) m.oldValue = func(ctx context.Context) (*Category, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Category.Get(ctx, id) } }) return value, err } m.id = &id } } // withCategory sets the old Category of the mutation. func withCategory(node *Category) categoryOption { return func(m *CategoryMutation) { m.oldValue = func(context.Context) (*Category, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m CategoryMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m CategoryMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Category entities. func (m *CategoryMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *CategoryMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *CategoryMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Category.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetCreatedAt sets the "created_at" field. func (m *CategoryMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *CategoryMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the Category entity. // If the Category object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *CategoryMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ResetCreatedAt resets all changes to the "created_at" field. func (m *CategoryMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *CategoryMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *CategoryMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the Category entity. // If the Category object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *CategoryMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ClearUpdatedAt clears the value of the "updated_at" field. func (m *CategoryMutation) ClearUpdatedAt() { m.updated_at = nil m.clearedFields[category.FieldUpdatedAt] = struct{}{} } // UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation. func (m *CategoryMutation) UpdatedAtCleared() bool { _, ok := m.clearedFields[category.FieldUpdatedAt] return ok } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *CategoryMutation) ResetUpdatedAt() { m.updated_at = nil delete(m.clearedFields, category.FieldUpdatedAt) } // SetTitle sets the "title" field. func (m *CategoryMutation) SetTitle(s string) { m.title = &s } // Title returns the value of the "title" field in the mutation. func (m *CategoryMutation) Title() (r string, exists bool) { v := m.title if v == nil { return } return *v, true } // OldTitle returns the old "title" field's value of the Category entity. // If the Category object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *CategoryMutation) OldTitle(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTitle is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTitle requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTitle: %w", err) } return oldValue.Title, nil } // ResetTitle resets all changes to the "title" field. func (m *CategoryMutation) ResetTitle() { m.title = nil } // SetDescription sets the "description" field. func (m *CategoryMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *CategoryMutation) Description() (r string, exists bool) { v := m.description if v == nil { return } return *v, true } // OldDescription returns the old "description" field's value of the Category entity. // If the Category object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *CategoryMutation) OldDescription(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDescription: %w", err) } return oldValue.Description, nil } // ClearDescription clears the value of the "description" field. func (m *CategoryMutation) ClearDescription() { m.description = nil m.clearedFields[category.FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *CategoryMutation) DescriptionCleared() bool { _, ok := m.clearedFields[category.FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *CategoryMutation) ResetDescription() { m.description = nil delete(m.clearedFields, category.FieldDescription) } // AddPostIDs adds the "posts" edge to the Post entity by ids. func (m *CategoryMutation) AddPostIDs(ids ...uuid.UUID) { if m.posts == nil { m.posts = make(map[uuid.UUID]struct{}) } for i := range ids { m.posts[ids[i]] = struct{}{} } } // ClearPosts clears the "posts" edge to the Post entity. func (m *CategoryMutation) ClearPosts() { m.clearedposts = true } // PostsCleared reports if the "posts" edge to the Post entity was cleared. func (m *CategoryMutation) PostsCleared() bool { return m.clearedposts } // RemovePostIDs removes the "posts" edge to the Post entity by IDs. func (m *CategoryMutation) RemovePostIDs(ids ...uuid.UUID) { if m.removedposts == nil { m.removedposts = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.posts, ids[i]) m.removedposts[ids[i]] = struct{}{} } } // RemovedPosts returns the removed IDs of the "posts" edge to the Post entity. func (m *CategoryMutation) RemovedPostsIDs() (ids []uuid.UUID) { for id := range m.removedposts { ids = append(ids, id) } return } // PostsIDs returns the "posts" edge IDs in the mutation. func (m *CategoryMutation) PostsIDs() (ids []uuid.UUID) { for id := range m.posts { ids = append(ids, id) } return } // ResetPosts resets all changes to the "posts" edge. func (m *CategoryMutation) ResetPosts() { m.posts = nil m.clearedposts = false m.removedposts = nil } // Where appends a list predicates to the CategoryMutation builder. func (m *CategoryMutation) Where(ps ...predicate.Category) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the CategoryMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *CategoryMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Category, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *CategoryMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *CategoryMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Category). func (m *CategoryMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *CategoryMutation) Fields() []string { fields := make([]string, 0, 4) if m.created_at != nil { fields = append(fields, category.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, category.FieldUpdatedAt) } if m.title != nil { fields = append(fields, category.FieldTitle) } if m.description != nil { fields = append(fields, category.FieldDescription) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *CategoryMutation) Field(name string) (ent.Value, bool) { switch name { case category.FieldCreatedAt: return m.CreatedAt() case category.FieldUpdatedAt: return m.UpdatedAt() case category.FieldTitle: return m.Title() case category.FieldDescription: return m.Description() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *CategoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case category.FieldCreatedAt: return m.OldCreatedAt(ctx) case category.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case category.FieldTitle: return m.OldTitle(ctx) case category.FieldDescription: return m.OldDescription(ctx) } return nil, fmt.Errorf("unknown Category field %s", name) } // 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. func (m *CategoryMutation) SetField(name string, value ent.Value) error { switch name { case category.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case category.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil case category.FieldTitle: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTitle(v) return nil case category.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil } return fmt.Errorf("unknown Category field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *CategoryMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *CategoryMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the 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. func (m *CategoryMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Category numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *CategoryMutation) ClearedFields() []string { var fields []string if m.FieldCleared(category.FieldUpdatedAt) { fields = append(fields, category.FieldUpdatedAt) } if m.FieldCleared(category.FieldDescription) { fields = append(fields, category.FieldDescription) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *CategoryMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *CategoryMutation) ClearField(name string) error { switch name { case category.FieldUpdatedAt: m.ClearUpdatedAt() return nil case category.FieldDescription: m.ClearDescription() return nil } return fmt.Errorf("unknown Category nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *CategoryMutation) ResetField(name string) error { switch name { case category.FieldCreatedAt: m.ResetCreatedAt() return nil case category.FieldUpdatedAt: m.ResetUpdatedAt() return nil case category.FieldTitle: m.ResetTitle() return nil case category.FieldDescription: m.ResetDescription() return nil } return fmt.Errorf("unknown Category field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *CategoryMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.posts != nil { edges = append(edges, category.EdgePosts) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *CategoryMutation) AddedIDs(name string) []ent.Value { switch name { case category.EdgePosts: ids := make([]ent.Value, 0, len(m.posts)) for id := range m.posts { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *CategoryMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedposts != nil { edges = append(edges, category.EdgePosts) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *CategoryMutation) RemovedIDs(name string) []ent.Value { switch name { case category.EdgePosts: ids := make([]ent.Value, 0, len(m.removedposts)) for id := range m.removedposts { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *CategoryMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedposts { edges = append(edges, category.EdgePosts) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *CategoryMutation) EdgeCleared(name string) bool { switch name { case category.EdgePosts: return m.clearedposts } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *CategoryMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Category unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *CategoryMutation) ResetEdge(name string) error { switch name { case category.EdgePosts: m.ResetPosts() return nil } return fmt.Errorf("unknown Category edge %s", name) } // PostMutation represents an operation that mutates the Post nodes in the graph. type PostMutation struct { config op Op typ string id *uuid.UUID created_at *time.Time updated_at *time.Time expires *bool expire_time *time.Time title *string body *string clearedFields map[string]struct{} category *uuid.UUID clearedcategory bool profile *uuid.UUID clearedprofile bool done bool oldValue func(context.Context) (*Post, error) predicates []predicate.Post } var _ ent.Mutation = (*PostMutation)(nil) // postOption allows management of the mutation configuration using functional options. type postOption func(*PostMutation) // newPostMutation creates new mutation for the Post entity. func newPostMutation(c config, op Op, opts ...postOption) *PostMutation { m := &PostMutation{ config: c, op: op, typ: TypePost, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withPostID sets the ID field of the mutation. func withPostID(id uuid.UUID) postOption { return func(m *PostMutation) { var ( err error once sync.Once value *Post ) m.oldValue = func(ctx context.Context) (*Post, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Post.Get(ctx, id) } }) return value, err } m.id = &id } } // withPost sets the old Post of the mutation. func withPost(node *Post) postOption { return func(m *PostMutation) { m.oldValue = func(context.Context) (*Post, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m PostMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m PostMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Post entities. func (m *PostMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *PostMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *PostMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Post.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetCreatedAt sets the "created_at" field. func (m *PostMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *PostMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the Post entity. // If the Post object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PostMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ResetCreatedAt resets all changes to the "created_at" field. func (m *PostMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *PostMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *PostMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the Post entity. // If the Post object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PostMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ClearUpdatedAt clears the value of the "updated_at" field. func (m *PostMutation) ClearUpdatedAt() { m.updated_at = nil m.clearedFields[post.FieldUpdatedAt] = struct{}{} } // UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation. func (m *PostMutation) UpdatedAtCleared() bool { _, ok := m.clearedFields[post.FieldUpdatedAt] return ok } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *PostMutation) ResetUpdatedAt() { m.updated_at = nil delete(m.clearedFields, post.FieldUpdatedAt) } // SetExpires sets the "expires" field. func (m *PostMutation) SetExpires(b bool) { m.expires = &b } // Expires returns the value of the "expires" field in the mutation. func (m *PostMutation) Expires() (r bool, exists bool) { v := m.expires if v == nil { return } return *v, true } // OldExpires returns the old "expires" field's value of the Post entity. // If the Post object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PostMutation) OldExpires(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldExpires is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldExpires requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldExpires: %w", err) } return oldValue.Expires, nil } // ResetExpires resets all changes to the "expires" field. func (m *PostMutation) ResetExpires() { m.expires = nil } // SetExpireTime sets the "expire_time" field. func (m *PostMutation) SetExpireTime(t time.Time) { m.expire_time = &t } // ExpireTime returns the value of the "expire_time" field in the mutation. func (m *PostMutation) ExpireTime() (r time.Time, exists bool) { v := m.expire_time if v == nil { return } return *v, true } // OldExpireTime returns the old "expire_time" field's value of the Post entity. // If the Post object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PostMutation) OldExpireTime(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldExpireTime is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldExpireTime requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldExpireTime: %w", err) } return oldValue.ExpireTime, nil } // ClearExpireTime clears the value of the "expire_time" field. func (m *PostMutation) ClearExpireTime() { m.expire_time = nil m.clearedFields[post.FieldExpireTime] = struct{}{} } // ExpireTimeCleared returns if the "expire_time" field was cleared in this mutation. func (m *PostMutation) ExpireTimeCleared() bool { _, ok := m.clearedFields[post.FieldExpireTime] return ok } // ResetExpireTime resets all changes to the "expire_time" field. func (m *PostMutation) ResetExpireTime() { m.expire_time = nil delete(m.clearedFields, post.FieldExpireTime) } // SetTitle sets the "title" field. func (m *PostMutation) SetTitle(s string) { m.title = &s } // Title returns the value of the "title" field in the mutation. func (m *PostMutation) Title() (r string, exists bool) { v := m.title if v == nil { return } return *v, true } // OldTitle returns the old "title" field's value of the Post entity. // If the Post object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PostMutation) OldTitle(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTitle is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTitle requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTitle: %w", err) } return oldValue.Title, nil } // ResetTitle resets all changes to the "title" field. func (m *PostMutation) ResetTitle() { m.title = nil } // SetBody sets the "body" field. func (m *PostMutation) SetBody(s string) { m.body = &s } // Body returns the value of the "body" field in the mutation. func (m *PostMutation) Body() (r string, exists bool) { v := m.body if v == nil { return } return *v, true } // OldBody returns the old "body" field's value of the Post entity. // If the Post object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PostMutation) OldBody(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldBody is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldBody requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldBody: %w", err) } return oldValue.Body, nil } // ResetBody resets all changes to the "body" field. func (m *PostMutation) ResetBody() { m.body = nil } // SetCategoryID sets the "category" edge to the Category entity by id. func (m *PostMutation) SetCategoryID(id uuid.UUID) { m.category = &id } // ClearCategory clears the "category" edge to the Category entity. func (m *PostMutation) ClearCategory() { m.clearedcategory = true } // CategoryCleared reports if the "category" edge to the Category entity was cleared. func (m *PostMutation) CategoryCleared() bool { return m.clearedcategory } // CategoryID returns the "category" edge ID in the mutation. func (m *PostMutation) CategoryID() (id uuid.UUID, exists bool) { if m.category != nil { return *m.category, true } return } // CategoryIDs returns the "category" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // CategoryID instead. It exists only for internal usage by the builders. func (m *PostMutation) CategoryIDs() (ids []uuid.UUID) { if id := m.category; id != nil { ids = append(ids, *id) } return } // ResetCategory resets all changes to the "category" edge. func (m *PostMutation) ResetCategory() { m.category = nil m.clearedcategory = false } // SetProfileID sets the "profile" edge to the Profile entity by id. func (m *PostMutation) SetProfileID(id uuid.UUID) { m.profile = &id } // ClearProfile clears the "profile" edge to the Profile entity. func (m *PostMutation) ClearProfile() { m.clearedprofile = true } // ProfileCleared reports if the "profile" edge to the Profile entity was cleared. func (m *PostMutation) ProfileCleared() bool { return m.clearedprofile } // ProfileID returns the "profile" edge ID in the mutation. func (m *PostMutation) ProfileID() (id uuid.UUID, exists bool) { if m.profile != nil { return *m.profile, true } return } // ProfileIDs returns the "profile" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // ProfileID instead. It exists only for internal usage by the builders. func (m *PostMutation) ProfileIDs() (ids []uuid.UUID) { if id := m.profile; id != nil { ids = append(ids, *id) } return } // ResetProfile resets all changes to the "profile" edge. func (m *PostMutation) ResetProfile() { m.profile = nil m.clearedprofile = false } // Where appends a list predicates to the PostMutation builder. func (m *PostMutation) Where(ps ...predicate.Post) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the PostMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *PostMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Post, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *PostMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *PostMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Post). func (m *PostMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *PostMutation) Fields() []string { fields := make([]string, 0, 6) if m.created_at != nil { fields = append(fields, post.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, post.FieldUpdatedAt) } if m.expires != nil { fields = append(fields, post.FieldExpires) } if m.expire_time != nil { fields = append(fields, post.FieldExpireTime) } if m.title != nil { fields = append(fields, post.FieldTitle) } if m.body != nil { fields = append(fields, post.FieldBody) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *PostMutation) Field(name string) (ent.Value, bool) { switch name { case post.FieldCreatedAt: return m.CreatedAt() case post.FieldUpdatedAt: return m.UpdatedAt() case post.FieldExpires: return m.Expires() case post.FieldExpireTime: return m.ExpireTime() case post.FieldTitle: return m.Title() case post.FieldBody: return m.Body() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *PostMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case post.FieldCreatedAt: return m.OldCreatedAt(ctx) case post.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case post.FieldExpires: return m.OldExpires(ctx) case post.FieldExpireTime: return m.OldExpireTime(ctx) case post.FieldTitle: return m.OldTitle(ctx) case post.FieldBody: return m.OldBody(ctx) } return nil, fmt.Errorf("unknown Post field %s", name) } // 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. func (m *PostMutation) SetField(name string, value ent.Value) error { switch name { case post.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case post.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil case post.FieldExpires: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetExpires(v) return nil case post.FieldExpireTime: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetExpireTime(v) return nil case post.FieldTitle: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTitle(v) return nil case post.FieldBody: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetBody(v) return nil } return fmt.Errorf("unknown Post field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *PostMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *PostMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the 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. func (m *PostMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Post numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *PostMutation) ClearedFields() []string { var fields []string if m.FieldCleared(post.FieldUpdatedAt) { fields = append(fields, post.FieldUpdatedAt) } if m.FieldCleared(post.FieldExpireTime) { fields = append(fields, post.FieldExpireTime) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *PostMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *PostMutation) ClearField(name string) error { switch name { case post.FieldUpdatedAt: m.ClearUpdatedAt() return nil case post.FieldExpireTime: m.ClearExpireTime() return nil } return fmt.Errorf("unknown Post nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *PostMutation) ResetField(name string) error { switch name { case post.FieldCreatedAt: m.ResetCreatedAt() return nil case post.FieldUpdatedAt: m.ResetUpdatedAt() return nil case post.FieldExpires: m.ResetExpires() return nil case post.FieldExpireTime: m.ResetExpireTime() return nil case post.FieldTitle: m.ResetTitle() return nil case post.FieldBody: m.ResetBody() return nil } return fmt.Errorf("unknown Post field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *PostMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.category != nil { edges = append(edges, post.EdgeCategory) } if m.profile != nil { edges = append(edges, post.EdgeProfile) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *PostMutation) AddedIDs(name string) []ent.Value { switch name { case post.EdgeCategory: if id := m.category; id != nil { return []ent.Value{*id} } case post.EdgeProfile: if id := m.profile; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *PostMutation) RemovedEdges() []string { edges := make([]string, 0, 2) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *PostMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *PostMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedcategory { edges = append(edges, post.EdgeCategory) } if m.clearedprofile { edges = append(edges, post.EdgeProfile) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *PostMutation) EdgeCleared(name string) bool { switch name { case post.EdgeCategory: return m.clearedcategory case post.EdgeProfile: return m.clearedprofile } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *PostMutation) ClearEdge(name string) error { switch name { case post.EdgeCategory: m.ClearCategory() return nil case post.EdgeProfile: m.ClearProfile() return nil } return fmt.Errorf("unknown Post unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *PostMutation) ResetEdge(name string) error { switch name { case post.EdgeCategory: m.ResetCategory() return nil case post.EdgeProfile: m.ResetProfile() return nil } return fmt.Errorf("unknown Post edge %s", name) } // ProfileMutation represents an operation that mutates the Profile nodes in the graph. type ProfileMutation struct { config op Op typ string id *uuid.UUID created_at *time.Time updated_at *time.Time name *string address *string phone *string clearedFields map[string]struct{} posts map[uuid.UUID]struct{} removedposts map[uuid.UUID]struct{} clearedposts bool done bool oldValue func(context.Context) (*Profile, error) predicates []predicate.Profile } var _ ent.Mutation = (*ProfileMutation)(nil) // profileOption allows management of the mutation configuration using functional options. type profileOption func(*ProfileMutation) // newProfileMutation creates new mutation for the Profile entity. func newProfileMutation(c config, op Op, opts ...profileOption) *ProfileMutation { m := &ProfileMutation{ config: c, op: op, typ: TypeProfile, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withProfileID sets the ID field of the mutation. func withProfileID(id uuid.UUID) profileOption { return func(m *ProfileMutation) { var ( err error once sync.Once value *Profile ) m.oldValue = func(ctx context.Context) (*Profile, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Profile.Get(ctx, id) } }) return value, err } m.id = &id } } // withProfile sets the old Profile of the mutation. func withProfile(node *Profile) profileOption { return func(m *ProfileMutation) { m.oldValue = func(context.Context) (*Profile, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m ProfileMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m ProfileMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Profile entities. func (m *ProfileMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *ProfileMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *ProfileMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Profile.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetCreatedAt sets the "created_at" field. func (m *ProfileMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *ProfileMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the Profile entity. // If the Profile object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProfileMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ResetCreatedAt resets all changes to the "created_at" field. func (m *ProfileMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *ProfileMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *ProfileMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return } return *v, true } // OldUpdatedAt returns the old "updated_at" field's value of the Profile entity. // If the Profile object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProfileMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } return oldValue.UpdatedAt, nil } // ClearUpdatedAt clears the value of the "updated_at" field. func (m *ProfileMutation) ClearUpdatedAt() { m.updated_at = nil m.clearedFields[profile.FieldUpdatedAt] = struct{}{} } // UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation. func (m *ProfileMutation) UpdatedAtCleared() bool { _, ok := m.clearedFields[profile.FieldUpdatedAt] return ok } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *ProfileMutation) ResetUpdatedAt() { m.updated_at = nil delete(m.clearedFields, profile.FieldUpdatedAt) } // SetName sets the "name" field. func (m *ProfileMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *ProfileMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old "name" field's value of the Profile entity. // If the Profile object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProfileMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldName: %w", err) } return oldValue.Name, nil } // ClearName clears the value of the "name" field. func (m *ProfileMutation) ClearName() { m.name = nil m.clearedFields[profile.FieldName] = struct{}{} } // NameCleared returns if the "name" field was cleared in this mutation. func (m *ProfileMutation) NameCleared() bool { _, ok := m.clearedFields[profile.FieldName] return ok } // ResetName resets all changes to the "name" field. func (m *ProfileMutation) ResetName() { m.name = nil delete(m.clearedFields, profile.FieldName) } // SetAddress sets the "address" field. func (m *ProfileMutation) SetAddress(s string) { m.address = &s } // Address returns the value of the "address" field in the mutation. func (m *ProfileMutation) Address() (r string, exists bool) { v := m.address if v == nil { return } return *v, true } // OldAddress returns the old "address" field's value of the Profile entity. // If the Profile object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProfileMutation) OldAddress(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAddress is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAddress requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAddress: %w", err) } return oldValue.Address, nil } // ClearAddress clears the value of the "address" field. func (m *ProfileMutation) ClearAddress() { m.address = nil m.clearedFields[profile.FieldAddress] = struct{}{} } // AddressCleared returns if the "address" field was cleared in this mutation. func (m *ProfileMutation) AddressCleared() bool { _, ok := m.clearedFields[profile.FieldAddress] return ok } // ResetAddress resets all changes to the "address" field. func (m *ProfileMutation) ResetAddress() { m.address = nil delete(m.clearedFields, profile.FieldAddress) } // SetPhone sets the "phone" field. func (m *ProfileMutation) SetPhone(s string) { m.phone = &s } // Phone returns the value of the "phone" field in the mutation. func (m *ProfileMutation) Phone() (r string, exists bool) { v := m.phone if v == nil { return } return *v, true } // OldPhone returns the old "phone" field's value of the Profile entity. // If the Profile object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ProfileMutation) OldPhone(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPhone is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPhone requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPhone: %w", err) } return oldValue.Phone, nil } // ClearPhone clears the value of the "phone" field. func (m *ProfileMutation) ClearPhone() { m.phone = nil m.clearedFields[profile.FieldPhone] = struct{}{} } // PhoneCleared returns if the "phone" field was cleared in this mutation. func (m *ProfileMutation) PhoneCleared() bool { _, ok := m.clearedFields[profile.FieldPhone] return ok } // ResetPhone resets all changes to the "phone" field. func (m *ProfileMutation) ResetPhone() { m.phone = nil delete(m.clearedFields, profile.FieldPhone) } // AddPostIDs adds the "posts" edge to the Post entity by ids. func (m *ProfileMutation) AddPostIDs(ids ...uuid.UUID) { if m.posts == nil { m.posts = make(map[uuid.UUID]struct{}) } for i := range ids { m.posts[ids[i]] = struct{}{} } } // ClearPosts clears the "posts" edge to the Post entity. func (m *ProfileMutation) ClearPosts() { m.clearedposts = true } // PostsCleared reports if the "posts" edge to the Post entity was cleared. func (m *ProfileMutation) PostsCleared() bool { return m.clearedposts } // RemovePostIDs removes the "posts" edge to the Post entity by IDs. func (m *ProfileMutation) RemovePostIDs(ids ...uuid.UUID) { if m.removedposts == nil { m.removedposts = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.posts, ids[i]) m.removedposts[ids[i]] = struct{}{} } } // RemovedPosts returns the removed IDs of the "posts" edge to the Post entity. func (m *ProfileMutation) RemovedPostsIDs() (ids []uuid.UUID) { for id := range m.removedposts { ids = append(ids, id) } return } // PostsIDs returns the "posts" edge IDs in the mutation. func (m *ProfileMutation) PostsIDs() (ids []uuid.UUID) { for id := range m.posts { ids = append(ids, id) } return } // ResetPosts resets all changes to the "posts" edge. func (m *ProfileMutation) ResetPosts() { m.posts = nil m.clearedposts = false m.removedposts = nil } // Where appends a list predicates to the ProfileMutation builder. func (m *ProfileMutation) Where(ps ...predicate.Profile) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the ProfileMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *ProfileMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Profile, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *ProfileMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *ProfileMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Profile). func (m *ProfileMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ProfileMutation) Fields() []string { fields := make([]string, 0, 5) if m.created_at != nil { fields = append(fields, profile.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, profile.FieldUpdatedAt) } if m.name != nil { fields = append(fields, profile.FieldName) } if m.address != nil { fields = append(fields, profile.FieldAddress) } if m.phone != nil { fields = append(fields, profile.FieldPhone) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *ProfileMutation) Field(name string) (ent.Value, bool) { switch name { case profile.FieldCreatedAt: return m.CreatedAt() case profile.FieldUpdatedAt: return m.UpdatedAt() case profile.FieldName: return m.Name() case profile.FieldAddress: return m.Address() case profile.FieldPhone: return m.Phone() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *ProfileMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case profile.FieldCreatedAt: return m.OldCreatedAt(ctx) case profile.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case profile.FieldName: return m.OldName(ctx) case profile.FieldAddress: return m.OldAddress(ctx) case profile.FieldPhone: return m.OldPhone(ctx) } return nil, fmt.Errorf("unknown Profile field %s", name) } // 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. func (m *ProfileMutation) SetField(name string, value ent.Value) error { switch name { case profile.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case profile.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil case profile.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case profile.FieldAddress: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAddress(v) return nil case profile.FieldPhone: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPhone(v) return nil } return fmt.Errorf("unknown Profile field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *ProfileMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *ProfileMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the 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. func (m *ProfileMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Profile numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ProfileMutation) ClearedFields() []string { var fields []string if m.FieldCleared(profile.FieldUpdatedAt) { fields = append(fields, profile.FieldUpdatedAt) } if m.FieldCleared(profile.FieldName) { fields = append(fields, profile.FieldName) } if m.FieldCleared(profile.FieldAddress) { fields = append(fields, profile.FieldAddress) } if m.FieldCleared(profile.FieldPhone) { fields = append(fields, profile.FieldPhone) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *ProfileMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *ProfileMutation) ClearField(name string) error { switch name { case profile.FieldUpdatedAt: m.ClearUpdatedAt() return nil case profile.FieldName: m.ClearName() return nil case profile.FieldAddress: m.ClearAddress() return nil case profile.FieldPhone: m.ClearPhone() return nil } return fmt.Errorf("unknown Profile nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *ProfileMutation) ResetField(name string) error { switch name { case profile.FieldCreatedAt: m.ResetCreatedAt() return nil case profile.FieldUpdatedAt: m.ResetUpdatedAt() return nil case profile.FieldName: m.ResetName() return nil case profile.FieldAddress: m.ResetAddress() return nil case profile.FieldPhone: m.ResetPhone() return nil } return fmt.Errorf("unknown Profile field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ProfileMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.posts != nil { edges = append(edges, profile.EdgePosts) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *ProfileMutation) AddedIDs(name string) []ent.Value { switch name { case profile.EdgePosts: ids := make([]ent.Value, 0, len(m.posts)) for id := range m.posts { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *ProfileMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedposts != nil { edges = append(edges, profile.EdgePosts) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *ProfileMutation) RemovedIDs(name string) []ent.Value { switch name { case profile.EdgePosts: ids := make([]ent.Value, 0, len(m.removedposts)) for id := range m.removedposts { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ProfileMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedposts { edges = append(edges, profile.EdgePosts) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *ProfileMutation) EdgeCleared(name string) bool { switch name { case profile.EdgePosts: return m.clearedposts } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *ProfileMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Profile unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *ProfileMutation) ResetEdge(name string) error { switch name { case profile.EdgePosts: m.ResetPosts() return nil } return fmt.Errorf("unknown Profile edge %s", name) }