// Copyright 2019-present Facebook Inc. All rights reserved. // This source code is licensed under the Apache 2.0 license found // in the LICENSE file in the root directory of this source tree. // Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "math/big" "net/url" "entgo.io/ent/dialect/gremlin" "entgo.io/ent/dialect/gremlin/graph/dsl" "entgo.io/ent/dialect/gremlin/graph/dsl/__" "entgo.io/ent/dialect/gremlin/graph/dsl/g" "entgo.io/ent/entc/integration/gremlin/ent/exvaluescan" "entgo.io/ent/entc/integration/gremlin/ent/predicate" ) // ExValueScanUpdate is the builder for updating ExValueScan entities. type ExValueScanUpdate struct { config hooks []Hook mutation *ExValueScanMutation } // Where appends a list predicates to the ExValueScanUpdate builder. func (_u *ExValueScanUpdate) Where(ps ...predicate.ExValueScan) *ExValueScanUpdate { _u.mutation.Where(ps...) return _u } // SetBinary sets the "binary" field. func (_u *ExValueScanUpdate) SetBinary(v *url.URL) *ExValueScanUpdate { _u.mutation.SetBinary(v) return _u } // SetBinaryBytes sets the "binary_bytes" field. func (_u *ExValueScanUpdate) SetBinaryBytes(v *url.URL) *ExValueScanUpdate { _u.mutation.SetBinaryBytes(v) return _u } // SetBinaryOptional sets the "binary_optional" field. func (_u *ExValueScanUpdate) SetBinaryOptional(v *url.URL) *ExValueScanUpdate { _u.mutation.SetBinaryOptional(v) return _u } // ClearBinaryOptional clears the value of the "binary_optional" field. func (_u *ExValueScanUpdate) ClearBinaryOptional() *ExValueScanUpdate { _u.mutation.ClearBinaryOptional() return _u } // SetText sets the "text" field. func (_u *ExValueScanUpdate) SetText(v *big.Int) *ExValueScanUpdate { _u.mutation.SetText(v) return _u } // SetTextOptional sets the "text_optional" field. func (_u *ExValueScanUpdate) SetTextOptional(v *big.Int) *ExValueScanUpdate { _u.mutation.SetTextOptional(v) return _u } // ClearTextOptional clears the value of the "text_optional" field. func (_u *ExValueScanUpdate) ClearTextOptional() *ExValueScanUpdate { _u.mutation.ClearTextOptional() return _u } // SetBase64 sets the "base64" field. func (_u *ExValueScanUpdate) SetBase64(v string) *ExValueScanUpdate { _u.mutation.SetBase64(v) return _u } // SetNillableBase64 sets the "base64" field if the given value is not nil. func (_u *ExValueScanUpdate) SetNillableBase64(v *string) *ExValueScanUpdate { if v != nil { _u.SetBase64(*v) } return _u } // SetCustom sets the "custom" field. func (_u *ExValueScanUpdate) SetCustom(v string) *ExValueScanUpdate { _u.mutation.SetCustom(v) return _u } // SetNillableCustom sets the "custom" field if the given value is not nil. func (_u *ExValueScanUpdate) SetNillableCustom(v *string) *ExValueScanUpdate { if v != nil { _u.SetCustom(*v) } return _u } // SetCustomOptional sets the "custom_optional" field. func (_u *ExValueScanUpdate) SetCustomOptional(v string) *ExValueScanUpdate { _u.mutation.SetCustomOptional(v) return _u } // SetNillableCustomOptional sets the "custom_optional" field if the given value is not nil. func (_u *ExValueScanUpdate) SetNillableCustomOptional(v *string) *ExValueScanUpdate { if v != nil { _u.SetCustomOptional(*v) } return _u } // ClearCustomOptional clears the value of the "custom_optional" field. func (_u *ExValueScanUpdate) ClearCustomOptional() *ExValueScanUpdate { _u.mutation.ClearCustomOptional() return _u } // Mutation returns the ExValueScanMutation object of the builder. func (_u *ExValueScanUpdate) Mutation() *ExValueScanMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *ExValueScanUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, _u.gremlinSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *ExValueScanUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *ExValueScanUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *ExValueScanUpdate) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } func (_u *ExValueScanUpdate) gremlinSave(ctx context.Context) (int, error) { res := &gremlin.Response{} query, bindings := _u.gremlin().Query() if err := _u.driver.Exec(ctx, query, bindings, res); err != nil { return 0, err } if err, ok := isConstantError(res); ok { return 0, err } _u.mutation.done = true return res.ReadInt() } func (_u *ExValueScanUpdate) gremlin() *dsl.Traversal { v := g.V().HasLabel(exvaluescan.Label) for _, p := range _u.mutation.Predicates() { p(v) } var ( trs []*dsl.Traversal ) if value, ok := _u.mutation.Binary(); ok { v.Property(dsl.Single, exvaluescan.FieldBinary, value) } if value, ok := _u.mutation.BinaryBytes(); ok { v.Property(dsl.Single, exvaluescan.FieldBinaryBytes, value) } if value, ok := _u.mutation.BinaryOptional(); ok { v.Property(dsl.Single, exvaluescan.FieldBinaryOptional, value) } if value, ok := _u.mutation.Text(); ok { v.Property(dsl.Single, exvaluescan.FieldText, value) } if value, ok := _u.mutation.TextOptional(); ok { v.Property(dsl.Single, exvaluescan.FieldTextOptional, value) } if value, ok := _u.mutation.Base64(); ok { v.Property(dsl.Single, exvaluescan.FieldBase64, value) } if value, ok := _u.mutation.Custom(); ok { v.Property(dsl.Single, exvaluescan.FieldCustom, value) } if value, ok := _u.mutation.CustomOptional(); ok { v.Property(dsl.Single, exvaluescan.FieldCustomOptional, value) } var properties []any if _u.mutation.BinaryOptionalCleared() { properties = append(properties, exvaluescan.FieldBinaryOptional) } if _u.mutation.TextOptionalCleared() { properties = append(properties, exvaluescan.FieldTextOptional) } if _u.mutation.CustomOptionalCleared() { properties = append(properties, exvaluescan.FieldCustomOptional) } if len(properties) > 0 { v.SideEffect(__.Properties(properties...).Drop()) } v.Count() trs = append(trs, v) return dsl.Join(trs...) } // ExValueScanUpdateOne is the builder for updating a single ExValueScan entity. type ExValueScanUpdateOne struct { config fields []string hooks []Hook mutation *ExValueScanMutation } // SetBinary sets the "binary" field. func (_u *ExValueScanUpdateOne) SetBinary(v *url.URL) *ExValueScanUpdateOne { _u.mutation.SetBinary(v) return _u } // SetBinaryBytes sets the "binary_bytes" field. func (_u *ExValueScanUpdateOne) SetBinaryBytes(v *url.URL) *ExValueScanUpdateOne { _u.mutation.SetBinaryBytes(v) return _u } // SetBinaryOptional sets the "binary_optional" field. func (_u *ExValueScanUpdateOne) SetBinaryOptional(v *url.URL) *ExValueScanUpdateOne { _u.mutation.SetBinaryOptional(v) return _u } // ClearBinaryOptional clears the value of the "binary_optional" field. func (_u *ExValueScanUpdateOne) ClearBinaryOptional() *ExValueScanUpdateOne { _u.mutation.ClearBinaryOptional() return _u } // SetText sets the "text" field. func (_u *ExValueScanUpdateOne) SetText(v *big.Int) *ExValueScanUpdateOne { _u.mutation.SetText(v) return _u } // SetTextOptional sets the "text_optional" field. func (_u *ExValueScanUpdateOne) SetTextOptional(v *big.Int) *ExValueScanUpdateOne { _u.mutation.SetTextOptional(v) return _u } // ClearTextOptional clears the value of the "text_optional" field. func (_u *ExValueScanUpdateOne) ClearTextOptional() *ExValueScanUpdateOne { _u.mutation.ClearTextOptional() return _u } // SetBase64 sets the "base64" field. func (_u *ExValueScanUpdateOne) SetBase64(v string) *ExValueScanUpdateOne { _u.mutation.SetBase64(v) return _u } // SetNillableBase64 sets the "base64" field if the given value is not nil. func (_u *ExValueScanUpdateOne) SetNillableBase64(v *string) *ExValueScanUpdateOne { if v != nil { _u.SetBase64(*v) } return _u } // SetCustom sets the "custom" field. func (_u *ExValueScanUpdateOne) SetCustom(v string) *ExValueScanUpdateOne { _u.mutation.SetCustom(v) return _u } // SetNillableCustom sets the "custom" field if the given value is not nil. func (_u *ExValueScanUpdateOne) SetNillableCustom(v *string) *ExValueScanUpdateOne { if v != nil { _u.SetCustom(*v) } return _u } // SetCustomOptional sets the "custom_optional" field. func (_u *ExValueScanUpdateOne) SetCustomOptional(v string) *ExValueScanUpdateOne { _u.mutation.SetCustomOptional(v) return _u } // SetNillableCustomOptional sets the "custom_optional" field if the given value is not nil. func (_u *ExValueScanUpdateOne) SetNillableCustomOptional(v *string) *ExValueScanUpdateOne { if v != nil { _u.SetCustomOptional(*v) } return _u } // ClearCustomOptional clears the value of the "custom_optional" field. func (_u *ExValueScanUpdateOne) ClearCustomOptional() *ExValueScanUpdateOne { _u.mutation.ClearCustomOptional() return _u } // Mutation returns the ExValueScanMutation object of the builder. func (_u *ExValueScanUpdateOne) Mutation() *ExValueScanMutation { return _u.mutation } // Where appends a list predicates to the ExValueScanUpdate builder. func (_u *ExValueScanUpdateOne) Where(ps ...predicate.ExValueScan) *ExValueScanUpdateOne { _u.mutation.Where(ps...) return _u } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (_u *ExValueScanUpdateOne) Select(field string, fields ...string) *ExValueScanUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated ExValueScan entity. func (_u *ExValueScanUpdateOne) Save(ctx context.Context) (*ExValueScan, error) { return withHooks(ctx, _u.gremlinSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *ExValueScanUpdateOne) SaveX(ctx context.Context) *ExValueScan { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *ExValueScanUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *ExValueScanUpdateOne) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } func (_u *ExValueScanUpdateOne) gremlinSave(ctx context.Context) (*ExValueScan, error) { res := &gremlin.Response{} id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ExValueScan.id" for update`)} } query, bindings := _u.gremlin(id).Query() if err := _u.driver.Exec(ctx, query, bindings, res); err != nil { return nil, err } if err, ok := isConstantError(res); ok { return nil, err } _u.mutation.done = true _m := &ExValueScan{config: _u.config} if err := _m.FromResponse(res); err != nil { return nil, err } return _m, nil } func (_u *ExValueScanUpdateOne) gremlin(id string) *dsl.Traversal { v := g.V(id) var ( trs []*dsl.Traversal ) if value, ok := _u.mutation.Binary(); ok { v.Property(dsl.Single, exvaluescan.FieldBinary, value) } if value, ok := _u.mutation.BinaryBytes(); ok { v.Property(dsl.Single, exvaluescan.FieldBinaryBytes, value) } if value, ok := _u.mutation.BinaryOptional(); ok { v.Property(dsl.Single, exvaluescan.FieldBinaryOptional, value) } if value, ok := _u.mutation.Text(); ok { v.Property(dsl.Single, exvaluescan.FieldText, value) } if value, ok := _u.mutation.TextOptional(); ok { v.Property(dsl.Single, exvaluescan.FieldTextOptional, value) } if value, ok := _u.mutation.Base64(); ok { v.Property(dsl.Single, exvaluescan.FieldBase64, value) } if value, ok := _u.mutation.Custom(); ok { v.Property(dsl.Single, exvaluescan.FieldCustom, value) } if value, ok := _u.mutation.CustomOptional(); ok { v.Property(dsl.Single, exvaluescan.FieldCustomOptional, value) } var properties []any if _u.mutation.BinaryOptionalCleared() { properties = append(properties, exvaluescan.FieldBinaryOptional) } if _u.mutation.TextOptionalCleared() { properties = append(properties, exvaluescan.FieldTextOptional) } if _u.mutation.CustomOptionalCleared() { properties = append(properties, exvaluescan.FieldCustomOptional) } if len(properties) > 0 { v.SideEffect(__.Properties(properties...).Drop()) } if len(_u.fields) > 0 { fields := make([]any, 0, len(_u.fields)+1) fields = append(fields, true) for _, f := range _u.fields { fields = append(fields, f) } v.ValueMap(fields...) } else { v.ValueMap(true) } trs = append(trs, v) return dsl.Join(trs...) }