| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- "github.com/Wei-Shaw/sub2api/ent/batchimageevent"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- )
- // BatchImageEventUpdate is the builder for updating BatchImageEvent entities.
- type BatchImageEventUpdate struct {
- config
- hooks []Hook
- mutation *BatchImageEventMutation
- }
- // Where appends a list predicates to the BatchImageEventUpdate builder.
- func (_u *BatchImageEventUpdate) Where(ps ...predicate.BatchImageEvent) *BatchImageEventUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetJobID sets the "job_id" field.
- func (_u *BatchImageEventUpdate) SetJobID(v string) *BatchImageEventUpdate {
- _u.mutation.SetJobID(v)
- return _u
- }
- // SetNillableJobID sets the "job_id" field if the given value is not nil.
- func (_u *BatchImageEventUpdate) SetNillableJobID(v *string) *BatchImageEventUpdate {
- if v != nil {
- _u.SetJobID(*v)
- }
- return _u
- }
- // SetEventType sets the "event_type" field.
- func (_u *BatchImageEventUpdate) SetEventType(v string) *BatchImageEventUpdate {
- _u.mutation.SetEventType(v)
- return _u
- }
- // SetNillableEventType sets the "event_type" field if the given value is not nil.
- func (_u *BatchImageEventUpdate) SetNillableEventType(v *string) *BatchImageEventUpdate {
- if v != nil {
- _u.SetEventType(*v)
- }
- return _u
- }
- // SetPayload sets the "payload" field.
- func (_u *BatchImageEventUpdate) SetPayload(v map[string]interface{}) *BatchImageEventUpdate {
- _u.mutation.SetPayload(v)
- return _u
- }
- // ClearPayload clears the value of the "payload" field.
- func (_u *BatchImageEventUpdate) ClearPayload() *BatchImageEventUpdate {
- _u.mutation.ClearPayload()
- return _u
- }
- // SetEventHash sets the "event_hash" field.
- func (_u *BatchImageEventUpdate) SetEventHash(v string) *BatchImageEventUpdate {
- _u.mutation.SetEventHash(v)
- return _u
- }
- // SetNillableEventHash sets the "event_hash" field if the given value is not nil.
- func (_u *BatchImageEventUpdate) SetNillableEventHash(v *string) *BatchImageEventUpdate {
- if v != nil {
- _u.SetEventHash(*v)
- }
- return _u
- }
- // ClearEventHash clears the value of the "event_hash" field.
- func (_u *BatchImageEventUpdate) ClearEventHash() *BatchImageEventUpdate {
- _u.mutation.ClearEventHash()
- return _u
- }
- // Mutation returns the BatchImageEventMutation object of the builder.
- func (_u *BatchImageEventUpdate) Mutation() *BatchImageEventMutation {
- return _u.mutation
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *BatchImageEventUpdate) Save(ctx context.Context) (int, error) {
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *BatchImageEventUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *BatchImageEventUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *BatchImageEventUpdate) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *BatchImageEventUpdate) check() error {
- if v, ok := _u.mutation.JobID(); ok {
- if err := batchimageevent.JobIDValidator(v); err != nil {
- return &ValidationError{Name: "job_id", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.job_id": %w`, err)}
- }
- }
- if v, ok := _u.mutation.EventType(); ok {
- if err := batchimageevent.EventTypeValidator(v); err != nil {
- return &ValidationError{Name: "event_type", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.event_type": %w`, err)}
- }
- }
- if v, ok := _u.mutation.EventHash(); ok {
- if err := batchimageevent.EventHashValidator(v); err != nil {
- return &ValidationError{Name: "event_hash", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.event_hash": %w`, err)}
- }
- }
- return nil
- }
- func (_u *BatchImageEventUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(batchimageevent.Table, batchimageevent.Columns, sqlgraph.NewFieldSpec(batchimageevent.FieldID, field.TypeInt64))
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.JobID(); ok {
- _spec.SetField(batchimageevent.FieldJobID, field.TypeString, value)
- }
- if value, ok := _u.mutation.EventType(); ok {
- _spec.SetField(batchimageevent.FieldEventType, field.TypeString, value)
- }
- if value, ok := _u.mutation.Payload(); ok {
- _spec.SetField(batchimageevent.FieldPayload, field.TypeJSON, value)
- }
- if _u.mutation.PayloadCleared() {
- _spec.ClearField(batchimageevent.FieldPayload, field.TypeJSON)
- }
- if value, ok := _u.mutation.EventHash(); ok {
- _spec.SetField(batchimageevent.FieldEventHash, field.TypeString, value)
- }
- if _u.mutation.EventHashCleared() {
- _spec.ClearField(batchimageevent.FieldEventHash, field.TypeString)
- }
- if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{batchimageevent.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // BatchImageEventUpdateOne is the builder for updating a single BatchImageEvent entity.
- type BatchImageEventUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *BatchImageEventMutation
- }
- // SetJobID sets the "job_id" field.
- func (_u *BatchImageEventUpdateOne) SetJobID(v string) *BatchImageEventUpdateOne {
- _u.mutation.SetJobID(v)
- return _u
- }
- // SetNillableJobID sets the "job_id" field if the given value is not nil.
- func (_u *BatchImageEventUpdateOne) SetNillableJobID(v *string) *BatchImageEventUpdateOne {
- if v != nil {
- _u.SetJobID(*v)
- }
- return _u
- }
- // SetEventType sets the "event_type" field.
- func (_u *BatchImageEventUpdateOne) SetEventType(v string) *BatchImageEventUpdateOne {
- _u.mutation.SetEventType(v)
- return _u
- }
- // SetNillableEventType sets the "event_type" field if the given value is not nil.
- func (_u *BatchImageEventUpdateOne) SetNillableEventType(v *string) *BatchImageEventUpdateOne {
- if v != nil {
- _u.SetEventType(*v)
- }
- return _u
- }
- // SetPayload sets the "payload" field.
- func (_u *BatchImageEventUpdateOne) SetPayload(v map[string]interface{}) *BatchImageEventUpdateOne {
- _u.mutation.SetPayload(v)
- return _u
- }
- // ClearPayload clears the value of the "payload" field.
- func (_u *BatchImageEventUpdateOne) ClearPayload() *BatchImageEventUpdateOne {
- _u.mutation.ClearPayload()
- return _u
- }
- // SetEventHash sets the "event_hash" field.
- func (_u *BatchImageEventUpdateOne) SetEventHash(v string) *BatchImageEventUpdateOne {
- _u.mutation.SetEventHash(v)
- return _u
- }
- // SetNillableEventHash sets the "event_hash" field if the given value is not nil.
- func (_u *BatchImageEventUpdateOne) SetNillableEventHash(v *string) *BatchImageEventUpdateOne {
- if v != nil {
- _u.SetEventHash(*v)
- }
- return _u
- }
- // ClearEventHash clears the value of the "event_hash" field.
- func (_u *BatchImageEventUpdateOne) ClearEventHash() *BatchImageEventUpdateOne {
- _u.mutation.ClearEventHash()
- return _u
- }
- // Mutation returns the BatchImageEventMutation object of the builder.
- func (_u *BatchImageEventUpdateOne) Mutation() *BatchImageEventMutation {
- return _u.mutation
- }
- // Where appends a list predicates to the BatchImageEventUpdate builder.
- func (_u *BatchImageEventUpdateOne) Where(ps ...predicate.BatchImageEvent) *BatchImageEventUpdateOne {
- _u.mutation.Where(ps...)
- return _u
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (_u *BatchImageEventUpdateOne) Select(field string, fields ...string) *BatchImageEventUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated BatchImageEvent entity.
- func (_u *BatchImageEventUpdateOne) Save(ctx context.Context) (*BatchImageEvent, error) {
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *BatchImageEventUpdateOne) SaveX(ctx context.Context) *BatchImageEvent {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *BatchImageEventUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *BatchImageEventUpdateOne) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *BatchImageEventUpdateOne) check() error {
- if v, ok := _u.mutation.JobID(); ok {
- if err := batchimageevent.JobIDValidator(v); err != nil {
- return &ValidationError{Name: "job_id", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.job_id": %w`, err)}
- }
- }
- if v, ok := _u.mutation.EventType(); ok {
- if err := batchimageevent.EventTypeValidator(v); err != nil {
- return &ValidationError{Name: "event_type", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.event_type": %w`, err)}
- }
- }
- if v, ok := _u.mutation.EventHash(); ok {
- if err := batchimageevent.EventHashValidator(v); err != nil {
- return &ValidationError{Name: "event_hash", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.event_hash": %w`, err)}
- }
- }
- return nil
- }
- func (_u *BatchImageEventUpdateOne) sqlSave(ctx context.Context) (_node *BatchImageEvent, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(batchimageevent.Table, batchimageevent.Columns, sqlgraph.NewFieldSpec(batchimageevent.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BatchImageEvent.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := _u.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, batchimageevent.FieldID)
- for _, f := range fields {
- if !batchimageevent.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != batchimageevent.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.JobID(); ok {
- _spec.SetField(batchimageevent.FieldJobID, field.TypeString, value)
- }
- if value, ok := _u.mutation.EventType(); ok {
- _spec.SetField(batchimageevent.FieldEventType, field.TypeString, value)
- }
- if value, ok := _u.mutation.Payload(); ok {
- _spec.SetField(batchimageevent.FieldPayload, field.TypeJSON, value)
- }
- if _u.mutation.PayloadCleared() {
- _spec.ClearField(batchimageevent.FieldPayload, field.TypeJSON)
- }
- if value, ok := _u.mutation.EventHash(); ok {
- _spec.SetField(batchimageevent.FieldEventHash, field.TypeString, value)
- }
- if _u.mutation.EventHashCleared() {
- _spec.ClearField(batchimageevent.FieldEventHash, field.TypeString)
- }
- _node = &BatchImageEvent{config: _u.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{batchimageevent.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|