1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "sync"
- "time"
- "entgo.io/ent"
- "entgo.io/ent/dialect/sql"
- "github.com/suyuan32/simple-admin-job/ent/predicate"
- "github.com/suyuan32/simple-admin-job/ent/task"
- "github.com/suyuan32/simple-admin-job/ent/tasklog"
- )
- const (
- // Operation types.
- OpCreate = ent.OpCreate
- OpDelete = ent.OpDelete
- OpDeleteOne = ent.OpDeleteOne
- OpUpdate = ent.OpUpdate
- OpUpdateOne = ent.OpUpdateOne
- // Node types.
- TypeTask = "Task"
- TypeTaskLog = "TaskLog"
- )
- // TaskMutation represents an operation that mutates the Task nodes in the graph.
- type TaskMutation struct {
- config
- op Op
- typ string
- id *uint64
- created_at *time.Time
- updated_at *time.Time
- status *uint8
- addstatus *int8
- name *string
- task_group *string
- cron_expression *string
- pattern *string
- payload *string
- clearedFields map[string]struct{}
- task_logs map[uint64]struct{}
- removedtask_logs map[uint64]struct{}
- clearedtask_logs bool
- done bool
- oldValue func(context.Context) (*Task, error)
- predicates []predicate.Task
- }
- var _ ent.Mutation = (*TaskMutation)(nil)
- // taskOption allows management of the mutation configuration using functional options.
- type taskOption func(*TaskMutation)
- // newTaskMutation creates new mutation for the Task entity.
- func newTaskMutation(c config, op Op, opts ...taskOption) *TaskMutation {
- m := &TaskMutation{
- config: c,
- op: op,
- typ: TypeTask,
- clearedFields: make(map[string]struct{}),
- }
- for _, opt := range opts {
- opt(m)
- }
- return m
- }
- // withTaskID sets the ID field of the mutation.
- func withTaskID(id uint64) taskOption {
- return func(m *TaskMutation) {
- var (
- err error
- once sync.Once
- value *Task
- )
- m.oldValue = func(ctx context.Context) (*Task, error) {
- once.Do(func() {
- if m.done {
- err = errors.New("querying old values post mutation is not allowed")
- } else {
- value, err = m.Client().Task.Get(ctx, id)
- }
- })
- return value, err
- }
- m.id = &id
- }
- }
- // withTask sets the old Task of the mutation.
- func withTask(node *Task) taskOption {
- return func(m *TaskMutation) {
- m.oldValue = func(context.Context) (*Task, 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 TaskMutation) 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 TaskMutation) 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 Task entities.
- func (m *TaskMutation) SetID(id uint64) {
- 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 *TaskMutation) ID() (id uint64, 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 *TaskMutation) IDs(ctx context.Context) ([]uint64, error) {
- switch {
- case m.op.Is(OpUpdateOne | OpDeleteOne):
- id, exists := m.ID()
- if exists {
- return []uint64{id}, nil
- }
- fallthrough
- case m.op.Is(OpUpdate | OpDelete):
- return m.Client().Task.Query().Where(m.predicates...).IDs(ctx)
- default:
- return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
- }
- }
- // SetCreatedAt sets the "created_at" field.
- func (m *TaskMutation) SetCreatedAt(t time.Time) {
- m.created_at = &t
- }
- // CreatedAt returns the value of the "created_at" field in the mutation.
- func (m *TaskMutation) CreatedAt() (r time.Time, exists bool) {
- v := m.created_at
- if v == nil {
- return
- }
- return *v, true
- }
- // OldCreatedAt returns the old "created_at" field's value of the Task entity.
- // If the Task 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 *TaskMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
- if !m.op.Is(OpUpdateOne) {
- return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
- }
- if m.id == nil || m.oldValue == nil {
- return v, errors.New("OldCreatedAt requires an ID field in the mutation")
- }
- oldValue, err := m.oldValue(ctx)
- if err != nil {
- return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
- }
- return oldValue.CreatedAt, nil
- }
- // ResetCreatedAt resets all changes to the "created_at" field.
- func (m *TaskMutation) ResetCreatedAt() {
- m.created_at = nil
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (m *TaskMutation) SetUpdatedAt(t time.Time) {
- m.updated_at = &t
- }
- // UpdatedAt returns the value of the "updated_at" field in the mutation.
- func (m *TaskMutation) UpdatedAt() (r time.Time, exists bool) {
- v := m.updated_at
- if v == nil {
- return
- }
- return *v, true
- }
- // OldUpdatedAt returns the old "updated_at" field's value of the Task entity.
- // If the Task 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 *TaskMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
- if !m.op.Is(OpUpdateOne) {
- return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
- }
- if m.id == nil || m.oldValue == nil {
- return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
- }
- oldValue, err := m.oldValue(ctx)
- if err != nil {
- return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
- }
- return oldValue.UpdatedAt, nil
- }
- // ResetUpdatedAt resets all changes to the "updated_at" field.
- func (m *TaskMutation) ResetUpdatedAt() {
- m.updated_at = nil
- }
- // SetStatus sets the "status" field.
- func (m *TaskMutation) SetStatus(u uint8) {
- m.status = &u
- m.addstatus = nil
- }
- // Status returns the value of the "status" field in the mutation.
- func (m *TaskMutation) Status() (r uint8, exists bool) {
- v := m.status
- if v == nil {
- return
- }
- return *v, true
- }
- // OldStatus returns the old "status" field's value of the Task entity.
- // If the Task 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 *TaskMutation) OldStatus(ctx context.Context) (v uint8, 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
- }
- // AddStatus adds u to the "status" field.
- func (m *TaskMutation) AddStatus(u int8) {
- if m.addstatus != nil {
- *m.addstatus += u
- } else {
- m.addstatus = &u
- }
- }
- // AddedStatus returns the value that was added to the "status" field in this mutation.
- func (m *TaskMutation) AddedStatus() (r int8, exists bool) {
- v := m.addstatus
- if v == nil {
- return
- }
- return *v, true
- }
- // ClearStatus clears the value of the "status" field.
- func (m *TaskMutation) ClearStatus() {
- m.status = nil
- m.addstatus = nil
- m.clearedFields[task.FieldStatus] = struct{}{}
- }
- // StatusCleared returns if the "status" field was cleared in this mutation.
- func (m *TaskMutation) StatusCleared() bool {
- _, ok := m.clearedFields[task.FieldStatus]
- return ok
- }
- // ResetStatus resets all changes to the "status" field.
- func (m *TaskMutation) ResetStatus() {
- m.status = nil
- m.addstatus = nil
- delete(m.clearedFields, task.FieldStatus)
- }
- // SetName sets the "name" field.
- func (m *TaskMutation) SetName(s string) {
- m.name = &s
- }
- // Name returns the value of the "name" field in the mutation.
- func (m *TaskMutation) 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 Task entity.
- // If the Task 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 *TaskMutation) 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 *TaskMutation) ResetName() {
- m.name = nil
- }
- // SetTaskGroup sets the "task_group" field.
- func (m *TaskMutation) SetTaskGroup(s string) {
- m.task_group = &s
- }
- // TaskGroup returns the value of the "task_group" field in the mutation.
- func (m *TaskMutation) TaskGroup() (r string, exists bool) {
- v := m.task_group
- if v == nil {
- return
- }
- return *v, true
- }
- // OldTaskGroup returns the old "task_group" field's value of the Task entity.
- // If the Task 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 *TaskMutation) OldTaskGroup(ctx context.Context) (v string, err error) {
- if !m.op.Is(OpUpdateOne) {
- return v, errors.New("OldTaskGroup is only allowed on UpdateOne operations")
- }
- if m.id == nil || m.oldValue == nil {
- return v, errors.New("OldTaskGroup requires an ID field in the mutation")
- }
- oldValue, err := m.oldValue(ctx)
- if err != nil {
- return v, fmt.Errorf("querying old value for OldTaskGroup: %w", err)
- }
- return oldValue.TaskGroup, nil
- }
- // ResetTaskGroup resets all changes to the "task_group" field.
- func (m *TaskMutation) ResetTaskGroup() {
- m.task_group = nil
- }
- // SetCronExpression sets the "cron_expression" field.
- func (m *TaskMutation) SetCronExpression(s string) {
- m.cron_expression = &s
- }
- // CronExpression returns the value of the "cron_expression" field in the mutation.
- func (m *TaskMutation) CronExpression() (r string, exists bool) {
- v := m.cron_expression
- if v == nil {
- return
- }
- return *v, true
- }
- // OldCronExpression returns the old "cron_expression" field's value of the Task entity.
- // If the Task 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 *TaskMutation) OldCronExpression(ctx context.Context) (v string, err error) {
- if !m.op.Is(OpUpdateOne) {
- return v, errors.New("OldCronExpression is only allowed on UpdateOne operations")
- }
- if m.id == nil || m.oldValue == nil {
- return v, errors.New("OldCronExpression requires an ID field in the mutation")
- }
- oldValue, err := m.oldValue(ctx)
- if err != nil {
- return v, fmt.Errorf("querying old value for OldCronExpression: %w", err)
- }
- return oldValue.CronExpression, nil
- }
- // ResetCronExpression resets all changes to the "cron_expression" field.
- func (m *TaskMutation) ResetCronExpression() {
- m.cron_expression = nil
- }
- // SetPattern sets the "pattern" field.
- func (m *TaskMutation) SetPattern(s string) {
- m.pattern = &s
- }
- // Pattern returns the value of the "pattern" field in the mutation.
- func (m *TaskMutation) Pattern() (r string, exists bool) {
- v := m.pattern
- if v == nil {
- return
- }
- return *v, true
- }
- // OldPattern returns the old "pattern" field's value of the Task entity.
- // If the Task 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 *TaskMutation) OldPattern(ctx context.Context) (v string, err error) {
- if !m.op.Is(OpUpdateOne) {
- return v, errors.New("OldPattern is only allowed on UpdateOne operations")
- }
- if m.id == nil || m.oldValue == nil {
- return v, errors.New("OldPattern requires an ID field in the mutation")
- }
- oldValue, err := m.oldValue(ctx)
- if err != nil {
- return v, fmt.Errorf("querying old value for OldPattern: %w", err)
- }
- return oldValue.Pattern, nil
- }
- // ResetPattern resets all changes to the "pattern" field.
- func (m *TaskMutation) ResetPattern() {
- m.pattern = nil
- }
- // SetPayload sets the "payload" field.
- func (m *TaskMutation) SetPayload(s string) {
- m.payload = &s
- }
- // Payload returns the value of the "payload" field in the mutation.
- func (m *TaskMutation) Payload() (r string, exists bool) {
- v := m.payload
- if v == nil {
- return
- }
- return *v, true
- }
- // OldPayload returns the old "payload" field's value of the Task entity.
- // If the Task 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 *TaskMutation) OldPayload(ctx context.Context) (v string, err error) {
- if !m.op.Is(OpUpdateOne) {
- return v, errors.New("OldPayload is only allowed on UpdateOne operations")
- }
- if m.id == nil || m.oldValue == nil {
- return v, errors.New("OldPayload requires an ID field in the mutation")
- }
- oldValue, err := m.oldValue(ctx)
- if err != nil {
- return v, fmt.Errorf("querying old value for OldPayload: %w", err)
- }
- return oldValue.Payload, nil
- }
- // ResetPayload resets all changes to the "payload" field.
- func (m *TaskMutation) ResetPayload() {
- m.payload = nil
- }
- // AddTaskLogIDs adds the "task_logs" edge to the TaskLog entity by ids.
- func (m *TaskMutation) AddTaskLogIDs(ids ...uint64) {
- if m.task_logs == nil {
- m.task_logs = make(map[uint64]struct{})
- }
- for i := range ids {
- m.task_logs[ids[i]] = struct{}{}
- }
- }
- // ClearTaskLogs clears the "task_logs" edge to the TaskLog entity.
- func (m *TaskMutation) ClearTaskLogs() {
- m.clearedtask_logs = true
- }
- // TaskLogsCleared reports if the "task_logs" edge to the TaskLog entity was cleared.
- func (m *TaskMutation) TaskLogsCleared() bool {
- return m.clearedtask_logs
- }
- // RemoveTaskLogIDs removes the "task_logs" edge to the TaskLog entity by IDs.
- func (m *TaskMutation) RemoveTaskLogIDs(ids ...uint64) {
- if m.removedtask_logs == nil {
- m.removedtask_logs = make(map[uint64]struct{})
- }
- for i := range ids {
- delete(m.task_logs, ids[i])
- m.removedtask_logs[ids[i]] = struct{}{}
- }
- }
- // RemovedTaskLogs returns the removed IDs of the "task_logs" edge to the TaskLog entity.
- func (m *TaskMutation) RemovedTaskLogsIDs() (ids []uint64) {
- for id := range m.removedtask_logs {
- ids = append(ids, id)
- }
- return
- }
- // TaskLogsIDs returns the "task_logs" edge IDs in the mutation.
- func (m *TaskMutation) TaskLogsIDs() (ids []uint64) {
- for id := range m.task_logs {
- ids = append(ids, id)
- }
- return
- }
- // ResetTaskLogs resets all changes to the "task_logs" edge.
- func (m *TaskMutation) ResetTaskLogs() {
- m.task_logs = nil
- m.clearedtask_logs = false
- m.removedtask_logs = nil
- }
- // Where appends a list predicates to the TaskMutation builder.
- func (m *TaskMutation) Where(ps ...predicate.Task) {
- m.predicates = append(m.predicates, ps...)
- }
- // WhereP appends storage-level predicates to the TaskMutation builder. Using this method,
- // users can use type-assertion to append predicates that do not depend on any generated package.
- func (m *TaskMutation) WhereP(ps ...func(*sql.Selector)) {
- p := make([]predicate.Task, len(ps))
- for i := range ps {
- p[i] = ps[i]
- }
- m.Where(p...)
- }
- // Op returns the operation name.
- func (m *TaskMutation) Op() Op {
- return m.op
- }
- // SetOp allows setting the mutation operation.
- func (m *TaskMutation) SetOp(op Op) {
- m.op = op
- }
- // Type returns the node type of this mutation (Task).
- func (m *TaskMutation) 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 *TaskMutation) Fields() []string {
- fields := make([]string, 0, 8)
- if m.created_at != nil {
- fields = append(fields, task.FieldCreatedAt)
- }
- if m.updated_at != nil {
- fields = append(fields, task.FieldUpdatedAt)
- }
- if m.status != nil {
- fields = append(fields, task.FieldStatus)
- }
- if m.name != nil {
- fields = append(fields, task.FieldName)
- }
- if m.task_group != nil {
- fields = append(fields, task.FieldTaskGroup)
- }
- if m.cron_expression != nil {
- fields = append(fields, task.FieldCronExpression)
- }
- if m.pattern != nil {
- fields = append(fields, task.FieldPattern)
- }
- if m.payload != nil {
- fields = append(fields, task.FieldPayload)
- }
- 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 *TaskMutation) Field(name string) (ent.Value, bool) {
- switch name {
- case task.FieldCreatedAt:
- return m.CreatedAt()
- case task.FieldUpdatedAt:
- return m.UpdatedAt()
- case task.FieldStatus:
- return m.Status()
- case task.FieldName:
- return m.Name()
- case task.FieldTaskGroup:
- return m.TaskGroup()
- case task.FieldCronExpression:
- return m.CronExpression()
- case task.FieldPattern:
- return m.Pattern()
- case task.FieldPayload:
- return m.Payload()
- }
- 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 *TaskMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
- switch name {
- case task.FieldCreatedAt:
- return m.OldCreatedAt(ctx)
- case task.FieldUpdatedAt:
- return m.OldUpdatedAt(ctx)
- case task.FieldStatus:
- return m.OldStatus(ctx)
- case task.FieldName:
- return m.OldName(ctx)
- case task.FieldTaskGroup:
- return m.OldTaskGroup(ctx)
- case task.FieldCronExpression:
- return m.OldCronExpression(ctx)
- case task.FieldPattern:
- return m.OldPattern(ctx)
- case task.FieldPayload:
- return m.OldPayload(ctx)
- }
- return nil, fmt.Errorf("unknown Task 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 *TaskMutation) SetField(name string, value ent.Value) error {
- switch name {
- case task.FieldCreatedAt:
- v, ok := value.(time.Time)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetCreatedAt(v)
- return nil
- case task.FieldUpdatedAt:
- v, ok := value.(time.Time)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetUpdatedAt(v)
- return nil
- case task.FieldStatus:
- v, ok := value.(uint8)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetStatus(v)
- return nil
- case task.FieldName:
- v, ok := value.(string)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetName(v)
- return nil
- case task.FieldTaskGroup:
- v, ok := value.(string)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetTaskGroup(v)
- return nil
- case task.FieldCronExpression:
- v, ok := value.(string)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetCronExpression(v)
- return nil
- case task.FieldPattern:
- v, ok := value.(string)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetPattern(v)
- return nil
- case task.FieldPayload:
- v, ok := value.(string)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetPayload(v)
- return nil
- }
- return fmt.Errorf("unknown Task field %s", name)
- }
- // AddedFields returns all numeric fields that were incremented/decremented during
- // this mutation.
- func (m *TaskMutation) AddedFields() []string {
- var fields []string
- if m.addstatus != nil {
- fields = append(fields, task.FieldStatus)
- }
- 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 *TaskMutation) AddedField(name string) (ent.Value, bool) {
- switch name {
- case task.FieldStatus:
- return m.AddedStatus()
- }
- 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 *TaskMutation) AddField(name string, value ent.Value) error {
- switch name {
- case task.FieldStatus:
- v, ok := value.(int8)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.AddStatus(v)
- return nil
- }
- return fmt.Errorf("unknown Task numeric field %s", name)
- }
- // ClearedFields returns all nullable fields that were cleared during this
- // mutation.
- func (m *TaskMutation) ClearedFields() []string {
- var fields []string
- if m.FieldCleared(task.FieldStatus) {
- fields = append(fields, task.FieldStatus)
- }
- return fields
- }
- // FieldCleared returns a boolean indicating if a field with the given name was
- // cleared in this mutation.
- func (m *TaskMutation) 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 *TaskMutation) ClearField(name string) error {
- switch name {
- case task.FieldStatus:
- m.ClearStatus()
- return nil
- }
- return fmt.Errorf("unknown Task 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 *TaskMutation) ResetField(name string) error {
- switch name {
- case task.FieldCreatedAt:
- m.ResetCreatedAt()
- return nil
- case task.FieldUpdatedAt:
- m.ResetUpdatedAt()
- return nil
- case task.FieldStatus:
- m.ResetStatus()
- return nil
- case task.FieldName:
- m.ResetName()
- return nil
- case task.FieldTaskGroup:
- m.ResetTaskGroup()
- return nil
- case task.FieldCronExpression:
- m.ResetCronExpression()
- return nil
- case task.FieldPattern:
- m.ResetPattern()
- return nil
- case task.FieldPayload:
- m.ResetPayload()
- return nil
- }
- return fmt.Errorf("unknown Task field %s", name)
- }
- // AddedEdges returns all edge names that were set/added in this mutation.
- func (m *TaskMutation) AddedEdges() []string {
- edges := make([]string, 0, 1)
- if m.task_logs != nil {
- edges = append(edges, task.EdgeTaskLogs)
- }
- return edges
- }
- // AddedIDs returns all IDs (to other nodes) that were added for the given edge
- // name in this mutation.
- func (m *TaskMutation) AddedIDs(name string) []ent.Value {
- switch name {
- case task.EdgeTaskLogs:
- ids := make([]ent.Value, 0, len(m.task_logs))
- for id := range m.task_logs {
- ids = append(ids, id)
- }
- return ids
- }
- return nil
- }
- // RemovedEdges returns all edge names that were removed in this mutation.
- func (m *TaskMutation) RemovedEdges() []string {
- edges := make([]string, 0, 1)
- if m.removedtask_logs != nil {
- edges = append(edges, task.EdgeTaskLogs)
- }
- return edges
- }
- // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
- // the given name in this mutation.
- func (m *TaskMutation) RemovedIDs(name string) []ent.Value {
- switch name {
- case task.EdgeTaskLogs:
- ids := make([]ent.Value, 0, len(m.removedtask_logs))
- for id := range m.removedtask_logs {
- ids = append(ids, id)
- }
- return ids
- }
- return nil
- }
- // ClearedEdges returns all edge names that were cleared in this mutation.
- func (m *TaskMutation) ClearedEdges() []string {
- edges := make([]string, 0, 1)
- if m.clearedtask_logs {
- edges = append(edges, task.EdgeTaskLogs)
- }
- return edges
- }
- // EdgeCleared returns a boolean which indicates if the edge with the given name
- // was cleared in this mutation.
- func (m *TaskMutation) EdgeCleared(name string) bool {
- switch name {
- case task.EdgeTaskLogs:
- return m.clearedtask_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 *TaskMutation) ClearEdge(name string) error {
- switch name {
- }
- return fmt.Errorf("unknown Task 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 *TaskMutation) ResetEdge(name string) error {
- switch name {
- case task.EdgeTaskLogs:
- m.ResetTaskLogs()
- return nil
- }
- return fmt.Errorf("unknown Task edge %s", name)
- }
- // TaskLogMutation represents an operation that mutates the TaskLog nodes in the graph.
- type TaskLogMutation struct {
- config
- op Op
- typ string
- id *uint64
- started_at *time.Time
- finished_at *time.Time
- result *uint8
- addresult *int8
- clearedFields map[string]struct{}
- tasks *uint64
- clearedtasks bool
- done bool
- oldValue func(context.Context) (*TaskLog, error)
- predicates []predicate.TaskLog
- }
- var _ ent.Mutation = (*TaskLogMutation)(nil)
- // tasklogOption allows management of the mutation configuration using functional options.
- type tasklogOption func(*TaskLogMutation)
- // newTaskLogMutation creates new mutation for the TaskLog entity.
- func newTaskLogMutation(c config, op Op, opts ...tasklogOption) *TaskLogMutation {
- m := &TaskLogMutation{
- config: c,
- op: op,
- typ: TypeTaskLog,
- clearedFields: make(map[string]struct{}),
- }
- for _, opt := range opts {
- opt(m)
- }
- return m
- }
- // withTaskLogID sets the ID field of the mutation.
- func withTaskLogID(id uint64) tasklogOption {
- return func(m *TaskLogMutation) {
- var (
- err error
- once sync.Once
- value *TaskLog
- )
- m.oldValue = func(ctx context.Context) (*TaskLog, error) {
- once.Do(func() {
- if m.done {
- err = errors.New("querying old values post mutation is not allowed")
- } else {
- value, err = m.Client().TaskLog.Get(ctx, id)
- }
- })
- return value, err
- }
- m.id = &id
- }
- }
- // withTaskLog sets the old TaskLog of the mutation.
- func withTaskLog(node *TaskLog) tasklogOption {
- return func(m *TaskLogMutation) {
- m.oldValue = func(context.Context) (*TaskLog, 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 TaskLogMutation) 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 TaskLogMutation) 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 TaskLog entities.
- func (m *TaskLogMutation) SetID(id uint64) {
- 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 *TaskLogMutation) ID() (id uint64, 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 *TaskLogMutation) IDs(ctx context.Context) ([]uint64, error) {
- switch {
- case m.op.Is(OpUpdateOne | OpDeleteOne):
- id, exists := m.ID()
- if exists {
- return []uint64{id}, nil
- }
- fallthrough
- case m.op.Is(OpUpdate | OpDelete):
- return m.Client().TaskLog.Query().Where(m.predicates...).IDs(ctx)
- default:
- return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
- }
- }
- // SetStartedAt sets the "started_at" field.
- func (m *TaskLogMutation) SetStartedAt(t time.Time) {
- m.started_at = &t
- }
- // StartedAt returns the value of the "started_at" field in the mutation.
- func (m *TaskLogMutation) StartedAt() (r time.Time, exists bool) {
- v := m.started_at
- if v == nil {
- return
- }
- return *v, true
- }
- // OldStartedAt returns the old "started_at" field's value of the TaskLog entity.
- // If the TaskLog 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 *TaskLogMutation) OldStartedAt(ctx context.Context) (v time.Time, err error) {
- if !m.op.Is(OpUpdateOne) {
- return v, errors.New("OldStartedAt is only allowed on UpdateOne operations")
- }
- if m.id == nil || m.oldValue == nil {
- return v, errors.New("OldStartedAt requires an ID field in the mutation")
- }
- oldValue, err := m.oldValue(ctx)
- if err != nil {
- return v, fmt.Errorf("querying old value for OldStartedAt: %w", err)
- }
- return oldValue.StartedAt, nil
- }
- // ResetStartedAt resets all changes to the "started_at" field.
- func (m *TaskLogMutation) ResetStartedAt() {
- m.started_at = nil
- }
- // SetFinishedAt sets the "finished_at" field.
- func (m *TaskLogMutation) SetFinishedAt(t time.Time) {
- m.finished_at = &t
- }
- // FinishedAt returns the value of the "finished_at" field in the mutation.
- func (m *TaskLogMutation) FinishedAt() (r time.Time, exists bool) {
- v := m.finished_at
- if v == nil {
- return
- }
- return *v, true
- }
- // OldFinishedAt returns the old "finished_at" field's value of the TaskLog entity.
- // If the TaskLog 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 *TaskLogMutation) OldFinishedAt(ctx context.Context) (v time.Time, err error) {
- if !m.op.Is(OpUpdateOne) {
- return v, errors.New("OldFinishedAt is only allowed on UpdateOne operations")
- }
- if m.id == nil || m.oldValue == nil {
- return v, errors.New("OldFinishedAt requires an ID field in the mutation")
- }
- oldValue, err := m.oldValue(ctx)
- if err != nil {
- return v, fmt.Errorf("querying old value for OldFinishedAt: %w", err)
- }
- return oldValue.FinishedAt, nil
- }
- // ResetFinishedAt resets all changes to the "finished_at" field.
- func (m *TaskLogMutation) ResetFinishedAt() {
- m.finished_at = nil
- }
- // SetResult sets the "result" field.
- func (m *TaskLogMutation) SetResult(u uint8) {
- m.result = &u
- m.addresult = nil
- }
- // Result returns the value of the "result" field in the mutation.
- func (m *TaskLogMutation) Result() (r uint8, exists bool) {
- v := m.result
- if v == nil {
- return
- }
- return *v, true
- }
- // OldResult returns the old "result" field's value of the TaskLog entity.
- // If the TaskLog 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 *TaskLogMutation) OldResult(ctx context.Context) (v uint8, err error) {
- if !m.op.Is(OpUpdateOne) {
- return v, errors.New("OldResult is only allowed on UpdateOne operations")
- }
- if m.id == nil || m.oldValue == nil {
- return v, errors.New("OldResult requires an ID field in the mutation")
- }
- oldValue, err := m.oldValue(ctx)
- if err != nil {
- return v, fmt.Errorf("querying old value for OldResult: %w", err)
- }
- return oldValue.Result, nil
- }
- // AddResult adds u to the "result" field.
- func (m *TaskLogMutation) AddResult(u int8) {
- if m.addresult != nil {
- *m.addresult += u
- } else {
- m.addresult = &u
- }
- }
- // AddedResult returns the value that was added to the "result" field in this mutation.
- func (m *TaskLogMutation) AddedResult() (r int8, exists bool) {
- v := m.addresult
- if v == nil {
- return
- }
- return *v, true
- }
- // ResetResult resets all changes to the "result" field.
- func (m *TaskLogMutation) ResetResult() {
- m.result = nil
- m.addresult = nil
- }
- // SetTasksID sets the "tasks" edge to the Task entity by id.
- func (m *TaskLogMutation) SetTasksID(id uint64) {
- m.tasks = &id
- }
- // ClearTasks clears the "tasks" edge to the Task entity.
- func (m *TaskLogMutation) ClearTasks() {
- m.clearedtasks = true
- }
- // TasksCleared reports if the "tasks" edge to the Task entity was cleared.
- func (m *TaskLogMutation) TasksCleared() bool {
- return m.clearedtasks
- }
- // TasksID returns the "tasks" edge ID in the mutation.
- func (m *TaskLogMutation) TasksID() (id uint64, exists bool) {
- if m.tasks != nil {
- return *m.tasks, true
- }
- return
- }
- // TasksIDs returns the "tasks" edge IDs in the mutation.
- // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
- // TasksID instead. It exists only for internal usage by the builders.
- func (m *TaskLogMutation) TasksIDs() (ids []uint64) {
- if id := m.tasks; id != nil {
- ids = append(ids, *id)
- }
- return
- }
- // ResetTasks resets all changes to the "tasks" edge.
- func (m *TaskLogMutation) ResetTasks() {
- m.tasks = nil
- m.clearedtasks = false
- }
- // Where appends a list predicates to the TaskLogMutation builder.
- func (m *TaskLogMutation) Where(ps ...predicate.TaskLog) {
- m.predicates = append(m.predicates, ps...)
- }
- // WhereP appends storage-level predicates to the TaskLogMutation builder. Using this method,
- // users can use type-assertion to append predicates that do not depend on any generated package.
- func (m *TaskLogMutation) WhereP(ps ...func(*sql.Selector)) {
- p := make([]predicate.TaskLog, len(ps))
- for i := range ps {
- p[i] = ps[i]
- }
- m.Where(p...)
- }
- // Op returns the operation name.
- func (m *TaskLogMutation) Op() Op {
- return m.op
- }
- // SetOp allows setting the mutation operation.
- func (m *TaskLogMutation) SetOp(op Op) {
- m.op = op
- }
- // Type returns the node type of this mutation (TaskLog).
- func (m *TaskLogMutation) 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 *TaskLogMutation) Fields() []string {
- fields := make([]string, 0, 3)
- if m.started_at != nil {
- fields = append(fields, tasklog.FieldStartedAt)
- }
- if m.finished_at != nil {
- fields = append(fields, tasklog.FieldFinishedAt)
- }
- if m.result != nil {
- fields = append(fields, tasklog.FieldResult)
- }
- 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 *TaskLogMutation) Field(name string) (ent.Value, bool) {
- switch name {
- case tasklog.FieldStartedAt:
- return m.StartedAt()
- case tasklog.FieldFinishedAt:
- return m.FinishedAt()
- case tasklog.FieldResult:
- return m.Result()
- }
- 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 *TaskLogMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
- switch name {
- case tasklog.FieldStartedAt:
- return m.OldStartedAt(ctx)
- case tasklog.FieldFinishedAt:
- return m.OldFinishedAt(ctx)
- case tasklog.FieldResult:
- return m.OldResult(ctx)
- }
- return nil, fmt.Errorf("unknown TaskLog 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 *TaskLogMutation) SetField(name string, value ent.Value) error {
- switch name {
- case tasklog.FieldStartedAt:
- v, ok := value.(time.Time)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetStartedAt(v)
- return nil
- case tasklog.FieldFinishedAt:
- v, ok := value.(time.Time)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetFinishedAt(v)
- return nil
- case tasklog.FieldResult:
- v, ok := value.(uint8)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.SetResult(v)
- return nil
- }
- return fmt.Errorf("unknown TaskLog field %s", name)
- }
- // AddedFields returns all numeric fields that were incremented/decremented during
- // this mutation.
- func (m *TaskLogMutation) AddedFields() []string {
- var fields []string
- if m.addresult != nil {
- fields = append(fields, tasklog.FieldResult)
- }
- 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 *TaskLogMutation) AddedField(name string) (ent.Value, bool) {
- switch name {
- case tasklog.FieldResult:
- return m.AddedResult()
- }
- 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 *TaskLogMutation) AddField(name string, value ent.Value) error {
- switch name {
- case tasklog.FieldResult:
- v, ok := value.(int8)
- if !ok {
- return fmt.Errorf("unexpected type %T for field %s", value, name)
- }
- m.AddResult(v)
- return nil
- }
- return fmt.Errorf("unknown TaskLog numeric field %s", name)
- }
- // ClearedFields returns all nullable fields that were cleared during this
- // mutation.
- func (m *TaskLogMutation) ClearedFields() []string {
- return nil
- }
- // FieldCleared returns a boolean indicating if a field with the given name was
- // cleared in this mutation.
- func (m *TaskLogMutation) 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 *TaskLogMutation) ClearField(name string) error {
- return fmt.Errorf("unknown TaskLog 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 *TaskLogMutation) ResetField(name string) error {
- switch name {
- case tasklog.FieldStartedAt:
- m.ResetStartedAt()
- return nil
- case tasklog.FieldFinishedAt:
- m.ResetFinishedAt()
- return nil
- case tasklog.FieldResult:
- m.ResetResult()
- return nil
- }
- return fmt.Errorf("unknown TaskLog field %s", name)
- }
- // AddedEdges returns all edge names that were set/added in this mutation.
- func (m *TaskLogMutation) AddedEdges() []string {
- edges := make([]string, 0, 1)
- if m.tasks != nil {
- edges = append(edges, tasklog.EdgeTasks)
- }
- return edges
- }
- // AddedIDs returns all IDs (to other nodes) that were added for the given edge
- // name in this mutation.
- func (m *TaskLogMutation) AddedIDs(name string) []ent.Value {
- switch name {
- case tasklog.EdgeTasks:
- if id := m.tasks; id != nil {
- return []ent.Value{*id}
- }
- }
- return nil
- }
- // RemovedEdges returns all edge names that were removed in this mutation.
- func (m *TaskLogMutation) 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 *TaskLogMutation) RemovedIDs(name string) []ent.Value {
- return nil
- }
- // ClearedEdges returns all edge names that were cleared in this mutation.
- func (m *TaskLogMutation) ClearedEdges() []string {
- edges := make([]string, 0, 1)
- if m.clearedtasks {
- edges = append(edges, tasklog.EdgeTasks)
- }
- return edges
- }
- // EdgeCleared returns a boolean which indicates if the edge with the given name
- // was cleared in this mutation.
- func (m *TaskLogMutation) EdgeCleared(name string) bool {
- switch name {
- case tasklog.EdgeTasks:
- return m.clearedtasks
- }
- 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 *TaskLogMutation) ClearEdge(name string) error {
- switch name {
- case tasklog.EdgeTasks:
- m.ClearTasks()
- return nil
- }
- return fmt.Errorf("unknown TaskLog 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 *TaskLogMutation) ResetEdge(name string) error {
- switch name {
- case tasklog.EdgeTasks:
- m.ResetTasks()
- return nil
- }
- return fmt.Errorf("unknown TaskLog edge %s", name)
- }
|