privacy/server/ent/sfmodel_update.go
2020-11-28 18:50:30 +08:00

312 lines
7.9 KiB
Go

// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"github.com/facebook/ent/dialect/sql"
"github.com/facebook/ent/dialect/sql/sqlgraph"
"github.com/facebook/ent/schema/field"
"github.com/kallydev/privacy/ent/predicate"
"github.com/kallydev/privacy/ent/sfmodel"
)
// SFModelUpdate is the builder for updating SFModel entities.
type SFModelUpdate struct {
config
hooks []Hook
mutation *SFModelMutation
}
// Where adds a new predicate for the builder.
func (smu *SFModelUpdate) Where(ps ...predicate.SFModel) *SFModelUpdate {
smu.mutation.predicates = append(smu.mutation.predicates, ps...)
return smu
}
// SetName sets the name field.
func (smu *SFModelUpdate) SetName(s string) *SFModelUpdate {
smu.mutation.SetName(s)
return smu
}
// SetPhoneNumber sets the phone_number field.
func (smu *SFModelUpdate) SetPhoneNumber(i int64) *SFModelUpdate {
smu.mutation.ResetPhoneNumber()
smu.mutation.SetPhoneNumber(i)
return smu
}
// AddPhoneNumber adds i to phone_number.
func (smu *SFModelUpdate) AddPhoneNumber(i int64) *SFModelUpdate {
smu.mutation.AddPhoneNumber(i)
return smu
}
// SetAddress sets the address field.
func (smu *SFModelUpdate) SetAddress(s string) *SFModelUpdate {
smu.mutation.SetAddress(s)
return smu
}
// Mutation returns the SFModelMutation object of the builder.
func (smu *SFModelUpdate) Mutation() *SFModelMutation {
return smu.mutation
}
// Save executes the query and returns the number of rows/vertices matched by this operation.
func (smu *SFModelUpdate) Save(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(smu.hooks) == 0 {
affected, err = smu.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*SFModelMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
smu.mutation = mutation
affected, err = smu.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(smu.hooks) - 1; i >= 0; i-- {
mut = smu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, smu.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// SaveX is like Save, but panics if an error occurs.
func (smu *SFModelUpdate) SaveX(ctx context.Context) int {
affected, err := smu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (smu *SFModelUpdate) Exec(ctx context.Context) error {
_, err := smu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (smu *SFModelUpdate) ExecX(ctx context.Context) {
if err := smu.Exec(ctx); err != nil {
panic(err)
}
}
func (smu *SFModelUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: sfmodel.Table,
Columns: sfmodel.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: sfmodel.FieldID,
},
},
}
if ps := smu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := smu.mutation.Name(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: sfmodel.FieldName,
})
}
if value, ok := smu.mutation.PhoneNumber(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: sfmodel.FieldPhoneNumber,
})
}
if value, ok := smu.mutation.AddedPhoneNumber(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: sfmodel.FieldPhoneNumber,
})
}
if value, ok := smu.mutation.Address(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: sfmodel.FieldAddress,
})
}
if n, err = sqlgraph.UpdateNodes(ctx, smu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{sfmodel.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
}
return n, nil
}
// SFModelUpdateOne is the builder for updating a single SFModel entity.
type SFModelUpdateOne struct {
config
hooks []Hook
mutation *SFModelMutation
}
// SetName sets the name field.
func (smuo *SFModelUpdateOne) SetName(s string) *SFModelUpdateOne {
smuo.mutation.SetName(s)
return smuo
}
// SetPhoneNumber sets the phone_number field.
func (smuo *SFModelUpdateOne) SetPhoneNumber(i int64) *SFModelUpdateOne {
smuo.mutation.ResetPhoneNumber()
smuo.mutation.SetPhoneNumber(i)
return smuo
}
// AddPhoneNumber adds i to phone_number.
func (smuo *SFModelUpdateOne) AddPhoneNumber(i int64) *SFModelUpdateOne {
smuo.mutation.AddPhoneNumber(i)
return smuo
}
// SetAddress sets the address field.
func (smuo *SFModelUpdateOne) SetAddress(s string) *SFModelUpdateOne {
smuo.mutation.SetAddress(s)
return smuo
}
// Mutation returns the SFModelMutation object of the builder.
func (smuo *SFModelUpdateOne) Mutation() *SFModelMutation {
return smuo.mutation
}
// Save executes the query and returns the updated entity.
func (smuo *SFModelUpdateOne) Save(ctx context.Context) (*SFModel, error) {
var (
err error
node *SFModel
)
if len(smuo.hooks) == 0 {
node, err = smuo.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*SFModelMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
smuo.mutation = mutation
node, err = smuo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(smuo.hooks) - 1; i >= 0; i-- {
mut = smuo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, smuo.mutation); err != nil {
return nil, err
}
}
return node, err
}
// SaveX is like Save, but panics if an error occurs.
func (smuo *SFModelUpdateOne) SaveX(ctx context.Context) *SFModel {
node, err := smuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (smuo *SFModelUpdateOne) Exec(ctx context.Context) error {
_, err := smuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (smuo *SFModelUpdateOne) ExecX(ctx context.Context) {
if err := smuo.Exec(ctx); err != nil {
panic(err)
}
}
func (smuo *SFModelUpdateOne) sqlSave(ctx context.Context) (_node *SFModel, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: sfmodel.Table,
Columns: sfmodel.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: sfmodel.FieldID,
},
},
}
id, ok := smuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing SFModel.ID for update")}
}
_spec.Node.ID.Value = id
if value, ok := smuo.mutation.Name(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: sfmodel.FieldName,
})
}
if value, ok := smuo.mutation.PhoneNumber(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: sfmodel.FieldPhoneNumber,
})
}
if value, ok := smuo.mutation.AddedPhoneNumber(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Value: value,
Column: sfmodel.FieldPhoneNumber,
})
}
if value, ok := smuo.mutation.Address(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: sfmodel.FieldAddress,
})
}
_node = &SFModel{config: smuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues()
if err = sqlgraph.UpdateNode(ctx, smuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{sfmodel.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err
}
return _node, nil
}