407 lines
12 KiB
Go
407 lines
12 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"gitserver.in/patialtech/rano/db/ent/predicate"
|
|
"gitserver.in/patialtech/rano/db/ent/user"
|
|
"gitserver.in/patialtech/rano/db/ent/verifytoken"
|
|
)
|
|
|
|
// VerifyTokenUpdate is the builder for updating VerifyToken entities.
|
|
type VerifyTokenUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *VerifyTokenMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the VerifyTokenUpdate builder.
|
|
func (vtu *VerifyTokenUpdate) Where(ps ...predicate.VerifyToken) *VerifyTokenUpdate {
|
|
vtu.mutation.Where(ps...)
|
|
return vtu
|
|
}
|
|
|
|
// SetToken sets the "token" field.
|
|
func (vtu *VerifyTokenUpdate) SetToken(s string) *VerifyTokenUpdate {
|
|
vtu.mutation.SetToken(s)
|
|
return vtu
|
|
}
|
|
|
|
// SetNillableToken sets the "token" field if the given value is not nil.
|
|
func (vtu *VerifyTokenUpdate) SetNillableToken(s *string) *VerifyTokenUpdate {
|
|
if s != nil {
|
|
vtu.SetToken(*s)
|
|
}
|
|
return vtu
|
|
}
|
|
|
|
// SetPurpose sets the "purpose" field.
|
|
func (vtu *VerifyTokenUpdate) SetPurpose(s string) *VerifyTokenUpdate {
|
|
vtu.mutation.SetPurpose(s)
|
|
return vtu
|
|
}
|
|
|
|
// SetNillablePurpose sets the "purpose" field if the given value is not nil.
|
|
func (vtu *VerifyTokenUpdate) SetNillablePurpose(s *string) *VerifyTokenUpdate {
|
|
if s != nil {
|
|
vtu.SetPurpose(*s)
|
|
}
|
|
return vtu
|
|
}
|
|
|
|
// ClearPurpose clears the value of the "purpose" field.
|
|
func (vtu *VerifyTokenUpdate) ClearPurpose() *VerifyTokenUpdate {
|
|
vtu.mutation.ClearPurpose()
|
|
return vtu
|
|
}
|
|
|
|
// SetUserID sets the "user" edge to the User entity by ID.
|
|
func (vtu *VerifyTokenUpdate) SetUserID(id int64) *VerifyTokenUpdate {
|
|
vtu.mutation.SetUserID(id)
|
|
return vtu
|
|
}
|
|
|
|
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
|
func (vtu *VerifyTokenUpdate) SetNillableUserID(id *int64) *VerifyTokenUpdate {
|
|
if id != nil {
|
|
vtu = vtu.SetUserID(*id)
|
|
}
|
|
return vtu
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (vtu *VerifyTokenUpdate) SetUser(u *User) *VerifyTokenUpdate {
|
|
return vtu.SetUserID(u.ID)
|
|
}
|
|
|
|
// Mutation returns the VerifyTokenMutation object of the builder.
|
|
func (vtu *VerifyTokenUpdate) Mutation() *VerifyTokenMutation {
|
|
return vtu.mutation
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (vtu *VerifyTokenUpdate) ClearUser() *VerifyTokenUpdate {
|
|
vtu.mutation.ClearUser()
|
|
return vtu
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (vtu *VerifyTokenUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, vtu.sqlSave, vtu.mutation, vtu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (vtu *VerifyTokenUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := vtu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (vtu *VerifyTokenUpdate) Exec(ctx context.Context) error {
|
|
_, err := vtu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (vtu *VerifyTokenUpdate) ExecX(ctx context.Context) {
|
|
if err := vtu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (vtu *VerifyTokenUpdate) check() error {
|
|
if v, ok := vtu.mutation.Token(); ok {
|
|
if err := verifytoken.TokenValidator(v); err != nil {
|
|
return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "VerifyToken.token": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := vtu.mutation.Purpose(); ok {
|
|
if err := verifytoken.PurposeValidator(v); err != nil {
|
|
return &ValidationError{Name: "purpose", err: fmt.Errorf(`ent: validator failed for field "VerifyToken.purpose": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (vtu *VerifyTokenUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
if err := vtu.check(); err != nil {
|
|
return n, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(verifytoken.Table, verifytoken.Columns, sqlgraph.NewFieldSpec(verifytoken.FieldID, field.TypeInt64))
|
|
if ps := vtu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := vtu.mutation.Token(); ok {
|
|
_spec.SetField(verifytoken.FieldToken, field.TypeString, value)
|
|
}
|
|
if value, ok := vtu.mutation.Purpose(); ok {
|
|
_spec.SetField(verifytoken.FieldPurpose, field.TypeString, value)
|
|
}
|
|
if vtu.mutation.PurposeCleared() {
|
|
_spec.ClearField(verifytoken.FieldPurpose, field.TypeString)
|
|
}
|
|
if vtu.mutation.UserCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: verifytoken.UserTable,
|
|
Columns: []string{verifytoken.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := vtu.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: verifytoken.UserTable,
|
|
Columns: []string{verifytoken.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)
|
|
}
|
|
if n, err = sqlgraph.UpdateNodes(ctx, vtu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{verifytoken.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
vtu.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// VerifyTokenUpdateOne is the builder for updating a single VerifyToken entity.
|
|
type VerifyTokenUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *VerifyTokenMutation
|
|
}
|
|
|
|
// SetToken sets the "token" field.
|
|
func (vtuo *VerifyTokenUpdateOne) SetToken(s string) *VerifyTokenUpdateOne {
|
|
vtuo.mutation.SetToken(s)
|
|
return vtuo
|
|
}
|
|
|
|
// SetNillableToken sets the "token" field if the given value is not nil.
|
|
func (vtuo *VerifyTokenUpdateOne) SetNillableToken(s *string) *VerifyTokenUpdateOne {
|
|
if s != nil {
|
|
vtuo.SetToken(*s)
|
|
}
|
|
return vtuo
|
|
}
|
|
|
|
// SetPurpose sets the "purpose" field.
|
|
func (vtuo *VerifyTokenUpdateOne) SetPurpose(s string) *VerifyTokenUpdateOne {
|
|
vtuo.mutation.SetPurpose(s)
|
|
return vtuo
|
|
}
|
|
|
|
// SetNillablePurpose sets the "purpose" field if the given value is not nil.
|
|
func (vtuo *VerifyTokenUpdateOne) SetNillablePurpose(s *string) *VerifyTokenUpdateOne {
|
|
if s != nil {
|
|
vtuo.SetPurpose(*s)
|
|
}
|
|
return vtuo
|
|
}
|
|
|
|
// ClearPurpose clears the value of the "purpose" field.
|
|
func (vtuo *VerifyTokenUpdateOne) ClearPurpose() *VerifyTokenUpdateOne {
|
|
vtuo.mutation.ClearPurpose()
|
|
return vtuo
|
|
}
|
|
|
|
// SetUserID sets the "user" edge to the User entity by ID.
|
|
func (vtuo *VerifyTokenUpdateOne) SetUserID(id int64) *VerifyTokenUpdateOne {
|
|
vtuo.mutation.SetUserID(id)
|
|
return vtuo
|
|
}
|
|
|
|
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
|
func (vtuo *VerifyTokenUpdateOne) SetNillableUserID(id *int64) *VerifyTokenUpdateOne {
|
|
if id != nil {
|
|
vtuo = vtuo.SetUserID(*id)
|
|
}
|
|
return vtuo
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (vtuo *VerifyTokenUpdateOne) SetUser(u *User) *VerifyTokenUpdateOne {
|
|
return vtuo.SetUserID(u.ID)
|
|
}
|
|
|
|
// Mutation returns the VerifyTokenMutation object of the builder.
|
|
func (vtuo *VerifyTokenUpdateOne) Mutation() *VerifyTokenMutation {
|
|
return vtuo.mutation
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (vtuo *VerifyTokenUpdateOne) ClearUser() *VerifyTokenUpdateOne {
|
|
vtuo.mutation.ClearUser()
|
|
return vtuo
|
|
}
|
|
|
|
// Where appends a list predicates to the VerifyTokenUpdate builder.
|
|
func (vtuo *VerifyTokenUpdateOne) Where(ps ...predicate.VerifyToken) *VerifyTokenUpdateOne {
|
|
vtuo.mutation.Where(ps...)
|
|
return vtuo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (vtuo *VerifyTokenUpdateOne) Select(field string, fields ...string) *VerifyTokenUpdateOne {
|
|
vtuo.fields = append([]string{field}, fields...)
|
|
return vtuo
|
|
}
|
|
|
|
// Save executes the query and returns the updated VerifyToken entity.
|
|
func (vtuo *VerifyTokenUpdateOne) Save(ctx context.Context) (*VerifyToken, error) {
|
|
return withHooks(ctx, vtuo.sqlSave, vtuo.mutation, vtuo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (vtuo *VerifyTokenUpdateOne) SaveX(ctx context.Context) *VerifyToken {
|
|
node, err := vtuo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (vtuo *VerifyTokenUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := vtuo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (vtuo *VerifyTokenUpdateOne) ExecX(ctx context.Context) {
|
|
if err := vtuo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (vtuo *VerifyTokenUpdateOne) check() error {
|
|
if v, ok := vtuo.mutation.Token(); ok {
|
|
if err := verifytoken.TokenValidator(v); err != nil {
|
|
return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "VerifyToken.token": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := vtuo.mutation.Purpose(); ok {
|
|
if err := verifytoken.PurposeValidator(v); err != nil {
|
|
return &ValidationError{Name: "purpose", err: fmt.Errorf(`ent: validator failed for field "VerifyToken.purpose": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (vtuo *VerifyTokenUpdateOne) sqlSave(ctx context.Context) (_node *VerifyToken, err error) {
|
|
if err := vtuo.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(verifytoken.Table, verifytoken.Columns, sqlgraph.NewFieldSpec(verifytoken.FieldID, field.TypeInt64))
|
|
id, ok := vtuo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "VerifyToken.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := vtuo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, verifytoken.FieldID)
|
|
for _, f := range fields {
|
|
if !verifytoken.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != verifytoken.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := vtuo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := vtuo.mutation.Token(); ok {
|
|
_spec.SetField(verifytoken.FieldToken, field.TypeString, value)
|
|
}
|
|
if value, ok := vtuo.mutation.Purpose(); ok {
|
|
_spec.SetField(verifytoken.FieldPurpose, field.TypeString, value)
|
|
}
|
|
if vtuo.mutation.PurposeCleared() {
|
|
_spec.ClearField(verifytoken.FieldPurpose, field.TypeString)
|
|
}
|
|
if vtuo.mutation.UserCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: verifytoken.UserTable,
|
|
Columns: []string{verifytoken.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := vtuo.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: verifytoken.UserTable,
|
|
Columns: []string{verifytoken.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)
|
|
}
|
|
_node = &VerifyToken{config: vtuo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, vtuo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{verifytoken.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
vtuo.mutation.done = true
|
|
return _node, nil
|
|
}
|