12
This commit is contained in:
761
internal/ent/cloudflarer2_update.go
Normal file
761
internal/ent/cloudflarer2_update.go
Normal file
@ -0,0 +1,761 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
"unR2/internal/ent/cloudflareaccounts"
|
||||
"unR2/internal/ent/cloudflarer2"
|
||||
"unR2/internal/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CloudflareR2Update is the builder for updating CloudflareR2 entities.
|
||||
type CloudflareR2Update struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CloudflareR2Mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CloudflareR2Update builder.
|
||||
func (cr *CloudflareR2Update) Where(ps ...predicate.CloudflareR2) *CloudflareR2Update {
|
||||
cr.mutation.Where(ps...)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner_id" field.
|
||||
func (cr *CloudflareR2Update) SetOwnerID(s string) *CloudflareR2Update {
|
||||
cr.mutation.SetOwnerID(s)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
||||
func (cr *CloudflareR2Update) SetNillableOwnerID(s *string) *CloudflareR2Update {
|
||||
if s != nil {
|
||||
cr.SetOwnerID(*s)
|
||||
}
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (cr *CloudflareR2Update) SetName(s string) *CloudflareR2Update {
|
||||
cr.mutation.SetName(s)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (cr *CloudflareR2Update) SetNillableName(s *string) *CloudflareR2Update {
|
||||
if s != nil {
|
||||
cr.SetName(*s)
|
||||
}
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetLocation sets the "location" field.
|
||||
func (cr *CloudflareR2Update) SetLocation(s string) *CloudflareR2Update {
|
||||
cr.mutation.SetLocation(s)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetNillableLocation sets the "location" field if the given value is not nil.
|
||||
func (cr *CloudflareR2Update) SetNillableLocation(s *string) *CloudflareR2Update {
|
||||
if s != nil {
|
||||
cr.SetLocation(*s)
|
||||
}
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetStorageClass sets the "storage_class" field.
|
||||
func (cr *CloudflareR2Update) SetStorageClass(s string) *CloudflareR2Update {
|
||||
cr.mutation.SetStorageClass(s)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetNillableStorageClass sets the "storage_class" field if the given value is not nil.
|
||||
func (cr *CloudflareR2Update) SetNillableStorageClass(s *string) *CloudflareR2Update {
|
||||
if s != nil {
|
||||
cr.SetStorageClass(*s)
|
||||
}
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (cr *CloudflareR2Update) SetStatus(i int8) *CloudflareR2Update {
|
||||
cr.mutation.ResetStatus()
|
||||
cr.mutation.SetStatus(i)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (cr *CloudflareR2Update) SetNillableStatus(i *int8) *CloudflareR2Update {
|
||||
if i != nil {
|
||||
cr.SetStatus(*i)
|
||||
}
|
||||
return cr
|
||||
}
|
||||
|
||||
// AddStatus adds i to the "status" field.
|
||||
func (cr *CloudflareR2Update) AddStatus(i int8) *CloudflareR2Update {
|
||||
cr.mutation.AddStatus(i)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetPayloadSize sets the "payload_size" field.
|
||||
func (cr *CloudflareR2Update) SetPayloadSize(i int64) *CloudflareR2Update {
|
||||
cr.mutation.ResetPayloadSize()
|
||||
cr.mutation.SetPayloadSize(i)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetNillablePayloadSize sets the "payload_size" field if the given value is not nil.
|
||||
func (cr *CloudflareR2Update) SetNillablePayloadSize(i *int64) *CloudflareR2Update {
|
||||
if i != nil {
|
||||
cr.SetPayloadSize(*i)
|
||||
}
|
||||
return cr
|
||||
}
|
||||
|
||||
// AddPayloadSize adds i to the "payload_size" field.
|
||||
func (cr *CloudflareR2Update) AddPayloadSize(i int64) *CloudflareR2Update {
|
||||
cr.mutation.AddPayloadSize(i)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetMetadataSize sets the "metadata_size" field.
|
||||
func (cr *CloudflareR2Update) SetMetadataSize(i int64) *CloudflareR2Update {
|
||||
cr.mutation.ResetMetadataSize()
|
||||
cr.mutation.SetMetadataSize(i)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetNillableMetadataSize sets the "metadata_size" field if the given value is not nil.
|
||||
func (cr *CloudflareR2Update) SetNillableMetadataSize(i *int64) *CloudflareR2Update {
|
||||
if i != nil {
|
||||
cr.SetMetadataSize(*i)
|
||||
}
|
||||
return cr
|
||||
}
|
||||
|
||||
// AddMetadataSize adds i to the "metadata_size" field.
|
||||
func (cr *CloudflareR2Update) AddMetadataSize(i int64) *CloudflareR2Update {
|
||||
cr.mutation.AddMetadataSize(i)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetObjectCount sets the "object_count" field.
|
||||
func (cr *CloudflareR2Update) SetObjectCount(i int) *CloudflareR2Update {
|
||||
cr.mutation.ResetObjectCount()
|
||||
cr.mutation.SetObjectCount(i)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetNillableObjectCount sets the "object_count" field if the given value is not nil.
|
||||
func (cr *CloudflareR2Update) SetNillableObjectCount(i *int) *CloudflareR2Update {
|
||||
if i != nil {
|
||||
cr.SetObjectCount(*i)
|
||||
}
|
||||
return cr
|
||||
}
|
||||
|
||||
// AddObjectCount adds i to the "object_count" field.
|
||||
func (cr *CloudflareR2Update) AddObjectCount(i int) *CloudflareR2Update {
|
||||
cr.mutation.AddObjectCount(i)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetRemark sets the "remark" field.
|
||||
func (cr *CloudflareR2Update) SetRemark(s string) *CloudflareR2Update {
|
||||
cr.mutation.SetRemark(s)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
||||
func (cr *CloudflareR2Update) SetNillableRemark(s *string) *CloudflareR2Update {
|
||||
if s != nil {
|
||||
cr.SetRemark(*s)
|
||||
}
|
||||
return cr
|
||||
}
|
||||
|
||||
// ClearRemark clears the value of the "remark" field.
|
||||
func (cr *CloudflareR2Update) ClearRemark() *CloudflareR2Update {
|
||||
cr.mutation.ClearRemark()
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (cr *CloudflareR2Update) SetUpdatedAt(t time.Time) *CloudflareR2Update {
|
||||
cr.mutation.SetUpdatedAt(t)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetCloudflareAccountID sets the "cloudflare_account" edge to the CloudflareAccounts entity by ID.
|
||||
func (cr *CloudflareR2Update) SetCloudflareAccountID(id int) *CloudflareR2Update {
|
||||
cr.mutation.SetCloudflareAccountID(id)
|
||||
return cr
|
||||
}
|
||||
|
||||
// SetCloudflareAccount sets the "cloudflare_account" edge to the CloudflareAccounts entity.
|
||||
func (cr *CloudflareR2Update) SetCloudflareAccount(c *CloudflareAccounts) *CloudflareR2Update {
|
||||
return cr.SetCloudflareAccountID(c.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CloudflareR2Mutation object of the builder.
|
||||
func (cr *CloudflareR2Update) Mutation() *CloudflareR2Mutation {
|
||||
return cr.mutation
|
||||
}
|
||||
|
||||
// ClearCloudflareAccount clears the "cloudflare_account" edge to the CloudflareAccounts entity.
|
||||
func (cr *CloudflareR2Update) ClearCloudflareAccount() *CloudflareR2Update {
|
||||
cr.mutation.ClearCloudflareAccount()
|
||||
return cr
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (cr *CloudflareR2Update) Save(ctx context.Context) (int, error) {
|
||||
cr.defaults()
|
||||
return withHooks(ctx, cr.sqlSave, cr.mutation, cr.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (cr *CloudflareR2Update) SaveX(ctx context.Context) int {
|
||||
affected, err := cr.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (cr *CloudflareR2Update) Exec(ctx context.Context) error {
|
||||
_, err := cr.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cr *CloudflareR2Update) ExecX(ctx context.Context) {
|
||||
if err := cr.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (cr *CloudflareR2Update) defaults() {
|
||||
if _, ok := cr.mutation.UpdatedAt(); !ok {
|
||||
v := cloudflarer2.UpdateDefaultUpdatedAt()
|
||||
cr.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cr *CloudflareR2Update) check() error {
|
||||
if v, ok := cr.mutation.Name(); ok {
|
||||
if err := cloudflarer2.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "CloudflareR2.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := cr.mutation.Location(); ok {
|
||||
if err := cloudflarer2.LocationValidator(v); err != nil {
|
||||
return &ValidationError{Name: "location", err: fmt.Errorf(`ent: validator failed for field "CloudflareR2.location": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := cr.mutation.StorageClass(); ok {
|
||||
if err := cloudflarer2.StorageClassValidator(v); err != nil {
|
||||
return &ValidationError{Name: "storage_class", err: fmt.Errorf(`ent: validator failed for field "CloudflareR2.storage_class": %w`, err)}
|
||||
}
|
||||
}
|
||||
if cr.mutation.CloudflareAccountCleared() && len(cr.mutation.CloudflareAccountIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CloudflareR2.cloudflare_account"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cr *CloudflareR2Update) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := cr.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(cloudflarer2.Table, cloudflarer2.Columns, sqlgraph.NewFieldSpec(cloudflarer2.FieldID, field.TypeInt))
|
||||
if ps := cr.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := cr.mutation.OwnerID(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldOwnerID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cr.mutation.Name(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cr.mutation.Location(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldLocation, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cr.mutation.StorageClass(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldStorageClass, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cr.mutation.Status(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldStatus, field.TypeInt8, value)
|
||||
}
|
||||
if value, ok := cr.mutation.AddedStatus(); ok {
|
||||
_spec.AddField(cloudflarer2.FieldStatus, field.TypeInt8, value)
|
||||
}
|
||||
if value, ok := cr.mutation.PayloadSize(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldPayloadSize, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := cr.mutation.AddedPayloadSize(); ok {
|
||||
_spec.AddField(cloudflarer2.FieldPayloadSize, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := cr.mutation.MetadataSize(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldMetadataSize, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := cr.mutation.AddedMetadataSize(); ok {
|
||||
_spec.AddField(cloudflarer2.FieldMetadataSize, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := cr.mutation.ObjectCount(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldObjectCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := cr.mutation.AddedObjectCount(); ok {
|
||||
_spec.AddField(cloudflarer2.FieldObjectCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := cr.mutation.Remark(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldRemark, field.TypeString, value)
|
||||
}
|
||||
if cr.mutation.RemarkCleared() {
|
||||
_spec.ClearField(cloudflarer2.FieldRemark, field.TypeString)
|
||||
}
|
||||
if value, ok := cr.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if cr.mutation.CloudflareAccountCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cloudflarer2.CloudflareAccountTable,
|
||||
Columns: []string{cloudflarer2.CloudflareAccountColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cloudflareaccounts.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := cr.mutation.CloudflareAccountIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cloudflarer2.CloudflareAccountTable,
|
||||
Columns: []string{cloudflarer2.CloudflareAccountColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cloudflareaccounts.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
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, cr.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{cloudflarer2.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
cr.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// CloudflareR2UpdateOne is the builder for updating a single CloudflareR2 entity.
|
||||
type CloudflareR2UpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *CloudflareR2Mutation
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner_id" field.
|
||||
func (cro *CloudflareR2UpdateOne) SetOwnerID(s string) *CloudflareR2UpdateOne {
|
||||
cro.mutation.SetOwnerID(s)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
||||
func (cro *CloudflareR2UpdateOne) SetNillableOwnerID(s *string) *CloudflareR2UpdateOne {
|
||||
if s != nil {
|
||||
cro.SetOwnerID(*s)
|
||||
}
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (cro *CloudflareR2UpdateOne) SetName(s string) *CloudflareR2UpdateOne {
|
||||
cro.mutation.SetName(s)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (cro *CloudflareR2UpdateOne) SetNillableName(s *string) *CloudflareR2UpdateOne {
|
||||
if s != nil {
|
||||
cro.SetName(*s)
|
||||
}
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetLocation sets the "location" field.
|
||||
func (cro *CloudflareR2UpdateOne) SetLocation(s string) *CloudflareR2UpdateOne {
|
||||
cro.mutation.SetLocation(s)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetNillableLocation sets the "location" field if the given value is not nil.
|
||||
func (cro *CloudflareR2UpdateOne) SetNillableLocation(s *string) *CloudflareR2UpdateOne {
|
||||
if s != nil {
|
||||
cro.SetLocation(*s)
|
||||
}
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetStorageClass sets the "storage_class" field.
|
||||
func (cro *CloudflareR2UpdateOne) SetStorageClass(s string) *CloudflareR2UpdateOne {
|
||||
cro.mutation.SetStorageClass(s)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetNillableStorageClass sets the "storage_class" field if the given value is not nil.
|
||||
func (cro *CloudflareR2UpdateOne) SetNillableStorageClass(s *string) *CloudflareR2UpdateOne {
|
||||
if s != nil {
|
||||
cro.SetStorageClass(*s)
|
||||
}
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (cro *CloudflareR2UpdateOne) SetStatus(i int8) *CloudflareR2UpdateOne {
|
||||
cro.mutation.ResetStatus()
|
||||
cro.mutation.SetStatus(i)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (cro *CloudflareR2UpdateOne) SetNillableStatus(i *int8) *CloudflareR2UpdateOne {
|
||||
if i != nil {
|
||||
cro.SetStatus(*i)
|
||||
}
|
||||
return cro
|
||||
}
|
||||
|
||||
// AddStatus adds i to the "status" field.
|
||||
func (cro *CloudflareR2UpdateOne) AddStatus(i int8) *CloudflareR2UpdateOne {
|
||||
cro.mutation.AddStatus(i)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetPayloadSize sets the "payload_size" field.
|
||||
func (cro *CloudflareR2UpdateOne) SetPayloadSize(i int64) *CloudflareR2UpdateOne {
|
||||
cro.mutation.ResetPayloadSize()
|
||||
cro.mutation.SetPayloadSize(i)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetNillablePayloadSize sets the "payload_size" field if the given value is not nil.
|
||||
func (cro *CloudflareR2UpdateOne) SetNillablePayloadSize(i *int64) *CloudflareR2UpdateOne {
|
||||
if i != nil {
|
||||
cro.SetPayloadSize(*i)
|
||||
}
|
||||
return cro
|
||||
}
|
||||
|
||||
// AddPayloadSize adds i to the "payload_size" field.
|
||||
func (cro *CloudflareR2UpdateOne) AddPayloadSize(i int64) *CloudflareR2UpdateOne {
|
||||
cro.mutation.AddPayloadSize(i)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetMetadataSize sets the "metadata_size" field.
|
||||
func (cro *CloudflareR2UpdateOne) SetMetadataSize(i int64) *CloudflareR2UpdateOne {
|
||||
cro.mutation.ResetMetadataSize()
|
||||
cro.mutation.SetMetadataSize(i)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetNillableMetadataSize sets the "metadata_size" field if the given value is not nil.
|
||||
func (cro *CloudflareR2UpdateOne) SetNillableMetadataSize(i *int64) *CloudflareR2UpdateOne {
|
||||
if i != nil {
|
||||
cro.SetMetadataSize(*i)
|
||||
}
|
||||
return cro
|
||||
}
|
||||
|
||||
// AddMetadataSize adds i to the "metadata_size" field.
|
||||
func (cro *CloudflareR2UpdateOne) AddMetadataSize(i int64) *CloudflareR2UpdateOne {
|
||||
cro.mutation.AddMetadataSize(i)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetObjectCount sets the "object_count" field.
|
||||
func (cro *CloudflareR2UpdateOne) SetObjectCount(i int) *CloudflareR2UpdateOne {
|
||||
cro.mutation.ResetObjectCount()
|
||||
cro.mutation.SetObjectCount(i)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetNillableObjectCount sets the "object_count" field if the given value is not nil.
|
||||
func (cro *CloudflareR2UpdateOne) SetNillableObjectCount(i *int) *CloudflareR2UpdateOne {
|
||||
if i != nil {
|
||||
cro.SetObjectCount(*i)
|
||||
}
|
||||
return cro
|
||||
}
|
||||
|
||||
// AddObjectCount adds i to the "object_count" field.
|
||||
func (cro *CloudflareR2UpdateOne) AddObjectCount(i int) *CloudflareR2UpdateOne {
|
||||
cro.mutation.AddObjectCount(i)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetRemark sets the "remark" field.
|
||||
func (cro *CloudflareR2UpdateOne) SetRemark(s string) *CloudflareR2UpdateOne {
|
||||
cro.mutation.SetRemark(s)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
||||
func (cro *CloudflareR2UpdateOne) SetNillableRemark(s *string) *CloudflareR2UpdateOne {
|
||||
if s != nil {
|
||||
cro.SetRemark(*s)
|
||||
}
|
||||
return cro
|
||||
}
|
||||
|
||||
// ClearRemark clears the value of the "remark" field.
|
||||
func (cro *CloudflareR2UpdateOne) ClearRemark() *CloudflareR2UpdateOne {
|
||||
cro.mutation.ClearRemark()
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (cro *CloudflareR2UpdateOne) SetUpdatedAt(t time.Time) *CloudflareR2UpdateOne {
|
||||
cro.mutation.SetUpdatedAt(t)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetCloudflareAccountID sets the "cloudflare_account" edge to the CloudflareAccounts entity by ID.
|
||||
func (cro *CloudflareR2UpdateOne) SetCloudflareAccountID(id int) *CloudflareR2UpdateOne {
|
||||
cro.mutation.SetCloudflareAccountID(id)
|
||||
return cro
|
||||
}
|
||||
|
||||
// SetCloudflareAccount sets the "cloudflare_account" edge to the CloudflareAccounts entity.
|
||||
func (cro *CloudflareR2UpdateOne) SetCloudflareAccount(c *CloudflareAccounts) *CloudflareR2UpdateOne {
|
||||
return cro.SetCloudflareAccountID(c.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CloudflareR2Mutation object of the builder.
|
||||
func (cro *CloudflareR2UpdateOne) Mutation() *CloudflareR2Mutation {
|
||||
return cro.mutation
|
||||
}
|
||||
|
||||
// ClearCloudflareAccount clears the "cloudflare_account" edge to the CloudflareAccounts entity.
|
||||
func (cro *CloudflareR2UpdateOne) ClearCloudflareAccount() *CloudflareR2UpdateOne {
|
||||
cro.mutation.ClearCloudflareAccount()
|
||||
return cro
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CloudflareR2Update builder.
|
||||
func (cro *CloudflareR2UpdateOne) Where(ps ...predicate.CloudflareR2) *CloudflareR2UpdateOne {
|
||||
cro.mutation.Where(ps...)
|
||||
return cro
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (cro *CloudflareR2UpdateOne) Select(field string, fields ...string) *CloudflareR2UpdateOne {
|
||||
cro.fields = append([]string{field}, fields...)
|
||||
return cro
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated CloudflareR2 entity.
|
||||
func (cro *CloudflareR2UpdateOne) Save(ctx context.Context) (*CloudflareR2, error) {
|
||||
cro.defaults()
|
||||
return withHooks(ctx, cro.sqlSave, cro.mutation, cro.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (cro *CloudflareR2UpdateOne) SaveX(ctx context.Context) *CloudflareR2 {
|
||||
node, err := cro.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (cro *CloudflareR2UpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := cro.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cro *CloudflareR2UpdateOne) ExecX(ctx context.Context) {
|
||||
if err := cro.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (cro *CloudflareR2UpdateOne) defaults() {
|
||||
if _, ok := cro.mutation.UpdatedAt(); !ok {
|
||||
v := cloudflarer2.UpdateDefaultUpdatedAt()
|
||||
cro.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cro *CloudflareR2UpdateOne) check() error {
|
||||
if v, ok := cro.mutation.Name(); ok {
|
||||
if err := cloudflarer2.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "CloudflareR2.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := cro.mutation.Location(); ok {
|
||||
if err := cloudflarer2.LocationValidator(v); err != nil {
|
||||
return &ValidationError{Name: "location", err: fmt.Errorf(`ent: validator failed for field "CloudflareR2.location": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := cro.mutation.StorageClass(); ok {
|
||||
if err := cloudflarer2.StorageClassValidator(v); err != nil {
|
||||
return &ValidationError{Name: "storage_class", err: fmt.Errorf(`ent: validator failed for field "CloudflareR2.storage_class": %w`, err)}
|
||||
}
|
||||
}
|
||||
if cro.mutation.CloudflareAccountCleared() && len(cro.mutation.CloudflareAccountIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CloudflareR2.cloudflare_account"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cro *CloudflareR2UpdateOne) sqlSave(ctx context.Context) (_node *CloudflareR2, err error) {
|
||||
if err := cro.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(cloudflarer2.Table, cloudflarer2.Columns, sqlgraph.NewFieldSpec(cloudflarer2.FieldID, field.TypeInt))
|
||||
id, ok := cro.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CloudflareR2.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := cro.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, cloudflarer2.FieldID)
|
||||
for _, f := range fields {
|
||||
if !cloudflarer2.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != cloudflarer2.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := cro.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := cro.mutation.OwnerID(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldOwnerID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cro.mutation.Name(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cro.mutation.Location(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldLocation, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cro.mutation.StorageClass(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldStorageClass, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cro.mutation.Status(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldStatus, field.TypeInt8, value)
|
||||
}
|
||||
if value, ok := cro.mutation.AddedStatus(); ok {
|
||||
_spec.AddField(cloudflarer2.FieldStatus, field.TypeInt8, value)
|
||||
}
|
||||
if value, ok := cro.mutation.PayloadSize(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldPayloadSize, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := cro.mutation.AddedPayloadSize(); ok {
|
||||
_spec.AddField(cloudflarer2.FieldPayloadSize, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := cro.mutation.MetadataSize(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldMetadataSize, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := cro.mutation.AddedMetadataSize(); ok {
|
||||
_spec.AddField(cloudflarer2.FieldMetadataSize, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := cro.mutation.ObjectCount(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldObjectCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := cro.mutation.AddedObjectCount(); ok {
|
||||
_spec.AddField(cloudflarer2.FieldObjectCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := cro.mutation.Remark(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldRemark, field.TypeString, value)
|
||||
}
|
||||
if cro.mutation.RemarkCleared() {
|
||||
_spec.ClearField(cloudflarer2.FieldRemark, field.TypeString)
|
||||
}
|
||||
if value, ok := cro.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(cloudflarer2.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if cro.mutation.CloudflareAccountCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cloudflarer2.CloudflareAccountTable,
|
||||
Columns: []string{cloudflarer2.CloudflareAccountColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cloudflareaccounts.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := cro.mutation.CloudflareAccountIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cloudflarer2.CloudflareAccountTable,
|
||||
Columns: []string{cloudflarer2.CloudflareAccountColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cloudflareaccounts.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &CloudflareR2{config: cro.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, cro.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{cloudflarer2.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
cro.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user