// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/loginrecord"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/user"
)

// LoginRecordUpdate is the builder for updating LoginRecord entities.
type LoginRecordUpdate struct {
	config
	hooks     []Hook
	mutation  *LoginRecordMutation
	modifiers []func(*sql.UpdateBuilder)
}

// Where appends a list predicates to the LoginRecordUpdate builder.
func (lru *LoginRecordUpdate) Where(ps ...predicate.LoginRecord) *LoginRecordUpdate {
	lru.mutation.Where(ps...)
	return lru
}

// SetUpdatedAt sets the "updated_at" field.
func (lru *LoginRecordUpdate) SetUpdatedAt(t time.Time) *LoginRecordUpdate {
	lru.mutation.SetUpdatedAt(t)
	return lru
}

// SetVersion sets the "version" field.
func (lru *LoginRecordUpdate) SetVersion(i int64) *LoginRecordUpdate {
	lru.mutation.ResetVersion()
	lru.mutation.SetVersion(i)
	return lru
}

// SetNillableVersion sets the "version" field if the given value is not nil.
func (lru *LoginRecordUpdate) SetNillableVersion(i *int64) *LoginRecordUpdate {
	if i != nil {
		lru.SetVersion(*i)
	}
	return lru
}

// AddVersion adds i to the "version" field.
func (lru *LoginRecordUpdate) AddVersion(i int64) *LoginRecordUpdate {
	lru.mutation.AddVersion(i)
	return lru
}

// SetUserID sets the "user_id" field.
func (lru *LoginRecordUpdate) SetUserID(i int64) *LoginRecordUpdate {
	lru.mutation.SetUserID(i)
	return lru
}

// SetLastLoginAt sets the "last_login_at" field.
func (lru *LoginRecordUpdate) SetLastLoginAt(t time.Time) *LoginRecordUpdate {
	lru.mutation.SetLastLoginAt(t)
	return lru
}

// SetNillableLastLoginAt sets the "last_login_at" field if the given value is not nil.
func (lru *LoginRecordUpdate) SetNillableLastLoginAt(t *time.Time) *LoginRecordUpdate {
	if t != nil {
		lru.SetLastLoginAt(*t)
	}
	return lru
}

// ClearLastLoginAt clears the value of the "last_login_at" field.
func (lru *LoginRecordUpdate) ClearLastLoginAt() *LoginRecordUpdate {
	lru.mutation.ClearLastLoginAt()
	return lru
}

// SetLastLoginIpv4 sets the "last_login_ipv4" field.
func (lru *LoginRecordUpdate) SetLastLoginIpv4(s string) *LoginRecordUpdate {
	lru.mutation.SetLastLoginIpv4(s)
	return lru
}

// SetNillableLastLoginIpv4 sets the "last_login_ipv4" field if the given value is not nil.
func (lru *LoginRecordUpdate) SetNillableLastLoginIpv4(s *string) *LoginRecordUpdate {
	if s != nil {
		lru.SetLastLoginIpv4(*s)
	}
	return lru
}

// ClearLastLoginIpv4 clears the value of the "last_login_ipv4" field.
func (lru *LoginRecordUpdate) ClearLastLoginIpv4() *LoginRecordUpdate {
	lru.mutation.ClearLastLoginIpv4()
	return lru
}

// SetLastLoginDevice sets the "last_login_device" field.
func (lru *LoginRecordUpdate) SetLastLoginDevice(s string) *LoginRecordUpdate {
	lru.mutation.SetLastLoginDevice(s)
	return lru
}

// SetNillableLastLoginDevice sets the "last_login_device" field if the given value is not nil.
func (lru *LoginRecordUpdate) SetNillableLastLoginDevice(s *string) *LoginRecordUpdate {
	if s != nil {
		lru.SetLastLoginDevice(*s)
	}
	return lru
}

// ClearLastLoginDevice clears the value of the "last_login_device" field.
func (lru *LoginRecordUpdate) ClearLastLoginDevice() *LoginRecordUpdate {
	lru.mutation.ClearLastLoginDevice()
	return lru
}

