versia-go/ent/attachment_update.go

844 lines
24 KiB
Go
Raw Permalink Normal View History

2024-08-11 03:51:22 +02:00
// 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"
2024-08-28 00:25:25 +02:00
"github.com/versia-pub/versia-go/ent/attachment"
"github.com/versia-pub/versia-go/ent/predicate"
"github.com/versia-pub/versia-go/ent/user"
"github.com/versia-pub/versia-go/pkg/versia"
2024-08-11 03:51:22 +02:00
)
// AttachmentUpdate is the builder for updating Attachment entities.
type AttachmentUpdate struct {
config
hooks []Hook
mutation *AttachmentMutation
}
// Where appends a list predicates to the AttachmentUpdate builder.
func (au *AttachmentUpdate) Where(ps ...predicate.Attachment) *AttachmentUpdate {
au.mutation.Where(ps...)
return au
}
// SetIsRemote sets the "isRemote" field.
func (au *AttachmentUpdate) SetIsRemote(b bool) *AttachmentUpdate {
au.mutation.SetIsRemote(b)
return au
}
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
func (au *AttachmentUpdate) SetNillableIsRemote(b *bool) *AttachmentUpdate {
if b != nil {
au.SetIsRemote(*b)
}
return au
}
// SetURI sets the "uri" field.
func (au *AttachmentUpdate) SetURI(s string) *AttachmentUpdate {
au.mutation.SetURI(s)
return au
}
// SetNillableURI sets the "uri" field if the given value is not nil.
func (au *AttachmentUpdate) SetNillableURI(s *string) *AttachmentUpdate {
if s != nil {
au.SetURI(*s)
}
return au
}
// SetExtensions sets the "extensions" field.
2024-08-22 23:03:38 +02:00
func (au *AttachmentUpdate) SetExtensions(v versia.Extensions) *AttachmentUpdate {
au.mutation.SetExtensions(v)
2024-08-11 03:51:22 +02:00
return au
}
// SetUpdatedAt sets the "updated_at" field.
func (au *AttachmentUpdate) SetUpdatedAt(t time.Time) *AttachmentUpdate {
au.mutation.SetUpdatedAt(t)
return au
}
// SetDescription sets the "description" field.
func (au *AttachmentUpdate) SetDescription(s string) *AttachmentUpdate {
au.mutation.SetDescription(s)
return au
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (au *AttachmentUpdate) SetNillableDescription(s *string) *AttachmentUpdate {
if s != nil {
au.SetDescription(*s)
}
return au
}
// SetSha256 sets the "sha256" field.
func (au *AttachmentUpdate) SetSha256(b []byte) *AttachmentUpdate {
au.mutation.SetSha256(b)
return au
}
// SetSize sets the "size" field.
func (au *AttachmentUpdate) SetSize(i int) *AttachmentUpdate {
au.mutation.ResetSize()
au.mutation.SetSize(i)
return au
}
// SetNillableSize sets the "size" field if the given value is not nil.
func (au *AttachmentUpdate) SetNillableSize(i *int) *AttachmentUpdate {
if i != nil {
au.SetSize(*i)
}
return au
}
// AddSize adds i to the "size" field.
func (au *AttachmentUpdate) AddSize(i int) *AttachmentUpdate {
au.mutation.AddSize(i)
return au
}
// SetBlurhash sets the "blurhash" field.
func (au *AttachmentUpdate) SetBlurhash(s string) *AttachmentUpdate {
au.mutation.SetBlurhash(s)
return au
}
// SetNillableBlurhash sets the "blurhash" field if the given value is not nil.
func (au *AttachmentUpdate) SetNillableBlurhash(s *string) *AttachmentUpdate {
if s != nil {
au.SetBlurhash(*s)
}
return au
}
// ClearBlurhash clears the value of the "blurhash" field.
func (au *AttachmentUpdate) ClearBlurhash() *AttachmentUpdate {
au.mutation.ClearBlurhash()
return au
}
// SetHeight sets the "height" field.
func (au *AttachmentUpdate) SetHeight(i int) *AttachmentUpdate {
au.mutation.ResetHeight()
au.mutation.SetHeight(i)
return au
}
// SetNillableHeight sets the "height" field if the given value is not nil.
func (au *AttachmentUpdate) SetNillableHeight(i *int) *AttachmentUpdate {
if i != nil {
au.SetHeight(*i)
}
return au
}
// AddHeight adds i to the "height" field.
func (au *AttachmentUpdate) AddHeight(i int) *AttachmentUpdate {
au.mutation.AddHeight(i)
return au
}
// ClearHeight clears the value of the "height" field.
func (au *AttachmentUpdate) ClearHeight() *AttachmentUpdate {
au.mutation.ClearHeight()
return au
}
// SetWidth sets the "width" field.
func (au *AttachmentUpdate) SetWidth(i int) *AttachmentUpdate {
au.mutation.ResetWidth()
au.mutation.SetWidth(i)
return au
}
// SetNillableWidth sets the "width" field if the given value is not nil.
func (au *AttachmentUpdate) SetNillableWidth(i *int) *AttachmentUpdate {
if i != nil {
au.SetWidth(*i)
}
return au
}
// AddWidth adds i to the "width" field.
func (au *AttachmentUpdate) AddWidth(i int) *AttachmentUpdate {
au.mutation.AddWidth(i)
return au
}
// ClearWidth clears the value of the "width" field.
func (au *AttachmentUpdate) ClearWidth() *AttachmentUpdate {
au.mutation.ClearWidth()
return au
}
// SetFps sets the "fps" field.
func (au *AttachmentUpdate) SetFps(i int) *AttachmentUpdate {
au.mutation.ResetFps()
au.mutation.SetFps(i)
return au
}
// SetNillableFps sets the "fps" field if the given value is not nil.
func (au *AttachmentUpdate) SetNillableFps(i *int) *AttachmentUpdate {
if i != nil {
au.SetFps(*i)
}
return au
}
// AddFps adds i to the "fps" field.
func (au *AttachmentUpdate) AddFps(i int) *AttachmentUpdate {
au.mutation.AddFps(i)
return au
}
// ClearFps clears the value of the "fps" field.
func (au *AttachmentUpdate) ClearFps() *AttachmentUpdate {
au.mutation.ClearFps()
return au
}
// SetMimeType sets the "mimeType" field.
func (au *AttachmentUpdate) SetMimeType(s string) *AttachmentUpdate {
au.mutation.SetMimeType(s)
return au
}
// SetNillableMimeType sets the "mimeType" field if the given value is not nil.
func (au *AttachmentUpdate) SetNillableMimeType(s *string) *AttachmentUpdate {
if s != nil {
au.SetMimeType(*s)
}
return au
}
// SetAuthorID sets the "author" edge to the User entity by ID.
func (au *AttachmentUpdate) SetAuthorID(id uuid.UUID) *AttachmentUpdate {
au.mutation.SetAuthorID(id)
return au
}
// SetAuthor sets the "author" edge to the User entity.
func (au *AttachmentUpdate) SetAuthor(u *User) *AttachmentUpdate {
return au.SetAuthorID(u.ID)
}
// Mutation returns the AttachmentMutation object of the builder.
func (au *AttachmentUpdate) Mutation() *AttachmentMutation {
return au.mutation
}
// ClearAuthor clears the "author" edge to the User entity.
func (au *AttachmentUpdate) ClearAuthor() *AttachmentUpdate {
au.mutation.ClearAuthor()
return au
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (au *AttachmentUpdate) Save(ctx context.Context) (int, error) {
au.defaults()
return withHooks(ctx, au.sqlSave, au.mutation, au.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (au *AttachmentUpdate) SaveX(ctx context.Context) int {
affected, err := au.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (au *AttachmentUpdate) Exec(ctx context.Context) error {
_, err := au.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (au *AttachmentUpdate) ExecX(ctx context.Context) {
if err := au.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (au *AttachmentUpdate) defaults() {
if _, ok := au.mutation.UpdatedAt(); !ok {
v := attachment.UpdateDefaultUpdatedAt()
au.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (au *AttachmentUpdate) check() error {
if v, ok := au.mutation.URI(); ok {
if err := attachment.URIValidator(v); err != nil {
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Attachment.uri": %w`, err)}
}
}
if v, ok := au.mutation.Description(); ok {
if err := attachment.DescriptionValidator(v); err != nil {
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Attachment.description": %w`, err)}
}
}
if _, ok := au.mutation.AuthorID(); au.mutation.AuthorCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "Attachment.author"`)
}
return nil
}
func (au *AttachmentUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := au.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID))
if ps := au.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := au.mutation.IsRemote(); ok {
_spec.SetField(attachment.FieldIsRemote, field.TypeBool, value)
}
if value, ok := au.mutation.URI(); ok {
_spec.SetField(attachment.FieldURI, field.TypeString, value)
}
if value, ok := au.mutation.Extensions(); ok {
_spec.SetField(attachment.FieldExtensions, field.TypeJSON, value)
}
if value, ok := au.mutation.UpdatedAt(); ok {
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := au.mutation.Description(); ok {
_spec.SetField(attachment.FieldDescription, field.TypeString, value)
}
if value, ok := au.mutation.Sha256(); ok {
_spec.SetField(attachment.FieldSha256, field.TypeBytes, value)
}
if value, ok := au.mutation.Size(); ok {
_spec.SetField(attachment.FieldSize, field.TypeInt, value)
}
if value, ok := au.mutation.AddedSize(); ok {
_spec.AddField(attachment.FieldSize, field.TypeInt, value)
}
if value, ok := au.mutation.Blurhash(); ok {
_spec.SetField(attachment.FieldBlurhash, field.TypeString, value)
}
if au.mutation.BlurhashCleared() {
_spec.ClearField(attachment.FieldBlurhash, field.TypeString)
}
if value, ok := au.mutation.Height(); ok {
_spec.SetField(attachment.FieldHeight, field.TypeInt, value)
}
if value, ok := au.mutation.AddedHeight(); ok {
_spec.AddField(attachment.FieldHeight, field.TypeInt, value)
}
if au.mutation.HeightCleared() {
_spec.ClearField(attachment.FieldHeight, field.TypeInt)
}
if value, ok := au.mutation.Width(); ok {
_spec.SetField(attachment.FieldWidth, field.TypeInt, value)
}
if value, ok := au.mutation.AddedWidth(); ok {
_spec.AddField(attachment.FieldWidth, field.TypeInt, value)
}
if au.mutation.WidthCleared() {
_spec.ClearField(attachment.FieldWidth, field.TypeInt)
}
if value, ok := au.mutation.Fps(); ok {
_spec.SetField(attachment.FieldFps, field.TypeInt, value)
}
if value, ok := au.mutation.AddedFps(); ok {
_spec.AddField(attachment.FieldFps, field.TypeInt, value)
}
if au.mutation.FpsCleared() {
_spec.ClearField(attachment.FieldFps, field.TypeInt)
}
if value, ok := au.mutation.MimeType(); ok {
_spec.SetField(attachment.FieldMimeType, field.TypeString, value)
}
if au.mutation.AuthorCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: attachment.AuthorTable,
Columns: []string{attachment.AuthorColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := au.mutation.AuthorIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: attachment.AuthorTable,
Columns: []string{attachment.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 n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{attachment.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
au.mutation.done = true
return n, nil
}
// AttachmentUpdateOne is the builder for updating a single Attachment entity.
type AttachmentUpdateOne struct {
config
fields []string
hooks []Hook
mutation *AttachmentMutation
}
// SetIsRemote sets the "isRemote" field.
func (auo *AttachmentUpdateOne) SetIsRemote(b bool) *AttachmentUpdateOne {
auo.mutation.SetIsRemote(b)
return auo
}
// SetNillableIsRemote sets the "isRemote" field if the given value is not nil.
func (auo *AttachmentUpdateOne) SetNillableIsRemote(b *bool) *AttachmentUpdateOne {
if b != nil {
auo.SetIsRemote(*b)
}
return auo
}
// SetURI sets the "uri" field.
func (auo *AttachmentUpdateOne) SetURI(s string) *AttachmentUpdateOne {
auo.mutation.SetURI(s)
return auo
}
// SetNillableURI sets the "uri" field if the given value is not nil.
func (auo *AttachmentUpdateOne) SetNillableURI(s *string) *AttachmentUpdateOne {
if s != nil {
auo.SetURI(*s)
}
return auo
}
// SetExtensions sets the "extensions" field.
2024-08-22 23:03:38 +02:00
func (auo *AttachmentUpdateOne) SetExtensions(v versia.Extensions) *AttachmentUpdateOne {
auo.mutation.SetExtensions(v)
2024-08-11 03:51:22 +02:00
return auo
}
// SetUpdatedAt sets the "updated_at" field.
func (auo *AttachmentUpdateOne) SetUpdatedAt(t time.Time) *AttachmentUpdateOne {
auo.mutation.SetUpdatedAt(t)
return auo
}
// SetDescription sets the "description" field.
func (auo *AttachmentUpdateOne) SetDescription(s string) *AttachmentUpdateOne {
auo.mutation.SetDescription(s)
return auo
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (auo *AttachmentUpdateOne) SetNillableDescription(s *string) *AttachmentUpdateOne {
if s != nil {
auo.SetDescription(*s)
}
return auo
}
// SetSha256 sets the "sha256" field.
func (auo *AttachmentUpdateOne) SetSha256(b []byte) *AttachmentUpdateOne {
auo.mutation.SetSha256(b)
return auo
}
// SetSize sets the "size" field.
func (auo *AttachmentUpdateOne) SetSize(i int) *AttachmentUpdateOne {
auo.mutation.ResetSize()
auo.mutation.SetSize(i)
return auo
}
// SetNillableSize sets the "size" field if the given value is not nil.
func (auo *AttachmentUpdateOne) SetNillableSize(i *int) *AttachmentUpdateOne {
if i != nil {
auo.SetSize(*i)
}
return auo
}
// AddSize adds i to the "size" field.
func (auo *AttachmentUpdateOne) AddSize(i int) *AttachmentUpdateOne {
auo.mutation.AddSize(i)
return auo
}
// SetBlurhash sets the "blurhash" field.
func (auo *AttachmentUpdateOne) SetBlurhash(s string) *AttachmentUpdateOne {
auo.mutation.SetBlurhash(s)
return auo
}
// SetNillableBlurhash sets the "blurhash" field if the given value is not nil.
func (auo *AttachmentUpdateOne) SetNillableBlurhash(s *string) *AttachmentUpdateOne {
if s != nil {
auo.SetBlurhash(*s)
}
return auo
}
// ClearBlurhash clears the value of the "blurhash" field.
func (auo *AttachmentUpdateOne) ClearBlurhash() *AttachmentUpdateOne {
auo.mutation.ClearBlurhash()
return auo
}
// SetHeight sets the "height" field.
func (auo *AttachmentUpdateOne) SetHeight(i int) *AttachmentUpdateOne {
auo.mutation.ResetHeight()
auo.mutation.SetHeight(i)
return auo
}
// SetNillableHeight sets the "height" field if the given value is not nil.
func (auo *AttachmentUpdateOne) SetNillableHeight(i *int) *AttachmentUpdateOne {
if i != nil {
auo.SetHeight(*i)
}
return auo
}
// AddHeight adds i to the "height" field.
func (auo *AttachmentUpdateOne) AddHeight(i int) *AttachmentUpdateOne {
auo.mutation.AddHeight(i)
return auo
}
// ClearHeight clears the value of the "height" field.
func (auo *AttachmentUpdateOne) ClearHeight() *AttachmentUpdateOne {
auo.mutation.ClearHeight()
return auo
}
// SetWidth sets the "width" field.
func (auo *AttachmentUpdateOne) SetWidth(i int) *AttachmentUpdateOne {
auo.mutation.ResetWidth()
auo.mutation.SetWidth(i)
return auo
}
// SetNillableWidth sets the "width" field if the given value is not nil.
func (auo *AttachmentUpdateOne) SetNillableWidth(i *int) *AttachmentUpdateOne {
if i != nil {
auo.SetWidth(*i)
}
return auo
}
// AddWidth adds i to the "width" field.
func (auo *AttachmentUpdateOne) AddWidth(i int) *AttachmentUpdateOne {
auo.mutation.AddWidth(i)
return auo
}
// ClearWidth clears the value of the "width" field.
func (auo *AttachmentUpdateOne) ClearWidth() *AttachmentUpdateOne {
auo.mutation.ClearWidth()
return auo
}
// SetFps sets the "fps" field.
func (auo *AttachmentUpdateOne) SetFps(i int) *AttachmentUpdateOne {
auo.mutation.ResetFps()
auo.mutation.SetFps(i)
return auo
}
// SetNillableFps sets the "fps" field if the given value is not nil.
func (auo *AttachmentUpdateOne) SetNillableFps(i *int) *AttachmentUpdateOne {
if i != nil {
auo.SetFps(*i)
}
return auo
}
// AddFps adds i to the "fps" field.
func (auo *AttachmentUpdateOne) AddFps(i int) *AttachmentUpdateOne {
auo.mutation.AddFps(i)
return auo
}
// ClearFps clears the value of the "fps" field.
func (auo *AttachmentUpdateOne) ClearFps() *AttachmentUpdateOne {
auo.mutation.ClearFps()
return auo
}
// SetMimeType sets the "mimeType" field.
func (auo *AttachmentUpdateOne) SetMimeType(s string) *AttachmentUpdateOne {
auo.mutation.SetMimeType(s)
return auo
}
// SetNillableMimeType sets the "mimeType" field if the given value is not nil.
func (auo *AttachmentUpdateOne) SetNillableMimeType(s *string) *AttachmentUpdateOne {
if s != nil {
auo.SetMimeType(*s)
}
return auo
}
// SetAuthorID sets the "author" edge to the User entity by ID.
func (auo *AttachmentUpdateOne) SetAuthorID(id uuid.UUID) *AttachmentUpdateOne {
auo.mutation.SetAuthorID(id)
return auo
}
// SetAuthor sets the "author" edge to the User entity.
func (auo *AttachmentUpdateOne) SetAuthor(u *User) *AttachmentUpdateOne {
return auo.SetAuthorID(u.ID)
}
// Mutation returns the AttachmentMutation object of the builder.
func (auo *AttachmentUpdateOne) Mutation() *AttachmentMutation {
return auo.mutation
}
// ClearAuthor clears the "author" edge to the User entity.
func (auo *AttachmentUpdateOne) ClearAuthor() *AttachmentUpdateOne {
auo.mutation.ClearAuthor()
return auo
}
// Where appends a list predicates to the AttachmentUpdate builder.
func (auo *AttachmentUpdateOne) Where(ps ...predicate.Attachment) *AttachmentUpdateOne {
auo.mutation.Where(ps...)
return auo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (auo *AttachmentUpdateOne) Select(field string, fields ...string) *AttachmentUpdateOne {
auo.fields = append([]string{field}, fields...)
return auo
}
// Save executes the query and returns the updated Attachment entity.
func (auo *AttachmentUpdateOne) Save(ctx context.Context) (*Attachment, error) {
auo.defaults()
return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (auo *AttachmentUpdateOne) SaveX(ctx context.Context) *Attachment {
node, err := auo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (auo *AttachmentUpdateOne) Exec(ctx context.Context) error {
_, err := auo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (auo *AttachmentUpdateOne) ExecX(ctx context.Context) {
if err := auo.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (auo *AttachmentUpdateOne) defaults() {
if _, ok := auo.mutation.UpdatedAt(); !ok {
v := attachment.UpdateDefaultUpdatedAt()
auo.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (auo *AttachmentUpdateOne) check() error {
if v, ok := auo.mutation.URI(); ok {
if err := attachment.URIValidator(v); err != nil {
return &ValidationError{Name: "uri", err: fmt.Errorf(`ent: validator failed for field "Attachment.uri": %w`, err)}
}
}
if v, ok := auo.mutation.Description(); ok {
if err := attachment.DescriptionValidator(v); err != nil {
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Attachment.description": %w`, err)}
}
}
if _, ok := auo.mutation.AuthorID(); auo.mutation.AuthorCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "Attachment.author"`)
}
return nil
}
func (auo *AttachmentUpdateOne) sqlSave(ctx context.Context) (_node *Attachment, err error) {
if err := auo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID))
id, ok := auo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Attachment.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := auo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, attachment.FieldID)
for _, f := range fields {
if !attachment.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != attachment.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := auo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := auo.mutation.IsRemote(); ok {
_spec.SetField(attachment.FieldIsRemote, field.TypeBool, value)
}
if value, ok := auo.mutation.URI(); ok {
_spec.SetField(attachment.FieldURI, field.TypeString, value)
}
if value, ok := auo.mutation.Extensions(); ok {
_spec.SetField(attachment.FieldExtensions, field.TypeJSON, value)
}
if value, ok := auo.mutation.UpdatedAt(); ok {
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := auo.mutation.Description(); ok {
_spec.SetField(attachment.FieldDescription, field.TypeString, value)
}
if value, ok := auo.mutation.Sha256(); ok {
_spec.SetField(attachment.FieldSha256, field.TypeBytes, value)
}
if value, ok := auo.mutation.Size(); ok {
_spec.SetField(attachment.FieldSize, field.TypeInt, value)
}
if value, ok := auo.mutation.AddedSize(); ok {
_spec.AddField(attachment.FieldSize, field.TypeInt, value)
}
if value, ok := auo.mutation.Blurhash(); ok {
_spec.SetField(attachment.FieldBlurhash, field.TypeString, value)
}
if auo.mutation.BlurhashCleared() {
_spec.ClearField(attachment.FieldBlurhash, field.TypeString)
}
if value, ok := auo.mutation.Height(); ok {
_spec.SetField(attachment.FieldHeight, field.TypeInt, value)
}
if value, ok := auo.mutation.AddedHeight(); ok {
_spec.AddField(attachment.FieldHeight, field.TypeInt, value)
}
if auo.mutation.HeightCleared() {
_spec.ClearField(attachment.FieldHeight, field.TypeInt)
}
if value, ok := auo.mutation.Width(); ok {
_spec.SetField(attachment.FieldWidth, field.TypeInt, value)
}
if value, ok := auo.mutation.AddedWidth(); ok {
_spec.AddField(attachment.FieldWidth, field.TypeInt, value)
}
if auo.mutation.WidthCleared() {
_spec.ClearField(attachment.FieldWidth, field.TypeInt)
}
if value, ok := auo.mutation.Fps(); ok {
_spec.SetField(attachment.FieldFps, field.TypeInt, value)
}
if value, ok := auo.mutation.AddedFps(); ok {
_spec.AddField(attachment.FieldFps, field.TypeInt, value)
}
if auo.mutation.FpsCleared() {
_spec.ClearField(attachment.FieldFps, field.TypeInt)
}
if value, ok := auo.mutation.MimeType(); ok {
_spec.SetField(attachment.FieldMimeType, field.TypeString, value)
}
if auo.mutation.AuthorCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: attachment.AuthorTable,
Columns: []string{attachment.AuthorColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := auo.mutation.AuthorIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: attachment.AuthorTable,
Columns: []string{attachment.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)
}
_node = &Attachment{config: auo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{attachment.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
auo.mutation.done = true
return _node, nil
}