561 lines
16 KiB
Go
561 lines
16 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"code.icod.de/auth/accountserver/ent/account"
|
|
"code.icod.de/auth/accountserver/ent/email"
|
|
"code.icod.de/auth/accountserver/ent/predicate"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// 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
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (au *AccountUpdate) SetUpdatedAt(t time.Time) *AccountUpdate {
|
|
au.mutation.SetUpdatedAt(t)
|
|
return au
|
|
}
|
|
|
|
// SetNickname sets the "nickname" field.
|
|
func (au *AccountUpdate) SetNickname(s string) *AccountUpdate {
|
|
au.mutation.SetNickname(s)
|
|
return au
|
|
}
|
|
|
|
// SetNillableNickname sets the "nickname" field if the given value is not nil.
|
|
func (au *AccountUpdate) SetNillableNickname(s *string) *AccountUpdate {
|
|
if s != nil {
|
|
au.SetNickname(*s)
|
|
}
|
|
return au
|
|
}
|
|
|
|
// ClearNickname clears the value of the "nickname" field.
|
|
func (au *AccountUpdate) ClearNickname() *AccountUpdate {
|
|
au.mutation.ClearNickname()
|
|
return au
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (au *AccountUpdate) SetName(s string) *AccountUpdate {
|
|
au.mutation.SetName(s)
|
|
return au
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (au *AccountUpdate) SetNillableName(s *string) *AccountUpdate {
|
|
if s != nil {
|
|
au.SetName(*s)
|
|
}
|
|
return au
|
|
}
|
|
|
|
// ClearName clears the value of the "name" field.
|
|
func (au *AccountUpdate) ClearName() *AccountUpdate {
|
|
au.mutation.ClearName()
|
|
return au
|
|
}
|
|
|
|
// SetSecret sets the "secret" field.
|
|
func (au *AccountUpdate) SetSecret(b []byte) *AccountUpdate {
|
|
au.mutation.SetSecret(b)
|
|
return au
|
|
}
|
|
|
|
// SetAes sets the "aes" field.
|
|
func (au *AccountUpdate) SetAes(b []byte) *AccountUpdate {
|
|
au.mutation.SetAes(b)
|
|
return au
|
|
}
|
|
|
|
// SetX509 sets the "x509" field.
|
|
func (au *AccountUpdate) SetX509(b []byte) *AccountUpdate {
|
|
au.mutation.SetX509(b)
|
|
return au
|
|
}
|
|
|
|
// AddEmailIDs adds the "emails" edge to the Email entity by IDs.
|
|
func (au *AccountUpdate) AddEmailIDs(ids ...uuid.UUID) *AccountUpdate {
|
|
au.mutation.AddEmailIDs(ids...)
|
|
return au
|
|
}
|
|
|
|
// AddEmails adds the "emails" edges to the Email entity.
|
|
func (au *AccountUpdate) AddEmails(e ...*Email) *AccountUpdate {
|
|
ids := make([]uuid.UUID, len(e))
|
|
for i := range e {
|
|
ids[i] = e[i].ID
|
|
}
|
|
return au.AddEmailIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the AccountMutation object of the builder.
|
|
func (au *AccountUpdate) Mutation() *AccountMutation {
|
|
return au.mutation
|
|
}
|
|
|
|
// ClearEmails clears all "emails" edges to the Email entity.
|
|
func (au *AccountUpdate) ClearEmails() *AccountUpdate {
|
|
au.mutation.ClearEmails()
|
|
return au
|
|
}
|
|
|
|
// RemoveEmailIDs removes the "emails" edge to Email entities by IDs.
|
|
func (au *AccountUpdate) RemoveEmailIDs(ids ...uuid.UUID) *AccountUpdate {
|
|
au.mutation.RemoveEmailIDs(ids...)
|
|
return au
|
|
}
|
|
|
|
// RemoveEmails removes "emails" edges to Email entities.
|
|
func (au *AccountUpdate) RemoveEmails(e ...*Email) *AccountUpdate {
|
|
ids := make([]uuid.UUID, len(e))
|
|
for i := range e {
|
|
ids[i] = e[i].ID
|
|
}
|
|
return au.RemoveEmailIDs(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.UpdatedAt(); !ok {
|
|
v := account.UpdateDefaultUpdatedAt()
|
|
au.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (au *AccountUpdate) check() error {
|
|
if v, ok := au.mutation.Aes(); ok {
|
|
if err := account.AesValidator(v); err != nil {
|
|
return &ValidationError{Name: "aes", err: fmt.Errorf(`ent: validator failed for field "Account.aes": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (au *AccountUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
if err := au.check(); err != nil {
|
|
return n, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID))
|
|
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.UpdatedAt(); ok {
|
|
_spec.SetField(account.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := au.mutation.Nickname(); ok {
|
|
_spec.SetField(account.FieldNickname, field.TypeString, value)
|
|
}
|
|
if au.mutation.NicknameCleared() {
|
|
_spec.ClearField(account.FieldNickname, field.TypeString)
|
|
}
|
|
if value, ok := au.mutation.Name(); ok {
|
|
_spec.SetField(account.FieldName, field.TypeString, value)
|
|
}
|
|
if au.mutation.NameCleared() {
|
|
_spec.ClearField(account.FieldName, field.TypeString)
|
|
}
|
|
if value, ok := au.mutation.Secret(); ok {
|
|
_spec.SetField(account.FieldSecret, field.TypeBytes, value)
|
|
}
|
|
if value, ok := au.mutation.Aes(); ok {
|
|
_spec.SetField(account.FieldAes, field.TypeBytes, value)
|
|
}
|
|
if value, ok := au.mutation.X509(); ok {
|
|
_spec.SetField(account.FieldX509, field.TypeBytes, value)
|
|
}
|
|
if au.mutation.EmailsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: account.EmailsTable,
|
|
Columns: []string{account.EmailsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(email.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := au.mutation.RemovedEmailsIDs(); len(nodes) > 0 && !au.mutation.EmailsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: account.EmailsTable,
|
|
Columns: []string{account.EmailsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(email.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := au.mutation.EmailsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: account.EmailsTable,
|
|
Columns: []string{account.EmailsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(email.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
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
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (auo *AccountUpdateOne) SetUpdatedAt(t time.Time) *AccountUpdateOne {
|
|
auo.mutation.SetUpdatedAt(t)
|
|
return auo
|
|
}
|
|
|
|
// SetNickname sets the "nickname" field.
|
|
func (auo *AccountUpdateOne) SetNickname(s string) *AccountUpdateOne {
|
|
auo.mutation.SetNickname(s)
|
|
return auo
|
|
}
|
|
|
|
// SetNillableNickname sets the "nickname" field if the given value is not nil.
|
|
func (auo *AccountUpdateOne) SetNillableNickname(s *string) *AccountUpdateOne {
|
|
if s != nil {
|
|
auo.SetNickname(*s)
|
|
}
|
|
return auo
|
|
}
|
|
|
|
// ClearNickname clears the value of the "nickname" field.
|
|
func (auo *AccountUpdateOne) ClearNickname() *AccountUpdateOne {
|
|
auo.mutation.ClearNickname()
|
|
return auo
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (auo *AccountUpdateOne) SetName(s string) *AccountUpdateOne {
|
|
auo.mutation.SetName(s)
|
|
return auo
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (auo *AccountUpdateOne) SetNillableName(s *string) *AccountUpdateOne {
|
|
if s != nil {
|
|
auo.SetName(*s)
|
|
}
|
|
return auo
|
|
}
|
|
|
|
// ClearName clears the value of the "name" field.
|
|
func (auo *AccountUpdateOne) ClearName() *AccountUpdateOne {
|
|
auo.mutation.ClearName()
|
|
return auo
|
|
}
|
|
|
|
// SetSecret sets the "secret" field.
|
|
func (auo *AccountUpdateOne) SetSecret(b []byte) *AccountUpdateOne {
|
|
auo.mutation.SetSecret(b)
|
|
return auo
|
|
}
|
|
|
|
// SetAes sets the "aes" field.
|
|
func (auo *AccountUpdateOne) SetAes(b []byte) *AccountUpdateOne {
|
|
auo.mutation.SetAes(b)
|
|
return auo
|
|
}
|
|
|
|
// SetX509 sets the "x509" field.
|
|
func (auo *AccountUpdateOne) SetX509(b []byte) *AccountUpdateOne {
|
|
auo.mutation.SetX509(b)
|
|
return auo
|
|
}
|
|
|
|
// AddEmailIDs adds the "emails" edge to the Email entity by IDs.
|
|
func (auo *AccountUpdateOne) AddEmailIDs(ids ...uuid.UUID) *AccountUpdateOne {
|
|
auo.mutation.AddEmailIDs(ids...)
|
|
return auo
|
|
}
|
|
|
|
// AddEmails adds the "emails" edges to the Email entity.
|
|
func (auo *AccountUpdateOne) AddEmails(e ...*Email) *AccountUpdateOne {
|
|
ids := make([]uuid.UUID, len(e))
|
|
for i := range e {
|
|
ids[i] = e[i].ID
|
|
}
|
|
return auo.AddEmailIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the AccountMutation object of the builder.
|
|
func (auo *AccountUpdateOne) Mutation() *AccountMutation {
|
|
return auo.mutation
|
|
}
|
|
|
|
// ClearEmails clears all "emails" edges to the Email entity.
|
|
func (auo *AccountUpdateOne) ClearEmails() *AccountUpdateOne {
|
|
auo.mutation.ClearEmails()
|
|
return auo
|
|
}
|
|
|
|
// RemoveEmailIDs removes the "emails" edge to Email entities by IDs.
|
|
func (auo *AccountUpdateOne) RemoveEmailIDs(ids ...uuid.UUID) *AccountUpdateOne {
|
|
auo.mutation.RemoveEmailIDs(ids...)
|
|
return auo
|
|
}
|
|
|
|
// RemoveEmails removes "emails" edges to Email entities.
|
|
func (auo *AccountUpdateOne) RemoveEmails(e ...*Email) *AccountUpdateOne {
|
|
ids := make([]uuid.UUID, len(e))
|
|
for i := range e {
|
|
ids[i] = e[i].ID
|
|
}
|
|
return auo.RemoveEmailIDs(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.UpdatedAt(); !ok {
|
|
v := account.UpdateDefaultUpdatedAt()
|
|
auo.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (auo *AccountUpdateOne) check() error {
|
|
if v, ok := auo.mutation.Aes(); ok {
|
|
if err := account.AesValidator(v); err != nil {
|
|
return &ValidationError{Name: "aes", err: fmt.Errorf(`ent: validator failed for field "Account.aes": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (auo *AccountUpdateOne) sqlSave(ctx context.Context) (_node *Account, err error) {
|
|
if err := auo.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(account.Table, account.Columns, sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID))
|
|
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.UpdatedAt(); ok {
|
|
_spec.SetField(account.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := auo.mutation.Nickname(); ok {
|
|
_spec.SetField(account.FieldNickname, field.TypeString, value)
|
|
}
|
|
if auo.mutation.NicknameCleared() {
|
|
_spec.ClearField(account.FieldNickname, field.TypeString)
|
|
}
|
|
if value, ok := auo.mutation.Name(); ok {
|
|
_spec.SetField(account.FieldName, field.TypeString, value)
|
|
}
|
|
if auo.mutation.NameCleared() {
|
|
_spec.ClearField(account.FieldName, field.TypeString)
|
|
}
|
|
if value, ok := auo.mutation.Secret(); ok {
|
|
_spec.SetField(account.FieldSecret, field.TypeBytes, value)
|
|
}
|
|
if value, ok := auo.mutation.Aes(); ok {
|
|
_spec.SetField(account.FieldAes, field.TypeBytes, value)
|
|
}
|
|
if value, ok := auo.mutation.X509(); ok {
|
|
_spec.SetField(account.FieldX509, field.TypeBytes, value)
|
|
}
|
|
if auo.mutation.EmailsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: account.EmailsTable,
|
|
Columns: []string{account.EmailsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(email.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := auo.mutation.RemovedEmailsIDs(); len(nodes) > 0 && !auo.mutation.EmailsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: account.EmailsTable,
|
|
Columns: []string{account.EmailsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(email.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := auo.mutation.EmailsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: account.EmailsTable,
|
|
Columns: []string{account.EmailsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(email.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
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
|
|
}
|