// SetLastLoginUA sets the "last_login_UA" field.
func (lru *LoginRecordUpdate) SetLastLoginUA(s string) *LoginRecordUpdate {
	lru.mutation.SetLastLoginUA(s)
	return lru
}

// SetNillableLastLoginUA sets the "last_login_UA" field if the given value is not nil.
func (lru *LoginRecordUpdate) SetNillableLastLoginUA(s *string) *LoginRecordUpdate {
	if s != nil {
		lru.SetLastLoginUA(*s)
	}
	return lru
}

// ClearLastLoginUA clears the value of the "last_login_UA" field.
func (lru *LoginRecordUpdate) ClearLastLoginUA() *LoginRecordUpdate {
	lru.mutation.ClearLastLoginUA()
	return lru
}

// SetLoginCount sets the "login_count" field.
func (lru *LoginRecordUpdate) SetLoginCount(u uint64) *LoginRecordUpdate {
	lru.mutation.ResetLoginCount()
	lru.mutation.SetLoginCount(u)
	return lru
}

// SetNillableLoginCount sets the "login_count" field if the given value is not nil.
func (lru *LoginRecordUpdate) SetNillableLoginCount(u *uint64) *LoginRecordUpdate {
	if u != nil {
		lru.SetLoginCount(*u)
	}
	return lru
}

// AddLoginCount adds u to the "login_count" field.
func (lru *LoginRecordUpdate) AddLoginCount(u int64) *LoginRecordUpdate {
	lru.mutation.AddLoginCount(u)
	return lru
}

// SetUser sets the "user" edge to the User entity.
func (lru *LoginRecordUpdate) SetUser(u *User) *LoginRecordUpdate {
	return lru.SetUserID(u.ID)
}

// Mutation returns the LoginRecordMutation object of the builder.
func (lru *LoginRecordUpdate) Mutation() *LoginRecordMutation {
	return lru.mutation
}

