// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "sync" "time" "tss-rocks-be/ent/category" "tss-rocks-be/ent/categorycontent" "tss-rocks-be/ent/contributor" "tss-rocks-be/ent/contributorrole" "tss-rocks-be/ent/contributorsociallink" "tss-rocks-be/ent/daily" "tss-rocks-be/ent/dailycategory" "tss-rocks-be/ent/dailycategorycontent" "tss-rocks-be/ent/dailycontent" "tss-rocks-be/ent/media" "tss-rocks-be/ent/permission" "tss-rocks-be/ent/post" "tss-rocks-be/ent/postcontent" "tss-rocks-be/ent/postcontributor" "tss-rocks-be/ent/predicate" "tss-rocks-be/ent/role" "tss-rocks-be/ent/user" "entgo.io/ent" "entgo.io/ent/dialect/sql" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeCategory = "Category" TypeCategoryContent = "CategoryContent" TypeContributor = "Contributor" TypeContributorRole = "ContributorRole" TypeContributorSocialLink = "ContributorSocialLink" TypeDaily = "Daily" TypeDailyCategory = "DailyCategory" TypeDailyCategoryContent = "DailyCategoryContent" TypeDailyContent = "DailyContent" TypeMedia = "Media" TypePermission = "Permission" TypePost = "Post" TypePostContent = "PostContent" TypePostContributor = "PostContributor" TypeRole = "Role" TypeUser = "User" ) // CategoryMutation represents an operation that mutates the Category nodes in the graph. type CategoryMutation struct { config op Op typ string id *int created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} contents map[int]struct{} removedcontents map[int]struct{} clearedcontents bool posts map[int]struct{} removedposts map[int]struct{} clearedposts bool daily_items map[string]struct{} removeddaily_items map[string]struct{} cleareddaily_items 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 int) 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 } // 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 int, 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) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{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 } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *CategoryMutation) ResetUpdatedAt() { m.updated_at = nil } // AddContentIDs adds the "contents" edge to the CategoryContent entity by ids. func (m *CategoryMutation) AddContentIDs(ids ...int) { if m.contents == nil { m.contents = make(map[int]struct{}) } for i := range ids { m.contents[ids[i]] = struct{}{} } } // ClearContents clears the "contents" edge to the CategoryContent entity. func (m *CategoryMutation) ClearContents() { m.clearedcontents = true } // ContentsCleared reports if the "contents" edge to the CategoryContent entity was cleared. func (m *CategoryMutation) ContentsCleared() bool { return m.clearedcontents } // RemoveContentIDs removes the "contents" edge to the CategoryContent entity by IDs. func (m *CategoryMutation) RemoveContentIDs(ids ...int) { if m.removedcontents == nil { m.removedcontents = make(map[int]struct{}) } for i := range ids { delete(m.contents, ids[i]) m.removedcontents[ids[i]] = struct{}{} } } // RemovedContents returns the removed IDs of the "contents" edge to the CategoryContent entity. func (m *CategoryMutation) RemovedContentsIDs() (ids []int) { for id := range m.removedcontents { ids = append(ids, id) } return } // ContentsIDs returns the "contents" edge IDs in the mutation. func (m *CategoryMutation) ContentsIDs() (ids []int) { for id := range m.contents { ids = append(ids, id) } return } // ResetContents resets all changes to the "contents" edge. func (m *CategoryMutation) ResetContents() { m.contents = nil m.clearedcontents = false m.removedcontents = nil } // AddPostIDs adds the "posts" edge to the Post entity by ids. func (m *CategoryMutation) AddPostIDs(ids ...int) { if m.posts == nil { m.posts = make(map[int]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 ...int) { if m.removedposts == nil { m.removedposts = make(map[int]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 []int) { for id := range m.removedposts { ids = append(ids, id) } return } // PostsIDs returns the "posts" edge IDs in the mutation. func (m *CategoryMutation) PostsIDs() (ids []int) { 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 } // AddDailyItemIDs adds the "daily_items" edge to the Daily entity by ids. func (m *CategoryMutation) AddDailyItemIDs(ids ...string) { if m.daily_items == nil { m.daily_items = make(map[string]struct{}) } for i := range ids { m.daily_items[ids[i]] = struct{}{} } } // ClearDailyItems clears the "daily_items" edge to the Daily entity. func (m *CategoryMutation) ClearDailyItems() { m.cleareddaily_items = true } // DailyItemsCleared reports if the "daily_items" edge to the Daily entity was cleared. func (m *CategoryMutation) DailyItemsCleared() bool { return m.cleareddaily_items } // RemoveDailyItemIDs removes the "daily_items" edge to the Daily entity by IDs. func (m *CategoryMutation) RemoveDailyItemIDs(ids ...string) { if m.removeddaily_items == nil { m.removeddaily_items = make(map[string]struct{}) } for i := range ids { delete(m.daily_items, ids[i]) m.removeddaily_items[ids[i]] = struct{}{} } } // RemovedDailyItems returns the removed IDs of the "daily_items" edge to the Daily entity. func (m *CategoryMutation) RemovedDailyItemsIDs() (ids []string) { for id := range m.removeddaily_items { ids = append(ids, id) } return } // DailyItemsIDs returns the "daily_items" edge IDs in the mutation. func (m *CategoryMutation) DailyItemsIDs() (ids []string) { for id := range m.daily_items { ids = append(ids, id) } return } // ResetDailyItems resets all changes to the "daily_items" edge. func (m *CategoryMutation) ResetDailyItems() { m.daily_items = nil m.cleareddaily_items = false m.removeddaily_items = 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, 2) if m.created_at != nil { fields = append(fields, category.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, category.FieldUpdatedAt) } 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() } 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) } 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 } 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 { return nil } // 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 { 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 } 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, 3) if m.contents != nil { edges = append(edges, category.EdgeContents) } if m.posts != nil { edges = append(edges, category.EdgePosts) } if m.daily_items != nil { edges = append(edges, category.EdgeDailyItems) } 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.EdgeContents: ids := make([]ent.Value, 0, len(m.contents)) for id := range m.contents { ids = append(ids, id) } return ids case category.EdgePosts: ids := make([]ent.Value, 0, len(m.posts)) for id := range m.posts { ids = append(ids, id) } return ids case category.EdgeDailyItems: ids := make([]ent.Value, 0, len(m.daily_items)) for id := range m.daily_items { 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, 3) if m.removedcontents != nil { edges = append(edges, category.EdgeContents) } if m.removedposts != nil { edges = append(edges, category.EdgePosts) } if m.removeddaily_items != nil { edges = append(edges, category.EdgeDailyItems) } 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.EdgeContents: ids := make([]ent.Value, 0, len(m.removedcontents)) for id := range m.removedcontents { ids = append(ids, id) } return ids case category.EdgePosts: ids := make([]ent.Value, 0, len(m.removedposts)) for id := range m.removedposts { ids = append(ids, id) } return ids case category.EdgeDailyItems: ids := make([]ent.Value, 0, len(m.removeddaily_items)) for id := range m.removeddaily_items { 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, 3) if m.clearedcontents { edges = append(edges, category.EdgeContents) } if m.clearedposts { edges = append(edges, category.EdgePosts) } if m.cleareddaily_items { edges = append(edges, category.EdgeDailyItems) } 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.EdgeContents: return m.clearedcontents case category.EdgePosts: return m.clearedposts case category.EdgeDailyItems: return m.cleareddaily_items } 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.EdgeContents: m.ResetContents() return nil case category.EdgePosts: m.ResetPosts() return nil case category.EdgeDailyItems: m.ResetDailyItems() return nil } return fmt.Errorf("unknown Category edge %s", name) } // CategoryContentMutation represents an operation that mutates the CategoryContent nodes in the graph. type CategoryContentMutation struct { config op Op typ string id *int language_code *categorycontent.LanguageCode name *string description *string slug *string clearedFields map[string]struct{} category *int clearedcategory bool done bool oldValue func(context.Context) (*CategoryContent, error) predicates []predicate.CategoryContent } var _ ent.Mutation = (*CategoryContentMutation)(nil) // categorycontentOption allows management of the mutation configuration using functional options. type categorycontentOption func(*CategoryContentMutation) // newCategoryContentMutation creates new mutation for the CategoryContent entity. func newCategoryContentMutation(c config, op Op, opts ...categorycontentOption) *CategoryContentMutation { m := &CategoryContentMutation{ config: c, op: op, typ: TypeCategoryContent, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withCategoryContentID sets the ID field of the mutation. func withCategoryContentID(id int) categorycontentOption { return func(m *CategoryContentMutation) { var ( err error once sync.Once value *CategoryContent ) m.oldValue = func(ctx context.Context) (*CategoryContent, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().CategoryContent.Get(ctx, id) } }) return value, err } m.id = &id } } // withCategoryContent sets the old CategoryContent of the mutation. func withCategoryContent(node *CategoryContent) categorycontentOption { return func(m *CategoryContentMutation) { m.oldValue = func(context.Context) (*CategoryContent, 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 CategoryContentMutation) 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 CategoryContentMutation) 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 } // 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 *CategoryContentMutation) ID() (id int, 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 *CategoryContentMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().CategoryContent.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetLanguageCode sets the "language_code" field. func (m *CategoryContentMutation) SetLanguageCode(cc categorycontent.LanguageCode) { m.language_code = &cc } // LanguageCode returns the value of the "language_code" field in the mutation. func (m *CategoryContentMutation) LanguageCode() (r categorycontent.LanguageCode, exists bool) { v := m.language_code if v == nil { return } return *v, true } // OldLanguageCode returns the old "language_code" field's value of the CategoryContent entity. // If the CategoryContent 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 *CategoryContentMutation) OldLanguageCode(ctx context.Context) (v categorycontent.LanguageCode, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLanguageCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLanguageCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLanguageCode: %w", err) } return oldValue.LanguageCode, nil } // ResetLanguageCode resets all changes to the "language_code" field. func (m *CategoryContentMutation) ResetLanguageCode() { m.language_code = nil } // SetName sets the "name" field. func (m *CategoryContentMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *CategoryContentMutation) 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 CategoryContent entity. // If the CategoryContent 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 *CategoryContentMutation) 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 } // ResetName resets all changes to the "name" field. func (m *CategoryContentMutation) ResetName() { m.name = nil } // SetDescription sets the "description" field. func (m *CategoryContentMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *CategoryContentMutation) 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 CategoryContent entity. // If the CategoryContent 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 *CategoryContentMutation) 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 *CategoryContentMutation) ClearDescription() { m.description = nil m.clearedFields[categorycontent.FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *CategoryContentMutation) DescriptionCleared() bool { _, ok := m.clearedFields[categorycontent.FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *CategoryContentMutation) ResetDescription() { m.description = nil delete(m.clearedFields, categorycontent.FieldDescription) } // SetSlug sets the "slug" field. func (m *CategoryContentMutation) SetSlug(s string) { m.slug = &s } // Slug returns the value of the "slug" field in the mutation. func (m *CategoryContentMutation) Slug() (r string, exists bool) { v := m.slug if v == nil { return } return *v, true } // OldSlug returns the old "slug" field's value of the CategoryContent entity. // If the CategoryContent 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 *CategoryContentMutation) OldSlug(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSlug is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSlug requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSlug: %w", err) } return oldValue.Slug, nil } // ResetSlug resets all changes to the "slug" field. func (m *CategoryContentMutation) ResetSlug() { m.slug = nil } // SetCategoryID sets the "category" edge to the Category entity by id. func (m *CategoryContentMutation) SetCategoryID(id int) { m.category = &id } // ClearCategory clears the "category" edge to the Category entity. func (m *CategoryContentMutation) ClearCategory() { m.clearedcategory = true } // CategoryCleared reports if the "category" edge to the Category entity was cleared. func (m *CategoryContentMutation) CategoryCleared() bool { return m.clearedcategory } // CategoryID returns the "category" edge ID in the mutation. func (m *CategoryContentMutation) CategoryID() (id int, 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 *CategoryContentMutation) CategoryIDs() (ids []int) { if id := m.category; id != nil { ids = append(ids, *id) } return } // ResetCategory resets all changes to the "category" edge. func (m *CategoryContentMutation) ResetCategory() { m.category = nil m.clearedcategory = false } // Where appends a list predicates to the CategoryContentMutation builder. func (m *CategoryContentMutation) Where(ps ...predicate.CategoryContent) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the CategoryContentMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *CategoryContentMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.CategoryContent, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *CategoryContentMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *CategoryContentMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (CategoryContent). func (m *CategoryContentMutation) 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 *CategoryContentMutation) Fields() []string { fields := make([]string, 0, 4) if m.language_code != nil { fields = append(fields, categorycontent.FieldLanguageCode) } if m.name != nil { fields = append(fields, categorycontent.FieldName) } if m.description != nil { fields = append(fields, categorycontent.FieldDescription) } if m.slug != nil { fields = append(fields, categorycontent.FieldSlug) } 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 *CategoryContentMutation) Field(name string) (ent.Value, bool) { switch name { case categorycontent.FieldLanguageCode: return m.LanguageCode() case categorycontent.FieldName: return m.Name() case categorycontent.FieldDescription: return m.Description() case categorycontent.FieldSlug: return m.Slug() } 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 *CategoryContentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case categorycontent.FieldLanguageCode: return m.OldLanguageCode(ctx) case categorycontent.FieldName: return m.OldName(ctx) case categorycontent.FieldDescription: return m.OldDescription(ctx) case categorycontent.FieldSlug: return m.OldSlug(ctx) } return nil, fmt.Errorf("unknown CategoryContent 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 *CategoryContentMutation) SetField(name string, value ent.Value) error { switch name { case categorycontent.FieldLanguageCode: v, ok := value.(categorycontent.LanguageCode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLanguageCode(v) return nil case categorycontent.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case categorycontent.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case categorycontent.FieldSlug: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSlug(v) return nil } return fmt.Errorf("unknown CategoryContent field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *CategoryContentMutation) 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 *CategoryContentMutation) 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 *CategoryContentMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown CategoryContent numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *CategoryContentMutation) ClearedFields() []string { var fields []string if m.FieldCleared(categorycontent.FieldDescription) { fields = append(fields, categorycontent.FieldDescription) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *CategoryContentMutation) 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 *CategoryContentMutation) ClearField(name string) error { switch name { case categorycontent.FieldDescription: m.ClearDescription() return nil } return fmt.Errorf("unknown CategoryContent 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 *CategoryContentMutation) ResetField(name string) error { switch name { case categorycontent.FieldLanguageCode: m.ResetLanguageCode() return nil case categorycontent.FieldName: m.ResetName() return nil case categorycontent.FieldDescription: m.ResetDescription() return nil case categorycontent.FieldSlug: m.ResetSlug() return nil } return fmt.Errorf("unknown CategoryContent field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *CategoryContentMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.category != nil { edges = append(edges, categorycontent.EdgeCategory) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *CategoryContentMutation) AddedIDs(name string) []ent.Value { switch name { case categorycontent.EdgeCategory: if id := m.category; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *CategoryContentMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *CategoryContentMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *CategoryContentMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedcategory { edges = append(edges, categorycontent.EdgeCategory) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *CategoryContentMutation) EdgeCleared(name string) bool { switch name { case categorycontent.EdgeCategory: return m.clearedcategory } 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 *CategoryContentMutation) ClearEdge(name string) error { switch name { case categorycontent.EdgeCategory: m.ClearCategory() return nil } return fmt.Errorf("unknown CategoryContent 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 *CategoryContentMutation) ResetEdge(name string) error { switch name { case categorycontent.EdgeCategory: m.ResetCategory() return nil } return fmt.Errorf("unknown CategoryContent edge %s", name) } // ContributorMutation represents an operation that mutates the Contributor nodes in the graph. type ContributorMutation struct { config op Op typ string id *int name *string avatar_url *string bio *string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} user *int cleareduser bool social_links map[int]struct{} removedsocial_links map[int]struct{} clearedsocial_links bool posts map[int]struct{} removedposts map[int]struct{} clearedposts bool done bool oldValue func(context.Context) (*Contributor, error) predicates []predicate.Contributor } var _ ent.Mutation = (*ContributorMutation)(nil) // contributorOption allows management of the mutation configuration using functional options. type contributorOption func(*ContributorMutation) // newContributorMutation creates new mutation for the Contributor entity. func newContributorMutation(c config, op Op, opts ...contributorOption) *ContributorMutation { m := &ContributorMutation{ config: c, op: op, typ: TypeContributor, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withContributorID sets the ID field of the mutation. func withContributorID(id int) contributorOption { return func(m *ContributorMutation) { var ( err error once sync.Once value *Contributor ) m.oldValue = func(ctx context.Context) (*Contributor, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Contributor.Get(ctx, id) } }) return value, err } m.id = &id } } // withContributor sets the old Contributor of the mutation. func withContributor(node *Contributor) contributorOption { return func(m *ContributorMutation) { m.oldValue = func(context.Context) (*Contributor, 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 ContributorMutation) 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 ContributorMutation) 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 } // 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 *ContributorMutation) ID() (id int, 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 *ContributorMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Contributor.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetName sets the "name" field. func (m *ContributorMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *ContributorMutation) 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 Contributor entity. // If the Contributor 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 *ContributorMutation) 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 } // ResetName resets all changes to the "name" field. func (m *ContributorMutation) ResetName() { m.name = nil } // SetAvatarURL sets the "avatar_url" field. func (m *ContributorMutation) SetAvatarURL(s string) { m.avatar_url = &s } // AvatarURL returns the value of the "avatar_url" field in the mutation. func (m *ContributorMutation) AvatarURL() (r string, exists bool) { v := m.avatar_url if v == nil { return } return *v, true } // OldAvatarURL returns the old "avatar_url" field's value of the Contributor entity. // If the Contributor 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 *ContributorMutation) OldAvatarURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAvatarURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAvatarURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAvatarURL: %w", err) } return oldValue.AvatarURL, nil } // ClearAvatarURL clears the value of the "avatar_url" field. func (m *ContributorMutation) ClearAvatarURL() { m.avatar_url = nil m.clearedFields[contributor.FieldAvatarURL] = struct{}{} } // AvatarURLCleared returns if the "avatar_url" field was cleared in this mutation. func (m *ContributorMutation) AvatarURLCleared() bool { _, ok := m.clearedFields[contributor.FieldAvatarURL] return ok } // ResetAvatarURL resets all changes to the "avatar_url" field. func (m *ContributorMutation) ResetAvatarURL() { m.avatar_url = nil delete(m.clearedFields, contributor.FieldAvatarURL) } // SetBio sets the "bio" field. func (m *ContributorMutation) SetBio(s string) { m.bio = &s } // Bio returns the value of the "bio" field in the mutation. func (m *ContributorMutation) Bio() (r string, exists bool) { v := m.bio if v == nil { return } return *v, true } // OldBio returns the old "bio" field's value of the Contributor entity. // If the Contributor 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 *ContributorMutation) OldBio(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldBio is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldBio requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldBio: %w", err) } return oldValue.Bio, nil } // ClearBio clears the value of the "bio" field. func (m *ContributorMutation) ClearBio() { m.bio = nil m.clearedFields[contributor.FieldBio] = struct{}{} } // BioCleared returns if the "bio" field was cleared in this mutation. func (m *ContributorMutation) BioCleared() bool { _, ok := m.clearedFields[contributor.FieldBio] return ok } // ResetBio resets all changes to the "bio" field. func (m *ContributorMutation) ResetBio() { m.bio = nil delete(m.clearedFields, contributor.FieldBio) } // SetCreatedAt sets the "created_at" field. func (m *ContributorMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *ContributorMutation) 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 Contributor entity. // If the Contributor 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 *ContributorMutation) 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 *ContributorMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *ContributorMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *ContributorMutation) 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 Contributor entity. // If the Contributor 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 *ContributorMutation) 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 } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *ContributorMutation) ResetUpdatedAt() { m.updated_at = nil } // SetUserID sets the "user" edge to the User entity by id. func (m *ContributorMutation) SetUserID(id int) { m.user = &id } // ClearUser clears the "user" edge to the User entity. func (m *ContributorMutation) ClearUser() { m.cleareduser = true } // UserCleared reports if the "user" edge to the User entity was cleared. func (m *ContributorMutation) UserCleared() bool { return m.cleareduser } // UserID returns the "user" edge ID in the mutation. func (m *ContributorMutation) UserID() (id int, exists bool) { if m.user != nil { return *m.user, true } return } // UserIDs returns the "user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UserID instead. It exists only for internal usage by the builders. func (m *ContributorMutation) UserIDs() (ids []int) { if id := m.user; id != nil { ids = append(ids, *id) } return } // ResetUser resets all changes to the "user" edge. func (m *ContributorMutation) ResetUser() { m.user = nil m.cleareduser = false } // AddSocialLinkIDs adds the "social_links" edge to the ContributorSocialLink entity by ids. func (m *ContributorMutation) AddSocialLinkIDs(ids ...int) { if m.social_links == nil { m.social_links = make(map[int]struct{}) } for i := range ids { m.social_links[ids[i]] = struct{}{} } } // ClearSocialLinks clears the "social_links" edge to the ContributorSocialLink entity. func (m *ContributorMutation) ClearSocialLinks() { m.clearedsocial_links = true } // SocialLinksCleared reports if the "social_links" edge to the ContributorSocialLink entity was cleared. func (m *ContributorMutation) SocialLinksCleared() bool { return m.clearedsocial_links } // RemoveSocialLinkIDs removes the "social_links" edge to the ContributorSocialLink entity by IDs. func (m *ContributorMutation) RemoveSocialLinkIDs(ids ...int) { if m.removedsocial_links == nil { m.removedsocial_links = make(map[int]struct{}) } for i := range ids { delete(m.social_links, ids[i]) m.removedsocial_links[ids[i]] = struct{}{} } } // RemovedSocialLinks returns the removed IDs of the "social_links" edge to the ContributorSocialLink entity. func (m *ContributorMutation) RemovedSocialLinksIDs() (ids []int) { for id := range m.removedsocial_links { ids = append(ids, id) } return } // SocialLinksIDs returns the "social_links" edge IDs in the mutation. func (m *ContributorMutation) SocialLinksIDs() (ids []int) { for id := range m.social_links { ids = append(ids, id) } return } // ResetSocialLinks resets all changes to the "social_links" edge. func (m *ContributorMutation) ResetSocialLinks() { m.social_links = nil m.clearedsocial_links = false m.removedsocial_links = nil } // AddPostIDs adds the "posts" edge to the PostContributor entity by ids. func (m *ContributorMutation) AddPostIDs(ids ...int) { if m.posts == nil { m.posts = make(map[int]struct{}) } for i := range ids { m.posts[ids[i]] = struct{}{} } } // ClearPosts clears the "posts" edge to the PostContributor entity. func (m *ContributorMutation) ClearPosts() { m.clearedposts = true } // PostsCleared reports if the "posts" edge to the PostContributor entity was cleared. func (m *ContributorMutation) PostsCleared() bool { return m.clearedposts } // RemovePostIDs removes the "posts" edge to the PostContributor entity by IDs. func (m *ContributorMutation) RemovePostIDs(ids ...int) { if m.removedposts == nil { m.removedposts = make(map[int]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 PostContributor entity. func (m *ContributorMutation) RemovedPostsIDs() (ids []int) { for id := range m.removedposts { ids = append(ids, id) } return } // PostsIDs returns the "posts" edge IDs in the mutation. func (m *ContributorMutation) PostsIDs() (ids []int) { for id := range m.posts { ids = append(ids, id) } return } // ResetPosts resets all changes to the "posts" edge. func (m *ContributorMutation) ResetPosts() { m.posts = nil m.clearedposts = false m.removedposts = nil } // Where appends a list predicates to the ContributorMutation builder. func (m *ContributorMutation) Where(ps ...predicate.Contributor) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the ContributorMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *ContributorMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Contributor, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *ContributorMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *ContributorMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Contributor). func (m *ContributorMutation) 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 *ContributorMutation) Fields() []string { fields := make([]string, 0, 5) if m.name != nil { fields = append(fields, contributor.FieldName) } if m.avatar_url != nil { fields = append(fields, contributor.FieldAvatarURL) } if m.bio != nil { fields = append(fields, contributor.FieldBio) } if m.created_at != nil { fields = append(fields, contributor.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, contributor.FieldUpdatedAt) } 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 *ContributorMutation) Field(name string) (ent.Value, bool) { switch name { case contributor.FieldName: return m.Name() case contributor.FieldAvatarURL: return m.AvatarURL() case contributor.FieldBio: return m.Bio() case contributor.FieldCreatedAt: return m.CreatedAt() case contributor.FieldUpdatedAt: return m.UpdatedAt() } 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 *ContributorMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case contributor.FieldName: return m.OldName(ctx) case contributor.FieldAvatarURL: return m.OldAvatarURL(ctx) case contributor.FieldBio: return m.OldBio(ctx) case contributor.FieldCreatedAt: return m.OldCreatedAt(ctx) case contributor.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Contributor 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 *ContributorMutation) SetField(name string, value ent.Value) error { switch name { case contributor.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case contributor.FieldAvatarURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAvatarURL(v) return nil case contributor.FieldBio: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetBio(v) return nil case contributor.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 contributor.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Contributor field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *ContributorMutation) 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 *ContributorMutation) 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 *ContributorMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Contributor numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ContributorMutation) ClearedFields() []string { var fields []string if m.FieldCleared(contributor.FieldAvatarURL) { fields = append(fields, contributor.FieldAvatarURL) } if m.FieldCleared(contributor.FieldBio) { fields = append(fields, contributor.FieldBio) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *ContributorMutation) 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 *ContributorMutation) ClearField(name string) error { switch name { case contributor.FieldAvatarURL: m.ClearAvatarURL() return nil case contributor.FieldBio: m.ClearBio() return nil } return fmt.Errorf("unknown Contributor 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 *ContributorMutation) ResetField(name string) error { switch name { case contributor.FieldName: m.ResetName() return nil case contributor.FieldAvatarURL: m.ResetAvatarURL() return nil case contributor.FieldBio: m.ResetBio() return nil case contributor.FieldCreatedAt: m.ResetCreatedAt() return nil case contributor.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Contributor field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ContributorMutation) AddedEdges() []string { edges := make([]string, 0, 3) if m.user != nil { edges = append(edges, contributor.EdgeUser) } if m.social_links != nil { edges = append(edges, contributor.EdgeSocialLinks) } if m.posts != nil { edges = append(edges, contributor.EdgePosts) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *ContributorMutation) AddedIDs(name string) []ent.Value { switch name { case contributor.EdgeUser: if id := m.user; id != nil { return []ent.Value{*id} } case contributor.EdgeSocialLinks: ids := make([]ent.Value, 0, len(m.social_links)) for id := range m.social_links { ids = append(ids, id) } return ids case contributor.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 *ContributorMutation) RemovedEdges() []string { edges := make([]string, 0, 3) if m.removedsocial_links != nil { edges = append(edges, contributor.EdgeSocialLinks) } if m.removedposts != nil { edges = append(edges, contributor.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 *ContributorMutation) RemovedIDs(name string) []ent.Value { switch name { case contributor.EdgeSocialLinks: ids := make([]ent.Value, 0, len(m.removedsocial_links)) for id := range m.removedsocial_links { ids = append(ids, id) } return ids case contributor.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 *ContributorMutation) ClearedEdges() []string { edges := make([]string, 0, 3) if m.cleareduser { edges = append(edges, contributor.EdgeUser) } if m.clearedsocial_links { edges = append(edges, contributor.EdgeSocialLinks) } if m.clearedposts { edges = append(edges, contributor.EdgePosts) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *ContributorMutation) EdgeCleared(name string) bool { switch name { case contributor.EdgeUser: return m.cleareduser case contributor.EdgeSocialLinks: return m.clearedsocial_links case contributor.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 *ContributorMutation) ClearEdge(name string) error { switch name { case contributor.EdgeUser: m.ClearUser() return nil } return fmt.Errorf("unknown Contributor 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 *ContributorMutation) ResetEdge(name string) error { switch name { case contributor.EdgeUser: m.ResetUser() return nil case contributor.EdgeSocialLinks: m.ResetSocialLinks() return nil case contributor.EdgePosts: m.ResetPosts() return nil } return fmt.Errorf("unknown Contributor edge %s", name) } // ContributorRoleMutation represents an operation that mutates the ContributorRole nodes in the graph. type ContributorRoleMutation struct { config op Op typ string id *int name *string clearedFields map[string]struct{} post_contributors map[int]struct{} removedpost_contributors map[int]struct{} clearedpost_contributors bool done bool oldValue func(context.Context) (*ContributorRole, error) predicates []predicate.ContributorRole } var _ ent.Mutation = (*ContributorRoleMutation)(nil) // contributorroleOption allows management of the mutation configuration using functional options. type contributorroleOption func(*ContributorRoleMutation) // newContributorRoleMutation creates new mutation for the ContributorRole entity. func newContributorRoleMutation(c config, op Op, opts ...contributorroleOption) *ContributorRoleMutation { m := &ContributorRoleMutation{ config: c, op: op, typ: TypeContributorRole, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withContributorRoleID sets the ID field of the mutation. func withContributorRoleID(id int) contributorroleOption { return func(m *ContributorRoleMutation) { var ( err error once sync.Once value *ContributorRole ) m.oldValue = func(ctx context.Context) (*ContributorRole, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().ContributorRole.Get(ctx, id) } }) return value, err } m.id = &id } } // withContributorRole sets the old ContributorRole of the mutation. func withContributorRole(node *ContributorRole) contributorroleOption { return func(m *ContributorRoleMutation) { m.oldValue = func(context.Context) (*ContributorRole, 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 ContributorRoleMutation) 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 ContributorRoleMutation) 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 } // 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 *ContributorRoleMutation) ID() (id int, 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 *ContributorRoleMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().ContributorRole.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetName sets the "name" field. func (m *ContributorRoleMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *ContributorRoleMutation) 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 ContributorRole entity. // If the ContributorRole 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 *ContributorRoleMutation) 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 } // ResetName resets all changes to the "name" field. func (m *ContributorRoleMutation) ResetName() { m.name = nil } // AddPostContributorIDs adds the "post_contributors" edge to the PostContributor entity by ids. func (m *ContributorRoleMutation) AddPostContributorIDs(ids ...int) { if m.post_contributors == nil { m.post_contributors = make(map[int]struct{}) } for i := range ids { m.post_contributors[ids[i]] = struct{}{} } } // ClearPostContributors clears the "post_contributors" edge to the PostContributor entity. func (m *ContributorRoleMutation) ClearPostContributors() { m.clearedpost_contributors = true } // PostContributorsCleared reports if the "post_contributors" edge to the PostContributor entity was cleared. func (m *ContributorRoleMutation) PostContributorsCleared() bool { return m.clearedpost_contributors } // RemovePostContributorIDs removes the "post_contributors" edge to the PostContributor entity by IDs. func (m *ContributorRoleMutation) RemovePostContributorIDs(ids ...int) { if m.removedpost_contributors == nil { m.removedpost_contributors = make(map[int]struct{}) } for i := range ids { delete(m.post_contributors, ids[i]) m.removedpost_contributors[ids[i]] = struct{}{} } } // RemovedPostContributors returns the removed IDs of the "post_contributors" edge to the PostContributor entity. func (m *ContributorRoleMutation) RemovedPostContributorsIDs() (ids []int) { for id := range m.removedpost_contributors { ids = append(ids, id) } return } // PostContributorsIDs returns the "post_contributors" edge IDs in the mutation. func (m *ContributorRoleMutation) PostContributorsIDs() (ids []int) { for id := range m.post_contributors { ids = append(ids, id) } return } // ResetPostContributors resets all changes to the "post_contributors" edge. func (m *ContributorRoleMutation) ResetPostContributors() { m.post_contributors = nil m.clearedpost_contributors = false m.removedpost_contributors = nil } // Where appends a list predicates to the ContributorRoleMutation builder. func (m *ContributorRoleMutation) Where(ps ...predicate.ContributorRole) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the ContributorRoleMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *ContributorRoleMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.ContributorRole, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *ContributorRoleMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *ContributorRoleMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (ContributorRole). func (m *ContributorRoleMutation) 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 *ContributorRoleMutation) Fields() []string { fields := make([]string, 0, 1) if m.name != nil { fields = append(fields, contributorrole.FieldName) } 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 *ContributorRoleMutation) Field(name string) (ent.Value, bool) { switch name { case contributorrole.FieldName: return m.Name() } 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 *ContributorRoleMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case contributorrole.FieldName: return m.OldName(ctx) } return nil, fmt.Errorf("unknown ContributorRole 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 *ContributorRoleMutation) SetField(name string, value ent.Value) error { switch name { case contributorrole.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil } return fmt.Errorf("unknown ContributorRole field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *ContributorRoleMutation) 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 *ContributorRoleMutation) 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 *ContributorRoleMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown ContributorRole numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ContributorRoleMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *ContributorRoleMutation) 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 *ContributorRoleMutation) ClearField(name string) error { return fmt.Errorf("unknown ContributorRole 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 *ContributorRoleMutation) ResetField(name string) error { switch name { case contributorrole.FieldName: m.ResetName() return nil } return fmt.Errorf("unknown ContributorRole field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ContributorRoleMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.post_contributors != nil { edges = append(edges, contributorrole.EdgePostContributors) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *ContributorRoleMutation) AddedIDs(name string) []ent.Value { switch name { case contributorrole.EdgePostContributors: ids := make([]ent.Value, 0, len(m.post_contributors)) for id := range m.post_contributors { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *ContributorRoleMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedpost_contributors != nil { edges = append(edges, contributorrole.EdgePostContributors) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *ContributorRoleMutation) RemovedIDs(name string) []ent.Value { switch name { case contributorrole.EdgePostContributors: ids := make([]ent.Value, 0, len(m.removedpost_contributors)) for id := range m.removedpost_contributors { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ContributorRoleMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedpost_contributors { edges = append(edges, contributorrole.EdgePostContributors) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *ContributorRoleMutation) EdgeCleared(name string) bool { switch name { case contributorrole.EdgePostContributors: return m.clearedpost_contributors } 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 *ContributorRoleMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown ContributorRole 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 *ContributorRoleMutation) ResetEdge(name string) error { switch name { case contributorrole.EdgePostContributors: m.ResetPostContributors() return nil } return fmt.Errorf("unknown ContributorRole edge %s", name) } // ContributorSocialLinkMutation represents an operation that mutates the ContributorSocialLink nodes in the graph. type ContributorSocialLinkMutation struct { config op Op typ string id *int _type *contributorsociallink.Type name *string value *string clearedFields map[string]struct{} contributor *int clearedcontributor bool done bool oldValue func(context.Context) (*ContributorSocialLink, error) predicates []predicate.ContributorSocialLink } var _ ent.Mutation = (*ContributorSocialLinkMutation)(nil) // contributorsociallinkOption allows management of the mutation configuration using functional options. type contributorsociallinkOption func(*ContributorSocialLinkMutation) // newContributorSocialLinkMutation creates new mutation for the ContributorSocialLink entity. func newContributorSocialLinkMutation(c config, op Op, opts ...contributorsociallinkOption) *ContributorSocialLinkMutation { m := &ContributorSocialLinkMutation{ config: c, op: op, typ: TypeContributorSocialLink, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withContributorSocialLinkID sets the ID field of the mutation. func withContributorSocialLinkID(id int) contributorsociallinkOption { return func(m *ContributorSocialLinkMutation) { var ( err error once sync.Once value *ContributorSocialLink ) m.oldValue = func(ctx context.Context) (*ContributorSocialLink, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().ContributorSocialLink.Get(ctx, id) } }) return value, err } m.id = &id } } // withContributorSocialLink sets the old ContributorSocialLink of the mutation. func withContributorSocialLink(node *ContributorSocialLink) contributorsociallinkOption { return func(m *ContributorSocialLinkMutation) { m.oldValue = func(context.Context) (*ContributorSocialLink, 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 ContributorSocialLinkMutation) 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 ContributorSocialLinkMutation) 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 } // 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 *ContributorSocialLinkMutation) ID() (id int, 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 *ContributorSocialLinkMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().ContributorSocialLink.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetType sets the "type" field. func (m *ContributorSocialLinkMutation) SetType(c contributorsociallink.Type) { m._type = &c } // GetType returns the value of the "type" field in the mutation. func (m *ContributorSocialLinkMutation) GetType() (r contributorsociallink.Type, exists bool) { v := m._type if v == nil { return } return *v, true } // OldType returns the old "type" field's value of the ContributorSocialLink entity. // If the ContributorSocialLink 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 *ContributorSocialLinkMutation) OldType(ctx context.Context) (v contributorsociallink.Type, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldType: %w", err) } return oldValue.Type, nil } // ResetType resets all changes to the "type" field. func (m *ContributorSocialLinkMutation) ResetType() { m._type = nil } // SetName sets the "name" field. func (m *ContributorSocialLinkMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *ContributorSocialLinkMutation) 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 ContributorSocialLink entity. // If the ContributorSocialLink 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 *ContributorSocialLinkMutation) 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 *ContributorSocialLinkMutation) ClearName() { m.name = nil m.clearedFields[contributorsociallink.FieldName] = struct{}{} } // NameCleared returns if the "name" field was cleared in this mutation. func (m *ContributorSocialLinkMutation) NameCleared() bool { _, ok := m.clearedFields[contributorsociallink.FieldName] return ok } // ResetName resets all changes to the "name" field. func (m *ContributorSocialLinkMutation) ResetName() { m.name = nil delete(m.clearedFields, contributorsociallink.FieldName) } // SetValue sets the "value" field. func (m *ContributorSocialLinkMutation) SetValue(s string) { m.value = &s } // Value returns the value of the "value" field in the mutation. func (m *ContributorSocialLinkMutation) Value() (r string, exists bool) { v := m.value if v == nil { return } return *v, true } // OldValue returns the old "value" field's value of the ContributorSocialLink entity. // If the ContributorSocialLink 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 *ContributorSocialLinkMutation) OldValue(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldValue is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldValue requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldValue: %w", err) } return oldValue.Value, nil } // ResetValue resets all changes to the "value" field. func (m *ContributorSocialLinkMutation) ResetValue() { m.value = nil } // SetContributorID sets the "contributor" edge to the Contributor entity by id. func (m *ContributorSocialLinkMutation) SetContributorID(id int) { m.contributor = &id } // ClearContributor clears the "contributor" edge to the Contributor entity. func (m *ContributorSocialLinkMutation) ClearContributor() { m.clearedcontributor = true } // ContributorCleared reports if the "contributor" edge to the Contributor entity was cleared. func (m *ContributorSocialLinkMutation) ContributorCleared() bool { return m.clearedcontributor } // ContributorID returns the "contributor" edge ID in the mutation. func (m *ContributorSocialLinkMutation) ContributorID() (id int, exists bool) { if m.contributor != nil { return *m.contributor, true } return } // ContributorIDs returns the "contributor" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // ContributorID instead. It exists only for internal usage by the builders. func (m *ContributorSocialLinkMutation) ContributorIDs() (ids []int) { if id := m.contributor; id != nil { ids = append(ids, *id) } return } // ResetContributor resets all changes to the "contributor" edge. func (m *ContributorSocialLinkMutation) ResetContributor() { m.contributor = nil m.clearedcontributor = false } // Where appends a list predicates to the ContributorSocialLinkMutation builder. func (m *ContributorSocialLinkMutation) Where(ps ...predicate.ContributorSocialLink) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the ContributorSocialLinkMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *ContributorSocialLinkMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.ContributorSocialLink, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *ContributorSocialLinkMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *ContributorSocialLinkMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (ContributorSocialLink). func (m *ContributorSocialLinkMutation) 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 *ContributorSocialLinkMutation) Fields() []string { fields := make([]string, 0, 3) if m._type != nil { fields = append(fields, contributorsociallink.FieldType) } if m.name != nil { fields = append(fields, contributorsociallink.FieldName) } if m.value != nil { fields = append(fields, contributorsociallink.FieldValue) } 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 *ContributorSocialLinkMutation) Field(name string) (ent.Value, bool) { switch name { case contributorsociallink.FieldType: return m.GetType() case contributorsociallink.FieldName: return m.Name() case contributorsociallink.FieldValue: return m.Value() } 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 *ContributorSocialLinkMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case contributorsociallink.FieldType: return m.OldType(ctx) case contributorsociallink.FieldName: return m.OldName(ctx) case contributorsociallink.FieldValue: return m.OldValue(ctx) } return nil, fmt.Errorf("unknown ContributorSocialLink 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 *ContributorSocialLinkMutation) SetField(name string, value ent.Value) error { switch name { case contributorsociallink.FieldType: v, ok := value.(contributorsociallink.Type) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetType(v) return nil case contributorsociallink.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case contributorsociallink.FieldValue: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetValue(v) return nil } return fmt.Errorf("unknown ContributorSocialLink field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *ContributorSocialLinkMutation) 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 *ContributorSocialLinkMutation) 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 *ContributorSocialLinkMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown ContributorSocialLink numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ContributorSocialLinkMutation) ClearedFields() []string { var fields []string if m.FieldCleared(contributorsociallink.FieldName) { fields = append(fields, contributorsociallink.FieldName) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *ContributorSocialLinkMutation) 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 *ContributorSocialLinkMutation) ClearField(name string) error { switch name { case contributorsociallink.FieldName: m.ClearName() return nil } return fmt.Errorf("unknown ContributorSocialLink 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 *ContributorSocialLinkMutation) ResetField(name string) error { switch name { case contributorsociallink.FieldType: m.ResetType() return nil case contributorsociallink.FieldName: m.ResetName() return nil case contributorsociallink.FieldValue: m.ResetValue() return nil } return fmt.Errorf("unknown ContributorSocialLink field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ContributorSocialLinkMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.contributor != nil { edges = append(edges, contributorsociallink.EdgeContributor) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *ContributorSocialLinkMutation) AddedIDs(name string) []ent.Value { switch name { case contributorsociallink.EdgeContributor: if id := m.contributor; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *ContributorSocialLinkMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *ContributorSocialLinkMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ContributorSocialLinkMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedcontributor { edges = append(edges, contributorsociallink.EdgeContributor) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *ContributorSocialLinkMutation) EdgeCleared(name string) bool { switch name { case contributorsociallink.EdgeContributor: return m.clearedcontributor } 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 *ContributorSocialLinkMutation) ClearEdge(name string) error { switch name { case contributorsociallink.EdgeContributor: m.ClearContributor() return nil } return fmt.Errorf("unknown ContributorSocialLink 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 *ContributorSocialLinkMutation) ResetEdge(name string) error { switch name { case contributorsociallink.EdgeContributor: m.ResetContributor() return nil } return fmt.Errorf("unknown ContributorSocialLink edge %s", name) } // DailyMutation represents an operation that mutates the Daily nodes in the graph. type DailyMutation struct { config op Op typ string id *string image_url *string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} category *int clearedcategory bool contents map[int]struct{} removedcontents map[int]struct{} clearedcontents bool done bool oldValue func(context.Context) (*Daily, error) predicates []predicate.Daily } var _ ent.Mutation = (*DailyMutation)(nil) // dailyOption allows management of the mutation configuration using functional options. type dailyOption func(*DailyMutation) // newDailyMutation creates new mutation for the Daily entity. func newDailyMutation(c config, op Op, opts ...dailyOption) *DailyMutation { m := &DailyMutation{ config: c, op: op, typ: TypeDaily, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withDailyID sets the ID field of the mutation. func withDailyID(id string) dailyOption { return func(m *DailyMutation) { var ( err error once sync.Once value *Daily ) m.oldValue = func(ctx context.Context) (*Daily, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Daily.Get(ctx, id) } }) return value, err } m.id = &id } } // withDaily sets the old Daily of the mutation. func withDaily(node *Daily) dailyOption { return func(m *DailyMutation) { m.oldValue = func(context.Context) (*Daily, 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 DailyMutation) 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 DailyMutation) 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 Daily entities. func (m *DailyMutation) SetID(id string) { 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 *DailyMutation) ID() (id string, 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 *DailyMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Daily.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetImageURL sets the "image_url" field. func (m *DailyMutation) SetImageURL(s string) { m.image_url = &s } // ImageURL returns the value of the "image_url" field in the mutation. func (m *DailyMutation) ImageURL() (r string, exists bool) { v := m.image_url if v == nil { return } return *v, true } // OldImageURL returns the old "image_url" field's value of the Daily entity. // If the Daily 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 *DailyMutation) OldImageURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldImageURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldImageURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldImageURL: %w", err) } return oldValue.ImageURL, nil } // ResetImageURL resets all changes to the "image_url" field. func (m *DailyMutation) ResetImageURL() { m.image_url = nil } // SetCreatedAt sets the "created_at" field. func (m *DailyMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *DailyMutation) 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 Daily entity. // If the Daily 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 *DailyMutation) 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 *DailyMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *DailyMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *DailyMutation) 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 Daily entity. // If the Daily 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 *DailyMutation) 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 } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *DailyMutation) ResetUpdatedAt() { m.updated_at = nil } // SetCategoryID sets the "category" edge to the Category entity by id. func (m *DailyMutation) SetCategoryID(id int) { m.category = &id } // ClearCategory clears the "category" edge to the Category entity. func (m *DailyMutation) ClearCategory() { m.clearedcategory = true } // CategoryCleared reports if the "category" edge to the Category entity was cleared. func (m *DailyMutation) CategoryCleared() bool { return m.clearedcategory } // CategoryID returns the "category" edge ID in the mutation. func (m *DailyMutation) CategoryID() (id int, 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 *DailyMutation) CategoryIDs() (ids []int) { if id := m.category; id != nil { ids = append(ids, *id) } return } // ResetCategory resets all changes to the "category" edge. func (m *DailyMutation) ResetCategory() { m.category = nil m.clearedcategory = false } // AddContentIDs adds the "contents" edge to the DailyContent entity by ids. func (m *DailyMutation) AddContentIDs(ids ...int) { if m.contents == nil { m.contents = make(map[int]struct{}) } for i := range ids { m.contents[ids[i]] = struct{}{} } } // ClearContents clears the "contents" edge to the DailyContent entity. func (m *DailyMutation) ClearContents() { m.clearedcontents = true } // ContentsCleared reports if the "contents" edge to the DailyContent entity was cleared. func (m *DailyMutation) ContentsCleared() bool { return m.clearedcontents } // RemoveContentIDs removes the "contents" edge to the DailyContent entity by IDs. func (m *DailyMutation) RemoveContentIDs(ids ...int) { if m.removedcontents == nil { m.removedcontents = make(map[int]struct{}) } for i := range ids { delete(m.contents, ids[i]) m.removedcontents[ids[i]] = struct{}{} } } // RemovedContents returns the removed IDs of the "contents" edge to the DailyContent entity. func (m *DailyMutation) RemovedContentsIDs() (ids []int) { for id := range m.removedcontents { ids = append(ids, id) } return } // ContentsIDs returns the "contents" edge IDs in the mutation. func (m *DailyMutation) ContentsIDs() (ids []int) { for id := range m.contents { ids = append(ids, id) } return } // ResetContents resets all changes to the "contents" edge. func (m *DailyMutation) ResetContents() { m.contents = nil m.clearedcontents = false m.removedcontents = nil } // Where appends a list predicates to the DailyMutation builder. func (m *DailyMutation) Where(ps ...predicate.Daily) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the DailyMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *DailyMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Daily, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *DailyMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *DailyMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Daily). func (m *DailyMutation) 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 *DailyMutation) Fields() []string { fields := make([]string, 0, 3) if m.image_url != nil { fields = append(fields, daily.FieldImageURL) } if m.created_at != nil { fields = append(fields, daily.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, daily.FieldUpdatedAt) } 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 *DailyMutation) Field(name string) (ent.Value, bool) { switch name { case daily.FieldImageURL: return m.ImageURL() case daily.FieldCreatedAt: return m.CreatedAt() case daily.FieldUpdatedAt: return m.UpdatedAt() } 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 *DailyMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case daily.FieldImageURL: return m.OldImageURL(ctx) case daily.FieldCreatedAt: return m.OldCreatedAt(ctx) case daily.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Daily 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 *DailyMutation) SetField(name string, value ent.Value) error { switch name { case daily.FieldImageURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetImageURL(v) return nil case daily.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 daily.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Daily field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *DailyMutation) 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 *DailyMutation) 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 *DailyMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Daily numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *DailyMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DailyMutation) 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 *DailyMutation) ClearField(name string) error { return fmt.Errorf("unknown Daily 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 *DailyMutation) ResetField(name string) error { switch name { case daily.FieldImageURL: m.ResetImageURL() return nil case daily.FieldCreatedAt: m.ResetCreatedAt() return nil case daily.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Daily field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *DailyMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.category != nil { edges = append(edges, daily.EdgeCategory) } if m.contents != nil { edges = append(edges, daily.EdgeContents) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *DailyMutation) AddedIDs(name string) []ent.Value { switch name { case daily.EdgeCategory: if id := m.category; id != nil { return []ent.Value{*id} } case daily.EdgeContents: ids := make([]ent.Value, 0, len(m.contents)) for id := range m.contents { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *DailyMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedcontents != nil { edges = append(edges, daily.EdgeContents) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *DailyMutation) RemovedIDs(name string) []ent.Value { switch name { case daily.EdgeContents: ids := make([]ent.Value, 0, len(m.removedcontents)) for id := range m.removedcontents { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DailyMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedcategory { edges = append(edges, daily.EdgeCategory) } if m.clearedcontents { edges = append(edges, daily.EdgeContents) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *DailyMutation) EdgeCleared(name string) bool { switch name { case daily.EdgeCategory: return m.clearedcategory case daily.EdgeContents: return m.clearedcontents } 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 *DailyMutation) ClearEdge(name string) error { switch name { case daily.EdgeCategory: m.ClearCategory() return nil } return fmt.Errorf("unknown Daily 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 *DailyMutation) ResetEdge(name string) error { switch name { case daily.EdgeCategory: m.ResetCategory() return nil case daily.EdgeContents: m.ResetContents() return nil } return fmt.Errorf("unknown Daily edge %s", name) } // DailyCategoryMutation represents an operation that mutates the DailyCategory nodes in the graph. type DailyCategoryMutation struct { config op Op typ string id *int created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} contents map[int]struct{} removedcontents map[int]struct{} clearedcontents bool daily_items map[string]struct{} removeddaily_items map[string]struct{} cleareddaily_items bool done bool oldValue func(context.Context) (*DailyCategory, error) predicates []predicate.DailyCategory } var _ ent.Mutation = (*DailyCategoryMutation)(nil) // dailycategoryOption allows management of the mutation configuration using functional options. type dailycategoryOption func(*DailyCategoryMutation) // newDailyCategoryMutation creates new mutation for the DailyCategory entity. func newDailyCategoryMutation(c config, op Op, opts ...dailycategoryOption) *DailyCategoryMutation { m := &DailyCategoryMutation{ config: c, op: op, typ: TypeDailyCategory, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withDailyCategoryID sets the ID field of the mutation. func withDailyCategoryID(id int) dailycategoryOption { return func(m *DailyCategoryMutation) { var ( err error once sync.Once value *DailyCategory ) m.oldValue = func(ctx context.Context) (*DailyCategory, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().DailyCategory.Get(ctx, id) } }) return value, err } m.id = &id } } // withDailyCategory sets the old DailyCategory of the mutation. func withDailyCategory(node *DailyCategory) dailycategoryOption { return func(m *DailyCategoryMutation) { m.oldValue = func(context.Context) (*DailyCategory, 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 DailyCategoryMutation) 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 DailyCategoryMutation) 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 } // 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 *DailyCategoryMutation) ID() (id int, 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 *DailyCategoryMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().DailyCategory.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 *DailyCategoryMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *DailyCategoryMutation) 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 DailyCategory entity. // If the DailyCategory 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 *DailyCategoryMutation) 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 *DailyCategoryMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *DailyCategoryMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *DailyCategoryMutation) 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 DailyCategory entity. // If the DailyCategory 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 *DailyCategoryMutation) 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 } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *DailyCategoryMutation) ResetUpdatedAt() { m.updated_at = nil } // AddContentIDs adds the "contents" edge to the DailyCategoryContent entity by ids. func (m *DailyCategoryMutation) AddContentIDs(ids ...int) { if m.contents == nil { m.contents = make(map[int]struct{}) } for i := range ids { m.contents[ids[i]] = struct{}{} } } // ClearContents clears the "contents" edge to the DailyCategoryContent entity. func (m *DailyCategoryMutation) ClearContents() { m.clearedcontents = true } // ContentsCleared reports if the "contents" edge to the DailyCategoryContent entity was cleared. func (m *DailyCategoryMutation) ContentsCleared() bool { return m.clearedcontents } // RemoveContentIDs removes the "contents" edge to the DailyCategoryContent entity by IDs. func (m *DailyCategoryMutation) RemoveContentIDs(ids ...int) { if m.removedcontents == nil { m.removedcontents = make(map[int]struct{}) } for i := range ids { delete(m.contents, ids[i]) m.removedcontents[ids[i]] = struct{}{} } } // RemovedContents returns the removed IDs of the "contents" edge to the DailyCategoryContent entity. func (m *DailyCategoryMutation) RemovedContentsIDs() (ids []int) { for id := range m.removedcontents { ids = append(ids, id) } return } // ContentsIDs returns the "contents" edge IDs in the mutation. func (m *DailyCategoryMutation) ContentsIDs() (ids []int) { for id := range m.contents { ids = append(ids, id) } return } // ResetContents resets all changes to the "contents" edge. func (m *DailyCategoryMutation) ResetContents() { m.contents = nil m.clearedcontents = false m.removedcontents = nil } // AddDailyItemIDs adds the "daily_items" edge to the Daily entity by ids. func (m *DailyCategoryMutation) AddDailyItemIDs(ids ...string) { if m.daily_items == nil { m.daily_items = make(map[string]struct{}) } for i := range ids { m.daily_items[ids[i]] = struct{}{} } } // ClearDailyItems clears the "daily_items" edge to the Daily entity. func (m *DailyCategoryMutation) ClearDailyItems() { m.cleareddaily_items = true } // DailyItemsCleared reports if the "daily_items" edge to the Daily entity was cleared. func (m *DailyCategoryMutation) DailyItemsCleared() bool { return m.cleareddaily_items } // RemoveDailyItemIDs removes the "daily_items" edge to the Daily entity by IDs. func (m *DailyCategoryMutation) RemoveDailyItemIDs(ids ...string) { if m.removeddaily_items == nil { m.removeddaily_items = make(map[string]struct{}) } for i := range ids { delete(m.daily_items, ids[i]) m.removeddaily_items[ids[i]] = struct{}{} } } // RemovedDailyItems returns the removed IDs of the "daily_items" edge to the Daily entity. func (m *DailyCategoryMutation) RemovedDailyItemsIDs() (ids []string) { for id := range m.removeddaily_items { ids = append(ids, id) } return } // DailyItemsIDs returns the "daily_items" edge IDs in the mutation. func (m *DailyCategoryMutation) DailyItemsIDs() (ids []string) { for id := range m.daily_items { ids = append(ids, id) } return } // ResetDailyItems resets all changes to the "daily_items" edge. func (m *DailyCategoryMutation) ResetDailyItems() { m.daily_items = nil m.cleareddaily_items = false m.removeddaily_items = nil } // Where appends a list predicates to the DailyCategoryMutation builder. func (m *DailyCategoryMutation) Where(ps ...predicate.DailyCategory) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the DailyCategoryMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *DailyCategoryMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.DailyCategory, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *DailyCategoryMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *DailyCategoryMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (DailyCategory). func (m *DailyCategoryMutation) 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 *DailyCategoryMutation) Fields() []string { fields := make([]string, 0, 2) if m.created_at != nil { fields = append(fields, dailycategory.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, dailycategory.FieldUpdatedAt) } 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 *DailyCategoryMutation) Field(name string) (ent.Value, bool) { switch name { case dailycategory.FieldCreatedAt: return m.CreatedAt() case dailycategory.FieldUpdatedAt: return m.UpdatedAt() } 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 *DailyCategoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case dailycategory.FieldCreatedAt: return m.OldCreatedAt(ctx) case dailycategory.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown DailyCategory 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 *DailyCategoryMutation) SetField(name string, value ent.Value) error { switch name { case dailycategory.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 dailycategory.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown DailyCategory field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *DailyCategoryMutation) 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 *DailyCategoryMutation) 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 *DailyCategoryMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown DailyCategory numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *DailyCategoryMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DailyCategoryMutation) 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 *DailyCategoryMutation) ClearField(name string) error { return fmt.Errorf("unknown DailyCategory 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 *DailyCategoryMutation) ResetField(name string) error { switch name { case dailycategory.FieldCreatedAt: m.ResetCreatedAt() return nil case dailycategory.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown DailyCategory field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *DailyCategoryMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.contents != nil { edges = append(edges, dailycategory.EdgeContents) } if m.daily_items != nil { edges = append(edges, dailycategory.EdgeDailyItems) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *DailyCategoryMutation) AddedIDs(name string) []ent.Value { switch name { case dailycategory.EdgeContents: ids := make([]ent.Value, 0, len(m.contents)) for id := range m.contents { ids = append(ids, id) } return ids case dailycategory.EdgeDailyItems: ids := make([]ent.Value, 0, len(m.daily_items)) for id := range m.daily_items { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *DailyCategoryMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedcontents != nil { edges = append(edges, dailycategory.EdgeContents) } if m.removeddaily_items != nil { edges = append(edges, dailycategory.EdgeDailyItems) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *DailyCategoryMutation) RemovedIDs(name string) []ent.Value { switch name { case dailycategory.EdgeContents: ids := make([]ent.Value, 0, len(m.removedcontents)) for id := range m.removedcontents { ids = append(ids, id) } return ids case dailycategory.EdgeDailyItems: ids := make([]ent.Value, 0, len(m.removeddaily_items)) for id := range m.removeddaily_items { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DailyCategoryMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedcontents { edges = append(edges, dailycategory.EdgeContents) } if m.cleareddaily_items { edges = append(edges, dailycategory.EdgeDailyItems) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *DailyCategoryMutation) EdgeCleared(name string) bool { switch name { case dailycategory.EdgeContents: return m.clearedcontents case dailycategory.EdgeDailyItems: return m.cleareddaily_items } 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 *DailyCategoryMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown DailyCategory 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 *DailyCategoryMutation) ResetEdge(name string) error { switch name { case dailycategory.EdgeContents: m.ResetContents() return nil case dailycategory.EdgeDailyItems: m.ResetDailyItems() return nil } return fmt.Errorf("unknown DailyCategory edge %s", name) } // DailyCategoryContentMutation represents an operation that mutates the DailyCategoryContent nodes in the graph. type DailyCategoryContentMutation struct { config op Op typ string id *int language_code *dailycategorycontent.LanguageCode name *string clearedFields map[string]struct{} category *int clearedcategory bool done bool oldValue func(context.Context) (*DailyCategoryContent, error) predicates []predicate.DailyCategoryContent } var _ ent.Mutation = (*DailyCategoryContentMutation)(nil) // dailycategorycontentOption allows management of the mutation configuration using functional options. type dailycategorycontentOption func(*DailyCategoryContentMutation) // newDailyCategoryContentMutation creates new mutation for the DailyCategoryContent entity. func newDailyCategoryContentMutation(c config, op Op, opts ...dailycategorycontentOption) *DailyCategoryContentMutation { m := &DailyCategoryContentMutation{ config: c, op: op, typ: TypeDailyCategoryContent, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withDailyCategoryContentID sets the ID field of the mutation. func withDailyCategoryContentID(id int) dailycategorycontentOption { return func(m *DailyCategoryContentMutation) { var ( err error once sync.Once value *DailyCategoryContent ) m.oldValue = func(ctx context.Context) (*DailyCategoryContent, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().DailyCategoryContent.Get(ctx, id) } }) return value, err } m.id = &id } } // withDailyCategoryContent sets the old DailyCategoryContent of the mutation. func withDailyCategoryContent(node *DailyCategoryContent) dailycategorycontentOption { return func(m *DailyCategoryContentMutation) { m.oldValue = func(context.Context) (*DailyCategoryContent, 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 DailyCategoryContentMutation) 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 DailyCategoryContentMutation) 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 } // 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 *DailyCategoryContentMutation) ID() (id int, 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 *DailyCategoryContentMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().DailyCategoryContent.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetLanguageCode sets the "language_code" field. func (m *DailyCategoryContentMutation) SetLanguageCode(dc dailycategorycontent.LanguageCode) { m.language_code = &dc } // LanguageCode returns the value of the "language_code" field in the mutation. func (m *DailyCategoryContentMutation) LanguageCode() (r dailycategorycontent.LanguageCode, exists bool) { v := m.language_code if v == nil { return } return *v, true } // OldLanguageCode returns the old "language_code" field's value of the DailyCategoryContent entity. // If the DailyCategoryContent 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 *DailyCategoryContentMutation) OldLanguageCode(ctx context.Context) (v dailycategorycontent.LanguageCode, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLanguageCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLanguageCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLanguageCode: %w", err) } return oldValue.LanguageCode, nil } // ResetLanguageCode resets all changes to the "language_code" field. func (m *DailyCategoryContentMutation) ResetLanguageCode() { m.language_code = nil } // SetName sets the "name" field. func (m *DailyCategoryContentMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *DailyCategoryContentMutation) 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 DailyCategoryContent entity. // If the DailyCategoryContent 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 *DailyCategoryContentMutation) 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 } // ResetName resets all changes to the "name" field. func (m *DailyCategoryContentMutation) ResetName() { m.name = nil } // SetCategoryID sets the "category" edge to the DailyCategory entity by id. func (m *DailyCategoryContentMutation) SetCategoryID(id int) { m.category = &id } // ClearCategory clears the "category" edge to the DailyCategory entity. func (m *DailyCategoryContentMutation) ClearCategory() { m.clearedcategory = true } // CategoryCleared reports if the "category" edge to the DailyCategory entity was cleared. func (m *DailyCategoryContentMutation) CategoryCleared() bool { return m.clearedcategory } // CategoryID returns the "category" edge ID in the mutation. func (m *DailyCategoryContentMutation) CategoryID() (id int, 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 *DailyCategoryContentMutation) CategoryIDs() (ids []int) { if id := m.category; id != nil { ids = append(ids, *id) } return } // ResetCategory resets all changes to the "category" edge. func (m *DailyCategoryContentMutation) ResetCategory() { m.category = nil m.clearedcategory = false } // Where appends a list predicates to the DailyCategoryContentMutation builder. func (m *DailyCategoryContentMutation) Where(ps ...predicate.DailyCategoryContent) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the DailyCategoryContentMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *DailyCategoryContentMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.DailyCategoryContent, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *DailyCategoryContentMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *DailyCategoryContentMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (DailyCategoryContent). func (m *DailyCategoryContentMutation) 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 *DailyCategoryContentMutation) Fields() []string { fields := make([]string, 0, 2) if m.language_code != nil { fields = append(fields, dailycategorycontent.FieldLanguageCode) } if m.name != nil { fields = append(fields, dailycategorycontent.FieldName) } 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 *DailyCategoryContentMutation) Field(name string) (ent.Value, bool) { switch name { case dailycategorycontent.FieldLanguageCode: return m.LanguageCode() case dailycategorycontent.FieldName: return m.Name() } 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 *DailyCategoryContentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case dailycategorycontent.FieldLanguageCode: return m.OldLanguageCode(ctx) case dailycategorycontent.FieldName: return m.OldName(ctx) } return nil, fmt.Errorf("unknown DailyCategoryContent 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 *DailyCategoryContentMutation) SetField(name string, value ent.Value) error { switch name { case dailycategorycontent.FieldLanguageCode: v, ok := value.(dailycategorycontent.LanguageCode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLanguageCode(v) return nil case dailycategorycontent.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil } return fmt.Errorf("unknown DailyCategoryContent field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *DailyCategoryContentMutation) 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 *DailyCategoryContentMutation) 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 *DailyCategoryContentMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown DailyCategoryContent numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *DailyCategoryContentMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DailyCategoryContentMutation) 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 *DailyCategoryContentMutation) ClearField(name string) error { return fmt.Errorf("unknown DailyCategoryContent 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 *DailyCategoryContentMutation) ResetField(name string) error { switch name { case dailycategorycontent.FieldLanguageCode: m.ResetLanguageCode() return nil case dailycategorycontent.FieldName: m.ResetName() return nil } return fmt.Errorf("unknown DailyCategoryContent field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *DailyCategoryContentMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.category != nil { edges = append(edges, dailycategorycontent.EdgeCategory) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *DailyCategoryContentMutation) AddedIDs(name string) []ent.Value { switch name { case dailycategorycontent.EdgeCategory: if id := m.category; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *DailyCategoryContentMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *DailyCategoryContentMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DailyCategoryContentMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedcategory { edges = append(edges, dailycategorycontent.EdgeCategory) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *DailyCategoryContentMutation) EdgeCleared(name string) bool { switch name { case dailycategorycontent.EdgeCategory: return m.clearedcategory } 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 *DailyCategoryContentMutation) ClearEdge(name string) error { switch name { case dailycategorycontent.EdgeCategory: m.ClearCategory() return nil } return fmt.Errorf("unknown DailyCategoryContent 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 *DailyCategoryContentMutation) ResetEdge(name string) error { switch name { case dailycategorycontent.EdgeCategory: m.ResetCategory() return nil } return fmt.Errorf("unknown DailyCategoryContent edge %s", name) } // DailyContentMutation represents an operation that mutates the DailyContent nodes in the graph. type DailyContentMutation struct { config op Op typ string id *int language_code *dailycontent.LanguageCode quote *string clearedFields map[string]struct{} daily *string cleareddaily bool done bool oldValue func(context.Context) (*DailyContent, error) predicates []predicate.DailyContent } var _ ent.Mutation = (*DailyContentMutation)(nil) // dailycontentOption allows management of the mutation configuration using functional options. type dailycontentOption func(*DailyContentMutation) // newDailyContentMutation creates new mutation for the DailyContent entity. func newDailyContentMutation(c config, op Op, opts ...dailycontentOption) *DailyContentMutation { m := &DailyContentMutation{ config: c, op: op, typ: TypeDailyContent, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withDailyContentID sets the ID field of the mutation. func withDailyContentID(id int) dailycontentOption { return func(m *DailyContentMutation) { var ( err error once sync.Once value *DailyContent ) m.oldValue = func(ctx context.Context) (*DailyContent, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().DailyContent.Get(ctx, id) } }) return value, err } m.id = &id } } // withDailyContent sets the old DailyContent of the mutation. func withDailyContent(node *DailyContent) dailycontentOption { return func(m *DailyContentMutation) { m.oldValue = func(context.Context) (*DailyContent, 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 DailyContentMutation) 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 DailyContentMutation) 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 } // 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 *DailyContentMutation) ID() (id int, 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 *DailyContentMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().DailyContent.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetLanguageCode sets the "language_code" field. func (m *DailyContentMutation) SetLanguageCode(dc dailycontent.LanguageCode) { m.language_code = &dc } // LanguageCode returns the value of the "language_code" field in the mutation. func (m *DailyContentMutation) LanguageCode() (r dailycontent.LanguageCode, exists bool) { v := m.language_code if v == nil { return } return *v, true } // OldLanguageCode returns the old "language_code" field's value of the DailyContent entity. // If the DailyContent 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 *DailyContentMutation) OldLanguageCode(ctx context.Context) (v dailycontent.LanguageCode, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLanguageCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLanguageCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLanguageCode: %w", err) } return oldValue.LanguageCode, nil } // ResetLanguageCode resets all changes to the "language_code" field. func (m *DailyContentMutation) ResetLanguageCode() { m.language_code = nil } // SetQuote sets the "quote" field. func (m *DailyContentMutation) SetQuote(s string) { m.quote = &s } // Quote returns the value of the "quote" field in the mutation. func (m *DailyContentMutation) Quote() (r string, exists bool) { v := m.quote if v == nil { return } return *v, true } // OldQuote returns the old "quote" field's value of the DailyContent entity. // If the DailyContent 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 *DailyContentMutation) OldQuote(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldQuote is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldQuote requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldQuote: %w", err) } return oldValue.Quote, nil } // ResetQuote resets all changes to the "quote" field. func (m *DailyContentMutation) ResetQuote() { m.quote = nil } // SetDailyID sets the "daily" edge to the Daily entity by id. func (m *DailyContentMutation) SetDailyID(id string) { m.daily = &id } // ClearDaily clears the "daily" edge to the Daily entity. func (m *DailyContentMutation) ClearDaily() { m.cleareddaily = true } // DailyCleared reports if the "daily" edge to the Daily entity was cleared. func (m *DailyContentMutation) DailyCleared() bool { return m.cleareddaily } // DailyID returns the "daily" edge ID in the mutation. func (m *DailyContentMutation) DailyID() (id string, exists bool) { if m.daily != nil { return *m.daily, true } return } // DailyIDs returns the "daily" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // DailyID instead. It exists only for internal usage by the builders. func (m *DailyContentMutation) DailyIDs() (ids []string) { if id := m.daily; id != nil { ids = append(ids, *id) } return } // ResetDaily resets all changes to the "daily" edge. func (m *DailyContentMutation) ResetDaily() { m.daily = nil m.cleareddaily = false } // Where appends a list predicates to the DailyContentMutation builder. func (m *DailyContentMutation) Where(ps ...predicate.DailyContent) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the DailyContentMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *DailyContentMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.DailyContent, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *DailyContentMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *DailyContentMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (DailyContent). func (m *DailyContentMutation) 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 *DailyContentMutation) Fields() []string { fields := make([]string, 0, 2) if m.language_code != nil { fields = append(fields, dailycontent.FieldLanguageCode) } if m.quote != nil { fields = append(fields, dailycontent.FieldQuote) } 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 *DailyContentMutation) Field(name string) (ent.Value, bool) { switch name { case dailycontent.FieldLanguageCode: return m.LanguageCode() case dailycontent.FieldQuote: return m.Quote() } 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 *DailyContentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case dailycontent.FieldLanguageCode: return m.OldLanguageCode(ctx) case dailycontent.FieldQuote: return m.OldQuote(ctx) } return nil, fmt.Errorf("unknown DailyContent 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 *DailyContentMutation) SetField(name string, value ent.Value) error { switch name { case dailycontent.FieldLanguageCode: v, ok := value.(dailycontent.LanguageCode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLanguageCode(v) return nil case dailycontent.FieldQuote: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetQuote(v) return nil } return fmt.Errorf("unknown DailyContent field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *DailyContentMutation) 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 *DailyContentMutation) 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 *DailyContentMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown DailyContent numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *DailyContentMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DailyContentMutation) 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 *DailyContentMutation) ClearField(name string) error { return fmt.Errorf("unknown DailyContent 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 *DailyContentMutation) ResetField(name string) error { switch name { case dailycontent.FieldLanguageCode: m.ResetLanguageCode() return nil case dailycontent.FieldQuote: m.ResetQuote() return nil } return fmt.Errorf("unknown DailyContent field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *DailyContentMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.daily != nil { edges = append(edges, dailycontent.EdgeDaily) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *DailyContentMutation) AddedIDs(name string) []ent.Value { switch name { case dailycontent.EdgeDaily: if id := m.daily; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *DailyContentMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *DailyContentMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DailyContentMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareddaily { edges = append(edges, dailycontent.EdgeDaily) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *DailyContentMutation) EdgeCleared(name string) bool { switch name { case dailycontent.EdgeDaily: return m.cleareddaily } 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 *DailyContentMutation) ClearEdge(name string) error { switch name { case dailycontent.EdgeDaily: m.ClearDaily() return nil } return fmt.Errorf("unknown DailyContent 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 *DailyContentMutation) ResetEdge(name string) error { switch name { case dailycontent.EdgeDaily: m.ResetDaily() return nil } return fmt.Errorf("unknown DailyContent edge %s", name) } // MediaMutation represents an operation that mutates the Media nodes in the graph. type MediaMutation struct { config op Op typ string id *int storage_id *string original_name *string mime_type *string size *int64 addsize *int64 url *string created_at *time.Time updated_at *time.Time created_by *string clearedFields map[string]struct{} owner *int clearedowner bool done bool oldValue func(context.Context) (*Media, error) predicates []predicate.Media } var _ ent.Mutation = (*MediaMutation)(nil) // mediaOption allows management of the mutation configuration using functional options. type mediaOption func(*MediaMutation) // newMediaMutation creates new mutation for the Media entity. func newMediaMutation(c config, op Op, opts ...mediaOption) *MediaMutation { m := &MediaMutation{ config: c, op: op, typ: TypeMedia, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withMediaID sets the ID field of the mutation. func withMediaID(id int) mediaOption { return func(m *MediaMutation) { var ( err error once sync.Once value *Media ) m.oldValue = func(ctx context.Context) (*Media, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Media.Get(ctx, id) } }) return value, err } m.id = &id } } // withMedia sets the old Media of the mutation. func withMedia(node *Media) mediaOption { return func(m *MediaMutation) { m.oldValue = func(context.Context) (*Media, 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 MediaMutation) 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 MediaMutation) 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 } // 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 *MediaMutation) ID() (id int, 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 *MediaMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Media.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetStorageID sets the "storage_id" field. func (m *MediaMutation) SetStorageID(s string) { m.storage_id = &s } // StorageID returns the value of the "storage_id" field in the mutation. func (m *MediaMutation) StorageID() (r string, exists bool) { v := m.storage_id if v == nil { return } return *v, true } // OldStorageID returns the old "storage_id" field's value of the Media entity. // If the Media 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 *MediaMutation) OldStorageID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStorageID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStorageID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStorageID: %w", err) } return oldValue.StorageID, nil } // ResetStorageID resets all changes to the "storage_id" field. func (m *MediaMutation) ResetStorageID() { m.storage_id = nil } // SetOriginalName sets the "original_name" field. func (m *MediaMutation) SetOriginalName(s string) { m.original_name = &s } // OriginalName returns the value of the "original_name" field in the mutation. func (m *MediaMutation) OriginalName() (r string, exists bool) { v := m.original_name if v == nil { return } return *v, true } // OldOriginalName returns the old "original_name" field's value of the Media entity. // If the Media 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 *MediaMutation) OldOriginalName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldOriginalName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldOriginalName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldOriginalName: %w", err) } return oldValue.OriginalName, nil } // ResetOriginalName resets all changes to the "original_name" field. func (m *MediaMutation) ResetOriginalName() { m.original_name = nil } // SetMimeType sets the "mime_type" field. func (m *MediaMutation) SetMimeType(s string) { m.mime_type = &s } // MimeType returns the value of the "mime_type" field in the mutation. func (m *MediaMutation) MimeType() (r string, exists bool) { v := m.mime_type if v == nil { return } return *v, true } // OldMimeType returns the old "mime_type" field's value of the Media entity. // If the Media 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 *MediaMutation) OldMimeType(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldMimeType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldMimeType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldMimeType: %w", err) } return oldValue.MimeType, nil } // ResetMimeType resets all changes to the "mime_type" field. func (m *MediaMutation) ResetMimeType() { m.mime_type = nil } // SetSize sets the "size" field. func (m *MediaMutation) SetSize(i int64) { m.size = &i m.addsize = nil } // Size returns the value of the "size" field in the mutation. func (m *MediaMutation) Size() (r int64, exists bool) { v := m.size if v == nil { return } return *v, true } // OldSize returns the old "size" field's value of the Media entity. // If the Media 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 *MediaMutation) OldSize(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSize is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSize requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSize: %w", err) } return oldValue.Size, nil } // AddSize adds i to the "size" field. func (m *MediaMutation) AddSize(i int64) { if m.addsize != nil { *m.addsize += i } else { m.addsize = &i } } // AddedSize returns the value that was added to the "size" field in this mutation. func (m *MediaMutation) AddedSize() (r int64, exists bool) { v := m.addsize if v == nil { return } return *v, true } // ResetSize resets all changes to the "size" field. func (m *MediaMutation) ResetSize() { m.size = nil m.addsize = nil } // SetURL sets the "url" field. func (m *MediaMutation) SetURL(s string) { m.url = &s } // URL returns the value of the "url" field in the mutation. func (m *MediaMutation) URL() (r string, exists bool) { v := m.url if v == nil { return } return *v, true } // OldURL returns the old "url" field's value of the Media entity. // If the Media 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 *MediaMutation) OldURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldURL: %w", err) } return oldValue.URL, nil } // ResetURL resets all changes to the "url" field. func (m *MediaMutation) ResetURL() { m.url = nil } // SetCreatedAt sets the "created_at" field. func (m *MediaMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *MediaMutation) 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 Media entity. // If the Media 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 *MediaMutation) 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 *MediaMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *MediaMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *MediaMutation) 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 Media entity. // If the Media 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 *MediaMutation) 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 } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *MediaMutation) ResetUpdatedAt() { m.updated_at = nil } // SetCreatedBy sets the "created_by" field. func (m *MediaMutation) SetCreatedBy(s string) { m.created_by = &s } // CreatedBy returns the value of the "created_by" field in the mutation. func (m *MediaMutation) CreatedBy() (r string, exists bool) { v := m.created_by if v == nil { return } return *v, true } // OldCreatedBy returns the old "created_by" field's value of the Media entity. // If the Media 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 *MediaMutation) OldCreatedBy(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedBy is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedBy requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedBy: %w", err) } return oldValue.CreatedBy, nil } // ClearCreatedBy clears the value of the "created_by" field. func (m *MediaMutation) ClearCreatedBy() { m.created_by = nil m.clearedFields[media.FieldCreatedBy] = struct{}{} } // CreatedByCleared returns if the "created_by" field was cleared in this mutation. func (m *MediaMutation) CreatedByCleared() bool { _, ok := m.clearedFields[media.FieldCreatedBy] return ok } // ResetCreatedBy resets all changes to the "created_by" field. func (m *MediaMutation) ResetCreatedBy() { m.created_by = nil delete(m.clearedFields, media.FieldCreatedBy) } // SetOwnerID sets the "owner" edge to the User entity by id. func (m *MediaMutation) SetOwnerID(id int) { m.owner = &id } // ClearOwner clears the "owner" edge to the User entity. func (m *MediaMutation) ClearOwner() { m.clearedowner = true } // OwnerCleared reports if the "owner" edge to the User entity was cleared. func (m *MediaMutation) OwnerCleared() bool { return m.clearedowner } // OwnerID returns the "owner" edge ID in the mutation. func (m *MediaMutation) OwnerID() (id int, exists bool) { if m.owner != nil { return *m.owner, true } return } // OwnerIDs returns the "owner" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // OwnerID instead. It exists only for internal usage by the builders. func (m *MediaMutation) OwnerIDs() (ids []int) { if id := m.owner; id != nil { ids = append(ids, *id) } return } // ResetOwner resets all changes to the "owner" edge. func (m *MediaMutation) ResetOwner() { m.owner = nil m.clearedowner = false } // Where appends a list predicates to the MediaMutation builder. func (m *MediaMutation) Where(ps ...predicate.Media) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the MediaMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *MediaMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Media, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *MediaMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *MediaMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Media). func (m *MediaMutation) 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 *MediaMutation) Fields() []string { fields := make([]string, 0, 8) if m.storage_id != nil { fields = append(fields, media.FieldStorageID) } if m.original_name != nil { fields = append(fields, media.FieldOriginalName) } if m.mime_type != nil { fields = append(fields, media.FieldMimeType) } if m.size != nil { fields = append(fields, media.FieldSize) } if m.url != nil { fields = append(fields, media.FieldURL) } if m.created_at != nil { fields = append(fields, media.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, media.FieldUpdatedAt) } if m.created_by != nil { fields = append(fields, media.FieldCreatedBy) } 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 *MediaMutation) Field(name string) (ent.Value, bool) { switch name { case media.FieldStorageID: return m.StorageID() case media.FieldOriginalName: return m.OriginalName() case media.FieldMimeType: return m.MimeType() case media.FieldSize: return m.Size() case media.FieldURL: return m.URL() case media.FieldCreatedAt: return m.CreatedAt() case media.FieldUpdatedAt: return m.UpdatedAt() case media.FieldCreatedBy: return m.CreatedBy() } 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 *MediaMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case media.FieldStorageID: return m.OldStorageID(ctx) case media.FieldOriginalName: return m.OldOriginalName(ctx) case media.FieldMimeType: return m.OldMimeType(ctx) case media.FieldSize: return m.OldSize(ctx) case media.FieldURL: return m.OldURL(ctx) case media.FieldCreatedAt: return m.OldCreatedAt(ctx) case media.FieldUpdatedAt: return m.OldUpdatedAt(ctx) case media.FieldCreatedBy: return m.OldCreatedBy(ctx) } return nil, fmt.Errorf("unknown Media 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 *MediaMutation) SetField(name string, value ent.Value) error { switch name { case media.FieldStorageID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStorageID(v) return nil case media.FieldOriginalName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetOriginalName(v) return nil case media.FieldMimeType: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetMimeType(v) return nil case media.FieldSize: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSize(v) return nil case media.FieldURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetURL(v) return nil case media.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 media.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 media.FieldCreatedBy: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedBy(v) return nil } return fmt.Errorf("unknown Media field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *MediaMutation) AddedFields() []string { var fields []string if m.addsize != nil { fields = append(fields, media.FieldSize) } return fields } // 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 *MediaMutation) AddedField(name string) (ent.Value, bool) { switch name { case media.FieldSize: return m.AddedSize() } 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 *MediaMutation) AddField(name string, value ent.Value) error { switch name { case media.FieldSize: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddSize(v) return nil } return fmt.Errorf("unknown Media numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *MediaMutation) ClearedFields() []string { var fields []string if m.FieldCleared(media.FieldCreatedBy) { fields = append(fields, media.FieldCreatedBy) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *MediaMutation) 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 *MediaMutation) ClearField(name string) error { switch name { case media.FieldCreatedBy: m.ClearCreatedBy() return nil } return fmt.Errorf("unknown Media 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 *MediaMutation) ResetField(name string) error { switch name { case media.FieldStorageID: m.ResetStorageID() return nil case media.FieldOriginalName: m.ResetOriginalName() return nil case media.FieldMimeType: m.ResetMimeType() return nil case media.FieldSize: m.ResetSize() return nil case media.FieldURL: m.ResetURL() return nil case media.FieldCreatedAt: m.ResetCreatedAt() return nil case media.FieldUpdatedAt: m.ResetUpdatedAt() return nil case media.FieldCreatedBy: m.ResetCreatedBy() return nil } return fmt.Errorf("unknown Media field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *MediaMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.owner != nil { edges = append(edges, media.EdgeOwner) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *MediaMutation) AddedIDs(name string) []ent.Value { switch name { case media.EdgeOwner: if id := m.owner; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *MediaMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *MediaMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *MediaMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedowner { edges = append(edges, media.EdgeOwner) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *MediaMutation) EdgeCleared(name string) bool { switch name { case media.EdgeOwner: return m.clearedowner } 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 *MediaMutation) ClearEdge(name string) error { switch name { case media.EdgeOwner: m.ClearOwner() return nil } return fmt.Errorf("unknown Media 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 *MediaMutation) ResetEdge(name string) error { switch name { case media.EdgeOwner: m.ResetOwner() return nil } return fmt.Errorf("unknown Media edge %s", name) } // PermissionMutation represents an operation that mutates the Permission nodes in the graph. type PermissionMutation struct { config op Op typ string id *int resource *string action *string description *string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} roles map[int]struct{} removedroles map[int]struct{} clearedroles bool done bool oldValue func(context.Context) (*Permission, error) predicates []predicate.Permission } var _ ent.Mutation = (*PermissionMutation)(nil) // permissionOption allows management of the mutation configuration using functional options. type permissionOption func(*PermissionMutation) // newPermissionMutation creates new mutation for the Permission entity. func newPermissionMutation(c config, op Op, opts ...permissionOption) *PermissionMutation { m := &PermissionMutation{ config: c, op: op, typ: TypePermission, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withPermissionID sets the ID field of the mutation. func withPermissionID(id int) permissionOption { return func(m *PermissionMutation) { var ( err error once sync.Once value *Permission ) m.oldValue = func(ctx context.Context) (*Permission, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Permission.Get(ctx, id) } }) return value, err } m.id = &id } } // withPermission sets the old Permission of the mutation. func withPermission(node *Permission) permissionOption { return func(m *PermissionMutation) { m.oldValue = func(context.Context) (*Permission, 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 PermissionMutation) 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 PermissionMutation) 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 } // 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 *PermissionMutation) ID() (id int, 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 *PermissionMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Permission.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetResource sets the "resource" field. func (m *PermissionMutation) SetResource(s string) { m.resource = &s } // Resource returns the value of the "resource" field in the mutation. func (m *PermissionMutation) Resource() (r string, exists bool) { v := m.resource if v == nil { return } return *v, true } // OldResource returns the old "resource" field's value of the Permission entity. // If the Permission 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 *PermissionMutation) OldResource(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldResource is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldResource requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldResource: %w", err) } return oldValue.Resource, nil } // ResetResource resets all changes to the "resource" field. func (m *PermissionMutation) ResetResource() { m.resource = nil } // SetAction sets the "action" field. func (m *PermissionMutation) SetAction(s string) { m.action = &s } // Action returns the value of the "action" field in the mutation. func (m *PermissionMutation) Action() (r string, exists bool) { v := m.action if v == nil { return } return *v, true } // OldAction returns the old "action" field's value of the Permission entity. // If the Permission 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 *PermissionMutation) OldAction(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAction is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAction requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAction: %w", err) } return oldValue.Action, nil } // ResetAction resets all changes to the "action" field. func (m *PermissionMutation) ResetAction() { m.action = nil } // SetDescription sets the "description" field. func (m *PermissionMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *PermissionMutation) 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 Permission entity. // If the Permission 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 *PermissionMutation) 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 *PermissionMutation) ClearDescription() { m.description = nil m.clearedFields[permission.FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *PermissionMutation) DescriptionCleared() bool { _, ok := m.clearedFields[permission.FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *PermissionMutation) ResetDescription() { m.description = nil delete(m.clearedFields, permission.FieldDescription) } // SetCreatedAt sets the "created_at" field. func (m *PermissionMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *PermissionMutation) 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 Permission entity. // If the Permission 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 *PermissionMutation) 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 *PermissionMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *PermissionMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *PermissionMutation) 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 Permission entity. // If the Permission 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 *PermissionMutation) 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 } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *PermissionMutation) ResetUpdatedAt() { m.updated_at = nil } // AddRoleIDs adds the "roles" edge to the Role entity by ids. func (m *PermissionMutation) AddRoleIDs(ids ...int) { if m.roles == nil { m.roles = make(map[int]struct{}) } for i := range ids { m.roles[ids[i]] = struct{}{} } } // ClearRoles clears the "roles" edge to the Role entity. func (m *PermissionMutation) ClearRoles() { m.clearedroles = true } // RolesCleared reports if the "roles" edge to the Role entity was cleared. func (m *PermissionMutation) RolesCleared() bool { return m.clearedroles } // RemoveRoleIDs removes the "roles" edge to the Role entity by IDs. func (m *PermissionMutation) RemoveRoleIDs(ids ...int) { if m.removedroles == nil { m.removedroles = make(map[int]struct{}) } for i := range ids { delete(m.roles, ids[i]) m.removedroles[ids[i]] = struct{}{} } } // RemovedRoles returns the removed IDs of the "roles" edge to the Role entity. func (m *PermissionMutation) RemovedRolesIDs() (ids []int) { for id := range m.removedroles { ids = append(ids, id) } return } // RolesIDs returns the "roles" edge IDs in the mutation. func (m *PermissionMutation) RolesIDs() (ids []int) { for id := range m.roles { ids = append(ids, id) } return } // ResetRoles resets all changes to the "roles" edge. func (m *PermissionMutation) ResetRoles() { m.roles = nil m.clearedroles = false m.removedroles = nil } // Where appends a list predicates to the PermissionMutation builder. func (m *PermissionMutation) Where(ps ...predicate.Permission) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the PermissionMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *PermissionMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Permission, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *PermissionMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *PermissionMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Permission). func (m *PermissionMutation) 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 *PermissionMutation) Fields() []string { fields := make([]string, 0, 5) if m.resource != nil { fields = append(fields, permission.FieldResource) } if m.action != nil { fields = append(fields, permission.FieldAction) } if m.description != nil { fields = append(fields, permission.FieldDescription) } if m.created_at != nil { fields = append(fields, permission.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, permission.FieldUpdatedAt) } 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 *PermissionMutation) Field(name string) (ent.Value, bool) { switch name { case permission.FieldResource: return m.Resource() case permission.FieldAction: return m.Action() case permission.FieldDescription: return m.Description() case permission.FieldCreatedAt: return m.CreatedAt() case permission.FieldUpdatedAt: return m.UpdatedAt() } 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 *PermissionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case permission.FieldResource: return m.OldResource(ctx) case permission.FieldAction: return m.OldAction(ctx) case permission.FieldDescription: return m.OldDescription(ctx) case permission.FieldCreatedAt: return m.OldCreatedAt(ctx) case permission.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Permission 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 *PermissionMutation) SetField(name string, value ent.Value) error { switch name { case permission.FieldResource: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetResource(v) return nil case permission.FieldAction: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAction(v) return nil case permission.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case permission.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 permission.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Permission field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *PermissionMutation) 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 *PermissionMutation) 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 *PermissionMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Permission numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *PermissionMutation) ClearedFields() []string { var fields []string if m.FieldCleared(permission.FieldDescription) { fields = append(fields, permission.FieldDescription) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *PermissionMutation) 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 *PermissionMutation) ClearField(name string) error { switch name { case permission.FieldDescription: m.ClearDescription() return nil } return fmt.Errorf("unknown Permission 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 *PermissionMutation) ResetField(name string) error { switch name { case permission.FieldResource: m.ResetResource() return nil case permission.FieldAction: m.ResetAction() return nil case permission.FieldDescription: m.ResetDescription() return nil case permission.FieldCreatedAt: m.ResetCreatedAt() return nil case permission.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Permission field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *PermissionMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.roles != nil { edges = append(edges, permission.EdgeRoles) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *PermissionMutation) AddedIDs(name string) []ent.Value { switch name { case permission.EdgeRoles: ids := make([]ent.Value, 0, len(m.roles)) for id := range m.roles { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *PermissionMutation) RemovedEdges() []string { edges := make([]string, 0, 1) if m.removedroles != nil { edges = append(edges, permission.EdgeRoles) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *PermissionMutation) RemovedIDs(name string) []ent.Value { switch name { case permission.EdgeRoles: ids := make([]ent.Value, 0, len(m.removedroles)) for id := range m.removedroles { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *PermissionMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedroles { edges = append(edges, permission.EdgeRoles) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *PermissionMutation) EdgeCleared(name string) bool { switch name { case permission.EdgeRoles: return m.clearedroles } 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 *PermissionMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Permission 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 *PermissionMutation) ResetEdge(name string) error { switch name { case permission.EdgeRoles: m.ResetRoles() return nil } return fmt.Errorf("unknown Permission edge %s", name) } // PostMutation represents an operation that mutates the Post nodes in the graph. type PostMutation struct { config op Op typ string id *int status *post.Status slug *string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} contents map[int]struct{} removedcontents map[int]struct{} clearedcontents bool contributors map[int]struct{} removedcontributors map[int]struct{} clearedcontributors bool category *int clearedcategory 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 int) 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 } // 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 int, 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) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{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) } } // SetStatus sets the "status" field. func (m *PostMutation) SetStatus(po post.Status) { m.status = &po } // Status returns the value of the "status" field in the mutation. func (m *PostMutation) Status() (r post.Status, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" 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) OldStatus(ctx context.Context) (v post.Status, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStatus: %w", err) } return oldValue.Status, nil } // ResetStatus resets all changes to the "status" field. func (m *PostMutation) ResetStatus() { m.status = nil } // SetSlug sets the "slug" field. func (m *PostMutation) SetSlug(s string) { m.slug = &s } // Slug returns the value of the "slug" field in the mutation. func (m *PostMutation) Slug() (r string, exists bool) { v := m.slug if v == nil { return } return *v, true } // OldSlug returns the old "slug" 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) OldSlug(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSlug is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSlug requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSlug: %w", err) } return oldValue.Slug, nil } // ResetSlug resets all changes to the "slug" field. func (m *PostMutation) ResetSlug() { m.slug = nil } // 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 } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *PostMutation) ResetUpdatedAt() { m.updated_at = nil } // AddContentIDs adds the "contents" edge to the PostContent entity by ids. func (m *PostMutation) AddContentIDs(ids ...int) { if m.contents == nil { m.contents = make(map[int]struct{}) } for i := range ids { m.contents[ids[i]] = struct{}{} } } // ClearContents clears the "contents" edge to the PostContent entity. func (m *PostMutation) ClearContents() { m.clearedcontents = true } // ContentsCleared reports if the "contents" edge to the PostContent entity was cleared. func (m *PostMutation) ContentsCleared() bool { return m.clearedcontents } // RemoveContentIDs removes the "contents" edge to the PostContent entity by IDs. func (m *PostMutation) RemoveContentIDs(ids ...int) { if m.removedcontents == nil { m.removedcontents = make(map[int]struct{}) } for i := range ids { delete(m.contents, ids[i]) m.removedcontents[ids[i]] = struct{}{} } } // RemovedContents returns the removed IDs of the "contents" edge to the PostContent entity. func (m *PostMutation) RemovedContentsIDs() (ids []int) { for id := range m.removedcontents { ids = append(ids, id) } return } // ContentsIDs returns the "contents" edge IDs in the mutation. func (m *PostMutation) ContentsIDs() (ids []int) { for id := range m.contents { ids = append(ids, id) } return } // ResetContents resets all changes to the "contents" edge. func (m *PostMutation) ResetContents() { m.contents = nil m.clearedcontents = false m.removedcontents = nil } // AddContributorIDs adds the "contributors" edge to the PostContributor entity by ids. func (m *PostMutation) AddContributorIDs(ids ...int) { if m.contributors == nil { m.contributors = make(map[int]struct{}) } for i := range ids { m.contributors[ids[i]] = struct{}{} } } // ClearContributors clears the "contributors" edge to the PostContributor entity. func (m *PostMutation) ClearContributors() { m.clearedcontributors = true } // ContributorsCleared reports if the "contributors" edge to the PostContributor entity was cleared. func (m *PostMutation) ContributorsCleared() bool { return m.clearedcontributors } // RemoveContributorIDs removes the "contributors" edge to the PostContributor entity by IDs. func (m *PostMutation) RemoveContributorIDs(ids ...int) { if m.removedcontributors == nil { m.removedcontributors = make(map[int]struct{}) } for i := range ids { delete(m.contributors, ids[i]) m.removedcontributors[ids[i]] = struct{}{} } } // RemovedContributors returns the removed IDs of the "contributors" edge to the PostContributor entity. func (m *PostMutation) RemovedContributorsIDs() (ids []int) { for id := range m.removedcontributors { ids = append(ids, id) } return } // ContributorsIDs returns the "contributors" edge IDs in the mutation. func (m *PostMutation) ContributorsIDs() (ids []int) { for id := range m.contributors { ids = append(ids, id) } return } // ResetContributors resets all changes to the "contributors" edge. func (m *PostMutation) ResetContributors() { m.contributors = nil m.clearedcontributors = false m.removedcontributors = nil } // SetCategoryID sets the "category" edge to the Category entity by id. func (m *PostMutation) SetCategoryID(id int) { 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 int, 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 []int) { 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 } // 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, 4) if m.status != nil { fields = append(fields, post.FieldStatus) } if m.slug != nil { fields = append(fields, post.FieldSlug) } if m.created_at != nil { fields = append(fields, post.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, post.FieldUpdatedAt) } 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.FieldStatus: return m.Status() case post.FieldSlug: return m.Slug() case post.FieldCreatedAt: return m.CreatedAt() case post.FieldUpdatedAt: return m.UpdatedAt() } 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.FieldStatus: return m.OldStatus(ctx) case post.FieldSlug: return m.OldSlug(ctx) case post.FieldCreatedAt: return m.OldCreatedAt(ctx) case post.FieldUpdatedAt: return m.OldUpdatedAt(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.FieldStatus: v, ok := value.(post.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case post.FieldSlug: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSlug(v) return nil 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 } 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 { return nil } // 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 { 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.FieldStatus: m.ResetStatus() return nil case post.FieldSlug: m.ResetSlug() return nil case post.FieldCreatedAt: m.ResetCreatedAt() return nil case post.FieldUpdatedAt: m.ResetUpdatedAt() 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, 3) if m.contents != nil { edges = append(edges, post.EdgeContents) } if m.contributors != nil { edges = append(edges, post.EdgeContributors) } if m.category != nil { edges = append(edges, post.EdgeCategory) } 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.EdgeContents: ids := make([]ent.Value, 0, len(m.contents)) for id := range m.contents { ids = append(ids, id) } return ids case post.EdgeContributors: ids := make([]ent.Value, 0, len(m.contributors)) for id := range m.contributors { ids = append(ids, id) } return ids case post.EdgeCategory: if id := m.category; 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, 3) if m.removedcontents != nil { edges = append(edges, post.EdgeContents) } if m.removedcontributors != nil { edges = append(edges, post.EdgeContributors) } 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 { switch name { case post.EdgeContents: ids := make([]ent.Value, 0, len(m.removedcontents)) for id := range m.removedcontents { ids = append(ids, id) } return ids case post.EdgeContributors: ids := make([]ent.Value, 0, len(m.removedcontributors)) for id := range m.removedcontributors { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *PostMutation) ClearedEdges() []string { edges := make([]string, 0, 3) if m.clearedcontents { edges = append(edges, post.EdgeContents) } if m.clearedcontributors { edges = append(edges, post.EdgeContributors) } if m.clearedcategory { edges = append(edges, post.EdgeCategory) } 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.EdgeContents: return m.clearedcontents case post.EdgeContributors: return m.clearedcontributors case post.EdgeCategory: return m.clearedcategory } 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 } 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.EdgeContents: m.ResetContents() return nil case post.EdgeContributors: m.ResetContributors() return nil case post.EdgeCategory: m.ResetCategory() return nil } return fmt.Errorf("unknown Post edge %s", name) } // PostContentMutation represents an operation that mutates the PostContent nodes in the graph. type PostContentMutation struct { config op Op typ string id *int language_code *postcontent.LanguageCode title *string content_markdown *string summary *string meta_keywords *string meta_description *string slug *string clearedFields map[string]struct{} post *int clearedpost bool done bool oldValue func(context.Context) (*PostContent, error) predicates []predicate.PostContent } var _ ent.Mutation = (*PostContentMutation)(nil) // postcontentOption allows management of the mutation configuration using functional options. type postcontentOption func(*PostContentMutation) // newPostContentMutation creates new mutation for the PostContent entity. func newPostContentMutation(c config, op Op, opts ...postcontentOption) *PostContentMutation { m := &PostContentMutation{ config: c, op: op, typ: TypePostContent, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withPostContentID sets the ID field of the mutation. func withPostContentID(id int) postcontentOption { return func(m *PostContentMutation) { var ( err error once sync.Once value *PostContent ) m.oldValue = func(ctx context.Context) (*PostContent, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().PostContent.Get(ctx, id) } }) return value, err } m.id = &id } } // withPostContent sets the old PostContent of the mutation. func withPostContent(node *PostContent) postcontentOption { return func(m *PostContentMutation) { m.oldValue = func(context.Context) (*PostContent, 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 PostContentMutation) 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 PostContentMutation) 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 } // 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 *PostContentMutation) ID() (id int, 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 *PostContentMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().PostContent.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetLanguageCode sets the "language_code" field. func (m *PostContentMutation) SetLanguageCode(pc postcontent.LanguageCode) { m.language_code = &pc } // LanguageCode returns the value of the "language_code" field in the mutation. func (m *PostContentMutation) LanguageCode() (r postcontent.LanguageCode, exists bool) { v := m.language_code if v == nil { return } return *v, true } // OldLanguageCode returns the old "language_code" field's value of the PostContent entity. // If the PostContent 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 *PostContentMutation) OldLanguageCode(ctx context.Context) (v postcontent.LanguageCode, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLanguageCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLanguageCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLanguageCode: %w", err) } return oldValue.LanguageCode, nil } // ResetLanguageCode resets all changes to the "language_code" field. func (m *PostContentMutation) ResetLanguageCode() { m.language_code = nil } // SetTitle sets the "title" field. func (m *PostContentMutation) SetTitle(s string) { m.title = &s } // Title returns the value of the "title" field in the mutation. func (m *PostContentMutation) 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 PostContent entity. // If the PostContent 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 *PostContentMutation) 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 *PostContentMutation) ResetTitle() { m.title = nil } // SetContentMarkdown sets the "content_markdown" field. func (m *PostContentMutation) SetContentMarkdown(s string) { m.content_markdown = &s } // ContentMarkdown returns the value of the "content_markdown" field in the mutation. func (m *PostContentMutation) ContentMarkdown() (r string, exists bool) { v := m.content_markdown if v == nil { return } return *v, true } // OldContentMarkdown returns the old "content_markdown" field's value of the PostContent entity. // If the PostContent 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 *PostContentMutation) OldContentMarkdown(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldContentMarkdown is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldContentMarkdown requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldContentMarkdown: %w", err) } return oldValue.ContentMarkdown, nil } // ResetContentMarkdown resets all changes to the "content_markdown" field. func (m *PostContentMutation) ResetContentMarkdown() { m.content_markdown = nil } // SetSummary sets the "summary" field. func (m *PostContentMutation) SetSummary(s string) { m.summary = &s } // Summary returns the value of the "summary" field in the mutation. func (m *PostContentMutation) Summary() (r string, exists bool) { v := m.summary if v == nil { return } return *v, true } // OldSummary returns the old "summary" field's value of the PostContent entity. // If the PostContent 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 *PostContentMutation) OldSummary(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSummary is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSummary requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSummary: %w", err) } return oldValue.Summary, nil } // ResetSummary resets all changes to the "summary" field. func (m *PostContentMutation) ResetSummary() { m.summary = nil } // SetMetaKeywords sets the "meta_keywords" field. func (m *PostContentMutation) SetMetaKeywords(s string) { m.meta_keywords = &s } // MetaKeywords returns the value of the "meta_keywords" field in the mutation. func (m *PostContentMutation) MetaKeywords() (r string, exists bool) { v := m.meta_keywords if v == nil { return } return *v, true } // OldMetaKeywords returns the old "meta_keywords" field's value of the PostContent entity. // If the PostContent 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 *PostContentMutation) OldMetaKeywords(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldMetaKeywords is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldMetaKeywords requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldMetaKeywords: %w", err) } return oldValue.MetaKeywords, nil } // ClearMetaKeywords clears the value of the "meta_keywords" field. func (m *PostContentMutation) ClearMetaKeywords() { m.meta_keywords = nil m.clearedFields[postcontent.FieldMetaKeywords] = struct{}{} } // MetaKeywordsCleared returns if the "meta_keywords" field was cleared in this mutation. func (m *PostContentMutation) MetaKeywordsCleared() bool { _, ok := m.clearedFields[postcontent.FieldMetaKeywords] return ok } // ResetMetaKeywords resets all changes to the "meta_keywords" field. func (m *PostContentMutation) ResetMetaKeywords() { m.meta_keywords = nil delete(m.clearedFields, postcontent.FieldMetaKeywords) } // SetMetaDescription sets the "meta_description" field. func (m *PostContentMutation) SetMetaDescription(s string) { m.meta_description = &s } // MetaDescription returns the value of the "meta_description" field in the mutation. func (m *PostContentMutation) MetaDescription() (r string, exists bool) { v := m.meta_description if v == nil { return } return *v, true } // OldMetaDescription returns the old "meta_description" field's value of the PostContent entity. // If the PostContent 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 *PostContentMutation) OldMetaDescription(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldMetaDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldMetaDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldMetaDescription: %w", err) } return oldValue.MetaDescription, nil } // ClearMetaDescription clears the value of the "meta_description" field. func (m *PostContentMutation) ClearMetaDescription() { m.meta_description = nil m.clearedFields[postcontent.FieldMetaDescription] = struct{}{} } // MetaDescriptionCleared returns if the "meta_description" field was cleared in this mutation. func (m *PostContentMutation) MetaDescriptionCleared() bool { _, ok := m.clearedFields[postcontent.FieldMetaDescription] return ok } // ResetMetaDescription resets all changes to the "meta_description" field. func (m *PostContentMutation) ResetMetaDescription() { m.meta_description = nil delete(m.clearedFields, postcontent.FieldMetaDescription) } // SetSlug sets the "slug" field. func (m *PostContentMutation) SetSlug(s string) { m.slug = &s } // Slug returns the value of the "slug" field in the mutation. func (m *PostContentMutation) Slug() (r string, exists bool) { v := m.slug if v == nil { return } return *v, true } // OldSlug returns the old "slug" field's value of the PostContent entity. // If the PostContent 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 *PostContentMutation) OldSlug(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSlug is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSlug requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSlug: %w", err) } return oldValue.Slug, nil } // ResetSlug resets all changes to the "slug" field. func (m *PostContentMutation) ResetSlug() { m.slug = nil } // SetPostID sets the "post" edge to the Post entity by id. func (m *PostContentMutation) SetPostID(id int) { m.post = &id } // ClearPost clears the "post" edge to the Post entity. func (m *PostContentMutation) ClearPost() { m.clearedpost = true } // PostCleared reports if the "post" edge to the Post entity was cleared. func (m *PostContentMutation) PostCleared() bool { return m.clearedpost } // PostID returns the "post" edge ID in the mutation. func (m *PostContentMutation) PostID() (id int, exists bool) { if m.post != nil { return *m.post, true } return } // PostIDs returns the "post" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // PostID instead. It exists only for internal usage by the builders. func (m *PostContentMutation) PostIDs() (ids []int) { if id := m.post; id != nil { ids = append(ids, *id) } return } // ResetPost resets all changes to the "post" edge. func (m *PostContentMutation) ResetPost() { m.post = nil m.clearedpost = false } // Where appends a list predicates to the PostContentMutation builder. func (m *PostContentMutation) Where(ps ...predicate.PostContent) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the PostContentMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *PostContentMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.PostContent, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *PostContentMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *PostContentMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (PostContent). func (m *PostContentMutation) 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 *PostContentMutation) Fields() []string { fields := make([]string, 0, 7) if m.language_code != nil { fields = append(fields, postcontent.FieldLanguageCode) } if m.title != nil { fields = append(fields, postcontent.FieldTitle) } if m.content_markdown != nil { fields = append(fields, postcontent.FieldContentMarkdown) } if m.summary != nil { fields = append(fields, postcontent.FieldSummary) } if m.meta_keywords != nil { fields = append(fields, postcontent.FieldMetaKeywords) } if m.meta_description != nil { fields = append(fields, postcontent.FieldMetaDescription) } if m.slug != nil { fields = append(fields, postcontent.FieldSlug) } 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 *PostContentMutation) Field(name string) (ent.Value, bool) { switch name { case postcontent.FieldLanguageCode: return m.LanguageCode() case postcontent.FieldTitle: return m.Title() case postcontent.FieldContentMarkdown: return m.ContentMarkdown() case postcontent.FieldSummary: return m.Summary() case postcontent.FieldMetaKeywords: return m.MetaKeywords() case postcontent.FieldMetaDescription: return m.MetaDescription() case postcontent.FieldSlug: return m.Slug() } 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 *PostContentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case postcontent.FieldLanguageCode: return m.OldLanguageCode(ctx) case postcontent.FieldTitle: return m.OldTitle(ctx) case postcontent.FieldContentMarkdown: return m.OldContentMarkdown(ctx) case postcontent.FieldSummary: return m.OldSummary(ctx) case postcontent.FieldMetaKeywords: return m.OldMetaKeywords(ctx) case postcontent.FieldMetaDescription: return m.OldMetaDescription(ctx) case postcontent.FieldSlug: return m.OldSlug(ctx) } return nil, fmt.Errorf("unknown PostContent 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 *PostContentMutation) SetField(name string, value ent.Value) error { switch name { case postcontent.FieldLanguageCode: v, ok := value.(postcontent.LanguageCode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLanguageCode(v) return nil case postcontent.FieldTitle: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTitle(v) return nil case postcontent.FieldContentMarkdown: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetContentMarkdown(v) return nil case postcontent.FieldSummary: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSummary(v) return nil case postcontent.FieldMetaKeywords: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetMetaKeywords(v) return nil case postcontent.FieldMetaDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetMetaDescription(v) return nil case postcontent.FieldSlug: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSlug(v) return nil } return fmt.Errorf("unknown PostContent field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *PostContentMutation) 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 *PostContentMutation) 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 *PostContentMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown PostContent numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *PostContentMutation) ClearedFields() []string { var fields []string if m.FieldCleared(postcontent.FieldMetaKeywords) { fields = append(fields, postcontent.FieldMetaKeywords) } if m.FieldCleared(postcontent.FieldMetaDescription) { fields = append(fields, postcontent.FieldMetaDescription) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *PostContentMutation) 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 *PostContentMutation) ClearField(name string) error { switch name { case postcontent.FieldMetaKeywords: m.ClearMetaKeywords() return nil case postcontent.FieldMetaDescription: m.ClearMetaDescription() return nil } return fmt.Errorf("unknown PostContent 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 *PostContentMutation) ResetField(name string) error { switch name { case postcontent.FieldLanguageCode: m.ResetLanguageCode() return nil case postcontent.FieldTitle: m.ResetTitle() return nil case postcontent.FieldContentMarkdown: m.ResetContentMarkdown() return nil case postcontent.FieldSummary: m.ResetSummary() return nil case postcontent.FieldMetaKeywords: m.ResetMetaKeywords() return nil case postcontent.FieldMetaDescription: m.ResetMetaDescription() return nil case postcontent.FieldSlug: m.ResetSlug() return nil } return fmt.Errorf("unknown PostContent field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *PostContentMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.post != nil { edges = append(edges, postcontent.EdgePost) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *PostContentMutation) AddedIDs(name string) []ent.Value { switch name { case postcontent.EdgePost: if id := m.post; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *PostContentMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *PostContentMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *PostContentMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedpost { edges = append(edges, postcontent.EdgePost) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *PostContentMutation) EdgeCleared(name string) bool { switch name { case postcontent.EdgePost: return m.clearedpost } 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 *PostContentMutation) ClearEdge(name string) error { switch name { case postcontent.EdgePost: m.ClearPost() return nil } return fmt.Errorf("unknown PostContent 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 *PostContentMutation) ResetEdge(name string) error { switch name { case postcontent.EdgePost: m.ResetPost() return nil } return fmt.Errorf("unknown PostContent edge %s", name) } // PostContributorMutation represents an operation that mutates the PostContributor nodes in the graph. type PostContributorMutation struct { config op Op typ string id *int language_code *postcontributor.LanguageCode created_at *time.Time clearedFields map[string]struct{} post *int clearedpost bool contributor *int clearedcontributor bool role *int clearedrole bool done bool oldValue func(context.Context) (*PostContributor, error) predicates []predicate.PostContributor } var _ ent.Mutation = (*PostContributorMutation)(nil) // postcontributorOption allows management of the mutation configuration using functional options. type postcontributorOption func(*PostContributorMutation) // newPostContributorMutation creates new mutation for the PostContributor entity. func newPostContributorMutation(c config, op Op, opts ...postcontributorOption) *PostContributorMutation { m := &PostContributorMutation{ config: c, op: op, typ: TypePostContributor, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withPostContributorID sets the ID field of the mutation. func withPostContributorID(id int) postcontributorOption { return func(m *PostContributorMutation) { var ( err error once sync.Once value *PostContributor ) m.oldValue = func(ctx context.Context) (*PostContributor, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().PostContributor.Get(ctx, id) } }) return value, err } m.id = &id } } // withPostContributor sets the old PostContributor of the mutation. func withPostContributor(node *PostContributor) postcontributorOption { return func(m *PostContributorMutation) { m.oldValue = func(context.Context) (*PostContributor, 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 PostContributorMutation) 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 PostContributorMutation) 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 } // 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 *PostContributorMutation) ID() (id int, 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 *PostContributorMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().PostContributor.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetLanguageCode sets the "language_code" field. func (m *PostContributorMutation) SetLanguageCode(pc postcontributor.LanguageCode) { m.language_code = &pc } // LanguageCode returns the value of the "language_code" field in the mutation. func (m *PostContributorMutation) LanguageCode() (r postcontributor.LanguageCode, exists bool) { v := m.language_code if v == nil { return } return *v, true } // OldLanguageCode returns the old "language_code" field's value of the PostContributor entity. // If the PostContributor 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 *PostContributorMutation) OldLanguageCode(ctx context.Context) (v *postcontributor.LanguageCode, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLanguageCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLanguageCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLanguageCode: %w", err) } return oldValue.LanguageCode, nil } // ClearLanguageCode clears the value of the "language_code" field. func (m *PostContributorMutation) ClearLanguageCode() { m.language_code = nil m.clearedFields[postcontributor.FieldLanguageCode] = struct{}{} } // LanguageCodeCleared returns if the "language_code" field was cleared in this mutation. func (m *PostContributorMutation) LanguageCodeCleared() bool { _, ok := m.clearedFields[postcontributor.FieldLanguageCode] return ok } // ResetLanguageCode resets all changes to the "language_code" field. func (m *PostContributorMutation) ResetLanguageCode() { m.language_code = nil delete(m.clearedFields, postcontributor.FieldLanguageCode) } // SetCreatedAt sets the "created_at" field. func (m *PostContributorMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *PostContributorMutation) 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 PostContributor entity. // If the PostContributor 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 *PostContributorMutation) 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 *PostContributorMutation) ResetCreatedAt() { m.created_at = nil } // SetPostID sets the "post" edge to the Post entity by id. func (m *PostContributorMutation) SetPostID(id int) { m.post = &id } // ClearPost clears the "post" edge to the Post entity. func (m *PostContributorMutation) ClearPost() { m.clearedpost = true } // PostCleared reports if the "post" edge to the Post entity was cleared. func (m *PostContributorMutation) PostCleared() bool { return m.clearedpost } // PostID returns the "post" edge ID in the mutation. func (m *PostContributorMutation) PostID() (id int, exists bool) { if m.post != nil { return *m.post, true } return } // PostIDs returns the "post" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // PostID instead. It exists only for internal usage by the builders. func (m *PostContributorMutation) PostIDs() (ids []int) { if id := m.post; id != nil { ids = append(ids, *id) } return } // ResetPost resets all changes to the "post" edge. func (m *PostContributorMutation) ResetPost() { m.post = nil m.clearedpost = false } // SetContributorID sets the "contributor" edge to the Contributor entity by id. func (m *PostContributorMutation) SetContributorID(id int) { m.contributor = &id } // ClearContributor clears the "contributor" edge to the Contributor entity. func (m *PostContributorMutation) ClearContributor() { m.clearedcontributor = true } // ContributorCleared reports if the "contributor" edge to the Contributor entity was cleared. func (m *PostContributorMutation) ContributorCleared() bool { return m.clearedcontributor } // ContributorID returns the "contributor" edge ID in the mutation. func (m *PostContributorMutation) ContributorID() (id int, exists bool) { if m.contributor != nil { return *m.contributor, true } return } // ContributorIDs returns the "contributor" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // ContributorID instead. It exists only for internal usage by the builders. func (m *PostContributorMutation) ContributorIDs() (ids []int) { if id := m.contributor; id != nil { ids = append(ids, *id) } return } // ResetContributor resets all changes to the "contributor" edge. func (m *PostContributorMutation) ResetContributor() { m.contributor = nil m.clearedcontributor = false } // SetRoleID sets the "role" edge to the ContributorRole entity by id. func (m *PostContributorMutation) SetRoleID(id int) { m.role = &id } // ClearRole clears the "role" edge to the ContributorRole entity. func (m *PostContributorMutation) ClearRole() { m.clearedrole = true } // RoleCleared reports if the "role" edge to the ContributorRole entity was cleared. func (m *PostContributorMutation) RoleCleared() bool { return m.clearedrole } // RoleID returns the "role" edge ID in the mutation. func (m *PostContributorMutation) RoleID() (id int, exists bool) { if m.role != nil { return *m.role, true } return } // RoleIDs returns the "role" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // RoleID instead. It exists only for internal usage by the builders. func (m *PostContributorMutation) RoleIDs() (ids []int) { if id := m.role; id != nil { ids = append(ids, *id) } return } // ResetRole resets all changes to the "role" edge. func (m *PostContributorMutation) ResetRole() { m.role = nil m.clearedrole = false } // Where appends a list predicates to the PostContributorMutation builder. func (m *PostContributorMutation) Where(ps ...predicate.PostContributor) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the PostContributorMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *PostContributorMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.PostContributor, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *PostContributorMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *PostContributorMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (PostContributor). func (m *PostContributorMutation) 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 *PostContributorMutation) Fields() []string { fields := make([]string, 0, 2) if m.language_code != nil { fields = append(fields, postcontributor.FieldLanguageCode) } if m.created_at != nil { fields = append(fields, postcontributor.FieldCreatedAt) } 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 *PostContributorMutation) Field(name string) (ent.Value, bool) { switch name { case postcontributor.FieldLanguageCode: return m.LanguageCode() case postcontributor.FieldCreatedAt: return m.CreatedAt() } 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 *PostContributorMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case postcontributor.FieldLanguageCode: return m.OldLanguageCode(ctx) case postcontributor.FieldCreatedAt: return m.OldCreatedAt(ctx) } return nil, fmt.Errorf("unknown PostContributor 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 *PostContributorMutation) SetField(name string, value ent.Value) error { switch name { case postcontributor.FieldLanguageCode: v, ok := value.(postcontributor.LanguageCode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLanguageCode(v) return nil case postcontributor.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil } return fmt.Errorf("unknown PostContributor field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *PostContributorMutation) 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 *PostContributorMutation) 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 *PostContributorMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown PostContributor numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *PostContributorMutation) ClearedFields() []string { var fields []string if m.FieldCleared(postcontributor.FieldLanguageCode) { fields = append(fields, postcontributor.FieldLanguageCode) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *PostContributorMutation) 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 *PostContributorMutation) ClearField(name string) error { switch name { case postcontributor.FieldLanguageCode: m.ClearLanguageCode() return nil } return fmt.Errorf("unknown PostContributor 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 *PostContributorMutation) ResetField(name string) error { switch name { case postcontributor.FieldLanguageCode: m.ResetLanguageCode() return nil case postcontributor.FieldCreatedAt: m.ResetCreatedAt() return nil } return fmt.Errorf("unknown PostContributor field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *PostContributorMutation) AddedEdges() []string { edges := make([]string, 0, 3) if m.post != nil { edges = append(edges, postcontributor.EdgePost) } if m.contributor != nil { edges = append(edges, postcontributor.EdgeContributor) } if m.role != nil { edges = append(edges, postcontributor.EdgeRole) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *PostContributorMutation) AddedIDs(name string) []ent.Value { switch name { case postcontributor.EdgePost: if id := m.post; id != nil { return []ent.Value{*id} } case postcontributor.EdgeContributor: if id := m.contributor; id != nil { return []ent.Value{*id} } case postcontributor.EdgeRole: if id := m.role; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *PostContributorMutation) RemovedEdges() []string { edges := make([]string, 0, 3) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *PostContributorMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *PostContributorMutation) ClearedEdges() []string { edges := make([]string, 0, 3) if m.clearedpost { edges = append(edges, postcontributor.EdgePost) } if m.clearedcontributor { edges = append(edges, postcontributor.EdgeContributor) } if m.clearedrole { edges = append(edges, postcontributor.EdgeRole) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *PostContributorMutation) EdgeCleared(name string) bool { switch name { case postcontributor.EdgePost: return m.clearedpost case postcontributor.EdgeContributor: return m.clearedcontributor case postcontributor.EdgeRole: return m.clearedrole } 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 *PostContributorMutation) ClearEdge(name string) error { switch name { case postcontributor.EdgePost: m.ClearPost() return nil case postcontributor.EdgeContributor: m.ClearContributor() return nil case postcontributor.EdgeRole: m.ClearRole() return nil } return fmt.Errorf("unknown PostContributor 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 *PostContributorMutation) ResetEdge(name string) error { switch name { case postcontributor.EdgePost: m.ResetPost() return nil case postcontributor.EdgeContributor: m.ResetContributor() return nil case postcontributor.EdgeRole: m.ResetRole() return nil } return fmt.Errorf("unknown PostContributor edge %s", name) } // RoleMutation represents an operation that mutates the Role nodes in the graph. type RoleMutation struct { config op Op typ string id *int name *string description *string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} permissions map[int]struct{} removedpermissions map[int]struct{} clearedpermissions bool users map[int]struct{} removedusers map[int]struct{} clearedusers bool done bool oldValue func(context.Context) (*Role, error) predicates []predicate.Role } var _ ent.Mutation = (*RoleMutation)(nil) // roleOption allows management of the mutation configuration using functional options. type roleOption func(*RoleMutation) // newRoleMutation creates new mutation for the Role entity. func newRoleMutation(c config, op Op, opts ...roleOption) *RoleMutation { m := &RoleMutation{ config: c, op: op, typ: TypeRole, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withRoleID sets the ID field of the mutation. func withRoleID(id int) roleOption { return func(m *RoleMutation) { var ( err error once sync.Once value *Role ) m.oldValue = func(ctx context.Context) (*Role, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Role.Get(ctx, id) } }) return value, err } m.id = &id } } // withRole sets the old Role of the mutation. func withRole(node *Role) roleOption { return func(m *RoleMutation) { m.oldValue = func(context.Context) (*Role, 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 RoleMutation) 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 RoleMutation) 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 } // 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 *RoleMutation) ID() (id int, 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 *RoleMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Role.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetName sets the "name" field. func (m *RoleMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *RoleMutation) 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 Role entity. // If the Role 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 *RoleMutation) 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 } // ResetName resets all changes to the "name" field. func (m *RoleMutation) ResetName() { m.name = nil } // SetDescription sets the "description" field. func (m *RoleMutation) SetDescription(s string) { m.description = &s } // Description returns the value of the "description" field in the mutation. func (m *RoleMutation) 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 Role entity. // If the Role 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 *RoleMutation) 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 *RoleMutation) ClearDescription() { m.description = nil m.clearedFields[role.FieldDescription] = struct{}{} } // DescriptionCleared returns if the "description" field was cleared in this mutation. func (m *RoleMutation) DescriptionCleared() bool { _, ok := m.clearedFields[role.FieldDescription] return ok } // ResetDescription resets all changes to the "description" field. func (m *RoleMutation) ResetDescription() { m.description = nil delete(m.clearedFields, role.FieldDescription) } // SetCreatedAt sets the "created_at" field. func (m *RoleMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *RoleMutation) 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 Role entity. // If the Role 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 *RoleMutation) 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 *RoleMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *RoleMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *RoleMutation) 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 Role entity. // If the Role 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 *RoleMutation) 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 } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *RoleMutation) ResetUpdatedAt() { m.updated_at = nil } // AddPermissionIDs adds the "permissions" edge to the Permission entity by ids. func (m *RoleMutation) AddPermissionIDs(ids ...int) { if m.permissions == nil { m.permissions = make(map[int]struct{}) } for i := range ids { m.permissions[ids[i]] = struct{}{} } } // ClearPermissions clears the "permissions" edge to the Permission entity. func (m *RoleMutation) ClearPermissions() { m.clearedpermissions = true } // PermissionsCleared reports if the "permissions" edge to the Permission entity was cleared. func (m *RoleMutation) PermissionsCleared() bool { return m.clearedpermissions } // RemovePermissionIDs removes the "permissions" edge to the Permission entity by IDs. func (m *RoleMutation) RemovePermissionIDs(ids ...int) { if m.removedpermissions == nil { m.removedpermissions = make(map[int]struct{}) } for i := range ids { delete(m.permissions, ids[i]) m.removedpermissions[ids[i]] = struct{}{} } } // RemovedPermissions returns the removed IDs of the "permissions" edge to the Permission entity. func (m *RoleMutation) RemovedPermissionsIDs() (ids []int) { for id := range m.removedpermissions { ids = append(ids, id) } return } // PermissionsIDs returns the "permissions" edge IDs in the mutation. func (m *RoleMutation) PermissionsIDs() (ids []int) { for id := range m.permissions { ids = append(ids, id) } return } // ResetPermissions resets all changes to the "permissions" edge. func (m *RoleMutation) ResetPermissions() { m.permissions = nil m.clearedpermissions = false m.removedpermissions = nil } // AddUserIDs adds the "users" edge to the User entity by ids. func (m *RoleMutation) AddUserIDs(ids ...int) { if m.users == nil { m.users = make(map[int]struct{}) } for i := range ids { m.users[ids[i]] = struct{}{} } } // ClearUsers clears the "users" edge to the User entity. func (m *RoleMutation) ClearUsers() { m.clearedusers = true } // UsersCleared reports if the "users" edge to the User entity was cleared. func (m *RoleMutation) UsersCleared() bool { return m.clearedusers } // RemoveUserIDs removes the "users" edge to the User entity by IDs. func (m *RoleMutation) RemoveUserIDs(ids ...int) { if m.removedusers == nil { m.removedusers = make(map[int]struct{}) } for i := range ids { delete(m.users, ids[i]) m.removedusers[ids[i]] = struct{}{} } } // RemovedUsers returns the removed IDs of the "users" edge to the User entity. func (m *RoleMutation) RemovedUsersIDs() (ids []int) { for id := range m.removedusers { ids = append(ids, id) } return } // UsersIDs returns the "users" edge IDs in the mutation. func (m *RoleMutation) UsersIDs() (ids []int) { for id := range m.users { ids = append(ids, id) } return } // ResetUsers resets all changes to the "users" edge. func (m *RoleMutation) ResetUsers() { m.users = nil m.clearedusers = false m.removedusers = nil } // Where appends a list predicates to the RoleMutation builder. func (m *RoleMutation) Where(ps ...predicate.Role) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the RoleMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *RoleMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Role, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *RoleMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *RoleMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Role). func (m *RoleMutation) 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 *RoleMutation) Fields() []string { fields := make([]string, 0, 4) if m.name != nil { fields = append(fields, role.FieldName) } if m.description != nil { fields = append(fields, role.FieldDescription) } if m.created_at != nil { fields = append(fields, role.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, role.FieldUpdatedAt) } 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 *RoleMutation) Field(name string) (ent.Value, bool) { switch name { case role.FieldName: return m.Name() case role.FieldDescription: return m.Description() case role.FieldCreatedAt: return m.CreatedAt() case role.FieldUpdatedAt: return m.UpdatedAt() } 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 *RoleMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case role.FieldName: return m.OldName(ctx) case role.FieldDescription: return m.OldDescription(ctx) case role.FieldCreatedAt: return m.OldCreatedAt(ctx) case role.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown Role 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 *RoleMutation) SetField(name string, value ent.Value) error { switch name { case role.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case role.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDescription(v) return nil case role.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 role.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown Role field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *RoleMutation) 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 *RoleMutation) 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 *RoleMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Role numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *RoleMutation) ClearedFields() []string { var fields []string if m.FieldCleared(role.FieldDescription) { fields = append(fields, role.FieldDescription) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *RoleMutation) 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 *RoleMutation) ClearField(name string) error { switch name { case role.FieldDescription: m.ClearDescription() return nil } return fmt.Errorf("unknown Role 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 *RoleMutation) ResetField(name string) error { switch name { case role.FieldName: m.ResetName() return nil case role.FieldDescription: m.ResetDescription() return nil case role.FieldCreatedAt: m.ResetCreatedAt() return nil case role.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown Role field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *RoleMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.permissions != nil { edges = append(edges, role.EdgePermissions) } if m.users != nil { edges = append(edges, role.EdgeUsers) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *RoleMutation) AddedIDs(name string) []ent.Value { switch name { case role.EdgePermissions: ids := make([]ent.Value, 0, len(m.permissions)) for id := range m.permissions { ids = append(ids, id) } return ids case role.EdgeUsers: ids := make([]ent.Value, 0, len(m.users)) for id := range m.users { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *RoleMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedpermissions != nil { edges = append(edges, role.EdgePermissions) } if m.removedusers != nil { edges = append(edges, role.EdgeUsers) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *RoleMutation) RemovedIDs(name string) []ent.Value { switch name { case role.EdgePermissions: ids := make([]ent.Value, 0, len(m.removedpermissions)) for id := range m.removedpermissions { ids = append(ids, id) } return ids case role.EdgeUsers: ids := make([]ent.Value, 0, len(m.removedusers)) for id := range m.removedusers { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *RoleMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedpermissions { edges = append(edges, role.EdgePermissions) } if m.clearedusers { edges = append(edges, role.EdgeUsers) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *RoleMutation) EdgeCleared(name string) bool { switch name { case role.EdgePermissions: return m.clearedpermissions case role.EdgeUsers: return m.clearedusers } 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 *RoleMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown Role 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 *RoleMutation) ResetEdge(name string) error { switch name { case role.EdgePermissions: m.ResetPermissions() return nil case role.EdgeUsers: m.ResetUsers() return nil } return fmt.Errorf("unknown Role edge %s", name) } // UserMutation represents an operation that mutates the User nodes in the graph. type UserMutation struct { config op Op typ string id *int username *string display_name *string email *string password_hash *string status *user.Status created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} roles map[int]struct{} removedroles map[int]struct{} clearedroles bool contributors map[int]struct{} removedcontributors map[int]struct{} clearedcontributors bool media map[int]struct{} removedmedia map[int]struct{} clearedmedia bool done bool oldValue func(context.Context) (*User, error) predicates []predicate.User } var _ ent.Mutation = (*UserMutation)(nil) // userOption allows management of the mutation configuration using functional options. type userOption func(*UserMutation) // newUserMutation creates new mutation for the User entity. func newUserMutation(c config, op Op, opts ...userOption) *UserMutation { m := &UserMutation{ config: c, op: op, typ: TypeUser, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withUserID sets the ID field of the mutation. func withUserID(id int) userOption { return func(m *UserMutation) { var ( err error once sync.Once value *User ) m.oldValue = func(ctx context.Context) (*User, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().User.Get(ctx, id) } }) return value, err } m.id = &id } } // withUser sets the old User of the mutation. func withUser(node *User) userOption { return func(m *UserMutation) { m.oldValue = func(context.Context) (*User, 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 UserMutation) 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 UserMutation) 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 } // 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 *UserMutation) ID() (id int, 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 *UserMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().User.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetUsername sets the "username" field. func (m *UserMutation) SetUsername(s string) { m.username = &s } // Username returns the value of the "username" field in the mutation. func (m *UserMutation) Username() (r string, exists bool) { v := m.username if v == nil { return } return *v, true } // OldUsername returns the old "username" field's value of the User entity. // If the User 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 *UserMutation) OldUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUsername: %w", err) } return oldValue.Username, nil } // ResetUsername resets all changes to the "username" field. func (m *UserMutation) ResetUsername() { m.username = nil } // SetDisplayName sets the "display_name" field. func (m *UserMutation) SetDisplayName(s string) { m.display_name = &s } // DisplayName returns the value of the "display_name" field in the mutation. func (m *UserMutation) DisplayName() (r string, exists bool) { v := m.display_name if v == nil { return } return *v, true } // OldDisplayName returns the old "display_name" field's value of the User entity. // If the User 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 *UserMutation) OldDisplayName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldDisplayName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldDisplayName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldDisplayName: %w", err) } return oldValue.DisplayName, nil } // ClearDisplayName clears the value of the "display_name" field. func (m *UserMutation) ClearDisplayName() { m.display_name = nil m.clearedFields[user.FieldDisplayName] = struct{}{} } // DisplayNameCleared returns if the "display_name" field was cleared in this mutation. func (m *UserMutation) DisplayNameCleared() bool { _, ok := m.clearedFields[user.FieldDisplayName] return ok } // ResetDisplayName resets all changes to the "display_name" field. func (m *UserMutation) ResetDisplayName() { m.display_name = nil delete(m.clearedFields, user.FieldDisplayName) } // SetEmail sets the "email" field. func (m *UserMutation) SetEmail(s string) { m.email = &s } // Email returns the value of the "email" field in the mutation. func (m *UserMutation) Email() (r string, exists bool) { v := m.email if v == nil { return } return *v, true } // OldEmail returns the old "email" field's value of the User entity. // If the User 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 *UserMutation) OldEmail(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldEmail is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldEmail requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldEmail: %w", err) } return oldValue.Email, nil } // ResetEmail resets all changes to the "email" field. func (m *UserMutation) ResetEmail() { m.email = nil } // SetPasswordHash sets the "password_hash" field. func (m *UserMutation) SetPasswordHash(s string) { m.password_hash = &s } // PasswordHash returns the value of the "password_hash" field in the mutation. func (m *UserMutation) PasswordHash() (r string, exists bool) { v := m.password_hash if v == nil { return } return *v, true } // OldPasswordHash returns the old "password_hash" field's value of the User entity. // If the User 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 *UserMutation) OldPasswordHash(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPasswordHash is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPasswordHash requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPasswordHash: %w", err) } return oldValue.PasswordHash, nil } // ResetPasswordHash resets all changes to the "password_hash" field. func (m *UserMutation) ResetPasswordHash() { m.password_hash = nil } // SetStatus sets the "status" field. func (m *UserMutation) SetStatus(u user.Status) { m.status = &u } // Status returns the value of the "status" field in the mutation. func (m *UserMutation) Status() (r user.Status, exists bool) { v := m.status if v == nil { return } return *v, true } // OldStatus returns the old "status" field's value of the User entity. // If the User 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 *UserMutation) OldStatus(ctx context.Context) (v user.Status, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldStatus: %w", err) } return oldValue.Status, nil } // ResetStatus resets all changes to the "status" field. func (m *UserMutation) ResetStatus() { m.status = nil } // SetCreatedAt sets the "created_at" field. func (m *UserMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *UserMutation) 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 User entity. // If the User 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 *UserMutation) 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 *UserMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. func (m *UserMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. func (m *UserMutation) 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 User entity. // If the User 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 *UserMutation) 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 } // ResetUpdatedAt resets all changes to the "updated_at" field. func (m *UserMutation) ResetUpdatedAt() { m.updated_at = nil } // AddRoleIDs adds the "roles" edge to the Role entity by ids. func (m *UserMutation) AddRoleIDs(ids ...int) { if m.roles == nil { m.roles = make(map[int]struct{}) } for i := range ids { m.roles[ids[i]] = struct{}{} } } // ClearRoles clears the "roles" edge to the Role entity. func (m *UserMutation) ClearRoles() { m.clearedroles = true } // RolesCleared reports if the "roles" edge to the Role entity was cleared. func (m *UserMutation) RolesCleared() bool { return m.clearedroles } // RemoveRoleIDs removes the "roles" edge to the Role entity by IDs. func (m *UserMutation) RemoveRoleIDs(ids ...int) { if m.removedroles == nil { m.removedroles = make(map[int]struct{}) } for i := range ids { delete(m.roles, ids[i]) m.removedroles[ids[i]] = struct{}{} } } // RemovedRoles returns the removed IDs of the "roles" edge to the Role entity. func (m *UserMutation) RemovedRolesIDs() (ids []int) { for id := range m.removedroles { ids = append(ids, id) } return } // RolesIDs returns the "roles" edge IDs in the mutation. func (m *UserMutation) RolesIDs() (ids []int) { for id := range m.roles { ids = append(ids, id) } return } // ResetRoles resets all changes to the "roles" edge. func (m *UserMutation) ResetRoles() { m.roles = nil m.clearedroles = false m.removedroles = nil } // AddContributorIDs adds the "contributors" edge to the Contributor entity by ids. func (m *UserMutation) AddContributorIDs(ids ...int) { if m.contributors == nil { m.contributors = make(map[int]struct{}) } for i := range ids { m.contributors[ids[i]] = struct{}{} } } // ClearContributors clears the "contributors" edge to the Contributor entity. func (m *UserMutation) ClearContributors() { m.clearedcontributors = true } // ContributorsCleared reports if the "contributors" edge to the Contributor entity was cleared. func (m *UserMutation) ContributorsCleared() bool { return m.clearedcontributors } // RemoveContributorIDs removes the "contributors" edge to the Contributor entity by IDs. func (m *UserMutation) RemoveContributorIDs(ids ...int) { if m.removedcontributors == nil { m.removedcontributors = make(map[int]struct{}) } for i := range ids { delete(m.contributors, ids[i]) m.removedcontributors[ids[i]] = struct{}{} } } // RemovedContributors returns the removed IDs of the "contributors" edge to the Contributor entity. func (m *UserMutation) RemovedContributorsIDs() (ids []int) { for id := range m.removedcontributors { ids = append(ids, id) } return } // ContributorsIDs returns the "contributors" edge IDs in the mutation. func (m *UserMutation) ContributorsIDs() (ids []int) { for id := range m.contributors { ids = append(ids, id) } return } // ResetContributors resets all changes to the "contributors" edge. func (m *UserMutation) ResetContributors() { m.contributors = nil m.clearedcontributors = false m.removedcontributors = nil } // AddMediumIDs adds the "media" edge to the Media entity by ids. func (m *UserMutation) AddMediumIDs(ids ...int) { if m.media == nil { m.media = make(map[int]struct{}) } for i := range ids { m.media[ids[i]] = struct{}{} } } // ClearMedia clears the "media" edge to the Media entity. func (m *UserMutation) ClearMedia() { m.clearedmedia = true } // MediaCleared reports if the "media" edge to the Media entity was cleared. func (m *UserMutation) MediaCleared() bool { return m.clearedmedia } // RemoveMediumIDs removes the "media" edge to the Media entity by IDs. func (m *UserMutation) RemoveMediumIDs(ids ...int) { if m.removedmedia == nil { m.removedmedia = make(map[int]struct{}) } for i := range ids { delete(m.media, ids[i]) m.removedmedia[ids[i]] = struct{}{} } } // RemovedMedia returns the removed IDs of the "media" edge to the Media entity. func (m *UserMutation) RemovedMediaIDs() (ids []int) { for id := range m.removedmedia { ids = append(ids, id) } return } // MediaIDs returns the "media" edge IDs in the mutation. func (m *UserMutation) MediaIDs() (ids []int) { for id := range m.media { ids = append(ids, id) } return } // ResetMedia resets all changes to the "media" edge. func (m *UserMutation) ResetMedia() { m.media = nil m.clearedmedia = false m.removedmedia = nil } // Where appends a list predicates to the UserMutation builder. func (m *UserMutation) Where(ps ...predicate.User) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the UserMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.User, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *UserMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *UserMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (User). func (m *UserMutation) 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 *UserMutation) Fields() []string { fields := make([]string, 0, 7) if m.username != nil { fields = append(fields, user.FieldUsername) } if m.display_name != nil { fields = append(fields, user.FieldDisplayName) } if m.email != nil { fields = append(fields, user.FieldEmail) } if m.password_hash != nil { fields = append(fields, user.FieldPasswordHash) } if m.status != nil { fields = append(fields, user.FieldStatus) } if m.created_at != nil { fields = append(fields, user.FieldCreatedAt) } if m.updated_at != nil { fields = append(fields, user.FieldUpdatedAt) } 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 *UserMutation) Field(name string) (ent.Value, bool) { switch name { case user.FieldUsername: return m.Username() case user.FieldDisplayName: return m.DisplayName() case user.FieldEmail: return m.Email() case user.FieldPasswordHash: return m.PasswordHash() case user.FieldStatus: return m.Status() case user.FieldCreatedAt: return m.CreatedAt() case user.FieldUpdatedAt: return m.UpdatedAt() } 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 *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case user.FieldUsername: return m.OldUsername(ctx) case user.FieldDisplayName: return m.OldDisplayName(ctx) case user.FieldEmail: return m.OldEmail(ctx) case user.FieldPasswordHash: return m.OldPasswordHash(ctx) case user.FieldStatus: return m.OldStatus(ctx) case user.FieldCreatedAt: return m.OldCreatedAt(ctx) case user.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } return nil, fmt.Errorf("unknown User 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 *UserMutation) SetField(name string, value ent.Value) error { switch name { case user.FieldUsername: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUsername(v) return nil case user.FieldDisplayName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetDisplayName(v) return nil case user.FieldEmail: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetEmail(v) return nil case user.FieldPasswordHash: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPasswordHash(v) return nil case user.FieldStatus: v, ok := value.(user.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil case user.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 user.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil } return fmt.Errorf("unknown User field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *UserMutation) 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 *UserMutation) 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 *UserMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown User numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *UserMutation) ClearedFields() []string { var fields []string if m.FieldCleared(user.FieldDisplayName) { fields = append(fields, user.FieldDisplayName) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *UserMutation) 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 *UserMutation) ClearField(name string) error { switch name { case user.FieldDisplayName: m.ClearDisplayName() return nil } return fmt.Errorf("unknown User 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 *UserMutation) ResetField(name string) error { switch name { case user.FieldUsername: m.ResetUsername() return nil case user.FieldDisplayName: m.ResetDisplayName() return nil case user.FieldEmail: m.ResetEmail() return nil case user.FieldPasswordHash: m.ResetPasswordHash() return nil case user.FieldStatus: m.ResetStatus() return nil case user.FieldCreatedAt: m.ResetCreatedAt() return nil case user.FieldUpdatedAt: m.ResetUpdatedAt() return nil } return fmt.Errorf("unknown User field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *UserMutation) AddedEdges() []string { edges := make([]string, 0, 3) if m.roles != nil { edges = append(edges, user.EdgeRoles) } if m.contributors != nil { edges = append(edges, user.EdgeContributors) } if m.media != nil { edges = append(edges, user.EdgeMedia) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *UserMutation) AddedIDs(name string) []ent.Value { switch name { case user.EdgeRoles: ids := make([]ent.Value, 0, len(m.roles)) for id := range m.roles { ids = append(ids, id) } return ids case user.EdgeContributors: ids := make([]ent.Value, 0, len(m.contributors)) for id := range m.contributors { ids = append(ids, id) } return ids case user.EdgeMedia: ids := make([]ent.Value, 0, len(m.media)) for id := range m.media { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserMutation) RemovedEdges() []string { edges := make([]string, 0, 3) if m.removedroles != nil { edges = append(edges, user.EdgeRoles) } if m.removedcontributors != nil { edges = append(edges, user.EdgeContributors) } if m.removedmedia != nil { edges = append(edges, user.EdgeMedia) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *UserMutation) RemovedIDs(name string) []ent.Value { switch name { case user.EdgeRoles: ids := make([]ent.Value, 0, len(m.removedroles)) for id := range m.removedroles { ids = append(ids, id) } return ids case user.EdgeContributors: ids := make([]ent.Value, 0, len(m.removedcontributors)) for id := range m.removedcontributors { ids = append(ids, id) } return ids case user.EdgeMedia: ids := make([]ent.Value, 0, len(m.removedmedia)) for id := range m.removedmedia { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserMutation) ClearedEdges() []string { edges := make([]string, 0, 3) if m.clearedroles { edges = append(edges, user.EdgeRoles) } if m.clearedcontributors { edges = append(edges, user.EdgeContributors) } if m.clearedmedia { edges = append(edges, user.EdgeMedia) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *UserMutation) EdgeCleared(name string) bool { switch name { case user.EdgeRoles: return m.clearedroles case user.EdgeContributors: return m.clearedcontributors case user.EdgeMedia: return m.clearedmedia } 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 *UserMutation) ClearEdge(name string) error { switch name { } return fmt.Errorf("unknown User 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 *UserMutation) ResetEdge(name string) error { switch name { case user.EdgeRoles: m.ResetRoles() return nil case user.EdgeContributors: m.ResetContributors() return nil case user.EdgeMedia: m.ResetMedia() return nil } return fmt.Errorf("unknown User edge %s", name) }