tss-rocks/backend/ent/dailycontent_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
12 KiB
Go

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