123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- "github.com/suyuan32/simple-admin-job/ent/predicate"
- "github.com/suyuan32/simple-admin-job/ent/task"
- "github.com/suyuan32/simple-admin-job/ent/tasklog"
- )
- // TaskLogUpdate is the builder for updating TaskLog entities.
- type TaskLogUpdate struct {
- config
- hooks []Hook
- mutation *TaskLogMutation
- }
- // Where appends a list predicates to the TaskLogUpdate builder.
- func (tlu *TaskLogUpdate) Where(ps ...predicate.TaskLog) *TaskLogUpdate {
- tlu.mutation.Where(ps...)
- return tlu
- }
- // SetFinishedAt sets the "finished_at" field.
- func (tlu *TaskLogUpdate) SetFinishedAt(t time.Time) *TaskLogUpdate {
- tlu.mutation.SetFinishedAt(t)
- return tlu
- }
- // SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
- func (tlu *TaskLogUpdate) SetNillableFinishedAt(t *time.Time) *TaskLogUpdate {
- if t != nil {
- tlu.SetFinishedAt(*t)
- }
- return tlu
- }
- // SetResult sets the "result" field.
- func (tlu *TaskLogUpdate) SetResult(u uint8) *TaskLogUpdate {
- tlu.mutation.ResetResult()
- tlu.mutation.SetResult(u)
- return tlu
- }
- // SetNillableResult sets the "result" field if the given value is not nil.
- func (tlu *TaskLogUpdate) SetNillableResult(u *uint8) *TaskLogUpdate {
- if u != nil {
- tlu.SetResult(*u)
- }
- return tlu
- }
- // AddResult adds u to the "result" field.
- func (tlu *TaskLogUpdate) AddResult(u int8) *TaskLogUpdate {
- tlu.mutation.AddResult(u)
- return tlu
- }
- // SetTasksID sets the "tasks" edge to the Task entity by ID.
- func (tlu *TaskLogUpdate) SetTasksID(id uint64) *TaskLogUpdate {
- tlu.mutation.SetTasksID(id)
- return tlu
- }
- // SetNillableTasksID sets the "tasks" edge to the Task entity by ID if the given value is not nil.
- func (tlu *TaskLogUpdate) SetNillableTasksID(id *uint64) *TaskLogUpdate {
- if id != nil {
- tlu = tlu.SetTasksID(*id)
- }
- return tlu
- }
- // SetTasks sets the "tasks" edge to the Task entity.
- func (tlu *TaskLogUpdate) SetTasks(t *Task) *TaskLogUpdate {
- return tlu.SetTasksID(t.ID)
- }
- // Mutation returns the TaskLogMutation object of the builder.
- func (tlu *TaskLogUpdate) Mutation() *TaskLogMutation {
- return tlu.mutation
- }
- // ClearTasks clears the "tasks" edge to the Task entity.
- func (tlu *TaskLogUpdate) ClearTasks() *TaskLogUpdate {
- tlu.mutation.ClearTasks()
- return tlu
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (tlu *TaskLogUpdate) Save(ctx context.Context) (int, error) {
- return withHooks(ctx, tlu.sqlSave, tlu.mutation, tlu.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (tlu *TaskLogUpdate) SaveX(ctx context.Context) int {
- affected, err := tlu.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (tlu *TaskLogUpdate) Exec(ctx context.Context) error {
- _, err := tlu.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (tlu *TaskLogUpdate) ExecX(ctx context.Context) {
- if err := tlu.Exec(ctx); err != nil {
- panic(err)
- }
- }
- func (tlu *TaskLogUpdate) sqlSave(ctx context.Context) (n int, err error) {
- _spec := sqlgraph.NewUpdateSpec(tasklog.Table, tasklog.Columns, sqlgraph.NewFieldSpec(tasklog.FieldID, field.TypeUint64))
- if ps := tlu.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := tlu.mutation.FinishedAt(); ok {
- _spec.SetField(tasklog.FieldFinishedAt, field.TypeTime, value)
- }
- if value, ok := tlu.mutation.Result(); ok {
- _spec.SetField(tasklog.FieldResult, field.TypeUint8, value)
- }
- if value, ok := tlu.mutation.AddedResult(); ok {
- _spec.AddField(tasklog.FieldResult, field.TypeUint8, value)
- }
- if tlu.mutation.TasksCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: tasklog.TasksTable,
- Columns: []string{tasklog.TasksColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := tlu.mutation.TasksIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: tasklog.TasksTable,
- Columns: []string{tasklog.TasksColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, tlu.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{tasklog.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- tlu.mutation.done = true
- return n, nil
- }
- // TaskLogUpdateOne is the builder for updating a single TaskLog entity.
- type TaskLogUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *TaskLogMutation
- }
- // SetFinishedAt sets the "finished_at" field.
- func (tluo *TaskLogUpdateOne) SetFinishedAt(t time.Time) *TaskLogUpdateOne {
- tluo.mutation.SetFinishedAt(t)
- return tluo
- }
- // SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
- func (tluo *TaskLogUpdateOne) SetNillableFinishedAt(t *time.Time) *TaskLogUpdateOne {
- if t != nil {
- tluo.SetFinishedAt(*t)
- }
- return tluo
- }
- // SetResult sets the "result" field.
- func (tluo *TaskLogUpdateOne) SetResult(u uint8) *TaskLogUpdateOne {
- tluo.mutation.ResetResult()
- tluo.mutation.SetResult(u)
- return tluo
- }
- // SetNillableResult sets the "result" field if the given value is not nil.
- func (tluo *TaskLogUpdateOne) SetNillableResult(u *uint8) *TaskLogUpdateOne {
- if u != nil {
- tluo.SetResult(*u)
- }
- return tluo
- }
- // AddResult adds u to the "result" field.
- func (tluo *TaskLogUpdateOne) AddResult(u int8) *TaskLogUpdateOne {
- tluo.mutation.AddResult(u)
- return tluo
- }
- // SetTasksID sets the "tasks" edge to the Task entity by ID.
- func (tluo *TaskLogUpdateOne) SetTasksID(id uint64) *TaskLogUpdateOne {
- tluo.mutation.SetTasksID(id)
- return tluo
- }
- // SetNillableTasksID sets the "tasks" edge to the Task entity by ID if the given value is not nil.
- func (tluo *TaskLogUpdateOne) SetNillableTasksID(id *uint64) *TaskLogUpdateOne {
- if id != nil {
- tluo = tluo.SetTasksID(*id)
- }
- return tluo
- }
- // SetTasks sets the "tasks" edge to the Task entity.
- func (tluo *TaskLogUpdateOne) SetTasks(t *Task) *TaskLogUpdateOne {
- return tluo.SetTasksID(t.ID)
- }
- // Mutation returns the TaskLogMutation object of the builder.
- func (tluo *TaskLogUpdateOne) Mutation() *TaskLogMutation {
- return tluo.mutation
- }
- // ClearTasks clears the "tasks" edge to the Task entity.
- func (tluo *TaskLogUpdateOne) ClearTasks() *TaskLogUpdateOne {
- tluo.mutation.ClearTasks()
- return tluo
- }
- // Where appends a list predicates to the TaskLogUpdate builder.
- func (tluo *TaskLogUpdateOne) Where(ps ...predicate.TaskLog) *TaskLogUpdateOne {
- tluo.mutation.Where(ps...)
- return tluo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (tluo *TaskLogUpdateOne) Select(field string, fields ...string) *TaskLogUpdateOne {
- tluo.fields = append([]string{field}, fields...)
- return tluo
- }
- // Save executes the query and returns the updated TaskLog entity.
- func (tluo *TaskLogUpdateOne) Save(ctx context.Context) (*TaskLog, error) {
- return withHooks(ctx, tluo.sqlSave, tluo.mutation, tluo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (tluo *TaskLogUpdateOne) SaveX(ctx context.Context) *TaskLog {
- node, err := tluo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (tluo *TaskLogUpdateOne) Exec(ctx context.Context) error {
- _, err := tluo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (tluo *TaskLogUpdateOne) ExecX(ctx context.Context) {
- if err := tluo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- func (tluo *TaskLogUpdateOne) sqlSave(ctx context.Context) (_node *TaskLog, err error) {
- _spec := sqlgraph.NewUpdateSpec(tasklog.Table, tasklog.Columns, sqlgraph.NewFieldSpec(tasklog.FieldID, field.TypeUint64))
- id, ok := tluo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "TaskLog.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := tluo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, tasklog.FieldID)
- for _, f := range fields {
- if !tasklog.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != tasklog.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := tluo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := tluo.mutation.FinishedAt(); ok {
- _spec.SetField(tasklog.FieldFinishedAt, field.TypeTime, value)
- }
- if value, ok := tluo.mutation.Result(); ok {
- _spec.SetField(tasklog.FieldResult, field.TypeUint8, value)
- }
- if value, ok := tluo.mutation.AddedResult(); ok {
- _spec.AddField(tasklog.FieldResult, field.TypeUint8, value)
- }
- if tluo.mutation.TasksCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: tasklog.TasksTable,
- Columns: []string{tasklog.TasksColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := tluo.mutation.TasksIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: tasklog.TasksTable,
- Columns: []string{tasklog.TasksColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &TaskLog{config: tluo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, tluo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{tasklog.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- tluo.mutation.done = true
- return _node, nil
- }
|