Files

1074 lines
34 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"registry-backend/ent/node"
"registry-backend/ent/personalaccesstoken"
"registry-backend/ent/predicate"
"registry-backend/ent/publisher"
"registry-backend/ent/publisherpermission"
"registry-backend/ent/schema"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// PublisherUpdate is the builder for updating Publisher entities.
type PublisherUpdate struct {
config
hooks []Hook
mutation *PublisherMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the PublisherUpdate builder.
func (pu *PublisherUpdate) Where(ps ...predicate.Publisher) *PublisherUpdate {
pu.mutation.Where(ps...)
return pu
}
// SetUpdateTime sets the "update_time" field.
func (pu *PublisherUpdate) SetUpdateTime(t time.Time) *PublisherUpdate {
pu.mutation.SetUpdateTime(t)
return pu
}
// SetName sets the "name" field.
func (pu *PublisherUpdate) SetName(s string) *PublisherUpdate {
pu.mutation.SetName(s)
return pu
}
// SetNillableName sets the "name" field if the given value is not nil.
func (pu *PublisherUpdate) SetNillableName(s *string) *PublisherUpdate {
if s != nil {
pu.SetName(*s)
}
return pu
}
// SetDescription sets the "description" field.
func (pu *PublisherUpdate) SetDescription(s string) *PublisherUpdate {
pu.mutation.SetDescription(s)
return pu
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (pu *PublisherUpdate) SetNillableDescription(s *string) *PublisherUpdate {
if s != nil {
pu.SetDescription(*s)
}
return pu
}
// ClearDescription clears the value of the "description" field.
func (pu *PublisherUpdate) ClearDescription() *PublisherUpdate {
pu.mutation.ClearDescription()
return pu
}
// SetWebsite sets the "website" field.
func (pu *PublisherUpdate) SetWebsite(s string) *PublisherUpdate {
pu.mutation.SetWebsite(s)
return pu
}
// SetNillableWebsite sets the "website" field if the given value is not nil.
func (pu *PublisherUpdate) SetNillableWebsite(s *string) *PublisherUpdate {
if s != nil {
pu.SetWebsite(*s)
}
return pu
}
// ClearWebsite clears the value of the "website" field.
func (pu *PublisherUpdate) ClearWebsite() *PublisherUpdate {
pu.mutation.ClearWebsite()
return pu
}
// SetSupportEmail sets the "support_email" field.
func (pu *PublisherUpdate) SetSupportEmail(s string) *PublisherUpdate {
pu.mutation.SetSupportEmail(s)
return pu
}
// SetNillableSupportEmail sets the "support_email" field if the given value is not nil.
func (pu *PublisherUpdate) SetNillableSupportEmail(s *string) *PublisherUpdate {
if s != nil {
pu.SetSupportEmail(*s)
}
return pu
}
// ClearSupportEmail clears the value of the "support_email" field.
func (pu *PublisherUpdate) ClearSupportEmail() *PublisherUpdate {
pu.mutation.ClearSupportEmail()
return pu
}
// SetSourceCodeRepo sets the "source_code_repo" field.
func (pu *PublisherUpdate) SetSourceCodeRepo(s string) *PublisherUpdate {
pu.mutation.SetSourceCodeRepo(s)
return pu
}
// SetNillableSourceCodeRepo sets the "source_code_repo" field if the given value is not nil.
func (pu *PublisherUpdate) SetNillableSourceCodeRepo(s *string) *PublisherUpdate {
if s != nil {
pu.SetSourceCodeRepo(*s)
}
return pu
}
// ClearSourceCodeRepo clears the value of the "source_code_repo" field.
func (pu *PublisherUpdate) ClearSourceCodeRepo() *PublisherUpdate {
pu.mutation.ClearSourceCodeRepo()
return pu
}
// SetLogoURL sets the "logo_url" field.
func (pu *PublisherUpdate) SetLogoURL(s string) *PublisherUpdate {
pu.mutation.SetLogoURL(s)
return pu
}
// SetNillableLogoURL sets the "logo_url" field if the given value is not nil.
func (pu *PublisherUpdate) SetNillableLogoURL(s *string) *PublisherUpdate {
if s != nil {
pu.SetLogoURL(*s)
}
return pu
}
// ClearLogoURL clears the value of the "logo_url" field.
func (pu *PublisherUpdate) ClearLogoURL() *PublisherUpdate {
pu.mutation.ClearLogoURL()
return pu
}
// SetStatus sets the "status" field.
func (pu *PublisherUpdate) SetStatus(sst schema.PublisherStatusType) *PublisherUpdate {
pu.mutation.SetStatus(sst)
return pu
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (pu *PublisherUpdate) SetNillableStatus(sst *schema.PublisherStatusType) *PublisherUpdate {
if sst != nil {
pu.SetStatus(*sst)
}
return pu
}
// AddPublisherPermissionIDs adds the "publisher_permissions" edge to the PublisherPermission entity by IDs.
func (pu *PublisherUpdate) AddPublisherPermissionIDs(ids ...int) *PublisherUpdate {
pu.mutation.AddPublisherPermissionIDs(ids...)
return pu
}
// AddPublisherPermissions adds the "publisher_permissions" edges to the PublisherPermission entity.
func (pu *PublisherUpdate) AddPublisherPermissions(p ...*PublisherPermission) *PublisherUpdate {
ids := make([]int, len(p))
for i := range p {
ids[i] = p[i].ID
}
return pu.AddPublisherPermissionIDs(ids...)
}
// AddNodeIDs adds the "nodes" edge to the Node entity by IDs.
func (pu *PublisherUpdate) AddNodeIDs(ids ...string) *PublisherUpdate {
pu.mutation.AddNodeIDs(ids...)
return pu
}
// AddNodes adds the "nodes" edges to the Node entity.
func (pu *PublisherUpdate) AddNodes(n ...*Node) *PublisherUpdate {
ids := make([]string, len(n))
for i := range n {
ids[i] = n[i].ID
}
return pu.AddNodeIDs(ids...)
}
// AddPersonalAccessTokenIDs adds the "personal_access_tokens" edge to the PersonalAccessToken entity by IDs.
func (pu *PublisherUpdate) AddPersonalAccessTokenIDs(ids ...uuid.UUID) *PublisherUpdate {
pu.mutation.AddPersonalAccessTokenIDs(ids...)
return pu
}
// AddPersonalAccessTokens adds the "personal_access_tokens" edges to the PersonalAccessToken entity.
func (pu *PublisherUpdate) AddPersonalAccessTokens(p ...*PersonalAccessToken) *PublisherUpdate {
ids := make([]uuid.UUID, len(p))
for i := range p {
ids[i] = p[i].ID
}
return pu.AddPersonalAccessTokenIDs(ids...)
}
// Mutation returns the PublisherMutation object of the builder.
func (pu *PublisherUpdate) Mutation() *PublisherMutation {
return pu.mutation
}
// ClearPublisherPermissions clears all "publisher_permissions" edges to the PublisherPermission entity.
func (pu *PublisherUpdate) ClearPublisherPermissions() *PublisherUpdate {
pu.mutation.ClearPublisherPermissions()
return pu
}
// RemovePublisherPermissionIDs removes the "publisher_permissions" edge to PublisherPermission entities by IDs.
func (pu *PublisherUpdate) RemovePublisherPermissionIDs(ids ...int) *PublisherUpdate {
pu.mutation.RemovePublisherPermissionIDs(ids...)
return pu
}
// RemovePublisherPermissions removes "publisher_permissions" edges to PublisherPermission entities.
func (pu *PublisherUpdate) RemovePublisherPermissions(p ...*PublisherPermission) *PublisherUpdate {
ids := make([]int, len(p))
for i := range p {
ids[i] = p[i].ID
}
return pu.RemovePublisherPermissionIDs(ids...)
}
// ClearNodes clears all "nodes" edges to the Node entity.
func (pu *PublisherUpdate) ClearNodes() *PublisherUpdate {
pu.mutation.ClearNodes()
return pu
}
// RemoveNodeIDs removes the "nodes" edge to Node entities by IDs.
func (pu *PublisherUpdate) RemoveNodeIDs(ids ...string) *PublisherUpdate {
pu.mutation.RemoveNodeIDs(ids...)
return pu
}
// RemoveNodes removes "nodes" edges to Node entities.
func (pu *PublisherUpdate) RemoveNodes(n ...*Node) *PublisherUpdate {
ids := make([]string, len(n))
for i := range n {
ids[i] = n[i].ID
}
return pu.RemoveNodeIDs(ids...)
}
// ClearPersonalAccessTokens clears all "personal_access_tokens" edges to the PersonalAccessToken entity.
func (pu *PublisherUpdate) ClearPersonalAccessTokens() *PublisherUpdate {
pu.mutation.ClearPersonalAccessTokens()
return pu
}
// RemovePersonalAccessTokenIDs removes the "personal_access_tokens" edge to PersonalAccessToken entities by IDs.
func (pu *PublisherUpdate) RemovePersonalAccessTokenIDs(ids ...uuid.UUID) *PublisherUpdate {
pu.mutation.RemovePersonalAccessTokenIDs(ids...)
return pu
}
// RemovePersonalAccessTokens removes "personal_access_tokens" edges to PersonalAccessToken entities.
func (pu *PublisherUpdate) RemovePersonalAccessTokens(p ...*PersonalAccessToken) *PublisherUpdate {
ids := make([]uuid.UUID, len(p))
for i := range p {
ids[i] = p[i].ID
}
return pu.RemovePersonalAccessTokenIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (pu *PublisherUpdate) Save(ctx context.Context) (int, error) {
pu.defaults()
return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (pu *PublisherUpdate) SaveX(ctx context.Context) int {
affected, err := pu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (pu *PublisherUpdate) Exec(ctx context.Context) error {
_, err := pu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (pu *PublisherUpdate) ExecX(ctx context.Context) {
if err := pu.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (pu *PublisherUpdate) defaults() {
if _, ok := pu.mutation.UpdateTime(); !ok {
v := publisher.UpdateDefaultUpdateTime()
pu.mutation.SetUpdateTime(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (pu *PublisherUpdate) check() error {
if v, ok := pu.mutation.Status(); ok {
if err := publisher.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Publisher.status": %w`, err)}
}
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (pu *PublisherUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *PublisherUpdate {
pu.modifiers = append(pu.modifiers, modifiers...)
return pu
}
func (pu *PublisherUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := pu.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(publisher.Table, publisher.Columns, sqlgraph.NewFieldSpec(publisher.FieldID, field.TypeString))
if ps := pu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := pu.mutation.UpdateTime(); ok {
_spec.SetField(publisher.FieldUpdateTime, field.TypeTime, value)
}
if value, ok := pu.mutation.Name(); ok {
_spec.SetField(publisher.FieldName, field.TypeString, value)
}
if value, ok := pu.mutation.Description(); ok {
_spec.SetField(publisher.FieldDescription, field.TypeString, value)
}
if pu.mutation.DescriptionCleared() {
_spec.ClearField(publisher.FieldDescription, field.TypeString)
}
if value, ok := pu.mutation.Website(); ok {
_spec.SetField(publisher.FieldWebsite, field.TypeString, value)
}
if pu.mutation.WebsiteCleared() {
_spec.ClearField(publisher.FieldWebsite, field.TypeString)
}
if value, ok := pu.mutation.SupportEmail(); ok {
_spec.SetField(publisher.FieldSupportEmail, field.TypeString, value)
}
if pu.mutation.SupportEmailCleared() {
_spec.ClearField(publisher.FieldSupportEmail, field.TypeString)
}
if value, ok := pu.mutation.SourceCodeRepo(); ok {
_spec.SetField(publisher.FieldSourceCodeRepo, field.TypeString, value)
}
if pu.mutation.SourceCodeRepoCleared() {
_spec.ClearField(publisher.FieldSourceCodeRepo, field.TypeString)
}
if value, ok := pu.mutation.LogoURL(); ok {
_spec.SetField(publisher.FieldLogoURL, field.TypeString, value)
}
if pu.mutation.LogoURLCleared() {
_spec.ClearField(publisher.FieldLogoURL, field.TypeString)
}
if value, ok := pu.mutation.Status(); ok {
_spec.SetField(publisher.FieldStatus, field.TypeEnum, value)
}
if pu.mutation.PublisherPermissionsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PublisherPermissionsTable,
Columns: []string{publisher.PublisherPermissionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(publisherpermission.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pu.mutation.RemovedPublisherPermissionsIDs(); len(nodes) > 0 && !pu.mutation.PublisherPermissionsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PublisherPermissionsTable,
Columns: []string{publisher.PublisherPermissionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(publisherpermission.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pu.mutation.PublisherPermissionsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PublisherPermissionsTable,
Columns: []string{publisher.PublisherPermissionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(publisherpermission.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if pu.mutation.NodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.NodesTable,
Columns: []string{publisher.NodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pu.mutation.RemovedNodesIDs(); len(nodes) > 0 && !pu.mutation.NodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.NodesTable,
Columns: []string{publisher.NodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pu.mutation.NodesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.NodesTable,
Columns: []string{publisher.NodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if pu.mutation.PersonalAccessTokensCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PersonalAccessTokensTable,
Columns: []string{publisher.PersonalAccessTokensColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(personalaccesstoken.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pu.mutation.RemovedPersonalAccessTokensIDs(); len(nodes) > 0 && !pu.mutation.PersonalAccessTokensCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PersonalAccessTokensTable,
Columns: []string{publisher.PersonalAccessTokensColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(personalaccesstoken.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := pu.mutation.PersonalAccessTokensIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PersonalAccessTokensTable,
Columns: []string{publisher.PersonalAccessTokensColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(personalaccesstoken.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(pu.modifiers...)
if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{publisher.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
pu.mutation.done = true
return n, nil
}
// PublisherUpdateOne is the builder for updating a single Publisher entity.
type PublisherUpdateOne struct {
config
fields []string
hooks []Hook
mutation *PublisherMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetUpdateTime sets the "update_time" field.
func (puo *PublisherUpdateOne) SetUpdateTime(t time.Time) *PublisherUpdateOne {
puo.mutation.SetUpdateTime(t)
return puo
}
// SetName sets the "name" field.
func (puo *PublisherUpdateOne) SetName(s string) *PublisherUpdateOne {
puo.mutation.SetName(s)
return puo
}
// SetNillableName sets the "name" field if the given value is not nil.
func (puo *PublisherUpdateOne) SetNillableName(s *string) *PublisherUpdateOne {
if s != nil {
puo.SetName(*s)
}
return puo
}
// SetDescription sets the "description" field.
func (puo *PublisherUpdateOne) SetDescription(s string) *PublisherUpdateOne {
puo.mutation.SetDescription(s)
return puo
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (puo *PublisherUpdateOne) SetNillableDescription(s *string) *PublisherUpdateOne {
if s != nil {
puo.SetDescription(*s)
}
return puo
}
// ClearDescription clears the value of the "description" field.
func (puo *PublisherUpdateOne) ClearDescription() *PublisherUpdateOne {
puo.mutation.ClearDescription()
return puo
}
// SetWebsite sets the "website" field.
func (puo *PublisherUpdateOne) SetWebsite(s string) *PublisherUpdateOne {
puo.mutation.SetWebsite(s)
return puo
}
// SetNillableWebsite sets the "website" field if the given value is not nil.
func (puo *PublisherUpdateOne) SetNillableWebsite(s *string) *PublisherUpdateOne {
if s != nil {
puo.SetWebsite(*s)
}
return puo
}
// ClearWebsite clears the value of the "website" field.
func (puo *PublisherUpdateOne) ClearWebsite() *PublisherUpdateOne {
puo.mutation.ClearWebsite()
return puo
}
// SetSupportEmail sets the "support_email" field.
func (puo *PublisherUpdateOne) SetSupportEmail(s string) *PublisherUpdateOne {
puo.mutation.SetSupportEmail(s)
return puo
}
// SetNillableSupportEmail sets the "support_email" field if the given value is not nil.
func (puo *PublisherUpdateOne) SetNillableSupportEmail(s *string) *PublisherUpdateOne {
if s != nil {
puo.SetSupportEmail(*s)
}
return puo
}
// ClearSupportEmail clears the value of the "support_email" field.
func (puo *PublisherUpdateOne) ClearSupportEmail() *PublisherUpdateOne {
puo.mutation.ClearSupportEmail()
return puo
}
// SetSourceCodeRepo sets the "source_code_repo" field.
func (puo *PublisherUpdateOne) SetSourceCodeRepo(s string) *PublisherUpdateOne {
puo.mutation.SetSourceCodeRepo(s)
return puo
}
// SetNillableSourceCodeRepo sets the "source_code_repo" field if the given value is not nil.
func (puo *PublisherUpdateOne) SetNillableSourceCodeRepo(s *string) *PublisherUpdateOne {
if s != nil {
puo.SetSourceCodeRepo(*s)
}
return puo
}
// ClearSourceCodeRepo clears the value of the "source_code_repo" field.
func (puo *PublisherUpdateOne) ClearSourceCodeRepo() *PublisherUpdateOne {
puo.mutation.ClearSourceCodeRepo()
return puo
}
// SetLogoURL sets the "logo_url" field.
func (puo *PublisherUpdateOne) SetLogoURL(s string) *PublisherUpdateOne {
puo.mutation.SetLogoURL(s)
return puo
}
// SetNillableLogoURL sets the "logo_url" field if the given value is not nil.
func (puo *PublisherUpdateOne) SetNillableLogoURL(s *string) *PublisherUpdateOne {
if s != nil {
puo.SetLogoURL(*s)
}
return puo
}
// ClearLogoURL clears the value of the "logo_url" field.
func (puo *PublisherUpdateOne) ClearLogoURL() *PublisherUpdateOne {
puo.mutation.ClearLogoURL()
return puo
}
// SetStatus sets the "status" field.
func (puo *PublisherUpdateOne) SetStatus(sst schema.PublisherStatusType) *PublisherUpdateOne {
puo.mutation.SetStatus(sst)
return puo
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (puo *PublisherUpdateOne) SetNillableStatus(sst *schema.PublisherStatusType) *PublisherUpdateOne {
if sst != nil {
puo.SetStatus(*sst)
}
return puo
}
// AddPublisherPermissionIDs adds the "publisher_permissions" edge to the PublisherPermission entity by IDs.
func (puo *PublisherUpdateOne) AddPublisherPermissionIDs(ids ...int) *PublisherUpdateOne {
puo.mutation.AddPublisherPermissionIDs(ids...)
return puo
}
// AddPublisherPermissions adds the "publisher_permissions" edges to the PublisherPermission entity.
func (puo *PublisherUpdateOne) AddPublisherPermissions(p ...*PublisherPermission) *PublisherUpdateOne {
ids := make([]int, len(p))
for i := range p {
ids[i] = p[i].ID
}
return puo.AddPublisherPermissionIDs(ids...)
}
// AddNodeIDs adds the "nodes" edge to the Node entity by IDs.
func (puo *PublisherUpdateOne) AddNodeIDs(ids ...string) *PublisherUpdateOne {
puo.mutation.AddNodeIDs(ids...)
return puo
}
// AddNodes adds the "nodes" edges to the Node entity.
func (puo *PublisherUpdateOne) AddNodes(n ...*Node) *PublisherUpdateOne {
ids := make([]string, len(n))
for i := range n {
ids[i] = n[i].ID
}
return puo.AddNodeIDs(ids...)
}
// AddPersonalAccessTokenIDs adds the "personal_access_tokens" edge to the PersonalAccessToken entity by IDs.
func (puo *PublisherUpdateOne) AddPersonalAccessTokenIDs(ids ...uuid.UUID) *PublisherUpdateOne {
puo.mutation.AddPersonalAccessTokenIDs(ids...)
return puo
}
// AddPersonalAccessTokens adds the "personal_access_tokens" edges to the PersonalAccessToken entity.
func (puo *PublisherUpdateOne) AddPersonalAccessTokens(p ...*PersonalAccessToken) *PublisherUpdateOne {
ids := make([]uuid.UUID, len(p))
for i := range p {
ids[i] = p[i].ID
}
return puo.AddPersonalAccessTokenIDs(ids...)
}
// Mutation returns the PublisherMutation object of the builder.
func (puo *PublisherUpdateOne) Mutation() *PublisherMutation {
return puo.mutation
}
// ClearPublisherPermissions clears all "publisher_permissions" edges to the PublisherPermission entity.
func (puo *PublisherUpdateOne) ClearPublisherPermissions() *PublisherUpdateOne {
puo.mutation.ClearPublisherPermissions()
return puo
}
// RemovePublisherPermissionIDs removes the "publisher_permissions" edge to PublisherPermission entities by IDs.
func (puo *PublisherUpdateOne) RemovePublisherPermissionIDs(ids ...int) *PublisherUpdateOne {
puo.mutation.RemovePublisherPermissionIDs(ids...)
return puo
}
// RemovePublisherPermissions removes "publisher_permissions" edges to PublisherPermission entities.
func (puo *PublisherUpdateOne) RemovePublisherPermissions(p ...*PublisherPermission) *PublisherUpdateOne {
ids := make([]int, len(p))
for i := range p {
ids[i] = p[i].ID
}
return puo.RemovePublisherPermissionIDs(ids...)
}
// ClearNodes clears all "nodes" edges to the Node entity.
func (puo *PublisherUpdateOne) ClearNodes() *PublisherUpdateOne {
puo.mutation.ClearNodes()
return puo
}
// RemoveNodeIDs removes the "nodes" edge to Node entities by IDs.
func (puo *PublisherUpdateOne) RemoveNodeIDs(ids ...string) *PublisherUpdateOne {
puo.mutation.RemoveNodeIDs(ids...)
return puo
}
// RemoveNodes removes "nodes" edges to Node entities.
func (puo *PublisherUpdateOne) RemoveNodes(n ...*Node) *PublisherUpdateOne {
ids := make([]string, len(n))
for i := range n {
ids[i] = n[i].ID
}
return puo.RemoveNodeIDs(ids...)
}
// ClearPersonalAccessTokens clears all "personal_access_tokens" edges to the PersonalAccessToken entity.
func (puo *PublisherUpdateOne) ClearPersonalAccessTokens() *PublisherUpdateOne {
puo.mutation.ClearPersonalAccessTokens()
return puo
}
// RemovePersonalAccessTokenIDs removes the "personal_access_tokens" edge to PersonalAccessToken entities by IDs.
func (puo *PublisherUpdateOne) RemovePersonalAccessTokenIDs(ids ...uuid.UUID) *PublisherUpdateOne {
puo.mutation.RemovePersonalAccessTokenIDs(ids...)
return puo
}
// RemovePersonalAccessTokens removes "personal_access_tokens" edges to PersonalAccessToken entities.
func (puo *PublisherUpdateOne) RemovePersonalAccessTokens(p ...*PersonalAccessToken) *PublisherUpdateOne {
ids := make([]uuid.UUID, len(p))
for i := range p {
ids[i] = p[i].ID
}
return puo.RemovePersonalAccessTokenIDs(ids...)
}
// Where appends a list predicates to the PublisherUpdate builder.
func (puo *PublisherUpdateOne) Where(ps ...predicate.Publisher) *PublisherUpdateOne {
puo.mutation.Where(ps...)
return puo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (puo *PublisherUpdateOne) Select(field string, fields ...string) *PublisherUpdateOne {
puo.fields = append([]string{field}, fields...)
return puo
}
// Save executes the query and returns the updated Publisher entity.
func (puo *PublisherUpdateOne) Save(ctx context.Context) (*Publisher, error) {
puo.defaults()
return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (puo *PublisherUpdateOne) SaveX(ctx context.Context) *Publisher {
node, err := puo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (puo *PublisherUpdateOne) Exec(ctx context.Context) error {
_, err := puo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (puo *PublisherUpdateOne) ExecX(ctx context.Context) {
if err := puo.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (puo *PublisherUpdateOne) defaults() {
if _, ok := puo.mutation.UpdateTime(); !ok {
v := publisher.UpdateDefaultUpdateTime()
puo.mutation.SetUpdateTime(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (puo *PublisherUpdateOne) check() error {
if v, ok := puo.mutation.Status(); ok {
if err := publisher.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Publisher.status": %w`, err)}
}
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (puo *PublisherUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *PublisherUpdateOne {
puo.modifiers = append(puo.modifiers, modifiers...)
return puo
}
func (puo *PublisherUpdateOne) sqlSave(ctx context.Context) (_node *Publisher, err error) {
if err := puo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(publisher.Table, publisher.Columns, sqlgraph.NewFieldSpec(publisher.FieldID, field.TypeString))
id, ok := puo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Publisher.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := puo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, publisher.FieldID)
for _, f := range fields {
if !publisher.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != publisher.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := puo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := puo.mutation.UpdateTime(); ok {
_spec.SetField(publisher.FieldUpdateTime, field.TypeTime, value)
}
if value, ok := puo.mutation.Name(); ok {
_spec.SetField(publisher.FieldName, field.TypeString, value)
}
if value, ok := puo.mutation.Description(); ok {
_spec.SetField(publisher.FieldDescription, field.TypeString, value)
}
if puo.mutation.DescriptionCleared() {
_spec.ClearField(publisher.FieldDescription, field.TypeString)
}
if value, ok := puo.mutation.Website(); ok {
_spec.SetField(publisher.FieldWebsite, field.TypeString, value)
}
if puo.mutation.WebsiteCleared() {
_spec.ClearField(publisher.FieldWebsite, field.TypeString)
}
if value, ok := puo.mutation.SupportEmail(); ok {
_spec.SetField(publisher.FieldSupportEmail, field.TypeString, value)
}
if puo.mutation.SupportEmailCleared() {
_spec.ClearField(publisher.FieldSupportEmail, field.TypeString)
}
if value, ok := puo.mutation.SourceCodeRepo(); ok {
_spec.SetField(publisher.FieldSourceCodeRepo, field.TypeString, value)
}
if puo.mutation.SourceCodeRepoCleared() {
_spec.ClearField(publisher.FieldSourceCodeRepo, field.TypeString)
}
if value, ok := puo.mutation.LogoURL(); ok {
_spec.SetField(publisher.FieldLogoURL, field.TypeString, value)
}
if puo.mutation.LogoURLCleared() {
_spec.ClearField(publisher.FieldLogoURL, field.TypeString)
}
if value, ok := puo.mutation.Status(); ok {
_spec.SetField(publisher.FieldStatus, field.TypeEnum, value)
}
if puo.mutation.PublisherPermissionsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PublisherPermissionsTable,
Columns: []string{publisher.PublisherPermissionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(publisherpermission.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := puo.mutation.RemovedPublisherPermissionsIDs(); len(nodes) > 0 && !puo.mutation.PublisherPermissionsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PublisherPermissionsTable,
Columns: []string{publisher.PublisherPermissionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(publisherpermission.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := puo.mutation.PublisherPermissionsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PublisherPermissionsTable,
Columns: []string{publisher.PublisherPermissionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(publisherpermission.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if puo.mutation.NodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.NodesTable,
Columns: []string{publisher.NodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := puo.mutation.RemovedNodesIDs(); len(nodes) > 0 && !puo.mutation.NodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.NodesTable,
Columns: []string{publisher.NodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := puo.mutation.NodesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.NodesTable,
Columns: []string{publisher.NodesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if puo.mutation.PersonalAccessTokensCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PersonalAccessTokensTable,
Columns: []string{publisher.PersonalAccessTokensColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(personalaccesstoken.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := puo.mutation.RemovedPersonalAccessTokensIDs(); len(nodes) > 0 && !puo.mutation.PersonalAccessTokensCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PersonalAccessTokensTable,
Columns: []string{publisher.PersonalAccessTokensColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(personalaccesstoken.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := puo.mutation.PersonalAccessTokensIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: publisher.PersonalAccessTokensTable,
Columns: []string{publisher.PersonalAccessTokensColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(personalaccesstoken.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(puo.modifiers...)
_node = &Publisher{config: puo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{publisher.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
puo.mutation.done = true
return _node, nil
}