// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "code.icod.de/postfix/manager/ent/account" "code.icod.de/postfix/manager/ent/domain" "code.icod.de/postfix/manager/ent/logentry" "code.icod.de/postfix/manager/ent/predicate" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // AccountUpdate is the builder for updating Account entities. type AccountUpdate struct { config hooks []Hook mutation *AccountMutation } // Where appends a list predicates to the AccountUpdate builder. func (au *AccountUpdate) Where(ps ...predicate.Account) *AccountUpdate { au.mutation.Where(ps...) return au } // SetModified sets the "modified" field. func (au *AccountUpdate) SetModified(t time.Time) *AccountUpdate { au.mutation.SetModified(t) return au } // ClearModified clears the value of the "modified" field. func (au *AccountUpdate) ClearModified() *AccountUpdate { au.mutation.ClearModified() return au } // SetUsername sets the "username" field. func (au *AccountUpdate) SetUsername(s string) *AccountUpdate { au.mutation.SetUsername(s) return au } // SetNillableUsername sets the "username" field if the given value is not nil. func (au *AccountUpdate) SetNillableUsername(s *string) *AccountUpdate { if s != nil { au.SetUsername(*s) } return au } // SetPassword sets the "password" field. func (au *AccountUpdate) SetPassword(b []byte) *AccountUpdate { au.mutation.SetPassword(b) return au } // SetSuper sets the "super" field. func (au *AccountUpdate) SetSuper(b bool) *AccountUpdate { au.mutation.SetSuper(b) return au } // SetNillableSuper sets the "super" field if the given value is not nil. func (au *AccountUpdate) SetNillableSuper(b *bool) *AccountUpdate { if b != nil { au.SetSuper(*b) } return au } // SetActive sets the "active" field. func (au *AccountUpdate) SetActive(b bool) *AccountUpdate { au.mutation.SetActive(b) return au } // SetNillableActive sets the "active" field if the given value is not nil. func (au *AccountUpdate) SetNillableActive(b *bool) *AccountUpdate { if b != nil { au.SetActive(*b) } return au } // AddDomainIDs adds the "domains" edge to the Domain entity by IDs. func (au *AccountUpdate) AddDomainIDs(ids ...int64) *AccountUpdate { au.mutation.AddDomainIDs(ids...) return au } // AddDomains adds the "domains" edges to the Domain entity. func (au *AccountUpdate) AddDomains(d ...*Domain) *AccountUpdate { ids := make([]int64, len(d)) for i := range d { ids[i] = d[i].ID } return au.AddDomainIDs(ids...) } // AddLogIDs adds the "logs" edge to the Logentry entity by IDs. func (au *AccountUpdate) AddLogIDs(ids ...int64) *AccountUpdate { au.mutation.AddLogIDs(ids...) return au } // AddLogs adds the "logs" edges to the Logentry entity. func (au *AccountUpdate) AddLogs(l ...*Logentry) *AccountUpdate { ids := make([]int64, len(l)) for i := range l { ids[i] = l[i].ID } return au.AddLogIDs(ids...) } // Mutation returns the AccountMutation object of the builder. func (au *AccountUpdate) Mutation() *AccountMutation { return au.mutation } // ClearDomains clears all "domains" edges to the Domain entity. func (au *AccountUpdate) ClearDomains() *AccountUpdate { au.mutation.ClearDomains() return au } // RemoveDomainIDs removes the "domains" edge to Domain entities by IDs. func (au *AccountUpdate) RemoveDomainIDs(ids ...int64) *AccountUpdate { au.mutation.RemoveDomainIDs(ids...) return au } // RemoveDomains removes "domains" edges to Domain entities. func (au *AccountUpdate) RemoveDomains(d ...*Domain) *AccountUpdate { ids := make([]int64, len(d)) for i := range d { ids[i] = d[i].ID } return au.RemoveDomainIDs(ids...) } // ClearLogs clears all "logs" edges to the Logentry entity. func (au *AccountUpdate) ClearLogs() *AccountUpdate { au.mutation.ClearLogs() return au } // RemoveLogIDs removes the "logs" edge to Logentry entities by IDs. func (au *AccountUpdate) RemoveLogIDs(ids ...int64) *AccountUpdate { au.mutation.RemoveLogIDs(ids...) return au } // RemoveLogs removes "logs" edges to Logentry entities. func (au *AccountUpdate) RemoveLogs(l ...*Logentry) *AccountUpdate { ids := make([]int64, len(l)) for i := range l { ids[i] = l[i].ID } return au.RemoveLogIDs(ids...) } // Save executes the query and returns the number of nodes affected by the update operation. func (au *AccountUpdate) 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 *AccountUpdate) SaveX(ctx context.Context) int { affected, err := au.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (au *AccountUpdate) Exec(ctx context.Context) error { _, err := au.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (au *AccountUpdate) 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 *AccountUpdate) defaults() { if _, ok := au.mutation.Modified(); !ok && !au.mutation.ModifiedCleared() { v := account.UpdateDefaultModified() au.mutation.SetModified(v) } } func (au *AccountUpdate) sqlSave(ctx context.Context) (n int, err error) { _spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64)) 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.Modified(); ok { _spec.SetField(account.FieldModified, field.TypeTime, value) } if au.mutation.ModifiedCleared() { _spec.ClearField(account.FieldModified, field.TypeTime) } if value, ok := au.mutation.Username(); ok { _spec.SetField(account.FieldUsername, field.TypeString, value) } if value, ok := au.mutation.Password(); ok { _spec.SetField(account.FieldPassword, field.TypeBytes, value) } if value, ok := au.mutation.Super(); ok { _spec.SetField(account.FieldSuper, field.TypeBool, value) } if value, ok := au.mutation.Active(); ok { _spec.SetField(account.FieldActive, field.TypeBool, value) } if au.mutation.DomainsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: account.DomainsTable, Columns: account.DomainsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(domain.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := au.mutation.RemovedDomainsIDs(); len(nodes) > 0 && !au.mutation.DomainsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: account.DomainsTable, Columns: account.DomainsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(domain.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := au.mutation.DomainsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: account.DomainsTable, Columns: account.DomainsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(domain.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if au.mutation.LogsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: account.LogsTable, Columns: []string{account.LogsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(logentry.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := au.mutation.RemovedLogsIDs(); len(nodes) > 0 && !au.mutation.LogsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: account.LogsTable, Columns: []string{account.LogsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(logentry.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := au.mutation.LogsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: account.LogsTable, Columns: []string{account.LogsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(logentry.FieldID, field.TypeInt64), }, } 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{account.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } au.mutation.done = true return n, nil } // AccountUpdateOne is the builder for updating a single Account entity. type AccountUpdateOne struct { config fields []string hooks []Hook mutation *AccountMutation } // SetModified sets the "modified" field. func (auo *AccountUpdateOne) SetModified(t time.Time) *AccountUpdateOne { auo.mutation.SetModified(t) return auo } // ClearModified clears the value of the "modified" field. func (auo *AccountUpdateOne) ClearModified() *AccountUpdateOne { auo.mutation.ClearModified() return auo } // SetUsername sets the "username" field. func (auo *AccountUpdateOne) SetUsername(s string) *AccountUpdateOne { auo.mutation.SetUsername(s) return auo } // SetNillableUsername sets the "username" field if the given value is not nil. func (auo *AccountUpdateOne) SetNillableUsername(s *string) *AccountUpdateOne { if s != nil { auo.SetUsername(*s) } return auo } // SetPassword sets the "password" field. func (auo *AccountUpdateOne) SetPassword(b []byte) *AccountUpdateOne { auo.mutation.SetPassword(b) return auo } // SetSuper sets the "super" field. func (auo *AccountUpdateOne) SetSuper(b bool) *AccountUpdateOne { auo.mutation.SetSuper(b) return auo } // SetNillableSuper sets the "super" field if the given value is not nil. func (auo *AccountUpdateOne) SetNillableSuper(b *bool) *AccountUpdateOne { if b != nil { auo.SetSuper(*b) } return auo } // SetActive sets the "active" field. func (auo *AccountUpdateOne) SetActive(b bool) *AccountUpdateOne { auo.mutation.SetActive(b) return auo } // SetNillableActive sets the "active" field if the given value is not nil. func (auo *AccountUpdateOne) SetNillableActive(b *bool) *AccountUpdateOne { if b != nil { auo.SetActive(*b) } return auo } // AddDomainIDs adds the "domains" edge to the Domain entity by IDs. func (auo *AccountUpdateOne) AddDomainIDs(ids ...int64) *AccountUpdateOne { auo.mutation.AddDomainIDs(ids...) return auo } // AddDomains adds the "domains" edges to the Domain entity. func (auo *AccountUpdateOne) AddDomains(d ...*Domain) *AccountUpdateOne { ids := make([]int64, len(d)) for i := range d { ids[i] = d[i].ID } return auo.AddDomainIDs(ids...) } // AddLogIDs adds the "logs" edge to the Logentry entity by IDs. func (auo *AccountUpdateOne) AddLogIDs(ids ...int64) *AccountUpdateOne { auo.mutation.AddLogIDs(ids...) return auo } // AddLogs adds the "logs" edges to the Logentry entity. func (auo *AccountUpdateOne) AddLogs(l ...*Logentry) *AccountUpdateOne { ids := make([]int64, len(l)) for i := range l { ids[i] = l[i].ID } return auo.AddLogIDs(ids...) } // Mutation returns the AccountMutation object of the builder. func (auo *AccountUpdateOne) Mutation() *AccountMutation { return auo.mutation } // ClearDomains clears all "domains" edges to the Domain entity. func (auo *AccountUpdateOne) ClearDomains() *AccountUpdateOne { auo.mutation.ClearDomains() return auo } // RemoveDomainIDs removes the "domains" edge to Domain entities by IDs. func (auo *AccountUpdateOne) RemoveDomainIDs(ids ...int64) *AccountUpdateOne { auo.mutation.RemoveDomainIDs(ids...) return auo } // RemoveDomains removes "domains" edges to Domain entities. func (auo *AccountUpdateOne) RemoveDomains(d ...*Domain) *AccountUpdateOne { ids := make([]int64, len(d)) for i := range d { ids[i] = d[i].ID } return auo.RemoveDomainIDs(ids...) } // ClearLogs clears all "logs" edges to the Logentry entity. func (auo *AccountUpdateOne) ClearLogs() *AccountUpdateOne { auo.mutation.ClearLogs() return auo } // RemoveLogIDs removes the "logs" edge to Logentry entities by IDs. func (auo *AccountUpdateOne) RemoveLogIDs(ids ...int64) *AccountUpdateOne { auo.mutation.RemoveLogIDs(ids...) return auo } // RemoveLogs removes "logs" edges to Logentry entities. func (auo *AccountUpdateOne) RemoveLogs(l ...*Logentry) *AccountUpdateOne { ids := make([]int64, len(l)) for i := range l { ids[i] = l[i].ID } return auo.RemoveLogIDs(ids...) } // Where appends a list predicates to the AccountUpdate builder. func (auo *AccountUpdateOne) Where(ps ...predicate.Account) *AccountUpdateOne { 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 *AccountUpdateOne) Select(field string, fields ...string) *AccountUpdateOne { auo.fields = append([]string{field}, fields...) return auo } // Save executes the query and returns the updated Account entity. func (auo *AccountUpdateOne) Save(ctx context.Context) (*Account, error) { auo.defaults() return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks) } // SaveX is like Save, but panics if an error occurs. func (auo *AccountUpdateOne) SaveX(ctx context.Context) *Account { node, err := auo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (auo *AccountUpdateOne) Exec(ctx context.Context) error { _, err := auo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (auo *AccountUpdateOne) 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 *AccountUpdateOne) defaults() { if _, ok := auo.mutation.Modified(); !ok && !auo.mutation.ModifiedCleared() { v := account.UpdateDefaultModified() auo.mutation.SetModified(v) } } func (auo *AccountUpdateOne) sqlSave(ctx context.Context) (_node *Account, err error) { _spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64)) id, ok := auo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Account.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, account.FieldID) for _, f := range fields { if !account.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != account.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.Modified(); ok { _spec.SetField(account.FieldModified, field.TypeTime, value) } if auo.mutation.ModifiedCleared() { _spec.ClearField(account.FieldModified, field.TypeTime) } if value, ok := auo.mutation.Username(); ok { _spec.SetField(account.FieldUsername, field.TypeString, value) } if value, ok := auo.mutation.Password(); ok { _spec.SetField(account.FieldPassword, field.TypeBytes, value) } if value, ok := auo.mutation.Super(); ok { _spec.SetField(account.FieldSuper, field.TypeBool, value) } if value, ok := auo.mutation.Active(); ok { _spec.SetField(account.FieldActive, field.TypeBool, value) } if auo.mutation.DomainsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: account.DomainsTable, Columns: account.DomainsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(domain.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := auo.mutation.RemovedDomainsIDs(); len(nodes) > 0 && !auo.mutation.DomainsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: account.DomainsTable, Columns: account.DomainsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(domain.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := auo.mutation.DomainsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: account.DomainsTable, Columns: account.DomainsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(domain.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if auo.mutation.LogsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: account.LogsTable, Columns: []string{account.LogsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(logentry.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := auo.mutation.RemovedLogsIDs(); len(nodes) > 0 && !auo.mutation.LogsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: account.LogsTable, Columns: []string{account.LogsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(logentry.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := auo.mutation.LogsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: account.LogsTable, Columns: []string{account.LogsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(logentry.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _node = &Account{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{account.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } auo.mutation.done = true return _node, nil }