pcmt/ent/trackedbreaches_update.go
surtur 74546f996b
All checks were successful
continuous-integration/drone/push Build is passing
ent: add/extend entities, tests, validation
2023-08-19 04:52:15 +02:00

543 lines
17 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"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"git.dotya.ml/mirre-mt/pcmt/ent/localbreach"
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
"github.com/google/uuid"
)
// TrackedBreachesUpdate is the builder for updating TrackedBreaches entities.
type TrackedBreachesUpdate struct {
config
hooks []Hook
mutation *TrackedBreachesMutation
}
// Where appends a list predicates to the TrackedBreachesUpdate builder.
func (tbu *TrackedBreachesUpdate) Where(ps ...predicate.TrackedBreaches) *TrackedBreachesUpdate {
tbu.mutation.Where(ps...)
return tbu
}
// SetBreach sets the "breach" field.
func (tbu *TrackedBreachesUpdate) SetBreach(u uuid.UUID) *TrackedBreachesUpdate {
tbu.mutation.SetBreach(u)
return tbu
}
// AddLocalbreachIDs adds the "localbreach" edge to the LocalBreach entity by IDs.
func (tbu *TrackedBreachesUpdate) AddLocalbreachIDs(ids ...uuid.UUID) *TrackedBreachesUpdate {
tbu.mutation.AddLocalbreachIDs(ids...)
return tbu
}
// AddLocalbreach adds the "localbreach" edges to the LocalBreach entity.
func (tbu *TrackedBreachesUpdate) AddLocalbreach(l ...*LocalBreach) *TrackedBreachesUpdate {
ids := make([]uuid.UUID, len(l))
for i := range l {
ids[i] = l[i].ID
}
return tbu.AddLocalbreachIDs(ids...)
}
// AddHibpIDs adds the "hibp" edge to the HIBP entity by IDs.
func (tbu *TrackedBreachesUpdate) AddHibpIDs(ids ...uuid.UUID) *TrackedBreachesUpdate {
tbu.mutation.AddHibpIDs(ids...)
return tbu
}
// AddHibp adds the "hibp" edges to the HIBP entity.
func (tbu *TrackedBreachesUpdate) AddHibp(h ...*HIBP) *TrackedBreachesUpdate {
ids := make([]uuid.UUID, len(h))
for i := range h {
ids[i] = h[i].ID
}
return tbu.AddHibpIDs(ids...)
}
// Mutation returns the TrackedBreachesMutation object of the builder.
func (tbu *TrackedBreachesUpdate) Mutation() *TrackedBreachesMutation {
return tbu.mutation
}
// ClearLocalbreach clears all "localbreach" edges to the LocalBreach entity.
func (tbu *TrackedBreachesUpdate) ClearLocalbreach() *TrackedBreachesUpdate {
tbu.mutation.ClearLocalbreach()
return tbu
}
// RemoveLocalbreachIDs removes the "localbreach" edge to LocalBreach entities by IDs.
func (tbu *TrackedBreachesUpdate) RemoveLocalbreachIDs(ids ...uuid.UUID) *TrackedBreachesUpdate {
tbu.mutation.RemoveLocalbreachIDs(ids...)
return tbu
}
// RemoveLocalbreach removes "localbreach" edges to LocalBreach entities.
func (tbu *TrackedBreachesUpdate) RemoveLocalbreach(l ...*LocalBreach) *TrackedBreachesUpdate {
ids := make([]uuid.UUID, len(l))
for i := range l {
ids[i] = l[i].ID
}
return tbu.RemoveLocalbreachIDs(ids...)
}
// ClearHibp clears all "hibp" edges to the HIBP entity.
func (tbu *TrackedBreachesUpdate) ClearHibp() *TrackedBreachesUpdate {
tbu.mutation.ClearHibp()
return tbu
}
// RemoveHibpIDs removes the "hibp" edge to HIBP entities by IDs.
func (tbu *TrackedBreachesUpdate) RemoveHibpIDs(ids ...uuid.UUID) *TrackedBreachesUpdate {
tbu.mutation.RemoveHibpIDs(ids...)
return tbu
}
// RemoveHibp removes "hibp" edges to HIBP entities.
func (tbu *TrackedBreachesUpdate) RemoveHibp(h ...*HIBP) *TrackedBreachesUpdate {
ids := make([]uuid.UUID, len(h))
for i := range h {
ids[i] = h[i].ID
}
return tbu.RemoveHibpIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (tbu *TrackedBreachesUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, tbu.sqlSave, tbu.mutation, tbu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (tbu *TrackedBreachesUpdate) SaveX(ctx context.Context) int {
affected, err := tbu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (tbu *TrackedBreachesUpdate) Exec(ctx context.Context) error {
_, err := tbu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (tbu *TrackedBreachesUpdate) ExecX(ctx context.Context) {
if err := tbu.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (tbu *TrackedBreachesUpdate) check() error {
if _, ok := tbu.mutation.UserID(); tbu.mutation.UserCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "TrackedBreaches.user"`)
}
return nil
}
func (tbu *TrackedBreachesUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := tbu.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(trackedbreaches.Table, trackedbreaches.Columns, sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID))
if ps := tbu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := tbu.mutation.Breach(); ok {
_spec.SetField(trackedbreaches.FieldBreach, field.TypeUUID, value)
}
if tbu.mutation.LocalbreachCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: trackedbreaches.LocalbreachTable,
Columns: trackedbreaches.LocalbreachPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := tbu.mutation.RemovedLocalbreachIDs(); len(nodes) > 0 && !tbu.mutation.LocalbreachCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: trackedbreaches.LocalbreachTable,
Columns: trackedbreaches.LocalbreachPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(localbreach.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 := tbu.mutation.LocalbreachIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: trackedbreaches.LocalbreachTable,
Columns: trackedbreaches.LocalbreachPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if tbu.mutation.HibpCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: trackedbreaches.HibpTable,
Columns: []string{trackedbreaches.HibpColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := tbu.mutation.RemovedHibpIDs(); len(nodes) > 0 && !tbu.mutation.HibpCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: trackedbreaches.HibpTable,
Columns: []string{trackedbreaches.HibpColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(hibp.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 := tbu.mutation.HibpIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: trackedbreaches.HibpTable,
Columns: []string{trackedbreaches.HibpColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
},
}
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, tbu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{trackedbreaches.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
tbu.mutation.done = true
return n, nil
}
// TrackedBreachesUpdateOne is the builder for updating a single TrackedBreaches entity.
type TrackedBreachesUpdateOne struct {
config
fields []string
hooks []Hook
mutation *TrackedBreachesMutation
}
// SetBreach sets the "breach" field.
func (tbuo *TrackedBreachesUpdateOne) SetBreach(u uuid.UUID) *TrackedBreachesUpdateOne {
tbuo.mutation.SetBreach(u)
return tbuo
}
// AddLocalbreachIDs adds the "localbreach" edge to the LocalBreach entity by IDs.
func (tbuo *TrackedBreachesUpdateOne) AddLocalbreachIDs(ids ...uuid.UUID) *TrackedBreachesUpdateOne {
tbuo.mutation.AddLocalbreachIDs(ids...)
return tbuo
}
// AddLocalbreach adds the "localbreach" edges to the LocalBreach entity.
func (tbuo *TrackedBreachesUpdateOne) AddLocalbreach(l ...*LocalBreach) *TrackedBreachesUpdateOne {
ids := make([]uuid.UUID, len(l))
for i := range l {
ids[i] = l[i].ID
}
return tbuo.AddLocalbreachIDs(ids...)
}
// AddHibpIDs adds the "hibp" edge to the HIBP entity by IDs.
func (tbuo *TrackedBreachesUpdateOne) AddHibpIDs(ids ...uuid.UUID) *TrackedBreachesUpdateOne {
tbuo.mutation.AddHibpIDs(ids...)
return tbuo
}
// AddHibp adds the "hibp" edges to the HIBP entity.
func (tbuo *TrackedBreachesUpdateOne) AddHibp(h ...*HIBP) *TrackedBreachesUpdateOne {
ids := make([]uuid.UUID, len(h))
for i := range h {
ids[i] = h[i].ID
}
return tbuo.AddHibpIDs(ids...)
}
// Mutation returns the TrackedBreachesMutation object of the builder.
func (tbuo *TrackedBreachesUpdateOne) Mutation() *TrackedBreachesMutation {
return tbuo.mutation
}
// ClearLocalbreach clears all "localbreach" edges to the LocalBreach entity.
func (tbuo *TrackedBreachesUpdateOne) ClearLocalbreach() *TrackedBreachesUpdateOne {
tbuo.mutation.ClearLocalbreach()
return tbuo
}
// RemoveLocalbreachIDs removes the "localbreach" edge to LocalBreach entities by IDs.
func (tbuo *TrackedBreachesUpdateOne) RemoveLocalbreachIDs(ids ...uuid.UUID) *TrackedBreachesUpdateOne {
tbuo.mutation.RemoveLocalbreachIDs(ids...)
return tbuo
}
// RemoveLocalbreach removes "localbreach" edges to LocalBreach entities.
func (tbuo *TrackedBreachesUpdateOne) RemoveLocalbreach(l ...*LocalBreach) *TrackedBreachesUpdateOne {
ids := make([]uuid.UUID, len(l))
for i := range l {
ids[i] = l[i].ID
}
return tbuo.RemoveLocalbreachIDs(ids...)
}
// ClearHibp clears all "hibp" edges to the HIBP entity.
func (tbuo *TrackedBreachesUpdateOne) ClearHibp() *TrackedBreachesUpdateOne {
tbuo.mutation.ClearHibp()
return tbuo
}
// RemoveHibpIDs removes the "hibp" edge to HIBP entities by IDs.
func (tbuo *TrackedBreachesUpdateOne) RemoveHibpIDs(ids ...uuid.UUID) *TrackedBreachesUpdateOne {
tbuo.mutation.RemoveHibpIDs(ids...)
return tbuo
}
// RemoveHibp removes "hibp" edges to HIBP entities.
func (tbuo *TrackedBreachesUpdateOne) RemoveHibp(h ...*HIBP) *TrackedBreachesUpdateOne {
ids := make([]uuid.UUID, len(h))
for i := range h {
ids[i] = h[i].ID
}
return tbuo.RemoveHibpIDs(ids...)
}
// Where appends a list predicates to the TrackedBreachesUpdate builder.
func (tbuo *TrackedBreachesUpdateOne) Where(ps ...predicate.TrackedBreaches) *TrackedBreachesUpdateOne {
tbuo.mutation.Where(ps...)
return tbuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (tbuo *TrackedBreachesUpdateOne) Select(field string, fields ...string) *TrackedBreachesUpdateOne {
tbuo.fields = append([]string{field}, fields...)
return tbuo
}
// Save executes the query and returns the updated TrackedBreaches entity.
func (tbuo *TrackedBreachesUpdateOne) Save(ctx context.Context) (*TrackedBreaches, error) {
return withHooks(ctx, tbuo.sqlSave, tbuo.mutation, tbuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (tbuo *TrackedBreachesUpdateOne) SaveX(ctx context.Context) *TrackedBreaches {
node, err := tbuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (tbuo *TrackedBreachesUpdateOne) Exec(ctx context.Context) error {
_, err := tbuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (tbuo *TrackedBreachesUpdateOne) ExecX(ctx context.Context) {
if err := tbuo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (tbuo *TrackedBreachesUpdateOne) check() error {
if _, ok := tbuo.mutation.UserID(); tbuo.mutation.UserCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "TrackedBreaches.user"`)
}
return nil
}
func (tbuo *TrackedBreachesUpdateOne) sqlSave(ctx context.Context) (_node *TrackedBreaches, err error) {
if err := tbuo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(trackedbreaches.Table, trackedbreaches.Columns, sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID))
id, ok := tbuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "TrackedBreaches.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := tbuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, trackedbreaches.FieldID)
for _, f := range fields {
if !trackedbreaches.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != trackedbreaches.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := tbuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := tbuo.mutation.Breach(); ok {
_spec.SetField(trackedbreaches.FieldBreach, field.TypeUUID, value)
}
if tbuo.mutation.LocalbreachCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: trackedbreaches.LocalbreachTable,
Columns: trackedbreaches.LocalbreachPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := tbuo.mutation.RemovedLocalbreachIDs(); len(nodes) > 0 && !tbuo.mutation.LocalbreachCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: trackedbreaches.LocalbreachTable,
Columns: trackedbreaches.LocalbreachPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(localbreach.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 := tbuo.mutation.LocalbreachIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: trackedbreaches.LocalbreachTable,
Columns: trackedbreaches.LocalbreachPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if tbuo.mutation.HibpCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: trackedbreaches.HibpTable,
Columns: []string{trackedbreaches.HibpColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := tbuo.mutation.RemovedHibpIDs(); len(nodes) > 0 && !tbuo.mutation.HibpCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: trackedbreaches.HibpTable,
Columns: []string{trackedbreaches.HibpColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(hibp.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 := tbuo.mutation.HibpIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: trackedbreaches.HibpTable,
Columns: []string{trackedbreaches.HibpColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &TrackedBreaches{config: tbuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, tbuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{trackedbreaches.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
tbuo.mutation.done = true
return _node, nil
}