mirror of
https://github.com/versia-pub/versia-go.git
synced 2025-12-06 14:28:20 +01:00
925 lines
26 KiB
Go
925 lines
26 KiB
Go
// 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/google/uuid"
|
|
"github.com/lysand-org/versia-go/ent/attachment"
|
|
"github.com/lysand-org/versia-go/ent/note"
|
|
"github.com/lysand-org/versia-go/ent/predicate"
|
|
"github.com/lysand-org/versia-go/ent/user"
|
|
"github.com/lysand-org/versia-go/pkg/versia"
|
|
)
|
|
|
|
// NoteUpdate is the builder for updating Note entities.
|
|
type NoteUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *NoteMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the NoteUpdate builder.
|
|
func (nu *NoteUpdate) Where(ps ...predicate.Note) *NoteUpdate {
|
|
nu.mutation.Where(ps...)
|
|
return nu
|
|
}
|
|
|
|
// SetIsRemote sets the "isRemote" field.
|
|
func (nu *NoteUpdate) SetIsRemote(b bool) *NoteUpdate {
|
|
nu.mutation.SetIsRemote(b)
|
|
return nu
|
|
}
|
|
|
|
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
|
|
func (nu *NoteUpdate) SetNillableIsRemote(b *bool) *NoteUpdate {
|
|
if b != nil {
|
|
nu.SetIsRemote(*b)
|
|
}
|
|
return nu
|
|
}
|
|
|
|
// SetURI sets the "uri" field.
|
|
func (nu *NoteUpdate) SetURI(s string) *NoteUpdate {
|
|
nu.mutation.SetURI(s)
|
|
return nu
|
|
}
|
|
|
|
// SetNillableURI sets the "uri" field if the given value is not nil.
|
|
func (nu *NoteUpdate) SetNillableURI(s *string) *NoteUpdate {
|
|
if s != nil {
|
|
nu.SetURI(*s)
|
|
}
|
|
return nu
|
|
}
|
|
|
|
// SetExtensions sets the "extensions" field.
|
|
func (nu *NoteUpdate) SetExtensions(v versia.Extensions) *NoteUpdate {
|
|
nu.mutation.SetExtensions(v)
|
|
return nu
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (nu *NoteUpdate) SetUpdatedAt(t time.Time) *NoteUpdate {
|
|
nu.mutation.SetUpdatedAt(t)
|
|
return nu
|
|
}
|
|
|
|
// SetSubject sets the "subject" field.
|
|
func (nu *NoteUpdate) SetSubject(s string) *NoteUpdate {
|
|
nu.mutation.SetSubject(s)
|
|
return nu
|
|
}
|
|
|
|
// SetNillableSubject sets the "subject" field if the given value is not nil.
|
|
func (nu *NoteUpdate) SetNillableSubject(s *string) *NoteUpdate {
|
|
if s != nil {
|
|
nu.SetSubject(*s)
|
|
}
|
|
return nu
|
|
}
|
|
|
|
// ClearSubject clears the value of the "subject" field.
|
|
func (nu *NoteUpdate) ClearSubject() *NoteUpdate {
|
|
nu.mutation.ClearSubject()
|
|
return nu
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (nu *NoteUpdate) SetContent(s string) *NoteUpdate {
|
|
nu.mutation.SetContent(s)
|
|
return nu
|
|
}
|
|
|
|
// SetNillableContent sets the "content" field if the given value is not nil.
|
|
func (nu *NoteUpdate) SetNillableContent(s *string) *NoteUpdate {
|
|
if s != nil {
|
|
nu.SetContent(*s)
|
|
}
|
|
return nu
|
|
}
|
|
|
|
// SetIsSensitive sets the "isSensitive" field.
|
|
func (nu *NoteUpdate) SetIsSensitive(b bool) *NoteUpdate {
|
|
nu.mutation.SetIsSensitive(b)
|
|
return nu
|
|
}
|
|
|
|
// SetNillableIsSensitive sets the "isSensitive" field if the given value is not nil.
|
|
func (nu *NoteUpdate) SetNillableIsSensitive(b *bool) *NoteUpdate {
|
|
if b != nil {
|
|
nu.SetIsSensitive(*b)
|
|
}
|
|
return nu
|
|
}
|
|
|
|
// SetVisibility sets the "visibility" field.
|
|
func (nu *NoteUpdate) SetVisibility(n note.Visibility) *NoteUpdate {
|
|
nu.mutation.SetVisibility(n)
|
|
return nu
|
|
}
|
|
|
|
// SetNillableVisibility sets the "visibility" field if the given value is not nil.
|
|
func (nu *NoteUpdate) SetNillableVisibility(n *note.Visibility) *NoteUpdate {
|
|
if n != nil {
|
|
nu.SetVisibility(*n)
|
|
}
|
|
return nu
|
|
}
|
|
|
|
// SetAuthorID sets the "author" edge to the User entity by ID.
|
|
func (nu *NoteUpdate) SetAuthorID(id uuid.UUID) *NoteUpdate {
|
|
nu.mutation.SetAuthorID(id)
|
|
return nu
|
|
}
|
|
|
|
// SetAuthor sets the "author" edge to the User entity.
|
|
func (nu *NoteUpdate) SetAuthor(u *User) *NoteUpdate {
|
|
return nu.SetAuthorID(u.ID)
|
|
}
|
|
|
|
// AddMentionIDs adds the "mentions" edge to the User entity by IDs.
|
|
func (nu *NoteUpdate) AddMentionIDs(ids ...uuid.UUID) *NoteUpdate {
|
|
nu.mutation.AddMentionIDs(ids...)
|
|
return nu
|
|
}
|
|
|
|
// AddMentions adds the "mentions" edges to the User entity.
|
|
func (nu *NoteUpdate) AddMentions(u ...*User) *NoteUpdate {
|
|
ids := make([]uuid.UUID, len(u))
|
|
for i := range u {
|
|
ids[i] = u[i].ID
|
|
}
|
|
return nu.AddMentionIDs(ids...)
|
|
}
|
|
|
|
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
|
func (nu *NoteUpdate) AddAttachmentIDs(ids ...uuid.UUID) *NoteUpdate {
|
|
nu.mutation.AddAttachmentIDs(ids...)
|
|
return nu
|
|
}
|
|
|
|
// AddAttachments adds the "attachments" edges to the Attachment entity.
|
|
func (nu *NoteUpdate) AddAttachments(a ...*Attachment) *NoteUpdate {
|
|
ids := make([]uuid.UUID, len(a))
|
|
for i := range a {
|
|
ids[i] = a[i].ID
|
|
}
|
|
return nu.AddAttachmentIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the NoteMutation object of the builder.
|
|
func (nu *NoteUpdate) Mutation() *NoteMutation {
|
|
return nu.mutation
|
|
}
|
|
|
|
// ClearAuthor clears the "author" edge to the User entity.
|
|
func (nu *NoteUpdate) ClearAuthor() *NoteUpdate {
|
|
nu.mutation.ClearAuthor()
|
|
return nu
|
|
}
|
|
|
|
// ClearMentions clears all "mentions" edges to the User entity.
|
|
func (nu *NoteUpdate) ClearMentions() *NoteUpdate {
|
|
nu.mutation.ClearMentions()
|
|
return nu
|
|
}
|
|
|
|
// RemoveMentionIDs removes the "mentions" edge to User entities by IDs.
|
|
func (nu *NoteUpdate) RemoveMentionIDs(ids ...uuid.UUID) *NoteUpdate {
|
|
nu.mutation.RemoveMentionIDs(ids...)
|
|
return nu
|
|
}
|
|
|
|
// RemoveMentions removes "mentions" edges to User entities.
|
|
func (nu *NoteUpdate) RemoveMentions(u ...*User) *NoteUpdate {
|
|
ids := make([]uuid.UUID, len(u))
|
|
for i := range u {
|
|
ids[i] = u[i].ID
|
|
}
|
|
return nu.RemoveMentionIDs(ids...)
|
|
}
|
|
|
|
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
|
func (nu *NoteUpdate) ClearAttachments() *NoteUpdate {
|
|
nu.mutation.ClearAttachments()
|
|
return nu
|
|
}
|
|
|
|
// RemoveAttachmentIDs removes the "attachments" edge to Attachment entities by IDs.
|
|
func (nu *NoteUpdate) RemoveAttachmentIDs(ids ...uuid.UUID) *NoteUpdate {
|
|
nu.mutation.RemoveAttachmentIDs(ids...)
|
|
return nu
|
|
}
|
|
|
|
// RemoveAttachments removes "attachments" edges to Attachment entities.
|
|
func (nu *NoteUpdate) RemoveAttachments(a ...*Attachment) *NoteUpdate {
|
|
ids := make([]uuid.UUID, len(a))
|
|
for i := range a {
|
|
ids[i] = a[i].ID
|
|
}
|
|
return nu.RemoveAttachmentIDs(ids...)
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (nu *NoteUpdate) Save(ctx context.Context) (int, error) {
|
|
nu.defaults()
|
|
return withHooks(ctx, nu.sqlSave, nu.mutation, nu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (nu *NoteUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := nu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (nu *NoteUpdate) Exec(ctx context.Context) error {
|
|
_, err := nu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (nu *NoteUpdate) ExecX(ctx context.Context) {
|
|
if err := nu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (nu *NoteUpdate) defaults() {
|
|
if _, ok := nu.mutation.UpdatedAt(); !ok {
|
|
v := note.UpdateDefaultUpdatedAt()
|
|
nu.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (nu *NoteUpdate) check() error {
|
|
if v, ok := nu.mutation.URI(); ok {
|
|
if err := note.URIValidator(v); err != nil {
|
|
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Note.uri": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := nu.mutation.Subject(); ok {
|
|
if err := note.SubjectValidator(v); err != nil {
|
|
return &ValidationError{Name: "subject", err: fmt.Errorf(`ent: validator failed for field "Note.subject": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := nu.mutation.Visibility(); ok {
|
|
if err := note.VisibilityValidator(v); err != nil {
|
|
return &ValidationError{Name: "visibility", err: fmt.Errorf(`ent: validator failed for field "Note.visibility": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := nu.mutation.AuthorID(); nu.mutation.AuthorCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "Note.author"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (nu *NoteUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
if err := nu.check(); err != nil {
|
|
return n, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(note.Table, note.Columns, sqlgraph.NewFieldSpec(note.FieldID, field.TypeUUID))
|
|
if ps := nu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := nu.mutation.IsRemote(); ok {
|
|
_spec.SetField(note.FieldIsRemote, field.TypeBool, value)
|
|
}
|
|
if value, ok := nu.mutation.URI(); ok {
|
|
_spec.SetField(note.FieldURI, field.TypeString, value)
|
|
}
|
|
if value, ok := nu.mutation.Extensions(); ok {
|
|
_spec.SetField(note.FieldExtensions, field.TypeJSON, value)
|
|
}
|
|
if value, ok := nu.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(note.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := nu.mutation.Subject(); ok {
|
|
_spec.SetField(note.FieldSubject, field.TypeString, value)
|
|
}
|
|
if nu.mutation.SubjectCleared() {
|
|
_spec.ClearField(note.FieldSubject, field.TypeString)
|
|
}
|
|
if value, ok := nu.mutation.Content(); ok {
|
|
_spec.SetField(note.FieldContent, field.TypeString, value)
|
|
}
|
|
if value, ok := nu.mutation.IsSensitive(); ok {
|
|
_spec.SetField(note.FieldIsSensitive, field.TypeBool, value)
|
|
}
|
|
if value, ok := nu.mutation.Visibility(); ok {
|
|
_spec.SetField(note.FieldVisibility, field.TypeEnum, value)
|
|
}
|
|
if nu.mutation.AuthorCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: note.AuthorTable,
|
|
Columns: []string{note.AuthorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := nu.mutation.AuthorIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: note.AuthorTable,
|
|
Columns: []string{note.AuthorColumn},
|
|
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 nu.mutation.MentionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: note.MentionsTable,
|
|
Columns: note.MentionsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := nu.mutation.RemovedMentionsIDs(); len(nodes) > 0 && !nu.mutation.MentionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: note.MentionsTable,
|
|
Columns: note.MentionsPrimaryKey,
|
|
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.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := nu.mutation.MentionsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: note.MentionsTable,
|
|
Columns: note.MentionsPrimaryKey,
|
|
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 nu.mutation.AttachmentsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.AttachmentsTable,
|
|
Columns: []string{note.AttachmentsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := nu.mutation.RemovedAttachmentsIDs(); len(nodes) > 0 && !nu.mutation.AttachmentsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.AttachmentsTable,
|
|
Columns: []string{note.AttachmentsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(attachment.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 := nu.mutation.AttachmentsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.AttachmentsTable,
|
|
Columns: []string{note.AttachmentsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
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, nu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{note.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
nu.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// NoteUpdateOne is the builder for updating a single Note entity.
|
|
type NoteUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *NoteMutation
|
|
}
|
|
|
|
// SetIsRemote sets the "isRemote" field.
|
|
func (nuo *NoteUpdateOne) SetIsRemote(b bool) *NoteUpdateOne {
|
|
nuo.mutation.SetIsRemote(b)
|
|
return nuo
|
|
}
|
|
|
|
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
|
|
func (nuo *NoteUpdateOne) SetNillableIsRemote(b *bool) *NoteUpdateOne {
|
|
if b != nil {
|
|
nuo.SetIsRemote(*b)
|
|
}
|
|
return nuo
|
|
}
|
|
|
|
// SetURI sets the "uri" field.
|
|
func (nuo *NoteUpdateOne) SetURI(s string) *NoteUpdateOne {
|
|
nuo.mutation.SetURI(s)
|
|
return nuo
|
|
}
|
|
|
|
// SetNillableURI sets the "uri" field if the given value is not nil.
|
|
func (nuo *NoteUpdateOne) SetNillableURI(s *string) *NoteUpdateOne {
|
|
if s != nil {
|
|
nuo.SetURI(*s)
|
|
}
|
|
return nuo
|
|
}
|
|
|
|
// SetExtensions sets the "extensions" field.
|
|
func (nuo *NoteUpdateOne) SetExtensions(v versia.Extensions) *NoteUpdateOne {
|
|
nuo.mutation.SetExtensions(v)
|
|
return nuo
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (nuo *NoteUpdateOne) SetUpdatedAt(t time.Time) *NoteUpdateOne {
|
|
nuo.mutation.SetUpdatedAt(t)
|
|
return nuo
|
|
}
|
|
|
|
// SetSubject sets the "subject" field.
|
|
func (nuo *NoteUpdateOne) SetSubject(s string) *NoteUpdateOne {
|
|
nuo.mutation.SetSubject(s)
|
|
return nuo
|
|
}
|
|
|
|
// SetNillableSubject sets the "subject" field if the given value is not nil.
|
|
func (nuo *NoteUpdateOne) SetNillableSubject(s *string) *NoteUpdateOne {
|
|
if s != nil {
|
|
nuo.SetSubject(*s)
|
|
}
|
|
return nuo
|
|
}
|
|
|
|
// ClearSubject clears the value of the "subject" field.
|
|
func (nuo *NoteUpdateOne) ClearSubject() *NoteUpdateOne {
|
|
nuo.mutation.ClearSubject()
|
|
return nuo
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (nuo *NoteUpdateOne) SetContent(s string) *NoteUpdateOne {
|
|
nuo.mutation.SetContent(s)
|
|
return nuo
|
|
}
|
|
|
|
// SetNillableContent sets the "content" field if the given value is not nil.
|
|
func (nuo *NoteUpdateOne) SetNillableContent(s *string) *NoteUpdateOne {
|
|
if s != nil {
|
|
nuo.SetContent(*s)
|
|
}
|
|
return nuo
|
|
}
|
|
|
|
// SetIsSensitive sets the "isSensitive" field.
|
|
func (nuo *NoteUpdateOne) SetIsSensitive(b bool) *NoteUpdateOne {
|
|
nuo.mutation.SetIsSensitive(b)
|
|
return nuo
|
|
}
|
|
|
|
// SetNillableIsSensitive sets the "isSensitive" field if the given value is not nil.
|
|
func (nuo *NoteUpdateOne) SetNillableIsSensitive(b *bool) *NoteUpdateOne {
|
|
if b != nil {
|
|
nuo.SetIsSensitive(*b)
|
|
}
|
|
return nuo
|
|
}
|
|
|
|
// SetVisibility sets the "visibility" field.
|
|
func (nuo *NoteUpdateOne) SetVisibility(n note.Visibility) *NoteUpdateOne {
|
|
nuo.mutation.SetVisibility(n)
|
|
return nuo
|
|
}
|
|
|
|
// SetNillableVisibility sets the "visibility" field if the given value is not nil.
|
|
func (nuo *NoteUpdateOne) SetNillableVisibility(n *note.Visibility) *NoteUpdateOne {
|
|
if n != nil {
|
|
nuo.SetVisibility(*n)
|
|
}
|
|
return nuo
|
|
}
|
|
|
|
// SetAuthorID sets the "author" edge to the User entity by ID.
|
|
func (nuo *NoteUpdateOne) SetAuthorID(id uuid.UUID) *NoteUpdateOne {
|
|
nuo.mutation.SetAuthorID(id)
|
|
return nuo
|
|
}
|
|
|
|
// SetAuthor sets the "author" edge to the User entity.
|
|
func (nuo *NoteUpdateOne) SetAuthor(u *User) *NoteUpdateOne {
|
|
return nuo.SetAuthorID(u.ID)
|
|
}
|
|
|
|
// AddMentionIDs adds the "mentions" edge to the User entity by IDs.
|
|
func (nuo *NoteUpdateOne) AddMentionIDs(ids ...uuid.UUID) *NoteUpdateOne {
|
|
nuo.mutation.AddMentionIDs(ids...)
|
|
return nuo
|
|
}
|
|
|
|
// AddMentions adds the "mentions" edges to the User entity.
|
|
func (nuo *NoteUpdateOne) AddMentions(u ...*User) *NoteUpdateOne {
|
|
ids := make([]uuid.UUID, len(u))
|
|
for i := range u {
|
|
ids[i] = u[i].ID
|
|
}
|
|
return nuo.AddMentionIDs(ids...)
|
|
}
|
|
|
|
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
|
func (nuo *NoteUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *NoteUpdateOne {
|
|
nuo.mutation.AddAttachmentIDs(ids...)
|
|
return nuo
|
|
}
|
|
|
|
// AddAttachments adds the "attachments" edges to the Attachment entity.
|
|
func (nuo *NoteUpdateOne) AddAttachments(a ...*Attachment) *NoteUpdateOne {
|
|
ids := make([]uuid.UUID, len(a))
|
|
for i := range a {
|
|
ids[i] = a[i].ID
|
|
}
|
|
return nuo.AddAttachmentIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the NoteMutation object of the builder.
|
|
func (nuo *NoteUpdateOne) Mutation() *NoteMutation {
|
|
return nuo.mutation
|
|
}
|
|
|
|
// ClearAuthor clears the "author" edge to the User entity.
|
|
func (nuo *NoteUpdateOne) ClearAuthor() *NoteUpdateOne {
|
|
nuo.mutation.ClearAuthor()
|
|
return nuo
|
|
}
|
|
|
|
// ClearMentions clears all "mentions" edges to the User entity.
|
|
func (nuo *NoteUpdateOne) ClearMentions() *NoteUpdateOne {
|
|
nuo.mutation.ClearMentions()
|
|
return nuo
|
|
}
|
|
|
|
// RemoveMentionIDs removes the "mentions" edge to User entities by IDs.
|
|
func (nuo *NoteUpdateOne) RemoveMentionIDs(ids ...uuid.UUID) *NoteUpdateOne {
|
|
nuo.mutation.RemoveMentionIDs(ids...)
|
|
return nuo
|
|
}
|
|
|
|
// RemoveMentions removes "mentions" edges to User entities.
|
|
func (nuo *NoteUpdateOne) RemoveMentions(u ...*User) *NoteUpdateOne {
|
|
ids := make([]uuid.UUID, len(u))
|
|
for i := range u {
|
|
ids[i] = u[i].ID
|
|
}
|
|
return nuo.RemoveMentionIDs(ids...)
|
|
}
|
|
|
|
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
|
func (nuo *NoteUpdateOne) ClearAttachments() *NoteUpdateOne {
|
|
nuo.mutation.ClearAttachments()
|
|
return nuo
|
|
}
|
|
|
|
// RemoveAttachmentIDs removes the "attachments" edge to Attachment entities by IDs.
|
|
func (nuo *NoteUpdateOne) RemoveAttachmentIDs(ids ...uuid.UUID) *NoteUpdateOne {
|
|
nuo.mutation.RemoveAttachmentIDs(ids...)
|
|
return nuo
|
|
}
|
|
|
|
// RemoveAttachments removes "attachments" edges to Attachment entities.
|
|
func (nuo *NoteUpdateOne) RemoveAttachments(a ...*Attachment) *NoteUpdateOne {
|
|
ids := make([]uuid.UUID, len(a))
|
|
for i := range a {
|
|
ids[i] = a[i].ID
|
|
}
|
|
return nuo.RemoveAttachmentIDs(ids...)
|
|
}
|
|
|
|
// Where appends a list predicates to the NoteUpdate builder.
|
|
func (nuo *NoteUpdateOne) Where(ps ...predicate.Note) *NoteUpdateOne {
|
|
nuo.mutation.Where(ps...)
|
|
return nuo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (nuo *NoteUpdateOne) Select(field string, fields ...string) *NoteUpdateOne {
|
|
nuo.fields = append([]string{field}, fields...)
|
|
return nuo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Note entity.
|
|
func (nuo *NoteUpdateOne) Save(ctx context.Context) (*Note, error) {
|
|
nuo.defaults()
|
|
return withHooks(ctx, nuo.sqlSave, nuo.mutation, nuo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (nuo *NoteUpdateOne) SaveX(ctx context.Context) *Note {
|
|
node, err := nuo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (nuo *NoteUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := nuo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (nuo *NoteUpdateOne) ExecX(ctx context.Context) {
|
|
if err := nuo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (nuo *NoteUpdateOne) defaults() {
|
|
if _, ok := nuo.mutation.UpdatedAt(); !ok {
|
|
v := note.UpdateDefaultUpdatedAt()
|
|
nuo.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (nuo *NoteUpdateOne) check() error {
|
|
if v, ok := nuo.mutation.URI(); ok {
|
|
if err := note.URIValidator(v); err != nil {
|
|
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Note.uri": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := nuo.mutation.Subject(); ok {
|
|
if err := note.SubjectValidator(v); err != nil {
|
|
return &ValidationError{Name: "subject", err: fmt.Errorf(`ent: validator failed for field "Note.subject": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := nuo.mutation.Visibility(); ok {
|
|
if err := note.VisibilityValidator(v); err != nil {
|
|
return &ValidationError{Name: "visibility", err: fmt.Errorf(`ent: validator failed for field "Note.visibility": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := nuo.mutation.AuthorID(); nuo.mutation.AuthorCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "Note.author"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (nuo *NoteUpdateOne) sqlSave(ctx context.Context) (_node *Note, err error) {
|
|
if err := nuo.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(note.Table, note.Columns, sqlgraph.NewFieldSpec(note.FieldID, field.TypeUUID))
|
|
id, ok := nuo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Note.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := nuo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, note.FieldID)
|
|
for _, f := range fields {
|
|
if !note.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != note.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := nuo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := nuo.mutation.IsRemote(); ok {
|
|
_spec.SetField(note.FieldIsRemote, field.TypeBool, value)
|
|
}
|
|
if value, ok := nuo.mutation.URI(); ok {
|
|
_spec.SetField(note.FieldURI, field.TypeString, value)
|
|
}
|
|
if value, ok := nuo.mutation.Extensions(); ok {
|
|
_spec.SetField(note.FieldExtensions, field.TypeJSON, value)
|
|
}
|
|
if value, ok := nuo.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(note.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := nuo.mutation.Subject(); ok {
|
|
_spec.SetField(note.FieldSubject, field.TypeString, value)
|
|
}
|
|
if nuo.mutation.SubjectCleared() {
|
|
_spec.ClearField(note.FieldSubject, field.TypeString)
|
|
}
|
|
if value, ok := nuo.mutation.Content(); ok {
|
|
_spec.SetField(note.FieldContent, field.TypeString, value)
|
|
}
|
|
if value, ok := nuo.mutation.IsSensitive(); ok {
|
|
_spec.SetField(note.FieldIsSensitive, field.TypeBool, value)
|
|
}
|
|
if value, ok := nuo.mutation.Visibility(); ok {
|
|
_spec.SetField(note.FieldVisibility, field.TypeEnum, value)
|
|
}
|
|
if nuo.mutation.AuthorCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: note.AuthorTable,
|
|
Columns: []string{note.AuthorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := nuo.mutation.AuthorIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: note.AuthorTable,
|
|
Columns: []string{note.AuthorColumn},
|
|
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 nuo.mutation.MentionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: note.MentionsTable,
|
|
Columns: note.MentionsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := nuo.mutation.RemovedMentionsIDs(); len(nodes) > 0 && !nuo.mutation.MentionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: note.MentionsTable,
|
|
Columns: note.MentionsPrimaryKey,
|
|
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.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := nuo.mutation.MentionsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: note.MentionsTable,
|
|
Columns: note.MentionsPrimaryKey,
|
|
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 nuo.mutation.AttachmentsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.AttachmentsTable,
|
|
Columns: []string{note.AttachmentsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := nuo.mutation.RemovedAttachmentsIDs(); len(nodes) > 0 && !nuo.mutation.AttachmentsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.AttachmentsTable,
|
|
Columns: []string{note.AttachmentsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(attachment.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 := nuo.mutation.AttachmentsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.AttachmentsTable,
|
|
Columns: []string{note.AttachmentsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &Note{config: nuo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, nuo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{note.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
nuo.mutation.done = true
|
|
return _node, nil
|
|
}
|