// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "home-vue-go/internal/ent/contact" "home-vue-go/internal/ent/loginhistory" "home-vue-go/internal/ent/predicate" "home-vue-go/internal/ent/site" "home-vue-go/internal/ent/siteconfig" "home-vue-go/internal/ent/user" "home-vue-go/internal/ent/visit" "sync" "time" "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. TypeContact = "Contact" TypeLoginHistory = "LoginHistory" TypeSite = "Site" TypeSiteConfig = "SiteConfig" TypeUser = "User" TypeVisit = "Visit" ) // ContactMutation represents an operation that mutates the Contact nodes in the graph. type ContactMutation struct { config op Op typ string id *int _type *string icon *string url *string qr_code *string hover_color *string sort_order *int addsort_order *int clearedFields map[string]struct{} done bool oldValue func(context.Context) (*Contact, error) predicates []predicate.Contact } var _ ent.Mutation = (*ContactMutation)(nil) // contactOption allows management of the mutation configuration using functional options. type contactOption func(*ContactMutation) // newContactMutation creates new mutation for the Contact entity. func newContactMutation(c config, op Op, opts ...contactOption) *ContactMutation { m := &ContactMutation{ config: c, op: op, typ: TypeContact, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withContactID sets the ID field of the mutation. func withContactID(id int) contactOption { return func(m *ContactMutation) { var ( err error once sync.Once value *Contact ) m.oldValue = func(ctx context.Context) (*Contact, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Contact.Get(ctx, id) } }) return value, err } m.id = &id } } // withContact sets the old Contact of the mutation. func withContact(node *Contact) contactOption { return func(m *ContactMutation) { m.oldValue = func(context.Context) (*Contact, 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 ContactMutation) 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 ContactMutation) 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 Contact entities. func (m *ContactMutation) SetID(id int) { 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 *ContactMutation) 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 *ContactMutation) 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().Contact.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 *ContactMutation) SetType(s string) { m._type = &s } // GetType returns the value of the "type" field in the mutation. func (m *ContactMutation) GetType() (r string, exists bool) { v := m._type if v == nil { return } return *v, true } // OldType returns the old "type" field's value of the Contact entity. // If the Contact 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 *ContactMutation) OldType(ctx context.Context) (v string, 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 *ContactMutation) ResetType() { m._type = nil } // SetIcon sets the "icon" field. func (m *ContactMutation) SetIcon(s string) { m.icon = &s } // Icon returns the value of the "icon" field in the mutation. func (m *ContactMutation) Icon() (r string, exists bool) { v := m.icon if v == nil { return } return *v, true } // OldIcon returns the old "icon" field's value of the Contact entity. // If the Contact 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 *ContactMutation) OldIcon(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIcon is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIcon requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIcon: %w", err) } return oldValue.Icon, nil } // ResetIcon resets all changes to the "icon" field. func (m *ContactMutation) ResetIcon() { m.icon = nil } // SetURL sets the "url" field. func (m *ContactMutation) SetURL(s string) { m.url = &s } // URL returns the value of the "url" field in the mutation. func (m *ContactMutation) 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 Contact entity. // If the Contact 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 *ContactMutation) 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 } // ClearURL clears the value of the "url" field. func (m *ContactMutation) ClearURL() { m.url = nil m.clearedFields[contact.FieldURL] = struct{}{} } // URLCleared returns if the "url" field was cleared in this mutation. func (m *ContactMutation) URLCleared() bool { _, ok := m.clearedFields[contact.FieldURL] return ok } // ResetURL resets all changes to the "url" field. func (m *ContactMutation) ResetURL() { m.url = nil delete(m.clearedFields, contact.FieldURL) } // SetQrCode sets the "qr_code" field. func (m *ContactMutation) SetQrCode(s string) { m.qr_code = &s } // QrCode returns the value of the "qr_code" field in the mutation. func (m *ContactMutation) QrCode() (r string, exists bool) { v := m.qr_code if v == nil { return } return *v, true } // OldQrCode returns the old "qr_code" field's value of the Contact entity. // If the Contact 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 *ContactMutation) OldQrCode(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldQrCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldQrCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldQrCode: %w", err) } return oldValue.QrCode, nil } // ClearQrCode clears the value of the "qr_code" field. func (m *ContactMutation) ClearQrCode() { m.qr_code = nil m.clearedFields[contact.FieldQrCode] = struct{}{} } // QrCodeCleared returns if the "qr_code" field was cleared in this mutation. func (m *ContactMutation) QrCodeCleared() bool { _, ok := m.clearedFields[contact.FieldQrCode] return ok } // ResetQrCode resets all changes to the "qr_code" field. func (m *ContactMutation) ResetQrCode() { m.qr_code = nil delete(m.clearedFields, contact.FieldQrCode) } // SetHoverColor sets the "hover_color" field. func (m *ContactMutation) SetHoverColor(s string) { m.hover_color = &s } // HoverColor returns the value of the "hover_color" field in the mutation. func (m *ContactMutation) HoverColor() (r string, exists bool) { v := m.hover_color if v == nil { return } return *v, true } // OldHoverColor returns the old "hover_color" field's value of the Contact entity. // If the Contact 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 *ContactMutation) OldHoverColor(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldHoverColor is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldHoverColor requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldHoverColor: %w", err) } return oldValue.HoverColor, nil } // ClearHoverColor clears the value of the "hover_color" field. func (m *ContactMutation) ClearHoverColor() { m.hover_color = nil m.clearedFields[contact.FieldHoverColor] = struct{}{} } // HoverColorCleared returns if the "hover_color" field was cleared in this mutation. func (m *ContactMutation) HoverColorCleared() bool { _, ok := m.clearedFields[contact.FieldHoverColor] return ok } // ResetHoverColor resets all changes to the "hover_color" field. func (m *ContactMutation) ResetHoverColor() { m.hover_color = nil delete(m.clearedFields, contact.FieldHoverColor) } // SetSortOrder sets the "sort_order" field. func (m *ContactMutation) SetSortOrder(i int) { m.sort_order = &i m.addsort_order = nil } // SortOrder returns the value of the "sort_order" field in the mutation. func (m *ContactMutation) SortOrder() (r int, exists bool) { v := m.sort_order if v == nil { return } return *v, true } // OldSortOrder returns the old "sort_order" field's value of the Contact entity. // If the Contact 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 *ContactMutation) OldSortOrder(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSortOrder is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSortOrder requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSortOrder: %w", err) } return oldValue.SortOrder, nil } // AddSortOrder adds i to the "sort_order" field. func (m *ContactMutation) AddSortOrder(i int) { if m.addsort_order != nil { *m.addsort_order += i } else { m.addsort_order = &i } } // AddedSortOrder returns the value that was added to the "sort_order" field in this mutation. func (m *ContactMutation) AddedSortOrder() (r int, exists bool) { v := m.addsort_order if v == nil { return } return *v, true } // ResetSortOrder resets all changes to the "sort_order" field. func (m *ContactMutation) ResetSortOrder() { m.sort_order = nil m.addsort_order = nil } // Where appends a list predicates to the ContactMutation builder. func (m *ContactMutation) Where(ps ...predicate.Contact) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the ContactMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *ContactMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Contact, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *ContactMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *ContactMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Contact). func (m *ContactMutation) 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 *ContactMutation) Fields() []string { fields := make([]string, 0, 6) if m._type != nil { fields = append(fields, contact.FieldType) } if m.icon != nil { fields = append(fields, contact.FieldIcon) } if m.url != nil { fields = append(fields, contact.FieldURL) } if m.qr_code != nil { fields = append(fields, contact.FieldQrCode) } if m.hover_color != nil { fields = append(fields, contact.FieldHoverColor) } if m.sort_order != nil { fields = append(fields, contact.FieldSortOrder) } 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 *ContactMutation) Field(name string) (ent.Value, bool) { switch name { case contact.FieldType: return m.GetType() case contact.FieldIcon: return m.Icon() case contact.FieldURL: return m.URL() case contact.FieldQrCode: return m.QrCode() case contact.FieldHoverColor: return m.HoverColor() case contact.FieldSortOrder: return m.SortOrder() } 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 *ContactMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case contact.FieldType: return m.OldType(ctx) case contact.FieldIcon: return m.OldIcon(ctx) case contact.FieldURL: return m.OldURL(ctx) case contact.FieldQrCode: return m.OldQrCode(ctx) case contact.FieldHoverColor: return m.OldHoverColor(ctx) case contact.FieldSortOrder: return m.OldSortOrder(ctx) } return nil, fmt.Errorf("unknown Contact 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 *ContactMutation) SetField(name string, value ent.Value) error { switch name { case contact.FieldType: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetType(v) return nil case contact.FieldIcon: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIcon(v) return nil case contact.FieldURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetURL(v) return nil case contact.FieldQrCode: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetQrCode(v) return nil case contact.FieldHoverColor: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetHoverColor(v) return nil case contact.FieldSortOrder: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSortOrder(v) return nil } return fmt.Errorf("unknown Contact field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *ContactMutation) AddedFields() []string { var fields []string if m.addsort_order != nil { fields = append(fields, contact.FieldSortOrder) } 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 *ContactMutation) AddedField(name string) (ent.Value, bool) { switch name { case contact.FieldSortOrder: return m.AddedSortOrder() } 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 *ContactMutation) AddField(name string, value ent.Value) error { switch name { case contact.FieldSortOrder: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddSortOrder(v) return nil } return fmt.Errorf("unknown Contact numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ContactMutation) ClearedFields() []string { var fields []string if m.FieldCleared(contact.FieldURL) { fields = append(fields, contact.FieldURL) } if m.FieldCleared(contact.FieldQrCode) { fields = append(fields, contact.FieldQrCode) } if m.FieldCleared(contact.FieldHoverColor) { fields = append(fields, contact.FieldHoverColor) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *ContactMutation) 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 *ContactMutation) ClearField(name string) error { switch name { case contact.FieldURL: m.ClearURL() return nil case contact.FieldQrCode: m.ClearQrCode() return nil case contact.FieldHoverColor: m.ClearHoverColor() return nil } return fmt.Errorf("unknown Contact 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 *ContactMutation) ResetField(name string) error { switch name { case contact.FieldType: m.ResetType() return nil case contact.FieldIcon: m.ResetIcon() return nil case contact.FieldURL: m.ResetURL() return nil case contact.FieldQrCode: m.ResetQrCode() return nil case contact.FieldHoverColor: m.ResetHoverColor() return nil case contact.FieldSortOrder: m.ResetSortOrder() return nil } return fmt.Errorf("unknown Contact field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ContactMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *ContactMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *ContactMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *ContactMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ContactMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *ContactMutation) EdgeCleared(name string) bool { 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 *ContactMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Contact 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 *ContactMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Contact edge %s", name) } // LoginHistoryMutation represents an operation that mutates the LoginHistory nodes in the graph. type LoginHistoryMutation struct { config op Op typ string id *int username *string ip *string location *string user_agent *string login_time *time.Time success *bool clearedFields map[string]struct{} done bool oldValue func(context.Context) (*LoginHistory, error) predicates []predicate.LoginHistory } var _ ent.Mutation = (*LoginHistoryMutation)(nil) // loginhistoryOption allows management of the mutation configuration using functional options. type loginhistoryOption func(*LoginHistoryMutation) // newLoginHistoryMutation creates new mutation for the LoginHistory entity. func newLoginHistoryMutation(c config, op Op, opts ...loginhistoryOption) *LoginHistoryMutation { m := &LoginHistoryMutation{ config: c, op: op, typ: TypeLoginHistory, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withLoginHistoryID sets the ID field of the mutation. func withLoginHistoryID(id int) loginhistoryOption { return func(m *LoginHistoryMutation) { var ( err error once sync.Once value *LoginHistory ) m.oldValue = func(ctx context.Context) (*LoginHistory, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().LoginHistory.Get(ctx, id) } }) return value, err } m.id = &id } } // withLoginHistory sets the old LoginHistory of the mutation. func withLoginHistory(node *LoginHistory) loginhistoryOption { return func(m *LoginHistoryMutation) { m.oldValue = func(context.Context) (*LoginHistory, 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 LoginHistoryMutation) 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 LoginHistoryMutation) 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 LoginHistory entities. func (m *LoginHistoryMutation) SetID(id int) { 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 *LoginHistoryMutation) 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 *LoginHistoryMutation) 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().LoginHistory.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 *LoginHistoryMutation) SetUsername(s string) { m.username = &s } // Username returns the value of the "username" field in the mutation. func (m *LoginHistoryMutation) 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 LoginHistory entity. // If the LoginHistory 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 *LoginHistoryMutation) 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 *LoginHistoryMutation) ResetUsername() { m.username = nil } // SetIP sets the "ip" field. func (m *LoginHistoryMutation) SetIP(s string) { m.ip = &s } // IP returns the value of the "ip" field in the mutation. func (m *LoginHistoryMutation) IP() (r string, exists bool) { v := m.ip if v == nil { return } return *v, true } // OldIP returns the old "ip" field's value of the LoginHistory entity. // If the LoginHistory 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 *LoginHistoryMutation) OldIP(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIP is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIP requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIP: %w", err) } return oldValue.IP, nil } // ResetIP resets all changes to the "ip" field. func (m *LoginHistoryMutation) ResetIP() { m.ip = nil } // SetLocation sets the "location" field. func (m *LoginHistoryMutation) SetLocation(s string) { m.location = &s } // Location returns the value of the "location" field in the mutation. func (m *LoginHistoryMutation) Location() (r string, exists bool) { v := m.location if v == nil { return } return *v, true } // OldLocation returns the old "location" field's value of the LoginHistory entity. // If the LoginHistory 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 *LoginHistoryMutation) OldLocation(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLocation is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLocation requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLocation: %w", err) } return oldValue.Location, nil } // ClearLocation clears the value of the "location" field. func (m *LoginHistoryMutation) ClearLocation() { m.location = nil m.clearedFields[loginhistory.FieldLocation] = struct{}{} } // LocationCleared returns if the "location" field was cleared in this mutation. func (m *LoginHistoryMutation) LocationCleared() bool { _, ok := m.clearedFields[loginhistory.FieldLocation] return ok } // ResetLocation resets all changes to the "location" field. func (m *LoginHistoryMutation) ResetLocation() { m.location = nil delete(m.clearedFields, loginhistory.FieldLocation) } // SetUserAgent sets the "user_agent" field. func (m *LoginHistoryMutation) SetUserAgent(s string) { m.user_agent = &s } // UserAgent returns the value of the "user_agent" field in the mutation. func (m *LoginHistoryMutation) UserAgent() (r string, exists bool) { v := m.user_agent if v == nil { return } return *v, true } // OldUserAgent returns the old "user_agent" field's value of the LoginHistory entity. // If the LoginHistory 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 *LoginHistoryMutation) OldUserAgent(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserAgent is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserAgent requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserAgent: %w", err) } return oldValue.UserAgent, nil } // ClearUserAgent clears the value of the "user_agent" field. func (m *LoginHistoryMutation) ClearUserAgent() { m.user_agent = nil m.clearedFields[loginhistory.FieldUserAgent] = struct{}{} } // UserAgentCleared returns if the "user_agent" field was cleared in this mutation. func (m *LoginHistoryMutation) UserAgentCleared() bool { _, ok := m.clearedFields[loginhistory.FieldUserAgent] return ok } // ResetUserAgent resets all changes to the "user_agent" field. func (m *LoginHistoryMutation) ResetUserAgent() { m.user_agent = nil delete(m.clearedFields, loginhistory.FieldUserAgent) } // SetLoginTime sets the "login_time" field. func (m *LoginHistoryMutation) SetLoginTime(t time.Time) { m.login_time = &t } // LoginTime returns the value of the "login_time" field in the mutation. func (m *LoginHistoryMutation) LoginTime() (r time.Time, exists bool) { v := m.login_time if v == nil { return } return *v, true } // OldLoginTime returns the old "login_time" field's value of the LoginHistory entity. // If the LoginHistory 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 *LoginHistoryMutation) OldLoginTime(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLoginTime is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldLoginTime requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldLoginTime: %w", err) } return oldValue.LoginTime, nil } // ResetLoginTime resets all changes to the "login_time" field. func (m *LoginHistoryMutation) ResetLoginTime() { m.login_time = nil } // SetSuccess sets the "success" field. func (m *LoginHistoryMutation) SetSuccess(b bool) { m.success = &b } // Success returns the value of the "success" field in the mutation. func (m *LoginHistoryMutation) Success() (r bool, exists bool) { v := m.success if v == nil { return } return *v, true } // OldSuccess returns the old "success" field's value of the LoginHistory entity. // If the LoginHistory 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 *LoginHistoryMutation) OldSuccess(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSuccess is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSuccess requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSuccess: %w", err) } return oldValue.Success, nil } // ResetSuccess resets all changes to the "success" field. func (m *LoginHistoryMutation) ResetSuccess() { m.success = nil } // Where appends a list predicates to the LoginHistoryMutation builder. func (m *LoginHistoryMutation) Where(ps ...predicate.LoginHistory) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the LoginHistoryMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *LoginHistoryMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.LoginHistory, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *LoginHistoryMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *LoginHistoryMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (LoginHistory). func (m *LoginHistoryMutation) 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 *LoginHistoryMutation) Fields() []string { fields := make([]string, 0, 6) if m.username != nil { fields = append(fields, loginhistory.FieldUsername) } if m.ip != nil { fields = append(fields, loginhistory.FieldIP) } if m.location != nil { fields = append(fields, loginhistory.FieldLocation) } if m.user_agent != nil { fields = append(fields, loginhistory.FieldUserAgent) } if m.login_time != nil { fields = append(fields, loginhistory.FieldLoginTime) } if m.success != nil { fields = append(fields, loginhistory.FieldSuccess) } 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 *LoginHistoryMutation) Field(name string) (ent.Value, bool) { switch name { case loginhistory.FieldUsername: return m.Username() case loginhistory.FieldIP: return m.IP() case loginhistory.FieldLocation: return m.Location() case loginhistory.FieldUserAgent: return m.UserAgent() case loginhistory.FieldLoginTime: return m.LoginTime() case loginhistory.FieldSuccess: return m.Success() } 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 *LoginHistoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case loginhistory.FieldUsername: return m.OldUsername(ctx) case loginhistory.FieldIP: return m.OldIP(ctx) case loginhistory.FieldLocation: return m.OldLocation(ctx) case loginhistory.FieldUserAgent: return m.OldUserAgent(ctx) case loginhistory.FieldLoginTime: return m.OldLoginTime(ctx) case loginhistory.FieldSuccess: return m.OldSuccess(ctx) } return nil, fmt.Errorf("unknown LoginHistory 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 *LoginHistoryMutation) SetField(name string, value ent.Value) error { switch name { case loginhistory.FieldUsername: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUsername(v) return nil case loginhistory.FieldIP: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIP(v) return nil case loginhistory.FieldLocation: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLocation(v) return nil case loginhistory.FieldUserAgent: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserAgent(v) return nil case loginhistory.FieldLoginTime: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetLoginTime(v) return nil case loginhistory.FieldSuccess: v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSuccess(v) return nil } return fmt.Errorf("unknown LoginHistory field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *LoginHistoryMutation) 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 *LoginHistoryMutation) 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 *LoginHistoryMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown LoginHistory numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *LoginHistoryMutation) ClearedFields() []string { var fields []string if m.FieldCleared(loginhistory.FieldLocation) { fields = append(fields, loginhistory.FieldLocation) } if m.FieldCleared(loginhistory.FieldUserAgent) { fields = append(fields, loginhistory.FieldUserAgent) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *LoginHistoryMutation) 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 *LoginHistoryMutation) ClearField(name string) error { switch name { case loginhistory.FieldLocation: m.ClearLocation() return nil case loginhistory.FieldUserAgent: m.ClearUserAgent() return nil } return fmt.Errorf("unknown LoginHistory 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 *LoginHistoryMutation) ResetField(name string) error { switch name { case loginhistory.FieldUsername: m.ResetUsername() return nil case loginhistory.FieldIP: m.ResetIP() return nil case loginhistory.FieldLocation: m.ResetLocation() return nil case loginhistory.FieldUserAgent: m.ResetUserAgent() return nil case loginhistory.FieldLoginTime: m.ResetLoginTime() return nil case loginhistory.FieldSuccess: m.ResetSuccess() return nil } return fmt.Errorf("unknown LoginHistory field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *LoginHistoryMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *LoginHistoryMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *LoginHistoryMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *LoginHistoryMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *LoginHistoryMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *LoginHistoryMutation) EdgeCleared(name string) bool { 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 *LoginHistoryMutation) ClearEdge(name string) error { return fmt.Errorf("unknown LoginHistory 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 *LoginHistoryMutation) ResetEdge(name string) error { return fmt.Errorf("unknown LoginHistory edge %s", name) } // SiteMutation represents an operation that mutates the Site nodes in the graph. type SiteMutation struct { config op Op typ string id *int name *string url *string icon *string sort_order *int addsort_order *int clearedFields map[string]struct{} done bool oldValue func(context.Context) (*Site, error) predicates []predicate.Site } var _ ent.Mutation = (*SiteMutation)(nil) // siteOption allows management of the mutation configuration using functional options. type siteOption func(*SiteMutation) // newSiteMutation creates new mutation for the Site entity. func newSiteMutation(c config, op Op, opts ...siteOption) *SiteMutation { m := &SiteMutation{ config: c, op: op, typ: TypeSite, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withSiteID sets the ID field of the mutation. func withSiteID(id int) siteOption { return func(m *SiteMutation) { var ( err error once sync.Once value *Site ) m.oldValue = func(ctx context.Context) (*Site, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Site.Get(ctx, id) } }) return value, err } m.id = &id } } // withSite sets the old Site of the mutation. func withSite(node *Site) siteOption { return func(m *SiteMutation) { m.oldValue = func(context.Context) (*Site, 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 SiteMutation) 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 SiteMutation) 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 Site entities. func (m *SiteMutation) SetID(id int) { 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 *SiteMutation) 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 *SiteMutation) 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().Site.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 *SiteMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *SiteMutation) 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 Site entity. // If the Site 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 *SiteMutation) 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 *SiteMutation) ResetName() { m.name = nil } // SetURL sets the "url" field. func (m *SiteMutation) SetURL(s string) { m.url = &s } // URL returns the value of the "url" field in the mutation. func (m *SiteMutation) 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 Site entity. // If the Site 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 *SiteMutation) 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 *SiteMutation) ResetURL() { m.url = nil } // SetIcon sets the "icon" field. func (m *SiteMutation) SetIcon(s string) { m.icon = &s } // Icon returns the value of the "icon" field in the mutation. func (m *SiteMutation) Icon() (r string, exists bool) { v := m.icon if v == nil { return } return *v, true } // OldIcon returns the old "icon" field's value of the Site entity. // If the Site 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 *SiteMutation) OldIcon(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIcon is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIcon requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIcon: %w", err) } return oldValue.Icon, nil } // ResetIcon resets all changes to the "icon" field. func (m *SiteMutation) ResetIcon() { m.icon = nil } // SetSortOrder sets the "sort_order" field. func (m *SiteMutation) SetSortOrder(i int) { m.sort_order = &i m.addsort_order = nil } // SortOrder returns the value of the "sort_order" field in the mutation. func (m *SiteMutation) SortOrder() (r int, exists bool) { v := m.sort_order if v == nil { return } return *v, true } // OldSortOrder returns the old "sort_order" field's value of the Site entity. // If the Site 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 *SiteMutation) OldSortOrder(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSortOrder is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSortOrder requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSortOrder: %w", err) } return oldValue.SortOrder, nil } // AddSortOrder adds i to the "sort_order" field. func (m *SiteMutation) AddSortOrder(i int) { if m.addsort_order != nil { *m.addsort_order += i } else { m.addsort_order = &i } } // AddedSortOrder returns the value that was added to the "sort_order" field in this mutation. func (m *SiteMutation) AddedSortOrder() (r int, exists bool) { v := m.addsort_order if v == nil { return } return *v, true } // ResetSortOrder resets all changes to the "sort_order" field. func (m *SiteMutation) ResetSortOrder() { m.sort_order = nil m.addsort_order = nil } // Where appends a list predicates to the SiteMutation builder. func (m *SiteMutation) Where(ps ...predicate.Site) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the SiteMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *SiteMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Site, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *SiteMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *SiteMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Site). func (m *SiteMutation) 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 *SiteMutation) Fields() []string { fields := make([]string, 0, 4) if m.name != nil { fields = append(fields, site.FieldName) } if m.url != nil { fields = append(fields, site.FieldURL) } if m.icon != nil { fields = append(fields, site.FieldIcon) } if m.sort_order != nil { fields = append(fields, site.FieldSortOrder) } 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 *SiteMutation) Field(name string) (ent.Value, bool) { switch name { case site.FieldName: return m.Name() case site.FieldURL: return m.URL() case site.FieldIcon: return m.Icon() case site.FieldSortOrder: return m.SortOrder() } 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 *SiteMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case site.FieldName: return m.OldName(ctx) case site.FieldURL: return m.OldURL(ctx) case site.FieldIcon: return m.OldIcon(ctx) case site.FieldSortOrder: return m.OldSortOrder(ctx) } return nil, fmt.Errorf("unknown Site 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 *SiteMutation) SetField(name string, value ent.Value) error { switch name { case site.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil case site.FieldURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetURL(v) return nil case site.FieldIcon: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIcon(v) return nil case site.FieldSortOrder: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSortOrder(v) return nil } return fmt.Errorf("unknown Site field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *SiteMutation) AddedFields() []string { var fields []string if m.addsort_order != nil { fields = append(fields, site.FieldSortOrder) } 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 *SiteMutation) AddedField(name string) (ent.Value, bool) { switch name { case site.FieldSortOrder: return m.AddedSortOrder() } 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 *SiteMutation) AddField(name string, value ent.Value) error { switch name { case site.FieldSortOrder: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddSortOrder(v) return nil } return fmt.Errorf("unknown Site numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *SiteMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *SiteMutation) 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 *SiteMutation) ClearField(name string) error { return fmt.Errorf("unknown Site 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 *SiteMutation) ResetField(name string) error { switch name { case site.FieldName: m.ResetName() return nil case site.FieldURL: m.ResetURL() return nil case site.FieldIcon: m.ResetIcon() return nil case site.FieldSortOrder: m.ResetSortOrder() return nil } return fmt.Errorf("unknown Site field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *SiteMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *SiteMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *SiteMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *SiteMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SiteMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *SiteMutation) EdgeCleared(name string) bool { 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 *SiteMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Site 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 *SiteMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Site edge %s", name) } // SiteConfigMutation represents an operation that mutates the SiteConfig nodes in the graph. type SiteConfigMutation struct { config op Op typ string id *int site_name *string site_url *string site_icon *string site_description *string site_keywords *string user_name *string profile_image_url *string icp_number *string police_number *string page_title *string favicon *string umami_script *string umami_website_id *string icon_library *string font_library *string clearedFields map[string]struct{} done bool oldValue func(context.Context) (*SiteConfig, error) predicates []predicate.SiteConfig } var _ ent.Mutation = (*SiteConfigMutation)(nil) // siteconfigOption allows management of the mutation configuration using functional options. type siteconfigOption func(*SiteConfigMutation) // newSiteConfigMutation creates new mutation for the SiteConfig entity. func newSiteConfigMutation(c config, op Op, opts ...siteconfigOption) *SiteConfigMutation { m := &SiteConfigMutation{ config: c, op: op, typ: TypeSiteConfig, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withSiteConfigID sets the ID field of the mutation. func withSiteConfigID(id int) siteconfigOption { return func(m *SiteConfigMutation) { var ( err error once sync.Once value *SiteConfig ) m.oldValue = func(ctx context.Context) (*SiteConfig, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().SiteConfig.Get(ctx, id) } }) return value, err } m.id = &id } } // withSiteConfig sets the old SiteConfig of the mutation. func withSiteConfig(node *SiteConfig) siteconfigOption { return func(m *SiteConfigMutation) { m.oldValue = func(context.Context) (*SiteConfig, 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 SiteConfigMutation) 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 SiteConfigMutation) 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 SiteConfig entities. func (m *SiteConfigMutation) SetID(id int) { 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 *SiteConfigMutation) 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 *SiteConfigMutation) 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().SiteConfig.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetSiteName sets the "site_name" field. func (m *SiteConfigMutation) SetSiteName(s string) { m.site_name = &s } // SiteName returns the value of the "site_name" field in the mutation. func (m *SiteConfigMutation) SiteName() (r string, exists bool) { v := m.site_name if v == nil { return } return *v, true } // OldSiteName returns the old "site_name" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldSiteName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSiteName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSiteName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSiteName: %w", err) } return oldValue.SiteName, nil } // ResetSiteName resets all changes to the "site_name" field. func (m *SiteConfigMutation) ResetSiteName() { m.site_name = nil } // SetSiteURL sets the "site_url" field. func (m *SiteConfigMutation) SetSiteURL(s string) { m.site_url = &s } // SiteURL returns the value of the "site_url" field in the mutation. func (m *SiteConfigMutation) SiteURL() (r string, exists bool) { v := m.site_url if v == nil { return } return *v, true } // OldSiteURL returns the old "site_url" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldSiteURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSiteURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSiteURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSiteURL: %w", err) } return oldValue.SiteURL, nil } // ResetSiteURL resets all changes to the "site_url" field. func (m *SiteConfigMutation) ResetSiteURL() { m.site_url = nil } // SetSiteIcon sets the "site_icon" field. func (m *SiteConfigMutation) SetSiteIcon(s string) { m.site_icon = &s } // SiteIcon returns the value of the "site_icon" field in the mutation. func (m *SiteConfigMutation) SiteIcon() (r string, exists bool) { v := m.site_icon if v == nil { return } return *v, true } // OldSiteIcon returns the old "site_icon" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldSiteIcon(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSiteIcon is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSiteIcon requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSiteIcon: %w", err) } return oldValue.SiteIcon, nil } // ResetSiteIcon resets all changes to the "site_icon" field. func (m *SiteConfigMutation) ResetSiteIcon() { m.site_icon = nil } // SetSiteDescription sets the "site_description" field. func (m *SiteConfigMutation) SetSiteDescription(s string) { m.site_description = &s } // SiteDescription returns the value of the "site_description" field in the mutation. func (m *SiteConfigMutation) SiteDescription() (r string, exists bool) { v := m.site_description if v == nil { return } return *v, true } // OldSiteDescription returns the old "site_description" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldSiteDescription(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSiteDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSiteDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSiteDescription: %w", err) } return oldValue.SiteDescription, nil } // ResetSiteDescription resets all changes to the "site_description" field. func (m *SiteConfigMutation) ResetSiteDescription() { m.site_description = nil } // SetSiteKeywords sets the "site_keywords" field. func (m *SiteConfigMutation) SetSiteKeywords(s string) { m.site_keywords = &s } // SiteKeywords returns the value of the "site_keywords" field in the mutation. func (m *SiteConfigMutation) SiteKeywords() (r string, exists bool) { v := m.site_keywords if v == nil { return } return *v, true } // OldSiteKeywords returns the old "site_keywords" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldSiteKeywords(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSiteKeywords is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSiteKeywords requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSiteKeywords: %w", err) } return oldValue.SiteKeywords, nil } // ResetSiteKeywords resets all changes to the "site_keywords" field. func (m *SiteConfigMutation) ResetSiteKeywords() { m.site_keywords = nil } // SetUserName sets the "user_name" field. func (m *SiteConfigMutation) SetUserName(s string) { m.user_name = &s } // UserName returns the value of the "user_name" field in the mutation. func (m *SiteConfigMutation) UserName() (r string, exists bool) { v := m.user_name if v == nil { return } return *v, true } // OldUserName returns the old "user_name" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) 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 "user_name" field. func (m *SiteConfigMutation) ResetUserName() { m.user_name = nil } // SetProfileImageURL sets the "profile_image_url" field. func (m *SiteConfigMutation) SetProfileImageURL(s string) { m.profile_image_url = &s } // ProfileImageURL returns the value of the "profile_image_url" field in the mutation. func (m *SiteConfigMutation) ProfileImageURL() (r string, exists bool) { v := m.profile_image_url if v == nil { return } return *v, true } // OldProfileImageURL returns the old "profile_image_url" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldProfileImageURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldProfileImageURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldProfileImageURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldProfileImageURL: %w", err) } return oldValue.ProfileImageURL, nil } // ClearProfileImageURL clears the value of the "profile_image_url" field. func (m *SiteConfigMutation) ClearProfileImageURL() { m.profile_image_url = nil m.clearedFields[siteconfig.FieldProfileImageURL] = struct{}{} } // ProfileImageURLCleared returns if the "profile_image_url" field was cleared in this mutation. func (m *SiteConfigMutation) ProfileImageURLCleared() bool { _, ok := m.clearedFields[siteconfig.FieldProfileImageURL] return ok } // ResetProfileImageURL resets all changes to the "profile_image_url" field. func (m *SiteConfigMutation) ResetProfileImageURL() { m.profile_image_url = nil delete(m.clearedFields, siteconfig.FieldProfileImageURL) } // SetIcpNumber sets the "icp_number" field. func (m *SiteConfigMutation) SetIcpNumber(s string) { m.icp_number = &s } // IcpNumber returns the value of the "icp_number" field in the mutation. func (m *SiteConfigMutation) IcpNumber() (r string, exists bool) { v := m.icp_number if v == nil { return } return *v, true } // OldIcpNumber returns the old "icp_number" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldIcpNumber(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIcpNumber is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIcpNumber requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIcpNumber: %w", err) } return oldValue.IcpNumber, nil } // ClearIcpNumber clears the value of the "icp_number" field. func (m *SiteConfigMutation) ClearIcpNumber() { m.icp_number = nil m.clearedFields[siteconfig.FieldIcpNumber] = struct{}{} } // IcpNumberCleared returns if the "icp_number" field was cleared in this mutation. func (m *SiteConfigMutation) IcpNumberCleared() bool { _, ok := m.clearedFields[siteconfig.FieldIcpNumber] return ok } // ResetIcpNumber resets all changes to the "icp_number" field. func (m *SiteConfigMutation) ResetIcpNumber() { m.icp_number = nil delete(m.clearedFields, siteconfig.FieldIcpNumber) } // SetPoliceNumber sets the "police_number" field. func (m *SiteConfigMutation) SetPoliceNumber(s string) { m.police_number = &s } // PoliceNumber returns the value of the "police_number" field in the mutation. func (m *SiteConfigMutation) PoliceNumber() (r string, exists bool) { v := m.police_number if v == nil { return } return *v, true } // OldPoliceNumber returns the old "police_number" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldPoliceNumber(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPoliceNumber is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPoliceNumber requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPoliceNumber: %w", err) } return oldValue.PoliceNumber, nil } // ClearPoliceNumber clears the value of the "police_number" field. func (m *SiteConfigMutation) ClearPoliceNumber() { m.police_number = nil m.clearedFields[siteconfig.FieldPoliceNumber] = struct{}{} } // PoliceNumberCleared returns if the "police_number" field was cleared in this mutation. func (m *SiteConfigMutation) PoliceNumberCleared() bool { _, ok := m.clearedFields[siteconfig.FieldPoliceNumber] return ok } // ResetPoliceNumber resets all changes to the "police_number" field. func (m *SiteConfigMutation) ResetPoliceNumber() { m.police_number = nil delete(m.clearedFields, siteconfig.FieldPoliceNumber) } // SetPageTitle sets the "page_title" field. func (m *SiteConfigMutation) SetPageTitle(s string) { m.page_title = &s } // PageTitle returns the value of the "page_title" field in the mutation. func (m *SiteConfigMutation) PageTitle() (r string, exists bool) { v := m.page_title if v == nil { return } return *v, true } // OldPageTitle returns the old "page_title" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldPageTitle(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPageTitle is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPageTitle requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPageTitle: %w", err) } return oldValue.PageTitle, nil } // ClearPageTitle clears the value of the "page_title" field. func (m *SiteConfigMutation) ClearPageTitle() { m.page_title = nil m.clearedFields[siteconfig.FieldPageTitle] = struct{}{} } // PageTitleCleared returns if the "page_title" field was cleared in this mutation. func (m *SiteConfigMutation) PageTitleCleared() bool { _, ok := m.clearedFields[siteconfig.FieldPageTitle] return ok } // ResetPageTitle resets all changes to the "page_title" field. func (m *SiteConfigMutation) ResetPageTitle() { m.page_title = nil delete(m.clearedFields, siteconfig.FieldPageTitle) } // SetFavicon sets the "favicon" field. func (m *SiteConfigMutation) SetFavicon(s string) { m.favicon = &s } // Favicon returns the value of the "favicon" field in the mutation. func (m *SiteConfigMutation) Favicon() (r string, exists bool) { v := m.favicon if v == nil { return } return *v, true } // OldFavicon returns the old "favicon" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldFavicon(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldFavicon is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldFavicon requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldFavicon: %w", err) } return oldValue.Favicon, nil } // ClearFavicon clears the value of the "favicon" field. func (m *SiteConfigMutation) ClearFavicon() { m.favicon = nil m.clearedFields[siteconfig.FieldFavicon] = struct{}{} } // FaviconCleared returns if the "favicon" field was cleared in this mutation. func (m *SiteConfigMutation) FaviconCleared() bool { _, ok := m.clearedFields[siteconfig.FieldFavicon] return ok } // ResetFavicon resets all changes to the "favicon" field. func (m *SiteConfigMutation) ResetFavicon() { m.favicon = nil delete(m.clearedFields, siteconfig.FieldFavicon) } // SetUmamiScript sets the "umami_script" field. func (m *SiteConfigMutation) SetUmamiScript(s string) { m.umami_script = &s } // UmamiScript returns the value of the "umami_script" field in the mutation. func (m *SiteConfigMutation) UmamiScript() (r string, exists bool) { v := m.umami_script if v == nil { return } return *v, true } // OldUmamiScript returns the old "umami_script" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldUmamiScript(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUmamiScript is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUmamiScript requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUmamiScript: %w", err) } return oldValue.UmamiScript, nil } // ClearUmamiScript clears the value of the "umami_script" field. func (m *SiteConfigMutation) ClearUmamiScript() { m.umami_script = nil m.clearedFields[siteconfig.FieldUmamiScript] = struct{}{} } // UmamiScriptCleared returns if the "umami_script" field was cleared in this mutation. func (m *SiteConfigMutation) UmamiScriptCleared() bool { _, ok := m.clearedFields[siteconfig.FieldUmamiScript] return ok } // ResetUmamiScript resets all changes to the "umami_script" field. func (m *SiteConfigMutation) ResetUmamiScript() { m.umami_script = nil delete(m.clearedFields, siteconfig.FieldUmamiScript) } // SetUmamiWebsiteID sets the "umami_website_id" field. func (m *SiteConfigMutation) SetUmamiWebsiteID(s string) { m.umami_website_id = &s } // UmamiWebsiteID returns the value of the "umami_website_id" field in the mutation. func (m *SiteConfigMutation) UmamiWebsiteID() (r string, exists bool) { v := m.umami_website_id if v == nil { return } return *v, true } // OldUmamiWebsiteID returns the old "umami_website_id" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldUmamiWebsiteID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUmamiWebsiteID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUmamiWebsiteID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUmamiWebsiteID: %w", err) } return oldValue.UmamiWebsiteID, nil } // ClearUmamiWebsiteID clears the value of the "umami_website_id" field. func (m *SiteConfigMutation) ClearUmamiWebsiteID() { m.umami_website_id = nil m.clearedFields[siteconfig.FieldUmamiWebsiteID] = struct{}{} } // UmamiWebsiteIDCleared returns if the "umami_website_id" field was cleared in this mutation. func (m *SiteConfigMutation) UmamiWebsiteIDCleared() bool { _, ok := m.clearedFields[siteconfig.FieldUmamiWebsiteID] return ok } // ResetUmamiWebsiteID resets all changes to the "umami_website_id" field. func (m *SiteConfigMutation) ResetUmamiWebsiteID() { m.umami_website_id = nil delete(m.clearedFields, siteconfig.FieldUmamiWebsiteID) } // SetIconLibrary sets the "icon_library" field. func (m *SiteConfigMutation) SetIconLibrary(s string) { m.icon_library = &s } // IconLibrary returns the value of the "icon_library" field in the mutation. func (m *SiteConfigMutation) IconLibrary() (r string, exists bool) { v := m.icon_library if v == nil { return } return *v, true } // OldIconLibrary returns the old "icon_library" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldIconLibrary(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIconLibrary is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIconLibrary requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIconLibrary: %w", err) } return oldValue.IconLibrary, nil } // ClearIconLibrary clears the value of the "icon_library" field. func (m *SiteConfigMutation) ClearIconLibrary() { m.icon_library = nil m.clearedFields[siteconfig.FieldIconLibrary] = struct{}{} } // IconLibraryCleared returns if the "icon_library" field was cleared in this mutation. func (m *SiteConfigMutation) IconLibraryCleared() bool { _, ok := m.clearedFields[siteconfig.FieldIconLibrary] return ok } // ResetIconLibrary resets all changes to the "icon_library" field. func (m *SiteConfigMutation) ResetIconLibrary() { m.icon_library = nil delete(m.clearedFields, siteconfig.FieldIconLibrary) } // SetFontLibrary sets the "font_library" field. func (m *SiteConfigMutation) SetFontLibrary(s string) { m.font_library = &s } // FontLibrary returns the value of the "font_library" field in the mutation. func (m *SiteConfigMutation) FontLibrary() (r string, exists bool) { v := m.font_library if v == nil { return } return *v, true } // OldFontLibrary returns the old "font_library" field's value of the SiteConfig entity. // If the SiteConfig 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 *SiteConfigMutation) OldFontLibrary(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldFontLibrary is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldFontLibrary requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldFontLibrary: %w", err) } return oldValue.FontLibrary, nil } // ClearFontLibrary clears the value of the "font_library" field. func (m *SiteConfigMutation) ClearFontLibrary() { m.font_library = nil m.clearedFields[siteconfig.FieldFontLibrary] = struct{}{} } // FontLibraryCleared returns if the "font_library" field was cleared in this mutation. func (m *SiteConfigMutation) FontLibraryCleared() bool { _, ok := m.clearedFields[siteconfig.FieldFontLibrary] return ok } // ResetFontLibrary resets all changes to the "font_library" field. func (m *SiteConfigMutation) ResetFontLibrary() { m.font_library = nil delete(m.clearedFields, siteconfig.FieldFontLibrary) } // Where appends a list predicates to the SiteConfigMutation builder. func (m *SiteConfigMutation) Where(ps ...predicate.SiteConfig) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the SiteConfigMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *SiteConfigMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.SiteConfig, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *SiteConfigMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *SiteConfigMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (SiteConfig). func (m *SiteConfigMutation) 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 *SiteConfigMutation) Fields() []string { fields := make([]string, 0, 15) if m.site_name != nil { fields = append(fields, siteconfig.FieldSiteName) } if m.site_url != nil { fields = append(fields, siteconfig.FieldSiteURL) } if m.site_icon != nil { fields = append(fields, siteconfig.FieldSiteIcon) } if m.site_description != nil { fields = append(fields, siteconfig.FieldSiteDescription) } if m.site_keywords != nil { fields = append(fields, siteconfig.FieldSiteKeywords) } if m.user_name != nil { fields = append(fields, siteconfig.FieldUserName) } if m.profile_image_url != nil { fields = append(fields, siteconfig.FieldProfileImageURL) } if m.icp_number != nil { fields = append(fields, siteconfig.FieldIcpNumber) } if m.police_number != nil { fields = append(fields, siteconfig.FieldPoliceNumber) } if m.page_title != nil { fields = append(fields, siteconfig.FieldPageTitle) } if m.favicon != nil { fields = append(fields, siteconfig.FieldFavicon) } if m.umami_script != nil { fields = append(fields, siteconfig.FieldUmamiScript) } if m.umami_website_id != nil { fields = append(fields, siteconfig.FieldUmamiWebsiteID) } if m.icon_library != nil { fields = append(fields, siteconfig.FieldIconLibrary) } if m.font_library != nil { fields = append(fields, siteconfig.FieldFontLibrary) } 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 *SiteConfigMutation) Field(name string) (ent.Value, bool) { switch name { case siteconfig.FieldSiteName: return m.SiteName() case siteconfig.FieldSiteURL: return m.SiteURL() case siteconfig.FieldSiteIcon: return m.SiteIcon() case siteconfig.FieldSiteDescription: return m.SiteDescription() case siteconfig.FieldSiteKeywords: return m.SiteKeywords() case siteconfig.FieldUserName: return m.UserName() case siteconfig.FieldProfileImageURL: return m.ProfileImageURL() case siteconfig.FieldIcpNumber: return m.IcpNumber() case siteconfig.FieldPoliceNumber: return m.PoliceNumber() case siteconfig.FieldPageTitle: return m.PageTitle() case siteconfig.FieldFavicon: return m.Favicon() case siteconfig.FieldUmamiScript: return m.UmamiScript() case siteconfig.FieldUmamiWebsiteID: return m.UmamiWebsiteID() case siteconfig.FieldIconLibrary: return m.IconLibrary() case siteconfig.FieldFontLibrary: return m.FontLibrary() } 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 *SiteConfigMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case siteconfig.FieldSiteName: return m.OldSiteName(ctx) case siteconfig.FieldSiteURL: return m.OldSiteURL(ctx) case siteconfig.FieldSiteIcon: return m.OldSiteIcon(ctx) case siteconfig.FieldSiteDescription: return m.OldSiteDescription(ctx) case siteconfig.FieldSiteKeywords: return m.OldSiteKeywords(ctx) case siteconfig.FieldUserName: return m.OldUserName(ctx) case siteconfig.FieldProfileImageURL: return m.OldProfileImageURL(ctx) case siteconfig.FieldIcpNumber: return m.OldIcpNumber(ctx) case siteconfig.FieldPoliceNumber: return m.OldPoliceNumber(ctx) case siteconfig.FieldPageTitle: return m.OldPageTitle(ctx) case siteconfig.FieldFavicon: return m.OldFavicon(ctx) case siteconfig.FieldUmamiScript: return m.OldUmamiScript(ctx) case siteconfig.FieldUmamiWebsiteID: return m.OldUmamiWebsiteID(ctx) case siteconfig.FieldIconLibrary: return m.OldIconLibrary(ctx) case siteconfig.FieldFontLibrary: return m.OldFontLibrary(ctx) } return nil, fmt.Errorf("unknown SiteConfig 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 *SiteConfigMutation) SetField(name string, value ent.Value) error { switch name { case siteconfig.FieldSiteName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSiteName(v) return nil case siteconfig.FieldSiteURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSiteURL(v) return nil case siteconfig.FieldSiteIcon: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSiteIcon(v) return nil case siteconfig.FieldSiteDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSiteDescription(v) return nil case siteconfig.FieldSiteKeywords: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSiteKeywords(v) return nil case siteconfig.FieldUserName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserName(v) return nil case siteconfig.FieldProfileImageURL: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetProfileImageURL(v) return nil case siteconfig.FieldIcpNumber: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIcpNumber(v) return nil case siteconfig.FieldPoliceNumber: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPoliceNumber(v) return nil case siteconfig.FieldPageTitle: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPageTitle(v) return nil case siteconfig.FieldFavicon: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetFavicon(v) return nil case siteconfig.FieldUmamiScript: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUmamiScript(v) return nil case siteconfig.FieldUmamiWebsiteID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUmamiWebsiteID(v) return nil case siteconfig.FieldIconLibrary: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIconLibrary(v) return nil case siteconfig.FieldFontLibrary: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetFontLibrary(v) return nil } return fmt.Errorf("unknown SiteConfig field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *SiteConfigMutation) 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 *SiteConfigMutation) 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 *SiteConfigMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown SiteConfig numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *SiteConfigMutation) ClearedFields() []string { var fields []string if m.FieldCleared(siteconfig.FieldProfileImageURL) { fields = append(fields, siteconfig.FieldProfileImageURL) } if m.FieldCleared(siteconfig.FieldIcpNumber) { fields = append(fields, siteconfig.FieldIcpNumber) } if m.FieldCleared(siteconfig.FieldPoliceNumber) { fields = append(fields, siteconfig.FieldPoliceNumber) } if m.FieldCleared(siteconfig.FieldPageTitle) { fields = append(fields, siteconfig.FieldPageTitle) } if m.FieldCleared(siteconfig.FieldFavicon) { fields = append(fields, siteconfig.FieldFavicon) } if m.FieldCleared(siteconfig.FieldUmamiScript) { fields = append(fields, siteconfig.FieldUmamiScript) } if m.FieldCleared(siteconfig.FieldUmamiWebsiteID) { fields = append(fields, siteconfig.FieldUmamiWebsiteID) } if m.FieldCleared(siteconfig.FieldIconLibrary) { fields = append(fields, siteconfig.FieldIconLibrary) } if m.FieldCleared(siteconfig.FieldFontLibrary) { fields = append(fields, siteconfig.FieldFontLibrary) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *SiteConfigMutation) 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 *SiteConfigMutation) ClearField(name string) error { switch name { case siteconfig.FieldProfileImageURL: m.ClearProfileImageURL() return nil case siteconfig.FieldIcpNumber: m.ClearIcpNumber() return nil case siteconfig.FieldPoliceNumber: m.ClearPoliceNumber() return nil case siteconfig.FieldPageTitle: m.ClearPageTitle() return nil case siteconfig.FieldFavicon: m.ClearFavicon() return nil case siteconfig.FieldUmamiScript: m.ClearUmamiScript() return nil case siteconfig.FieldUmamiWebsiteID: m.ClearUmamiWebsiteID() return nil case siteconfig.FieldIconLibrary: m.ClearIconLibrary() return nil case siteconfig.FieldFontLibrary: m.ClearFontLibrary() return nil } return fmt.Errorf("unknown SiteConfig 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 *SiteConfigMutation) ResetField(name string) error { switch name { case siteconfig.FieldSiteName: m.ResetSiteName() return nil case siteconfig.FieldSiteURL: m.ResetSiteURL() return nil case siteconfig.FieldSiteIcon: m.ResetSiteIcon() return nil case siteconfig.FieldSiteDescription: m.ResetSiteDescription() return nil case siteconfig.FieldSiteKeywords: m.ResetSiteKeywords() return nil case siteconfig.FieldUserName: m.ResetUserName() return nil case siteconfig.FieldProfileImageURL: m.ResetProfileImageURL() return nil case siteconfig.FieldIcpNumber: m.ResetIcpNumber() return nil case siteconfig.FieldPoliceNumber: m.ResetPoliceNumber() return nil case siteconfig.FieldPageTitle: m.ResetPageTitle() return nil case siteconfig.FieldFavicon: m.ResetFavicon() return nil case siteconfig.FieldUmamiScript: m.ResetUmamiScript() return nil case siteconfig.FieldUmamiWebsiteID: m.ResetUmamiWebsiteID() return nil case siteconfig.FieldIconLibrary: m.ResetIconLibrary() return nil case siteconfig.FieldFontLibrary: m.ResetFontLibrary() return nil } return fmt.Errorf("unknown SiteConfig field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *SiteConfigMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *SiteConfigMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *SiteConfigMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *SiteConfigMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SiteConfigMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *SiteConfigMutation) EdgeCleared(name string) bool { 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 *SiteConfigMutation) ClearEdge(name string) error { return fmt.Errorf("unknown SiteConfig 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 *SiteConfigMutation) ResetEdge(name string) error { return fmt.Errorf("unknown SiteConfig 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 password *string clearedFields map[string]struct{} 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 } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of User entities. func (m *UserMutation) SetID(id int) { 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 *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 } // SetPassword sets the "password" field. func (m *UserMutation) SetPassword(s string) { m.password = &s } // Password returns the value of the "password" field in the mutation. func (m *UserMutation) Password() (r string, exists bool) { v := m.password if v == nil { return } return *v, true } // OldPassword returns the old "password" 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) OldPassword(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPassword is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPassword requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPassword: %w", err) } return oldValue.Password, nil } // ResetPassword resets all changes to the "password" field. func (m *UserMutation) ResetPassword() { m.password = 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, 2) if m.username != nil { fields = append(fields, user.FieldUsername) } if m.password != nil { fields = append(fields, user.FieldPassword) } 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.FieldPassword: return m.Password() } 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.FieldPassword: return m.OldPassword(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.FieldPassword: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPassword(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 { return nil } // 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 { 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.FieldPassword: m.ResetPassword() 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, 0) 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 { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *UserMutation) RemovedEdges() []string { edges := make([]string, 0, 0) 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 { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *UserMutation) ClearedEdges() []string { edges := make([]string, 0, 0) 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 { 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 { 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 { return fmt.Errorf("unknown User edge %s", name) } // VisitMutation represents an operation that mutates the Visit nodes in the graph. type VisitMutation struct { config op Op typ string id *int _path *string ip *string user_agent *string referer *string visit_time *time.Time clearedFields map[string]struct{} done bool oldValue func(context.Context) (*Visit, error) predicates []predicate.Visit } var _ ent.Mutation = (*VisitMutation)(nil) // visitOption allows management of the mutation configuration using functional options. type visitOption func(*VisitMutation) // newVisitMutation creates new mutation for the Visit entity. func newVisitMutation(c config, op Op, opts ...visitOption) *VisitMutation { m := &VisitMutation{ config: c, op: op, typ: TypeVisit, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withVisitID sets the ID field of the mutation. func withVisitID(id int) visitOption { return func(m *VisitMutation) { var ( err error once sync.Once value *Visit ) m.oldValue = func(ctx context.Context) (*Visit, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Visit.Get(ctx, id) } }) return value, err } m.id = &id } } // withVisit sets the old Visit of the mutation. func withVisit(node *Visit) visitOption { return func(m *VisitMutation) { m.oldValue = func(context.Context) (*Visit, 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 VisitMutation) 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 VisitMutation) 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 Visit entities. func (m *VisitMutation) SetID(id int) { 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 *VisitMutation) 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 *VisitMutation) 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().Visit.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetPath sets the "path" field. func (m *VisitMutation) SetPath(s string) { m._path = &s } // Path returns the value of the "path" field in the mutation. func (m *VisitMutation) Path() (r string, exists bool) { v := m._path if v == nil { return } return *v, true } // OldPath returns the old "path" field's value of the Visit entity. // If the Visit 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 *VisitMutation) OldPath(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPath is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPath requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPath: %w", err) } return oldValue.Path, nil } // ResetPath resets all changes to the "path" field. func (m *VisitMutation) ResetPath() { m._path = nil } // SetIP sets the "ip" field. func (m *VisitMutation) SetIP(s string) { m.ip = &s } // IP returns the value of the "ip" field in the mutation. func (m *VisitMutation) IP() (r string, exists bool) { v := m.ip if v == nil { return } return *v, true } // OldIP returns the old "ip" field's value of the Visit entity. // If the Visit 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 *VisitMutation) OldIP(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldIP is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldIP requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldIP: %w", err) } return oldValue.IP, nil } // ResetIP resets all changes to the "ip" field. func (m *VisitMutation) ResetIP() { m.ip = nil } // SetUserAgent sets the "user_agent" field. func (m *VisitMutation) SetUserAgent(s string) { m.user_agent = &s } // UserAgent returns the value of the "user_agent" field in the mutation. func (m *VisitMutation) UserAgent() (r string, exists bool) { v := m.user_agent if v == nil { return } return *v, true } // OldUserAgent returns the old "user_agent" field's value of the Visit entity. // If the Visit 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 *VisitMutation) OldUserAgent(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUserAgent is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldUserAgent requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldUserAgent: %w", err) } return oldValue.UserAgent, nil } // ClearUserAgent clears the value of the "user_agent" field. func (m *VisitMutation) ClearUserAgent() { m.user_agent = nil m.clearedFields[visit.FieldUserAgent] = struct{}{} } // UserAgentCleared returns if the "user_agent" field was cleared in this mutation. func (m *VisitMutation) UserAgentCleared() bool { _, ok := m.clearedFields[visit.FieldUserAgent] return ok } // ResetUserAgent resets all changes to the "user_agent" field. func (m *VisitMutation) ResetUserAgent() { m.user_agent = nil delete(m.clearedFields, visit.FieldUserAgent) } // SetReferer sets the "referer" field. func (m *VisitMutation) SetReferer(s string) { m.referer = &s } // Referer returns the value of the "referer" field in the mutation. func (m *VisitMutation) Referer() (r string, exists bool) { v := m.referer if v == nil { return } return *v, true } // OldReferer returns the old "referer" field's value of the Visit entity. // If the Visit 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 *VisitMutation) OldReferer(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldReferer is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldReferer requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldReferer: %w", err) } return oldValue.Referer, nil } // ClearReferer clears the value of the "referer" field. func (m *VisitMutation) ClearReferer() { m.referer = nil m.clearedFields[visit.FieldReferer] = struct{}{} } // RefererCleared returns if the "referer" field was cleared in this mutation. func (m *VisitMutation) RefererCleared() bool { _, ok := m.clearedFields[visit.FieldReferer] return ok } // ResetReferer resets all changes to the "referer" field. func (m *VisitMutation) ResetReferer() { m.referer = nil delete(m.clearedFields, visit.FieldReferer) } // SetVisitTime sets the "visit_time" field. func (m *VisitMutation) SetVisitTime(t time.Time) { m.visit_time = &t } // VisitTime returns the value of the "visit_time" field in the mutation. func (m *VisitMutation) VisitTime() (r time.Time, exists bool) { v := m.visit_time if v == nil { return } return *v, true } // OldVisitTime returns the old "visit_time" field's value of the Visit entity. // If the Visit 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 *VisitMutation) OldVisitTime(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldVisitTime is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldVisitTime requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldVisitTime: %w", err) } return oldValue.VisitTime, nil } // ResetVisitTime resets all changes to the "visit_time" field. func (m *VisitMutation) ResetVisitTime() { m.visit_time = nil } // Where appends a list predicates to the VisitMutation builder. func (m *VisitMutation) Where(ps ...predicate.Visit) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the VisitMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *VisitMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Visit, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *VisitMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *VisitMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Visit). func (m *VisitMutation) 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 *VisitMutation) Fields() []string { fields := make([]string, 0, 5) if m._path != nil { fields = append(fields, visit.FieldPath) } if m.ip != nil { fields = append(fields, visit.FieldIP) } if m.user_agent != nil { fields = append(fields, visit.FieldUserAgent) } if m.referer != nil { fields = append(fields, visit.FieldReferer) } if m.visit_time != nil { fields = append(fields, visit.FieldVisitTime) } 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 *VisitMutation) Field(name string) (ent.Value, bool) { switch name { case visit.FieldPath: return m.Path() case visit.FieldIP: return m.IP() case visit.FieldUserAgent: return m.UserAgent() case visit.FieldReferer: return m.Referer() case visit.FieldVisitTime: return m.VisitTime() } 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 *VisitMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case visit.FieldPath: return m.OldPath(ctx) case visit.FieldIP: return m.OldIP(ctx) case visit.FieldUserAgent: return m.OldUserAgent(ctx) case visit.FieldReferer: return m.OldReferer(ctx) case visit.FieldVisitTime: return m.OldVisitTime(ctx) } return nil, fmt.Errorf("unknown Visit 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 *VisitMutation) SetField(name string, value ent.Value) error { switch name { case visit.FieldPath: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPath(v) return nil case visit.FieldIP: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetIP(v) return nil case visit.FieldUserAgent: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserAgent(v) return nil case visit.FieldReferer: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetReferer(v) return nil case visit.FieldVisitTime: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetVisitTime(v) return nil } return fmt.Errorf("unknown Visit field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *VisitMutation) 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 *VisitMutation) 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 *VisitMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Visit numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *VisitMutation) ClearedFields() []string { var fields []string if m.FieldCleared(visit.FieldUserAgent) { fields = append(fields, visit.FieldUserAgent) } if m.FieldCleared(visit.FieldReferer) { fields = append(fields, visit.FieldReferer) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *VisitMutation) 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 *VisitMutation) ClearField(name string) error { switch name { case visit.FieldUserAgent: m.ClearUserAgent() return nil case visit.FieldReferer: m.ClearReferer() return nil } return fmt.Errorf("unknown Visit 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 *VisitMutation) ResetField(name string) error { switch name { case visit.FieldPath: m.ResetPath() return nil case visit.FieldIP: m.ResetIP() return nil case visit.FieldUserAgent: m.ResetUserAgent() return nil case visit.FieldReferer: m.ResetReferer() return nil case visit.FieldVisitTime: m.ResetVisitTime() return nil } return fmt.Errorf("unknown Visit field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *VisitMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *VisitMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *VisitMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *VisitMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *VisitMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *VisitMutation) EdgeCleared(name string) bool { 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 *VisitMutation) ClearEdge(name string) error { return fmt.Errorf("unknown Visit 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 *VisitMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Visit edge %s", name) }