440 lines
15 KiB
Go
440 lines
15 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"tss-rocks-be/ent/contributor"
|
|
"tss-rocks-be/ent/contributorsociallink"
|
|
"tss-rocks-be/ent/predicate"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ContributorSocialLinkUpdate is the builder for updating ContributorSocialLink entities.
|
|
type ContributorSocialLinkUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *ContributorSocialLinkMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the ContributorSocialLinkUpdate builder.
|
|
func (cslu *ContributorSocialLinkUpdate) Where(ps ...predicate.ContributorSocialLink) *ContributorSocialLinkUpdate {
|
|
cslu.mutation.Where(ps...)
|
|
return cslu
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (cslu *ContributorSocialLinkUpdate) SetType(c contributorsociallink.Type) *ContributorSocialLinkUpdate {
|
|
cslu.mutation.SetType(c)
|
|
return cslu
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (cslu *ContributorSocialLinkUpdate) SetNillableType(c *contributorsociallink.Type) *ContributorSocialLinkUpdate {
|
|
if c != nil {
|
|
cslu.SetType(*c)
|
|
}
|
|
return cslu
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (cslu *ContributorSocialLinkUpdate) SetName(s string) *ContributorSocialLinkUpdate {
|
|
cslu.mutation.SetName(s)
|
|
return cslu
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (cslu *ContributorSocialLinkUpdate) SetNillableName(s *string) *ContributorSocialLinkUpdate {
|
|
if s != nil {
|
|
cslu.SetName(*s)
|
|
}
|
|
return cslu
|
|
}
|
|
|
|
// ClearName clears the value of the "name" field.
|
|
func (cslu *ContributorSocialLinkUpdate) ClearName() *ContributorSocialLinkUpdate {
|
|
cslu.mutation.ClearName()
|
|
return cslu
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (cslu *ContributorSocialLinkUpdate) SetValue(s string) *ContributorSocialLinkUpdate {
|
|
cslu.mutation.SetValue(s)
|
|
return cslu
|
|
}
|
|
|
|
// SetNillableValue sets the "value" field if the given value is not nil.
|
|
func (cslu *ContributorSocialLinkUpdate) SetNillableValue(s *string) *ContributorSocialLinkUpdate {
|
|
if s != nil {
|
|
cslu.SetValue(*s)
|
|
}
|
|
return cslu
|
|
}
|
|
|
|
// SetContributorID sets the "contributor" edge to the Contributor entity by ID.
|
|
func (cslu *ContributorSocialLinkUpdate) SetContributorID(id int) *ContributorSocialLinkUpdate {
|
|
cslu.mutation.SetContributorID(id)
|
|
return cslu
|
|
}
|
|
|
|
// SetNillableContributorID sets the "contributor" edge to the Contributor entity by ID if the given value is not nil.
|
|
func (cslu *ContributorSocialLinkUpdate) SetNillableContributorID(id *int) *ContributorSocialLinkUpdate {
|
|
if id != nil {
|
|
cslu = cslu.SetContributorID(*id)
|
|
}
|
|
return cslu
|
|
}
|
|
|
|
// SetContributor sets the "contributor" edge to the Contributor entity.
|
|
func (cslu *ContributorSocialLinkUpdate) SetContributor(c *Contributor) *ContributorSocialLinkUpdate {
|
|
return cslu.SetContributorID(c.ID)
|
|
}
|
|
|
|
// Mutation returns the ContributorSocialLinkMutation object of the builder.
|
|
func (cslu *ContributorSocialLinkUpdate) Mutation() *ContributorSocialLinkMutation {
|
|
return cslu.mutation
|
|
}
|
|
|
|
// ClearContributor clears the "contributor" edge to the Contributor entity.
|
|
func (cslu *ContributorSocialLinkUpdate) ClearContributor() *ContributorSocialLinkUpdate {
|
|
cslu.mutation.ClearContributor()
|
|
return cslu
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (cslu *ContributorSocialLinkUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, cslu.sqlSave, cslu.mutation, cslu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (cslu *ContributorSocialLinkUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := cslu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (cslu *ContributorSocialLinkUpdate) Exec(ctx context.Context) error {
|
|
_, err := cslu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (cslu *ContributorSocialLinkUpdate) ExecX(ctx context.Context) {
|
|
if err := cslu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (cslu *ContributorSocialLinkUpdate) check() error {
|
|
if v, ok := cslu.mutation.GetType(); ok {
|
|
if err := contributorsociallink.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ContributorSocialLink.type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := cslu.mutation.Value(); ok {
|
|
if err := contributorsociallink.ValueValidator(v); err != nil {
|
|
return &ValidationError{Name: "value", err: fmt.Errorf(`ent: validator failed for field "ContributorSocialLink.value": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (cslu *ContributorSocialLinkUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
if err := cslu.check(); err != nil {
|
|
return n, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(contributorsociallink.Table, contributorsociallink.Columns, sqlgraph.NewFieldSpec(contributorsociallink.FieldID, field.TypeInt))
|
|
if ps := cslu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := cslu.mutation.GetType(); ok {
|
|
_spec.SetField(contributorsociallink.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := cslu.mutation.Name(); ok {
|
|
_spec.SetField(contributorsociallink.FieldName, field.TypeString, value)
|
|
}
|
|
if cslu.mutation.NameCleared() {
|
|
_spec.ClearField(contributorsociallink.FieldName, field.TypeString)
|
|
}
|
|
if value, ok := cslu.mutation.Value(); ok {
|
|
_spec.SetField(contributorsociallink.FieldValue, field.TypeString, value)
|
|
}
|
|
if cslu.mutation.ContributorCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: contributorsociallink.ContributorTable,
|
|
Columns: []string{contributorsociallink.ContributorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := cslu.mutation.ContributorIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: contributorsociallink.ContributorTable,
|
|
Columns: []string{contributorsociallink.ContributorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(contributor.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, cslu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{contributorsociallink.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
cslu.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// ContributorSocialLinkUpdateOne is the builder for updating a single ContributorSocialLink entity.
|
|
type ContributorSocialLinkUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *ContributorSocialLinkMutation
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (csluo *ContributorSocialLinkUpdateOne) SetType(c contributorsociallink.Type) *ContributorSocialLinkUpdateOne {
|
|
csluo.mutation.SetType(c)
|
|
return csluo
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (csluo *ContributorSocialLinkUpdateOne) SetNillableType(c *contributorsociallink.Type) *ContributorSocialLinkUpdateOne {
|
|
if c != nil {
|
|
csluo.SetType(*c)
|
|
}
|
|
return csluo
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (csluo *ContributorSocialLinkUpdateOne) SetName(s string) *ContributorSocialLinkUpdateOne {
|
|
csluo.mutation.SetName(s)
|
|
return csluo
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (csluo *ContributorSocialLinkUpdateOne) SetNillableName(s *string) *ContributorSocialLinkUpdateOne {
|
|
if s != nil {
|
|
csluo.SetName(*s)
|
|
}
|
|
return csluo
|
|
}
|
|
|
|
// ClearName clears the value of the "name" field.
|
|
func (csluo *ContributorSocialLinkUpdateOne) ClearName() *ContributorSocialLinkUpdateOne {
|
|
csluo.mutation.ClearName()
|
|
return csluo
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (csluo *ContributorSocialLinkUpdateOne) SetValue(s string) *ContributorSocialLinkUpdateOne {
|
|
csluo.mutation.SetValue(s)
|
|
return csluo
|
|
}
|
|
|
|
// SetNillableValue sets the "value" field if the given value is not nil.
|
|
func (csluo *ContributorSocialLinkUpdateOne) SetNillableValue(s *string) *ContributorSocialLinkUpdateOne {
|
|
if s != nil {
|
|
csluo.SetValue(*s)
|
|
}
|
|
return csluo
|
|
}
|
|
|
|
// SetContributorID sets the "contributor" edge to the Contributor entity by ID.
|
|
func (csluo *ContributorSocialLinkUpdateOne) SetContributorID(id int) *ContributorSocialLinkUpdateOne {
|
|
csluo.mutation.SetContributorID(id)
|
|
return csluo
|
|
}
|
|
|
|
// SetNillableContributorID sets the "contributor" edge to the Contributor entity by ID if the given value is not nil.
|
|
func (csluo *ContributorSocialLinkUpdateOne) SetNillableContributorID(id *int) *ContributorSocialLinkUpdateOne {
|
|
if id != nil {
|
|
csluo = csluo.SetContributorID(*id)
|
|
}
|
|
return csluo
|
|
}
|
|
|
|
// SetContributor sets the "contributor" edge to the Contributor entity.
|
|
func (csluo *ContributorSocialLinkUpdateOne) SetContributor(c *Contributor) *ContributorSocialLinkUpdateOne {
|
|
return csluo.SetContributorID(c.ID)
|
|
}
|
|
|
|
// Mutation returns the ContributorSocialLinkMutation object of the builder.
|
|
func (csluo *ContributorSocialLinkUpdateOne) Mutation() *ContributorSocialLinkMutation {
|
|
return csluo.mutation
|
|
}
|
|
|
|
// ClearContributor clears the "contributor" edge to the Contributor entity.
|
|
func (csluo *ContributorSocialLinkUpdateOne) ClearContributor() *ContributorSocialLinkUpdateOne {
|
|
csluo.mutation.ClearContributor()
|
|
return csluo
|
|
}
|
|
|
|
// Where appends a list predicates to the ContributorSocialLinkUpdate builder.
|
|
func (csluo *ContributorSocialLinkUpdateOne) Where(ps ...predicate.ContributorSocialLink) *ContributorSocialLinkUpdateOne {
|
|
csluo.mutation.Where(ps...)
|
|
return csluo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (csluo *ContributorSocialLinkUpdateOne) Select(field string, fields ...string) *ContributorSocialLinkUpdateOne {
|
|
csluo.fields = append([]string{field}, fields...)
|
|
return csluo
|
|
}
|
|
|
|
// Save executes the query and returns the updated ContributorSocialLink entity.
|
|
func (csluo *ContributorSocialLinkUpdateOne) Save(ctx context.Context) (*ContributorSocialLink, error) {
|
|
return withHooks(ctx, csluo.sqlSave, csluo.mutation, csluo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (csluo *ContributorSocialLinkUpdateOne) SaveX(ctx context.Context) *ContributorSocialLink {
|
|
node, err := csluo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (csluo *ContributorSocialLinkUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := csluo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (csluo *ContributorSocialLinkUpdateOne) ExecX(ctx context.Context) {
|
|
if err := csluo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (csluo *ContributorSocialLinkUpdateOne) check() error {
|
|
if v, ok := csluo.mutation.GetType(); ok {
|
|
if err := contributorsociallink.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ContributorSocialLink.type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := csluo.mutation.Value(); ok {
|
|
if err := contributorsociallink.ValueValidator(v); err != nil {
|
|
return &ValidationError{Name: "value", err: fmt.Errorf(`ent: validator failed for field "ContributorSocialLink.value": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (csluo *ContributorSocialLinkUpdateOne) sqlSave(ctx context.Context) (_node *ContributorSocialLink, err error) {
|
|
if err := csluo.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(contributorsociallink.Table, contributorsociallink.Columns, sqlgraph.NewFieldSpec(contributorsociallink.FieldID, field.TypeInt))
|
|
id, ok := csluo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ContributorSocialLink.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := csluo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, contributorsociallink.FieldID)
|
|
for _, f := range fields {
|
|
if !contributorsociallink.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != contributorsociallink.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := csluo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := csluo.mutation.GetType(); ok {
|
|
_spec.SetField(contributorsociallink.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := csluo.mutation.Name(); ok {
|
|
_spec.SetField(contributorsociallink.FieldName, field.TypeString, value)
|
|
}
|
|
if csluo.mutation.NameCleared() {
|
|
_spec.ClearField(contributorsociallink.FieldName, field.TypeString)
|
|
}
|
|
if value, ok := csluo.mutation.Value(); ok {
|
|
_spec.SetField(contributorsociallink.FieldValue, field.TypeString, value)
|
|
}
|
|
if csluo.mutation.ContributorCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: contributorsociallink.ContributorTable,
|
|
Columns: []string{contributorsociallink.ContributorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := csluo.mutation.ContributorIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: contributorsociallink.ContributorTable,
|
|
Columns: []string{contributorsociallink.ContributorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &ContributorSocialLink{config: csluo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, csluo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{contributorsociallink.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
csluo.mutation.done = true
|
|
return _node, nil
|
|
}
|