324 lines
8.7 KiB
Go
324 lines
8.7 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/FrankenBotDev/FrankenAPI/ent/predicate"
|
|
"github.com/FrankenBotDev/FrankenAPI/ent/socialmedia"
|
|
)
|
|
|
|
// SocialmediaUpdate is the builder for updating Socialmedia entities.
|
|
type SocialmediaUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *SocialmediaMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the SocialmediaUpdate builder.
|
|
func (su *SocialmediaUpdate) Where(ps ...predicate.Socialmedia) *SocialmediaUpdate {
|
|
su.mutation.Where(ps...)
|
|
return su
|
|
}
|
|
|
|
// SetServerid sets the "serverid" field.
|
|
func (su *SocialmediaUpdate) SetServerid(s string) *SocialmediaUpdate {
|
|
su.mutation.SetServerid(s)
|
|
return su
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (su *SocialmediaUpdate) SetType(s string) *SocialmediaUpdate {
|
|
su.mutation.SetType(s)
|
|
return su
|
|
}
|
|
|
|
// SetIdentificator sets the "identificator" field.
|
|
func (su *SocialmediaUpdate) SetIdentificator(s string) *SocialmediaUpdate {
|
|
su.mutation.SetIdentificator(s)
|
|
return su
|
|
}
|
|
|
|
// Mutation returns the SocialmediaMutation object of the builder.
|
|
func (su *SocialmediaUpdate) Mutation() *SocialmediaMutation {
|
|
return su.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (su *SocialmediaUpdate) Save(ctx context.Context) (int, error) {
|
|
var (
|
|
err error
|
|
affected int
|
|
)
|
|
if len(su.hooks) == 0 {
|
|
affected, err = su.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*SocialmediaMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
su.mutation = mutation
|
|
affected, err = su.sqlSave(ctx)
|
|
mutation.done = true
|
|
return affected, err
|
|
})
|
|
for i := len(su.hooks) - 1; i >= 0; i-- {
|
|
if su.hooks[i] == nil {
|
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = su.hooks[i](mut)
|
|
}
|
|
if _, err := mut.Mutate(ctx, su.mutation); err != nil {
|
|
return 0, err
|
|
}
|
|
}
|
|
return affected, err
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (su *SocialmediaUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := su.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (su *SocialmediaUpdate) Exec(ctx context.Context) error {
|
|
_, err := su.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (su *SocialmediaUpdate) ExecX(ctx context.Context) {
|
|
if err := su.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (su *SocialmediaUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: socialmedia.Table,
|
|
Columns: socialmedia.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: socialmedia.FieldID,
|
|
},
|
|
},
|
|
}
|
|
if ps := su.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := su.mutation.Serverid(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: socialmedia.FieldServerid,
|
|
})
|
|
}
|
|
if value, ok := su.mutation.GetType(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: socialmedia.FieldType,
|
|
})
|
|
}
|
|
if value, ok := su.mutation.Identificator(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: socialmedia.FieldIdentificator,
|
|
})
|
|
}
|
|
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{socialmedia.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
return n, nil
|
|
}
|
|
|
|
// SocialmediaUpdateOne is the builder for updating a single Socialmedia entity.
|
|
type SocialmediaUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *SocialmediaMutation
|
|
}
|
|
|
|
// SetServerid sets the "serverid" field.
|
|
func (suo *SocialmediaUpdateOne) SetServerid(s string) *SocialmediaUpdateOne {
|
|
suo.mutation.SetServerid(s)
|
|
return suo
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (suo *SocialmediaUpdateOne) SetType(s string) *SocialmediaUpdateOne {
|
|
suo.mutation.SetType(s)
|
|
return suo
|
|
}
|
|
|
|
// SetIdentificator sets the "identificator" field.
|
|
func (suo *SocialmediaUpdateOne) SetIdentificator(s string) *SocialmediaUpdateOne {
|
|
suo.mutation.SetIdentificator(s)
|
|
return suo
|
|
}
|
|
|
|
// Mutation returns the SocialmediaMutation object of the builder.
|
|
func (suo *SocialmediaUpdateOne) Mutation() *SocialmediaMutation {
|
|
return suo.mutation
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (suo *SocialmediaUpdateOne) Select(field string, fields ...string) *SocialmediaUpdateOne {
|
|
suo.fields = append([]string{field}, fields...)
|
|
return suo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Socialmedia entity.
|
|
func (suo *SocialmediaUpdateOne) Save(ctx context.Context) (*Socialmedia, error) {
|
|
var (
|
|
err error
|
|
node *Socialmedia
|
|
)
|
|
if len(suo.hooks) == 0 {
|
|
node, err = suo.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*SocialmediaMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
suo.mutation = mutation
|
|
node, err = suo.sqlSave(ctx)
|
|
mutation.done = true
|
|
return node, err
|
|
})
|
|
for i := len(suo.hooks) - 1; i >= 0; i-- {
|
|
if suo.hooks[i] == nil {
|
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = suo.hooks[i](mut)
|
|
}
|
|
v, err := mut.Mutate(ctx, suo.mutation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
nv, ok := v.(*Socialmedia)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected node type %T returned from SocialmediaMutation", v)
|
|
}
|
|
node = nv
|
|
}
|
|
return node, err
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (suo *SocialmediaUpdateOne) SaveX(ctx context.Context) *Socialmedia {
|
|
node, err := suo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (suo *SocialmediaUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := suo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (suo *SocialmediaUpdateOne) ExecX(ctx context.Context) {
|
|
if err := suo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (suo *SocialmediaUpdateOne) sqlSave(ctx context.Context) (_node *Socialmedia, err error) {
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: socialmedia.Table,
|
|
Columns: socialmedia.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: socialmedia.FieldID,
|
|
},
|
|
},
|
|
}
|
|
id, ok := suo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Socialmedia.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := suo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, socialmedia.FieldID)
|
|
for _, f := range fields {
|
|
if !socialmedia.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != socialmedia.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := suo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := suo.mutation.Serverid(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: socialmedia.FieldServerid,
|
|
})
|
|
}
|
|
if value, ok := suo.mutation.GetType(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: socialmedia.FieldType,
|
|
})
|
|
}
|
|
if value, ok := suo.mutation.Identificator(); ok {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: socialmedia.FieldIdentificator,
|
|
})
|
|
}
|
|
_node = &Socialmedia{config: suo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{socialmedia.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
return _node, nil
|
|
}
|