snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
578
examples/migration/ent/sessiondevice_update.go
Normal file
578
examples/migration/ent/sessiondevice_update.go
Normal file
@@ -0,0 +1,578 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// 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/examples/migration/ent/predicate"
|
||||
"entgo.io/ent/examples/migration/ent/session"
|
||||
"entgo.io/ent/examples/migration/ent/sessiondevice"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// SessionDeviceUpdate is the builder for updating SessionDevice entities.
|
||||
type SessionDeviceUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SessionDeviceMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SessionDeviceUpdate builder.
|
||||
func (_u *SessionDeviceUpdate) Where(ps ...predicate.SessionDevice) *SessionDeviceUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetIPAddress sets the "ip_address" field.
|
||||
func (_u *SessionDeviceUpdate) SetIPAddress(v string) *SessionDeviceUpdate {
|
||||
_u.mutation.SetIPAddress(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
|
||||
func (_u *SessionDeviceUpdate) SetNillableIPAddress(v *string) *SessionDeviceUpdate {
|
||||
if v != nil {
|
||||
_u.SetIPAddress(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserAgent sets the "user_agent" field.
|
||||
func (_u *SessionDeviceUpdate) SetUserAgent(v string) *SessionDeviceUpdate {
|
||||
_u.mutation.SetUserAgent(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
|
||||
func (_u *SessionDeviceUpdate) SetNillableUserAgent(v *string) *SessionDeviceUpdate {
|
||||
if v != nil {
|
||||
_u.SetUserAgent(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetLocation sets the "location" field.
|
||||
func (_u *SessionDeviceUpdate) SetLocation(v string) *SessionDeviceUpdate {
|
||||
_u.mutation.SetLocation(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableLocation sets the "location" field if the given value is not nil.
|
||||
func (_u *SessionDeviceUpdate) SetNillableLocation(v *string) *SessionDeviceUpdate {
|
||||
if v != nil {
|
||||
_u.SetLocation(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_u *SessionDeviceUpdate) SetCreatedAt(v time.Time) *SessionDeviceUpdate {
|
||||
_u.mutation.SetCreatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_u *SessionDeviceUpdate) SetNillableCreatedAt(v *time.Time) *SessionDeviceUpdate {
|
||||
if v != nil {
|
||||
_u.SetCreatedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *SessionDeviceUpdate) SetUpdatedAt(v time.Time) *SessionDeviceUpdate {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_u *SessionDeviceUpdate) SetNillableUpdatedAt(v *time.Time) *SessionDeviceUpdate {
|
||||
if v != nil {
|
||||
_u.SetUpdatedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUpdatedAt clears the value of the "updated_at" field.
|
||||
func (_u *SessionDeviceUpdate) ClearUpdatedAt() *SessionDeviceUpdate {
|
||||
_u.mutation.ClearUpdatedAt()
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddSessionIDs adds the "sessions" edge to the Session entity by IDs.
|
||||
func (_u *SessionDeviceUpdate) AddSessionIDs(ids ...uuid.UUID) *SessionDeviceUpdate {
|
||||
_u.mutation.AddSessionIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddSessions adds the "sessions" edges to the Session entity.
|
||||
func (_u *SessionDeviceUpdate) AddSessions(v ...*Session) *SessionDeviceUpdate {
|
||||
ids := make([]uuid.UUID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddSessionIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SessionDeviceMutation object of the builder.
|
||||
func (_u *SessionDeviceUpdate) Mutation() *SessionDeviceMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearSessions clears all "sessions" edges to the Session entity.
|
||||
func (_u *SessionDeviceUpdate) ClearSessions() *SessionDeviceUpdate {
|
||||
_u.mutation.ClearSessions()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveSessionIDs removes the "sessions" edge to Session entities by IDs.
|
||||
func (_u *SessionDeviceUpdate) RemoveSessionIDs(ids ...uuid.UUID) *SessionDeviceUpdate {
|
||||
_u.mutation.RemoveSessionIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveSessions removes "sessions" edges to Session entities.
|
||||
func (_u *SessionDeviceUpdate) RemoveSessions(v ...*Session) *SessionDeviceUpdate {
|
||||
ids := make([]uuid.UUID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveSessionIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *SessionDeviceUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *SessionDeviceUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *SessionDeviceUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *SessionDeviceUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *SessionDeviceUpdate) check() error {
|
||||
if v, ok := _u.mutation.IPAddress(); ok {
|
||||
if err := sessiondevice.IPAddressValidator(v); err != nil {
|
||||
return &ValidationError{Name: "ip_address", err: fmt.Errorf(`ent: validator failed for field "SessionDevice.ip_address": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.UserAgent(); ok {
|
||||
if err := sessiondevice.UserAgentValidator(v); err != nil {
|
||||
return &ValidationError{Name: "user_agent", err: fmt.Errorf(`ent: validator failed for field "SessionDevice.user_agent": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Location(); ok {
|
||||
if err := sessiondevice.LocationValidator(v); err != nil {
|
||||
return &ValidationError{Name: "location", err: fmt.Errorf(`ent: validator failed for field "SessionDevice.location": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *SessionDeviceUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(sessiondevice.Table, sessiondevice.Columns, sqlgraph.NewFieldSpec(sessiondevice.FieldID, field.TypeUUID))
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.IPAddress(); ok {
|
||||
_spec.SetField(sessiondevice.FieldIPAddress, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.UserAgent(); ok {
|
||||
_spec.SetField(sessiondevice.FieldUserAgent, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Location(); ok {
|
||||
_spec.SetField(sessiondevice.FieldLocation, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(sessiondevice.FieldCreatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(sessiondevice.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.UpdatedAtCleared() {
|
||||
_spec.ClearField(sessiondevice.FieldUpdatedAt, field.TypeTime)
|
||||
}
|
||||
if _u.mutation.SessionsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sessiondevice.SessionsTable,
|
||||
Columns: []string{sessiondevice.SessionsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(session.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedSessionsIDs(); len(nodes) > 0 && !_u.mutation.SessionsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sessiondevice.SessionsTable,
|
||||
Columns: []string{sessiondevice.SessionsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(session.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 := _u.mutation.SessionsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sessiondevice.SessionsTable,
|
||||
Columns: []string{sessiondevice.SessionsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(session.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{sessiondevice.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// SessionDeviceUpdateOne is the builder for updating a single SessionDevice entity.
|
||||
type SessionDeviceUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *SessionDeviceMutation
|
||||
}
|
||||
|
||||
// SetIPAddress sets the "ip_address" field.
|
||||
func (_u *SessionDeviceUpdateOne) SetIPAddress(v string) *SessionDeviceUpdateOne {
|
||||
_u.mutation.SetIPAddress(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
|
||||
func (_u *SessionDeviceUpdateOne) SetNillableIPAddress(v *string) *SessionDeviceUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetIPAddress(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserAgent sets the "user_agent" field.
|
||||
func (_u *SessionDeviceUpdateOne) SetUserAgent(v string) *SessionDeviceUpdateOne {
|
||||
_u.mutation.SetUserAgent(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
|
||||
func (_u *SessionDeviceUpdateOne) SetNillableUserAgent(v *string) *SessionDeviceUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUserAgent(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetLocation sets the "location" field.
|
||||
func (_u *SessionDeviceUpdateOne) SetLocation(v string) *SessionDeviceUpdateOne {
|
||||
_u.mutation.SetLocation(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableLocation sets the "location" field if the given value is not nil.
|
||||
func (_u *SessionDeviceUpdateOne) SetNillableLocation(v *string) *SessionDeviceUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetLocation(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_u *SessionDeviceUpdateOne) SetCreatedAt(v time.Time) *SessionDeviceUpdateOne {
|
||||
_u.mutation.SetCreatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_u *SessionDeviceUpdateOne) SetNillableCreatedAt(v *time.Time) *SessionDeviceUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCreatedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *SessionDeviceUpdateOne) SetUpdatedAt(v time.Time) *SessionDeviceUpdateOne {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_u *SessionDeviceUpdateOne) SetNillableUpdatedAt(v *time.Time) *SessionDeviceUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUpdatedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUpdatedAt clears the value of the "updated_at" field.
|
||||
func (_u *SessionDeviceUpdateOne) ClearUpdatedAt() *SessionDeviceUpdateOne {
|
||||
_u.mutation.ClearUpdatedAt()
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddSessionIDs adds the "sessions" edge to the Session entity by IDs.
|
||||
func (_u *SessionDeviceUpdateOne) AddSessionIDs(ids ...uuid.UUID) *SessionDeviceUpdateOne {
|
||||
_u.mutation.AddSessionIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddSessions adds the "sessions" edges to the Session entity.
|
||||
func (_u *SessionDeviceUpdateOne) AddSessions(v ...*Session) *SessionDeviceUpdateOne {
|
||||
ids := make([]uuid.UUID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddSessionIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SessionDeviceMutation object of the builder.
|
||||
func (_u *SessionDeviceUpdateOne) Mutation() *SessionDeviceMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearSessions clears all "sessions" edges to the Session entity.
|
||||
func (_u *SessionDeviceUpdateOne) ClearSessions() *SessionDeviceUpdateOne {
|
||||
_u.mutation.ClearSessions()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveSessionIDs removes the "sessions" edge to Session entities by IDs.
|
||||
func (_u *SessionDeviceUpdateOne) RemoveSessionIDs(ids ...uuid.UUID) *SessionDeviceUpdateOne {
|
||||
_u.mutation.RemoveSessionIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveSessions removes "sessions" edges to Session entities.
|
||||
func (_u *SessionDeviceUpdateOne) RemoveSessions(v ...*Session) *SessionDeviceUpdateOne {
|
||||
ids := make([]uuid.UUID, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveSessionIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SessionDeviceUpdate builder.
|
||||
func (_u *SessionDeviceUpdateOne) Where(ps ...predicate.SessionDevice) *SessionDeviceUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *SessionDeviceUpdateOne) Select(field string, fields ...string) *SessionDeviceUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated SessionDevice entity.
|
||||
func (_u *SessionDeviceUpdateOne) Save(ctx context.Context) (*SessionDevice, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *SessionDeviceUpdateOne) SaveX(ctx context.Context) *SessionDevice {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *SessionDeviceUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *SessionDeviceUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *SessionDeviceUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.IPAddress(); ok {
|
||||
if err := sessiondevice.IPAddressValidator(v); err != nil {
|
||||
return &ValidationError{Name: "ip_address", err: fmt.Errorf(`ent: validator failed for field "SessionDevice.ip_address": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.UserAgent(); ok {
|
||||
if err := sessiondevice.UserAgentValidator(v); err != nil {
|
||||
return &ValidationError{Name: "user_agent", err: fmt.Errorf(`ent: validator failed for field "SessionDevice.user_agent": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Location(); ok {
|
||||
if err := sessiondevice.LocationValidator(v); err != nil {
|
||||
return &ValidationError{Name: "location", err: fmt.Errorf(`ent: validator failed for field "SessionDevice.location": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *SessionDeviceUpdateOne) sqlSave(ctx context.Context) (_node *SessionDevice, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(sessiondevice.Table, sessiondevice.Columns, sqlgraph.NewFieldSpec(sessiondevice.FieldID, field.TypeUUID))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SessionDevice.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, sessiondevice.FieldID)
|
||||
for _, f := range fields {
|
||||
if !sessiondevice.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != sessiondevice.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.IPAddress(); ok {
|
||||
_spec.SetField(sessiondevice.FieldIPAddress, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.UserAgent(); ok {
|
||||
_spec.SetField(sessiondevice.FieldUserAgent, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Location(); ok {
|
||||
_spec.SetField(sessiondevice.FieldLocation, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(sessiondevice.FieldCreatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(sessiondevice.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.UpdatedAtCleared() {
|
||||
_spec.ClearField(sessiondevice.FieldUpdatedAt, field.TypeTime)
|
||||
}
|
||||
if _u.mutation.SessionsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sessiondevice.SessionsTable,
|
||||
Columns: []string{sessiondevice.SessionsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(session.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedSessionsIDs(); len(nodes) > 0 && !_u.mutation.SessionsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sessiondevice.SessionsTable,
|
||||
Columns: []string{sessiondevice.SessionsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(session.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 := _u.mutation.SessionsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sessiondevice.SessionsTable,
|
||||
Columns: []string{sessiondevice.SessionsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(session.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &SessionDevice{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{sessiondevice.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user