Files
upstream-ent/entc/integration/edgeschema/ent/tweet/mutation.go
upstream-mirror 4b3ad0b611
Some checks failed
Atlas CI Public / lint (push) Failing after 13s
Atlas CI Public / sync (push) Has been skipped
snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 22:12:36 +05:00

660 lines
17 KiB
Go

// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
// Code generated by ent, DO NOT EDIT.
package tweet
import (
"context"
"fmt"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/entc/integration/edgeschema/ent/predicate"
"github.com/google/uuid"
)
// Mutation represents an operation that mutates the Tweet nodes in the graph.
type Mutation struct {
op ent.Op
typ string
text *string
clearedFields map[string]struct{}
liked_users map[int]struct{}
removedliked_users map[int]struct{}
clearedliked_users bool
user map[int]struct{}
removeduser map[int]struct{}
cleareduser bool
tags map[int]struct{}
removedtags map[int]struct{}
clearedtags bool
tweet_user map[int]struct{}
removedtweet_user map[int]struct{}
clearedtweet_user bool
tweet_tags map[uuid.UUID]struct{}
removedtweet_tags map[uuid.UUID]struct{}
clearedtweet_tags bool
predicates []predicate.Tweet
}
// NewMutation creates a new Mutation for the Tweet entity.
func NewMutation(op ent.Op) *Mutation {
return &Mutation{
op: op,
typ: "Tweet",
clearedFields: make(map[string]struct{}),
}
}
// Predicates returns the list of predicates set on the mutation.
func (m *Mutation) Predicates() []predicate.Tweet {
return m.predicates
}
// SetText sets the "text" field.
func (m *Mutation) SetText(s string) {
m.text = &s
}
// Text returns the value of the "text" field in the mutation.
func (m *Mutation) Text() (r string, exists bool) {
v := m.text
if v == nil {
return
}
return *v, true
}
// ResetText resets all changes to the "text" field.
func (m *Mutation) ResetText() {
m.text = nil
}
// AddLikedUserIDs adds the "liked_users" edge to the User entity by ids.
func (m *Mutation) AddLikedUserIDs(ids ...int) {
if m.liked_users == nil {
m.liked_users = make(map[int]struct{})
}
for i := range ids {
m.liked_users[ids[i]] = struct{}{}
}
}
// ClearLikedUsers clears the "liked_users" edge to the User entity.
func (m *Mutation) ClearLikedUsers() {
m.clearedliked_users = true
}
// LikedUsersCleared reports if the "liked_users" edge to the User entity was cleared.
func (m *Mutation) LikedUsersCleared() bool {
return m.clearedliked_users
}
// RemoveLikedUserIDs removes the "liked_users" edge to the User entity by IDs.
func (m *Mutation) RemoveLikedUserIDs(ids ...int) {
if m.removedliked_users == nil {
m.removedliked_users = make(map[int]struct{})
}
for i := range ids {
delete(m.liked_users, ids[i])
m.removedliked_users[ids[i]] = struct{}{}
}
}
// RemovedLikedUsers returns the removed IDs of the "liked_users" edge to the User entity.
func (m *Mutation) RemovedLikedUsersIDs() (ids []int) {
for id := range m.removedliked_users {
ids = append(ids, id)
}
return
}
// LikedUsersIDs returns the "liked_users" edge IDs in the mutation.
func (m *Mutation) LikedUsersIDs() (ids []int) {
for id := range m.liked_users {
ids = append(ids, id)
}
return
}
// ResetLikedUsers resets all changes to the "liked_users" edge.
func (m *Mutation) ResetLikedUsers() {
m.liked_users = nil
m.clearedliked_users = false
m.removedliked_users = nil
}
// AddUserIDs adds the "user" edge to the User entity by ids.
func (m *Mutation) AddUserIDs(ids ...int) {
if m.user == nil {
m.user = make(map[int]struct{})
}
for i := range ids {
m.user[ids[i]] = struct{}{}
}
}
// ClearUser clears the "user" edge to the User entity.
func (m *Mutation) ClearUser() {
m.cleareduser = true
}
// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *Mutation) UserCleared() bool {
return m.cleareduser
}
// RemoveUserIDs removes the "user" edge to the User entity by IDs.
func (m *Mutation) RemoveUserIDs(ids ...int) {
if m.removeduser == nil {
m.removeduser = make(map[int]struct{})
}
for i := range ids {
delete(m.user, ids[i])
m.removeduser[ids[i]] = struct{}{}
}
}
// RemovedUser returns the removed IDs of the "user" edge to the User entity.
func (m *Mutation) RemovedUserIDs() (ids []int) {
for id := range m.removeduser {
ids = append(ids, id)
}
return
}
// UserIDs returns the "user" edge IDs in the mutation.
func (m *Mutation) UserIDs() (ids []int) {
for id := range m.user {
ids = append(ids, id)
}
return
}
// ResetUser resets all changes to the "user" edge.
func (m *Mutation) ResetUser() {
m.user = nil
m.cleareduser = false
m.removeduser = nil
}
// AddTagIDs adds the "tags" edge to the Tag entity by ids.
func (m *Mutation) AddTagIDs(ids ...int) {
if m.tags == nil {
m.tags = make(map[int]struct{})
}
for i := range ids {
m.tags[ids[i]] = struct{}{}
}
}
// ClearTags clears the "tags" edge to the Tag entity.
func (m *Mutation) ClearTags() {
m.clearedtags = true
}
// TagsCleared reports if the "tags" edge to the Tag entity was cleared.
func (m *Mutation) TagsCleared() bool {
return m.clearedtags
}
// RemoveTagIDs removes the "tags" edge to the Tag entity by IDs.
func (m *Mutation) RemoveTagIDs(ids ...int) {
if m.removedtags == nil {
m.removedtags = make(map[int]struct{})
}
for i := range ids {
delete(m.tags, ids[i])
m.removedtags[ids[i]] = struct{}{}
}
}
// RemovedTags returns the removed IDs of the "tags" edge to the Tag entity.
func (m *Mutation) RemovedTagsIDs() (ids []int) {
for id := range m.removedtags {
ids = append(ids, id)
}
return
}
// TagsIDs returns the "tags" edge IDs in the mutation.
func (m *Mutation) TagsIDs() (ids []int) {
for id := range m.tags {
ids = append(ids, id)
}
return
}
// ResetTags resets all changes to the "tags" edge.
func (m *Mutation) ResetTags() {
m.tags = nil
m.clearedtags = false
m.removedtags = nil
}
// AddTweetUserIDs adds the "tweet_user" edge to the UserTweet entity by ids.
func (m *Mutation) AddTweetUserIDs(ids ...int) {
if m.tweet_user == nil {
m.tweet_user = make(map[int]struct{})
}
for i := range ids {
m.tweet_user[ids[i]] = struct{}{}
}
}
// ClearTweetUser clears the "tweet_user" edge to the UserTweet entity.
func (m *Mutation) ClearTweetUser() {
m.clearedtweet_user = true
}
// TweetUserCleared reports if the "tweet_user" edge to the UserTweet entity was cleared.
func (m *Mutation) TweetUserCleared() bool {
return m.clearedtweet_user
}
// RemoveTweetUserIDs removes the "tweet_user" edge to the UserTweet entity by IDs.
func (m *Mutation) RemoveTweetUserIDs(ids ...int) {
if m.removedtweet_user == nil {
m.removedtweet_user = make(map[int]struct{})
}
for i := range ids {
delete(m.tweet_user, ids[i])
m.removedtweet_user[ids[i]] = struct{}{}
}
}
// RemovedTweetUser returns the removed IDs of the "tweet_user" edge to the UserTweet entity.
func (m *Mutation) RemovedTweetUserIDs() (ids []int) {
for id := range m.removedtweet_user {
ids = append(ids, id)
}
return
}
// TweetUserIDs returns the "tweet_user" edge IDs in the mutation.
func (m *Mutation) TweetUserIDs() (ids []int) {
for id := range m.tweet_user {
ids = append(ids, id)
}
return
}
// ResetTweetUser resets all changes to the "tweet_user" edge.
func (m *Mutation) ResetTweetUser() {
m.tweet_user = nil
m.clearedtweet_user = false
m.removedtweet_user = nil
}
// AddTweetTagIDs adds the "tweet_tags" edge to the TweetTag entity by ids.
func (m *Mutation) AddTweetTagIDs(ids ...uuid.UUID) {
if m.tweet_tags == nil {
m.tweet_tags = make(map[uuid.UUID]struct{})
}
for i := range ids {
m.tweet_tags[ids[i]] = struct{}{}
}
}
// ClearTweetTags clears the "tweet_tags" edge to the TweetTag entity.
func (m *Mutation) ClearTweetTags() {
m.clearedtweet_tags = true
}
// TweetTagsCleared reports if the "tweet_tags" edge to the TweetTag entity was cleared.
func (m *Mutation) TweetTagsCleared() bool {
return m.clearedtweet_tags
}
// RemoveTweetTagIDs removes the "tweet_tags" edge to the TweetTag entity by IDs.
func (m *Mutation) RemoveTweetTagIDs(ids ...uuid.UUID) {
if m.removedtweet_tags == nil {
m.removedtweet_tags = make(map[uuid.UUID]struct{})
}
for i := range ids {
delete(m.tweet_tags, ids[i])
m.removedtweet_tags[ids[i]] = struct{}{}
}
}
// RemovedTweetTags returns the removed IDs of the "tweet_tags" edge to the TweetTag entity.
func (m *Mutation) RemovedTweetTagsIDs() (ids []uuid.UUID) {
for id := range m.removedtweet_tags {
ids = append(ids, id)
}
return
}
// TweetTagsIDs returns the "tweet_tags" edge IDs in the mutation.
func (m *Mutation) TweetTagsIDs() (ids []uuid.UUID) {
for id := range m.tweet_tags {
ids = append(ids, id)
}
return
}
// ResetTweetTags resets all changes to the "tweet_tags" edge.
func (m *Mutation) ResetTweetTags() {
m.tweet_tags = nil
m.clearedtweet_tags = false
m.removedtweet_tags = nil
}
// Where appends a list predicates to the Mutation builder.
func (m *Mutation) Where(ps ...predicate.Tweet) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the Mutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *Mutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Tweet, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *Mutation) Op() ent.Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *Mutation) SetOp(op ent.Op) {
m.op = op
}
// Type returns the node type of this mutation (Tweet).
func (m *Mutation) 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 *Mutation) Fields() []string {
fields := make([]string, 0, 1)
if m.text != nil {
fields = append(fields, FieldText)
}
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 *Mutation) Field(name string) (ent.Value, bool) {
switch name {
case FieldText:
return m.Text()
}
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 *Mutation) OldField(ctx context.Context, name string) (ent.Value, error) {
return nil, fmt.Errorf("unknown Tweet 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 *Mutation) SetField(name string, value ent.Value) error {
switch name {
case FieldText:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetText(v)
return nil
}
return fmt.Errorf("unknown Tweet field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *Mutation) 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 *Mutation) 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 *Mutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Tweet numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *Mutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *Mutation) 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 *Mutation) ClearField(name string) error {
return fmt.Errorf("unknown Tweet 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 *Mutation) ResetField(name string) error {
switch name {
case FieldText:
m.ResetText()
return nil
}
return fmt.Errorf("unknown Tweet field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *Mutation) AddedEdges() []string {
edges := make([]string, 0, 5)
if m.liked_users != nil {
edges = append(edges, EdgeLikedUsers)
}
if m.user != nil {
edges = append(edges, EdgeUser)
}
if m.tags != nil {
edges = append(edges, EdgeTags)
}
if m.tweet_user != nil {
edges = append(edges, EdgeTweetUser)
}
if m.tweet_tags != nil {
edges = append(edges, EdgeTweetTags)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *Mutation) AddedIDs(name string) []ent.Value {
switch name {
case EdgeLikedUsers:
ids := make([]ent.Value, 0, len(m.liked_users))
for id := range m.liked_users {
ids = append(ids, id)
}
return ids
case EdgeUser:
ids := make([]ent.Value, 0, len(m.user))
for id := range m.user {
ids = append(ids, id)
}
return ids
case EdgeTags:
ids := make([]ent.Value, 0, len(m.tags))
for id := range m.tags {
ids = append(ids, id)
}
return ids
case EdgeTweetUser:
ids := make([]ent.Value, 0, len(m.tweet_user))
for id := range m.tweet_user {
ids = append(ids, id)
}
return ids
case EdgeTweetTags:
ids := make([]ent.Value, 0, len(m.tweet_tags))
for id := range m.tweet_tags {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *Mutation) RemovedEdges() []string {
edges := make([]string, 0, 5)
if m.removedliked_users != nil {
edges = append(edges, EdgeLikedUsers)
}
if m.removeduser != nil {
edges = append(edges, EdgeUser)
}
if m.removedtags != nil {
edges = append(edges, EdgeTags)
}
if m.removedtweet_user != nil {
edges = append(edges, EdgeTweetUser)
}
if m.removedtweet_tags != nil {
edges = append(edges, EdgeTweetTags)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *Mutation) RemovedIDs(name string) []ent.Value {
switch name {
case EdgeLikedUsers:
ids := make([]ent.Value, 0, len(m.removedliked_users))
for id := range m.removedliked_users {
ids = append(ids, id)
}
return ids
case EdgeUser:
ids := make([]ent.Value, 0, len(m.removeduser))
for id := range m.removeduser {
ids = append(ids, id)
}
return ids
case EdgeTags:
ids := make([]ent.Value, 0, len(m.removedtags))
for id := range m.removedtags {
ids = append(ids, id)
}
return ids
case EdgeTweetUser:
ids := make([]ent.Value, 0, len(m.removedtweet_user))
for id := range m.removedtweet_user {
ids = append(ids, id)
}
return ids
case EdgeTweetTags:
ids := make([]ent.Value, 0, len(m.removedtweet_tags))
for id := range m.removedtweet_tags {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *Mutation) ClearedEdges() []string {
edges := make([]string, 0, 5)
if m.clearedliked_users {
edges = append(edges, EdgeLikedUsers)
}
if m.cleareduser {
edges = append(edges, EdgeUser)
}
if m.clearedtags {
edges = append(edges, EdgeTags)
}
if m.clearedtweet_user {
edges = append(edges, EdgeTweetUser)
}
if m.clearedtweet_tags {
edges = append(edges, EdgeTweetTags)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *Mutation) EdgeCleared(name string) bool {
switch name {
case EdgeLikedUsers:
return m.clearedliked_users
case EdgeUser:
return m.cleareduser
case EdgeTags:
return m.clearedtags
case EdgeTweetUser:
return m.clearedtweet_user
case EdgeTweetTags:
return m.clearedtweet_tags
}
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 *Mutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown Tweet 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 *Mutation) ResetEdge(name string) error {
switch name {
case EdgeLikedUsers:
m.ResetLikedUsers()
return nil
case EdgeUser:
m.ResetUser()
return nil
case EdgeTags:
m.ResetTags()
return nil
case EdgeTweetUser:
m.ResetTweetUser()
return nil
case EdgeTweetTags:
m.ResetTweetTags()
return nil
}
return fmt.Errorf("unknown Tweet edge %s", name)
}