12
This commit is contained in:
671
internal/ent/cloudflareaccounts_update.go
Normal file
671
internal/ent/cloudflareaccounts_update.go
Normal file
@ -0,0 +1,671 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// CloudflareAccountsUpdate is the builder for updating CloudflareAccounts entities.
|
||||
type CloudflareAccountsUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CloudflareAccountsMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CloudflareAccountsUpdate builder.
|
||||
func (cau *CloudflareAccountsUpdate) Where(ps ...predicate.CloudflareAccounts) *CloudflareAccountsUpdate {
|
||||
cau.mutation.Where(ps...)
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (cau *CloudflareAccountsUpdate) SetName(s string) *CloudflareAccountsUpdate {
|
||||
cau.mutation.SetName(s)
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (cau *CloudflareAccountsUpdate) SetNillableName(s *string) *CloudflareAccountsUpdate {
|
||||
if s != nil {
|
||||
cau.SetName(*s)
|
||||
}
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetAccountID sets the "account_id" field.
|
||||
func (cau *CloudflareAccountsUpdate) SetAccountID(s string) *CloudflareAccountsUpdate {
|
||||
cau.mutation.SetAccountID(s)
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
|
||||
func (cau *CloudflareAccountsUpdate) SetNillableAccountID(s *string) *CloudflareAccountsUpdate {
|
||||
if s != nil {
|
||||
cau.SetAccountID(*s)
|
||||
}
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetAPIToken sets the "api_token" field.
|
||||
func (cau *CloudflareAccountsUpdate) SetAPIToken(s string) *CloudflareAccountsUpdate {
|
||||
cau.mutation.SetAPIToken(s)
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetNillableAPIToken sets the "api_token" field if the given value is not nil.
|
||||
func (cau *CloudflareAccountsUpdate) SetNillableAPIToken(s *string) *CloudflareAccountsUpdate {
|
||||
if s != nil {
|
||||
cau.SetAPIToken(*s)
|
||||
}
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (cau *CloudflareAccountsUpdate) SetEmail(s string) *CloudflareAccountsUpdate {
|
||||
cau.mutation.SetEmail(s)
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (cau *CloudflareAccountsUpdate) SetNillableEmail(s *string) *CloudflareAccountsUpdate {
|
||||
if s != nil {
|
||||
cau.SetEmail(*s)
|
||||
}
|
||||
return cau
|
||||
}
|
||||
|
||||
// ClearEmail clears the value of the "email" field.
|
||||
func (cau *CloudflareAccountsUpdate) ClearEmail() *CloudflareAccountsUpdate {
|
||||
cau.mutation.ClearEmail()
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (cau *CloudflareAccountsUpdate) SetStatus(i int8) *CloudflareAccountsUpdate {
|
||||
cau.mutation.ResetStatus()
|
||||
cau.mutation.SetStatus(i)
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (cau *CloudflareAccountsUpdate) SetNillableStatus(i *int8) *CloudflareAccountsUpdate {
|
||||
if i != nil {
|
||||
cau.SetStatus(*i)
|
||||
}
|
||||
return cau
|
||||
}
|
||||
|
||||
// AddStatus adds i to the "status" field.
|
||||
func (cau *CloudflareAccountsUpdate) AddStatus(i int8) *CloudflareAccountsUpdate {
|
||||
cau.mutation.AddStatus(i)
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetRemark sets the "remark" field.
|
||||
func (cau *CloudflareAccountsUpdate) SetRemark(s string) *CloudflareAccountsUpdate {
|
||||
cau.mutation.SetRemark(s)
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
||||
func (cau *CloudflareAccountsUpdate) SetNillableRemark(s *string) *CloudflareAccountsUpdate {
|
||||
if s != nil {
|
||||
cau.SetRemark(*s)
|
||||
}
|
||||
return cau
|
||||
}
|
||||
|
||||
// ClearRemark clears the value of the "remark" field.
|
||||
func (cau *CloudflareAccountsUpdate) ClearRemark() *CloudflareAccountsUpdate {
|
||||
cau.mutation.ClearRemark()
|
||||
return cau
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (cau *CloudflareAccountsUpdate) SetUpdatedAt(t time.Time) *CloudflareAccountsUpdate {
|
||||
cau.mutation.SetUpdatedAt(t)
|
||||
return cau
|
||||
}
|
||||
|
||||
// AddCloudflareBucketIDs adds the "cloudflare_buckets" edge to the CloudflareR2 entity by IDs.
|
||||
func (cau *CloudflareAccountsUpdate) AddCloudflareBucketIDs(ids ...int) *CloudflareAccountsUpdate {
|
||||
cau.mutation.AddCloudflareBucketIDs(ids...)
|
||||
return cau
|
||||
}
|
||||
|
||||
// AddCloudflareBuckets adds the "cloudflare_buckets" edges to the CloudflareR2 entity.
|
||||
func (cau *CloudflareAccountsUpdate) AddCloudflareBuckets(c ...*CloudflareR2) *CloudflareAccountsUpdate {
|
||||
ids := make([]int, len(c))
|
||||
for i := range c {
|
||||
ids[i] = c[i].ID
|
||||
}
|
||||
return cau.AddCloudflareBucketIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the CloudflareAccountsMutation object of the builder.
|
||||
func (cau *CloudflareAccountsUpdate) Mutation() *CloudflareAccountsMutation {
|
||||
return cau.mutation
|
||||
}
|
||||
|
||||
// ClearCloudflareBuckets clears all "cloudflare_buckets" edges to the CloudflareR2 entity.
|
||||
func (cau *CloudflareAccountsUpdate) ClearCloudflareBuckets() *CloudflareAccountsUpdate {
|
||||
cau.mutation.ClearCloudflareBuckets()
|
||||
return cau
|
||||
}
|
||||
|
||||
// RemoveCloudflareBucketIDs removes the "cloudflare_buckets" edge to CloudflareR2 entities by IDs.
|
||||
func (cau *CloudflareAccountsUpdate) RemoveCloudflareBucketIDs(ids ...int) *CloudflareAccountsUpdate {
|
||||
cau.mutation.RemoveCloudflareBucketIDs(ids...)
|
||||
return cau
|
||||
}
|
||||
|
||||
// RemoveCloudflareBuckets removes "cloudflare_buckets" edges to CloudflareR2 entities.
|
||||
func (cau *CloudflareAccountsUpdate) RemoveCloudflareBuckets(c ...*CloudflareR2) *CloudflareAccountsUpdate {
|
||||
ids := make([]int, len(c))
|
||||
for i := range c {
|
||||
ids[i] = c[i].ID
|
||||
}
|
||||
return cau.RemoveCloudflareBucketIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (cau *CloudflareAccountsUpdate) Save(ctx context.Context) (int, error) {
|
||||
cau.defaults()
|
||||
return withHooks(ctx, cau.sqlSave, cau.mutation, cau.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (cau *CloudflareAccountsUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := cau.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (cau *CloudflareAccountsUpdate) Exec(ctx context.Context) error {
|
||||
_, err := cau.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cau *CloudflareAccountsUpdate) ExecX(ctx context.Context) {
|
||||
if err := cau.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (cau *CloudflareAccountsUpdate) defaults() {
|
||||
if _, ok := cau.mutation.UpdatedAt(); !ok {
|
||||
v := cloudflareaccounts.UpdateDefaultUpdatedAt()
|
||||
cau.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cau *CloudflareAccountsUpdate) check() error {
|
||||
if v, ok := cau.mutation.Name(); ok {
|
||||
if err := cloudflareaccounts.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "CloudflareAccounts.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := cau.mutation.AccountID(); ok {
|
||||
if err := cloudflareaccounts.AccountIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "account_id", err: fmt.Errorf(`ent: validator failed for field "CloudflareAccounts.account_id": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cau *CloudflareAccountsUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := cau.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(cloudflareaccounts.Table, cloudflareaccounts.Columns, sqlgraph.NewFieldSpec(cloudflareaccounts.FieldID, field.TypeInt))
|
||||
if ps := cau.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := cau.mutation.Name(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cau.mutation.AccountID(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldAccountID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cau.mutation.APIToken(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldAPIToken, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cau.mutation.Email(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
if cau.mutation.EmailCleared() {
|
||||
_spec.ClearField(cloudflareaccounts.FieldEmail, field.TypeString)
|
||||
}
|
||||
if value, ok := cau.mutation.Status(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldStatus, field.TypeInt8, value)
|
||||
}
|
||||
if value, ok := cau.mutation.AddedStatus(); ok {
|
||||
_spec.AddField(cloudflareaccounts.FieldStatus, field.TypeInt8, value)
|
||||
}
|
||||
if value, ok := cau.mutation.Remark(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldRemark, field.TypeString, value)
|
||||
}
|
||||
if cau.mutation.RemarkCleared() {
|
||||
_spec.ClearField(cloudflareaccounts.FieldRemark, field.TypeString)
|
||||
}
|
||||
if value, ok := cau.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if cau.mutation.CloudflareBucketsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cloudflareaccounts.CloudflareBucketsTable,
|
||||
Columns: []string{cloudflareaccounts.CloudflareBucketsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cloudflarer2.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := cau.mutation.RemovedCloudflareBucketsIDs(); len(nodes) > 0 && !cau.mutation.CloudflareBucketsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cloudflareaccounts.CloudflareBucketsTable,
|
||||
Columns: []string{cloudflareaccounts.CloudflareBucketsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cloudflarer2.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := cau.mutation.CloudflareBucketsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cloudflareaccounts.CloudflareBucketsTable,
|
||||
Columns: []string{cloudflareaccounts.CloudflareBucketsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cloudflarer2.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, cau.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{cloudflareaccounts.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
cau.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// CloudflareAccountsUpdateOne is the builder for updating a single CloudflareAccounts entity.
|
||||
type CloudflareAccountsUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *CloudflareAccountsMutation
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetName(s string) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.SetName(s)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetNillableName(s *string) *CloudflareAccountsUpdateOne {
|
||||
if s != nil {
|
||||
cauo.SetName(*s)
|
||||
}
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetAccountID sets the "account_id" field.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetAccountID(s string) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.SetAccountID(s)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetNillableAccountID(s *string) *CloudflareAccountsUpdateOne {
|
||||
if s != nil {
|
||||
cauo.SetAccountID(*s)
|
||||
}
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetAPIToken sets the "api_token" field.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetAPIToken(s string) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.SetAPIToken(s)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetNillableAPIToken sets the "api_token" field if the given value is not nil.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetNillableAPIToken(s *string) *CloudflareAccountsUpdateOne {
|
||||
if s != nil {
|
||||
cauo.SetAPIToken(*s)
|
||||
}
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetEmail(s string) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.SetEmail(s)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetNillableEmail(s *string) *CloudflareAccountsUpdateOne {
|
||||
if s != nil {
|
||||
cauo.SetEmail(*s)
|
||||
}
|
||||
return cauo
|
||||
}
|
||||
|
||||
// ClearEmail clears the value of the "email" field.
|
||||
func (cauo *CloudflareAccountsUpdateOne) ClearEmail() *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.ClearEmail()
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetStatus(i int8) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.ResetStatus()
|
||||
cauo.mutation.SetStatus(i)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetNillableStatus(i *int8) *CloudflareAccountsUpdateOne {
|
||||
if i != nil {
|
||||
cauo.SetStatus(*i)
|
||||
}
|
||||
return cauo
|
||||
}
|
||||
|
||||
// AddStatus adds i to the "status" field.
|
||||
func (cauo *CloudflareAccountsUpdateOne) AddStatus(i int8) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.AddStatus(i)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetRemark sets the "remark" field.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetRemark(s string) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.SetRemark(s)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetNillableRemark(s *string) *CloudflareAccountsUpdateOne {
|
||||
if s != nil {
|
||||
cauo.SetRemark(*s)
|
||||
}
|
||||
return cauo
|
||||
}
|
||||
|
||||
// ClearRemark clears the value of the "remark" field.
|
||||
func (cauo *CloudflareAccountsUpdateOne) ClearRemark() *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.ClearRemark()
|
||||
return cauo
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SetUpdatedAt(t time.Time) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.SetUpdatedAt(t)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// AddCloudflareBucketIDs adds the "cloudflare_buckets" edge to the CloudflareR2 entity by IDs.
|
||||
func (cauo *CloudflareAccountsUpdateOne) AddCloudflareBucketIDs(ids ...int) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.AddCloudflareBucketIDs(ids...)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// AddCloudflareBuckets adds the "cloudflare_buckets" edges to the CloudflareR2 entity.
|
||||
func (cauo *CloudflareAccountsUpdateOne) AddCloudflareBuckets(c ...*CloudflareR2) *CloudflareAccountsUpdateOne {
|
||||
ids := make([]int, len(c))
|
||||
for i := range c {
|
||||
ids[i] = c[i].ID
|
||||
}
|
||||
return cauo.AddCloudflareBucketIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the CloudflareAccountsMutation object of the builder.
|
||||
func (cauo *CloudflareAccountsUpdateOne) Mutation() *CloudflareAccountsMutation {
|
||||
return cauo.mutation
|
||||
}
|
||||
|
||||
// ClearCloudflareBuckets clears all "cloudflare_buckets" edges to the CloudflareR2 entity.
|
||||
func (cauo *CloudflareAccountsUpdateOne) ClearCloudflareBuckets() *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.ClearCloudflareBuckets()
|
||||
return cauo
|
||||
}
|
||||
|
||||
// RemoveCloudflareBucketIDs removes the "cloudflare_buckets" edge to CloudflareR2 entities by IDs.
|
||||
func (cauo *CloudflareAccountsUpdateOne) RemoveCloudflareBucketIDs(ids ...int) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.RemoveCloudflareBucketIDs(ids...)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// RemoveCloudflareBuckets removes "cloudflare_buckets" edges to CloudflareR2 entities.
|
||||
func (cauo *CloudflareAccountsUpdateOne) RemoveCloudflareBuckets(c ...*CloudflareR2) *CloudflareAccountsUpdateOne {
|
||||
ids := make([]int, len(c))
|
||||
for i := range c {
|
||||
ids[i] = c[i].ID
|
||||
}
|
||||
return cauo.RemoveCloudflareBucketIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CloudflareAccountsUpdate builder.
|
||||
func (cauo *CloudflareAccountsUpdateOne) Where(ps ...predicate.CloudflareAccounts) *CloudflareAccountsUpdateOne {
|
||||
cauo.mutation.Where(ps...)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (cauo *CloudflareAccountsUpdateOne) Select(field string, fields ...string) *CloudflareAccountsUpdateOne {
|
||||
cauo.fields = append([]string{field}, fields...)
|
||||
return cauo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated CloudflareAccounts entity.
|
||||
func (cauo *CloudflareAccountsUpdateOne) Save(ctx context.Context) (*CloudflareAccounts, error) {
|
||||
cauo.defaults()
|
||||
return withHooks(ctx, cauo.sqlSave, cauo.mutation, cauo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (cauo *CloudflareAccountsUpdateOne) SaveX(ctx context.Context) *CloudflareAccounts {
|
||||
node, err := cauo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (cauo *CloudflareAccountsUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := cauo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cauo *CloudflareAccountsUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := cauo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (cauo *CloudflareAccountsUpdateOne) defaults() {
|
||||
if _, ok := cauo.mutation.UpdatedAt(); !ok {
|
||||
v := cloudflareaccounts.UpdateDefaultUpdatedAt()
|
||||
cauo.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cauo *CloudflareAccountsUpdateOne) check() error {
|
||||
if v, ok := cauo.mutation.Name(); ok {
|
||||
if err := cloudflareaccounts.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "CloudflareAccounts.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := cauo.mutation.AccountID(); ok {
|
||||
if err := cloudflareaccounts.AccountIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "account_id", err: fmt.Errorf(`ent: validator failed for field "CloudflareAccounts.account_id": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cauo *CloudflareAccountsUpdateOne) sqlSave(ctx context.Context) (_node *CloudflareAccounts, err error) {
|
||||
if err := cauo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(cloudflareaccounts.Table, cloudflareaccounts.Columns, sqlgraph.NewFieldSpec(cloudflareaccounts.FieldID, field.TypeInt))
|
||||
id, ok := cauo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CloudflareAccounts.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := cauo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, cloudflareaccounts.FieldID)
|
||||
for _, f := range fields {
|
||||
if !cloudflareaccounts.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != cloudflareaccounts.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := cauo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := cauo.mutation.Name(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cauo.mutation.AccountID(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldAccountID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cauo.mutation.APIToken(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldAPIToken, field.TypeString, value)
|
||||
}
|
||||
if value, ok := cauo.mutation.Email(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
if cauo.mutation.EmailCleared() {
|
||||
_spec.ClearField(cloudflareaccounts.FieldEmail, field.TypeString)
|
||||
}
|
||||
if value, ok := cauo.mutation.Status(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldStatus, field.TypeInt8, value)
|
||||
}
|
||||
if value, ok := cauo.mutation.AddedStatus(); ok {
|
||||
_spec.AddField(cloudflareaccounts.FieldStatus, field.TypeInt8, value)
|
||||
}
|
||||
if value, ok := cauo.mutation.Remark(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldRemark, field.TypeString, value)
|
||||
}
|
||||
if cauo.mutation.RemarkCleared() {
|
||||
_spec.ClearField(cloudflareaccounts.FieldRemark, field.TypeString)
|
||||
}
|
||||
if value, ok := cauo.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(cloudflareaccounts.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if cauo.mutation.CloudflareBucketsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cloudflareaccounts.CloudflareBucketsTable,
|
||||
Columns: []string{cloudflareaccounts.CloudflareBucketsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cloudflarer2.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := cauo.mutation.RemovedCloudflareBucketsIDs(); len(nodes) > 0 && !cauo.mutation.CloudflareBucketsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cloudflareaccounts.CloudflareBucketsTable,
|
||||
Columns: []string{cloudflareaccounts.CloudflareBucketsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cloudflarer2.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := cauo.mutation.CloudflareBucketsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cloudflareaccounts.CloudflareBucketsTable,
|
||||
Columns: []string{cloudflareaccounts.CloudflareBucketsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cloudflarer2.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &CloudflareAccounts{config: cauo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, cauo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{cloudflareaccounts.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
cauo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user