pcmt/ent/settings_update.go
surtur 74546f996b
All checks were successful
continuous-integration/drone/push Build is passing
ent: add/extend entities, tests, validation
2023-08-19 04:52:15 +02:00

334 lines
9.7 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
"git.dotya.ml/mirre-mt/pcmt/ent/settings"
)
// SettingsUpdate is the builder for updating Settings entities.
type SettingsUpdate struct {
config
hooks []Hook
mutation *SettingsMutation
}
// Where appends a list predicates to the SettingsUpdate builder.
func (su *SettingsUpdate) Where(ps ...predicate.Settings) *SettingsUpdate {
su.mutation.Where(ps...)
return su
}
// SetHibpAPIKey sets the "hibp_api_key" field.
func (su *SettingsUpdate) SetHibpAPIKey(s string) *SettingsUpdate {
su.mutation.SetHibpAPIKey(s)
return su
}
// SetNillableHibpAPIKey sets the "hibp_api_key" field if the given value is not nil.
func (su *SettingsUpdate) SetNillableHibpAPIKey(s *string) *SettingsUpdate {
if s != nil {
su.SetHibpAPIKey(*s)
}
return su
}
// ClearHibpAPIKey clears the value of the "hibp_api_key" field.
func (su *SettingsUpdate) ClearHibpAPIKey() *SettingsUpdate {
su.mutation.ClearHibpAPIKey()
return su
}
// SetDehashedAPIKey sets the "dehashed_api_key" field.
func (su *SettingsUpdate) SetDehashedAPIKey(s string) *SettingsUpdate {
su.mutation.SetDehashedAPIKey(s)
return su
}
// SetNillableDehashedAPIKey sets the "dehashed_api_key" field if the given value is not nil.
func (su *SettingsUpdate) SetNillableDehashedAPIKey(s *string) *SettingsUpdate {
if s != nil {
su.SetDehashedAPIKey(*s)
}
return su
}
// ClearDehashedAPIKey clears the value of the "dehashed_api_key" field.
func (su *SettingsUpdate) ClearDehashedAPIKey() *SettingsUpdate {
su.mutation.ClearDehashedAPIKey()
return su
}
// SetSearches sets the "searches" field.
func (su *SettingsUpdate) SetSearches(u uint64) *SettingsUpdate {
su.mutation.ResetSearches()
su.mutation.SetSearches(u)
return su
}
// SetNillableSearches sets the "searches" field if the given value is not nil.
func (su *SettingsUpdate) SetNillableSearches(u *uint64) *SettingsUpdate {
if u != nil {
su.SetSearches(*u)
}
return su
}
// AddSearches adds u to the "searches" field.
func (su *SettingsUpdate) AddSearches(u int64) *SettingsUpdate {
su.mutation.AddSearches(u)
return su
}
// Mutation returns the SettingsMutation object of the builder.
func (su *SettingsUpdate) Mutation() *SettingsMutation {
return su.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (su *SettingsUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, su.sqlSave, su.mutation, su.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (su *SettingsUpdate) SaveX(ctx context.Context) int {
affected, err := su.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (su *SettingsUpdate) Exec(ctx context.Context) error {
_, err := su.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (su *SettingsUpdate) ExecX(ctx context.Context) {
if err := su.Exec(ctx); err != nil {
panic(err)
}
}
func (su *SettingsUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(settings.Table, settings.Columns, sqlgraph.NewFieldSpec(settings.FieldID, field.TypeUUID))
if ps := su.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := su.mutation.HibpAPIKey(); ok {
_spec.SetField(settings.FieldHibpAPIKey, field.TypeString, value)
}
if su.mutation.HibpAPIKeyCleared() {
_spec.ClearField(settings.FieldHibpAPIKey, field.TypeString)
}
if value, ok := su.mutation.DehashedAPIKey(); ok {
_spec.SetField(settings.FieldDehashedAPIKey, field.TypeString, value)
}
if su.mutation.DehashedAPIKeyCleared() {
_spec.ClearField(settings.FieldDehashedAPIKey, field.TypeString)
}
if value, ok := su.mutation.Searches(); ok {
_spec.SetField(settings.FieldSearches, field.TypeUint64, value)
}
if value, ok := su.mutation.AddedSearches(); ok {
_spec.AddField(settings.FieldSearches, field.TypeUint64, value)
}
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{settings.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
su.mutation.done = true
return n, nil
}
// SettingsUpdateOne is the builder for updating a single Settings entity.
type SettingsUpdateOne struct {
config
fields []string
hooks []Hook
mutation *SettingsMutation
}
// SetHibpAPIKey sets the "hibp_api_key" field.
func (suo *SettingsUpdateOne) SetHibpAPIKey(s string) *SettingsUpdateOne {
suo.mutation.SetHibpAPIKey(s)
return suo
}
// SetNillableHibpAPIKey sets the "hibp_api_key" field if the given value is not nil.
func (suo *SettingsUpdateOne) SetNillableHibpAPIKey(s *string) *SettingsUpdateOne {
if s != nil {
suo.SetHibpAPIKey(*s)
}
return suo
}
// ClearHibpAPIKey clears the value of the "hibp_api_key" field.
func (suo *SettingsUpdateOne) ClearHibpAPIKey() *SettingsUpdateOne {
suo.mutation.ClearHibpAPIKey()
return suo
}
// SetDehashedAPIKey sets the "dehashed_api_key" field.
func (suo *SettingsUpdateOne) SetDehashedAPIKey(s string) *SettingsUpdateOne {
suo.mutation.SetDehashedAPIKey(s)
return suo
}
// SetNillableDehashedAPIKey sets the "dehashed_api_key" field if the given value is not nil.
func (suo *SettingsUpdateOne) SetNillableDehashedAPIKey(s *string) *SettingsUpdateOne {
if s != nil {
suo.SetDehashedAPIKey(*s)
}
return suo
}
// ClearDehashedAPIKey clears the value of the "dehashed_api_key" field.
func (suo *SettingsUpdateOne) ClearDehashedAPIKey() *SettingsUpdateOne {
suo.mutation.ClearDehashedAPIKey()
return suo
}
// SetSearches sets the "searches" field.
func (suo *SettingsUpdateOne) SetSearches(u uint64) *SettingsUpdateOne {
suo.mutation.ResetSearches()
suo.mutation.SetSearches(u)
return suo
}
// SetNillableSearches sets the "searches" field if the given value is not nil.
func (suo *SettingsUpdateOne) SetNillableSearches(u *uint64) *SettingsUpdateOne {
if u != nil {
suo.SetSearches(*u)
}
return suo
}
// AddSearches adds u to the "searches" field.
func (suo *SettingsUpdateOne) AddSearches(u int64) *SettingsUpdateOne {
suo.mutation.AddSearches(u)
return suo
}
// Mutation returns the SettingsMutation object of the builder.
func (suo *SettingsUpdateOne) Mutation() *SettingsMutation {
return suo.mutation
}
// Where appends a list predicates to the SettingsUpdate builder.
func (suo *SettingsUpdateOne) Where(ps ...predicate.Settings) *SettingsUpdateOne {
suo.mutation.Where(ps...)
return suo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (suo *SettingsUpdateOne) Select(field string, fields ...string) *SettingsUpdateOne {
suo.fields = append([]string{field}, fields...)
return suo
}
// Save executes the query and returns the updated Settings entity.
func (suo *SettingsUpdateOne) Save(ctx context.Context) (*Settings, error) {
return withHooks(ctx, suo.sqlSave, suo.mutation, suo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (suo *SettingsUpdateOne) SaveX(ctx context.Context) *Settings {
node, err := suo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (suo *SettingsUpdateOne) Exec(ctx context.Context) error {
_, err := suo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (suo *SettingsUpdateOne) ExecX(ctx context.Context) {
if err := suo.Exec(ctx); err != nil {
panic(err)
}
}
func (suo *SettingsUpdateOne) sqlSave(ctx context.Context) (_node *Settings, err error) {
_spec := sqlgraph.NewUpdateSpec(settings.Table, settings.Columns, sqlgraph.NewFieldSpec(settings.FieldID, field.TypeUUID))
id, ok := suo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Settings.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := suo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, settings.FieldID)
for _, f := range fields {
if !settings.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != settings.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := suo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := suo.mutation.HibpAPIKey(); ok {
_spec.SetField(settings.FieldHibpAPIKey, field.TypeString, value)
}
if suo.mutation.HibpAPIKeyCleared() {
_spec.ClearField(settings.FieldHibpAPIKey, field.TypeString)
}
if value, ok := suo.mutation.DehashedAPIKey(); ok {
_spec.SetField(settings.FieldDehashedAPIKey, field.TypeString, value)
}
if suo.mutation.DehashedAPIKeyCleared() {
_spec.ClearField(settings.FieldDehashedAPIKey, field.TypeString)
}
if value, ok := suo.mutation.Searches(); ok {
_spec.SetField(settings.FieldSearches, field.TypeUint64, value)
}
if value, ok := suo.mutation.AddedSearches(); ok {
_spec.AddField(settings.FieldSearches, field.TypeUint64, value)
}
_node = &Settings{config: suo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{settings.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
suo.mutation.done = true
return _node, nil
}