// ClearUser clears the "user" edge to the User entity.
func (lru *LoginRecordUpdate) ClearUser() *LoginRecordUpdate {
	lru.mutation.ClearUser()
	return lru
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (lru *LoginRecordUpdate) Save(ctx context.Context) (int, error) {
	if err := lru.defaults(); err != nil {
		return 0, err
	}
	return withHooks(ctx, lru.sqlSave, lru.mutation, lru.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (lru *LoginRecordUpdate) SaveX(ctx context.Context) int {
	affected, err := lru.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (lru *LoginRecordUpdate) Exec(ctx context.Context) error {
	_, err := lru.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (lru *LoginRecordUpdate) ExecX(ctx context.Context) {
	if err := lru.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (lru *LoginRecordUpdate) defaults() error {
	if _, ok := lru.mutation.UpdatedAt(); !ok {
		if loginrecord.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized loginrecord.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := loginrecord.UpdateDefaultUpdatedAt()
		lru.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (lru *LoginRecordUpdate) check() error {
	if _, ok := lru.mutation.UserID(); lru.mutation.UserCleared() && !ok {
		return errors.New(`ent: clearing a required unique edge "LoginRecord.user"`)
	}
	return nil
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (lru *LoginRecordUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *LoginRecordUpdate {
	lru.modifiers = append(lru.modifiers, modifiers...)
	return lru
}

func (lru *LoginRecordUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := lru.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(loginrecord.Table, loginrecord.Columns, sqlgraph.NewFieldSpec(loginrecord.FieldID, field.TypeInt64))
	if ps := lru.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := lru.mutation.UpdatedAt(); ok {
		_spec.SetField(loginrecord.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := lru.mutation.Version(); ok {
		_spec.SetField(loginrecord.FieldVersion, field.TypeInt64, value)
	}
	if value, ok := lru.mutation.AddedVersion(); ok {
		_spec.AddField(loginrecord.FieldVersion, field.TypeInt64, value)
	}
	if value, ok := lru.mutation.LastLoginAt(); ok {
		_spec.SetField(loginrecord.FieldLastLoginAt, field.TypeTime, value)
	}
	if lru.mutation.LastLoginAtCleared() {
		_spec.ClearField(loginrecord.FieldLastLoginAt, field.TypeTime)
	}
	if value, ok := lru.mutation.LastLoginIpv4(); ok {
		_spec.SetField(loginrecord.FieldLastLoginIpv4, field.TypeString, value)
	}
	if lru.mutation.LastLoginIpv4Cleared() {
		_spec.ClearField(loginrecord.FieldLastLoginIpv4, field.TypeString)
	}
	if value, ok := lru.mutation.LastLoginDevice(); ok {
		_spec.SetField(loginrecord.FieldLastLoginDevice, field.TypeString, value)
	}
	if lru.mutation.LastLoginDeviceCleared() {
		_spec.ClearField(loginrecord.FieldLastLoginDevice, field.TypeString)
	}
	if value, ok := lru.mutation.LastLoginUA(); ok {
		_spec.SetField(loginrecord.FieldLastLoginUA, field.TypeString, value)
	}
	if lru.mutation.LastLoginUACleared() {
		_spec.ClearField(loginrecord.FieldLastLoginUA, field.TypeString)
	}
	if value, ok := lru.mutation.LoginCount(); ok {
		_spec.SetField(loginrecord.FieldLoginCount, field.TypeUint64, value)
	}
	if value, ok := lru.mutation.AddedLoginCount(); ok {
		_spec.AddField(loginrecord.FieldLoginCount, field.TypeUint64, value)
	}
	if lru.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   loginrecord.UserTable,
			Columns: []string{loginrecord.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := lru.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   loginrecord.UserTable,
			Columns: []string{loginrecord.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(lru.modifiers...)
	if n, err = sqlgraph.UpdateNodes(ctx, lru.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{loginrecord.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	lru.mutation.done = true
	return n, nil
}

// LoginRecordUpdateOne is the builder for updating a single LoginRecord entity.
type LoginRecordUpdateOne struct {
	config
	fields    []string
	hooks     []Hook
	mutation  *LoginRecordMutation
	modifiers []func(*sql.UpdateBuilder)
}

// SetUpdatedAt sets the "updated_at" field.
func (lruo *LoginRecordUpdateOne) SetUpdatedAt(t time.Time) *LoginRecordUpdateOne {
	lruo.mutation.SetUpdatedAt(t)
	return lruo
}

// SetVersion sets the "version" field.
func (lruo *LoginRecordUpdateOne) SetVersion(i int64) *LoginRecordUpdateOne {
	lruo.mutation.ResetVersion()
	lruo.mutation.SetVersion(i)
	return lruo
}

// SetNillableVersion sets the "version" field if the given value is not nil.
func (lruo *LoginRecordUpdateOne) SetNillableVersion(i *int64) *LoginRecordUpdateOne {
	if i != nil {
		lruo.SetVersion(*i)
	}
	return lruo
}

// AddVersion adds i to the "version" field.
func (lruo *LoginRecordUpdateOne) AddVersion(i int64) *LoginRecordUpdateOne {
	lruo.mutation.AddVersion(i)
	return lruo
}

// SetUserID sets the "user_id" field.
func (lruo *LoginRecordUpdateOne) SetUserID(i int64) *LoginRecordUpdateOne {
	lruo.mutation.SetUserID(i)
	return lruo
}

// SetLastLoginAt sets the "last_login_at" field.
func (lruo *LoginRecordUpdateOne) SetLastLoginAt(t time.Time) *LoginRecordUpdateOne {
	lruo.mutation.SetLastLoginAt(t)
	return lruo
}

// SetNillableLastLoginAt sets the "last_login_at" field if the given value is not nil.
func (lruo *LoginRecordUpdateOne) SetNillableLastLoginAt(t *time.Time) *LoginRecordUpdateOne {
	if t != nil {
		lruo.SetLastLoginAt(*t)
	}
	return lruo
}

// ClearLastLoginAt clears the value of the "last_login_at" field.
func (lruo *LoginRecordUpdateOne) ClearLastLoginAt() *LoginRecordUpdateOne {
	lruo.mutation.ClearLastLoginAt()
	return lruo
}

// SetLastLoginIpv4 sets the "last_login_ipv4" field.
func (lruo *LoginRecordUpdateOne) SetLastLoginIpv4(s string) *LoginRecordUpdateOne {
	lruo.mutation.SetLastLoginIpv4(s)
	return lruo
}

// SetNillableLastLoginIpv4 sets the "last_login_ipv4" field if the given value is not nil.
func (lruo *LoginRecordUpdateOne) SetNillableLastLoginIpv4(s *string) *LoginRecordUpdateOne {
	if s != nil {
		lruo.SetLastLoginIpv4(*s)
	}
	return lruo
}

// ClearLastLoginIpv4 clears the value of the "last_login_ipv4" field.
func (lruo *LoginRecordUpdateOne) ClearLastLoginIpv4() *LoginRecordUpdateOne {
	lruo.mutation.ClearLastLoginIpv4()
	return lruo
}

// SetLastLoginDevice sets the "last_login_device" field.
func (lruo *LoginRecordUpdateOne) SetLastLoginDevice(s string) *LoginRecordUpdateOne {
	lruo.mutation.SetLastLoginDevice(s)
	return lruo
}

// SetNillableLastLoginDevice sets the "last_login_device" field if the given value is not nil.
func (lruo *LoginRecordUpdateOne) SetNillableLastLoginDevice(s *string) *LoginRecordUpdateOne {
	if s != nil {
		lruo.SetLastLoginDevice(*s)
	}
	return lruo
}

// ClearLastLoginDevice clears the value of the "last_login_device" field.
func (lruo *LoginRecordUpdateOne) ClearLastLoginDevice() *LoginRecordUpdateOne {
	lruo.mutation.ClearLastLoginDevice()
	return lruo
}

// SetLastLoginUA sets the "last_login_UA" field.
func (lruo *LoginRecordUpdateOne) SetLastLoginUA(s string) *LoginRecordUpdateOne {
	lruo.mutation.SetLastLoginUA(s)
	return lruo
}

// SetNillableLastLoginUA sets the "last_login_UA" field if the given value is not nil.
func (lruo *LoginRecordUpdateOne) SetNillableLastLoginUA(s *string) *LoginRecordUpdateOne {
	if s != nil {
		lruo.SetLastLoginUA(*s)
	}
	return lruo
}

// ClearLastLoginUA clears the value of the "last_login_UA" field.
func (lruo *LoginRecordUpdateOne) ClearLastLoginUA() *LoginRecordUpdateOne {
	lruo.mutation.ClearLastLoginUA()
	return lruo
}

// SetLoginCount sets the "login_count" field.
func (lruo *LoginRecordUpdateOne) SetLoginCount(u uint64) *LoginRecordUpdateOne {
	lruo.mutation.ResetLoginCount()
	lruo.mutation.SetLoginCount(u)
	return lruo
}

// SetNillableLoginCount sets the "login_count" field if the given value is not nil.
func (lruo *LoginRecordUpdateOne) SetNillableLoginCount(u *uint64) *LoginRecordUpdateOne {
	if u != nil {
		lruo.SetLoginCount(*u)
	}
	return lruo
}

// AddLoginCount adds u to the "login_count" field.
func (lruo *LoginRecordUpdateOne) AddLoginCount(u int64) *LoginRecordUpdateOne {
	lruo.mutation.AddLoginCount(u)
	return lruo
}

// SetUser sets the "user" edge to the User entity.
func (lruo *LoginRecordUpdateOne) SetUser(u *User) *LoginRecordUpdateOne {
	return lruo.SetUserID(u.ID)
}

// Mutation returns the LoginRecordMutation object of the builder.
func (lruo *LoginRecordUpdateOne) Mutation() *LoginRecordMutation {
	return lruo.mutation
}

// ClearUser clears the "user" edge to the User entity.
func (lruo *LoginRecordUpdateOne) ClearUser() *LoginRecordUpdateOne {
	lruo.mutation.ClearUser()
	return lruo
}

// Where appends a list predicates to the LoginRecordUpdate builder.
func (lruo *LoginRecordUpdateOne) Where(ps ...predicate.LoginRecord) *LoginRecordUpdateOne {
	lruo.mutation.Where(ps...)
	return lruo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (lruo *LoginRecordUpdateOne) Select(field string, fields ...string) *LoginRecordUpdateOne {
	lruo.fields = append([]string{field}, fields...)
	return lruo
}

// Save executes the query and returns the updated LoginRecord entity.
func (lruo *LoginRecordUpdateOne) Save(ctx context.Context) (*LoginRecord, error) {
	if err := lruo.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, lruo.sqlSave, lruo.mutation, lruo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (lruo *LoginRecordUpdateOne) SaveX(ctx context.Context) *LoginRecord {
	node, err := lruo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (lruo *LoginRecordUpdateOne) Exec(ctx context.Context) error {
	_, err := lruo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (lruo *LoginRecordUpdateOne) ExecX(ctx context.Context) {
	if err := lruo.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (lruo *LoginRecordUpdateOne) defaults() error {
	if _, ok := lruo.mutation.UpdatedAt(); !ok {
		if loginrecord.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized loginrecord.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := loginrecord.UpdateDefaultUpdatedAt()
		lruo.mutation.SetUpdatedAt(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (lruo *LoginRecordUpdateOne) check() error {
	if _, ok := lruo.mutation.UserID(); lruo.mutation.UserCleared() && !ok {
		return errors.New(`ent: clearing a required unique edge "LoginRecord.user"`)
	}
	return nil
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (lruo *LoginRecordUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *LoginRecordUpdateOne {
	lruo.modifiers = append(lruo.modifiers, modifiers...)
	return lruo
}

func (lruo *LoginRecordUpdateOne) sqlSave(ctx context.Context) (_node *LoginRecord, err error) {
	if err := lruo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(loginrecord.Table, loginrecord.Columns, sqlgraph.NewFieldSpec(loginrecord.FieldID, field.TypeInt64))
	id, ok := lruo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "LoginRecord.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := lruo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, loginrecord.FieldID)
		for _, f := range fields {
			if !loginrecord.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != loginrecord.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := lruo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := lruo.mutation.UpdatedAt(); ok {
		_spec.SetField(loginrecord.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := lruo.mutation.Version(); ok {
		_spec.SetField(loginrecord.FieldVersion, field.TypeInt64, value)
	}
	if value, ok := lruo.mutation.AddedVersion(); ok {
		_spec.AddField(loginrecord.FieldVersion, field.TypeInt64, value)
	}
	if value, ok := lruo.mutation.LastLoginAt(); ok {
		_spec.SetField(loginrecord.FieldLastLoginAt, field.TypeTime, value)
	}
	if lruo.mutation.LastLoginAtCleared() {
		_spec.ClearField(loginrecord.FieldLastLoginAt, field.TypeTime)
	}
	if value, ok := lruo.mutation.LastLoginIpv4(); ok {
		_spec.SetField(loginrecord.FieldLastLoginIpv4, field.TypeString, value)
	}
	if lruo.mutation.LastLoginIpv4Cleared() {
		_spec.ClearField(loginrecord.FieldLastLoginIpv4, field.TypeString)
	}
	if value, ok := lruo.mutation.LastLoginDevice(); ok {
		_spec.SetField(loginrecord.FieldLastLoginDevice, field.TypeString, value)
	}
	if lruo.mutation.LastLoginDeviceCleared() {
		_spec.ClearField(loginrecord.FieldLastLoginDevice, field.TypeString)
	}
	if value, ok := lruo.mutation.LastLoginUA(); ok {
		_spec.SetField(loginrecord.FieldLastLoginUA, field.TypeString, value)
	}
	if lruo.mutation.LastLoginUACleared() {
		_spec.ClearField(loginrecord.FieldLastLoginUA, field.TypeString)
	}
	if value, ok := lruo.mutation.LoginCount(); ok {
		_spec.SetField(loginrecord.FieldLoginCount, field.TypeUint64, value)
	}
	if value, ok := lruo.mutation.AddedLoginCount(); ok {
		_spec.AddField(loginrecord.FieldLoginCount, field.TypeUint64, value)
	}
	if lruo.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   loginrecord.UserTable,
			Columns: []string{loginrecord.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := lruo.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   loginrecord.UserTable,
			Columns: []string{loginrecord.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(lruo.modifiers...)
	_node = &LoginRecord{config: lruo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, lruo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{loginrecord.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	lruo.mutation.done = true
	return _node, nil
}
