426 lines
13 KiB
Go
426 lines
13 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"
|
|
"tinyskin/db/ent/predicate"
|
|
"tinyskin/db/ent/texture"
|
|
"tinyskin/db/ent/userprofile"
|
|
"tinyskin/db/ent/usertexture"
|
|
)
|
|
|
|
// UserTextureUpdate is the builder for updating UserTexture entities.
|
|
type UserTextureUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *UserTextureMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the UserTextureUpdate builder.
|
|
func (utu *UserTextureUpdate) Where(ps ...predicate.UserTexture) *UserTextureUpdate {
|
|
utu.mutation.Where(ps...)
|
|
return utu
|
|
}
|
|
|
|
// SetUserProfileID sets the "user_profile_id" field.
|
|
func (utu *UserTextureUpdate) SetUserProfileID(i int) *UserTextureUpdate {
|
|
utu.mutation.SetUserProfileID(i)
|
|
return utu
|
|
}
|
|
|
|
// SetTextureID sets the "texture_id" field.
|
|
func (utu *UserTextureUpdate) SetTextureID(i int) *UserTextureUpdate {
|
|
utu.mutation.SetTextureID(i)
|
|
return utu
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (utu *UserTextureUpdate) SetType(s string) *UserTextureUpdate {
|
|
utu.mutation.SetType(s)
|
|
return utu
|
|
}
|
|
|
|
// SetVariant sets the "variant" field.
|
|
func (utu *UserTextureUpdate) SetVariant(s string) *UserTextureUpdate {
|
|
utu.mutation.SetVariant(s)
|
|
return utu
|
|
}
|
|
|
|
// SetUserProfile sets the "user_profile" edge to the UserProfile entity.
|
|
func (utu *UserTextureUpdate) SetUserProfile(u *UserProfile) *UserTextureUpdate {
|
|
return utu.SetUserProfileID(u.ID)
|
|
}
|
|
|
|
// SetTexture sets the "texture" edge to the Texture entity.
|
|
func (utu *UserTextureUpdate) SetTexture(t *Texture) *UserTextureUpdate {
|
|
return utu.SetTextureID(t.ID)
|
|
}
|
|
|
|
// Mutation returns the UserTextureMutation object of the builder.
|
|
func (utu *UserTextureUpdate) Mutation() *UserTextureMutation {
|
|
return utu.mutation
|
|
}
|
|
|
|
// ClearUserProfile clears the "user_profile" edge to the UserProfile entity.
|
|
func (utu *UserTextureUpdate) ClearUserProfile() *UserTextureUpdate {
|
|
utu.mutation.ClearUserProfile()
|
|
return utu
|
|
}
|
|
|
|
// ClearTexture clears the "texture" edge to the Texture entity.
|
|
func (utu *UserTextureUpdate) ClearTexture() *UserTextureUpdate {
|
|
utu.mutation.ClearTexture()
|
|
return utu
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (utu *UserTextureUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, utu.sqlSave, utu.mutation, utu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (utu *UserTextureUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := utu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (utu *UserTextureUpdate) Exec(ctx context.Context) error {
|
|
_, err := utu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (utu *UserTextureUpdate) ExecX(ctx context.Context) {
|
|
if err := utu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (utu *UserTextureUpdate) check() error {
|
|
if _, ok := utu.mutation.UserProfileID(); utu.mutation.UserProfileCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "UserTexture.user_profile"`)
|
|
}
|
|
if _, ok := utu.mutation.TextureID(); utu.mutation.TextureCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "UserTexture.texture"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (utu *UserTextureUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
if err := utu.check(); err != nil {
|
|
return n, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(usertexture.Table, usertexture.Columns, sqlgraph.NewFieldSpec(usertexture.FieldID, field.TypeInt))
|
|
if ps := utu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := utu.mutation.GetType(); ok {
|
|
_spec.SetField(usertexture.FieldType, field.TypeString, value)
|
|
}
|
|
if value, ok := utu.mutation.Variant(); ok {
|
|
_spec.SetField(usertexture.FieldVariant, field.TypeString, value)
|
|
}
|
|
if utu.mutation.UserProfileCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: usertexture.UserProfileTable,
|
|
Columns: []string{usertexture.UserProfileColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(userprofile.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := utu.mutation.UserProfileIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: usertexture.UserProfileTable,
|
|
Columns: []string{usertexture.UserProfileColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(userprofile.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if utu.mutation.TextureCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: usertexture.TextureTable,
|
|
Columns: []string{usertexture.TextureColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := utu.mutation.TextureIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: usertexture.TextureTable,
|
|
Columns: []string{usertexture.TextureColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(texture.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, utu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{usertexture.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
utu.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// UserTextureUpdateOne is the builder for updating a single UserTexture entity.
|
|
type UserTextureUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *UserTextureMutation
|
|
}
|
|
|
|
// SetUserProfileID sets the "user_profile_id" field.
|
|
func (utuo *UserTextureUpdateOne) SetUserProfileID(i int) *UserTextureUpdateOne {
|
|
utuo.mutation.SetUserProfileID(i)
|
|
return utuo
|
|
}
|
|
|
|
// SetTextureID sets the "texture_id" field.
|
|
func (utuo *UserTextureUpdateOne) SetTextureID(i int) *UserTextureUpdateOne {
|
|
utuo.mutation.SetTextureID(i)
|
|
return utuo
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (utuo *UserTextureUpdateOne) SetType(s string) *UserTextureUpdateOne {
|
|
utuo.mutation.SetType(s)
|
|
return utuo
|
|
}
|
|
|
|
// SetVariant sets the "variant" field.
|
|
func (utuo *UserTextureUpdateOne) SetVariant(s string) *UserTextureUpdateOne {
|
|
utuo.mutation.SetVariant(s)
|
|
return utuo
|
|
}
|
|
|
|
// SetUserProfile sets the "user_profile" edge to the UserProfile entity.
|
|
func (utuo *UserTextureUpdateOne) SetUserProfile(u *UserProfile) *UserTextureUpdateOne {
|
|
return utuo.SetUserProfileID(u.ID)
|
|
}
|
|
|
|
// SetTexture sets the "texture" edge to the Texture entity.
|
|
func (utuo *UserTextureUpdateOne) SetTexture(t *Texture) *UserTextureUpdateOne {
|
|
return utuo.SetTextureID(t.ID)
|
|
}
|
|
|
|
// Mutation returns the UserTextureMutation object of the builder.
|
|
func (utuo *UserTextureUpdateOne) Mutation() *UserTextureMutation {
|
|
return utuo.mutation
|
|
}
|
|
|
|
// ClearUserProfile clears the "user_profile" edge to the UserProfile entity.
|
|
func (utuo *UserTextureUpdateOne) ClearUserProfile() *UserTextureUpdateOne {
|
|
utuo.mutation.ClearUserProfile()
|
|
return utuo
|
|
}
|
|
|
|
// ClearTexture clears the "texture" edge to the Texture entity.
|
|
func (utuo *UserTextureUpdateOne) ClearTexture() *UserTextureUpdateOne {
|
|
utuo.mutation.ClearTexture()
|
|
return utuo
|
|
}
|
|
|
|
// Where appends a list predicates to the UserTextureUpdate builder.
|
|
func (utuo *UserTextureUpdateOne) Where(ps ...predicate.UserTexture) *UserTextureUpdateOne {
|
|
utuo.mutation.Where(ps...)
|
|
return utuo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (utuo *UserTextureUpdateOne) Select(field string, fields ...string) *UserTextureUpdateOne {
|
|
utuo.fields = append([]string{field}, fields...)
|
|
return utuo
|
|
}
|
|
|
|
// Save executes the query and returns the updated UserTexture entity.
|
|
func (utuo *UserTextureUpdateOne) Save(ctx context.Context) (*UserTexture, error) {
|
|
return withHooks(ctx, utuo.sqlSave, utuo.mutation, utuo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (utuo *UserTextureUpdateOne) SaveX(ctx context.Context) *UserTexture {
|
|
node, err := utuo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (utuo *UserTextureUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := utuo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (utuo *UserTextureUpdateOne) ExecX(ctx context.Context) {
|
|
if err := utuo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (utuo *UserTextureUpdateOne) check() error {
|
|
if _, ok := utuo.mutation.UserProfileID(); utuo.mutation.UserProfileCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "UserTexture.user_profile"`)
|
|
}
|
|
if _, ok := utuo.mutation.TextureID(); utuo.mutation.TextureCleared() && !ok {
|
|
return errors.New(`ent: clearing a required unique edge "UserTexture.texture"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (utuo *UserTextureUpdateOne) sqlSave(ctx context.Context) (_node *UserTexture, err error) {
|
|
if err := utuo.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(usertexture.Table, usertexture.Columns, sqlgraph.NewFieldSpec(usertexture.FieldID, field.TypeInt))
|
|
id, ok := utuo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserTexture.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := utuo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, usertexture.FieldID)
|
|
for _, f := range fields {
|
|
if !usertexture.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != usertexture.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := utuo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := utuo.mutation.GetType(); ok {
|
|
_spec.SetField(usertexture.FieldType, field.TypeString, value)
|
|
}
|
|
if value, ok := utuo.mutation.Variant(); ok {
|
|
_spec.SetField(usertexture.FieldVariant, field.TypeString, value)
|
|
}
|
|
if utuo.mutation.UserProfileCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: usertexture.UserProfileTable,
|
|
Columns: []string{usertexture.UserProfileColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(userprofile.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := utuo.mutation.UserProfileIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: usertexture.UserProfileTable,
|
|
Columns: []string{usertexture.UserProfileColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(userprofile.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if utuo.mutation.TextureCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: usertexture.TextureTable,
|
|
Columns: []string{usertexture.TextureColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := utuo.mutation.TextureIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: usertexture.TextureTable,
|
|
Columns: []string{usertexture.TextureColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &UserTexture{config: utuo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, utuo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{usertexture.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
utuo.mutation.done = true
|
|
return _node, nil
|
|
}
|