tss-rocks/backend/ent/dailycategorycontent_update.go
CDN 05ddc1f783
Some checks failed
Build Backend / Build Docker Image (push) Successful in 3m33s
Test Backend / test (push) Failing after 31s
[feature] migrate to monorepo
2025-02-21 00:49:20 +08:00

388 lines
13 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"tss-rocks-be/ent/dailycategory"
"tss-rocks-be/ent/dailycategorycontent"
"tss-rocks-be/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// DailyCategoryContentUpdate is the builder for updating DailyCategoryContent entities.
type DailyCategoryContentUpdate struct {
config
hooks []Hook
mutation *DailyCategoryContentMutation
}
// Where appends a list predicates to the DailyCategoryContentUpdate builder.
func (dccu *DailyCategoryContentUpdate) Where(ps ...predicate.DailyCategoryContent) *DailyCategoryContentUpdate {
dccu.mutation.Where(ps...)
return dccu
}
// SetLanguageCode sets the "language_code" field.
func (dccu *DailyCategoryContentUpdate) SetLanguageCode(dc dailycategorycontent.LanguageCode) *DailyCategoryContentUpdate {
dccu.mutation.SetLanguageCode(dc)
return dccu
}
// SetNillableLanguageCode sets the "language_code" field if the given value is not nil.
func (dccu *DailyCategoryContentUpdate) SetNillableLanguageCode(dc *dailycategorycontent.LanguageCode) *DailyCategoryContentUpdate {
if dc != nil {
dccu.SetLanguageCode(*dc)
}
return dccu
}
// SetName sets the "name" field.
func (dccu *DailyCategoryContentUpdate) SetName(s string) *DailyCategoryContentUpdate {
dccu.mutation.SetName(s)
return dccu
}
// SetNillableName sets the "name" field if the given value is not nil.
func (dccu *DailyCategoryContentUpdate) SetNillableName(s *string) *DailyCategoryContentUpdate {
if s != nil {
dccu.SetName(*s)
}
return dccu
}
// SetCategoryID sets the "category" edge to the DailyCategory entity by ID.
func (dccu *DailyCategoryContentUpdate) SetCategoryID(id int) *DailyCategoryContentUpdate {
dccu.mutation.SetCategoryID(id)
return dccu
}
// SetNillableCategoryID sets the "category" edge to the DailyCategory entity by ID if the given value is not nil.
func (dccu *DailyCategoryContentUpdate) SetNillableCategoryID(id *int) *DailyCategoryContentUpdate {
if id != nil {
dccu = dccu.SetCategoryID(*id)
}
return dccu
}
// SetCategory sets the "category" edge to the DailyCategory entity.
func (dccu *DailyCategoryContentUpdate) SetCategory(d *DailyCategory) *DailyCategoryContentUpdate {
return dccu.SetCategoryID(d.ID)
}
// Mutation returns the DailyCategoryContentMutation object of the builder.
func (dccu *DailyCategoryContentUpdate) Mutation() *DailyCategoryContentMutation {
return dccu.mutation
}
// ClearCategory clears the "category" edge to the DailyCategory entity.
func (dccu *DailyCategoryContentUpdate) ClearCategory() *DailyCategoryContentUpdate {
dccu.mutation.ClearCategory()
return dccu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (dccu *DailyCategoryContentUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, dccu.sqlSave, dccu.mutation, dccu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (dccu *DailyCategoryContentUpdate) SaveX(ctx context.Context) int {
affected, err := dccu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (dccu *DailyCategoryContentUpdate) Exec(ctx context.Context) error {
_, err := dccu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dccu *DailyCategoryContentUpdate) ExecX(ctx context.Context) {
if err := dccu.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (dccu *DailyCategoryContentUpdate) check() error {
if v, ok := dccu.mutation.LanguageCode(); ok {
if err := dailycategorycontent.LanguageCodeValidator(v); err != nil {
return &ValidationError{Name: "language_code", err: fmt.Errorf(`ent: validator failed for field "DailyCategoryContent.language_code": %w`, err)}
}
}
if v, ok := dccu.mutation.Name(); ok {
if err := dailycategorycontent.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "DailyCategoryContent.name": %w`, err)}
}
}
return nil
}
func (dccu *DailyCategoryContentUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := dccu.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(dailycategorycontent.Table, dailycategorycontent.Columns, sqlgraph.NewFieldSpec(dailycategorycontent.FieldID, field.TypeInt))
if ps := dccu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := dccu.mutation.LanguageCode(); ok {
_spec.SetField(dailycategorycontent.FieldLanguageCode, field.TypeEnum, value)
}
if value, ok := dccu.mutation.Name(); ok {
_spec.SetField(dailycategorycontent.FieldName, field.TypeString, value)
}
if dccu.mutation.CategoryCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: dailycategorycontent.CategoryTable,
Columns: []string{dailycategorycontent.CategoryColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(dailycategory.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dccu.mutation.CategoryIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: dailycategorycontent.CategoryTable,
Columns: []string{dailycategorycontent.CategoryColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(dailycategory.FieldID, field.TypeInt),
},
}
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, dccu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{dailycategorycontent.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
dccu.mutation.done = true
return n, nil
}
// DailyCategoryContentUpdateOne is the builder for updating a single DailyCategoryContent entity.
type DailyCategoryContentUpdateOne struct {
config
fields []string
hooks []Hook
mutation *DailyCategoryContentMutation
}
// SetLanguageCode sets the "language_code" field.
func (dccuo *DailyCategoryContentUpdateOne) SetLanguageCode(dc dailycategorycontent.LanguageCode) *DailyCategoryContentUpdateOne {
dccuo.mutation.SetLanguageCode(dc)
return dccuo
}
// SetNillableLanguageCode sets the "language_code" field if the given value is not nil.
func (dccuo *DailyCategoryContentUpdateOne) SetNillableLanguageCode(dc *dailycategorycontent.LanguageCode) *DailyCategoryContentUpdateOne {
if dc != nil {
dccuo.SetLanguageCode(*dc)
}
return dccuo
}
// SetName sets the "name" field.
func (dccuo *DailyCategoryContentUpdateOne) SetName(s string) *DailyCategoryContentUpdateOne {
dccuo.mutation.SetName(s)
return dccuo
}
// SetNillableName sets the "name" field if the given value is not nil.
func (dccuo *DailyCategoryContentUpdateOne) SetNillableName(s *string) *DailyCategoryContentUpdateOne {
if s != nil {
dccuo.SetName(*s)
}
return dccuo
}
// SetCategoryID sets the "category" edge to the DailyCategory entity by ID.
func (dccuo *DailyCategoryContentUpdateOne) SetCategoryID(id int) *DailyCategoryContentUpdateOne {
dccuo.mutation.SetCategoryID(id)
return dccuo
}
// SetNillableCategoryID sets the "category" edge to the DailyCategory entity by ID if the given value is not nil.
func (dccuo *DailyCategoryContentUpdateOne) SetNillableCategoryID(id *int) *DailyCategoryContentUpdateOne {
if id != nil {
dccuo = dccuo.SetCategoryID(*id)
}
return dccuo
}
// SetCategory sets the "category" edge to the DailyCategory entity.
func (dccuo *DailyCategoryContentUpdateOne) SetCategory(d *DailyCategory) *DailyCategoryContentUpdateOne {
return dccuo.SetCategoryID(d.ID)
}
// Mutation returns the DailyCategoryContentMutation object of the builder.
func (dccuo *DailyCategoryContentUpdateOne) Mutation() *DailyCategoryContentMutation {
return dccuo.mutation
}
// ClearCategory clears the "category" edge to the DailyCategory entity.
func (dccuo *DailyCategoryContentUpdateOne) ClearCategory() *DailyCategoryContentUpdateOne {
dccuo.mutation.ClearCategory()
return dccuo
}
// Where appends a list predicates to the DailyCategoryContentUpdate builder.
func (dccuo *DailyCategoryContentUpdateOne) Where(ps ...predicate.DailyCategoryContent) *DailyCategoryContentUpdateOne {
dccuo.mutation.Where(ps...)
return dccuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (dccuo *DailyCategoryContentUpdateOne) Select(field string, fields ...string) *DailyCategoryContentUpdateOne {
dccuo.fields = append([]string{field}, fields...)
return dccuo
}
// Save executes the query and returns the updated DailyCategoryContent entity.
func (dccuo *DailyCategoryContentUpdateOne) Save(ctx context.Context) (*DailyCategoryContent, error) {
return withHooks(ctx, dccuo.sqlSave, dccuo.mutation, dccuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (dccuo *DailyCategoryContentUpdateOne) SaveX(ctx context.Context) *DailyCategoryContent {
node, err := dccuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (dccuo *DailyCategoryContentUpdateOne) Exec(ctx context.Context) error {
_, err := dccuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dccuo *DailyCategoryContentUpdateOne) ExecX(ctx context.Context) {
if err := dccuo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (dccuo *DailyCategoryContentUpdateOne) check() error {
if v, ok := dccuo.mutation.LanguageCode(); ok {
if err := dailycategorycontent.LanguageCodeValidator(v); err != nil {
return &ValidationError{Name: "language_code", err: fmt.Errorf(`ent: validator failed for field "DailyCategoryContent.language_code": %w`, err)}
}
}
if v, ok := dccuo.mutation.Name(); ok {
if err := dailycategorycontent.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "DailyCategoryContent.name": %w`, err)}
}
}
return nil
}
func (dccuo *DailyCategoryContentUpdateOne) sqlSave(ctx context.Context) (_node *DailyCategoryContent, err error) {
if err := dccuo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(dailycategorycontent.Table, dailycategorycontent.Columns, sqlgraph.NewFieldSpec(dailycategorycontent.FieldID, field.TypeInt))
id, ok := dccuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "DailyCategoryContent.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := dccuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, dailycategorycontent.FieldID)
for _, f := range fields {
if !dailycategorycontent.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != dailycategorycontent.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := dccuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := dccuo.mutation.LanguageCode(); ok {
_spec.SetField(dailycategorycontent.FieldLanguageCode, field.TypeEnum, value)
}
if value, ok := dccuo.mutation.Name(); ok {
_spec.SetField(dailycategorycontent.FieldName, field.TypeString, value)
}
if dccuo.mutation.CategoryCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: dailycategorycontent.CategoryTable,
Columns: []string{dailycategorycontent.CategoryColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(dailycategory.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dccuo.mutation.CategoryIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: dailycategorycontent.CategoryTable,
Columns: []string{dailycategorycontent.CategoryColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(dailycategory.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &DailyCategoryContent{config: dccuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, dccuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{dailycategorycontent.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
dccuo.mutation.done = true
return _node, nil
}