Files
MonkeyCode/backend/db/user_update.go
2025-06-25 15:56:22 +08:00

888 lines
26 KiB
Go

// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/consts"
"github.com/chaitin/MonkeyCode/backend/db/model"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/record"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/chaitin/MonkeyCode/backend/db/userloginhistory"
"github.com/google/uuid"
)
// UserUpdate is the builder for updating User entities.
type UserUpdate struct {
config
hooks []Hook
mutation *UserMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the UserUpdate builder.
func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
uu.mutation.Where(ps...)
return uu
}
// SetUsername sets the "username" field.
func (uu *UserUpdate) SetUsername(s string) *UserUpdate {
uu.mutation.SetUsername(s)
return uu
}
// SetNillableUsername sets the "username" field if the given value is not nil.
func (uu *UserUpdate) SetNillableUsername(s *string) *UserUpdate {
if s != nil {
uu.SetUsername(*s)
}
return uu
}
// SetPassword sets the "password" field.
func (uu *UserUpdate) SetPassword(s string) *UserUpdate {
uu.mutation.SetPassword(s)
return uu
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (uu *UserUpdate) SetNillablePassword(s *string) *UserUpdate {
if s != nil {
uu.SetPassword(*s)
}
return uu
}
// SetEmail sets the "email" field.
func (uu *UserUpdate) SetEmail(s string) *UserUpdate {
uu.mutation.SetEmail(s)
return uu
}
// SetNillableEmail sets the "email" field if the given value is not nil.
func (uu *UserUpdate) SetNillableEmail(s *string) *UserUpdate {
if s != nil {
uu.SetEmail(*s)
}
return uu
}
// SetStatus sets the "status" field.
func (uu *UserUpdate) SetStatus(cs consts.UserStatus) *UserUpdate {
uu.mutation.SetStatus(cs)
return uu
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (uu *UserUpdate) SetNillableStatus(cs *consts.UserStatus) *UserUpdate {
if cs != nil {
uu.SetStatus(*cs)
}
return uu
}
// SetCreatedAt sets the "created_at" field.
func (uu *UserUpdate) SetCreatedAt(t time.Time) *UserUpdate {
uu.mutation.SetCreatedAt(t)
return uu
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (uu *UserUpdate) SetNillableCreatedAt(t *time.Time) *UserUpdate {
if t != nil {
uu.SetCreatedAt(*t)
}
return uu
}
// SetUpdatedAt sets the "updated_at" field.
func (uu *UserUpdate) SetUpdatedAt(t time.Time) *UserUpdate {
uu.mutation.SetUpdatedAt(t)
return uu
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (uu *UserUpdate) SetNillableUpdatedAt(t *time.Time) *UserUpdate {
if t != nil {
uu.SetUpdatedAt(*t)
}
return uu
}
// AddRecordIDs adds the "records" edge to the Record entity by IDs.
func (uu *UserUpdate) AddRecordIDs(ids ...uuid.UUID) *UserUpdate {
uu.mutation.AddRecordIDs(ids...)
return uu
}
// AddRecords adds the "records" edges to the Record entity.
func (uu *UserUpdate) AddRecords(r ...*Record) *UserUpdate {
ids := make([]uuid.UUID, len(r))
for i := range r {
ids[i] = r[i].ID
}
return uu.AddRecordIDs(ids...)
}
// AddLoginHistoryIDs adds the "login_histories" edge to the UserLoginHistory entity by IDs.
func (uu *UserUpdate) AddLoginHistoryIDs(ids ...uuid.UUID) *UserUpdate {
uu.mutation.AddLoginHistoryIDs(ids...)
return uu
}
// AddLoginHistories adds the "login_histories" edges to the UserLoginHistory entity.
func (uu *UserUpdate) AddLoginHistories(u ...*UserLoginHistory) *UserUpdate {
ids := make([]uuid.UUID, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.AddLoginHistoryIDs(ids...)
}
// AddModelIDs adds the "models" edge to the Model entity by IDs.
func (uu *UserUpdate) AddModelIDs(ids ...uuid.UUID) *UserUpdate {
uu.mutation.AddModelIDs(ids...)
return uu
}
// AddModels adds the "models" edges to the Model entity.
func (uu *UserUpdate) AddModels(m ...*Model) *UserUpdate {
ids := make([]uuid.UUID, len(m))
for i := range m {
ids[i] = m[i].ID
}
return uu.AddModelIDs(ids...)
}
// Mutation returns the UserMutation object of the builder.
func (uu *UserUpdate) Mutation() *UserMutation {
return uu.mutation
}
// ClearRecords clears all "records" edges to the Record entity.
func (uu *UserUpdate) ClearRecords() *UserUpdate {
uu.mutation.ClearRecords()
return uu
}
// RemoveRecordIDs removes the "records" edge to Record entities by IDs.
func (uu *UserUpdate) RemoveRecordIDs(ids ...uuid.UUID) *UserUpdate {
uu.mutation.RemoveRecordIDs(ids...)
return uu
}
// RemoveRecords removes "records" edges to Record entities.
func (uu *UserUpdate) RemoveRecords(r ...*Record) *UserUpdate {
ids := make([]uuid.UUID, len(r))
for i := range r {
ids[i] = r[i].ID
}
return uu.RemoveRecordIDs(ids...)
}
// ClearLoginHistories clears all "login_histories" edges to the UserLoginHistory entity.
func (uu *UserUpdate) ClearLoginHistories() *UserUpdate {
uu.mutation.ClearLoginHistories()
return uu
}
// RemoveLoginHistoryIDs removes the "login_histories" edge to UserLoginHistory entities by IDs.
func (uu *UserUpdate) RemoveLoginHistoryIDs(ids ...uuid.UUID) *UserUpdate {
uu.mutation.RemoveLoginHistoryIDs(ids...)
return uu
}
// RemoveLoginHistories removes "login_histories" edges to UserLoginHistory entities.
func (uu *UserUpdate) RemoveLoginHistories(u ...*UserLoginHistory) *UserUpdate {
ids := make([]uuid.UUID, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.RemoveLoginHistoryIDs(ids...)
}
// ClearModels clears all "models" edges to the Model entity.
func (uu *UserUpdate) ClearModels() *UserUpdate {
uu.mutation.ClearModels()
return uu
}
// RemoveModelIDs removes the "models" edge to Model entities by IDs.
func (uu *UserUpdate) RemoveModelIDs(ids ...uuid.UUID) *UserUpdate {
uu.mutation.RemoveModelIDs(ids...)
return uu
}
// RemoveModels removes "models" edges to Model entities.
func (uu *UserUpdate) RemoveModels(m ...*Model) *UserUpdate {
ids := make([]uuid.UUID, len(m))
for i := range m {
ids[i] = m[i].ID
}
return uu.RemoveModelIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (uu *UserUpdate) SaveX(ctx context.Context) int {
affected, err := uu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (uu *UserUpdate) Exec(ctx context.Context) error {
_, err := uu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (uu *UserUpdate) ExecX(ctx context.Context) {
if err := uu.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (uu *UserUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserUpdate {
uu.modifiers = append(uu.modifiers, modifiers...)
return uu
}
func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID))
if ps := uu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := uu.mutation.Username(); ok {
_spec.SetField(user.FieldUsername, field.TypeString, value)
}
if value, ok := uu.mutation.Password(); ok {
_spec.SetField(user.FieldPassword, field.TypeString, value)
}
if value, ok := uu.mutation.Email(); ok {
_spec.SetField(user.FieldEmail, field.TypeString, value)
}
if value, ok := uu.mutation.Status(); ok {
_spec.SetField(user.FieldStatus, field.TypeString, value)
}
if value, ok := uu.mutation.CreatedAt(); ok {
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := uu.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
if uu.mutation.RecordsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.RecordsTable,
Columns: []string{user.RecordsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(record.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uu.mutation.RemovedRecordsIDs(); len(nodes) > 0 && !uu.mutation.RecordsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.RecordsTable,
Columns: []string{user.RecordsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(record.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 := uu.mutation.RecordsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.RecordsTable,
Columns: []string{user.RecordsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(record.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if uu.mutation.LoginHistoriesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.LoginHistoriesTable,
Columns: []string{user.LoginHistoriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(userloginhistory.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uu.mutation.RemovedLoginHistoriesIDs(); len(nodes) > 0 && !uu.mutation.LoginHistoriesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.LoginHistoriesTable,
Columns: []string{user.LoginHistoriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(userloginhistory.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 := uu.mutation.LoginHistoriesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.LoginHistoriesTable,
Columns: []string{user.LoginHistoriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(userloginhistory.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if uu.mutation.ModelsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.ModelsTable,
Columns: []string{user.ModelsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uu.mutation.RemovedModelsIDs(); len(nodes) > 0 && !uu.mutation.ModelsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.ModelsTable,
Columns: []string{user.ModelsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(model.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 := uu.mutation.ModelsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.ModelsTable,
Columns: []string{user.ModelsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(uu.modifiers...)
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
uu.mutation.done = true
return n, nil
}
// UserUpdateOne is the builder for updating a single User entity.
type UserUpdateOne struct {
config
fields []string
hooks []Hook
mutation *UserMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetUsername sets the "username" field.
func (uuo *UserUpdateOne) SetUsername(s string) *UserUpdateOne {
uuo.mutation.SetUsername(s)
return uuo
}
// SetNillableUsername sets the "username" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableUsername(s *string) *UserUpdateOne {
if s != nil {
uuo.SetUsername(*s)
}
return uuo
}
// SetPassword sets the "password" field.
func (uuo *UserUpdateOne) SetPassword(s string) *UserUpdateOne {
uuo.mutation.SetPassword(s)
return uuo
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillablePassword(s *string) *UserUpdateOne {
if s != nil {
uuo.SetPassword(*s)
}
return uuo
}
// SetEmail sets the "email" field.
func (uuo *UserUpdateOne) SetEmail(s string) *UserUpdateOne {
uuo.mutation.SetEmail(s)
return uuo
}
// SetNillableEmail sets the "email" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableEmail(s *string) *UserUpdateOne {
if s != nil {
uuo.SetEmail(*s)
}
return uuo
}
// SetStatus sets the "status" field.
func (uuo *UserUpdateOne) SetStatus(cs consts.UserStatus) *UserUpdateOne {
uuo.mutation.SetStatus(cs)
return uuo
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableStatus(cs *consts.UserStatus) *UserUpdateOne {
if cs != nil {
uuo.SetStatus(*cs)
}
return uuo
}
// SetCreatedAt sets the "created_at" field.
func (uuo *UserUpdateOne) SetCreatedAt(t time.Time) *UserUpdateOne {
uuo.mutation.SetCreatedAt(t)
return uuo
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableCreatedAt(t *time.Time) *UserUpdateOne {
if t != nil {
uuo.SetCreatedAt(*t)
}
return uuo
}
// SetUpdatedAt sets the "updated_at" field.
func (uuo *UserUpdateOne) SetUpdatedAt(t time.Time) *UserUpdateOne {
uuo.mutation.SetUpdatedAt(t)
return uuo
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableUpdatedAt(t *time.Time) *UserUpdateOne {
if t != nil {
uuo.SetUpdatedAt(*t)
}
return uuo
}
// AddRecordIDs adds the "records" edge to the Record entity by IDs.
func (uuo *UserUpdateOne) AddRecordIDs(ids ...uuid.UUID) *UserUpdateOne {
uuo.mutation.AddRecordIDs(ids...)
return uuo
}
// AddRecords adds the "records" edges to the Record entity.
func (uuo *UserUpdateOne) AddRecords(r ...*Record) *UserUpdateOne {
ids := make([]uuid.UUID, len(r))
for i := range r {
ids[i] = r[i].ID
}
return uuo.AddRecordIDs(ids...)
}
// AddLoginHistoryIDs adds the "login_histories" edge to the UserLoginHistory entity by IDs.
func (uuo *UserUpdateOne) AddLoginHistoryIDs(ids ...uuid.UUID) *UserUpdateOne {
uuo.mutation.AddLoginHistoryIDs(ids...)
return uuo
}
// AddLoginHistories adds the "login_histories" edges to the UserLoginHistory entity.
func (uuo *UserUpdateOne) AddLoginHistories(u ...*UserLoginHistory) *UserUpdateOne {
ids := make([]uuid.UUID, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.AddLoginHistoryIDs(ids...)
}
// AddModelIDs adds the "models" edge to the Model entity by IDs.
func (uuo *UserUpdateOne) AddModelIDs(ids ...uuid.UUID) *UserUpdateOne {
uuo.mutation.AddModelIDs(ids...)
return uuo
}
// AddModels adds the "models" edges to the Model entity.
func (uuo *UserUpdateOne) AddModels(m ...*Model) *UserUpdateOne {
ids := make([]uuid.UUID, len(m))
for i := range m {
ids[i] = m[i].ID
}
return uuo.AddModelIDs(ids...)
}
// Mutation returns the UserMutation object of the builder.
func (uuo *UserUpdateOne) Mutation() *UserMutation {
return uuo.mutation
}
// ClearRecords clears all "records" edges to the Record entity.
func (uuo *UserUpdateOne) ClearRecords() *UserUpdateOne {
uuo.mutation.ClearRecords()
return uuo
}
// RemoveRecordIDs removes the "records" edge to Record entities by IDs.
func (uuo *UserUpdateOne) RemoveRecordIDs(ids ...uuid.UUID) *UserUpdateOne {
uuo.mutation.RemoveRecordIDs(ids...)
return uuo
}
// RemoveRecords removes "records" edges to Record entities.
func (uuo *UserUpdateOne) RemoveRecords(r ...*Record) *UserUpdateOne {
ids := make([]uuid.UUID, len(r))
for i := range r {
ids[i] = r[i].ID
}
return uuo.RemoveRecordIDs(ids...)
}
// ClearLoginHistories clears all "login_histories" edges to the UserLoginHistory entity.
func (uuo *UserUpdateOne) ClearLoginHistories() *UserUpdateOne {
uuo.mutation.ClearLoginHistories()
return uuo
}
// RemoveLoginHistoryIDs removes the "login_histories" edge to UserLoginHistory entities by IDs.
func (uuo *UserUpdateOne) RemoveLoginHistoryIDs(ids ...uuid.UUID) *UserUpdateOne {
uuo.mutation.RemoveLoginHistoryIDs(ids...)
return uuo
}
// RemoveLoginHistories removes "login_histories" edges to UserLoginHistory entities.
func (uuo *UserUpdateOne) RemoveLoginHistories(u ...*UserLoginHistory) *UserUpdateOne {
ids := make([]uuid.UUID, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.RemoveLoginHistoryIDs(ids...)
}
// ClearModels clears all "models" edges to the Model entity.
func (uuo *UserUpdateOne) ClearModels() *UserUpdateOne {
uuo.mutation.ClearModels()
return uuo
}
// RemoveModelIDs removes the "models" edge to Model entities by IDs.
func (uuo *UserUpdateOne) RemoveModelIDs(ids ...uuid.UUID) *UserUpdateOne {
uuo.mutation.RemoveModelIDs(ids...)
return uuo
}
// RemoveModels removes "models" edges to Model entities.
func (uuo *UserUpdateOne) RemoveModels(m ...*Model) *UserUpdateOne {
ids := make([]uuid.UUID, len(m))
for i := range m {
ids[i] = m[i].ID
}
return uuo.RemoveModelIDs(ids...)
}
// Where appends a list predicates to the UserUpdate builder.
func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
uuo.mutation.Where(ps...)
return uuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
uuo.fields = append([]string{field}, fields...)
return uuo
}
// Save executes the query and returns the updated User entity.
func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User {
node, err := uuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (uuo *UserUpdateOne) Exec(ctx context.Context) error {
_, err := uuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (uuo *UserUpdateOne) ExecX(ctx context.Context) {
if err := uuo.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (uuo *UserUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserUpdateOne {
uuo.modifiers = append(uuo.modifiers, modifiers...)
return uuo
}
func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID))
id, ok := uuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "User.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := uuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
for _, f := range fields {
if !user.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != user.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := uuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := uuo.mutation.Username(); ok {
_spec.SetField(user.FieldUsername, field.TypeString, value)
}
if value, ok := uuo.mutation.Password(); ok {
_spec.SetField(user.FieldPassword, field.TypeString, value)
}
if value, ok := uuo.mutation.Email(); ok {
_spec.SetField(user.FieldEmail, field.TypeString, value)
}
if value, ok := uuo.mutation.Status(); ok {
_spec.SetField(user.FieldStatus, field.TypeString, value)
}
if value, ok := uuo.mutation.CreatedAt(); ok {
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := uuo.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
if uuo.mutation.RecordsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.RecordsTable,
Columns: []string{user.RecordsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(record.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uuo.mutation.RemovedRecordsIDs(); len(nodes) > 0 && !uuo.mutation.RecordsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.RecordsTable,
Columns: []string{user.RecordsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(record.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 := uuo.mutation.RecordsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.RecordsTable,
Columns: []string{user.RecordsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(record.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if uuo.mutation.LoginHistoriesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.LoginHistoriesTable,
Columns: []string{user.LoginHistoriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(userloginhistory.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uuo.mutation.RemovedLoginHistoriesIDs(); len(nodes) > 0 && !uuo.mutation.LoginHistoriesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.LoginHistoriesTable,
Columns: []string{user.LoginHistoriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(userloginhistory.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 := uuo.mutation.LoginHistoriesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.LoginHistoriesTable,
Columns: []string{user.LoginHistoriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(userloginhistory.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if uuo.mutation.ModelsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.ModelsTable,
Columns: []string{user.ModelsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uuo.mutation.RemovedModelsIDs(); len(nodes) > 0 && !uuo.mutation.ModelsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.ModelsTable,
Columns: []string{user.ModelsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(model.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 := uuo.mutation.ModelsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.ModelsTable,
Columns: []string{user.ModelsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(uuo.modifiers...)
_node = &User{config: uuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
uuo.mutation.done = true
return _node, nil
}