Files
MonkeyCode/backend/db/projectissuecomment_update.go

900 lines
29 KiB
Go

// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/projectissue"
"github.com/chaitin/MonkeyCode/backend/db/projectissuecomment"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/google/uuid"
)
// ProjectIssueCommentUpdate is the builder for updating ProjectIssueComment entities.
type ProjectIssueCommentUpdate struct {
config
hooks []Hook
mutation *ProjectIssueCommentMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the ProjectIssueCommentUpdate builder.
func (_u *ProjectIssueCommentUpdate) Where(ps ...predicate.ProjectIssueComment) *ProjectIssueCommentUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetDeletedAt sets the "deleted_at" field.
func (_u *ProjectIssueCommentUpdate) SetDeletedAt(v time.Time) *ProjectIssueCommentUpdate {
_u.mutation.SetDeletedAt(v)
return _u
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdate) SetNillableDeletedAt(v *time.Time) *ProjectIssueCommentUpdate {
if v != nil {
_u.SetDeletedAt(*v)
}
return _u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *ProjectIssueCommentUpdate) ClearDeletedAt() *ProjectIssueCommentUpdate {
_u.mutation.ClearDeletedAt()
return _u
}
// SetUserID sets the "user_id" field.
func (_u *ProjectIssueCommentUpdate) SetUserID(v uuid.UUID) *ProjectIssueCommentUpdate {
_u.mutation.SetUserID(v)
return _u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdate) SetNillableUserID(v *uuid.UUID) *ProjectIssueCommentUpdate {
if v != nil {
_u.SetUserID(*v)
}
return _u
}
// SetIssueID sets the "issue_id" field.
func (_u *ProjectIssueCommentUpdate) SetIssueID(v uuid.UUID) *ProjectIssueCommentUpdate {
_u.mutation.SetIssueID(v)
return _u
}
// SetNillableIssueID sets the "issue_id" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdate) SetNillableIssueID(v *uuid.UUID) *ProjectIssueCommentUpdate {
if v != nil {
_u.SetIssueID(*v)
}
return _u
}
// SetParentID sets the "parent_id" field.
func (_u *ProjectIssueCommentUpdate) SetParentID(v uuid.UUID) *ProjectIssueCommentUpdate {
_u.mutation.SetParentID(v)
return _u
}
// SetNillableParentID sets the "parent_id" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdate) SetNillableParentID(v *uuid.UUID) *ProjectIssueCommentUpdate {
if v != nil {
_u.SetParentID(*v)
}
return _u
}
// ClearParentID clears the value of the "parent_id" field.
func (_u *ProjectIssueCommentUpdate) ClearParentID() *ProjectIssueCommentUpdate {
_u.mutation.ClearParentID()
return _u
}
// SetComment sets the "comment" field.
func (_u *ProjectIssueCommentUpdate) SetComment(v string) *ProjectIssueCommentUpdate {
_u.mutation.SetComment(v)
return _u
}
// SetNillableComment sets the "comment" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdate) SetNillableComment(v *string) *ProjectIssueCommentUpdate {
if v != nil {
_u.SetComment(*v)
}
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *ProjectIssueCommentUpdate) SetCreatedAt(v time.Time) *ProjectIssueCommentUpdate {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdate) SetNillableCreatedAt(v *time.Time) *ProjectIssueCommentUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ProjectIssueCommentUpdate) SetUpdatedAt(v time.Time) *ProjectIssueCommentUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetUser sets the "user" edge to the User entity.
func (_u *ProjectIssueCommentUpdate) SetUser(v *User) *ProjectIssueCommentUpdate {
return _u.SetUserID(v.ID)
}
// SetIssue sets the "issue" edge to the ProjectIssue entity.
func (_u *ProjectIssueCommentUpdate) SetIssue(v *ProjectIssue) *ProjectIssueCommentUpdate {
return _u.SetIssueID(v.ID)
}
// SetParent sets the "parent" edge to the ProjectIssueComment entity.
func (_u *ProjectIssueCommentUpdate) SetParent(v *ProjectIssueComment) *ProjectIssueCommentUpdate {
return _u.SetParentID(v.ID)
}
// AddReplyIDs adds the "replies" edge to the ProjectIssueComment entity by IDs.
func (_u *ProjectIssueCommentUpdate) AddReplyIDs(ids ...uuid.UUID) *ProjectIssueCommentUpdate {
_u.mutation.AddReplyIDs(ids...)
return _u
}
// AddReplies adds the "replies" edges to the ProjectIssueComment entity.
func (_u *ProjectIssueCommentUpdate) AddReplies(v ...*ProjectIssueComment) *ProjectIssueCommentUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddReplyIDs(ids...)
}
// Mutation returns the ProjectIssueCommentMutation object of the builder.
func (_u *ProjectIssueCommentUpdate) Mutation() *ProjectIssueCommentMutation {
return _u.mutation
}
// ClearUser clears the "user" edge to the User entity.
func (_u *ProjectIssueCommentUpdate) ClearUser() *ProjectIssueCommentUpdate {
_u.mutation.ClearUser()
return _u
}
// ClearIssue clears the "issue" edge to the ProjectIssue entity.
func (_u *ProjectIssueCommentUpdate) ClearIssue() *ProjectIssueCommentUpdate {
_u.mutation.ClearIssue()
return _u
}
// ClearParent clears the "parent" edge to the ProjectIssueComment entity.
func (_u *ProjectIssueCommentUpdate) ClearParent() *ProjectIssueCommentUpdate {
_u.mutation.ClearParent()
return _u
}
// ClearReplies clears all "replies" edges to the ProjectIssueComment entity.
func (_u *ProjectIssueCommentUpdate) ClearReplies() *ProjectIssueCommentUpdate {
_u.mutation.ClearReplies()
return _u
}
// RemoveReplyIDs removes the "replies" edge to ProjectIssueComment entities by IDs.
func (_u *ProjectIssueCommentUpdate) RemoveReplyIDs(ids ...uuid.UUID) *ProjectIssueCommentUpdate {
_u.mutation.RemoveReplyIDs(ids...)
return _u
}
// RemoveReplies removes "replies" edges to ProjectIssueComment entities.
func (_u *ProjectIssueCommentUpdate) RemoveReplies(v ...*ProjectIssueComment) *ProjectIssueCommentUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveReplyIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ProjectIssueCommentUpdate) Save(ctx context.Context) (int, error) {
if err := _u.defaults(); err != nil {
return 0, err
}
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ProjectIssueCommentUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ProjectIssueCommentUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ProjectIssueCommentUpdate) 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 *ProjectIssueCommentUpdate) defaults() error {
if _, ok := _u.mutation.UpdatedAt(); !ok {
if projectissuecomment.UpdateDefaultUpdatedAt == nil {
return fmt.Errorf("db: uninitialized projectissuecomment.UpdateDefaultUpdatedAt (forgotten import db/runtime?)")
}
v := projectissuecomment.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (_u *ProjectIssueCommentUpdate) check() error {
if v, ok := _u.mutation.Comment(); ok {
if err := projectissuecomment.CommentValidator(v); err != nil {
return &ValidationError{Name: "comment", err: fmt.Errorf(`db: validator failed for field "ProjectIssueComment.comment": %w`, err)}
}
}
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "ProjectIssueComment.user"`)
}
if _u.mutation.IssueCleared() && len(_u.mutation.IssueIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "ProjectIssueComment.issue"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *ProjectIssueCommentUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ProjectIssueCommentUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *ProjectIssueCommentUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(projectissuecomment.Table, projectissuecomment.Columns, sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID))
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.DeletedAt(); ok {
_spec.SetField(projectissuecomment.FieldDeletedAt, field.TypeTime, value)
}
if _u.mutation.DeletedAtCleared() {
_spec.ClearField(projectissuecomment.FieldDeletedAt, field.TypeTime)
}
if value, ok := _u.mutation.Comment(); ok {
_spec.SetField(projectissuecomment.FieldComment, field.TypeString, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(projectissuecomment.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(projectissuecomment.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.UserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.UserTable,
Columns: []string{projectissuecomment.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.UserTable,
Columns: []string{projectissuecomment.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.IssueCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.IssueTable,
Columns: []string{projectissuecomment.IssueColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissue.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.IssueIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.IssueTable,
Columns: []string{projectissuecomment.IssueColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissue.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.ParentCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.ParentTable,
Columns: []string{projectissuecomment.ParentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.ParentTable,
Columns: []string{projectissuecomment.ParentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.RepliesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: projectissuecomment.RepliesTable,
Columns: []string{projectissuecomment.RepliesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedRepliesIDs(); len(nodes) > 0 && !_u.mutation.RepliesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: projectissuecomment.RepliesTable,
Columns: []string{projectissuecomment.RepliesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RepliesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: projectissuecomment.RepliesTable,
Columns: []string{projectissuecomment.RepliesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID),
},
}
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{projectissuecomment.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ProjectIssueCommentUpdateOne is the builder for updating a single ProjectIssueComment entity.
type ProjectIssueCommentUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ProjectIssueCommentMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetDeletedAt sets the "deleted_at" field.
func (_u *ProjectIssueCommentUpdateOne) SetDeletedAt(v time.Time) *ProjectIssueCommentUpdateOne {
_u.mutation.SetDeletedAt(v)
return _u
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdateOne) SetNillableDeletedAt(v *time.Time) *ProjectIssueCommentUpdateOne {
if v != nil {
_u.SetDeletedAt(*v)
}
return _u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *ProjectIssueCommentUpdateOne) ClearDeletedAt() *ProjectIssueCommentUpdateOne {
_u.mutation.ClearDeletedAt()
return _u
}
// SetUserID sets the "user_id" field.
func (_u *ProjectIssueCommentUpdateOne) SetUserID(v uuid.UUID) *ProjectIssueCommentUpdateOne {
_u.mutation.SetUserID(v)
return _u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdateOne) SetNillableUserID(v *uuid.UUID) *ProjectIssueCommentUpdateOne {
if v != nil {
_u.SetUserID(*v)
}
return _u
}
// SetIssueID sets the "issue_id" field.
func (_u *ProjectIssueCommentUpdateOne) SetIssueID(v uuid.UUID) *ProjectIssueCommentUpdateOne {
_u.mutation.SetIssueID(v)
return _u
}
// SetNillableIssueID sets the "issue_id" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdateOne) SetNillableIssueID(v *uuid.UUID) *ProjectIssueCommentUpdateOne {
if v != nil {
_u.SetIssueID(*v)
}
return _u
}
// SetParentID sets the "parent_id" field.
func (_u *ProjectIssueCommentUpdateOne) SetParentID(v uuid.UUID) *ProjectIssueCommentUpdateOne {
_u.mutation.SetParentID(v)
return _u
}
// SetNillableParentID sets the "parent_id" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdateOne) SetNillableParentID(v *uuid.UUID) *ProjectIssueCommentUpdateOne {
if v != nil {
_u.SetParentID(*v)
}
return _u
}
// ClearParentID clears the value of the "parent_id" field.
func (_u *ProjectIssueCommentUpdateOne) ClearParentID() *ProjectIssueCommentUpdateOne {
_u.mutation.ClearParentID()
return _u
}
// SetComment sets the "comment" field.
func (_u *ProjectIssueCommentUpdateOne) SetComment(v string) *ProjectIssueCommentUpdateOne {
_u.mutation.SetComment(v)
return _u
}
// SetNillableComment sets the "comment" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdateOne) SetNillableComment(v *string) *ProjectIssueCommentUpdateOne {
if v != nil {
_u.SetComment(*v)
}
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *ProjectIssueCommentUpdateOne) SetCreatedAt(v time.Time) *ProjectIssueCommentUpdateOne {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *ProjectIssueCommentUpdateOne) SetNillableCreatedAt(v *time.Time) *ProjectIssueCommentUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ProjectIssueCommentUpdateOne) SetUpdatedAt(v time.Time) *ProjectIssueCommentUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetUser sets the "user" edge to the User entity.
func (_u *ProjectIssueCommentUpdateOne) SetUser(v *User) *ProjectIssueCommentUpdateOne {
return _u.SetUserID(v.ID)
}
// SetIssue sets the "issue" edge to the ProjectIssue entity.
func (_u *ProjectIssueCommentUpdateOne) SetIssue(v *ProjectIssue) *ProjectIssueCommentUpdateOne {
return _u.SetIssueID(v.ID)
}
// SetParent sets the "parent" edge to the ProjectIssueComment entity.
func (_u *ProjectIssueCommentUpdateOne) SetParent(v *ProjectIssueComment) *ProjectIssueCommentUpdateOne {
return _u.SetParentID(v.ID)
}
// AddReplyIDs adds the "replies" edge to the ProjectIssueComment entity by IDs.
func (_u *ProjectIssueCommentUpdateOne) AddReplyIDs(ids ...uuid.UUID) *ProjectIssueCommentUpdateOne {
_u.mutation.AddReplyIDs(ids...)
return _u
}
// AddReplies adds the "replies" edges to the ProjectIssueComment entity.
func (_u *ProjectIssueCommentUpdateOne) AddReplies(v ...*ProjectIssueComment) *ProjectIssueCommentUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddReplyIDs(ids...)
}
// Mutation returns the ProjectIssueCommentMutation object of the builder.
func (_u *ProjectIssueCommentUpdateOne) Mutation() *ProjectIssueCommentMutation {
return _u.mutation
}
// ClearUser clears the "user" edge to the User entity.
func (_u *ProjectIssueCommentUpdateOne) ClearUser() *ProjectIssueCommentUpdateOne {
_u.mutation.ClearUser()
return _u
}
// ClearIssue clears the "issue" edge to the ProjectIssue entity.
func (_u *ProjectIssueCommentUpdateOne) ClearIssue() *ProjectIssueCommentUpdateOne {
_u.mutation.ClearIssue()
return _u
}
// ClearParent clears the "parent" edge to the ProjectIssueComment entity.
func (_u *ProjectIssueCommentUpdateOne) ClearParent() *ProjectIssueCommentUpdateOne {
_u.mutation.ClearParent()
return _u
}
// ClearReplies clears all "replies" edges to the ProjectIssueComment entity.
func (_u *ProjectIssueCommentUpdateOne) ClearReplies() *ProjectIssueCommentUpdateOne {
_u.mutation.ClearReplies()
return _u
}
// RemoveReplyIDs removes the "replies" edge to ProjectIssueComment entities by IDs.
func (_u *ProjectIssueCommentUpdateOne) RemoveReplyIDs(ids ...uuid.UUID) *ProjectIssueCommentUpdateOne {
_u.mutation.RemoveReplyIDs(ids...)
return _u
}
// RemoveReplies removes "replies" edges to ProjectIssueComment entities.
func (_u *ProjectIssueCommentUpdateOne) RemoveReplies(v ...*ProjectIssueComment) *ProjectIssueCommentUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveReplyIDs(ids...)
}
// Where appends a list predicates to the ProjectIssueCommentUpdate builder.
func (_u *ProjectIssueCommentUpdateOne) Where(ps ...predicate.ProjectIssueComment) *ProjectIssueCommentUpdateOne {
_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 *ProjectIssueCommentUpdateOne) Select(field string, fields ...string) *ProjectIssueCommentUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated ProjectIssueComment entity.
func (_u *ProjectIssueCommentUpdateOne) Save(ctx context.Context) (*ProjectIssueComment, error) {
if err := _u.defaults(); err != nil {
return nil, err
}
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ProjectIssueCommentUpdateOne) SaveX(ctx context.Context) *ProjectIssueComment {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ProjectIssueCommentUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ProjectIssueCommentUpdateOne) 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 *ProjectIssueCommentUpdateOne) defaults() error {
if _, ok := _u.mutation.UpdatedAt(); !ok {
if projectissuecomment.UpdateDefaultUpdatedAt == nil {
return fmt.Errorf("db: uninitialized projectissuecomment.UpdateDefaultUpdatedAt (forgotten import db/runtime?)")
}
v := projectissuecomment.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (_u *ProjectIssueCommentUpdateOne) check() error {
if v, ok := _u.mutation.Comment(); ok {
if err := projectissuecomment.CommentValidator(v); err != nil {
return &ValidationError{Name: "comment", err: fmt.Errorf(`db: validator failed for field "ProjectIssueComment.comment": %w`, err)}
}
}
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "ProjectIssueComment.user"`)
}
if _u.mutation.IssueCleared() && len(_u.mutation.IssueIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "ProjectIssueComment.issue"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *ProjectIssueCommentUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ProjectIssueCommentUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *ProjectIssueCommentUpdateOne) sqlSave(ctx context.Context) (_node *ProjectIssueComment, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(projectissuecomment.Table, projectissuecomment.Columns, sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "ProjectIssueComment.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, projectissuecomment.FieldID)
for _, f := range fields {
if !projectissuecomment.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != projectissuecomment.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.DeletedAt(); ok {
_spec.SetField(projectissuecomment.FieldDeletedAt, field.TypeTime, value)
}
if _u.mutation.DeletedAtCleared() {
_spec.ClearField(projectissuecomment.FieldDeletedAt, field.TypeTime)
}
if value, ok := _u.mutation.Comment(); ok {
_spec.SetField(projectissuecomment.FieldComment, field.TypeString, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(projectissuecomment.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(projectissuecomment.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.UserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.UserTable,
Columns: []string{projectissuecomment.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.UserTable,
Columns: []string{projectissuecomment.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.IssueCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.IssueTable,
Columns: []string{projectissuecomment.IssueColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissue.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.IssueIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.IssueTable,
Columns: []string{projectissuecomment.IssueColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissue.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.ParentCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.ParentTable,
Columns: []string{projectissuecomment.ParentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: projectissuecomment.ParentTable,
Columns: []string{projectissuecomment.ParentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.RepliesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: projectissuecomment.RepliesTable,
Columns: []string{projectissuecomment.RepliesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedRepliesIDs(); len(nodes) > 0 && !_u.mutation.RepliesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: projectissuecomment.RepliesTable,
Columns: []string{projectissuecomment.RepliesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RepliesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: projectissuecomment.RepliesTable,
Columns: []string{projectissuecomment.RepliesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(projectissuecomment.FieldID, field.TypeUUID),
},
}
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 = &ProjectIssueComment{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{projectissuecomment.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}