// Code generated by entc, 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 } // 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 } // SetActive sets the "active" field. func (au *AccountUpdate) SetActive(b bool) *AccountUpdate { au.mutation.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) { var ( err error affected int ) au.defaults() if len(au.hooks) == 0 { affected, err = au.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*AccountMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } au.mutation = mutation affected, err = au.sqlSave(ctx) mutation.done = true return affected, err }) for i := len(au.hooks) - 1; i >= 0; i-- { if au.hooks[i] == nil { return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } mut = au.hooks[i](mut) } if _, err := mut.Mutate(ctx, au.mutation); err != nil { return 0, err } } return affected, err } // 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.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: account.Table, Columns: account.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt64, Column: account.FieldID, }, }, } 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.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, Value: value, Column: account.FieldModified, }) } if au.mutation.ModifiedCleared() { _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ Type: field.TypeTime, Column: account.FieldModified, }) } if value, ok := au.mutation.Username(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: account.FieldUsername, }) } if value, ok := au.mutation.Password(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBytes, Value: value, Column: account.FieldPassword, }) } if value, ok := au.mutation.Super(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: account.FieldSuper, }) } if value, ok := au.mutation.Active(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: account.FieldActive, }) } 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.FieldSpec{ Type: field.TypeInt64, Column: domain.FieldID, }, }, } _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.FieldSpec{ Type: field.TypeInt64, Column: domain.FieldID, }, }, } 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.FieldSpec{ Type: field.TypeInt64, Column: domain.FieldID, }, }, } 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.FieldSpec{ Type: field.TypeInt64, Column: logentry.FieldID, }, }, } _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.FieldSpec{ Type: field.TypeInt64, Column: logentry.FieldID, }, }, } 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.FieldSpec{ Type: field.TypeInt64, Column: logentry.FieldID, }, }, } 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{err.Error(), err} } return 0, err } 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 } // 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 } // SetActive sets the "active" field. func (auo *AccountUpdateOne) SetActive(b bool) *AccountUpdateOne { auo.mutation.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...) } // 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) { var ( err error node *Account ) auo.defaults() if len(auo.hooks) == 0 { node, err = auo.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*AccountMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } auo.mutation = mutation node, err = auo.sqlSave(ctx) mutation.done = true return node, err }) for i := len(auo.hooks) - 1; i >= 0; i-- { if auo.hooks[i] == nil { return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } mut = auo.hooks[i](mut) } if _, err := mut.Mutate(ctx, auo.mutation); err != nil { return nil, err } } return node, err } // 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.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: account.Table, Columns: account.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt64, Column: account.FieldID, }, }, } 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.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, Value: value, Column: account.FieldModified, }) } if auo.mutation.ModifiedCleared() { _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ Type: field.TypeTime, Column: account.FieldModified, }) } if value, ok := auo.mutation.Username(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: account.FieldUsername, }) } if value, ok := auo.mutation.Password(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBytes, Value: value, Column: account.FieldPassword, }) } if value, ok := auo.mutation.Super(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: account.FieldSuper, }) } if value, ok := auo.mutation.Active(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, Value: value, Column: account.FieldActive, }) } 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.FieldSpec{ Type: field.TypeInt64, Column: domain.FieldID, }, }, } _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.FieldSpec{ Type: field.TypeInt64, Column: domain.FieldID, }, }, } 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.FieldSpec{ Type: field.TypeInt64, Column: domain.FieldID, }, }, } 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.FieldSpec{ Type: field.TypeInt64, Column: logentry.FieldID, }, }, } _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.FieldSpec{ Type: field.TypeInt64, Column: logentry.FieldID, }, }, } 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.FieldSpec{ Type: field.TypeInt64, Column: logentry.FieldID, }, }, } 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{err.Error(), err} } return nil, err } return _node, nil }