502 lines
15 KiB
Go
502 lines
15 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"thesis/ent/key"
|
|
"thesis/ent/predicate"
|
|
"thesis/ent/validators"
|
|
"thesis/ent/whitelist"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// WhiteListUpdate is the builder for updating WhiteList entities.
|
|
type WhiteListUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *WhiteListMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the WhiteListUpdate builder.
|
|
func (wlu *WhiteListUpdate) Where(ps ...predicate.WhiteList) *WhiteListUpdate {
|
|
wlu.mutation.Where(ps...)
|
|
return wlu
|
|
}
|
|
|
|
// AddSponsorIDs adds the "Sponsor" edge to the Validators entity by IDs.
|
|
func (wlu *WhiteListUpdate) AddSponsorIDs(ids ...int) *WhiteListUpdate {
|
|
wlu.mutation.AddSponsorIDs(ids...)
|
|
return wlu
|
|
}
|
|
|
|
// AddSponsor adds the "Sponsor" edges to the Validators entity.
|
|
func (wlu *WhiteListUpdate) AddSponsor(v ...*Validators) *WhiteListUpdate {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return wlu.AddSponsorIDs(ids...)
|
|
}
|
|
|
|
// AddAccountIDs adds the "Account" edge to the Key entity by IDs.
|
|
func (wlu *WhiteListUpdate) AddAccountIDs(ids ...int) *WhiteListUpdate {
|
|
wlu.mutation.AddAccountIDs(ids...)
|
|
return wlu
|
|
}
|
|
|
|
// AddAccount adds the "Account" edges to the Key entity.
|
|
func (wlu *WhiteListUpdate) AddAccount(k ...*Key) *WhiteListUpdate {
|
|
ids := make([]int, len(k))
|
|
for i := range k {
|
|
ids[i] = k[i].ID
|
|
}
|
|
return wlu.AddAccountIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the WhiteListMutation object of the builder.
|
|
func (wlu *WhiteListUpdate) Mutation() *WhiteListMutation {
|
|
return wlu.mutation
|
|
}
|
|
|
|
// ClearSponsor clears all "Sponsor" edges to the Validators entity.
|
|
func (wlu *WhiteListUpdate) ClearSponsor() *WhiteListUpdate {
|
|
wlu.mutation.ClearSponsor()
|
|
return wlu
|
|
}
|
|
|
|
// RemoveSponsorIDs removes the "Sponsor" edge to Validators entities by IDs.
|
|
func (wlu *WhiteListUpdate) RemoveSponsorIDs(ids ...int) *WhiteListUpdate {
|
|
wlu.mutation.RemoveSponsorIDs(ids...)
|
|
return wlu
|
|
}
|
|
|
|
// RemoveSponsor removes "Sponsor" edges to Validators entities.
|
|
func (wlu *WhiteListUpdate) RemoveSponsor(v ...*Validators) *WhiteListUpdate {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return wlu.RemoveSponsorIDs(ids...)
|
|
}
|
|
|
|
// ClearAccount clears all "Account" edges to the Key entity.
|
|
func (wlu *WhiteListUpdate) ClearAccount() *WhiteListUpdate {
|
|
wlu.mutation.ClearAccount()
|
|
return wlu
|
|
}
|
|
|
|
// RemoveAccountIDs removes the "Account" edge to Key entities by IDs.
|
|
func (wlu *WhiteListUpdate) RemoveAccountIDs(ids ...int) *WhiteListUpdate {
|
|
wlu.mutation.RemoveAccountIDs(ids...)
|
|
return wlu
|
|
}
|
|
|
|
// RemoveAccount removes "Account" edges to Key entities.
|
|
func (wlu *WhiteListUpdate) RemoveAccount(k ...*Key) *WhiteListUpdate {
|
|
ids := make([]int, len(k))
|
|
for i := range k {
|
|
ids[i] = k[i].ID
|
|
}
|
|
return wlu.RemoveAccountIDs(ids...)
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (wlu *WhiteListUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, wlu.sqlSave, wlu.mutation, wlu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (wlu *WhiteListUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := wlu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (wlu *WhiteListUpdate) Exec(ctx context.Context) error {
|
|
_, err := wlu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wlu *WhiteListUpdate) ExecX(ctx context.Context) {
|
|
if err := wlu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (wlu *WhiteListUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(whitelist.Table, whitelist.Columns, sqlgraph.NewFieldSpec(whitelist.FieldID, field.TypeInt))
|
|
if ps := wlu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if wlu.mutation.SponsorCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.SponsorTable,
|
|
Columns: []string{whitelist.SponsorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := wlu.mutation.RemovedSponsorIDs(); len(nodes) > 0 && !wlu.mutation.SponsorCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.SponsorTable,
|
|
Columns: []string{whitelist.SponsorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(validators.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 := wlu.mutation.SponsorIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.SponsorTable,
|
|
Columns: []string{whitelist.SponsorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if wlu.mutation.AccountCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.AccountTable,
|
|
Columns: []string{whitelist.AccountColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(key.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := wlu.mutation.RemovedAccountIDs(); len(nodes) > 0 && !wlu.mutation.AccountCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.AccountTable,
|
|
Columns: []string{whitelist.AccountColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(key.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 := wlu.mutation.AccountIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.AccountTable,
|
|
Columns: []string{whitelist.AccountColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(key.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, wlu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{whitelist.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
wlu.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// WhiteListUpdateOne is the builder for updating a single WhiteList entity.
|
|
type WhiteListUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *WhiteListMutation
|
|
}
|
|
|
|
// AddSponsorIDs adds the "Sponsor" edge to the Validators entity by IDs.
|
|
func (wluo *WhiteListUpdateOne) AddSponsorIDs(ids ...int) *WhiteListUpdateOne {
|
|
wluo.mutation.AddSponsorIDs(ids...)
|
|
return wluo
|
|
}
|
|
|
|
// AddSponsor adds the "Sponsor" edges to the Validators entity.
|
|
func (wluo *WhiteListUpdateOne) AddSponsor(v ...*Validators) *WhiteListUpdateOne {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return wluo.AddSponsorIDs(ids...)
|
|
}
|
|
|
|
// AddAccountIDs adds the "Account" edge to the Key entity by IDs.
|
|
func (wluo *WhiteListUpdateOne) AddAccountIDs(ids ...int) *WhiteListUpdateOne {
|
|
wluo.mutation.AddAccountIDs(ids...)
|
|
return wluo
|
|
}
|
|
|
|
// AddAccount adds the "Account" edges to the Key entity.
|
|
func (wluo *WhiteListUpdateOne) AddAccount(k ...*Key) *WhiteListUpdateOne {
|
|
ids := make([]int, len(k))
|
|
for i := range k {
|
|
ids[i] = k[i].ID
|
|
}
|
|
return wluo.AddAccountIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the WhiteListMutation object of the builder.
|
|
func (wluo *WhiteListUpdateOne) Mutation() *WhiteListMutation {
|
|
return wluo.mutation
|
|
}
|
|
|
|
// ClearSponsor clears all "Sponsor" edges to the Validators entity.
|
|
func (wluo *WhiteListUpdateOne) ClearSponsor() *WhiteListUpdateOne {
|
|
wluo.mutation.ClearSponsor()
|
|
return wluo
|
|
}
|
|
|
|
// RemoveSponsorIDs removes the "Sponsor" edge to Validators entities by IDs.
|
|
func (wluo *WhiteListUpdateOne) RemoveSponsorIDs(ids ...int) *WhiteListUpdateOne {
|
|
wluo.mutation.RemoveSponsorIDs(ids...)
|
|
return wluo
|
|
}
|
|
|
|
// RemoveSponsor removes "Sponsor" edges to Validators entities.
|
|
func (wluo *WhiteListUpdateOne) RemoveSponsor(v ...*Validators) *WhiteListUpdateOne {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return wluo.RemoveSponsorIDs(ids...)
|
|
}
|
|
|
|
// ClearAccount clears all "Account" edges to the Key entity.
|
|
func (wluo *WhiteListUpdateOne) ClearAccount() *WhiteListUpdateOne {
|
|
wluo.mutation.ClearAccount()
|
|
return wluo
|
|
}
|
|
|
|
// RemoveAccountIDs removes the "Account" edge to Key entities by IDs.
|
|
func (wluo *WhiteListUpdateOne) RemoveAccountIDs(ids ...int) *WhiteListUpdateOne {
|
|
wluo.mutation.RemoveAccountIDs(ids...)
|
|
return wluo
|
|
}
|
|
|
|
// RemoveAccount removes "Account" edges to Key entities.
|
|
func (wluo *WhiteListUpdateOne) RemoveAccount(k ...*Key) *WhiteListUpdateOne {
|
|
ids := make([]int, len(k))
|
|
for i := range k {
|
|
ids[i] = k[i].ID
|
|
}
|
|
return wluo.RemoveAccountIDs(ids...)
|
|
}
|
|
|
|
// Where appends a list predicates to the WhiteListUpdate builder.
|
|
func (wluo *WhiteListUpdateOne) Where(ps ...predicate.WhiteList) *WhiteListUpdateOne {
|
|
wluo.mutation.Where(ps...)
|
|
return wluo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (wluo *WhiteListUpdateOne) Select(field string, fields ...string) *WhiteListUpdateOne {
|
|
wluo.fields = append([]string{field}, fields...)
|
|
return wluo
|
|
}
|
|
|
|
// Save executes the query and returns the updated WhiteList entity.
|
|
func (wluo *WhiteListUpdateOne) Save(ctx context.Context) (*WhiteList, error) {
|
|
return withHooks(ctx, wluo.sqlSave, wluo.mutation, wluo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (wluo *WhiteListUpdateOne) SaveX(ctx context.Context) *WhiteList {
|
|
node, err := wluo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (wluo *WhiteListUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := wluo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (wluo *WhiteListUpdateOne) ExecX(ctx context.Context) {
|
|
if err := wluo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (wluo *WhiteListUpdateOne) sqlSave(ctx context.Context) (_node *WhiteList, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(whitelist.Table, whitelist.Columns, sqlgraph.NewFieldSpec(whitelist.FieldID, field.TypeInt))
|
|
id, ok := wluo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "WhiteList.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := wluo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, whitelist.FieldID)
|
|
for _, f := range fields {
|
|
if !whitelist.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != whitelist.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := wluo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if wluo.mutation.SponsorCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.SponsorTable,
|
|
Columns: []string{whitelist.SponsorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := wluo.mutation.RemovedSponsorIDs(); len(nodes) > 0 && !wluo.mutation.SponsorCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.SponsorTable,
|
|
Columns: []string{whitelist.SponsorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(validators.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 := wluo.mutation.SponsorIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.SponsorTable,
|
|
Columns: []string{whitelist.SponsorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(validators.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if wluo.mutation.AccountCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.AccountTable,
|
|
Columns: []string{whitelist.AccountColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(key.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := wluo.mutation.RemovedAccountIDs(); len(nodes) > 0 && !wluo.mutation.AccountCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.AccountTable,
|
|
Columns: []string{whitelist.AccountColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(key.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 := wluo.mutation.AccountIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: whitelist.AccountTable,
|
|
Columns: []string{whitelist.AccountColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(key.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &WhiteList{config: wluo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, wluo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{whitelist.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
wluo.mutation.done = true
|
|
return _node, nil
|
|
}
|