Files
likedream/internal/ent/mutation.go
T
sugarBecomer 6840b69f1a 🐛 登录问题
2025-11-07 15:28:54 +08:00

10723 lines
310 KiB
Go

// ENT数据库文件,请勿编辑。
package ent
import (
"context"
"errors"
"fmt"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/predicate"
"likedream-goframe/internal/ent/sysagent"
"likedream-goframe/internal/ent/syscard"
"likedream-goframe/internal/ent/sysmenu"
"likedream-goframe/internal/ent/sysrole"
"likedream-goframe/internal/ent/sysuser"
"likedream-goframe/internal/framework/ent2"
"sync"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/google/uuid"
"github.com/shopspring/decimal"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeCpImage = "CpImage"
TypeCpSchool = "CpSchool"
TypeCpTask = "CpTask"
TypeCpTaskLog = "CpTaskLog"
TypeCpUser = "CpUser"
TypeSysAgent = "SysAgent"
TypeSysCard = "SysCard"
TypeSysMenu = "SysMenu"
TypeSysRole = "SysRole"
TypeSysUser = "SysUser"
TypeSysUserLog = "SysUserLog"
)
// CpImageMutation represents an operation that mutates the CpImage nodes in the graph.
type CpImageMutation struct {
config
op Op
typ string
id *int64
create_time **ent2.CustomTime
update_time **ent2.CustomTime
image_id *uuid.UUID
key *string
content_type *string
content_length *int64
addcontent_length *int64
clearedFields map[string]struct{}
user *int64
cleareduser bool
done bool
oldValue func(context.Context) (*CpImage, error)
predicates []predicate.CpImage
}
var _ ent.Mutation = (*CpImageMutation)(nil)
// cpimageOption allows management of the mutation configuration using functional options.
type cpimageOption func(*CpImageMutation)
// newCpImageMutation creates new mutation for the CpImage entity.
func newCpImageMutation(c config, op Op, opts ...cpimageOption) *CpImageMutation {
m := &CpImageMutation{
config: c,
op: op,
typ: TypeCpImage,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withCpImageID sets the ID field of the mutation.
func withCpImageID(id int64) cpimageOption {
return func(m *CpImageMutation) {
var (
err error
once sync.Once
value *CpImage
)
m.oldValue = func(ctx context.Context) (*CpImage, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().CpImage.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withCpImage sets the old CpImage of the mutation.
func withCpImage(node *CpImage) cpimageOption {
return func(m *CpImageMutation) {
m.oldValue = func(context.Context) (*CpImage, 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 CpImageMutation) 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 CpImageMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *CpImageMutation) ID() (id int64, 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 *CpImageMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().CpImage.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreateTime sets the "create_time" field.
func (m *CpImageMutation) SetCreateTime(et *ent2.CustomTime) {
m.create_time = &et
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *CpImageMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the CpImage entity.
// If the CpImage 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 *CpImageMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *CpImageMutation) ResetCreateTime() {
m.create_time = nil
}
// SetUpdateTime sets the "update_time" field.
func (m *CpImageMutation) SetUpdateTime(et *ent2.CustomTime) {
m.update_time = &et
}
// UpdateTime returns the value of the "update_time" field in the mutation.
func (m *CpImageMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
v := m.update_time
if v == nil {
return
}
return *v, true
}
// OldUpdateTime returns the old "update_time" field's value of the CpImage entity.
// If the CpImage 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 *CpImageMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
}
return oldValue.UpdateTime, nil
}
// ResetUpdateTime resets all changes to the "update_time" field.
func (m *CpImageMutation) ResetUpdateTime() {
m.update_time = nil
}
// SetImageID sets the "image_id" field.
func (m *CpImageMutation) SetImageID(u uuid.UUID) {
m.image_id = &u
}
// ImageID returns the value of the "image_id" field in the mutation.
func (m *CpImageMutation) ImageID() (r uuid.UUID, exists bool) {
v := m.image_id
if v == nil {
return
}
return *v, true
}
// OldImageID returns the old "image_id" field's value of the CpImage entity.
// If the CpImage 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 *CpImageMutation) OldImageID(ctx context.Context) (v uuid.UUID, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldImageID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldImageID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldImageID: %w", err)
}
return oldValue.ImageID, nil
}
// ResetImageID resets all changes to the "image_id" field.
func (m *CpImageMutation) ResetImageID() {
m.image_id = nil
}
// SetKey sets the "key" field.
func (m *CpImageMutation) SetKey(s string) {
m.key = &s
}
// Key returns the value of the "key" field in the mutation.
func (m *CpImageMutation) Key() (r string, exists bool) {
v := m.key
if v == nil {
return
}
return *v, true
}
// OldKey returns the old "key" field's value of the CpImage entity.
// If the CpImage 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 *CpImageMutation) OldKey(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldKey is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldKey requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldKey: %w", err)
}
return oldValue.Key, nil
}
// ResetKey resets all changes to the "key" field.
func (m *CpImageMutation) ResetKey() {
m.key = nil
}
// SetUserID sets the "user_id" field.
func (m *CpImageMutation) SetUserID(i int64) {
m.user = &i
}
// UserID returns the value of the "user_id" field in the mutation.
func (m *CpImageMutation) UserID() (r int64, exists bool) {
v := m.user
if v == nil {
return
}
return *v, true
}
// OldUserID returns the old "user_id" field's value of the CpImage entity.
// If the CpImage 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 *CpImageMutation) OldUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
}
return oldValue.UserID, nil
}
// ResetUserID resets all changes to the "user_id" field.
func (m *CpImageMutation) ResetUserID() {
m.user = nil
}
// SetContentType sets the "content_type" field.
func (m *CpImageMutation) SetContentType(s string) {
m.content_type = &s
}
// ContentType returns the value of the "content_type" field in the mutation.
func (m *CpImageMutation) ContentType() (r string, exists bool) {
v := m.content_type
if v == nil {
return
}
return *v, true
}
// OldContentType returns the old "content_type" field's value of the CpImage entity.
// If the CpImage 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 *CpImageMutation) OldContentType(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldContentType is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldContentType requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldContentType: %w", err)
}
return oldValue.ContentType, nil
}
// ResetContentType resets all changes to the "content_type" field.
func (m *CpImageMutation) ResetContentType() {
m.content_type = nil
}
// SetContentLength sets the "content_length" field.
func (m *CpImageMutation) SetContentLength(i int64) {
m.content_length = &i
m.addcontent_length = nil
}
// ContentLength returns the value of the "content_length" field in the mutation.
func (m *CpImageMutation) ContentLength() (r int64, exists bool) {
v := m.content_length
if v == nil {
return
}
return *v, true
}
// OldContentLength returns the old "content_length" field's value of the CpImage entity.
// If the CpImage 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 *CpImageMutation) OldContentLength(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldContentLength is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldContentLength requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldContentLength: %w", err)
}
return oldValue.ContentLength, nil
}
// AddContentLength adds i to the "content_length" field.
func (m *CpImageMutation) AddContentLength(i int64) {
if m.addcontent_length != nil {
*m.addcontent_length += i
} else {
m.addcontent_length = &i
}
}
// AddedContentLength returns the value that was added to the "content_length" field in this mutation.
func (m *CpImageMutation) AddedContentLength() (r int64, exists bool) {
v := m.addcontent_length
if v == nil {
return
}
return *v, true
}
// ResetContentLength resets all changes to the "content_length" field.
func (m *CpImageMutation) ResetContentLength() {
m.content_length = nil
m.addcontent_length = nil
}
// ClearUser clears the "user" edge to the SysUser entity.
func (m *CpImageMutation) ClearUser() {
m.cleareduser = true
m.clearedFields[cpimage.FieldUserID] = struct{}{}
}
// UserCleared reports if the "user" edge to the SysUser entity was cleared.
func (m *CpImageMutation) UserCleared() bool {
return m.cleareduser
}
// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *CpImageMutation) UserIDs() (ids []int64) {
if id := m.user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetUser resets all changes to the "user" edge.
func (m *CpImageMutation) ResetUser() {
m.user = nil
m.cleareduser = false
}
// Where appends a list predicates to the CpImageMutation builder.
func (m *CpImageMutation) Where(ps ...predicate.CpImage) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the CpImageMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *CpImageMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.CpImage, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *CpImageMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *CpImageMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (CpImage).
func (m *CpImageMutation) 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 *CpImageMutation) Fields() []string {
fields := make([]string, 0, 7)
if m.create_time != nil {
fields = append(fields, cpimage.FieldCreateTime)
}
if m.update_time != nil {
fields = append(fields, cpimage.FieldUpdateTime)
}
if m.image_id != nil {
fields = append(fields, cpimage.FieldImageID)
}
if m.key != nil {
fields = append(fields, cpimage.FieldKey)
}
if m.user != nil {
fields = append(fields, cpimage.FieldUserID)
}
if m.content_type != nil {
fields = append(fields, cpimage.FieldContentType)
}
if m.content_length != nil {
fields = append(fields, cpimage.FieldContentLength)
}
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 *CpImageMutation) Field(name string) (ent.Value, bool) {
switch name {
case cpimage.FieldCreateTime:
return m.CreateTime()
case cpimage.FieldUpdateTime:
return m.UpdateTime()
case cpimage.FieldImageID:
return m.ImageID()
case cpimage.FieldKey:
return m.Key()
case cpimage.FieldUserID:
return m.UserID()
case cpimage.FieldContentType:
return m.ContentType()
case cpimage.FieldContentLength:
return m.ContentLength()
}
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 *CpImageMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case cpimage.FieldCreateTime:
return m.OldCreateTime(ctx)
case cpimage.FieldUpdateTime:
return m.OldUpdateTime(ctx)
case cpimage.FieldImageID:
return m.OldImageID(ctx)
case cpimage.FieldKey:
return m.OldKey(ctx)
case cpimage.FieldUserID:
return m.OldUserID(ctx)
case cpimage.FieldContentType:
return m.OldContentType(ctx)
case cpimage.FieldContentLength:
return m.OldContentLength(ctx)
}
return nil, fmt.Errorf("unknown CpImage 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 *CpImageMutation) SetField(name string, value ent.Value) error {
switch name {
case cpimage.FieldCreateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil
case cpimage.FieldUpdateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdateTime(v)
return nil
case cpimage.FieldImageID:
v, ok := value.(uuid.UUID)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetImageID(v)
return nil
case cpimage.FieldKey:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetKey(v)
return nil
case cpimage.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUserID(v)
return nil
case cpimage.FieldContentType:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetContentType(v)
return nil
case cpimage.FieldContentLength:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetContentLength(v)
return nil
}
return fmt.Errorf("unknown CpImage field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *CpImageMutation) AddedFields() []string {
var fields []string
if m.addcontent_length != nil {
fields = append(fields, cpimage.FieldContentLength)
}
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 *CpImageMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case cpimage.FieldContentLength:
return m.AddedContentLength()
}
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 *CpImageMutation) AddField(name string, value ent.Value) error {
switch name {
case cpimage.FieldContentLength:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddContentLength(v)
return nil
}
return fmt.Errorf("unknown CpImage numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *CpImageMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *CpImageMutation) 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 *CpImageMutation) ClearField(name string) error {
return fmt.Errorf("unknown CpImage 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 *CpImageMutation) ResetField(name string) error {
switch name {
case cpimage.FieldCreateTime:
m.ResetCreateTime()
return nil
case cpimage.FieldUpdateTime:
m.ResetUpdateTime()
return nil
case cpimage.FieldImageID:
m.ResetImageID()
return nil
case cpimage.FieldKey:
m.ResetKey()
return nil
case cpimage.FieldUserID:
m.ResetUserID()
return nil
case cpimage.FieldContentType:
m.ResetContentType()
return nil
case cpimage.FieldContentLength:
m.ResetContentLength()
return nil
}
return fmt.Errorf("unknown CpImage field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CpImageMutation) AddedEdges() []string {
edges := make([]string, 0, 1)
if m.user != nil {
edges = append(edges, cpimage.EdgeUser)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *CpImageMutation) AddedIDs(name string) []ent.Value {
switch name {
case cpimage.EdgeUser:
if id := m.user; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *CpImageMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *CpImageMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CpImageMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
if m.cleareduser {
edges = append(edges, cpimage.EdgeUser)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *CpImageMutation) EdgeCleared(name string) bool {
switch name {
case cpimage.EdgeUser:
return m.cleareduser
}
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 *CpImageMutation) ClearEdge(name string) error {
switch name {
case cpimage.EdgeUser:
m.ClearUser()
return nil
}
return fmt.Errorf("unknown CpImage 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 *CpImageMutation) ResetEdge(name string) error {
switch name {
case cpimage.EdgeUser:
m.ResetUser()
return nil
}
return fmt.Errorf("unknown CpImage edge %s", name)
}
// CpSchoolMutation represents an operation that mutates the CpSchool nodes in the graph.
type CpSchoolMutation struct {
config
op Op
typ string
id *string
create_time **ent2.CustomTime
update_time **ent2.CustomTime
name *string
name_pinyin *string
icon_img *string
clearedFields map[string]struct{}
cpusers map[int64]struct{}
removedcpusers map[int64]struct{}
clearedcpusers bool
done bool
oldValue func(context.Context) (*CpSchool, error)
predicates []predicate.CpSchool
}
var _ ent.Mutation = (*CpSchoolMutation)(nil)
// cpschoolOption allows management of the mutation configuration using functional options.
type cpschoolOption func(*CpSchoolMutation)
// newCpSchoolMutation creates new mutation for the CpSchool entity.
func newCpSchoolMutation(c config, op Op, opts ...cpschoolOption) *CpSchoolMutation {
m := &CpSchoolMutation{
config: c,
op: op,
typ: TypeCpSchool,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withCpSchoolID sets the ID field of the mutation.
func withCpSchoolID(id string) cpschoolOption {
return func(m *CpSchoolMutation) {
var (
err error
once sync.Once
value *CpSchool
)
m.oldValue = func(ctx context.Context) (*CpSchool, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().CpSchool.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withCpSchool sets the old CpSchool of the mutation.
func withCpSchool(node *CpSchool) cpschoolOption {
return func(m *CpSchoolMutation) {
m.oldValue = func(context.Context) (*CpSchool, 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 CpSchoolMutation) 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 CpSchoolMutation) 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 CpSchool entities.
func (m *CpSchoolMutation) SetID(id string) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *CpSchoolMutation) ID() (id string, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *CpSchoolMutation) IDs(ctx context.Context) ([]string, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []string{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().CpSchool.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreateTime sets the "create_time" field.
func (m *CpSchoolMutation) SetCreateTime(et *ent2.CustomTime) {
m.create_time = &et
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *CpSchoolMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the CpSchool entity.
// If the CpSchool 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 *CpSchoolMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *CpSchoolMutation) ResetCreateTime() {
m.create_time = nil
}
// SetUpdateTime sets the "update_time" field.
func (m *CpSchoolMutation) SetUpdateTime(et *ent2.CustomTime) {
m.update_time = &et
}
// UpdateTime returns the value of the "update_time" field in the mutation.
func (m *CpSchoolMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
v := m.update_time
if v == nil {
return
}
return *v, true
}
// OldUpdateTime returns the old "update_time" field's value of the CpSchool entity.
// If the CpSchool 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 *CpSchoolMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
}
return oldValue.UpdateTime, nil
}
// ResetUpdateTime resets all changes to the "update_time" field.
func (m *CpSchoolMutation) ResetUpdateTime() {
m.update_time = nil
}
// SetName sets the "name" field.
func (m *CpSchoolMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *CpSchoolMutation) 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 CpSchool entity.
// If the CpSchool 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 *CpSchoolMutation) 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 *CpSchoolMutation) ResetName() {
m.name = nil
}
// SetNamePinyin sets the "name_pinyin" field.
func (m *CpSchoolMutation) SetNamePinyin(s string) {
m.name_pinyin = &s
}
// NamePinyin returns the value of the "name_pinyin" field in the mutation.
func (m *CpSchoolMutation) NamePinyin() (r string, exists bool) {
v := m.name_pinyin
if v == nil {
return
}
return *v, true
}
// OldNamePinyin returns the old "name_pinyin" field's value of the CpSchool entity.
// If the CpSchool 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 *CpSchoolMutation) OldNamePinyin(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldNamePinyin is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldNamePinyin requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldNamePinyin: %w", err)
}
return oldValue.NamePinyin, nil
}
// ResetNamePinyin resets all changes to the "name_pinyin" field.
func (m *CpSchoolMutation) ResetNamePinyin() {
m.name_pinyin = nil
}
// SetIconImg sets the "icon_img" field.
func (m *CpSchoolMutation) SetIconImg(s string) {
m.icon_img = &s
}
// IconImg returns the value of the "icon_img" field in the mutation.
func (m *CpSchoolMutation) IconImg() (r string, exists bool) {
v := m.icon_img
if v == nil {
return
}
return *v, true
}
// OldIconImg returns the old "icon_img" field's value of the CpSchool entity.
// If the CpSchool 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 *CpSchoolMutation) OldIconImg(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIconImg is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIconImg requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIconImg: %w", err)
}
return oldValue.IconImg, nil
}
// ClearIconImg clears the value of the "icon_img" field.
func (m *CpSchoolMutation) ClearIconImg() {
m.icon_img = nil
m.clearedFields[cpschool.FieldIconImg] = struct{}{}
}
// IconImgCleared returns if the "icon_img" field was cleared in this mutation.
func (m *CpSchoolMutation) IconImgCleared() bool {
_, ok := m.clearedFields[cpschool.FieldIconImg]
return ok
}
// ResetIconImg resets all changes to the "icon_img" field.
func (m *CpSchoolMutation) ResetIconImg() {
m.icon_img = nil
delete(m.clearedFields, cpschool.FieldIconImg)
}
// AddCpuserIDs adds the "cpusers" edge to the CpUser entity by ids.
func (m *CpSchoolMutation) AddCpuserIDs(ids ...int64) {
if m.cpusers == nil {
m.cpusers = make(map[int64]struct{})
}
for i := range ids {
m.cpusers[ids[i]] = struct{}{}
}
}
// ClearCpusers clears the "cpusers" edge to the CpUser entity.
func (m *CpSchoolMutation) ClearCpusers() {
m.clearedcpusers = true
}
// CpusersCleared reports if the "cpusers" edge to the CpUser entity was cleared.
func (m *CpSchoolMutation) CpusersCleared() bool {
return m.clearedcpusers
}
// RemoveCpuserIDs removes the "cpusers" edge to the CpUser entity by IDs.
func (m *CpSchoolMutation) RemoveCpuserIDs(ids ...int64) {
if m.removedcpusers == nil {
m.removedcpusers = make(map[int64]struct{})
}
for i := range ids {
delete(m.cpusers, ids[i])
m.removedcpusers[ids[i]] = struct{}{}
}
}
// RemovedCpusers returns the removed IDs of the "cpusers" edge to the CpUser entity.
func (m *CpSchoolMutation) RemovedCpusersIDs() (ids []int64) {
for id := range m.removedcpusers {
ids = append(ids, id)
}
return
}
// CpusersIDs returns the "cpusers" edge IDs in the mutation.
func (m *CpSchoolMutation) CpusersIDs() (ids []int64) {
for id := range m.cpusers {
ids = append(ids, id)
}
return
}
// ResetCpusers resets all changes to the "cpusers" edge.
func (m *CpSchoolMutation) ResetCpusers() {
m.cpusers = nil
m.clearedcpusers = false
m.removedcpusers = nil
}
// Where appends a list predicates to the CpSchoolMutation builder.
func (m *CpSchoolMutation) Where(ps ...predicate.CpSchool) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the CpSchoolMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *CpSchoolMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.CpSchool, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *CpSchoolMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *CpSchoolMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (CpSchool).
func (m *CpSchoolMutation) 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 *CpSchoolMutation) Fields() []string {
fields := make([]string, 0, 5)
if m.create_time != nil {
fields = append(fields, cpschool.FieldCreateTime)
}
if m.update_time != nil {
fields = append(fields, cpschool.FieldUpdateTime)
}
if m.name != nil {
fields = append(fields, cpschool.FieldName)
}
if m.name_pinyin != nil {
fields = append(fields, cpschool.FieldNamePinyin)
}
if m.icon_img != nil {
fields = append(fields, cpschool.FieldIconImg)
}
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 *CpSchoolMutation) Field(name string) (ent.Value, bool) {
switch name {
case cpschool.FieldCreateTime:
return m.CreateTime()
case cpschool.FieldUpdateTime:
return m.UpdateTime()
case cpschool.FieldName:
return m.Name()
case cpschool.FieldNamePinyin:
return m.NamePinyin()
case cpschool.FieldIconImg:
return m.IconImg()
}
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 *CpSchoolMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case cpschool.FieldCreateTime:
return m.OldCreateTime(ctx)
case cpschool.FieldUpdateTime:
return m.OldUpdateTime(ctx)
case cpschool.FieldName:
return m.OldName(ctx)
case cpschool.FieldNamePinyin:
return m.OldNamePinyin(ctx)
case cpschool.FieldIconImg:
return m.OldIconImg(ctx)
}
return nil, fmt.Errorf("unknown CpSchool 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 *CpSchoolMutation) SetField(name string, value ent.Value) error {
switch name {
case cpschool.FieldCreateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil
case cpschool.FieldUpdateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdateTime(v)
return nil
case cpschool.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case cpschool.FieldNamePinyin:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetNamePinyin(v)
return nil
case cpschool.FieldIconImg:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIconImg(v)
return nil
}
return fmt.Errorf("unknown CpSchool field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *CpSchoolMutation) 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 *CpSchoolMutation) 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 *CpSchoolMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown CpSchool numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *CpSchoolMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(cpschool.FieldIconImg) {
fields = append(fields, cpschool.FieldIconImg)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *CpSchoolMutation) 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 *CpSchoolMutation) ClearField(name string) error {
switch name {
case cpschool.FieldIconImg:
m.ClearIconImg()
return nil
}
return fmt.Errorf("unknown CpSchool 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 *CpSchoolMutation) ResetField(name string) error {
switch name {
case cpschool.FieldCreateTime:
m.ResetCreateTime()
return nil
case cpschool.FieldUpdateTime:
m.ResetUpdateTime()
return nil
case cpschool.FieldName:
m.ResetName()
return nil
case cpschool.FieldNamePinyin:
m.ResetNamePinyin()
return nil
case cpschool.FieldIconImg:
m.ResetIconImg()
return nil
}
return fmt.Errorf("unknown CpSchool field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CpSchoolMutation) AddedEdges() []string {
edges := make([]string, 0, 1)
if m.cpusers != nil {
edges = append(edges, cpschool.EdgeCpusers)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *CpSchoolMutation) AddedIDs(name string) []ent.Value {
switch name {
case cpschool.EdgeCpusers:
ids := make([]ent.Value, 0, len(m.cpusers))
for id := range m.cpusers {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *CpSchoolMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
if m.removedcpusers != nil {
edges = append(edges, cpschool.EdgeCpusers)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *CpSchoolMutation) RemovedIDs(name string) []ent.Value {
switch name {
case cpschool.EdgeCpusers:
ids := make([]ent.Value, 0, len(m.removedcpusers))
for id := range m.removedcpusers {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CpSchoolMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
if m.clearedcpusers {
edges = append(edges, cpschool.EdgeCpusers)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *CpSchoolMutation) EdgeCleared(name string) bool {
switch name {
case cpschool.EdgeCpusers:
return m.clearedcpusers
}
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 *CpSchoolMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown CpSchool 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 *CpSchoolMutation) ResetEdge(name string) error {
switch name {
case cpschool.EdgeCpusers:
m.ResetCpusers()
return nil
}
return fmt.Errorf("unknown CpSchool edge %s", name)
}
// CpTaskMutation represents an operation that mutates the CpTask nodes in the graph.
type CpTaskMutation struct {
config
op Op
typ string
id *int64
create_time **ent2.CustomTime
update_time **ent2.CustomTime
task_type *cptask.TaskType
title *string
frequency *int
addfrequency *int
task_status *cptask.TaskStatus
success_count *int
addsuccess_count *int
form_data *string
step *cptask.Step
notification_type *cptask.NotificationType
execute_hour *int
addexecute_hour *int
execute_minute *int
addexecute_minute *int
next_execute_time *int64
addnext_execute_time *int64
clearedFields map[string]struct{}
cp_user *int64
clearedcp_user bool
sys_user *int64
clearedsys_user bool
cp_task_logs map[int64]struct{}
removedcp_task_logs map[int64]struct{}
clearedcp_task_logs bool
done bool
oldValue func(context.Context) (*CpTask, error)
predicates []predicate.CpTask
}
var _ ent.Mutation = (*CpTaskMutation)(nil)
// cptaskOption allows management of the mutation configuration using functional options.
type cptaskOption func(*CpTaskMutation)
// newCpTaskMutation creates new mutation for the CpTask entity.
func newCpTaskMutation(c config, op Op, opts ...cptaskOption) *CpTaskMutation {
m := &CpTaskMutation{
config: c,
op: op,
typ: TypeCpTask,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withCpTaskID sets the ID field of the mutation.
func withCpTaskID(id int64) cptaskOption {
return func(m *CpTaskMutation) {
var (
err error
once sync.Once
value *CpTask
)
m.oldValue = func(ctx context.Context) (*CpTask, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().CpTask.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withCpTask sets the old CpTask of the mutation.
func withCpTask(node *CpTask) cptaskOption {
return func(m *CpTaskMutation) {
m.oldValue = func(context.Context) (*CpTask, 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 CpTaskMutation) 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 CpTaskMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *CpTaskMutation) ID() (id int64, 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 *CpTaskMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().CpTask.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreateTime sets the "create_time" field.
func (m *CpTaskMutation) SetCreateTime(et *ent2.CustomTime) {
m.create_time = &et
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *CpTaskMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *CpTaskMutation) ResetCreateTime() {
m.create_time = nil
}
// SetUpdateTime sets the "update_time" field.
func (m *CpTaskMutation) SetUpdateTime(et *ent2.CustomTime) {
m.update_time = &et
}
// UpdateTime returns the value of the "update_time" field in the mutation.
func (m *CpTaskMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
v := m.update_time
if v == nil {
return
}
return *v, true
}
// OldUpdateTime returns the old "update_time" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
}
return oldValue.UpdateTime, nil
}
// ResetUpdateTime resets all changes to the "update_time" field.
func (m *CpTaskMutation) ResetUpdateTime() {
m.update_time = nil
}
// SetCpUserID sets the "cp_user_id" field.
func (m *CpTaskMutation) SetCpUserID(i int64) {
m.cp_user = &i
}
// CpUserID returns the value of the "cp_user_id" field in the mutation.
func (m *CpTaskMutation) CpUserID() (r int64, exists bool) {
v := m.cp_user
if v == nil {
return
}
return *v, true
}
// OldCpUserID returns the old "cp_user_id" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldCpUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCpUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCpUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCpUserID: %w", err)
}
return oldValue.CpUserID, nil
}
// ResetCpUserID resets all changes to the "cp_user_id" field.
func (m *CpTaskMutation) ResetCpUserID() {
m.cp_user = nil
}
// SetUserID sets the "user_id" field.
func (m *CpTaskMutation) SetUserID(i int64) {
m.sys_user = &i
}
// UserID returns the value of the "user_id" field in the mutation.
func (m *CpTaskMutation) UserID() (r int64, exists bool) {
v := m.sys_user
if v == nil {
return
}
return *v, true
}
// OldUserID returns the old "user_id" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
}
return oldValue.UserID, nil
}
// ResetUserID resets all changes to the "user_id" field.
func (m *CpTaskMutation) ResetUserID() {
m.sys_user = nil
}
// SetTaskType sets the "task_type" field.
func (m *CpTaskMutation) SetTaskType(ct cptask.TaskType) {
m.task_type = &ct
}
// TaskType returns the value of the "task_type" field in the mutation.
func (m *CpTaskMutation) TaskType() (r cptask.TaskType, exists bool) {
v := m.task_type
if v == nil {
return
}
return *v, true
}
// OldTaskType returns the old "task_type" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldTaskType(ctx context.Context) (v cptask.TaskType, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTaskType is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTaskType requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTaskType: %w", err)
}
return oldValue.TaskType, nil
}
// ResetTaskType resets all changes to the "task_type" field.
func (m *CpTaskMutation) ResetTaskType() {
m.task_type = nil
}
// SetTitle sets the "title" field.
func (m *CpTaskMutation) SetTitle(s string) {
m.title = &s
}
// Title returns the value of the "title" field in the mutation.
func (m *CpTaskMutation) Title() (r string, exists bool) {
v := m.title
if v == nil {
return
}
return *v, true
}
// OldTitle returns the old "title" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldTitle(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTitle is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTitle requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTitle: %w", err)
}
return oldValue.Title, nil
}
// ResetTitle resets all changes to the "title" field.
func (m *CpTaskMutation) ResetTitle() {
m.title = nil
}
// SetFrequency sets the "frequency" field.
func (m *CpTaskMutation) SetFrequency(i int) {
m.frequency = &i
m.addfrequency = nil
}
// Frequency returns the value of the "frequency" field in the mutation.
func (m *CpTaskMutation) Frequency() (r int, exists bool) {
v := m.frequency
if v == nil {
return
}
return *v, true
}
// OldFrequency returns the old "frequency" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldFrequency(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldFrequency is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldFrequency requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFrequency: %w", err)
}
return oldValue.Frequency, nil
}
// AddFrequency adds i to the "frequency" field.
func (m *CpTaskMutation) AddFrequency(i int) {
if m.addfrequency != nil {
*m.addfrequency += i
} else {
m.addfrequency = &i
}
}
// AddedFrequency returns the value that was added to the "frequency" field in this mutation.
func (m *CpTaskMutation) AddedFrequency() (r int, exists bool) {
v := m.addfrequency
if v == nil {
return
}
return *v, true
}
// ResetFrequency resets all changes to the "frequency" field.
func (m *CpTaskMutation) ResetFrequency() {
m.frequency = nil
m.addfrequency = nil
}
// SetTaskStatus sets the "task_status" field.
func (m *CpTaskMutation) SetTaskStatus(cs cptask.TaskStatus) {
m.task_status = &cs
}
// TaskStatus returns the value of the "task_status" field in the mutation.
func (m *CpTaskMutation) TaskStatus() (r cptask.TaskStatus, exists bool) {
v := m.task_status
if v == nil {
return
}
return *v, true
}
// OldTaskStatus returns the old "task_status" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldTaskStatus(ctx context.Context) (v cptask.TaskStatus, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTaskStatus is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTaskStatus requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTaskStatus: %w", err)
}
return oldValue.TaskStatus, nil
}
// ResetTaskStatus resets all changes to the "task_status" field.
func (m *CpTaskMutation) ResetTaskStatus() {
m.task_status = nil
}
// SetSuccessCount sets the "success_count" field.
func (m *CpTaskMutation) SetSuccessCount(i int) {
m.success_count = &i
m.addsuccess_count = nil
}
// SuccessCount returns the value of the "success_count" field in the mutation.
func (m *CpTaskMutation) SuccessCount() (r int, exists bool) {
v := m.success_count
if v == nil {
return
}
return *v, true
}
// OldSuccessCount returns the old "success_count" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldSuccessCount(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSuccessCount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSuccessCount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSuccessCount: %w", err)
}
return oldValue.SuccessCount, nil
}
// AddSuccessCount adds i to the "success_count" field.
func (m *CpTaskMutation) AddSuccessCount(i int) {
if m.addsuccess_count != nil {
*m.addsuccess_count += i
} else {
m.addsuccess_count = &i
}
}
// AddedSuccessCount returns the value that was added to the "success_count" field in this mutation.
func (m *CpTaskMutation) AddedSuccessCount() (r int, exists bool) {
v := m.addsuccess_count
if v == nil {
return
}
return *v, true
}
// ResetSuccessCount resets all changes to the "success_count" field.
func (m *CpTaskMutation) ResetSuccessCount() {
m.success_count = nil
m.addsuccess_count = nil
}
// SetFormData sets the "form_data" field.
func (m *CpTaskMutation) SetFormData(s string) {
m.form_data = &s
}
// FormData returns the value of the "form_data" field in the mutation.
func (m *CpTaskMutation) FormData() (r string, exists bool) {
v := m.form_data
if v == nil {
return
}
return *v, true
}
// OldFormData returns the old "form_data" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldFormData(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldFormData is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldFormData requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFormData: %w", err)
}
return oldValue.FormData, nil
}
// ClearFormData clears the value of the "form_data" field.
func (m *CpTaskMutation) ClearFormData() {
m.form_data = nil
m.clearedFields[cptask.FieldFormData] = struct{}{}
}
// FormDataCleared returns if the "form_data" field was cleared in this mutation.
func (m *CpTaskMutation) FormDataCleared() bool {
_, ok := m.clearedFields[cptask.FieldFormData]
return ok
}
// ResetFormData resets all changes to the "form_data" field.
func (m *CpTaskMutation) ResetFormData() {
m.form_data = nil
delete(m.clearedFields, cptask.FieldFormData)
}
// SetStep sets the "step" field.
func (m *CpTaskMutation) SetStep(c cptask.Step) {
m.step = &c
}
// Step returns the value of the "step" field in the mutation.
func (m *CpTaskMutation) Step() (r cptask.Step, exists bool) {
v := m.step
if v == nil {
return
}
return *v, true
}
// OldStep returns the old "step" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldStep(ctx context.Context) (v cptask.Step, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldStep is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldStep requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldStep: %w", err)
}
return oldValue.Step, nil
}
// ResetStep resets all changes to the "step" field.
func (m *CpTaskMutation) ResetStep() {
m.step = nil
}
// SetNotificationType sets the "notification_type" field.
func (m *CpTaskMutation) SetNotificationType(ct cptask.NotificationType) {
m.notification_type = &ct
}
// NotificationType returns the value of the "notification_type" field in the mutation.
func (m *CpTaskMutation) NotificationType() (r cptask.NotificationType, exists bool) {
v := m.notification_type
if v == nil {
return
}
return *v, true
}
// OldNotificationType returns the old "notification_type" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldNotificationType(ctx context.Context) (v cptask.NotificationType, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldNotificationType is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldNotificationType requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldNotificationType: %w", err)
}
return oldValue.NotificationType, nil
}
// ResetNotificationType resets all changes to the "notification_type" field.
func (m *CpTaskMutation) ResetNotificationType() {
m.notification_type = nil
}
// SetExecuteHour sets the "execute_hour" field.
func (m *CpTaskMutation) SetExecuteHour(i int) {
m.execute_hour = &i
m.addexecute_hour = nil
}
// ExecuteHour returns the value of the "execute_hour" field in the mutation.
func (m *CpTaskMutation) ExecuteHour() (r int, exists bool) {
v := m.execute_hour
if v == nil {
return
}
return *v, true
}
// OldExecuteHour returns the old "execute_hour" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldExecuteHour(ctx context.Context) (v *int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldExecuteHour is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldExecuteHour requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldExecuteHour: %w", err)
}
return oldValue.ExecuteHour, nil
}
// AddExecuteHour adds i to the "execute_hour" field.
func (m *CpTaskMutation) AddExecuteHour(i int) {
if m.addexecute_hour != nil {
*m.addexecute_hour += i
} else {
m.addexecute_hour = &i
}
}
// AddedExecuteHour returns the value that was added to the "execute_hour" field in this mutation.
func (m *CpTaskMutation) AddedExecuteHour() (r int, exists bool) {
v := m.addexecute_hour
if v == nil {
return
}
return *v, true
}
// ClearExecuteHour clears the value of the "execute_hour" field.
func (m *CpTaskMutation) ClearExecuteHour() {
m.execute_hour = nil
m.addexecute_hour = nil
m.clearedFields[cptask.FieldExecuteHour] = struct{}{}
}
// ExecuteHourCleared returns if the "execute_hour" field was cleared in this mutation.
func (m *CpTaskMutation) ExecuteHourCleared() bool {
_, ok := m.clearedFields[cptask.FieldExecuteHour]
return ok
}
// ResetExecuteHour resets all changes to the "execute_hour" field.
func (m *CpTaskMutation) ResetExecuteHour() {
m.execute_hour = nil
m.addexecute_hour = nil
delete(m.clearedFields, cptask.FieldExecuteHour)
}
// SetExecuteMinute sets the "execute_minute" field.
func (m *CpTaskMutation) SetExecuteMinute(i int) {
m.execute_minute = &i
m.addexecute_minute = nil
}
// ExecuteMinute returns the value of the "execute_minute" field in the mutation.
func (m *CpTaskMutation) ExecuteMinute() (r int, exists bool) {
v := m.execute_minute
if v == nil {
return
}
return *v, true
}
// OldExecuteMinute returns the old "execute_minute" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldExecuteMinute(ctx context.Context) (v *int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldExecuteMinute is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldExecuteMinute requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldExecuteMinute: %w", err)
}
return oldValue.ExecuteMinute, nil
}
// AddExecuteMinute adds i to the "execute_minute" field.
func (m *CpTaskMutation) AddExecuteMinute(i int) {
if m.addexecute_minute != nil {
*m.addexecute_minute += i
} else {
m.addexecute_minute = &i
}
}
// AddedExecuteMinute returns the value that was added to the "execute_minute" field in this mutation.
func (m *CpTaskMutation) AddedExecuteMinute() (r int, exists bool) {
v := m.addexecute_minute
if v == nil {
return
}
return *v, true
}
// ClearExecuteMinute clears the value of the "execute_minute" field.
func (m *CpTaskMutation) ClearExecuteMinute() {
m.execute_minute = nil
m.addexecute_minute = nil
m.clearedFields[cptask.FieldExecuteMinute] = struct{}{}
}
// ExecuteMinuteCleared returns if the "execute_minute" field was cleared in this mutation.
func (m *CpTaskMutation) ExecuteMinuteCleared() bool {
_, ok := m.clearedFields[cptask.FieldExecuteMinute]
return ok
}
// ResetExecuteMinute resets all changes to the "execute_minute" field.
func (m *CpTaskMutation) ResetExecuteMinute() {
m.execute_minute = nil
m.addexecute_minute = nil
delete(m.clearedFields, cptask.FieldExecuteMinute)
}
// SetNextExecuteTime sets the "next_execute_time" field.
func (m *CpTaskMutation) SetNextExecuteTime(i int64) {
m.next_execute_time = &i
m.addnext_execute_time = nil
}
// NextExecuteTime returns the value of the "next_execute_time" field in the mutation.
func (m *CpTaskMutation) NextExecuteTime() (r int64, exists bool) {
v := m.next_execute_time
if v == nil {
return
}
return *v, true
}
// OldNextExecuteTime returns the old "next_execute_time" field's value of the CpTask entity.
// If the CpTask 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 *CpTaskMutation) OldNextExecuteTime(ctx context.Context) (v *int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldNextExecuteTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldNextExecuteTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldNextExecuteTime: %w", err)
}
return oldValue.NextExecuteTime, nil
}
// AddNextExecuteTime adds i to the "next_execute_time" field.
func (m *CpTaskMutation) AddNextExecuteTime(i int64) {
if m.addnext_execute_time != nil {
*m.addnext_execute_time += i
} else {
m.addnext_execute_time = &i
}
}
// AddedNextExecuteTime returns the value that was added to the "next_execute_time" field in this mutation.
func (m *CpTaskMutation) AddedNextExecuteTime() (r int64, exists bool) {
v := m.addnext_execute_time
if v == nil {
return
}
return *v, true
}
// ClearNextExecuteTime clears the value of the "next_execute_time" field.
func (m *CpTaskMutation) ClearNextExecuteTime() {
m.next_execute_time = nil
m.addnext_execute_time = nil
m.clearedFields[cptask.FieldNextExecuteTime] = struct{}{}
}
// NextExecuteTimeCleared returns if the "next_execute_time" field was cleared in this mutation.
func (m *CpTaskMutation) NextExecuteTimeCleared() bool {
_, ok := m.clearedFields[cptask.FieldNextExecuteTime]
return ok
}
// ResetNextExecuteTime resets all changes to the "next_execute_time" field.
func (m *CpTaskMutation) ResetNextExecuteTime() {
m.next_execute_time = nil
m.addnext_execute_time = nil
delete(m.clearedFields, cptask.FieldNextExecuteTime)
}
// ClearCpUser clears the "cp_user" edge to the CpUser entity.
func (m *CpTaskMutation) ClearCpUser() {
m.clearedcp_user = true
m.clearedFields[cptask.FieldCpUserID] = struct{}{}
}
// CpUserCleared reports if the "cp_user" edge to the CpUser entity was cleared.
func (m *CpTaskMutation) CpUserCleared() bool {
return m.clearedcp_user
}
// CpUserIDs returns the "cp_user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// CpUserID instead. It exists only for internal usage by the builders.
func (m *CpTaskMutation) CpUserIDs() (ids []int64) {
if id := m.cp_user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetCpUser resets all changes to the "cp_user" edge.
func (m *CpTaskMutation) ResetCpUser() {
m.cp_user = nil
m.clearedcp_user = false
}
// SetSysUserID sets the "sys_user" edge to the SysUser entity by id.
func (m *CpTaskMutation) SetSysUserID(id int64) {
m.sys_user = &id
}
// ClearSysUser clears the "sys_user" edge to the SysUser entity.
func (m *CpTaskMutation) ClearSysUser() {
m.clearedsys_user = true
m.clearedFields[cptask.FieldUserID] = struct{}{}
}
// SysUserCleared reports if the "sys_user" edge to the SysUser entity was cleared.
func (m *CpTaskMutation) SysUserCleared() bool {
return m.clearedsys_user
}
// SysUserID returns the "sys_user" edge ID in the mutation.
func (m *CpTaskMutation) SysUserID() (id int64, exists bool) {
if m.sys_user != nil {
return *m.sys_user, true
}
return
}
// SysUserIDs returns the "sys_user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// SysUserID instead. It exists only for internal usage by the builders.
func (m *CpTaskMutation) SysUserIDs() (ids []int64) {
if id := m.sys_user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetSysUser resets all changes to the "sys_user" edge.
func (m *CpTaskMutation) ResetSysUser() {
m.sys_user = nil
m.clearedsys_user = false
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by ids.
func (m *CpTaskMutation) AddCpTaskLogIDs(ids ...int64) {
if m.cp_task_logs == nil {
m.cp_task_logs = make(map[int64]struct{})
}
for i := range ids {
m.cp_task_logs[ids[i]] = struct{}{}
}
}
// ClearCpTaskLogs clears the "cp_task_logs" edge to the CpTaskLog entity.
func (m *CpTaskMutation) ClearCpTaskLogs() {
m.clearedcp_task_logs = true
}
// CpTaskLogsCleared reports if the "cp_task_logs" edge to the CpTaskLog entity was cleared.
func (m *CpTaskMutation) CpTaskLogsCleared() bool {
return m.clearedcp_task_logs
}
// RemoveCpTaskLogIDs removes the "cp_task_logs" edge to the CpTaskLog entity by IDs.
func (m *CpTaskMutation) RemoveCpTaskLogIDs(ids ...int64) {
if m.removedcp_task_logs == nil {
m.removedcp_task_logs = make(map[int64]struct{})
}
for i := range ids {
delete(m.cp_task_logs, ids[i])
m.removedcp_task_logs[ids[i]] = struct{}{}
}
}
// RemovedCpTaskLogs returns the removed IDs of the "cp_task_logs" edge to the CpTaskLog entity.
func (m *CpTaskMutation) RemovedCpTaskLogsIDs() (ids []int64) {
for id := range m.removedcp_task_logs {
ids = append(ids, id)
}
return
}
// CpTaskLogsIDs returns the "cp_task_logs" edge IDs in the mutation.
func (m *CpTaskMutation) CpTaskLogsIDs() (ids []int64) {
for id := range m.cp_task_logs {
ids = append(ids, id)
}
return
}
// ResetCpTaskLogs resets all changes to the "cp_task_logs" edge.
func (m *CpTaskMutation) ResetCpTaskLogs() {
m.cp_task_logs = nil
m.clearedcp_task_logs = false
m.removedcp_task_logs = nil
}
// Where appends a list predicates to the CpTaskMutation builder.
func (m *CpTaskMutation) Where(ps ...predicate.CpTask) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the CpTaskMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *CpTaskMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.CpTask, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *CpTaskMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *CpTaskMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (CpTask).
func (m *CpTaskMutation) 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 *CpTaskMutation) Fields() []string {
fields := make([]string, 0, 15)
if m.create_time != nil {
fields = append(fields, cptask.FieldCreateTime)
}
if m.update_time != nil {
fields = append(fields, cptask.FieldUpdateTime)
}
if m.cp_user != nil {
fields = append(fields, cptask.FieldCpUserID)
}
if m.sys_user != nil {
fields = append(fields, cptask.FieldUserID)
}
if m.task_type != nil {
fields = append(fields, cptask.FieldTaskType)
}
if m.title != nil {
fields = append(fields, cptask.FieldTitle)
}
if m.frequency != nil {
fields = append(fields, cptask.FieldFrequency)
}
if m.task_status != nil {
fields = append(fields, cptask.FieldTaskStatus)
}
if m.success_count != nil {
fields = append(fields, cptask.FieldSuccessCount)
}
if m.form_data != nil {
fields = append(fields, cptask.FieldFormData)
}
if m.step != nil {
fields = append(fields, cptask.FieldStep)
}
if m.notification_type != nil {
fields = append(fields, cptask.FieldNotificationType)
}
if m.execute_hour != nil {
fields = append(fields, cptask.FieldExecuteHour)
}
if m.execute_minute != nil {
fields = append(fields, cptask.FieldExecuteMinute)
}
if m.next_execute_time != nil {
fields = append(fields, cptask.FieldNextExecuteTime)
}
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 *CpTaskMutation) Field(name string) (ent.Value, bool) {
switch name {
case cptask.FieldCreateTime:
return m.CreateTime()
case cptask.FieldUpdateTime:
return m.UpdateTime()
case cptask.FieldCpUserID:
return m.CpUserID()
case cptask.FieldUserID:
return m.UserID()
case cptask.FieldTaskType:
return m.TaskType()
case cptask.FieldTitle:
return m.Title()
case cptask.FieldFrequency:
return m.Frequency()
case cptask.FieldTaskStatus:
return m.TaskStatus()
case cptask.FieldSuccessCount:
return m.SuccessCount()
case cptask.FieldFormData:
return m.FormData()
case cptask.FieldStep:
return m.Step()
case cptask.FieldNotificationType:
return m.NotificationType()
case cptask.FieldExecuteHour:
return m.ExecuteHour()
case cptask.FieldExecuteMinute:
return m.ExecuteMinute()
case cptask.FieldNextExecuteTime:
return m.NextExecuteTime()
}
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 *CpTaskMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case cptask.FieldCreateTime:
return m.OldCreateTime(ctx)
case cptask.FieldUpdateTime:
return m.OldUpdateTime(ctx)
case cptask.FieldCpUserID:
return m.OldCpUserID(ctx)
case cptask.FieldUserID:
return m.OldUserID(ctx)
case cptask.FieldTaskType:
return m.OldTaskType(ctx)
case cptask.FieldTitle:
return m.OldTitle(ctx)
case cptask.FieldFrequency:
return m.OldFrequency(ctx)
case cptask.FieldTaskStatus:
return m.OldTaskStatus(ctx)
case cptask.FieldSuccessCount:
return m.OldSuccessCount(ctx)
case cptask.FieldFormData:
return m.OldFormData(ctx)
case cptask.FieldStep:
return m.OldStep(ctx)
case cptask.FieldNotificationType:
return m.OldNotificationType(ctx)
case cptask.FieldExecuteHour:
return m.OldExecuteHour(ctx)
case cptask.FieldExecuteMinute:
return m.OldExecuteMinute(ctx)
case cptask.FieldNextExecuteTime:
return m.OldNextExecuteTime(ctx)
}
return nil, fmt.Errorf("unknown CpTask 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 *CpTaskMutation) SetField(name string, value ent.Value) error {
switch name {
case cptask.FieldCreateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil
case cptask.FieldUpdateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdateTime(v)
return nil
case cptask.FieldCpUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCpUserID(v)
return nil
case cptask.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUserID(v)
return nil
case cptask.FieldTaskType:
v, ok := value.(cptask.TaskType)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTaskType(v)
return nil
case cptask.FieldTitle:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTitle(v)
return nil
case cptask.FieldFrequency:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetFrequency(v)
return nil
case cptask.FieldTaskStatus:
v, ok := value.(cptask.TaskStatus)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTaskStatus(v)
return nil
case cptask.FieldSuccessCount:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSuccessCount(v)
return nil
case cptask.FieldFormData:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetFormData(v)
return nil
case cptask.FieldStep:
v, ok := value.(cptask.Step)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetStep(v)
return nil
case cptask.FieldNotificationType:
v, ok := value.(cptask.NotificationType)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetNotificationType(v)
return nil
case cptask.FieldExecuteHour:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetExecuteHour(v)
return nil
case cptask.FieldExecuteMinute:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetExecuteMinute(v)
return nil
case cptask.FieldNextExecuteTime:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetNextExecuteTime(v)
return nil
}
return fmt.Errorf("unknown CpTask field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *CpTaskMutation) AddedFields() []string {
var fields []string
if m.addfrequency != nil {
fields = append(fields, cptask.FieldFrequency)
}
if m.addsuccess_count != nil {
fields = append(fields, cptask.FieldSuccessCount)
}
if m.addexecute_hour != nil {
fields = append(fields, cptask.FieldExecuteHour)
}
if m.addexecute_minute != nil {
fields = append(fields, cptask.FieldExecuteMinute)
}
if m.addnext_execute_time != nil {
fields = append(fields, cptask.FieldNextExecuteTime)
}
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 *CpTaskMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case cptask.FieldFrequency:
return m.AddedFrequency()
case cptask.FieldSuccessCount:
return m.AddedSuccessCount()
case cptask.FieldExecuteHour:
return m.AddedExecuteHour()
case cptask.FieldExecuteMinute:
return m.AddedExecuteMinute()
case cptask.FieldNextExecuteTime:
return m.AddedNextExecuteTime()
}
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 *CpTaskMutation) AddField(name string, value ent.Value) error {
switch name {
case cptask.FieldFrequency:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddFrequency(v)
return nil
case cptask.FieldSuccessCount:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddSuccessCount(v)
return nil
case cptask.FieldExecuteHour:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddExecuteHour(v)
return nil
case cptask.FieldExecuteMinute:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddExecuteMinute(v)
return nil
case cptask.FieldNextExecuteTime:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddNextExecuteTime(v)
return nil
}
return fmt.Errorf("unknown CpTask numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *CpTaskMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(cptask.FieldFormData) {
fields = append(fields, cptask.FieldFormData)
}
if m.FieldCleared(cptask.FieldExecuteHour) {
fields = append(fields, cptask.FieldExecuteHour)
}
if m.FieldCleared(cptask.FieldExecuteMinute) {
fields = append(fields, cptask.FieldExecuteMinute)
}
if m.FieldCleared(cptask.FieldNextExecuteTime) {
fields = append(fields, cptask.FieldNextExecuteTime)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *CpTaskMutation) 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 *CpTaskMutation) ClearField(name string) error {
switch name {
case cptask.FieldFormData:
m.ClearFormData()
return nil
case cptask.FieldExecuteHour:
m.ClearExecuteHour()
return nil
case cptask.FieldExecuteMinute:
m.ClearExecuteMinute()
return nil
case cptask.FieldNextExecuteTime:
m.ClearNextExecuteTime()
return nil
}
return fmt.Errorf("unknown CpTask 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 *CpTaskMutation) ResetField(name string) error {
switch name {
case cptask.FieldCreateTime:
m.ResetCreateTime()
return nil
case cptask.FieldUpdateTime:
m.ResetUpdateTime()
return nil
case cptask.FieldCpUserID:
m.ResetCpUserID()
return nil
case cptask.FieldUserID:
m.ResetUserID()
return nil
case cptask.FieldTaskType:
m.ResetTaskType()
return nil
case cptask.FieldTitle:
m.ResetTitle()
return nil
case cptask.FieldFrequency:
m.ResetFrequency()
return nil
case cptask.FieldTaskStatus:
m.ResetTaskStatus()
return nil
case cptask.FieldSuccessCount:
m.ResetSuccessCount()
return nil
case cptask.FieldFormData:
m.ResetFormData()
return nil
case cptask.FieldStep:
m.ResetStep()
return nil
case cptask.FieldNotificationType:
m.ResetNotificationType()
return nil
case cptask.FieldExecuteHour:
m.ResetExecuteHour()
return nil
case cptask.FieldExecuteMinute:
m.ResetExecuteMinute()
return nil
case cptask.FieldNextExecuteTime:
m.ResetNextExecuteTime()
return nil
}
return fmt.Errorf("unknown CpTask field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CpTaskMutation) AddedEdges() []string {
edges := make([]string, 0, 3)
if m.cp_user != nil {
edges = append(edges, cptask.EdgeCpUser)
}
if m.sys_user != nil {
edges = append(edges, cptask.EdgeSysUser)
}
if m.cp_task_logs != nil {
edges = append(edges, cptask.EdgeCpTaskLogs)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *CpTaskMutation) AddedIDs(name string) []ent.Value {
switch name {
case cptask.EdgeCpUser:
if id := m.cp_user; id != nil {
return []ent.Value{*id}
}
case cptask.EdgeSysUser:
if id := m.sys_user; id != nil {
return []ent.Value{*id}
}
case cptask.EdgeCpTaskLogs:
ids := make([]ent.Value, 0, len(m.cp_task_logs))
for id := range m.cp_task_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *CpTaskMutation) RemovedEdges() []string {
edges := make([]string, 0, 3)
if m.removedcp_task_logs != nil {
edges = append(edges, cptask.EdgeCpTaskLogs)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *CpTaskMutation) RemovedIDs(name string) []ent.Value {
switch name {
case cptask.EdgeCpTaskLogs:
ids := make([]ent.Value, 0, len(m.removedcp_task_logs))
for id := range m.removedcp_task_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CpTaskMutation) ClearedEdges() []string {
edges := make([]string, 0, 3)
if m.clearedcp_user {
edges = append(edges, cptask.EdgeCpUser)
}
if m.clearedsys_user {
edges = append(edges, cptask.EdgeSysUser)
}
if m.clearedcp_task_logs {
edges = append(edges, cptask.EdgeCpTaskLogs)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *CpTaskMutation) EdgeCleared(name string) bool {
switch name {
case cptask.EdgeCpUser:
return m.clearedcp_user
case cptask.EdgeSysUser:
return m.clearedsys_user
case cptask.EdgeCpTaskLogs:
return m.clearedcp_task_logs
}
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 *CpTaskMutation) ClearEdge(name string) error {
switch name {
case cptask.EdgeCpUser:
m.ClearCpUser()
return nil
case cptask.EdgeSysUser:
m.ClearSysUser()
return nil
}
return fmt.Errorf("unknown CpTask 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 *CpTaskMutation) ResetEdge(name string) error {
switch name {
case cptask.EdgeCpUser:
m.ResetCpUser()
return nil
case cptask.EdgeSysUser:
m.ResetSysUser()
return nil
case cptask.EdgeCpTaskLogs:
m.ResetCpTaskLogs()
return nil
}
return fmt.Errorf("unknown CpTask edge %s", name)
}
// CpTaskLogMutation represents an operation that mutates the CpTaskLog nodes in the graph.
type CpTaskLogMutation struct {
config
op Op
typ string
id *int64
create_time **ent2.CustomTime
update_time **ent2.CustomTime
is_success *bool
error_message *string
real_name *string
clearedFields map[string]struct{}
cp_task *int64
clearedcp_task bool
system_user *int64
clearedsystem_user bool
cp_user *int64
clearedcp_user bool
done bool
oldValue func(context.Context) (*CpTaskLog, error)
predicates []predicate.CpTaskLog
}
var _ ent.Mutation = (*CpTaskLogMutation)(nil)
// cptasklogOption allows management of the mutation configuration using functional options.
type cptasklogOption func(*CpTaskLogMutation)
// newCpTaskLogMutation creates new mutation for the CpTaskLog entity.
func newCpTaskLogMutation(c config, op Op, opts ...cptasklogOption) *CpTaskLogMutation {
m := &CpTaskLogMutation{
config: c,
op: op,
typ: TypeCpTaskLog,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withCpTaskLogID sets the ID field of the mutation.
func withCpTaskLogID(id int64) cptasklogOption {
return func(m *CpTaskLogMutation) {
var (
err error
once sync.Once
value *CpTaskLog
)
m.oldValue = func(ctx context.Context) (*CpTaskLog, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().CpTaskLog.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withCpTaskLog sets the old CpTaskLog of the mutation.
func withCpTaskLog(node *CpTaskLog) cptasklogOption {
return func(m *CpTaskLogMutation) {
m.oldValue = func(context.Context) (*CpTaskLog, 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 CpTaskLogMutation) 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 CpTaskLogMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *CpTaskLogMutation) ID() (id int64, 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 *CpTaskLogMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().CpTaskLog.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreateTime sets the "create_time" field.
func (m *CpTaskLogMutation) SetCreateTime(et *ent2.CustomTime) {
m.create_time = &et
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *CpTaskLogMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the CpTaskLog entity.
// If the CpTaskLog 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 *CpTaskLogMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *CpTaskLogMutation) ResetCreateTime() {
m.create_time = nil
}
// SetUpdateTime sets the "update_time" field.
func (m *CpTaskLogMutation) SetUpdateTime(et *ent2.CustomTime) {
m.update_time = &et
}
// UpdateTime returns the value of the "update_time" field in the mutation.
func (m *CpTaskLogMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
v := m.update_time
if v == nil {
return
}
return *v, true
}
// OldUpdateTime returns the old "update_time" field's value of the CpTaskLog entity.
// If the CpTaskLog 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 *CpTaskLogMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
}
return oldValue.UpdateTime, nil
}
// ResetUpdateTime resets all changes to the "update_time" field.
func (m *CpTaskLogMutation) ResetUpdateTime() {
m.update_time = nil
}
// SetCpTaskID sets the "cp_task_id" field.
func (m *CpTaskLogMutation) SetCpTaskID(i int64) {
m.cp_task = &i
}
// CpTaskID returns the value of the "cp_task_id" field in the mutation.
func (m *CpTaskLogMutation) CpTaskID() (r int64, exists bool) {
v := m.cp_task
if v == nil {
return
}
return *v, true
}
// OldCpTaskID returns the old "cp_task_id" field's value of the CpTaskLog entity.
// If the CpTaskLog 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 *CpTaskLogMutation) OldCpTaskID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCpTaskID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCpTaskID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCpTaskID: %w", err)
}
return oldValue.CpTaskID, nil
}
// ResetCpTaskID resets all changes to the "cp_task_id" field.
func (m *CpTaskLogMutation) ResetCpTaskID() {
m.cp_task = nil
}
// SetSystemUserID sets the "system_user_id" field.
func (m *CpTaskLogMutation) SetSystemUserID(i int64) {
m.system_user = &i
}
// SystemUserID returns the value of the "system_user_id" field in the mutation.
func (m *CpTaskLogMutation) SystemUserID() (r int64, exists bool) {
v := m.system_user
if v == nil {
return
}
return *v, true
}
// OldSystemUserID returns the old "system_user_id" field's value of the CpTaskLog entity.
// If the CpTaskLog 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 *CpTaskLogMutation) OldSystemUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSystemUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSystemUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSystemUserID: %w", err)
}
return oldValue.SystemUserID, nil
}
// ResetSystemUserID resets all changes to the "system_user_id" field.
func (m *CpTaskLogMutation) ResetSystemUserID() {
m.system_user = nil
}
// SetCpUserID sets the "cp_user_id" field.
func (m *CpTaskLogMutation) SetCpUserID(i int64) {
m.cp_user = &i
}
// CpUserID returns the value of the "cp_user_id" field in the mutation.
func (m *CpTaskLogMutation) CpUserID() (r int64, exists bool) {
v := m.cp_user
if v == nil {
return
}
return *v, true
}
// OldCpUserID returns the old "cp_user_id" field's value of the CpTaskLog entity.
// If the CpTaskLog 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 *CpTaskLogMutation) OldCpUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCpUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCpUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCpUserID: %w", err)
}
return oldValue.CpUserID, nil
}
// ResetCpUserID resets all changes to the "cp_user_id" field.
func (m *CpTaskLogMutation) ResetCpUserID() {
m.cp_user = nil
}
// SetIsSuccess sets the "is_success" field.
func (m *CpTaskLogMutation) SetIsSuccess(b bool) {
m.is_success = &b
}
// IsSuccess returns the value of the "is_success" field in the mutation.
func (m *CpTaskLogMutation) IsSuccess() (r bool, exists bool) {
v := m.is_success
if v == nil {
return
}
return *v, true
}
// OldIsSuccess returns the old "is_success" field's value of the CpTaskLog entity.
// If the CpTaskLog 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 *CpTaskLogMutation) OldIsSuccess(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIsSuccess is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIsSuccess requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIsSuccess: %w", err)
}
return oldValue.IsSuccess, nil
}
// ResetIsSuccess resets all changes to the "is_success" field.
func (m *CpTaskLogMutation) ResetIsSuccess() {
m.is_success = nil
}
// SetErrorMessage sets the "error_message" field.
func (m *CpTaskLogMutation) SetErrorMessage(s string) {
m.error_message = &s
}
// ErrorMessage returns the value of the "error_message" field in the mutation.
func (m *CpTaskLogMutation) ErrorMessage() (r string, exists bool) {
v := m.error_message
if v == nil {
return
}
return *v, true
}
// OldErrorMessage returns the old "error_message" field's value of the CpTaskLog entity.
// If the CpTaskLog 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 *CpTaskLogMutation) OldErrorMessage(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldErrorMessage is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldErrorMessage requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldErrorMessage: %w", err)
}
return oldValue.ErrorMessage, nil
}
// ClearErrorMessage clears the value of the "error_message" field.
func (m *CpTaskLogMutation) ClearErrorMessage() {
m.error_message = nil
m.clearedFields[cptasklog.FieldErrorMessage] = struct{}{}
}
// ErrorMessageCleared returns if the "error_message" field was cleared in this mutation.
func (m *CpTaskLogMutation) ErrorMessageCleared() bool {
_, ok := m.clearedFields[cptasklog.FieldErrorMessage]
return ok
}
// ResetErrorMessage resets all changes to the "error_message" field.
func (m *CpTaskLogMutation) ResetErrorMessage() {
m.error_message = nil
delete(m.clearedFields, cptasklog.FieldErrorMessage)
}
// SetRealName sets the "real_name" field.
func (m *CpTaskLogMutation) SetRealName(s string) {
m.real_name = &s
}
// RealName returns the value of the "real_name" field in the mutation.
func (m *CpTaskLogMutation) RealName() (r string, exists bool) {
v := m.real_name
if v == nil {
return
}
return *v, true
}
// OldRealName returns the old "real_name" field's value of the CpTaskLog entity.
// If the CpTaskLog 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 *CpTaskLogMutation) OldRealName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRealName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRealName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRealName: %w", err)
}
return oldValue.RealName, nil
}
// ClearRealName clears the value of the "real_name" field.
func (m *CpTaskLogMutation) ClearRealName() {
m.real_name = nil
m.clearedFields[cptasklog.FieldRealName] = struct{}{}
}
// RealNameCleared returns if the "real_name" field was cleared in this mutation.
func (m *CpTaskLogMutation) RealNameCleared() bool {
_, ok := m.clearedFields[cptasklog.FieldRealName]
return ok
}
// ResetRealName resets all changes to the "real_name" field.
func (m *CpTaskLogMutation) ResetRealName() {
m.real_name = nil
delete(m.clearedFields, cptasklog.FieldRealName)
}
// ClearCpTask clears the "cp_task" edge to the CpTask entity.
func (m *CpTaskLogMutation) ClearCpTask() {
m.clearedcp_task = true
m.clearedFields[cptasklog.FieldCpTaskID] = struct{}{}
}
// CpTaskCleared reports if the "cp_task" edge to the CpTask entity was cleared.
func (m *CpTaskLogMutation) CpTaskCleared() bool {
return m.clearedcp_task
}
// CpTaskIDs returns the "cp_task" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// CpTaskID instead. It exists only for internal usage by the builders.
func (m *CpTaskLogMutation) CpTaskIDs() (ids []int64) {
if id := m.cp_task; id != nil {
ids = append(ids, *id)
}
return
}
// ResetCpTask resets all changes to the "cp_task" edge.
func (m *CpTaskLogMutation) ResetCpTask() {
m.cp_task = nil
m.clearedcp_task = false
}
// ClearSystemUser clears the "system_user" edge to the SysUser entity.
func (m *CpTaskLogMutation) ClearSystemUser() {
m.clearedsystem_user = true
m.clearedFields[cptasklog.FieldSystemUserID] = struct{}{}
}
// SystemUserCleared reports if the "system_user" edge to the SysUser entity was cleared.
func (m *CpTaskLogMutation) SystemUserCleared() bool {
return m.clearedsystem_user
}
// SystemUserIDs returns the "system_user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// SystemUserID instead. It exists only for internal usage by the builders.
func (m *CpTaskLogMutation) SystemUserIDs() (ids []int64) {
if id := m.system_user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetSystemUser resets all changes to the "system_user" edge.
func (m *CpTaskLogMutation) ResetSystemUser() {
m.system_user = nil
m.clearedsystem_user = false
}
// ClearCpUser clears the "cp_user" edge to the CpUser entity.
func (m *CpTaskLogMutation) ClearCpUser() {
m.clearedcp_user = true
m.clearedFields[cptasklog.FieldCpUserID] = struct{}{}
}
// CpUserCleared reports if the "cp_user" edge to the CpUser entity was cleared.
func (m *CpTaskLogMutation) CpUserCleared() bool {
return m.clearedcp_user
}
// CpUserIDs returns the "cp_user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// CpUserID instead. It exists only for internal usage by the builders.
func (m *CpTaskLogMutation) CpUserIDs() (ids []int64) {
if id := m.cp_user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetCpUser resets all changes to the "cp_user" edge.
func (m *CpTaskLogMutation) ResetCpUser() {
m.cp_user = nil
m.clearedcp_user = false
}
// Where appends a list predicates to the CpTaskLogMutation builder.
func (m *CpTaskLogMutation) Where(ps ...predicate.CpTaskLog) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the CpTaskLogMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *CpTaskLogMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.CpTaskLog, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *CpTaskLogMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *CpTaskLogMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (CpTaskLog).
func (m *CpTaskLogMutation) 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 *CpTaskLogMutation) Fields() []string {
fields := make([]string, 0, 8)
if m.create_time != nil {
fields = append(fields, cptasklog.FieldCreateTime)
}
if m.update_time != nil {
fields = append(fields, cptasklog.FieldUpdateTime)
}
if m.cp_task != nil {
fields = append(fields, cptasklog.FieldCpTaskID)
}
if m.system_user != nil {
fields = append(fields, cptasklog.FieldSystemUserID)
}
if m.cp_user != nil {
fields = append(fields, cptasklog.FieldCpUserID)
}
if m.is_success != nil {
fields = append(fields, cptasklog.FieldIsSuccess)
}
if m.error_message != nil {
fields = append(fields, cptasklog.FieldErrorMessage)
}
if m.real_name != nil {
fields = append(fields, cptasklog.FieldRealName)
}
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 *CpTaskLogMutation) Field(name string) (ent.Value, bool) {
switch name {
case cptasklog.FieldCreateTime:
return m.CreateTime()
case cptasklog.FieldUpdateTime:
return m.UpdateTime()
case cptasklog.FieldCpTaskID:
return m.CpTaskID()
case cptasklog.FieldSystemUserID:
return m.SystemUserID()
case cptasklog.FieldCpUserID:
return m.CpUserID()
case cptasklog.FieldIsSuccess:
return m.IsSuccess()
case cptasklog.FieldErrorMessage:
return m.ErrorMessage()
case cptasklog.FieldRealName:
return m.RealName()
}
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 *CpTaskLogMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case cptasklog.FieldCreateTime:
return m.OldCreateTime(ctx)
case cptasklog.FieldUpdateTime:
return m.OldUpdateTime(ctx)
case cptasklog.FieldCpTaskID:
return m.OldCpTaskID(ctx)
case cptasklog.FieldSystemUserID:
return m.OldSystemUserID(ctx)
case cptasklog.FieldCpUserID:
return m.OldCpUserID(ctx)
case cptasklog.FieldIsSuccess:
return m.OldIsSuccess(ctx)
case cptasklog.FieldErrorMessage:
return m.OldErrorMessage(ctx)
case cptasklog.FieldRealName:
return m.OldRealName(ctx)
}
return nil, fmt.Errorf("unknown CpTaskLog 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 *CpTaskLogMutation) SetField(name string, value ent.Value) error {
switch name {
case cptasklog.FieldCreateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil
case cptasklog.FieldUpdateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdateTime(v)
return nil
case cptasklog.FieldCpTaskID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCpTaskID(v)
return nil
case cptasklog.FieldSystemUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSystemUserID(v)
return nil
case cptasklog.FieldCpUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCpUserID(v)
return nil
case cptasklog.FieldIsSuccess:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIsSuccess(v)
return nil
case cptasklog.FieldErrorMessage:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetErrorMessage(v)
return nil
case cptasklog.FieldRealName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRealName(v)
return nil
}
return fmt.Errorf("unknown CpTaskLog field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *CpTaskLogMutation) AddedFields() []string {
var fields []string
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 *CpTaskLogMutation) AddedField(name string) (ent.Value, bool) {
switch name {
}
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 *CpTaskLogMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown CpTaskLog numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *CpTaskLogMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(cptasklog.FieldErrorMessage) {
fields = append(fields, cptasklog.FieldErrorMessage)
}
if m.FieldCleared(cptasklog.FieldRealName) {
fields = append(fields, cptasklog.FieldRealName)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *CpTaskLogMutation) 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 *CpTaskLogMutation) ClearField(name string) error {
switch name {
case cptasklog.FieldErrorMessage:
m.ClearErrorMessage()
return nil
case cptasklog.FieldRealName:
m.ClearRealName()
return nil
}
return fmt.Errorf("unknown CpTaskLog 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 *CpTaskLogMutation) ResetField(name string) error {
switch name {
case cptasklog.FieldCreateTime:
m.ResetCreateTime()
return nil
case cptasklog.FieldUpdateTime:
m.ResetUpdateTime()
return nil
case cptasklog.FieldCpTaskID:
m.ResetCpTaskID()
return nil
case cptasklog.FieldSystemUserID:
m.ResetSystemUserID()
return nil
case cptasklog.FieldCpUserID:
m.ResetCpUserID()
return nil
case cptasklog.FieldIsSuccess:
m.ResetIsSuccess()
return nil
case cptasklog.FieldErrorMessage:
m.ResetErrorMessage()
return nil
case cptasklog.FieldRealName:
m.ResetRealName()
return nil
}
return fmt.Errorf("unknown CpTaskLog field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CpTaskLogMutation) AddedEdges() []string {
edges := make([]string, 0, 3)
if m.cp_task != nil {
edges = append(edges, cptasklog.EdgeCpTask)
}
if m.system_user != nil {
edges = append(edges, cptasklog.EdgeSystemUser)
}
if m.cp_user != nil {
edges = append(edges, cptasklog.EdgeCpUser)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *CpTaskLogMutation) AddedIDs(name string) []ent.Value {
switch name {
case cptasklog.EdgeCpTask:
if id := m.cp_task; id != nil {
return []ent.Value{*id}
}
case cptasklog.EdgeSystemUser:
if id := m.system_user; id != nil {
return []ent.Value{*id}
}
case cptasklog.EdgeCpUser:
if id := m.cp_user; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *CpTaskLogMutation) RemovedEdges() []string {
edges := make([]string, 0, 3)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *CpTaskLogMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CpTaskLogMutation) ClearedEdges() []string {
edges := make([]string, 0, 3)
if m.clearedcp_task {
edges = append(edges, cptasklog.EdgeCpTask)
}
if m.clearedsystem_user {
edges = append(edges, cptasklog.EdgeSystemUser)
}
if m.clearedcp_user {
edges = append(edges, cptasklog.EdgeCpUser)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *CpTaskLogMutation) EdgeCleared(name string) bool {
switch name {
case cptasklog.EdgeCpTask:
return m.clearedcp_task
case cptasklog.EdgeSystemUser:
return m.clearedsystem_user
case cptasklog.EdgeCpUser:
return m.clearedcp_user
}
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 *CpTaskLogMutation) ClearEdge(name string) error {
switch name {
case cptasklog.EdgeCpTask:
m.ClearCpTask()
return nil
case cptasklog.EdgeSystemUser:
m.ClearSystemUser()
return nil
case cptasklog.EdgeCpUser:
m.ClearCpUser()
return nil
}
return fmt.Errorf("unknown CpTaskLog 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 *CpTaskLogMutation) ResetEdge(name string) error {
switch name {
case cptasklog.EdgeCpTask:
m.ResetCpTask()
return nil
case cptasklog.EdgeSystemUser:
m.ResetSystemUser()
return nil
case cptasklog.EdgeCpUser:
m.ResetCpUser()
return nil
}
return fmt.Errorf("unknown CpTaskLog edge %s", name)
}
// CpUserMutation represents an operation that mutates the CpUser nodes in the graph.
type CpUserMutation struct {
config
op Op
typ string
id *int64
create_time **ent2.CustomTime
update_time **ent2.CustomTime
username *string
password *string
email *string
mobile_code *string
cookie *string
mobile_type *cpuser.MobileType
clearedFields map[string]struct{}
cptasks map[int64]struct{}
removedcptasks map[int64]struct{}
clearedcptasks bool
sysuser *int64
clearedsysuser bool
cp_task_logs map[int64]struct{}
removedcp_task_logs map[int64]struct{}
clearedcp_task_logs bool
school *string
clearedschool bool
done bool
oldValue func(context.Context) (*CpUser, error)
predicates []predicate.CpUser
}
var _ ent.Mutation = (*CpUserMutation)(nil)
// cpuserOption allows management of the mutation configuration using functional options.
type cpuserOption func(*CpUserMutation)
// newCpUserMutation creates new mutation for the CpUser entity.
func newCpUserMutation(c config, op Op, opts ...cpuserOption) *CpUserMutation {
m := &CpUserMutation{
config: c,
op: op,
typ: TypeCpUser,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withCpUserID sets the ID field of the mutation.
func withCpUserID(id int64) cpuserOption {
return func(m *CpUserMutation) {
var (
err error
once sync.Once
value *CpUser
)
m.oldValue = func(ctx context.Context) (*CpUser, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().CpUser.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withCpUser sets the old CpUser of the mutation.
func withCpUser(node *CpUser) cpuserOption {
return func(m *CpUserMutation) {
m.oldValue = func(context.Context) (*CpUser, 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 CpUserMutation) 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 CpUserMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *CpUserMutation) ID() (id int64, 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 *CpUserMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().CpUser.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreateTime sets the "create_time" field.
func (m *CpUserMutation) SetCreateTime(et *ent2.CustomTime) {
m.create_time = &et
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *CpUserMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the CpUser entity.
// If the CpUser 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 *CpUserMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *CpUserMutation) ResetCreateTime() {
m.create_time = nil
}
// SetUpdateTime sets the "update_time" field.
func (m *CpUserMutation) SetUpdateTime(et *ent2.CustomTime) {
m.update_time = &et
}
// UpdateTime returns the value of the "update_time" field in the mutation.
func (m *CpUserMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
v := m.update_time
if v == nil {
return
}
return *v, true
}
// OldUpdateTime returns the old "update_time" field's value of the CpUser entity.
// If the CpUser 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 *CpUserMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
}
return oldValue.UpdateTime, nil
}
// ResetUpdateTime resets all changes to the "update_time" field.
func (m *CpUserMutation) ResetUpdateTime() {
m.update_time = nil
}
// SetUserID sets the "user_id" field.
func (m *CpUserMutation) SetUserID(i int64) {
m.sysuser = &i
}
// UserID returns the value of the "user_id" field in the mutation.
func (m *CpUserMutation) UserID() (r int64, exists bool) {
v := m.sysuser
if v == nil {
return
}
return *v, true
}
// OldUserID returns the old "user_id" field's value of the CpUser entity.
// If the CpUser 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 *CpUserMutation) OldUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
}
return oldValue.UserID, nil
}
// ResetUserID resets all changes to the "user_id" field.
func (m *CpUserMutation) ResetUserID() {
m.sysuser = nil
}
// SetUsername sets the "username" field.
func (m *CpUserMutation) SetUsername(s string) {
m.username = &s
}
// Username returns the value of the "username" field in the mutation.
func (m *CpUserMutation) 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 CpUser entity.
// If the CpUser 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 *CpUserMutation) 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 *CpUserMutation) ResetUsername() {
m.username = nil
}
// SetPassword sets the "password" field.
func (m *CpUserMutation) SetPassword(s string) {
m.password = &s
}
// Password returns the value of the "password" field in the mutation.
func (m *CpUserMutation) 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 CpUser entity.
// If the CpUser 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 *CpUserMutation) 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 *CpUserMutation) ResetPassword() {
m.password = nil
}
// SetSchoolID sets the "school_id" field.
func (m *CpUserMutation) SetSchoolID(s string) {
m.school = &s
}
// SchoolID returns the value of the "school_id" field in the mutation.
func (m *CpUserMutation) SchoolID() (r string, exists bool) {
v := m.school
if v == nil {
return
}
return *v, true
}
// OldSchoolID returns the old "school_id" field's value of the CpUser entity.
// If the CpUser 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 *CpUserMutation) OldSchoolID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSchoolID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSchoolID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSchoolID: %w", err)
}
return oldValue.SchoolID, nil
}
// ResetSchoolID resets all changes to the "school_id" field.
func (m *CpUserMutation) ResetSchoolID() {
m.school = nil
}
// SetEmail sets the "email" field.
func (m *CpUserMutation) SetEmail(s string) {
m.email = &s
}
// Email returns the value of the "email" field in the mutation.
func (m *CpUserMutation) Email() (r string, exists bool) {
v := m.email
if v == nil {
return
}
return *v, true
}
// OldEmail returns the old "email" field's value of the CpUser entity.
// If the CpUser 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 *CpUserMutation) OldEmail(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldEmail is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldEmail requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldEmail: %w", err)
}
return oldValue.Email, nil
}
// ClearEmail clears the value of the "email" field.
func (m *CpUserMutation) ClearEmail() {
m.email = nil
m.clearedFields[cpuser.FieldEmail] = struct{}{}
}
// EmailCleared returns if the "email" field was cleared in this mutation.
func (m *CpUserMutation) EmailCleared() bool {
_, ok := m.clearedFields[cpuser.FieldEmail]
return ok
}
// ResetEmail resets all changes to the "email" field.
func (m *CpUserMutation) ResetEmail() {
m.email = nil
delete(m.clearedFields, cpuser.FieldEmail)
}
// SetMobileCode sets the "mobile_code" field.
func (m *CpUserMutation) SetMobileCode(s string) {
m.mobile_code = &s
}
// MobileCode returns the value of the "mobile_code" field in the mutation.
func (m *CpUserMutation) MobileCode() (r string, exists bool) {
v := m.mobile_code
if v == nil {
return
}
return *v, true
}
// OldMobileCode returns the old "mobile_code" field's value of the CpUser entity.
// If the CpUser 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 *CpUserMutation) OldMobileCode(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMobileCode is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMobileCode requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMobileCode: %w", err)
}
return oldValue.MobileCode, nil
}
// ClearMobileCode clears the value of the "mobile_code" field.
func (m *CpUserMutation) ClearMobileCode() {
m.mobile_code = nil
m.clearedFields[cpuser.FieldMobileCode] = struct{}{}
}
// MobileCodeCleared returns if the "mobile_code" field was cleared in this mutation.
func (m *CpUserMutation) MobileCodeCleared() bool {
_, ok := m.clearedFields[cpuser.FieldMobileCode]
return ok
}
// ResetMobileCode resets all changes to the "mobile_code" field.
func (m *CpUserMutation) ResetMobileCode() {
m.mobile_code = nil
delete(m.clearedFields, cpuser.FieldMobileCode)
}
// SetCookie sets the "cookie" field.
func (m *CpUserMutation) SetCookie(s string) {
m.cookie = &s
}
// Cookie returns the value of the "cookie" field in the mutation.
func (m *CpUserMutation) Cookie() (r string, exists bool) {
v := m.cookie
if v == nil {
return
}
return *v, true
}
// OldCookie returns the old "cookie" field's value of the CpUser entity.
// If the CpUser 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 *CpUserMutation) OldCookie(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCookie is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCookie requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCookie: %w", err)
}
return oldValue.Cookie, nil
}
// ClearCookie clears the value of the "cookie" field.
func (m *CpUserMutation) ClearCookie() {
m.cookie = nil
m.clearedFields[cpuser.FieldCookie] = struct{}{}
}
// CookieCleared returns if the "cookie" field was cleared in this mutation.
func (m *CpUserMutation) CookieCleared() bool {
_, ok := m.clearedFields[cpuser.FieldCookie]
return ok
}
// ResetCookie resets all changes to the "cookie" field.
func (m *CpUserMutation) ResetCookie() {
m.cookie = nil
delete(m.clearedFields, cpuser.FieldCookie)
}
// SetMobileType sets the "mobile_type" field.
func (m *CpUserMutation) SetMobileType(ct cpuser.MobileType) {
m.mobile_type = &ct
}
// MobileType returns the value of the "mobile_type" field in the mutation.
func (m *CpUserMutation) MobileType() (r cpuser.MobileType, exists bool) {
v := m.mobile_type
if v == nil {
return
}
return *v, true
}
// OldMobileType returns the old "mobile_type" field's value of the CpUser entity.
// If the CpUser 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 *CpUserMutation) OldMobileType(ctx context.Context) (v cpuser.MobileType, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMobileType is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMobileType requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMobileType: %w", err)
}
return oldValue.MobileType, nil
}
// ResetMobileType resets all changes to the "mobile_type" field.
func (m *CpUserMutation) ResetMobileType() {
m.mobile_type = nil
}
// AddCptaskIDs adds the "cptasks" edge to the CpTask entity by ids.
func (m *CpUserMutation) AddCptaskIDs(ids ...int64) {
if m.cptasks == nil {
m.cptasks = make(map[int64]struct{})
}
for i := range ids {
m.cptasks[ids[i]] = struct{}{}
}
}
// ClearCptasks clears the "cptasks" edge to the CpTask entity.
func (m *CpUserMutation) ClearCptasks() {
m.clearedcptasks = true
}
// CptasksCleared reports if the "cptasks" edge to the CpTask entity was cleared.
func (m *CpUserMutation) CptasksCleared() bool {
return m.clearedcptasks
}
// RemoveCptaskIDs removes the "cptasks" edge to the CpTask entity by IDs.
func (m *CpUserMutation) RemoveCptaskIDs(ids ...int64) {
if m.removedcptasks == nil {
m.removedcptasks = make(map[int64]struct{})
}
for i := range ids {
delete(m.cptasks, ids[i])
m.removedcptasks[ids[i]] = struct{}{}
}
}
// RemovedCptasks returns the removed IDs of the "cptasks" edge to the CpTask entity.
func (m *CpUserMutation) RemovedCptasksIDs() (ids []int64) {
for id := range m.removedcptasks {
ids = append(ids, id)
}
return
}
// CptasksIDs returns the "cptasks" edge IDs in the mutation.
func (m *CpUserMutation) CptasksIDs() (ids []int64) {
for id := range m.cptasks {
ids = append(ids, id)
}
return
}
// ResetCptasks resets all changes to the "cptasks" edge.
func (m *CpUserMutation) ResetCptasks() {
m.cptasks = nil
m.clearedcptasks = false
m.removedcptasks = nil
}
// SetSysuserID sets the "sysuser" edge to the SysUser entity by id.
func (m *CpUserMutation) SetSysuserID(id int64) {
m.sysuser = &id
}
// ClearSysuser clears the "sysuser" edge to the SysUser entity.
func (m *CpUserMutation) ClearSysuser() {
m.clearedsysuser = true
m.clearedFields[cpuser.FieldUserID] = struct{}{}
}
// SysuserCleared reports if the "sysuser" edge to the SysUser entity was cleared.
func (m *CpUserMutation) SysuserCleared() bool {
return m.clearedsysuser
}
// SysuserID returns the "sysuser" edge ID in the mutation.
func (m *CpUserMutation) SysuserID() (id int64, exists bool) {
if m.sysuser != nil {
return *m.sysuser, true
}
return
}
// SysuserIDs returns the "sysuser" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// SysuserID instead. It exists only for internal usage by the builders.
func (m *CpUserMutation) SysuserIDs() (ids []int64) {
if id := m.sysuser; id != nil {
ids = append(ids, *id)
}
return
}
// ResetSysuser resets all changes to the "sysuser" edge.
func (m *CpUserMutation) ResetSysuser() {
m.sysuser = nil
m.clearedsysuser = false
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by ids.
func (m *CpUserMutation) AddCpTaskLogIDs(ids ...int64) {
if m.cp_task_logs == nil {
m.cp_task_logs = make(map[int64]struct{})
}
for i := range ids {
m.cp_task_logs[ids[i]] = struct{}{}
}
}
// ClearCpTaskLogs clears the "cp_task_logs" edge to the CpTaskLog entity.
func (m *CpUserMutation) ClearCpTaskLogs() {
m.clearedcp_task_logs = true
}
// CpTaskLogsCleared reports if the "cp_task_logs" edge to the CpTaskLog entity was cleared.
func (m *CpUserMutation) CpTaskLogsCleared() bool {
return m.clearedcp_task_logs
}
// RemoveCpTaskLogIDs removes the "cp_task_logs" edge to the CpTaskLog entity by IDs.
func (m *CpUserMutation) RemoveCpTaskLogIDs(ids ...int64) {
if m.removedcp_task_logs == nil {
m.removedcp_task_logs = make(map[int64]struct{})
}
for i := range ids {
delete(m.cp_task_logs, ids[i])
m.removedcp_task_logs[ids[i]] = struct{}{}
}
}
// RemovedCpTaskLogs returns the removed IDs of the "cp_task_logs" edge to the CpTaskLog entity.
func (m *CpUserMutation) RemovedCpTaskLogsIDs() (ids []int64) {
for id := range m.removedcp_task_logs {
ids = append(ids, id)
}
return
}
// CpTaskLogsIDs returns the "cp_task_logs" edge IDs in the mutation.
func (m *CpUserMutation) CpTaskLogsIDs() (ids []int64) {
for id := range m.cp_task_logs {
ids = append(ids, id)
}
return
}
// ResetCpTaskLogs resets all changes to the "cp_task_logs" edge.
func (m *CpUserMutation) ResetCpTaskLogs() {
m.cp_task_logs = nil
m.clearedcp_task_logs = false
m.removedcp_task_logs = nil
}
// ClearSchool clears the "school" edge to the CpSchool entity.
func (m *CpUserMutation) ClearSchool() {
m.clearedschool = true
m.clearedFields[cpuser.FieldSchoolID] = struct{}{}
}
// SchoolCleared reports if the "school" edge to the CpSchool entity was cleared.
func (m *CpUserMutation) SchoolCleared() bool {
return m.clearedschool
}
// SchoolIDs returns the "school" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// SchoolID instead. It exists only for internal usage by the builders.
func (m *CpUserMutation) SchoolIDs() (ids []string) {
if id := m.school; id != nil {
ids = append(ids, *id)
}
return
}
// ResetSchool resets all changes to the "school" edge.
func (m *CpUserMutation) ResetSchool() {
m.school = nil
m.clearedschool = false
}
// Where appends a list predicates to the CpUserMutation builder.
func (m *CpUserMutation) Where(ps ...predicate.CpUser) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the CpUserMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *CpUserMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.CpUser, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *CpUserMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *CpUserMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (CpUser).
func (m *CpUserMutation) 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 *CpUserMutation) Fields() []string {
fields := make([]string, 0, 10)
if m.create_time != nil {
fields = append(fields, cpuser.FieldCreateTime)
}
if m.update_time != nil {
fields = append(fields, cpuser.FieldUpdateTime)
}
if m.sysuser != nil {
fields = append(fields, cpuser.FieldUserID)
}
if m.username != nil {
fields = append(fields, cpuser.FieldUsername)
}
if m.password != nil {
fields = append(fields, cpuser.FieldPassword)
}
if m.school != nil {
fields = append(fields, cpuser.FieldSchoolID)
}
if m.email != nil {
fields = append(fields, cpuser.FieldEmail)
}
if m.mobile_code != nil {
fields = append(fields, cpuser.FieldMobileCode)
}
if m.cookie != nil {
fields = append(fields, cpuser.FieldCookie)
}
if m.mobile_type != nil {
fields = append(fields, cpuser.FieldMobileType)
}
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 *CpUserMutation) Field(name string) (ent.Value, bool) {
switch name {
case cpuser.FieldCreateTime:
return m.CreateTime()
case cpuser.FieldUpdateTime:
return m.UpdateTime()
case cpuser.FieldUserID:
return m.UserID()
case cpuser.FieldUsername:
return m.Username()
case cpuser.FieldPassword:
return m.Password()
case cpuser.FieldSchoolID:
return m.SchoolID()
case cpuser.FieldEmail:
return m.Email()
case cpuser.FieldMobileCode:
return m.MobileCode()
case cpuser.FieldCookie:
return m.Cookie()
case cpuser.FieldMobileType:
return m.MobileType()
}
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 *CpUserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case cpuser.FieldCreateTime:
return m.OldCreateTime(ctx)
case cpuser.FieldUpdateTime:
return m.OldUpdateTime(ctx)
case cpuser.FieldUserID:
return m.OldUserID(ctx)
case cpuser.FieldUsername:
return m.OldUsername(ctx)
case cpuser.FieldPassword:
return m.OldPassword(ctx)
case cpuser.FieldSchoolID:
return m.OldSchoolID(ctx)
case cpuser.FieldEmail:
return m.OldEmail(ctx)
case cpuser.FieldMobileCode:
return m.OldMobileCode(ctx)
case cpuser.FieldCookie:
return m.OldCookie(ctx)
case cpuser.FieldMobileType:
return m.OldMobileType(ctx)
}
return nil, fmt.Errorf("unknown CpUser 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 *CpUserMutation) SetField(name string, value ent.Value) error {
switch name {
case cpuser.FieldCreateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil
case cpuser.FieldUpdateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdateTime(v)
return nil
case cpuser.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUserID(v)
return nil
case cpuser.FieldUsername:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsername(v)
return nil
case cpuser.FieldPassword:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPassword(v)
return nil
case cpuser.FieldSchoolID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSchoolID(v)
return nil
case cpuser.FieldEmail:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetEmail(v)
return nil
case cpuser.FieldMobileCode:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMobileCode(v)
return nil
case cpuser.FieldCookie:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCookie(v)
return nil
case cpuser.FieldMobileType:
v, ok := value.(cpuser.MobileType)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMobileType(v)
return nil
}
return fmt.Errorf("unknown CpUser field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *CpUserMutation) AddedFields() []string {
var fields []string
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 *CpUserMutation) AddedField(name string) (ent.Value, bool) {
switch name {
}
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 *CpUserMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown CpUser numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *CpUserMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(cpuser.FieldEmail) {
fields = append(fields, cpuser.FieldEmail)
}
if m.FieldCleared(cpuser.FieldMobileCode) {
fields = append(fields, cpuser.FieldMobileCode)
}
if m.FieldCleared(cpuser.FieldCookie) {
fields = append(fields, cpuser.FieldCookie)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *CpUserMutation) 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 *CpUserMutation) ClearField(name string) error {
switch name {
case cpuser.FieldEmail:
m.ClearEmail()
return nil
case cpuser.FieldMobileCode:
m.ClearMobileCode()
return nil
case cpuser.FieldCookie:
m.ClearCookie()
return nil
}
return fmt.Errorf("unknown CpUser 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 *CpUserMutation) ResetField(name string) error {
switch name {
case cpuser.FieldCreateTime:
m.ResetCreateTime()
return nil
case cpuser.FieldUpdateTime:
m.ResetUpdateTime()
return nil
case cpuser.FieldUserID:
m.ResetUserID()
return nil
case cpuser.FieldUsername:
m.ResetUsername()
return nil
case cpuser.FieldPassword:
m.ResetPassword()
return nil
case cpuser.FieldSchoolID:
m.ResetSchoolID()
return nil
case cpuser.FieldEmail:
m.ResetEmail()
return nil
case cpuser.FieldMobileCode:
m.ResetMobileCode()
return nil
case cpuser.FieldCookie:
m.ResetCookie()
return nil
case cpuser.FieldMobileType:
m.ResetMobileType()
return nil
}
return fmt.Errorf("unknown CpUser field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CpUserMutation) AddedEdges() []string {
edges := make([]string, 0, 4)
if m.cptasks != nil {
edges = append(edges, cpuser.EdgeCptasks)
}
if m.sysuser != nil {
edges = append(edges, cpuser.EdgeSysuser)
}
if m.cp_task_logs != nil {
edges = append(edges, cpuser.EdgeCpTaskLogs)
}
if m.school != nil {
edges = append(edges, cpuser.EdgeSchool)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *CpUserMutation) AddedIDs(name string) []ent.Value {
switch name {
case cpuser.EdgeCptasks:
ids := make([]ent.Value, 0, len(m.cptasks))
for id := range m.cptasks {
ids = append(ids, id)
}
return ids
case cpuser.EdgeSysuser:
if id := m.sysuser; id != nil {
return []ent.Value{*id}
}
case cpuser.EdgeCpTaskLogs:
ids := make([]ent.Value, 0, len(m.cp_task_logs))
for id := range m.cp_task_logs {
ids = append(ids, id)
}
return ids
case cpuser.EdgeSchool:
if id := m.school; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *CpUserMutation) RemovedEdges() []string {
edges := make([]string, 0, 4)
if m.removedcptasks != nil {
edges = append(edges, cpuser.EdgeCptasks)
}
if m.removedcp_task_logs != nil {
edges = append(edges, cpuser.EdgeCpTaskLogs)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *CpUserMutation) RemovedIDs(name string) []ent.Value {
switch name {
case cpuser.EdgeCptasks:
ids := make([]ent.Value, 0, len(m.removedcptasks))
for id := range m.removedcptasks {
ids = append(ids, id)
}
return ids
case cpuser.EdgeCpTaskLogs:
ids := make([]ent.Value, 0, len(m.removedcp_task_logs))
for id := range m.removedcp_task_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CpUserMutation) ClearedEdges() []string {
edges := make([]string, 0, 4)
if m.clearedcptasks {
edges = append(edges, cpuser.EdgeCptasks)
}
if m.clearedsysuser {
edges = append(edges, cpuser.EdgeSysuser)
}
if m.clearedcp_task_logs {
edges = append(edges, cpuser.EdgeCpTaskLogs)
}
if m.clearedschool {
edges = append(edges, cpuser.EdgeSchool)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *CpUserMutation) EdgeCleared(name string) bool {
switch name {
case cpuser.EdgeCptasks:
return m.clearedcptasks
case cpuser.EdgeSysuser:
return m.clearedsysuser
case cpuser.EdgeCpTaskLogs:
return m.clearedcp_task_logs
case cpuser.EdgeSchool:
return m.clearedschool
}
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 *CpUserMutation) ClearEdge(name string) error {
switch name {
case cpuser.EdgeSysuser:
m.ClearSysuser()
return nil
case cpuser.EdgeSchool:
m.ClearSchool()
return nil
}
return fmt.Errorf("unknown CpUser 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 *CpUserMutation) ResetEdge(name string) error {
switch name {
case cpuser.EdgeCptasks:
m.ResetCptasks()
return nil
case cpuser.EdgeSysuser:
m.ResetSysuser()
return nil
case cpuser.EdgeCpTaskLogs:
m.ResetCpTaskLogs()
return nil
case cpuser.EdgeSchool:
m.ResetSchool()
return nil
}
return fmt.Errorf("unknown CpUser edge %s", name)
}
// SysAgentMutation represents an operation that mutates the SysAgent nodes in the graph.
type SysAgentMutation struct {
config
op Op
typ string
id *int64
create_time **ent2.CustomTime
update_time **ent2.CustomTime
level *int
addlevel *int
rate *decimal.Decimal
clearedFields map[string]struct{}
users *int64
clearedusers bool
done bool
oldValue func(context.Context) (*SysAgent, error)
predicates []predicate.SysAgent
}
var _ ent.Mutation = (*SysAgentMutation)(nil)
// sysagentOption allows management of the mutation configuration using functional options.
type sysagentOption func(*SysAgentMutation)
// newSysAgentMutation creates new mutation for the SysAgent entity.
func newSysAgentMutation(c config, op Op, opts ...sysagentOption) *SysAgentMutation {
m := &SysAgentMutation{
config: c,
op: op,
typ: TypeSysAgent,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withSysAgentID sets the ID field of the mutation.
func withSysAgentID(id int64) sysagentOption {
return func(m *SysAgentMutation) {
var (
err error
once sync.Once
value *SysAgent
)
m.oldValue = func(ctx context.Context) (*SysAgent, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().SysAgent.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withSysAgent sets the old SysAgent of the mutation.
func withSysAgent(node *SysAgent) sysagentOption {
return func(m *SysAgentMutation) {
m.oldValue = func(context.Context) (*SysAgent, 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 SysAgentMutation) 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 SysAgentMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *SysAgentMutation) ID() (id int64, 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 *SysAgentMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().SysAgent.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreateTime sets the "create_time" field.
func (m *SysAgentMutation) SetCreateTime(et *ent2.CustomTime) {
m.create_time = &et
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *SysAgentMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the SysAgent entity.
// If the SysAgent 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 *SysAgentMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *SysAgentMutation) ResetCreateTime() {
m.create_time = nil
}
// SetUpdateTime sets the "update_time" field.
func (m *SysAgentMutation) SetUpdateTime(et *ent2.CustomTime) {
m.update_time = &et
}
// UpdateTime returns the value of the "update_time" field in the mutation.
func (m *SysAgentMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
v := m.update_time
if v == nil {
return
}
return *v, true
}
// OldUpdateTime returns the old "update_time" field's value of the SysAgent entity.
// If the SysAgent 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 *SysAgentMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
}
return oldValue.UpdateTime, nil
}
// ResetUpdateTime resets all changes to the "update_time" field.
func (m *SysAgentMutation) ResetUpdateTime() {
m.update_time = nil
}
// SetLevel sets the "level" field.
func (m *SysAgentMutation) SetLevel(i int) {
m.level = &i
m.addlevel = nil
}
// Level returns the value of the "level" field in the mutation.
func (m *SysAgentMutation) Level() (r int, exists bool) {
v := m.level
if v == nil {
return
}
return *v, true
}
// OldLevel returns the old "level" field's value of the SysAgent entity.
// If the SysAgent 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 *SysAgentMutation) OldLevel(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLevel is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldLevel requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLevel: %w", err)
}
return oldValue.Level, nil
}
// AddLevel adds i to the "level" field.
func (m *SysAgentMutation) AddLevel(i int) {
if m.addlevel != nil {
*m.addlevel += i
} else {
m.addlevel = &i
}
}
// AddedLevel returns the value that was added to the "level" field in this mutation.
func (m *SysAgentMutation) AddedLevel() (r int, exists bool) {
v := m.addlevel
if v == nil {
return
}
return *v, true
}
// ResetLevel resets all changes to the "level" field.
func (m *SysAgentMutation) ResetLevel() {
m.level = nil
m.addlevel = nil
}
// SetRate sets the "rate" field.
func (m *SysAgentMutation) SetRate(d decimal.Decimal) {
m.rate = &d
}
// Rate returns the value of the "rate" field in the mutation.
func (m *SysAgentMutation) Rate() (r decimal.Decimal, exists bool) {
v := m.rate
if v == nil {
return
}
return *v, true
}
// OldRate returns the old "rate" field's value of the SysAgent entity.
// If the SysAgent 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 *SysAgentMutation) OldRate(ctx context.Context) (v decimal.Decimal, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRate is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRate requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRate: %w", err)
}
return oldValue.Rate, nil
}
// ResetRate resets all changes to the "rate" field.
func (m *SysAgentMutation) ResetRate() {
m.rate = nil
}
// SetUsersID sets the "users" edge to the SysUser entity by id.
func (m *SysAgentMutation) SetUsersID(id int64) {
m.users = &id
}
// ClearUsers clears the "users" edge to the SysUser entity.
func (m *SysAgentMutation) ClearUsers() {
m.clearedusers = true
}
// UsersCleared reports if the "users" edge to the SysUser entity was cleared.
func (m *SysAgentMutation) UsersCleared() bool {
return m.clearedusers
}
// UsersID returns the "users" edge ID in the mutation.
func (m *SysAgentMutation) UsersID() (id int64, exists bool) {
if m.users != nil {
return *m.users, true
}
return
}
// UsersIDs returns the "users" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UsersID instead. It exists only for internal usage by the builders.
func (m *SysAgentMutation) UsersIDs() (ids []int64) {
if id := m.users; id != nil {
ids = append(ids, *id)
}
return
}
// ResetUsers resets all changes to the "users" edge.
func (m *SysAgentMutation) ResetUsers() {
m.users = nil
m.clearedusers = false
}
// Where appends a list predicates to the SysAgentMutation builder.
func (m *SysAgentMutation) Where(ps ...predicate.SysAgent) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the SysAgentMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SysAgentMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.SysAgent, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *SysAgentMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *SysAgentMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (SysAgent).
func (m *SysAgentMutation) 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 *SysAgentMutation) Fields() []string {
fields := make([]string, 0, 4)
if m.create_time != nil {
fields = append(fields, sysagent.FieldCreateTime)
}
if m.update_time != nil {
fields = append(fields, sysagent.FieldUpdateTime)
}
if m.level != nil {
fields = append(fields, sysagent.FieldLevel)
}
if m.rate != nil {
fields = append(fields, sysagent.FieldRate)
}
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 *SysAgentMutation) Field(name string) (ent.Value, bool) {
switch name {
case sysagent.FieldCreateTime:
return m.CreateTime()
case sysagent.FieldUpdateTime:
return m.UpdateTime()
case sysagent.FieldLevel:
return m.Level()
case sysagent.FieldRate:
return m.Rate()
}
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 *SysAgentMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case sysagent.FieldCreateTime:
return m.OldCreateTime(ctx)
case sysagent.FieldUpdateTime:
return m.OldUpdateTime(ctx)
case sysagent.FieldLevel:
return m.OldLevel(ctx)
case sysagent.FieldRate:
return m.OldRate(ctx)
}
return nil, fmt.Errorf("unknown SysAgent 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 *SysAgentMutation) SetField(name string, value ent.Value) error {
switch name {
case sysagent.FieldCreateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil
case sysagent.FieldUpdateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdateTime(v)
return nil
case sysagent.FieldLevel:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLevel(v)
return nil
case sysagent.FieldRate:
v, ok := value.(decimal.Decimal)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRate(v)
return nil
}
return fmt.Errorf("unknown SysAgent field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SysAgentMutation) AddedFields() []string {
var fields []string
if m.addlevel != nil {
fields = append(fields, sysagent.FieldLevel)
}
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 *SysAgentMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case sysagent.FieldLevel:
return m.AddedLevel()
}
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 *SysAgentMutation) AddField(name string, value ent.Value) error {
switch name {
case sysagent.FieldLevel:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddLevel(v)
return nil
}
return fmt.Errorf("unknown SysAgent numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SysAgentMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SysAgentMutation) 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 *SysAgentMutation) ClearField(name string) error {
return fmt.Errorf("unknown SysAgent 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 *SysAgentMutation) ResetField(name string) error {
switch name {
case sysagent.FieldCreateTime:
m.ResetCreateTime()
return nil
case sysagent.FieldUpdateTime:
m.ResetUpdateTime()
return nil
case sysagent.FieldLevel:
m.ResetLevel()
return nil
case sysagent.FieldRate:
m.ResetRate()
return nil
}
return fmt.Errorf("unknown SysAgent field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SysAgentMutation) AddedEdges() []string {
edges := make([]string, 0, 1)
if m.users != nil {
edges = append(edges, sysagent.EdgeUsers)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SysAgentMutation) AddedIDs(name string) []ent.Value {
switch name {
case sysagent.EdgeUsers:
if id := m.users; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SysAgentMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SysAgentMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SysAgentMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
if m.clearedusers {
edges = append(edges, sysagent.EdgeUsers)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SysAgentMutation) EdgeCleared(name string) bool {
switch name {
case sysagent.EdgeUsers:
return m.clearedusers
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *SysAgentMutation) ClearEdge(name string) error {
switch name {
case sysagent.EdgeUsers:
m.ClearUsers()
return nil
}
return fmt.Errorf("unknown SysAgent 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 *SysAgentMutation) ResetEdge(name string) error {
switch name {
case sysagent.EdgeUsers:
m.ResetUsers()
return nil
}
return fmt.Errorf("unknown SysAgent edge %s", name)
}
// SysCardMutation represents an operation that mutates the SysCard nodes in the graph.
type SysCardMutation struct {
config
op Op
typ string
id *int64
create_time **ent2.CustomTime
update_time **ent2.CustomTime
content *string
status *syscard.Status
value *uint64
addvalue *int64
cash_value *decimal.Decimal
clearedFields map[string]struct{}
creator *int64
clearedcreator bool
user *int64
cleareduser bool
cash_user *int64
clearedcash_user bool
done bool
oldValue func(context.Context) (*SysCard, error)
predicates []predicate.SysCard
}
var _ ent.Mutation = (*SysCardMutation)(nil)
// syscardOption allows management of the mutation configuration using functional options.
type syscardOption func(*SysCardMutation)
// newSysCardMutation creates new mutation for the SysCard entity.
func newSysCardMutation(c config, op Op, opts ...syscardOption) *SysCardMutation {
m := &SysCardMutation{
config: c,
op: op,
typ: TypeSysCard,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withSysCardID sets the ID field of the mutation.
func withSysCardID(id int64) syscardOption {
return func(m *SysCardMutation) {
var (
err error
once sync.Once
value *SysCard
)
m.oldValue = func(ctx context.Context) (*SysCard, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().SysCard.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withSysCard sets the old SysCard of the mutation.
func withSysCard(node *SysCard) syscardOption {
return func(m *SysCardMutation) {
m.oldValue = func(context.Context) (*SysCard, 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 SysCardMutation) 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 SysCardMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *SysCardMutation) ID() (id int64, 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 *SysCardMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().SysCard.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreateTime sets the "create_time" field.
func (m *SysCardMutation) SetCreateTime(et *ent2.CustomTime) {
m.create_time = &et
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *SysCardMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the SysCard entity.
// If the SysCard 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 *SysCardMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *SysCardMutation) ResetCreateTime() {
m.create_time = nil
}
// SetUpdateTime sets the "update_time" field.
func (m *SysCardMutation) SetUpdateTime(et *ent2.CustomTime) {
m.update_time = &et
}
// UpdateTime returns the value of the "update_time" field in the mutation.
func (m *SysCardMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
v := m.update_time
if v == nil {
return
}
return *v, true
}
// OldUpdateTime returns the old "update_time" field's value of the SysCard entity.
// If the SysCard 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 *SysCardMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
}
return oldValue.UpdateTime, nil
}
// ResetUpdateTime resets all changes to the "update_time" field.
func (m *SysCardMutation) ResetUpdateTime() {
m.update_time = nil
}
// SetContent sets the "content" field.
func (m *SysCardMutation) SetContent(s string) {
m.content = &s
}
// Content returns the value of the "content" field in the mutation.
func (m *SysCardMutation) Content() (r string, exists bool) {
v := m.content
if v == nil {
return
}
return *v, true
}
// OldContent returns the old "content" field's value of the SysCard entity.
// If the SysCard 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 *SysCardMutation) OldContent(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldContent is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldContent requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldContent: %w", err)
}
return oldValue.Content, nil
}
// ResetContent resets all changes to the "content" field.
func (m *SysCardMutation) ResetContent() {
m.content = nil
}
// SetStatus sets the "status" field.
func (m *SysCardMutation) SetStatus(s syscard.Status) {
m.status = &s
}
// Status returns the value of the "status" field in the mutation.
func (m *SysCardMutation) Status() (r syscard.Status, exists bool) {
v := m.status
if v == nil {
return
}
return *v, true
}
// OldStatus returns the old "status" field's value of the SysCard entity.
// If the SysCard 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 *SysCardMutation) OldStatus(ctx context.Context) (v syscard.Status, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldStatus is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldStatus requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldStatus: %w", err)
}
return oldValue.Status, nil
}
// ResetStatus resets all changes to the "status" field.
func (m *SysCardMutation) ResetStatus() {
m.status = nil
}
// SetValue sets the "value" field.
func (m *SysCardMutation) SetValue(u uint64) {
m.value = &u
m.addvalue = nil
}
// Value returns the value of the "value" field in the mutation.
func (m *SysCardMutation) Value() (r uint64, exists bool) {
v := m.value
if v == nil {
return
}
return *v, true
}
// OldValue returns the old "value" field's value of the SysCard entity.
// If the SysCard 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 *SysCardMutation) OldValue(ctx context.Context) (v uint64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldValue is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldValue requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldValue: %w", err)
}
return oldValue.Value, nil
}
// AddValue adds u to the "value" field.
func (m *SysCardMutation) AddValue(u int64) {
if m.addvalue != nil {
*m.addvalue += u
} else {
m.addvalue = &u
}
}
// AddedValue returns the value that was added to the "value" field in this mutation.
func (m *SysCardMutation) AddedValue() (r int64, exists bool) {
v := m.addvalue
if v == nil {
return
}
return *v, true
}
// ResetValue resets all changes to the "value" field.
func (m *SysCardMutation) ResetValue() {
m.value = nil
m.addvalue = nil
}
// SetCreatorID sets the "creator_id" field.
func (m *SysCardMutation) SetCreatorID(i int64) {
m.creator = &i
}
// CreatorID returns the value of the "creator_id" field in the mutation.
func (m *SysCardMutation) CreatorID() (r int64, exists bool) {
v := m.creator
if v == nil {
return
}
return *v, true
}
// OldCreatorID returns the old "creator_id" field's value of the SysCard entity.
// If the SysCard 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 *SysCardMutation) OldCreatorID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatorID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatorID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatorID: %w", err)
}
return oldValue.CreatorID, nil
}
// ResetCreatorID resets all changes to the "creator_id" field.
func (m *SysCardMutation) ResetCreatorID() {
m.creator = nil
}
// SetUsedID sets the "used_id" field.
func (m *SysCardMutation) SetUsedID(i int64) {
m.user = &i
}
// UsedID returns the value of the "used_id" field in the mutation.
func (m *SysCardMutation) UsedID() (r int64, exists bool) {
v := m.user
if v == nil {
return
}
return *v, true
}
// OldUsedID returns the old "used_id" field's value of the SysCard entity.
// If the SysCard 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 *SysCardMutation) OldUsedID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUsedID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUsedID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUsedID: %w", err)
}
return oldValue.UsedID, nil
}
// ClearUsedID clears the value of the "used_id" field.
func (m *SysCardMutation) ClearUsedID() {
m.user = nil
m.clearedFields[syscard.FieldUsedID] = struct{}{}
}
// UsedIDCleared returns if the "used_id" field was cleared in this mutation.
func (m *SysCardMutation) UsedIDCleared() bool {
_, ok := m.clearedFields[syscard.FieldUsedID]
return ok
}
// ResetUsedID resets all changes to the "used_id" field.
func (m *SysCardMutation) ResetUsedID() {
m.user = nil
delete(m.clearedFields, syscard.FieldUsedID)
}
// SetCashUserID sets the "cash_user_id" field.
func (m *SysCardMutation) SetCashUserID(i int64) {
m.cash_user = &i
}
// CashUserID returns the value of the "cash_user_id" field in the mutation.
func (m *SysCardMutation) CashUserID() (r int64, exists bool) {
v := m.cash_user
if v == nil {
return
}
return *v, true
}
// OldCashUserID returns the old "cash_user_id" field's value of the SysCard entity.
// If the SysCard 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 *SysCardMutation) OldCashUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCashUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCashUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCashUserID: %w", err)
}
return oldValue.CashUserID, nil
}
// ClearCashUserID clears the value of the "cash_user_id" field.
func (m *SysCardMutation) ClearCashUserID() {
m.cash_user = nil
m.clearedFields[syscard.FieldCashUserID] = struct{}{}
}
// CashUserIDCleared returns if the "cash_user_id" field was cleared in this mutation.
func (m *SysCardMutation) CashUserIDCleared() bool {
_, ok := m.clearedFields[syscard.FieldCashUserID]
return ok
}
// ResetCashUserID resets all changes to the "cash_user_id" field.
func (m *SysCardMutation) ResetCashUserID() {
m.cash_user = nil
delete(m.clearedFields, syscard.FieldCashUserID)
}
// SetCashValue sets the "cash_value" field.
func (m *SysCardMutation) SetCashValue(d decimal.Decimal) {
m.cash_value = &d
}
// CashValue returns the value of the "cash_value" field in the mutation.
func (m *SysCardMutation) CashValue() (r decimal.Decimal, exists bool) {
v := m.cash_value
if v == nil {
return
}
return *v, true
}
// OldCashValue returns the old "cash_value" field's value of the SysCard entity.
// If the SysCard 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 *SysCardMutation) OldCashValue(ctx context.Context) (v decimal.Decimal, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCashValue is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCashValue requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCashValue: %w", err)
}
return oldValue.CashValue, nil
}
// ResetCashValue resets all changes to the "cash_value" field.
func (m *SysCardMutation) ResetCashValue() {
m.cash_value = nil
}
// ClearCreator clears the "creator" edge to the SysUser entity.
func (m *SysCardMutation) ClearCreator() {
m.clearedcreator = true
m.clearedFields[syscard.FieldCreatorID] = struct{}{}
}
// CreatorCleared reports if the "creator" edge to the SysUser entity was cleared.
func (m *SysCardMutation) CreatorCleared() bool {
return m.clearedcreator
}
// CreatorIDs returns the "creator" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// CreatorID instead. It exists only for internal usage by the builders.
func (m *SysCardMutation) CreatorIDs() (ids []int64) {
if id := m.creator; id != nil {
ids = append(ids, *id)
}
return
}
// ResetCreator resets all changes to the "creator" edge.
func (m *SysCardMutation) ResetCreator() {
m.creator = nil
m.clearedcreator = false
}
// SetUserID sets the "user" edge to the SysUser entity by id.
func (m *SysCardMutation) SetUserID(id int64) {
m.user = &id
}
// ClearUser clears the "user" edge to the SysUser entity.
func (m *SysCardMutation) ClearUser() {
m.cleareduser = true
m.clearedFields[syscard.FieldUsedID] = struct{}{}
}
// UserCleared reports if the "user" edge to the SysUser entity was cleared.
func (m *SysCardMutation) UserCleared() bool {
return m.UsedIDCleared() || m.cleareduser
}
// UserID returns the "user" edge ID in the mutation.
func (m *SysCardMutation) UserID() (id int64, exists bool) {
if m.user != nil {
return *m.user, true
}
return
}
// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *SysCardMutation) UserIDs() (ids []int64) {
if id := m.user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetUser resets all changes to the "user" edge.
func (m *SysCardMutation) ResetUser() {
m.user = nil
m.cleareduser = false
}
// ClearCashUser clears the "cash_user" edge to the SysUser entity.
func (m *SysCardMutation) ClearCashUser() {
m.clearedcash_user = true
m.clearedFields[syscard.FieldCashUserID] = struct{}{}
}
// CashUserCleared reports if the "cash_user" edge to the SysUser entity was cleared.
func (m *SysCardMutation) CashUserCleared() bool {
return m.CashUserIDCleared() || m.clearedcash_user
}
// CashUserIDs returns the "cash_user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// CashUserID instead. It exists only for internal usage by the builders.
func (m *SysCardMutation) CashUserIDs() (ids []int64) {
if id := m.cash_user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetCashUser resets all changes to the "cash_user" edge.
func (m *SysCardMutation) ResetCashUser() {
m.cash_user = nil
m.clearedcash_user = false
}
// Where appends a list predicates to the SysCardMutation builder.
func (m *SysCardMutation) Where(ps ...predicate.SysCard) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the SysCardMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SysCardMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.SysCard, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *SysCardMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *SysCardMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (SysCard).
func (m *SysCardMutation) 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 *SysCardMutation) Fields() []string {
fields := make([]string, 0, 9)
if m.create_time != nil {
fields = append(fields, syscard.FieldCreateTime)
}
if m.update_time != nil {
fields = append(fields, syscard.FieldUpdateTime)
}
if m.content != nil {
fields = append(fields, syscard.FieldContent)
}
if m.status != nil {
fields = append(fields, syscard.FieldStatus)
}
if m.value != nil {
fields = append(fields, syscard.FieldValue)
}
if m.creator != nil {
fields = append(fields, syscard.FieldCreatorID)
}
if m.user != nil {
fields = append(fields, syscard.FieldUsedID)
}
if m.cash_user != nil {
fields = append(fields, syscard.FieldCashUserID)
}
if m.cash_value != nil {
fields = append(fields, syscard.FieldCashValue)
}
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 *SysCardMutation) Field(name string) (ent.Value, bool) {
switch name {
case syscard.FieldCreateTime:
return m.CreateTime()
case syscard.FieldUpdateTime:
return m.UpdateTime()
case syscard.FieldContent:
return m.Content()
case syscard.FieldStatus:
return m.Status()
case syscard.FieldValue:
return m.Value()
case syscard.FieldCreatorID:
return m.CreatorID()
case syscard.FieldUsedID:
return m.UsedID()
case syscard.FieldCashUserID:
return m.CashUserID()
case syscard.FieldCashValue:
return m.CashValue()
}
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 *SysCardMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case syscard.FieldCreateTime:
return m.OldCreateTime(ctx)
case syscard.FieldUpdateTime:
return m.OldUpdateTime(ctx)
case syscard.FieldContent:
return m.OldContent(ctx)
case syscard.FieldStatus:
return m.OldStatus(ctx)
case syscard.FieldValue:
return m.OldValue(ctx)
case syscard.FieldCreatorID:
return m.OldCreatorID(ctx)
case syscard.FieldUsedID:
return m.OldUsedID(ctx)
case syscard.FieldCashUserID:
return m.OldCashUserID(ctx)
case syscard.FieldCashValue:
return m.OldCashValue(ctx)
}
return nil, fmt.Errorf("unknown SysCard 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 *SysCardMutation) SetField(name string, value ent.Value) error {
switch name {
case syscard.FieldCreateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil
case syscard.FieldUpdateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdateTime(v)
return nil
case syscard.FieldContent:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetContent(v)
return nil
case syscard.FieldStatus:
v, ok := value.(syscard.Status)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetStatus(v)
return nil
case syscard.FieldValue:
v, ok := value.(uint64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetValue(v)
return nil
case syscard.FieldCreatorID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatorID(v)
return nil
case syscard.FieldUsedID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsedID(v)
return nil
case syscard.FieldCashUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCashUserID(v)
return nil
case syscard.FieldCashValue:
v, ok := value.(decimal.Decimal)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCashValue(v)
return nil
}
return fmt.Errorf("unknown SysCard field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SysCardMutation) AddedFields() []string {
var fields []string
if m.addvalue != nil {
fields = append(fields, syscard.FieldValue)
}
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 *SysCardMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case syscard.FieldValue:
return m.AddedValue()
}
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 *SysCardMutation) AddField(name string, value ent.Value) error {
switch name {
case syscard.FieldValue:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddValue(v)
return nil
}
return fmt.Errorf("unknown SysCard numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SysCardMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(syscard.FieldUsedID) {
fields = append(fields, syscard.FieldUsedID)
}
if m.FieldCleared(syscard.FieldCashUserID) {
fields = append(fields, syscard.FieldCashUserID)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SysCardMutation) 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 *SysCardMutation) ClearField(name string) error {
switch name {
case syscard.FieldUsedID:
m.ClearUsedID()
return nil
case syscard.FieldCashUserID:
m.ClearCashUserID()
return nil
}
return fmt.Errorf("unknown SysCard 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 *SysCardMutation) ResetField(name string) error {
switch name {
case syscard.FieldCreateTime:
m.ResetCreateTime()
return nil
case syscard.FieldUpdateTime:
m.ResetUpdateTime()
return nil
case syscard.FieldContent:
m.ResetContent()
return nil
case syscard.FieldStatus:
m.ResetStatus()
return nil
case syscard.FieldValue:
m.ResetValue()
return nil
case syscard.FieldCreatorID:
m.ResetCreatorID()
return nil
case syscard.FieldUsedID:
m.ResetUsedID()
return nil
case syscard.FieldCashUserID:
m.ResetCashUserID()
return nil
case syscard.FieldCashValue:
m.ResetCashValue()
return nil
}
return fmt.Errorf("unknown SysCard field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SysCardMutation) AddedEdges() []string {
edges := make([]string, 0, 3)
if m.creator != nil {
edges = append(edges, syscard.EdgeCreator)
}
if m.user != nil {
edges = append(edges, syscard.EdgeUser)
}
if m.cash_user != nil {
edges = append(edges, syscard.EdgeCashUser)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SysCardMutation) AddedIDs(name string) []ent.Value {
switch name {
case syscard.EdgeCreator:
if id := m.creator; id != nil {
return []ent.Value{*id}
}
case syscard.EdgeUser:
if id := m.user; id != nil {
return []ent.Value{*id}
}
case syscard.EdgeCashUser:
if id := m.cash_user; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SysCardMutation) RemovedEdges() []string {
edges := make([]string, 0, 3)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SysCardMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SysCardMutation) ClearedEdges() []string {
edges := make([]string, 0, 3)
if m.clearedcreator {
edges = append(edges, syscard.EdgeCreator)
}
if m.cleareduser {
edges = append(edges, syscard.EdgeUser)
}
if m.clearedcash_user {
edges = append(edges, syscard.EdgeCashUser)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SysCardMutation) EdgeCleared(name string) bool {
switch name {
case syscard.EdgeCreator:
return m.clearedcreator
case syscard.EdgeUser:
return m.cleareduser
case syscard.EdgeCashUser:
return m.clearedcash_user
}
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 *SysCardMutation) ClearEdge(name string) error {
switch name {
case syscard.EdgeCreator:
m.ClearCreator()
return nil
case syscard.EdgeUser:
m.ClearUser()
return nil
case syscard.EdgeCashUser:
m.ClearCashUser()
return nil
}
return fmt.Errorf("unknown SysCard 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 *SysCardMutation) ResetEdge(name string) error {
switch name {
case syscard.EdgeCreator:
m.ResetCreator()
return nil
case syscard.EdgeUser:
m.ResetUser()
return nil
case syscard.EdgeCashUser:
m.ResetCashUser()
return nil
}
return fmt.Errorf("unknown SysCard edge %s", name)
}
// SysMenuMutation represents an operation that mutates the SysMenu nodes in the graph.
type SysMenuMutation struct {
config
op Op
typ string
id *int64
create_time **ent2.CustomTime
update_time **ent2.CustomTime
name *string
label *string
_type *sysmenu.Type
link *string
permission *string
route *string
component *string
keep_alive *bool
hidden *bool
icon *string
_order *uint
add_order *int
clearedFields map[string]struct{}
roles map[int64]struct{}
removedroles map[int64]struct{}
clearedroles bool
parent *int64
clearedparent bool
children map[int64]struct{}
removedchildren map[int64]struct{}
clearedchildren bool
done bool
oldValue func(context.Context) (*SysMenu, error)
predicates []predicate.SysMenu
}
var _ ent.Mutation = (*SysMenuMutation)(nil)
// sysmenuOption allows management of the mutation configuration using functional options.
type sysmenuOption func(*SysMenuMutation)
// newSysMenuMutation creates new mutation for the SysMenu entity.
func newSysMenuMutation(c config, op Op, opts ...sysmenuOption) *SysMenuMutation {
m := &SysMenuMutation{
config: c,
op: op,
typ: TypeSysMenu,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withSysMenuID sets the ID field of the mutation.
func withSysMenuID(id int64) sysmenuOption {
return func(m *SysMenuMutation) {
var (
err error
once sync.Once
value *SysMenu
)
m.oldValue = func(ctx context.Context) (*SysMenu, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().SysMenu.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withSysMenu sets the old SysMenu of the mutation.
func withSysMenu(node *SysMenu) sysmenuOption {
return func(m *SysMenuMutation) {
m.oldValue = func(context.Context) (*SysMenu, 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 SysMenuMutation) 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 SysMenuMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *SysMenuMutation) ID() (id int64, 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 *SysMenuMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().SysMenu.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreateTime sets the "create_time" field.
func (m *SysMenuMutation) SetCreateTime(et *ent2.CustomTime) {
m.create_time = &et
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *SysMenuMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *SysMenuMutation) ResetCreateTime() {
m.create_time = nil
}
// SetUpdateTime sets the "update_time" field.
func (m *SysMenuMutation) SetUpdateTime(et *ent2.CustomTime) {
m.update_time = &et
}
// UpdateTime returns the value of the "update_time" field in the mutation.
func (m *SysMenuMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
v := m.update_time
if v == nil {
return
}
return *v, true
}
// OldUpdateTime returns the old "update_time" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
}
return oldValue.UpdateTime, nil
}
// ResetUpdateTime resets all changes to the "update_time" field.
func (m *SysMenuMutation) ResetUpdateTime() {
m.update_time = nil
}
// SetName sets the "name" field.
func (m *SysMenuMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *SysMenuMutation) 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 SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) 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 *SysMenuMutation) ResetName() {
m.name = nil
}
// SetLabel sets the "label" field.
func (m *SysMenuMutation) SetLabel(s string) {
m.label = &s
}
// Label returns the value of the "label" field in the mutation.
func (m *SysMenuMutation) Label() (r string, exists bool) {
v := m.label
if v == nil {
return
}
return *v, true
}
// OldLabel returns the old "label" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldLabel(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLabel is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldLabel requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLabel: %w", err)
}
return oldValue.Label, nil
}
// ResetLabel resets all changes to the "label" field.
func (m *SysMenuMutation) ResetLabel() {
m.label = nil
}
// SetType sets the "type" field.
func (m *SysMenuMutation) SetType(s sysmenu.Type) {
m._type = &s
}
// GetType returns the value of the "type" field in the mutation.
func (m *SysMenuMutation) GetType() (r sysmenu.Type, exists bool) {
v := m._type
if v == nil {
return
}
return *v, true
}
// OldType returns the old "type" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldType(ctx context.Context) (v sysmenu.Type, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldType is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldType requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldType: %w", err)
}
return oldValue.Type, nil
}
// ResetType resets all changes to the "type" field.
func (m *SysMenuMutation) ResetType() {
m._type = nil
}
// SetLink sets the "link" field.
func (m *SysMenuMutation) SetLink(s string) {
m.link = &s
}
// Link returns the value of the "link" field in the mutation.
func (m *SysMenuMutation) Link() (r string, exists bool) {
v := m.link
if v == nil {
return
}
return *v, true
}
// OldLink returns the old "link" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldLink(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLink is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldLink requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLink: %w", err)
}
return oldValue.Link, nil
}
// ClearLink clears the value of the "link" field.
func (m *SysMenuMutation) ClearLink() {
m.link = nil
m.clearedFields[sysmenu.FieldLink] = struct{}{}
}
// LinkCleared returns if the "link" field was cleared in this mutation.
func (m *SysMenuMutation) LinkCleared() bool {
_, ok := m.clearedFields[sysmenu.FieldLink]
return ok
}
// ResetLink resets all changes to the "link" field.
func (m *SysMenuMutation) ResetLink() {
m.link = nil
delete(m.clearedFields, sysmenu.FieldLink)
}
// SetPermission sets the "permission" field.
func (m *SysMenuMutation) SetPermission(s string) {
m.permission = &s
}
// Permission returns the value of the "permission" field in the mutation.
func (m *SysMenuMutation) Permission() (r string, exists bool) {
v := m.permission
if v == nil {
return
}
return *v, true
}
// OldPermission returns the old "permission" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldPermission(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPermission is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPermission requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPermission: %w", err)
}
return oldValue.Permission, nil
}
// ResetPermission resets all changes to the "permission" field.
func (m *SysMenuMutation) ResetPermission() {
m.permission = nil
}
// SetRoute sets the "route" field.
func (m *SysMenuMutation) SetRoute(s string) {
m.route = &s
}
// Route returns the value of the "route" field in the mutation.
func (m *SysMenuMutation) Route() (r string, exists bool) {
v := m.route
if v == nil {
return
}
return *v, true
}
// OldRoute returns the old "route" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldRoute(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRoute is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRoute requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRoute: %w", err)
}
return oldValue.Route, nil
}
// ClearRoute clears the value of the "route" field.
func (m *SysMenuMutation) ClearRoute() {
m.route = nil
m.clearedFields[sysmenu.FieldRoute] = struct{}{}
}
// RouteCleared returns if the "route" field was cleared in this mutation.
func (m *SysMenuMutation) RouteCleared() bool {
_, ok := m.clearedFields[sysmenu.FieldRoute]
return ok
}
// ResetRoute resets all changes to the "route" field.
func (m *SysMenuMutation) ResetRoute() {
m.route = nil
delete(m.clearedFields, sysmenu.FieldRoute)
}
// SetComponent sets the "component" field.
func (m *SysMenuMutation) SetComponent(s string) {
m.component = &s
}
// Component returns the value of the "component" field in the mutation.
func (m *SysMenuMutation) Component() (r string, exists bool) {
v := m.component
if v == nil {
return
}
return *v, true
}
// OldComponent returns the old "component" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldComponent(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldComponent is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldComponent requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldComponent: %w", err)
}
return oldValue.Component, nil
}
// ClearComponent clears the value of the "component" field.
func (m *SysMenuMutation) ClearComponent() {
m.component = nil
m.clearedFields[sysmenu.FieldComponent] = struct{}{}
}
// ComponentCleared returns if the "component" field was cleared in this mutation.
func (m *SysMenuMutation) ComponentCleared() bool {
_, ok := m.clearedFields[sysmenu.FieldComponent]
return ok
}
// ResetComponent resets all changes to the "component" field.
func (m *SysMenuMutation) ResetComponent() {
m.component = nil
delete(m.clearedFields, sysmenu.FieldComponent)
}
// SetKeepAlive sets the "keep_alive" field.
func (m *SysMenuMutation) SetKeepAlive(b bool) {
m.keep_alive = &b
}
// KeepAlive returns the value of the "keep_alive" field in the mutation.
func (m *SysMenuMutation) KeepAlive() (r bool, exists bool) {
v := m.keep_alive
if v == nil {
return
}
return *v, true
}
// OldKeepAlive returns the old "keep_alive" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldKeepAlive(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldKeepAlive is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldKeepAlive requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldKeepAlive: %w", err)
}
return oldValue.KeepAlive, nil
}
// ResetKeepAlive resets all changes to the "keep_alive" field.
func (m *SysMenuMutation) ResetKeepAlive() {
m.keep_alive = nil
}
// SetHidden sets the "hidden" field.
func (m *SysMenuMutation) SetHidden(b bool) {
m.hidden = &b
}
// Hidden returns the value of the "hidden" field in the mutation.
func (m *SysMenuMutation) Hidden() (r bool, exists bool) {
v := m.hidden
if v == nil {
return
}
return *v, true
}
// OldHidden returns the old "hidden" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldHidden(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldHidden is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldHidden requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldHidden: %w", err)
}
return oldValue.Hidden, nil
}
// ResetHidden resets all changes to the "hidden" field.
func (m *SysMenuMutation) ResetHidden() {
m.hidden = nil
}
// SetIcon sets the "icon" field.
func (m *SysMenuMutation) SetIcon(s string) {
m.icon = &s
}
// Icon returns the value of the "icon" field in the mutation.
func (m *SysMenuMutation) 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 SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) 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
}
// ClearIcon clears the value of the "icon" field.
func (m *SysMenuMutation) ClearIcon() {
m.icon = nil
m.clearedFields[sysmenu.FieldIcon] = struct{}{}
}
// IconCleared returns if the "icon" field was cleared in this mutation.
func (m *SysMenuMutation) IconCleared() bool {
_, ok := m.clearedFields[sysmenu.FieldIcon]
return ok
}
// ResetIcon resets all changes to the "icon" field.
func (m *SysMenuMutation) ResetIcon() {
m.icon = nil
delete(m.clearedFields, sysmenu.FieldIcon)
}
// SetOrder sets the "order" field.
func (m *SysMenuMutation) SetOrder(u uint) {
m._order = &u
m.add_order = nil
}
// Order returns the value of the "order" field in the mutation.
func (m *SysMenuMutation) Order() (r uint, exists bool) {
v := m._order
if v == nil {
return
}
return *v, true
}
// OldOrder returns the old "order" field's value of the SysMenu entity.
// If the SysMenu 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 *SysMenuMutation) OldOrder(ctx context.Context) (v uint, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldOrder is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldOrder requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldOrder: %w", err)
}
return oldValue.Order, nil
}
// AddOrder adds u to the "order" field.
func (m *SysMenuMutation) AddOrder(u int) {
if m.add_order != nil {
*m.add_order += u
} else {
m.add_order = &u
}
}
// AddedOrder returns the value that was added to the "order" field in this mutation.
func (m *SysMenuMutation) AddedOrder() (r int, exists bool) {
v := m.add_order
if v == nil {
return
}
return *v, true
}
// ResetOrder resets all changes to the "order" field.
func (m *SysMenuMutation) ResetOrder() {
m._order = nil
m.add_order = nil
}
// AddRoleIDs adds the "roles" edge to the SysRole entity by ids.
func (m *SysMenuMutation) AddRoleIDs(ids ...int64) {
if m.roles == nil {
m.roles = make(map[int64]struct{})
}
for i := range ids {
m.roles[ids[i]] = struct{}{}
}
}
// ClearRoles clears the "roles" edge to the SysRole entity.
func (m *SysMenuMutation) ClearRoles() {
m.clearedroles = true
}
// RolesCleared reports if the "roles" edge to the SysRole entity was cleared.
func (m *SysMenuMutation) RolesCleared() bool {
return m.clearedroles
}
// RemoveRoleIDs removes the "roles" edge to the SysRole entity by IDs.
func (m *SysMenuMutation) RemoveRoleIDs(ids ...int64) {
if m.removedroles == nil {
m.removedroles = make(map[int64]struct{})
}
for i := range ids {
delete(m.roles, ids[i])
m.removedroles[ids[i]] = struct{}{}
}
}
// RemovedRoles returns the removed IDs of the "roles" edge to the SysRole entity.
func (m *SysMenuMutation) RemovedRolesIDs() (ids []int64) {
for id := range m.removedroles {
ids = append(ids, id)
}
return
}
// RolesIDs returns the "roles" edge IDs in the mutation.
func (m *SysMenuMutation) RolesIDs() (ids []int64) {
for id := range m.roles {
ids = append(ids, id)
}
return
}
// ResetRoles resets all changes to the "roles" edge.
func (m *SysMenuMutation) ResetRoles() {
m.roles = nil
m.clearedroles = false
m.removedroles = nil
}
// SetParentID sets the "parent" edge to the SysMenu entity by id.
func (m *SysMenuMutation) SetParentID(id int64) {
m.parent = &id
}
// ClearParent clears the "parent" edge to the SysMenu entity.
func (m *SysMenuMutation) ClearParent() {
m.clearedparent = true
}
// ParentCleared reports if the "parent" edge to the SysMenu entity was cleared.
func (m *SysMenuMutation) ParentCleared() bool {
return m.clearedparent
}
// ParentID returns the "parent" edge ID in the mutation.
func (m *SysMenuMutation) ParentID() (id int64, exists bool) {
if m.parent != nil {
return *m.parent, true
}
return
}
// ParentIDs returns the "parent" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// ParentID instead. It exists only for internal usage by the builders.
func (m *SysMenuMutation) ParentIDs() (ids []int64) {
if id := m.parent; id != nil {
ids = append(ids, *id)
}
return
}
// ResetParent resets all changes to the "parent" edge.
func (m *SysMenuMutation) ResetParent() {
m.parent = nil
m.clearedparent = false
}
// AddChildIDs adds the "children" edge to the SysMenu entity by ids.
func (m *SysMenuMutation) AddChildIDs(ids ...int64) {
if m.children == nil {
m.children = make(map[int64]struct{})
}
for i := range ids {
m.children[ids[i]] = struct{}{}
}
}
// ClearChildren clears the "children" edge to the SysMenu entity.
func (m *SysMenuMutation) ClearChildren() {
m.clearedchildren = true
}
// ChildrenCleared reports if the "children" edge to the SysMenu entity was cleared.
func (m *SysMenuMutation) ChildrenCleared() bool {
return m.clearedchildren
}
// RemoveChildIDs removes the "children" edge to the SysMenu entity by IDs.
func (m *SysMenuMutation) RemoveChildIDs(ids ...int64) {
if m.removedchildren == nil {
m.removedchildren = make(map[int64]struct{})
}
for i := range ids {
delete(m.children, ids[i])
m.removedchildren[ids[i]] = struct{}{}
}
}
// RemovedChildren returns the removed IDs of the "children" edge to the SysMenu entity.
func (m *SysMenuMutation) RemovedChildrenIDs() (ids []int64) {
for id := range m.removedchildren {
ids = append(ids, id)
}
return
}
// ChildrenIDs returns the "children" edge IDs in the mutation.
func (m *SysMenuMutation) ChildrenIDs() (ids []int64) {
for id := range m.children {
ids = append(ids, id)
}
return
}
// ResetChildren resets all changes to the "children" edge.
func (m *SysMenuMutation) ResetChildren() {
m.children = nil
m.clearedchildren = false
m.removedchildren = nil
}
// Where appends a list predicates to the SysMenuMutation builder.
func (m *SysMenuMutation) Where(ps ...predicate.SysMenu) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the SysMenuMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SysMenuMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.SysMenu, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *SysMenuMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *SysMenuMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (SysMenu).
func (m *SysMenuMutation) 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 *SysMenuMutation) Fields() []string {
fields := make([]string, 0, 13)
if m.create_time != nil {
fields = append(fields, sysmenu.FieldCreateTime)
}
if m.update_time != nil {
fields = append(fields, sysmenu.FieldUpdateTime)
}
if m.name != nil {
fields = append(fields, sysmenu.FieldName)
}
if m.label != nil {
fields = append(fields, sysmenu.FieldLabel)
}
if m._type != nil {
fields = append(fields, sysmenu.FieldType)
}
if m.link != nil {
fields = append(fields, sysmenu.FieldLink)
}
if m.permission != nil {
fields = append(fields, sysmenu.FieldPermission)
}
if m.route != nil {
fields = append(fields, sysmenu.FieldRoute)
}
if m.component != nil {
fields = append(fields, sysmenu.FieldComponent)
}
if m.keep_alive != nil {
fields = append(fields, sysmenu.FieldKeepAlive)
}
if m.hidden != nil {
fields = append(fields, sysmenu.FieldHidden)
}
if m.icon != nil {
fields = append(fields, sysmenu.FieldIcon)
}
if m._order != nil {
fields = append(fields, sysmenu.FieldOrder)
}
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 *SysMenuMutation) Field(name string) (ent.Value, bool) {
switch name {
case sysmenu.FieldCreateTime:
return m.CreateTime()
case sysmenu.FieldUpdateTime:
return m.UpdateTime()
case sysmenu.FieldName:
return m.Name()
case sysmenu.FieldLabel:
return m.Label()
case sysmenu.FieldType:
return m.GetType()
case sysmenu.FieldLink:
return m.Link()
case sysmenu.FieldPermission:
return m.Permission()
case sysmenu.FieldRoute:
return m.Route()
case sysmenu.FieldComponent:
return m.Component()
case sysmenu.FieldKeepAlive:
return m.KeepAlive()
case sysmenu.FieldHidden:
return m.Hidden()
case sysmenu.FieldIcon:
return m.Icon()
case sysmenu.FieldOrder:
return m.Order()
}
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 *SysMenuMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case sysmenu.FieldCreateTime:
return m.OldCreateTime(ctx)
case sysmenu.FieldUpdateTime:
return m.OldUpdateTime(ctx)
case sysmenu.FieldName:
return m.OldName(ctx)
case sysmenu.FieldLabel:
return m.OldLabel(ctx)
case sysmenu.FieldType:
return m.OldType(ctx)
case sysmenu.FieldLink:
return m.OldLink(ctx)
case sysmenu.FieldPermission:
return m.OldPermission(ctx)
case sysmenu.FieldRoute:
return m.OldRoute(ctx)
case sysmenu.FieldComponent:
return m.OldComponent(ctx)
case sysmenu.FieldKeepAlive:
return m.OldKeepAlive(ctx)
case sysmenu.FieldHidden:
return m.OldHidden(ctx)
case sysmenu.FieldIcon:
return m.OldIcon(ctx)
case sysmenu.FieldOrder:
return m.OldOrder(ctx)
}
return nil, fmt.Errorf("unknown SysMenu 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 *SysMenuMutation) SetField(name string, value ent.Value) error {
switch name {
case sysmenu.FieldCreateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil
case sysmenu.FieldUpdateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdateTime(v)
return nil
case sysmenu.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case sysmenu.FieldLabel:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLabel(v)
return nil
case sysmenu.FieldType:
v, ok := value.(sysmenu.Type)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetType(v)
return nil
case sysmenu.FieldLink:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLink(v)
return nil
case sysmenu.FieldPermission:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPermission(v)
return nil
case sysmenu.FieldRoute:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRoute(v)
return nil
case sysmenu.FieldComponent:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetComponent(v)
return nil
case sysmenu.FieldKeepAlive:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetKeepAlive(v)
return nil
case sysmenu.FieldHidden:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetHidden(v)
return nil
case sysmenu.FieldIcon:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIcon(v)
return nil
case sysmenu.FieldOrder:
v, ok := value.(uint)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetOrder(v)
return nil
}
return fmt.Errorf("unknown SysMenu field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SysMenuMutation) AddedFields() []string {
var fields []string
if m.add_order != nil {
fields = append(fields, sysmenu.FieldOrder)
}
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 *SysMenuMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case sysmenu.FieldOrder:
return m.AddedOrder()
}
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 *SysMenuMutation) AddField(name string, value ent.Value) error {
switch name {
case sysmenu.FieldOrder:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddOrder(v)
return nil
}
return fmt.Errorf("unknown SysMenu numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SysMenuMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(sysmenu.FieldLink) {
fields = append(fields, sysmenu.FieldLink)
}
if m.FieldCleared(sysmenu.FieldRoute) {
fields = append(fields, sysmenu.FieldRoute)
}
if m.FieldCleared(sysmenu.FieldComponent) {
fields = append(fields, sysmenu.FieldComponent)
}
if m.FieldCleared(sysmenu.FieldIcon) {
fields = append(fields, sysmenu.FieldIcon)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SysMenuMutation) 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 *SysMenuMutation) ClearField(name string) error {
switch name {
case sysmenu.FieldLink:
m.ClearLink()
return nil
case sysmenu.FieldRoute:
m.ClearRoute()
return nil
case sysmenu.FieldComponent:
m.ClearComponent()
return nil
case sysmenu.FieldIcon:
m.ClearIcon()
return nil
}
return fmt.Errorf("unknown SysMenu 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 *SysMenuMutation) ResetField(name string) error {
switch name {
case sysmenu.FieldCreateTime:
m.ResetCreateTime()
return nil
case sysmenu.FieldUpdateTime:
m.ResetUpdateTime()
return nil
case sysmenu.FieldName:
m.ResetName()
return nil
case sysmenu.FieldLabel:
m.ResetLabel()
return nil
case sysmenu.FieldType:
m.ResetType()
return nil
case sysmenu.FieldLink:
m.ResetLink()
return nil
case sysmenu.FieldPermission:
m.ResetPermission()
return nil
case sysmenu.FieldRoute:
m.ResetRoute()
return nil
case sysmenu.FieldComponent:
m.ResetComponent()
return nil
case sysmenu.FieldKeepAlive:
m.ResetKeepAlive()
return nil
case sysmenu.FieldHidden:
m.ResetHidden()
return nil
case sysmenu.FieldIcon:
m.ResetIcon()
return nil
case sysmenu.FieldOrder:
m.ResetOrder()
return nil
}
return fmt.Errorf("unknown SysMenu field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SysMenuMutation) AddedEdges() []string {
edges := make([]string, 0, 3)
if m.roles != nil {
edges = append(edges, sysmenu.EdgeRoles)
}
if m.parent != nil {
edges = append(edges, sysmenu.EdgeParent)
}
if m.children != nil {
edges = append(edges, sysmenu.EdgeChildren)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SysMenuMutation) AddedIDs(name string) []ent.Value {
switch name {
case sysmenu.EdgeRoles:
ids := make([]ent.Value, 0, len(m.roles))
for id := range m.roles {
ids = append(ids, id)
}
return ids
case sysmenu.EdgeParent:
if id := m.parent; id != nil {
return []ent.Value{*id}
}
case sysmenu.EdgeChildren:
ids := make([]ent.Value, 0, len(m.children))
for id := range m.children {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SysMenuMutation) RemovedEdges() []string {
edges := make([]string, 0, 3)
if m.removedroles != nil {
edges = append(edges, sysmenu.EdgeRoles)
}
if m.removedchildren != nil {
edges = append(edges, sysmenu.EdgeChildren)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SysMenuMutation) RemovedIDs(name string) []ent.Value {
switch name {
case sysmenu.EdgeRoles:
ids := make([]ent.Value, 0, len(m.removedroles))
for id := range m.removedroles {
ids = append(ids, id)
}
return ids
case sysmenu.EdgeChildren:
ids := make([]ent.Value, 0, len(m.removedchildren))
for id := range m.removedchildren {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SysMenuMutation) ClearedEdges() []string {
edges := make([]string, 0, 3)
if m.clearedroles {
edges = append(edges, sysmenu.EdgeRoles)
}
if m.clearedparent {
edges = append(edges, sysmenu.EdgeParent)
}
if m.clearedchildren {
edges = append(edges, sysmenu.EdgeChildren)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SysMenuMutation) EdgeCleared(name string) bool {
switch name {
case sysmenu.EdgeRoles:
return m.clearedroles
case sysmenu.EdgeParent:
return m.clearedparent
case sysmenu.EdgeChildren:
return m.clearedchildren
}
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 *SysMenuMutation) ClearEdge(name string) error {
switch name {
case sysmenu.EdgeParent:
m.ClearParent()
return nil
}
return fmt.Errorf("unknown SysMenu 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 *SysMenuMutation) ResetEdge(name string) error {
switch name {
case sysmenu.EdgeRoles:
m.ResetRoles()
return nil
case sysmenu.EdgeParent:
m.ResetParent()
return nil
case sysmenu.EdgeChildren:
m.ResetChildren()
return nil
}
return fmt.Errorf("unknown SysMenu edge %s", name)
}
// SysRoleMutation represents an operation that mutates the SysRole nodes in the graph.
type SysRoleMutation struct {
config
op Op
typ string
id *int64
create_time **ent2.CustomTime
update_time **ent2.CustomTime
label *string
name *string
description *string
_order *uint
add_order *int
clearedFields map[string]struct{}
menus map[int64]struct{}
removedmenus map[int64]struct{}
clearedmenus bool
users map[int64]struct{}
removedusers map[int64]struct{}
clearedusers bool
done bool
oldValue func(context.Context) (*SysRole, error)
predicates []predicate.SysRole
}
var _ ent.Mutation = (*SysRoleMutation)(nil)
// sysroleOption allows management of the mutation configuration using functional options.
type sysroleOption func(*SysRoleMutation)
// newSysRoleMutation creates new mutation for the SysRole entity.
func newSysRoleMutation(c config, op Op, opts ...sysroleOption) *SysRoleMutation {
m := &SysRoleMutation{
config: c,
op: op,
typ: TypeSysRole,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withSysRoleID sets the ID field of the mutation.
func withSysRoleID(id int64) sysroleOption {
return func(m *SysRoleMutation) {
var (
err error
once sync.Once
value *SysRole
)
m.oldValue = func(ctx context.Context) (*SysRole, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().SysRole.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withSysRole sets the old SysRole of the mutation.
func withSysRole(node *SysRole) sysroleOption {
return func(m *SysRoleMutation) {
m.oldValue = func(context.Context) (*SysRole, 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 SysRoleMutation) 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 SysRoleMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *SysRoleMutation) ID() (id int64, 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 *SysRoleMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().SysRole.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreateTime sets the "create_time" field.
func (m *SysRoleMutation) SetCreateTime(et *ent2.CustomTime) {
m.create_time = &et
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *SysRoleMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the SysRole entity.
// If the SysRole 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 *SysRoleMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *SysRoleMutation) ResetCreateTime() {
m.create_time = nil
}
// SetUpdateTime sets the "update_time" field.
func (m *SysRoleMutation) SetUpdateTime(et *ent2.CustomTime) {
m.update_time = &et
}
// UpdateTime returns the value of the "update_time" field in the mutation.
func (m *SysRoleMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
v := m.update_time
if v == nil {
return
}
return *v, true
}
// OldUpdateTime returns the old "update_time" field's value of the SysRole entity.
// If the SysRole 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 *SysRoleMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
}
return oldValue.UpdateTime, nil
}
// ResetUpdateTime resets all changes to the "update_time" field.
func (m *SysRoleMutation) ResetUpdateTime() {
m.update_time = nil
}
// SetLabel sets the "label" field.
func (m *SysRoleMutation) SetLabel(s string) {
m.label = &s
}
// Label returns the value of the "label" field in the mutation.
func (m *SysRoleMutation) Label() (r string, exists bool) {
v := m.label
if v == nil {
return
}
return *v, true
}
// OldLabel returns the old "label" field's value of the SysRole entity.
// If the SysRole 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 *SysRoleMutation) OldLabel(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLabel is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldLabel requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLabel: %w", err)
}
return oldValue.Label, nil
}
// ResetLabel resets all changes to the "label" field.
func (m *SysRoleMutation) ResetLabel() {
m.label = nil
}
// SetName sets the "name" field.
func (m *SysRoleMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *SysRoleMutation) 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 SysRole entity.
// If the SysRole 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 *SysRoleMutation) 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 *SysRoleMutation) ResetName() {
m.name = nil
}
// SetDescription sets the "description" field.
func (m *SysRoleMutation) SetDescription(s string) {
m.description = &s
}
// Description returns the value of the "description" field in the mutation.
func (m *SysRoleMutation) Description() (r string, exists bool) {
v := m.description
if v == nil {
return
}
return *v, true
}
// OldDescription returns the old "description" field's value of the SysRole entity.
// If the SysRole 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 *SysRoleMutation) OldDescription(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDescription is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDescription requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDescription: %w", err)
}
return oldValue.Description, nil
}
// ResetDescription resets all changes to the "description" field.
func (m *SysRoleMutation) ResetDescription() {
m.description = nil
}
// SetOrder sets the "order" field.
func (m *SysRoleMutation) SetOrder(u uint) {
m._order = &u
m.add_order = nil
}
// Order returns the value of the "order" field in the mutation.
func (m *SysRoleMutation) Order() (r uint, exists bool) {
v := m._order
if v == nil {
return
}
return *v, true
}
// OldOrder returns the old "order" field's value of the SysRole entity.
// If the SysRole 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 *SysRoleMutation) OldOrder(ctx context.Context) (v uint, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldOrder is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldOrder requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldOrder: %w", err)
}
return oldValue.Order, nil
}
// AddOrder adds u to the "order" field.
func (m *SysRoleMutation) AddOrder(u int) {
if m.add_order != nil {
*m.add_order += u
} else {
m.add_order = &u
}
}
// AddedOrder returns the value that was added to the "order" field in this mutation.
func (m *SysRoleMutation) AddedOrder() (r int, exists bool) {
v := m.add_order
if v == nil {
return
}
return *v, true
}
// ResetOrder resets all changes to the "order" field.
func (m *SysRoleMutation) ResetOrder() {
m._order = nil
m.add_order = nil
}
// AddMenuIDs adds the "menus" edge to the SysMenu entity by ids.
func (m *SysRoleMutation) AddMenuIDs(ids ...int64) {
if m.menus == nil {
m.menus = make(map[int64]struct{})
}
for i := range ids {
m.menus[ids[i]] = struct{}{}
}
}
// ClearMenus clears the "menus" edge to the SysMenu entity.
func (m *SysRoleMutation) ClearMenus() {
m.clearedmenus = true
}
// MenusCleared reports if the "menus" edge to the SysMenu entity was cleared.
func (m *SysRoleMutation) MenusCleared() bool {
return m.clearedmenus
}
// RemoveMenuIDs removes the "menus" edge to the SysMenu entity by IDs.
func (m *SysRoleMutation) RemoveMenuIDs(ids ...int64) {
if m.removedmenus == nil {
m.removedmenus = make(map[int64]struct{})
}
for i := range ids {
delete(m.menus, ids[i])
m.removedmenus[ids[i]] = struct{}{}
}
}
// RemovedMenus returns the removed IDs of the "menus" edge to the SysMenu entity.
func (m *SysRoleMutation) RemovedMenusIDs() (ids []int64) {
for id := range m.removedmenus {
ids = append(ids, id)
}
return
}
// MenusIDs returns the "menus" edge IDs in the mutation.
func (m *SysRoleMutation) MenusIDs() (ids []int64) {
for id := range m.menus {
ids = append(ids, id)
}
return
}
// ResetMenus resets all changes to the "menus" edge.
func (m *SysRoleMutation) ResetMenus() {
m.menus = nil
m.clearedmenus = false
m.removedmenus = nil
}
// AddUserIDs adds the "users" edge to the SysUser entity by ids.
func (m *SysRoleMutation) AddUserIDs(ids ...int64) {
if m.users == nil {
m.users = make(map[int64]struct{})
}
for i := range ids {
m.users[ids[i]] = struct{}{}
}
}
// ClearUsers clears the "users" edge to the SysUser entity.
func (m *SysRoleMutation) ClearUsers() {
m.clearedusers = true
}
// UsersCleared reports if the "users" edge to the SysUser entity was cleared.
func (m *SysRoleMutation) UsersCleared() bool {
return m.clearedusers
}
// RemoveUserIDs removes the "users" edge to the SysUser entity by IDs.
func (m *SysRoleMutation) RemoveUserIDs(ids ...int64) {
if m.removedusers == nil {
m.removedusers = make(map[int64]struct{})
}
for i := range ids {
delete(m.users, ids[i])
m.removedusers[ids[i]] = struct{}{}
}
}
// RemovedUsers returns the removed IDs of the "users" edge to the SysUser entity.
func (m *SysRoleMutation) RemovedUsersIDs() (ids []int64) {
for id := range m.removedusers {
ids = append(ids, id)
}
return
}
// UsersIDs returns the "users" edge IDs in the mutation.
func (m *SysRoleMutation) UsersIDs() (ids []int64) {
for id := range m.users {
ids = append(ids, id)
}
return
}
// ResetUsers resets all changes to the "users" edge.
func (m *SysRoleMutation) ResetUsers() {
m.users = nil
m.clearedusers = false
m.removedusers = nil
}
// Where appends a list predicates to the SysRoleMutation builder.
func (m *SysRoleMutation) Where(ps ...predicate.SysRole) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the SysRoleMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SysRoleMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.SysRole, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *SysRoleMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *SysRoleMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (SysRole).
func (m *SysRoleMutation) 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 *SysRoleMutation) Fields() []string {
fields := make([]string, 0, 6)
if m.create_time != nil {
fields = append(fields, sysrole.FieldCreateTime)
}
if m.update_time != nil {
fields = append(fields, sysrole.FieldUpdateTime)
}
if m.label != nil {
fields = append(fields, sysrole.FieldLabel)
}
if m.name != nil {
fields = append(fields, sysrole.FieldName)
}
if m.description != nil {
fields = append(fields, sysrole.FieldDescription)
}
if m._order != nil {
fields = append(fields, sysrole.FieldOrder)
}
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 *SysRoleMutation) Field(name string) (ent.Value, bool) {
switch name {
case sysrole.FieldCreateTime:
return m.CreateTime()
case sysrole.FieldUpdateTime:
return m.UpdateTime()
case sysrole.FieldLabel:
return m.Label()
case sysrole.FieldName:
return m.Name()
case sysrole.FieldDescription:
return m.Description()
case sysrole.FieldOrder:
return m.Order()
}
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 *SysRoleMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case sysrole.FieldCreateTime:
return m.OldCreateTime(ctx)
case sysrole.FieldUpdateTime:
return m.OldUpdateTime(ctx)
case sysrole.FieldLabel:
return m.OldLabel(ctx)
case sysrole.FieldName:
return m.OldName(ctx)
case sysrole.FieldDescription:
return m.OldDescription(ctx)
case sysrole.FieldOrder:
return m.OldOrder(ctx)
}
return nil, fmt.Errorf("unknown SysRole 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 *SysRoleMutation) SetField(name string, value ent.Value) error {
switch name {
case sysrole.FieldCreateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil
case sysrole.FieldUpdateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdateTime(v)
return nil
case sysrole.FieldLabel:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLabel(v)
return nil
case sysrole.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case sysrole.FieldDescription:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDescription(v)
return nil
case sysrole.FieldOrder:
v, ok := value.(uint)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetOrder(v)
return nil
}
return fmt.Errorf("unknown SysRole field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SysRoleMutation) AddedFields() []string {
var fields []string
if m.add_order != nil {
fields = append(fields, sysrole.FieldOrder)
}
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 *SysRoleMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case sysrole.FieldOrder:
return m.AddedOrder()
}
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 *SysRoleMutation) AddField(name string, value ent.Value) error {
switch name {
case sysrole.FieldOrder:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddOrder(v)
return nil
}
return fmt.Errorf("unknown SysRole numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SysRoleMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SysRoleMutation) 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 *SysRoleMutation) ClearField(name string) error {
return fmt.Errorf("unknown SysRole 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 *SysRoleMutation) ResetField(name string) error {
switch name {
case sysrole.FieldCreateTime:
m.ResetCreateTime()
return nil
case sysrole.FieldUpdateTime:
m.ResetUpdateTime()
return nil
case sysrole.FieldLabel:
m.ResetLabel()
return nil
case sysrole.FieldName:
m.ResetName()
return nil
case sysrole.FieldDescription:
m.ResetDescription()
return nil
case sysrole.FieldOrder:
m.ResetOrder()
return nil
}
return fmt.Errorf("unknown SysRole field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SysRoleMutation) AddedEdges() []string {
edges := make([]string, 0, 2)
if m.menus != nil {
edges = append(edges, sysrole.EdgeMenus)
}
if m.users != nil {
edges = append(edges, sysrole.EdgeUsers)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SysRoleMutation) AddedIDs(name string) []ent.Value {
switch name {
case sysrole.EdgeMenus:
ids := make([]ent.Value, 0, len(m.menus))
for id := range m.menus {
ids = append(ids, id)
}
return ids
case sysrole.EdgeUsers:
ids := make([]ent.Value, 0, len(m.users))
for id := range m.users {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SysRoleMutation) RemovedEdges() []string {
edges := make([]string, 0, 2)
if m.removedmenus != nil {
edges = append(edges, sysrole.EdgeMenus)
}
if m.removedusers != nil {
edges = append(edges, sysrole.EdgeUsers)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SysRoleMutation) RemovedIDs(name string) []ent.Value {
switch name {
case sysrole.EdgeMenus:
ids := make([]ent.Value, 0, len(m.removedmenus))
for id := range m.removedmenus {
ids = append(ids, id)
}
return ids
case sysrole.EdgeUsers:
ids := make([]ent.Value, 0, len(m.removedusers))
for id := range m.removedusers {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SysRoleMutation) ClearedEdges() []string {
edges := make([]string, 0, 2)
if m.clearedmenus {
edges = append(edges, sysrole.EdgeMenus)
}
if m.clearedusers {
edges = append(edges, sysrole.EdgeUsers)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SysRoleMutation) EdgeCleared(name string) bool {
switch name {
case sysrole.EdgeMenus:
return m.clearedmenus
case sysrole.EdgeUsers:
return m.clearedusers
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *SysRoleMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown SysRole 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 *SysRoleMutation) ResetEdge(name string) error {
switch name {
case sysrole.EdgeMenus:
m.ResetMenus()
return nil
case sysrole.EdgeUsers:
m.ResetUsers()
return nil
}
return fmt.Errorf("unknown SysRole edge %s", name)
}
// SysUserMutation represents an operation that mutates the SysUser nodes in the graph.
type SysUserMutation struct {
config
op Op
typ string
id *int64
create_time **ent2.CustomTime
update_time **ent2.CustomTime
username *string
password *string
email *string
invite_code *string
balance *decimal.Decimal
block *bool
verify *bool
invite_cashback *decimal.Decimal
clearedFields map[string]struct{}
parent *int64
clearedparent bool
children map[int64]struct{}
removedchildren map[int64]struct{}
clearedchildren bool
roles map[int64]struct{}
removedroles map[int64]struct{}
clearedroles bool
agent *int64
clearedagent bool
images map[int64]struct{}
removedimages map[int64]struct{}
clearedimages bool
cpuser map[int64]struct{}
removedcpuser map[int64]struct{}
clearedcpuser bool
cp_task map[int64]struct{}
removedcp_task map[int64]struct{}
clearedcp_task bool
cp_task_logs map[int64]struct{}
removedcp_task_logs map[int64]struct{}
clearedcp_task_logs bool
created_cards map[int64]struct{}
removedcreated_cards map[int64]struct{}
clearedcreated_cards bool
used_cards map[int64]struct{}
removedused_cards map[int64]struct{}
clearedused_cards bool
cashback_cards map[int64]struct{}
removedcashback_cards map[int64]struct{}
clearedcashback_cards bool
done bool
oldValue func(context.Context) (*SysUser, error)
predicates []predicate.SysUser
}
var _ ent.Mutation = (*SysUserMutation)(nil)
// sysuserOption allows management of the mutation configuration using functional options.
type sysuserOption func(*SysUserMutation)
// newSysUserMutation creates new mutation for the SysUser entity.
func newSysUserMutation(c config, op Op, opts ...sysuserOption) *SysUserMutation {
m := &SysUserMutation{
config: c,
op: op,
typ: TypeSysUser,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withSysUserID sets the ID field of the mutation.
func withSysUserID(id int64) sysuserOption {
return func(m *SysUserMutation) {
var (
err error
once sync.Once
value *SysUser
)
m.oldValue = func(ctx context.Context) (*SysUser, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().SysUser.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withSysUser sets the old SysUser of the mutation.
func withSysUser(node *SysUser) sysuserOption {
return func(m *SysUserMutation) {
m.oldValue = func(context.Context) (*SysUser, 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 SysUserMutation) 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 SysUserMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *SysUserMutation) ID() (id int64, 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 *SysUserMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().SysUser.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreateTime sets the "create_time" field.
func (m *SysUserMutation) SetCreateTime(et *ent2.CustomTime) {
m.create_time = &et
}
// CreateTime returns the value of the "create_time" field in the mutation.
func (m *SysUserMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
v := m.create_time
if v == nil {
return
}
return *v, true
}
// OldCreateTime returns the old "create_time" field's value of the SysUser entity.
// If the SysUser 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 *SysUserMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
}
return oldValue.CreateTime, nil
}
// ResetCreateTime resets all changes to the "create_time" field.
func (m *SysUserMutation) ResetCreateTime() {
m.create_time = nil
}
// SetUpdateTime sets the "update_time" field.
func (m *SysUserMutation) SetUpdateTime(et *ent2.CustomTime) {
m.update_time = &et
}
// UpdateTime returns the value of the "update_time" field in the mutation.
func (m *SysUserMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
v := m.update_time
if v == nil {
return
}
return *v, true
}
// OldUpdateTime returns the old "update_time" field's value of the SysUser entity.
// If the SysUser 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 *SysUserMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
}
return oldValue.UpdateTime, nil
}
// ResetUpdateTime resets all changes to the "update_time" field.
func (m *SysUserMutation) ResetUpdateTime() {
m.update_time = nil
}
// SetUsername sets the "username" field.
func (m *SysUserMutation) SetUsername(s string) {
m.username = &s
}
// Username returns the value of the "username" field in the mutation.
func (m *SysUserMutation) 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 SysUser entity.
// If the SysUser 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 *SysUserMutation) 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 *SysUserMutation) ResetUsername() {
m.username = nil
}
// SetPassword sets the "password" field.
func (m *SysUserMutation) SetPassword(s string) {
m.password = &s
}
// Password returns the value of the "password" field in the mutation.
func (m *SysUserMutation) 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 SysUser entity.
// If the SysUser 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 *SysUserMutation) 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 *SysUserMutation) ResetPassword() {
m.password = nil
}
// SetEmail sets the "email" field.
func (m *SysUserMutation) SetEmail(s string) {
m.email = &s
}
// Email returns the value of the "email" field in the mutation.
func (m *SysUserMutation) Email() (r string, exists bool) {
v := m.email
if v == nil {
return
}
return *v, true
}
// OldEmail returns the old "email" field's value of the SysUser entity.
// If the SysUser 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 *SysUserMutation) OldEmail(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldEmail is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldEmail requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldEmail: %w", err)
}
return oldValue.Email, nil
}
// ResetEmail resets all changes to the "email" field.
func (m *SysUserMutation) ResetEmail() {
m.email = nil
}
// SetInviteCode sets the "invite_code" field.
func (m *SysUserMutation) SetInviteCode(s string) {
m.invite_code = &s
}
// InviteCode returns the value of the "invite_code" field in the mutation.
func (m *SysUserMutation) InviteCode() (r string, exists bool) {
v := m.invite_code
if v == nil {
return
}
return *v, true
}
// OldInviteCode returns the old "invite_code" field's value of the SysUser entity.
// If the SysUser 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 *SysUserMutation) OldInviteCode(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldInviteCode is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldInviteCode requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldInviteCode: %w", err)
}
return oldValue.InviteCode, nil
}
// ClearInviteCode clears the value of the "invite_code" field.
func (m *SysUserMutation) ClearInviteCode() {
m.invite_code = nil
m.clearedFields[sysuser.FieldInviteCode] = struct{}{}
}
// InviteCodeCleared returns if the "invite_code" field was cleared in this mutation.
func (m *SysUserMutation) InviteCodeCleared() bool {
_, ok := m.clearedFields[sysuser.FieldInviteCode]
return ok
}
// ResetInviteCode resets all changes to the "invite_code" field.
func (m *SysUserMutation) ResetInviteCode() {
m.invite_code = nil
delete(m.clearedFields, sysuser.FieldInviteCode)
}
// SetBalance sets the "balance" field.
func (m *SysUserMutation) SetBalance(d decimal.Decimal) {
m.balance = &d
}
// Balance returns the value of the "balance" field in the mutation.
func (m *SysUserMutation) Balance() (r decimal.Decimal, exists bool) {
v := m.balance
if v == nil {
return
}
return *v, true
}
// OldBalance returns the old "balance" field's value of the SysUser entity.
// If the SysUser 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 *SysUserMutation) OldBalance(ctx context.Context) (v decimal.Decimal, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBalance is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBalance requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBalance: %w", err)
}
return oldValue.Balance, nil
}
// ResetBalance resets all changes to the "balance" field.
func (m *SysUserMutation) ResetBalance() {
m.balance = nil
}
// SetBlock sets the "block" field.
func (m *SysUserMutation) SetBlock(b bool) {
m.block = &b
}
// Block returns the value of the "block" field in the mutation.
func (m *SysUserMutation) Block() (r bool, exists bool) {
v := m.block
if v == nil {
return
}
return *v, true
}
// OldBlock returns the old "block" field's value of the SysUser entity.
// If the SysUser 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 *SysUserMutation) OldBlock(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBlock is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBlock requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBlock: %w", err)
}
return oldValue.Block, nil
}
// ResetBlock resets all changes to the "block" field.
func (m *SysUserMutation) ResetBlock() {
m.block = nil
}
// SetVerify sets the "verify" field.
func (m *SysUserMutation) SetVerify(b bool) {
m.verify = &b
}
// Verify returns the value of the "verify" field in the mutation.
func (m *SysUserMutation) Verify() (r bool, exists bool) {
v := m.verify
if v == nil {
return
}
return *v, true
}
// OldVerify returns the old "verify" field's value of the SysUser entity.
// If the SysUser 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 *SysUserMutation) OldVerify(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldVerify is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldVerify requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldVerify: %w", err)
}
return oldValue.Verify, nil
}
// ResetVerify resets all changes to the "verify" field.
func (m *SysUserMutation) ResetVerify() {
m.verify = nil
}
// SetInviteCashback sets the "invite_cashback" field.
func (m *SysUserMutation) SetInviteCashback(d decimal.Decimal) {
m.invite_cashback = &d
}
// InviteCashback returns the value of the "invite_cashback" field in the mutation.
func (m *SysUserMutation) InviteCashback() (r decimal.Decimal, exists bool) {
v := m.invite_cashback
if v == nil {
return
}
return *v, true
}
// OldInviteCashback returns the old "invite_cashback" field's value of the SysUser entity.
// If the SysUser 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 *SysUserMutation) OldInviteCashback(ctx context.Context) (v decimal.Decimal, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldInviteCashback is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldInviteCashback requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldInviteCashback: %w", err)
}
return oldValue.InviteCashback, nil
}
// ResetInviteCashback resets all changes to the "invite_cashback" field.
func (m *SysUserMutation) ResetInviteCashback() {
m.invite_cashback = nil
}
// SetParentID sets the "parent" edge to the SysUser entity by id.
func (m *SysUserMutation) SetParentID(id int64) {
m.parent = &id
}
// ClearParent clears the "parent" edge to the SysUser entity.
func (m *SysUserMutation) ClearParent() {
m.clearedparent = true
}
// ParentCleared reports if the "parent" edge to the SysUser entity was cleared.
func (m *SysUserMutation) ParentCleared() bool {
return m.clearedparent
}
// ParentID returns the "parent" edge ID in the mutation.
func (m *SysUserMutation) ParentID() (id int64, exists bool) {
if m.parent != nil {
return *m.parent, true
}
return
}
// ParentIDs returns the "parent" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// ParentID instead. It exists only for internal usage by the builders.
func (m *SysUserMutation) ParentIDs() (ids []int64) {
if id := m.parent; id != nil {
ids = append(ids, *id)
}
return
}
// ResetParent resets all changes to the "parent" edge.
func (m *SysUserMutation) ResetParent() {
m.parent = nil
m.clearedparent = false
}
// AddChildIDs adds the "children" edge to the SysUser entity by ids.
func (m *SysUserMutation) AddChildIDs(ids ...int64) {
if m.children == nil {
m.children = make(map[int64]struct{})
}
for i := range ids {
m.children[ids[i]] = struct{}{}
}
}
// ClearChildren clears the "children" edge to the SysUser entity.
func (m *SysUserMutation) ClearChildren() {
m.clearedchildren = true
}
// ChildrenCleared reports if the "children" edge to the SysUser entity was cleared.
func (m *SysUserMutation) ChildrenCleared() bool {
return m.clearedchildren
}
// RemoveChildIDs removes the "children" edge to the SysUser entity by IDs.
func (m *SysUserMutation) RemoveChildIDs(ids ...int64) {
if m.removedchildren == nil {
m.removedchildren = make(map[int64]struct{})
}
for i := range ids {
delete(m.children, ids[i])
m.removedchildren[ids[i]] = struct{}{}
}
}
// RemovedChildren returns the removed IDs of the "children" edge to the SysUser entity.
func (m *SysUserMutation) RemovedChildrenIDs() (ids []int64) {
for id := range m.removedchildren {
ids = append(ids, id)
}
return
}
// ChildrenIDs returns the "children" edge IDs in the mutation.
func (m *SysUserMutation) ChildrenIDs() (ids []int64) {
for id := range m.children {
ids = append(ids, id)
}
return
}
// ResetChildren resets all changes to the "children" edge.
func (m *SysUserMutation) ResetChildren() {
m.children = nil
m.clearedchildren = false
m.removedchildren = nil
}
// AddRoleIDs adds the "roles" edge to the SysRole entity by ids.
func (m *SysUserMutation) AddRoleIDs(ids ...int64) {
if m.roles == nil {
m.roles = make(map[int64]struct{})
}
for i := range ids {
m.roles[ids[i]] = struct{}{}
}
}
// ClearRoles clears the "roles" edge to the SysRole entity.
func (m *SysUserMutation) ClearRoles() {
m.clearedroles = true
}
// RolesCleared reports if the "roles" edge to the SysRole entity was cleared.
func (m *SysUserMutation) RolesCleared() bool {
return m.clearedroles
}
// RemoveRoleIDs removes the "roles" edge to the SysRole entity by IDs.
func (m *SysUserMutation) RemoveRoleIDs(ids ...int64) {
if m.removedroles == nil {
m.removedroles = make(map[int64]struct{})
}
for i := range ids {
delete(m.roles, ids[i])
m.removedroles[ids[i]] = struct{}{}
}
}
// RemovedRoles returns the removed IDs of the "roles" edge to the SysRole entity.
func (m *SysUserMutation) RemovedRolesIDs() (ids []int64) {
for id := range m.removedroles {
ids = append(ids, id)
}
return
}
// RolesIDs returns the "roles" edge IDs in the mutation.
func (m *SysUserMutation) RolesIDs() (ids []int64) {
for id := range m.roles {
ids = append(ids, id)
}
return
}
// ResetRoles resets all changes to the "roles" edge.
func (m *SysUserMutation) ResetRoles() {
m.roles = nil
m.clearedroles = false
m.removedroles = nil
}
// SetAgentID sets the "agent" edge to the SysAgent entity by id.
func (m *SysUserMutation) SetAgentID(id int64) {
m.agent = &id
}
// ClearAgent clears the "agent" edge to the SysAgent entity.
func (m *SysUserMutation) ClearAgent() {
m.clearedagent = true
}
// AgentCleared reports if the "agent" edge to the SysAgent entity was cleared.
func (m *SysUserMutation) AgentCleared() bool {
return m.clearedagent
}
// AgentID returns the "agent" edge ID in the mutation.
func (m *SysUserMutation) AgentID() (id int64, exists bool) {
if m.agent != nil {
return *m.agent, true
}
return
}
// AgentIDs returns the "agent" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// AgentID instead. It exists only for internal usage by the builders.
func (m *SysUserMutation) AgentIDs() (ids []int64) {
if id := m.agent; id != nil {
ids = append(ids, *id)
}
return
}
// ResetAgent resets all changes to the "agent" edge.
func (m *SysUserMutation) ResetAgent() {
m.agent = nil
m.clearedagent = false
}
// AddImageIDs adds the "images" edge to the CpImage entity by ids.
func (m *SysUserMutation) AddImageIDs(ids ...int64) {
if m.images == nil {
m.images = make(map[int64]struct{})
}
for i := range ids {
m.images[ids[i]] = struct{}{}
}
}
// ClearImages clears the "images" edge to the CpImage entity.
func (m *SysUserMutation) ClearImages() {
m.clearedimages = true
}
// ImagesCleared reports if the "images" edge to the CpImage entity was cleared.
func (m *SysUserMutation) ImagesCleared() bool {
return m.clearedimages
}
// RemoveImageIDs removes the "images" edge to the CpImage entity by IDs.
func (m *SysUserMutation) RemoveImageIDs(ids ...int64) {
if m.removedimages == nil {
m.removedimages = make(map[int64]struct{})
}
for i := range ids {
delete(m.images, ids[i])
m.removedimages[ids[i]] = struct{}{}
}
}
// RemovedImages returns the removed IDs of the "images" edge to the CpImage entity.
func (m *SysUserMutation) RemovedImagesIDs() (ids []int64) {
for id := range m.removedimages {
ids = append(ids, id)
}
return
}
// ImagesIDs returns the "images" edge IDs in the mutation.
func (m *SysUserMutation) ImagesIDs() (ids []int64) {
for id := range m.images {
ids = append(ids, id)
}
return
}
// ResetImages resets all changes to the "images" edge.
func (m *SysUserMutation) ResetImages() {
m.images = nil
m.clearedimages = false
m.removedimages = nil
}
// AddCpuserIDs adds the "cpuser" edge to the CpUser entity by ids.
func (m *SysUserMutation) AddCpuserIDs(ids ...int64) {
if m.cpuser == nil {
m.cpuser = make(map[int64]struct{})
}
for i := range ids {
m.cpuser[ids[i]] = struct{}{}
}
}
// ClearCpuser clears the "cpuser" edge to the CpUser entity.
func (m *SysUserMutation) ClearCpuser() {
m.clearedcpuser = true
}
// CpuserCleared reports if the "cpuser" edge to the CpUser entity was cleared.
func (m *SysUserMutation) CpuserCleared() bool {
return m.clearedcpuser
}
// RemoveCpuserIDs removes the "cpuser" edge to the CpUser entity by IDs.
func (m *SysUserMutation) RemoveCpuserIDs(ids ...int64) {
if m.removedcpuser == nil {
m.removedcpuser = make(map[int64]struct{})
}
for i := range ids {
delete(m.cpuser, ids[i])
m.removedcpuser[ids[i]] = struct{}{}
}
}
// RemovedCpuser returns the removed IDs of the "cpuser" edge to the CpUser entity.
func (m *SysUserMutation) RemovedCpuserIDs() (ids []int64) {
for id := range m.removedcpuser {
ids = append(ids, id)
}
return
}
// CpuserIDs returns the "cpuser" edge IDs in the mutation.
func (m *SysUserMutation) CpuserIDs() (ids []int64) {
for id := range m.cpuser {
ids = append(ids, id)
}
return
}
// ResetCpuser resets all changes to the "cpuser" edge.
func (m *SysUserMutation) ResetCpuser() {
m.cpuser = nil
m.clearedcpuser = false
m.removedcpuser = nil
}
// AddCpTaskIDs adds the "cp_task" edge to the CpTask entity by ids.
func (m *SysUserMutation) AddCpTaskIDs(ids ...int64) {
if m.cp_task == nil {
m.cp_task = make(map[int64]struct{})
}
for i := range ids {
m.cp_task[ids[i]] = struct{}{}
}
}
// ClearCpTask clears the "cp_task" edge to the CpTask entity.
func (m *SysUserMutation) ClearCpTask() {
m.clearedcp_task = true
}
// CpTaskCleared reports if the "cp_task" edge to the CpTask entity was cleared.
func (m *SysUserMutation) CpTaskCleared() bool {
return m.clearedcp_task
}
// RemoveCpTaskIDs removes the "cp_task" edge to the CpTask entity by IDs.
func (m *SysUserMutation) RemoveCpTaskIDs(ids ...int64) {
if m.removedcp_task == nil {
m.removedcp_task = make(map[int64]struct{})
}
for i := range ids {
delete(m.cp_task, ids[i])
m.removedcp_task[ids[i]] = struct{}{}
}
}
// RemovedCpTask returns the removed IDs of the "cp_task" edge to the CpTask entity.
func (m *SysUserMutation) RemovedCpTaskIDs() (ids []int64) {
for id := range m.removedcp_task {
ids = append(ids, id)
}
return
}
// CpTaskIDs returns the "cp_task" edge IDs in the mutation.
func (m *SysUserMutation) CpTaskIDs() (ids []int64) {
for id := range m.cp_task {
ids = append(ids, id)
}
return
}
// ResetCpTask resets all changes to the "cp_task" edge.
func (m *SysUserMutation) ResetCpTask() {
m.cp_task = nil
m.clearedcp_task = false
m.removedcp_task = nil
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by ids.
func (m *SysUserMutation) AddCpTaskLogIDs(ids ...int64) {
if m.cp_task_logs == nil {
m.cp_task_logs = make(map[int64]struct{})
}
for i := range ids {
m.cp_task_logs[ids[i]] = struct{}{}
}
}
// ClearCpTaskLogs clears the "cp_task_logs" edge to the CpTaskLog entity.
func (m *SysUserMutation) ClearCpTaskLogs() {
m.clearedcp_task_logs = true
}
// CpTaskLogsCleared reports if the "cp_task_logs" edge to the CpTaskLog entity was cleared.
func (m *SysUserMutation) CpTaskLogsCleared() bool {
return m.clearedcp_task_logs
}
// RemoveCpTaskLogIDs removes the "cp_task_logs" edge to the CpTaskLog entity by IDs.
func (m *SysUserMutation) RemoveCpTaskLogIDs(ids ...int64) {
if m.removedcp_task_logs == nil {
m.removedcp_task_logs = make(map[int64]struct{})
}
for i := range ids {
delete(m.cp_task_logs, ids[i])
m.removedcp_task_logs[ids[i]] = struct{}{}
}
}
// RemovedCpTaskLogs returns the removed IDs of the "cp_task_logs" edge to the CpTaskLog entity.
func (m *SysUserMutation) RemovedCpTaskLogsIDs() (ids []int64) {
for id := range m.removedcp_task_logs {
ids = append(ids, id)
}
return
}
// CpTaskLogsIDs returns the "cp_task_logs" edge IDs in the mutation.
func (m *SysUserMutation) CpTaskLogsIDs() (ids []int64) {
for id := range m.cp_task_logs {
ids = append(ids, id)
}
return
}
// ResetCpTaskLogs resets all changes to the "cp_task_logs" edge.
func (m *SysUserMutation) ResetCpTaskLogs() {
m.cp_task_logs = nil
m.clearedcp_task_logs = false
m.removedcp_task_logs = nil
}
// AddCreatedCardIDs adds the "created_cards" edge to the SysCard entity by ids.
func (m *SysUserMutation) AddCreatedCardIDs(ids ...int64) {
if m.created_cards == nil {
m.created_cards = make(map[int64]struct{})
}
for i := range ids {
m.created_cards[ids[i]] = struct{}{}
}
}
// ClearCreatedCards clears the "created_cards" edge to the SysCard entity.
func (m *SysUserMutation) ClearCreatedCards() {
m.clearedcreated_cards = true
}
// CreatedCardsCleared reports if the "created_cards" edge to the SysCard entity was cleared.
func (m *SysUserMutation) CreatedCardsCleared() bool {
return m.clearedcreated_cards
}
// RemoveCreatedCardIDs removes the "created_cards" edge to the SysCard entity by IDs.
func (m *SysUserMutation) RemoveCreatedCardIDs(ids ...int64) {
if m.removedcreated_cards == nil {
m.removedcreated_cards = make(map[int64]struct{})
}
for i := range ids {
delete(m.created_cards, ids[i])
m.removedcreated_cards[ids[i]] = struct{}{}
}
}
// RemovedCreatedCards returns the removed IDs of the "created_cards" edge to the SysCard entity.
func (m *SysUserMutation) RemovedCreatedCardsIDs() (ids []int64) {
for id := range m.removedcreated_cards {
ids = append(ids, id)
}
return
}
// CreatedCardsIDs returns the "created_cards" edge IDs in the mutation.
func (m *SysUserMutation) CreatedCardsIDs() (ids []int64) {
for id := range m.created_cards {
ids = append(ids, id)
}
return
}
// ResetCreatedCards resets all changes to the "created_cards" edge.
func (m *SysUserMutation) ResetCreatedCards() {
m.created_cards = nil
m.clearedcreated_cards = false
m.removedcreated_cards = nil
}
// AddUsedCardIDs adds the "used_cards" edge to the SysCard entity by ids.
func (m *SysUserMutation) AddUsedCardIDs(ids ...int64) {
if m.used_cards == nil {
m.used_cards = make(map[int64]struct{})
}
for i := range ids {
m.used_cards[ids[i]] = struct{}{}
}
}
// ClearUsedCards clears the "used_cards" edge to the SysCard entity.
func (m *SysUserMutation) ClearUsedCards() {
m.clearedused_cards = true
}
// UsedCardsCleared reports if the "used_cards" edge to the SysCard entity was cleared.
func (m *SysUserMutation) UsedCardsCleared() bool {
return m.clearedused_cards
}
// RemoveUsedCardIDs removes the "used_cards" edge to the SysCard entity by IDs.
func (m *SysUserMutation) RemoveUsedCardIDs(ids ...int64) {
if m.removedused_cards == nil {
m.removedused_cards = make(map[int64]struct{})
}
for i := range ids {
delete(m.used_cards, ids[i])
m.removedused_cards[ids[i]] = struct{}{}
}
}
// RemovedUsedCards returns the removed IDs of the "used_cards" edge to the SysCard entity.
func (m *SysUserMutation) RemovedUsedCardsIDs() (ids []int64) {
for id := range m.removedused_cards {
ids = append(ids, id)
}
return
}
// UsedCardsIDs returns the "used_cards" edge IDs in the mutation.
func (m *SysUserMutation) UsedCardsIDs() (ids []int64) {
for id := range m.used_cards {
ids = append(ids, id)
}
return
}
// ResetUsedCards resets all changes to the "used_cards" edge.
func (m *SysUserMutation) ResetUsedCards() {
m.used_cards = nil
m.clearedused_cards = false
m.removedused_cards = nil
}
// AddCashbackCardIDs adds the "cashback_cards" edge to the SysCard entity by ids.
func (m *SysUserMutation) AddCashbackCardIDs(ids ...int64) {
if m.cashback_cards == nil {
m.cashback_cards = make(map[int64]struct{})
}
for i := range ids {
m.cashback_cards[ids[i]] = struct{}{}
}
}
// ClearCashbackCards clears the "cashback_cards" edge to the SysCard entity.
func (m *SysUserMutation) ClearCashbackCards() {
m.clearedcashback_cards = true
}
// CashbackCardsCleared reports if the "cashback_cards" edge to the SysCard entity was cleared.
func (m *SysUserMutation) CashbackCardsCleared() bool {
return m.clearedcashback_cards
}
// RemoveCashbackCardIDs removes the "cashback_cards" edge to the SysCard entity by IDs.
func (m *SysUserMutation) RemoveCashbackCardIDs(ids ...int64) {
if m.removedcashback_cards == nil {
m.removedcashback_cards = make(map[int64]struct{})
}
for i := range ids {
delete(m.cashback_cards, ids[i])
m.removedcashback_cards[ids[i]] = struct{}{}
}
}
// RemovedCashbackCards returns the removed IDs of the "cashback_cards" edge to the SysCard entity.
func (m *SysUserMutation) RemovedCashbackCardsIDs() (ids []int64) {
for id := range m.removedcashback_cards {
ids = append(ids, id)
}
return
}
// CashbackCardsIDs returns the "cashback_cards" edge IDs in the mutation.
func (m *SysUserMutation) CashbackCardsIDs() (ids []int64) {
for id := range m.cashback_cards {
ids = append(ids, id)
}
return
}
// ResetCashbackCards resets all changes to the "cashback_cards" edge.
func (m *SysUserMutation) ResetCashbackCards() {
m.cashback_cards = nil
m.clearedcashback_cards = false
m.removedcashback_cards = nil
}
// Where appends a list predicates to the SysUserMutation builder.
func (m *SysUserMutation) Where(ps ...predicate.SysUser) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the SysUserMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SysUserMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.SysUser, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *SysUserMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *SysUserMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (SysUser).
func (m *SysUserMutation) 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 *SysUserMutation) Fields() []string {
fields := make([]string, 0, 10)
if m.create_time != nil {
fields = append(fields, sysuser.FieldCreateTime)
}
if m.update_time != nil {
fields = append(fields, sysuser.FieldUpdateTime)
}
if m.username != nil {
fields = append(fields, sysuser.FieldUsername)
}
if m.password != nil {
fields = append(fields, sysuser.FieldPassword)
}
if m.email != nil {
fields = append(fields, sysuser.FieldEmail)
}
if m.invite_code != nil {
fields = append(fields, sysuser.FieldInviteCode)
}
if m.balance != nil {
fields = append(fields, sysuser.FieldBalance)
}
if m.block != nil {
fields = append(fields, sysuser.FieldBlock)
}
if m.verify != nil {
fields = append(fields, sysuser.FieldVerify)
}
if m.invite_cashback != nil {
fields = append(fields, sysuser.FieldInviteCashback)
}
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 *SysUserMutation) Field(name string) (ent.Value, bool) {
switch name {
case sysuser.FieldCreateTime:
return m.CreateTime()
case sysuser.FieldUpdateTime:
return m.UpdateTime()
case sysuser.FieldUsername:
return m.Username()
case sysuser.FieldPassword:
return m.Password()
case sysuser.FieldEmail:
return m.Email()
case sysuser.FieldInviteCode:
return m.InviteCode()
case sysuser.FieldBalance:
return m.Balance()
case sysuser.FieldBlock:
return m.Block()
case sysuser.FieldVerify:
return m.Verify()
case sysuser.FieldInviteCashback:
return m.InviteCashback()
}
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 *SysUserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case sysuser.FieldCreateTime:
return m.OldCreateTime(ctx)
case sysuser.FieldUpdateTime:
return m.OldUpdateTime(ctx)
case sysuser.FieldUsername:
return m.OldUsername(ctx)
case sysuser.FieldPassword:
return m.OldPassword(ctx)
case sysuser.FieldEmail:
return m.OldEmail(ctx)
case sysuser.FieldInviteCode:
return m.OldInviteCode(ctx)
case sysuser.FieldBalance:
return m.OldBalance(ctx)
case sysuser.FieldBlock:
return m.OldBlock(ctx)
case sysuser.FieldVerify:
return m.OldVerify(ctx)
case sysuser.FieldInviteCashback:
return m.OldInviteCashback(ctx)
}
return nil, fmt.Errorf("unknown SysUser 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 *SysUserMutation) SetField(name string, value ent.Value) error {
switch name {
case sysuser.FieldCreateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreateTime(v)
return nil
case sysuser.FieldUpdateTime:
v, ok := value.(*ent2.CustomTime)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdateTime(v)
return nil
case sysuser.FieldUsername:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsername(v)
return nil
case sysuser.FieldPassword:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPassword(v)
return nil
case sysuser.FieldEmail:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetEmail(v)
return nil
case sysuser.FieldInviteCode:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetInviteCode(v)
return nil
case sysuser.FieldBalance:
v, ok := value.(decimal.Decimal)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBalance(v)
return nil
case sysuser.FieldBlock:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBlock(v)
return nil
case sysuser.FieldVerify:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetVerify(v)
return nil
case sysuser.FieldInviteCashback:
v, ok := value.(decimal.Decimal)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetInviteCashback(v)
return nil
}
return fmt.Errorf("unknown SysUser field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SysUserMutation) 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 *SysUserMutation) 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 *SysUserMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown SysUser numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SysUserMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(sysuser.FieldInviteCode) {
fields = append(fields, sysuser.FieldInviteCode)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SysUserMutation) 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 *SysUserMutation) ClearField(name string) error {
switch name {
case sysuser.FieldInviteCode:
m.ClearInviteCode()
return nil
}
return fmt.Errorf("unknown SysUser 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 *SysUserMutation) ResetField(name string) error {
switch name {
case sysuser.FieldCreateTime:
m.ResetCreateTime()
return nil
case sysuser.FieldUpdateTime:
m.ResetUpdateTime()
return nil
case sysuser.FieldUsername:
m.ResetUsername()
return nil
case sysuser.FieldPassword:
m.ResetPassword()
return nil
case sysuser.FieldEmail:
m.ResetEmail()
return nil
case sysuser.FieldInviteCode:
m.ResetInviteCode()
return nil
case sysuser.FieldBalance:
m.ResetBalance()
return nil
case sysuser.FieldBlock:
m.ResetBlock()
return nil
case sysuser.FieldVerify:
m.ResetVerify()
return nil
case sysuser.FieldInviteCashback:
m.ResetInviteCashback()
return nil
}
return fmt.Errorf("unknown SysUser field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SysUserMutation) AddedEdges() []string {
edges := make([]string, 0, 11)
if m.parent != nil {
edges = append(edges, sysuser.EdgeParent)
}
if m.children != nil {
edges = append(edges, sysuser.EdgeChildren)
}
if m.roles != nil {
edges = append(edges, sysuser.EdgeRoles)
}
if m.agent != nil {
edges = append(edges, sysuser.EdgeAgent)
}
if m.images != nil {
edges = append(edges, sysuser.EdgeImages)
}
if m.cpuser != nil {
edges = append(edges, sysuser.EdgeCpuser)
}
if m.cp_task != nil {
edges = append(edges, sysuser.EdgeCpTask)
}
if m.cp_task_logs != nil {
edges = append(edges, sysuser.EdgeCpTaskLogs)
}
if m.created_cards != nil {
edges = append(edges, sysuser.EdgeCreatedCards)
}
if m.used_cards != nil {
edges = append(edges, sysuser.EdgeUsedCards)
}
if m.cashback_cards != nil {
edges = append(edges, sysuser.EdgeCashbackCards)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SysUserMutation) AddedIDs(name string) []ent.Value {
switch name {
case sysuser.EdgeParent:
if id := m.parent; id != nil {
return []ent.Value{*id}
}
case sysuser.EdgeChildren:
ids := make([]ent.Value, 0, len(m.children))
for id := range m.children {
ids = append(ids, id)
}
return ids
case sysuser.EdgeRoles:
ids := make([]ent.Value, 0, len(m.roles))
for id := range m.roles {
ids = append(ids, id)
}
return ids
case sysuser.EdgeAgent:
if id := m.agent; id != nil {
return []ent.Value{*id}
}
case sysuser.EdgeImages:
ids := make([]ent.Value, 0, len(m.images))
for id := range m.images {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCpuser:
ids := make([]ent.Value, 0, len(m.cpuser))
for id := range m.cpuser {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCpTask:
ids := make([]ent.Value, 0, len(m.cp_task))
for id := range m.cp_task {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCpTaskLogs:
ids := make([]ent.Value, 0, len(m.cp_task_logs))
for id := range m.cp_task_logs {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCreatedCards:
ids := make([]ent.Value, 0, len(m.created_cards))
for id := range m.created_cards {
ids = append(ids, id)
}
return ids
case sysuser.EdgeUsedCards:
ids := make([]ent.Value, 0, len(m.used_cards))
for id := range m.used_cards {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCashbackCards:
ids := make([]ent.Value, 0, len(m.cashback_cards))
for id := range m.cashback_cards {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SysUserMutation) RemovedEdges() []string {
edges := make([]string, 0, 11)
if m.removedchildren != nil {
edges = append(edges, sysuser.EdgeChildren)
}
if m.removedroles != nil {
edges = append(edges, sysuser.EdgeRoles)
}
if m.removedimages != nil {
edges = append(edges, sysuser.EdgeImages)
}
if m.removedcpuser != nil {
edges = append(edges, sysuser.EdgeCpuser)
}
if m.removedcp_task != nil {
edges = append(edges, sysuser.EdgeCpTask)
}
if m.removedcp_task_logs != nil {
edges = append(edges, sysuser.EdgeCpTaskLogs)
}
if m.removedcreated_cards != nil {
edges = append(edges, sysuser.EdgeCreatedCards)
}
if m.removedused_cards != nil {
edges = append(edges, sysuser.EdgeUsedCards)
}
if m.removedcashback_cards != nil {
edges = append(edges, sysuser.EdgeCashbackCards)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SysUserMutation) RemovedIDs(name string) []ent.Value {
switch name {
case sysuser.EdgeChildren:
ids := make([]ent.Value, 0, len(m.removedchildren))
for id := range m.removedchildren {
ids = append(ids, id)
}
return ids
case sysuser.EdgeRoles:
ids := make([]ent.Value, 0, len(m.removedroles))
for id := range m.removedroles {
ids = append(ids, id)
}
return ids
case sysuser.EdgeImages:
ids := make([]ent.Value, 0, len(m.removedimages))
for id := range m.removedimages {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCpuser:
ids := make([]ent.Value, 0, len(m.removedcpuser))
for id := range m.removedcpuser {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCpTask:
ids := make([]ent.Value, 0, len(m.removedcp_task))
for id := range m.removedcp_task {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCpTaskLogs:
ids := make([]ent.Value, 0, len(m.removedcp_task_logs))
for id := range m.removedcp_task_logs {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCreatedCards:
ids := make([]ent.Value, 0, len(m.removedcreated_cards))
for id := range m.removedcreated_cards {
ids = append(ids, id)
}
return ids
case sysuser.EdgeUsedCards:
ids := make([]ent.Value, 0, len(m.removedused_cards))
for id := range m.removedused_cards {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCashbackCards:
ids := make([]ent.Value, 0, len(m.removedcashback_cards))
for id := range m.removedcashback_cards {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SysUserMutation) ClearedEdges() []string {
edges := make([]string, 0, 11)
if m.clearedparent {
edges = append(edges, sysuser.EdgeParent)
}
if m.clearedchildren {
edges = append(edges, sysuser.EdgeChildren)
}
if m.clearedroles {
edges = append(edges, sysuser.EdgeRoles)
}
if m.clearedagent {
edges = append(edges, sysuser.EdgeAgent)
}
if m.clearedimages {
edges = append(edges, sysuser.EdgeImages)
}
if m.clearedcpuser {
edges = append(edges, sysuser.EdgeCpuser)
}
if m.clearedcp_task {
edges = append(edges, sysuser.EdgeCpTask)
}
if m.clearedcp_task_logs {
edges = append(edges, sysuser.EdgeCpTaskLogs)
}
if m.clearedcreated_cards {
edges = append(edges, sysuser.EdgeCreatedCards)
}
if m.clearedused_cards {
edges = append(edges, sysuser.EdgeUsedCards)
}
if m.clearedcashback_cards {
edges = append(edges, sysuser.EdgeCashbackCards)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SysUserMutation) EdgeCleared(name string) bool {
switch name {
case sysuser.EdgeParent:
return m.clearedparent
case sysuser.EdgeChildren:
return m.clearedchildren
case sysuser.EdgeRoles:
return m.clearedroles
case sysuser.EdgeAgent:
return m.clearedagent
case sysuser.EdgeImages:
return m.clearedimages
case sysuser.EdgeCpuser:
return m.clearedcpuser
case sysuser.EdgeCpTask:
return m.clearedcp_task
case sysuser.EdgeCpTaskLogs:
return m.clearedcp_task_logs
case sysuser.EdgeCreatedCards:
return m.clearedcreated_cards
case sysuser.EdgeUsedCards:
return m.clearedused_cards
case sysuser.EdgeCashbackCards:
return m.clearedcashback_cards
}
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 *SysUserMutation) ClearEdge(name string) error {
switch name {
case sysuser.EdgeParent:
m.ClearParent()
return nil
case sysuser.EdgeAgent:
m.ClearAgent()
return nil
}
return fmt.Errorf("unknown SysUser 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 *SysUserMutation) ResetEdge(name string) error {
switch name {
case sysuser.EdgeParent:
m.ResetParent()
return nil
case sysuser.EdgeChildren:
m.ResetChildren()
return nil
case sysuser.EdgeRoles:
m.ResetRoles()
return nil
case sysuser.EdgeAgent:
m.ResetAgent()
return nil
case sysuser.EdgeImages:
m.ResetImages()
return nil
case sysuser.EdgeCpuser:
m.ResetCpuser()
return nil
case sysuser.EdgeCpTask:
m.ResetCpTask()
return nil
case sysuser.EdgeCpTaskLogs:
m.ResetCpTaskLogs()
return nil
case sysuser.EdgeCreatedCards:
m.ResetCreatedCards()
return nil
case sysuser.EdgeUsedCards:
m.ResetUsedCards()
return nil
case sysuser.EdgeCashbackCards:
m.ResetCashbackCards()
return nil
}
return fmt.Errorf("unknown SysUser edge %s", name)
}
// SysUserLogMutation represents an operation that mutates the SysUserLog nodes in the graph.
type SysUserLogMutation struct {
config
op Op
typ string
id *int64
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*SysUserLog, error)
predicates []predicate.SysUserLog
}
var _ ent.Mutation = (*SysUserLogMutation)(nil)
// sysuserlogOption allows management of the mutation configuration using functional options.
type sysuserlogOption func(*SysUserLogMutation)
// newSysUserLogMutation creates new mutation for the SysUserLog entity.
func newSysUserLogMutation(c config, op Op, opts ...sysuserlogOption) *SysUserLogMutation {
m := &SysUserLogMutation{
config: c,
op: op,
typ: TypeSysUserLog,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withSysUserLogID sets the ID field of the mutation.
func withSysUserLogID(id int64) sysuserlogOption {
return func(m *SysUserLogMutation) {
var (
err error
once sync.Once
value *SysUserLog
)
m.oldValue = func(ctx context.Context) (*SysUserLog, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().SysUserLog.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withSysUserLog sets the old SysUserLog of the mutation.
func withSysUserLog(node *SysUserLog) sysuserlogOption {
return func(m *SysUserLogMutation) {
m.oldValue = func(context.Context) (*SysUserLog, 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 SysUserLogMutation) 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 SysUserLogMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *SysUserLogMutation) ID() (id int64, 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 *SysUserLogMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().SysUserLog.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// Where appends a list predicates to the SysUserLogMutation builder.
func (m *SysUserLogMutation) Where(ps ...predicate.SysUserLog) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the SysUserLogMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SysUserLogMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.SysUserLog, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *SysUserLogMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *SysUserLogMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (SysUserLog).
func (m *SysUserLogMutation) 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 *SysUserLogMutation) Fields() []string {
fields := make([]string, 0, 0)
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 *SysUserLogMutation) Field(name string) (ent.Value, bool) {
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 *SysUserLogMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
return nil, fmt.Errorf("unknown SysUserLog 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 *SysUserLogMutation) SetField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown SysUserLog field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SysUserLogMutation) 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 *SysUserLogMutation) 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 *SysUserLogMutation) AddField(name string, value ent.Value) error {
return fmt.Errorf("unknown SysUserLog numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SysUserLogMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SysUserLogMutation) 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 *SysUserLogMutation) ClearField(name string) error {
return fmt.Errorf("unknown SysUserLog 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 *SysUserLogMutation) ResetField(name string) error {
return fmt.Errorf("unknown SysUserLog field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SysUserLogMutation) 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 *SysUserLogMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SysUserLogMutation) 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 *SysUserLogMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SysUserLogMutation) 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 *SysUserLogMutation) 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 *SysUserLogMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown SysUserLog 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 *SysUserLogMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown SysUserLog edge %s", name)
}