report_update.go•19.8 kB
// 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/Southclaws/storyden/internal/ent/account"
"github.com/Southclaws/storyden/internal/ent/predicate"
"github.com/Southclaws/storyden/internal/ent/report"
"github.com/rs/xid"
)
// ReportUpdate is the builder for updating Report entities.
type ReportUpdate struct {
config
hooks []Hook
mutation *ReportMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the ReportUpdate builder.
func (_u *ReportUpdate) Where(ps ...predicate.Report) *ReportUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ReportUpdate) SetUpdatedAt(v time.Time) *ReportUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetTargetID sets the "target_id" field.
func (_u *ReportUpdate) SetTargetID(v xid.ID) *ReportUpdate {
_u.mutation.SetTargetID(v)
return _u
}
// SetNillableTargetID sets the "target_id" field if the given value is not nil.
func (_u *ReportUpdate) SetNillableTargetID(v *xid.ID) *ReportUpdate {
if v != nil {
_u.SetTargetID(*v)
}
return _u
}
// SetTargetKind sets the "target_kind" field.
func (_u *ReportUpdate) SetTargetKind(v string) *ReportUpdate {
_u.mutation.SetTargetKind(v)
return _u
}
// SetNillableTargetKind sets the "target_kind" field if the given value is not nil.
func (_u *ReportUpdate) SetNillableTargetKind(v *string) *ReportUpdate {
if v != nil {
_u.SetTargetKind(*v)
}
return _u
}
// SetReportedByID sets the "reported_by_id" field.
func (_u *ReportUpdate) SetReportedByID(v xid.ID) *ReportUpdate {
_u.mutation.SetReportedByID(v)
return _u
}
// SetNillableReportedByID sets the "reported_by_id" field if the given value is not nil.
func (_u *ReportUpdate) SetNillableReportedByID(v *xid.ID) *ReportUpdate {
if v != nil {
_u.SetReportedByID(*v)
}
return _u
}
// SetHandledByID sets the "handled_by_id" field.
func (_u *ReportUpdate) SetHandledByID(v xid.ID) *ReportUpdate {
_u.mutation.SetHandledByID(v)
return _u
}
// SetNillableHandledByID sets the "handled_by_id" field if the given value is not nil.
func (_u *ReportUpdate) SetNillableHandledByID(v *xid.ID) *ReportUpdate {
if v != nil {
_u.SetHandledByID(*v)
}
return _u
}
// ClearHandledByID clears the value of the "handled_by_id" field.
func (_u *ReportUpdate) ClearHandledByID() *ReportUpdate {
_u.mutation.ClearHandledByID()
return _u
}
// SetComment sets the "comment" field.
func (_u *ReportUpdate) SetComment(v string) *ReportUpdate {
_u.mutation.SetComment(v)
return _u
}
// SetNillableComment sets the "comment" field if the given value is not nil.
func (_u *ReportUpdate) SetNillableComment(v *string) *ReportUpdate {
if v != nil {
_u.SetComment(*v)
}
return _u
}
// ClearComment clears the value of the "comment" field.
func (_u *ReportUpdate) ClearComment() *ReportUpdate {
_u.mutation.ClearComment()
return _u
}
// SetReason sets the "reason" field.
func (_u *ReportUpdate) SetReason(v string) *ReportUpdate {
_u.mutation.SetReason(v)
return _u
}
// SetNillableReason sets the "reason" field if the given value is not nil.
func (_u *ReportUpdate) SetNillableReason(v *string) *ReportUpdate {
if v != nil {
_u.SetReason(*v)
}
return _u
}
// ClearReason clears the value of the "reason" field.
func (_u *ReportUpdate) ClearReason() *ReportUpdate {
_u.mutation.ClearReason()
return _u
}
// SetStatus sets the "status" field.
func (_u *ReportUpdate) SetStatus(v string) *ReportUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *ReportUpdate) SetNillableStatus(v *string) *ReportUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetReportedBy sets the "reported_by" edge to the Account entity.
func (_u *ReportUpdate) SetReportedBy(v *Account) *ReportUpdate {
return _u.SetReportedByID(v.ID)
}
// SetHandledBy sets the "handled_by" edge to the Account entity.
func (_u *ReportUpdate) SetHandledBy(v *Account) *ReportUpdate {
return _u.SetHandledByID(v.ID)
}
// Mutation returns the ReportMutation object of the builder.
func (_u *ReportUpdate) Mutation() *ReportMutation {
return _u.mutation
}
// ClearReportedBy clears the "reported_by" edge to the Account entity.
func (_u *ReportUpdate) ClearReportedBy() *ReportUpdate {
_u.mutation.ClearReportedBy()
return _u
}
// ClearHandledBy clears the "handled_by" edge to the Account entity.
func (_u *ReportUpdate) ClearHandledBy() *ReportUpdate {
_u.mutation.ClearHandledBy()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ReportUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ReportUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ReportUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ReportUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ReportUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := report.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *ReportUpdate) check() error {
if _u.mutation.ReportedByCleared() && len(_u.mutation.ReportedByIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "Report.reported_by"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *ReportUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ReportUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *ReportUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(report.Table, report.Columns, sqlgraph.NewFieldSpec(report.FieldID, field.TypeString))
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.UpdatedAt(); ok {
_spec.SetField(report.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.TargetID(); ok {
_spec.SetField(report.FieldTargetID, field.TypeString, value)
}
if value, ok := _u.mutation.TargetKind(); ok {
_spec.SetField(report.FieldTargetKind, field.TypeString, value)
}
if value, ok := _u.mutation.Comment(); ok {
_spec.SetField(report.FieldComment, field.TypeString, value)
}
if _u.mutation.CommentCleared() {
_spec.ClearField(report.FieldComment, field.TypeString)
}
if value, ok := _u.mutation.Reason(); ok {
_spec.SetField(report.FieldReason, field.TypeString, value)
}
if _u.mutation.ReasonCleared() {
_spec.ClearField(report.FieldReason, field.TypeString)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(report.FieldStatus, field.TypeString, value)
}
if _u.mutation.ReportedByCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: report.ReportedByTable,
Columns: []string{report.ReportedByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.ReportedByIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: report.ReportedByTable,
Columns: []string{report.ReportedByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.HandledByCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: report.HandledByTable,
Columns: []string{report.HandledByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.HandledByIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: report.HandledByTable,
Columns: []string{report.HandledByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{report.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ReportUpdateOne is the builder for updating a single Report entity.
type ReportUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ReportMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ReportUpdateOne) SetUpdatedAt(v time.Time) *ReportUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetTargetID sets the "target_id" field.
func (_u *ReportUpdateOne) SetTargetID(v xid.ID) *ReportUpdateOne {
_u.mutation.SetTargetID(v)
return _u
}
// SetNillableTargetID sets the "target_id" field if the given value is not nil.
func (_u *ReportUpdateOne) SetNillableTargetID(v *xid.ID) *ReportUpdateOne {
if v != nil {
_u.SetTargetID(*v)
}
return _u
}
// SetTargetKind sets the "target_kind" field.
func (_u *ReportUpdateOne) SetTargetKind(v string) *ReportUpdateOne {
_u.mutation.SetTargetKind(v)
return _u
}
// SetNillableTargetKind sets the "target_kind" field if the given value is not nil.
func (_u *ReportUpdateOne) SetNillableTargetKind(v *string) *ReportUpdateOne {
if v != nil {
_u.SetTargetKind(*v)
}
return _u
}
// SetReportedByID sets the "reported_by_id" field.
func (_u *ReportUpdateOne) SetReportedByID(v xid.ID) *ReportUpdateOne {
_u.mutation.SetReportedByID(v)
return _u
}
// SetNillableReportedByID sets the "reported_by_id" field if the given value is not nil.
func (_u *ReportUpdateOne) SetNillableReportedByID(v *xid.ID) *ReportUpdateOne {
if v != nil {
_u.SetReportedByID(*v)
}
return _u
}
// SetHandledByID sets the "handled_by_id" field.
func (_u *ReportUpdateOne) SetHandledByID(v xid.ID) *ReportUpdateOne {
_u.mutation.SetHandledByID(v)
return _u
}
// SetNillableHandledByID sets the "handled_by_id" field if the given value is not nil.
func (_u *ReportUpdateOne) SetNillableHandledByID(v *xid.ID) *ReportUpdateOne {
if v != nil {
_u.SetHandledByID(*v)
}
return _u
}
// ClearHandledByID clears the value of the "handled_by_id" field.
func (_u *ReportUpdateOne) ClearHandledByID() *ReportUpdateOne {
_u.mutation.ClearHandledByID()
return _u
}
// SetComment sets the "comment" field.
func (_u *ReportUpdateOne) SetComment(v string) *ReportUpdateOne {
_u.mutation.SetComment(v)
return _u
}
// SetNillableComment sets the "comment" field if the given value is not nil.
func (_u *ReportUpdateOne) SetNillableComment(v *string) *ReportUpdateOne {
if v != nil {
_u.SetComment(*v)
}
return _u
}
// ClearComment clears the value of the "comment" field.
func (_u *ReportUpdateOne) ClearComment() *ReportUpdateOne {
_u.mutation.ClearComment()
return _u
}
// SetReason sets the "reason" field.
func (_u *ReportUpdateOne) SetReason(v string) *ReportUpdateOne {
_u.mutation.SetReason(v)
return _u
}
// SetNillableReason sets the "reason" field if the given value is not nil.
func (_u *ReportUpdateOne) SetNillableReason(v *string) *ReportUpdateOne {
if v != nil {
_u.SetReason(*v)
}
return _u
}
// ClearReason clears the value of the "reason" field.
func (_u *ReportUpdateOne) ClearReason() *ReportUpdateOne {
_u.mutation.ClearReason()
return _u
}
// SetStatus sets the "status" field.
func (_u *ReportUpdateOne) SetStatus(v string) *ReportUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *ReportUpdateOne) SetNillableStatus(v *string) *ReportUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetReportedBy sets the "reported_by" edge to the Account entity.
func (_u *ReportUpdateOne) SetReportedBy(v *Account) *ReportUpdateOne {
return _u.SetReportedByID(v.ID)
}
// SetHandledBy sets the "handled_by" edge to the Account entity.
func (_u *ReportUpdateOne) SetHandledBy(v *Account) *ReportUpdateOne {
return _u.SetHandledByID(v.ID)
}
// Mutation returns the ReportMutation object of the builder.
func (_u *ReportUpdateOne) Mutation() *ReportMutation {
return _u.mutation
}
// ClearReportedBy clears the "reported_by" edge to the Account entity.
func (_u *ReportUpdateOne) ClearReportedBy() *ReportUpdateOne {
_u.mutation.ClearReportedBy()
return _u
}
// ClearHandledBy clears the "handled_by" edge to the Account entity.
func (_u *ReportUpdateOne) ClearHandledBy() *ReportUpdateOne {
_u.mutation.ClearHandledBy()
return _u
}
// Where appends a list predicates to the ReportUpdate builder.
func (_u *ReportUpdateOne) Where(ps ...predicate.Report) *ReportUpdateOne {
_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 *ReportUpdateOne) Select(field string, fields ...string) *ReportUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Report entity.
func (_u *ReportUpdateOne) Save(ctx context.Context) (*Report, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ReportUpdateOne) SaveX(ctx context.Context) *Report {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ReportUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ReportUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ReportUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := report.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *ReportUpdateOne) check() error {
if _u.mutation.ReportedByCleared() && len(_u.mutation.ReportedByIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "Report.reported_by"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *ReportUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ReportUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *ReportUpdateOne) sqlSave(ctx context.Context) (_node *Report, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(report.Table, report.Columns, sqlgraph.NewFieldSpec(report.FieldID, field.TypeString))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Report.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, report.FieldID)
for _, f := range fields {
if !report.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != report.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.UpdatedAt(); ok {
_spec.SetField(report.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.TargetID(); ok {
_spec.SetField(report.FieldTargetID, field.TypeString, value)
}
if value, ok := _u.mutation.TargetKind(); ok {
_spec.SetField(report.FieldTargetKind, field.TypeString, value)
}
if value, ok := _u.mutation.Comment(); ok {
_spec.SetField(report.FieldComment, field.TypeString, value)
}
if _u.mutation.CommentCleared() {
_spec.ClearField(report.FieldComment, field.TypeString)
}
if value, ok := _u.mutation.Reason(); ok {
_spec.SetField(report.FieldReason, field.TypeString, value)
}
if _u.mutation.ReasonCleared() {
_spec.ClearField(report.FieldReason, field.TypeString)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(report.FieldStatus, field.TypeString, value)
}
if _u.mutation.ReportedByCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: report.ReportedByTable,
Columns: []string{report.ReportedByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.ReportedByIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: report.ReportedByTable,
Columns: []string{report.ReportedByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.HandledByCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: report.HandledByTable,
Columns: []string{report.HandledByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.HandledByIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: report.HandledByTable,
Columns: []string{report.HandledByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
_node = &Report{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{report.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}