Files
likedream/internal/ent/cpschool_update.go
T
sugarBecomer 6840b69f1a 🐛 登录问题
2025-11-07 15:28:54 +08:00

505 lines
15 KiB
Go

// ENT数据库文件,请勿编辑。
package ent
import (
"context"
"errors"
"fmt"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/internal"
"likedream-goframe/internal/ent/predicate"
"likedream-goframe/internal/framework/ent2"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// CpSchoolUpdate is the builder for updating CpSchool entities.
type CpSchoolUpdate struct {
config
hooks []Hook
mutation *CpSchoolMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the CpSchoolUpdate builder.
func (_u *CpSchoolUpdate) Where(ps ...predicate.CpSchool) *CpSchoolUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetUpdateTime sets the "update_time" field.
func (_u *CpSchoolUpdate) SetUpdateTime(v *ent2.CustomTime) *CpSchoolUpdate {
_u.mutation.SetUpdateTime(v)
return _u
}
// SetName sets the "name" field.
func (_u *CpSchoolUpdate) SetName(v string) *CpSchoolUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *CpSchoolUpdate) SetNillableName(v *string) *CpSchoolUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetNamePinyin sets the "name_pinyin" field.
func (_u *CpSchoolUpdate) SetNamePinyin(v string) *CpSchoolUpdate {
_u.mutation.SetNamePinyin(v)
return _u
}
// SetNillableNamePinyin sets the "name_pinyin" field if the given value is not nil.
func (_u *CpSchoolUpdate) SetNillableNamePinyin(v *string) *CpSchoolUpdate {
if v != nil {
_u.SetNamePinyin(*v)
}
return _u
}
// SetIconImg sets the "icon_img" field.
func (_u *CpSchoolUpdate) SetIconImg(v string) *CpSchoolUpdate {
_u.mutation.SetIconImg(v)
return _u
}
// SetNillableIconImg sets the "icon_img" field if the given value is not nil.
func (_u *CpSchoolUpdate) SetNillableIconImg(v *string) *CpSchoolUpdate {
if v != nil {
_u.SetIconImg(*v)
}
return _u
}
// ClearIconImg clears the value of the "icon_img" field.
func (_u *CpSchoolUpdate) ClearIconImg() *CpSchoolUpdate {
_u.mutation.ClearIconImg()
return _u
}
// AddCpuserIDs adds the "cpusers" edge to the CpUser entity by IDs.
func (_u *CpSchoolUpdate) AddCpuserIDs(ids ...int64) *CpSchoolUpdate {
_u.mutation.AddCpuserIDs(ids...)
return _u
}
// AddCpusers adds the "cpusers" edges to the CpUser entity.
func (_u *CpSchoolUpdate) AddCpusers(v ...*CpUser) *CpSchoolUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddCpuserIDs(ids...)
}
// Mutation returns the CpSchoolMutation object of the builder.
func (_u *CpSchoolUpdate) Mutation() *CpSchoolMutation {
return _u.mutation
}
// ClearCpusers clears all "cpusers" edges to the CpUser entity.
func (_u *CpSchoolUpdate) ClearCpusers() *CpSchoolUpdate {
_u.mutation.ClearCpusers()
return _u
}
// RemoveCpuserIDs removes the "cpusers" edge to CpUser entities by IDs.
func (_u *CpSchoolUpdate) RemoveCpuserIDs(ids ...int64) *CpSchoolUpdate {
_u.mutation.RemoveCpuserIDs(ids...)
return _u
}
// RemoveCpusers removes "cpusers" edges to CpUser entities.
func (_u *CpSchoolUpdate) RemoveCpusers(v ...*CpUser) *CpSchoolUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveCpuserIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *CpSchoolUpdate) 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 *CpSchoolUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *CpSchoolUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *CpSchoolUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *CpSchoolUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CpSchoolUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *CpSchoolUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(cpschool.Table, cpschool.Columns, sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString))
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.UpdateTime(); ok {
_spec.SetField(cpschool.FieldUpdateTime, field.TypeString, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(cpschool.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.NamePinyin(); ok {
_spec.SetField(cpschool.FieldNamePinyin, field.TypeString, value)
}
if value, ok := _u.mutation.IconImg(); ok {
_spec.SetField(cpschool.FieldIconImg, field.TypeString, value)
}
if _u.mutation.IconImgCleared() {
_spec.ClearField(cpschool.FieldIconImg, field.TypeString)
}
if _u.mutation.CpusersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpUser
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedCpusersIDs(); len(nodes) > 0 && !_u.mutation.CpusersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpUser
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpusersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpUser
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.Node.Schema = _u.schemaConfig.CpSchool
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{cpschool.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// CpSchoolUpdateOne is the builder for updating a single CpSchool entity.
type CpSchoolUpdateOne struct {
config
fields []string
hooks []Hook
mutation *CpSchoolMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetUpdateTime sets the "update_time" field.
func (_u *CpSchoolUpdateOne) SetUpdateTime(v *ent2.CustomTime) *CpSchoolUpdateOne {
_u.mutation.SetUpdateTime(v)
return _u
}
// SetName sets the "name" field.
func (_u *CpSchoolUpdateOne) SetName(v string) *CpSchoolUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *CpSchoolUpdateOne) SetNillableName(v *string) *CpSchoolUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetNamePinyin sets the "name_pinyin" field.
func (_u *CpSchoolUpdateOne) SetNamePinyin(v string) *CpSchoolUpdateOne {
_u.mutation.SetNamePinyin(v)
return _u
}
// SetNillableNamePinyin sets the "name_pinyin" field if the given value is not nil.
func (_u *CpSchoolUpdateOne) SetNillableNamePinyin(v *string) *CpSchoolUpdateOne {
if v != nil {
_u.SetNamePinyin(*v)
}
return _u
}
// SetIconImg sets the "icon_img" field.
func (_u *CpSchoolUpdateOne) SetIconImg(v string) *CpSchoolUpdateOne {
_u.mutation.SetIconImg(v)
return _u
}
// SetNillableIconImg sets the "icon_img" field if the given value is not nil.
func (_u *CpSchoolUpdateOne) SetNillableIconImg(v *string) *CpSchoolUpdateOne {
if v != nil {
_u.SetIconImg(*v)
}
return _u
}
// ClearIconImg clears the value of the "icon_img" field.
func (_u *CpSchoolUpdateOne) ClearIconImg() *CpSchoolUpdateOne {
_u.mutation.ClearIconImg()
return _u
}
// AddCpuserIDs adds the "cpusers" edge to the CpUser entity by IDs.
func (_u *CpSchoolUpdateOne) AddCpuserIDs(ids ...int64) *CpSchoolUpdateOne {
_u.mutation.AddCpuserIDs(ids...)
return _u
}
// AddCpusers adds the "cpusers" edges to the CpUser entity.
func (_u *CpSchoolUpdateOne) AddCpusers(v ...*CpUser) *CpSchoolUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddCpuserIDs(ids...)
}
// Mutation returns the CpSchoolMutation object of the builder.
func (_u *CpSchoolUpdateOne) Mutation() *CpSchoolMutation {
return _u.mutation
}
// ClearCpusers clears all "cpusers" edges to the CpUser entity.
func (_u *CpSchoolUpdateOne) ClearCpusers() *CpSchoolUpdateOne {
_u.mutation.ClearCpusers()
return _u
}
// RemoveCpuserIDs removes the "cpusers" edge to CpUser entities by IDs.
func (_u *CpSchoolUpdateOne) RemoveCpuserIDs(ids ...int64) *CpSchoolUpdateOne {
_u.mutation.RemoveCpuserIDs(ids...)
return _u
}
// RemoveCpusers removes "cpusers" edges to CpUser entities.
func (_u *CpSchoolUpdateOne) RemoveCpusers(v ...*CpUser) *CpSchoolUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveCpuserIDs(ids...)
}
// Where appends a list predicates to the CpSchoolUpdate builder.
func (_u *CpSchoolUpdateOne) Where(ps ...predicate.CpSchool) *CpSchoolUpdateOne {
_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 *CpSchoolUpdateOne) Select(field string, fields ...string) *CpSchoolUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated CpSchool entity.
func (_u *CpSchoolUpdateOne) Save(ctx context.Context) (*CpSchool, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *CpSchoolUpdateOne) SaveX(ctx context.Context) *CpSchool {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *CpSchoolUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *CpSchoolUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *CpSchoolUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CpSchoolUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *CpSchoolUpdateOne) sqlSave(ctx context.Context) (_node *CpSchool, err error) {
_spec := sqlgraph.NewUpdateSpec(cpschool.Table, cpschool.Columns, sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CpSchool.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, cpschool.FieldID)
for _, f := range fields {
if !cpschool.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != cpschool.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.UpdateTime(); ok {
_spec.SetField(cpschool.FieldUpdateTime, field.TypeString, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(cpschool.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.NamePinyin(); ok {
_spec.SetField(cpschool.FieldNamePinyin, field.TypeString, value)
}
if value, ok := _u.mutation.IconImg(); ok {
_spec.SetField(cpschool.FieldIconImg, field.TypeString, value)
}
if _u.mutation.IconImgCleared() {
_spec.ClearField(cpschool.FieldIconImg, field.TypeString)
}
if _u.mutation.CpusersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpUser
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedCpusersIDs(); len(nodes) > 0 && !_u.mutation.CpusersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpUser
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpusersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpUser
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.Node.Schema = _u.schemaConfig.CpSchool
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
_spec.AddModifiers(_u.modifiers...)
_node = &CpSchool{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{cpschool.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}