420 lines
11 KiB
Go
420 lines
11 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"code.icod.de/postfix/manager/ent/alias"
|
|
"code.icod.de/postfix/manager/ent/domain"
|
|
"code.icod.de/postfix/manager/ent/predicate"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// AliasUpdate is the builder for updating Alias entities.
|
|
type AliasUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *AliasMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AliasUpdate builder.
|
|
func (au *AliasUpdate) Where(ps ...predicate.Alias) *AliasUpdate {
|
|
au.mutation.Where(ps...)
|
|
return au
|
|
}
|
|
|
|
// SetModified sets the "modified" field.
|
|
func (au *AliasUpdate) SetModified(t time.Time) *AliasUpdate {
|
|
au.mutation.SetModified(t)
|
|
return au
|
|
}
|
|
|
|
// ClearModified clears the value of the "modified" field.
|
|
func (au *AliasUpdate) ClearModified() *AliasUpdate {
|
|
au.mutation.ClearModified()
|
|
return au
|
|
}
|
|
|
|
// SetDomainID sets the "domain_id" field.
|
|
func (au *AliasUpdate) SetDomainID(i int64) *AliasUpdate {
|
|
au.mutation.SetDomainID(i)
|
|
return au
|
|
}
|
|
|
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
|
func (au *AliasUpdate) SetNillableDomainID(i *int64) *AliasUpdate {
|
|
if i != nil {
|
|
au.SetDomainID(*i)
|
|
}
|
|
return au
|
|
}
|
|
|
|
// ClearDomainID clears the value of the "domain_id" field.
|
|
func (au *AliasUpdate) ClearDomainID() *AliasUpdate {
|
|
au.mutation.ClearDomainID()
|
|
return au
|
|
}
|
|
|
|
// SetGoto sets the "goto" field.
|
|
func (au *AliasUpdate) SetGoto(s string) *AliasUpdate {
|
|
au.mutation.SetGoto(s)
|
|
return au
|
|
}
|
|
|
|
// SetNillableGoto sets the "goto" field if the given value is not nil.
|
|
func (au *AliasUpdate) SetNillableGoto(s *string) *AliasUpdate {
|
|
if s != nil {
|
|
au.SetGoto(*s)
|
|
}
|
|
return au
|
|
}
|
|
|
|
// SetActive sets the "active" field.
|
|
func (au *AliasUpdate) SetActive(b bool) *AliasUpdate {
|
|
au.mutation.SetActive(b)
|
|
return au
|
|
}
|
|
|
|
// SetNillableActive sets the "active" field if the given value is not nil.
|
|
func (au *AliasUpdate) SetNillableActive(b *bool) *AliasUpdate {
|
|
if b != nil {
|
|
au.SetActive(*b)
|
|
}
|
|
return au
|
|
}
|
|
|
|
// SetDomain sets the "domain" edge to the Domain entity.
|
|
func (au *AliasUpdate) SetDomain(d *Domain) *AliasUpdate {
|
|
return au.SetDomainID(d.ID)
|
|
}
|
|
|
|
// Mutation returns the AliasMutation object of the builder.
|
|
func (au *AliasUpdate) Mutation() *AliasMutation {
|
|
return au.mutation
|
|
}
|
|
|
|
// ClearDomain clears the "domain" edge to the Domain entity.
|
|
func (au *AliasUpdate) ClearDomain() *AliasUpdate {
|
|
au.mutation.ClearDomain()
|
|
return au
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (au *AliasUpdate) 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 *AliasUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := au.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (au *AliasUpdate) Exec(ctx context.Context) error {
|
|
_, err := au.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (au *AliasUpdate) 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 *AliasUpdate) defaults() {
|
|
if _, ok := au.mutation.Modified(); !ok && !au.mutation.ModifiedCleared() {
|
|
v := alias.UpdateDefaultModified()
|
|
au.mutation.SetModified(v)
|
|
}
|
|
}
|
|
|
|
func (au *AliasUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(alias.Table, alias.Columns, sqlgraph.NewFieldSpec(alias.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(alias.FieldModified, field.TypeTime, value)
|
|
}
|
|
if au.mutation.ModifiedCleared() {
|
|
_spec.ClearField(alias.FieldModified, field.TypeTime)
|
|
}
|
|
if value, ok := au.mutation.Goto(); ok {
|
|
_spec.SetField(alias.FieldGoto, field.TypeString, value)
|
|
}
|
|
if value, ok := au.mutation.Active(); ok {
|
|
_spec.SetField(alias.FieldActive, field.TypeBool, value)
|
|
}
|
|
if au.mutation.DomainCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: alias.DomainTable,
|
|
Columns: []string{alias.DomainColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(domain.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := au.mutation.DomainIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: alias.DomainTable,
|
|
Columns: []string{alias.DomainColumn},
|
|
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 n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{alias.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
au.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// AliasUpdateOne is the builder for updating a single Alias entity.
|
|
type AliasUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *AliasMutation
|
|
}
|
|
|
|
// SetModified sets the "modified" field.
|
|
func (auo *AliasUpdateOne) SetModified(t time.Time) *AliasUpdateOne {
|
|
auo.mutation.SetModified(t)
|
|
return auo
|
|
}
|
|
|
|
// ClearModified clears the value of the "modified" field.
|
|
func (auo *AliasUpdateOne) ClearModified() *AliasUpdateOne {
|
|
auo.mutation.ClearModified()
|
|
return auo
|
|
}
|
|
|
|
// SetDomainID sets the "domain_id" field.
|
|
func (auo *AliasUpdateOne) SetDomainID(i int64) *AliasUpdateOne {
|
|
auo.mutation.SetDomainID(i)
|
|
return auo
|
|
}
|
|
|
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
|
func (auo *AliasUpdateOne) SetNillableDomainID(i *int64) *AliasUpdateOne {
|
|
if i != nil {
|
|
auo.SetDomainID(*i)
|
|
}
|
|
return auo
|
|
}
|
|
|
|
// ClearDomainID clears the value of the "domain_id" field.
|
|
func (auo *AliasUpdateOne) ClearDomainID() *AliasUpdateOne {
|
|
auo.mutation.ClearDomainID()
|
|
return auo
|
|
}
|
|
|
|
// SetGoto sets the "goto" field.
|
|
func (auo *AliasUpdateOne) SetGoto(s string) *AliasUpdateOne {
|
|
auo.mutation.SetGoto(s)
|
|
return auo
|
|
}
|
|
|
|
// SetNillableGoto sets the "goto" field if the given value is not nil.
|
|
func (auo *AliasUpdateOne) SetNillableGoto(s *string) *AliasUpdateOne {
|
|
if s != nil {
|
|
auo.SetGoto(*s)
|
|
}
|
|
return auo
|
|
}
|
|
|
|
// SetActive sets the "active" field.
|
|
func (auo *AliasUpdateOne) SetActive(b bool) *AliasUpdateOne {
|
|
auo.mutation.SetActive(b)
|
|
return auo
|
|
}
|
|
|
|
// SetNillableActive sets the "active" field if the given value is not nil.
|
|
func (auo *AliasUpdateOne) SetNillableActive(b *bool) *AliasUpdateOne {
|
|
if b != nil {
|
|
auo.SetActive(*b)
|
|
}
|
|
return auo
|
|
}
|
|
|
|
// SetDomain sets the "domain" edge to the Domain entity.
|
|
func (auo *AliasUpdateOne) SetDomain(d *Domain) *AliasUpdateOne {
|
|
return auo.SetDomainID(d.ID)
|
|
}
|
|
|
|
// Mutation returns the AliasMutation object of the builder.
|
|
func (auo *AliasUpdateOne) Mutation() *AliasMutation {
|
|
return auo.mutation
|
|
}
|
|
|
|
// ClearDomain clears the "domain" edge to the Domain entity.
|
|
func (auo *AliasUpdateOne) ClearDomain() *AliasUpdateOne {
|
|
auo.mutation.ClearDomain()
|
|
return auo
|
|
}
|
|
|
|
// Where appends a list predicates to the AliasUpdate builder.
|
|
func (auo *AliasUpdateOne) Where(ps ...predicate.Alias) *AliasUpdateOne {
|
|
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 *AliasUpdateOne) Select(field string, fields ...string) *AliasUpdateOne {
|
|
auo.fields = append([]string{field}, fields...)
|
|
return auo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Alias entity.
|
|
func (auo *AliasUpdateOne) Save(ctx context.Context) (*Alias, error) {
|
|
auo.defaults()
|
|
return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (auo *AliasUpdateOne) SaveX(ctx context.Context) *Alias {
|
|
node, err := auo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (auo *AliasUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := auo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (auo *AliasUpdateOne) 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 *AliasUpdateOne) defaults() {
|
|
if _, ok := auo.mutation.Modified(); !ok && !auo.mutation.ModifiedCleared() {
|
|
v := alias.UpdateDefaultModified()
|
|
auo.mutation.SetModified(v)
|
|
}
|
|
}
|
|
|
|
func (auo *AliasUpdateOne) sqlSave(ctx context.Context) (_node *Alias, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(alias.Table, alias.Columns, sqlgraph.NewFieldSpec(alias.FieldID, field.TypeInt64))
|
|
id, ok := auo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Alias.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, alias.FieldID)
|
|
for _, f := range fields {
|
|
if !alias.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != alias.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(alias.FieldModified, field.TypeTime, value)
|
|
}
|
|
if auo.mutation.ModifiedCleared() {
|
|
_spec.ClearField(alias.FieldModified, field.TypeTime)
|
|
}
|
|
if value, ok := auo.mutation.Goto(); ok {
|
|
_spec.SetField(alias.FieldGoto, field.TypeString, value)
|
|
}
|
|
if value, ok := auo.mutation.Active(); ok {
|
|
_spec.SetField(alias.FieldActive, field.TypeBool, value)
|
|
}
|
|
if auo.mutation.DomainCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: alias.DomainTable,
|
|
Columns: []string{alias.DomainColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(domain.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := auo.mutation.DomainIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: alias.DomainTable,
|
|
Columns: []string{alias.DomainColumn},
|
|
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)
|
|
}
|
|
_node = &Alias{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{alias.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
auo.mutation.done = true
|
|
return _node, nil
|
|
}
|