340 lines
9.8 KiB
Go
340 lines
9.8 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"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/trackedbreaches"
|
|
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// TrackedBreachesCreate is the builder for creating a TrackedBreaches entity.
|
|
type TrackedBreachesCreate struct {
|
|
config
|
|
mutation *TrackedBreachesMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetBreach sets the "breach" field.
|
|
func (tbc *TrackedBreachesCreate) SetBreach(u uuid.UUID) *TrackedBreachesCreate {
|
|
tbc.mutation.SetBreach(u)
|
|
return tbc
|
|
}
|
|
|
|
// SetOnline sets the "online" field.
|
|
func (tbc *TrackedBreachesCreate) SetOnline(b bool) *TrackedBreachesCreate {
|
|
tbc.mutation.SetOnline(b)
|
|
return tbc
|
|
}
|
|
|
|
// SetNillableOnline sets the "online" field if the given value is not nil.
|
|
func (tbc *TrackedBreachesCreate) SetNillableOnline(b *bool) *TrackedBreachesCreate {
|
|
if b != nil {
|
|
tbc.SetOnline(*b)
|
|
}
|
|
return tbc
|
|
}
|
|
|
|
// SetOwner sets the "owner" field.
|
|
func (tbc *TrackedBreachesCreate) SetOwner(u uuid.UUID) *TrackedBreachesCreate {
|
|
tbc.mutation.SetOwner(u)
|
|
return tbc
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (tbc *TrackedBreachesCreate) SetID(u uuid.UUID) *TrackedBreachesCreate {
|
|
tbc.mutation.SetID(u)
|
|
return tbc
|
|
}
|
|
|
|
// SetNillableID sets the "id" field if the given value is not nil.
|
|
func (tbc *TrackedBreachesCreate) SetNillableID(u *uuid.UUID) *TrackedBreachesCreate {
|
|
if u != nil {
|
|
tbc.SetID(*u)
|
|
}
|
|
return tbc
|
|
}
|
|
|
|
// SetUserID sets the "user" edge to the User entity by ID.
|
|
func (tbc *TrackedBreachesCreate) SetUserID(id uuid.UUID) *TrackedBreachesCreate {
|
|
tbc.mutation.SetUserID(id)
|
|
return tbc
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (tbc *TrackedBreachesCreate) SetUser(u *User) *TrackedBreachesCreate {
|
|
return tbc.SetUserID(u.ID)
|
|
}
|
|
|
|
// AddLocalbreachIDs adds the "localbreach" edge to the LocalBreach entity by IDs.
|
|
func (tbc *TrackedBreachesCreate) AddLocalbreachIDs(ids ...uuid.UUID) *TrackedBreachesCreate {
|
|
tbc.mutation.AddLocalbreachIDs(ids...)
|
|
return tbc
|
|
}
|
|
|
|
// AddLocalbreach adds the "localbreach" edges to the LocalBreach entity.
|
|
func (tbc *TrackedBreachesCreate) AddLocalbreach(l ...*LocalBreach) *TrackedBreachesCreate {
|
|
ids := make([]uuid.UUID, len(l))
|
|
for i := range l {
|
|
ids[i] = l[i].ID
|
|
}
|
|
return tbc.AddLocalbreachIDs(ids...)
|
|
}
|
|
|
|
// AddHibpIDs adds the "hibp" edge to the HIBP entity by IDs.
|
|
func (tbc *TrackedBreachesCreate) AddHibpIDs(ids ...uuid.UUID) *TrackedBreachesCreate {
|
|
tbc.mutation.AddHibpIDs(ids...)
|
|
return tbc
|
|
}
|
|
|
|
// AddHibp adds the "hibp" edges to the HIBP entity.
|
|
func (tbc *TrackedBreachesCreate) AddHibp(h ...*HIBP) *TrackedBreachesCreate {
|
|
ids := make([]uuid.UUID, len(h))
|
|
for i := range h {
|
|
ids[i] = h[i].ID
|
|
}
|
|
return tbc.AddHibpIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the TrackedBreachesMutation object of the builder.
|
|
func (tbc *TrackedBreachesCreate) Mutation() *TrackedBreachesMutation {
|
|
return tbc.mutation
|
|
}
|
|
|
|
// Save creates the TrackedBreaches in the database.
|
|
func (tbc *TrackedBreachesCreate) Save(ctx context.Context) (*TrackedBreaches, error) {
|
|
tbc.defaults()
|
|
return withHooks(ctx, tbc.sqlSave, tbc.mutation, tbc.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (tbc *TrackedBreachesCreate) SaveX(ctx context.Context) *TrackedBreaches {
|
|
v, err := tbc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (tbc *TrackedBreachesCreate) Exec(ctx context.Context) error {
|
|
_, err := tbc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (tbc *TrackedBreachesCreate) ExecX(ctx context.Context) {
|
|
if err := tbc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (tbc *TrackedBreachesCreate) defaults() {
|
|
if _, ok := tbc.mutation.Online(); !ok {
|
|
v := trackedbreaches.DefaultOnline
|
|
tbc.mutation.SetOnline(v)
|
|
}
|
|
if _, ok := tbc.mutation.ID(); !ok {
|
|
v := trackedbreaches.DefaultID()
|
|
tbc.mutation.SetID(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (tbc *TrackedBreachesCreate) check() error {
|
|
if _, ok := tbc.mutation.Breach(); !ok {
|
|
return &ValidationError{Name: "breach", err: errors.New(`ent: missing required field "TrackedBreaches.breach"`)}
|
|
}
|
|
if _, ok := tbc.mutation.Online(); !ok {
|
|
return &ValidationError{Name: "online", err: errors.New(`ent: missing required field "TrackedBreaches.online"`)}
|
|
}
|
|
if _, ok := tbc.mutation.Owner(); !ok {
|
|
return &ValidationError{Name: "owner", err: errors.New(`ent: missing required field "TrackedBreaches.owner"`)}
|
|
}
|
|
if _, ok := tbc.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "TrackedBreaches.user"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (tbc *TrackedBreachesCreate) sqlSave(ctx context.Context) (*TrackedBreaches, error) {
|
|
if err := tbc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := tbc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, tbc.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
if _spec.ID.Value != nil {
|
|
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
|
_node.ID = *id
|
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
tbc.mutation.id = &_node.ID
|
|
tbc.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (tbc *TrackedBreachesCreate) createSpec() (*TrackedBreaches, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &TrackedBreaches{config: tbc.config}
|
|
_spec = sqlgraph.NewCreateSpec(trackedbreaches.Table, sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID))
|
|
)
|
|
if id, ok := tbc.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = &id
|
|
}
|
|
if value, ok := tbc.mutation.Breach(); ok {
|
|
_spec.SetField(trackedbreaches.FieldBreach, field.TypeUUID, value)
|
|
_node.Breach = value
|
|
}
|
|
if value, ok := tbc.mutation.Online(); ok {
|
|
_spec.SetField(trackedbreaches.FieldOnline, field.TypeBool, value)
|
|
_node.Online = value
|
|
}
|
|
if nodes := tbc.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: trackedbreaches.UserTable,
|
|
Columns: []string{trackedbreaches.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.Owner = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := tbc.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 = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := tbc.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 = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// TrackedBreachesCreateBulk is the builder for creating many TrackedBreaches entities in bulk.
|
|
type TrackedBreachesCreateBulk struct {
|
|
config
|
|
builders []*TrackedBreachesCreate
|
|
}
|
|
|
|
// Save creates the TrackedBreaches entities in the database.
|
|
func (tbcb *TrackedBreachesCreateBulk) Save(ctx context.Context) ([]*TrackedBreaches, error) {
|
|
specs := make([]*sqlgraph.CreateSpec, len(tbcb.builders))
|
|
nodes := make([]*TrackedBreaches, len(tbcb.builders))
|
|
mutators := make([]Mutator, len(tbcb.builders))
|
|
for i := range tbcb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := tbcb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*TrackedBreachesMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
var err error
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, tbcb.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, tbcb.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
mutation.done = true
|
|
return nodes[i], nil
|
|
})
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
mut = builder.hooks[i](mut)
|
|
}
|
|
mutators[i] = mut
|
|
}(i, ctx)
|
|
}
|
|
if len(mutators) > 0 {
|
|
if _, err := mutators[0].Mutate(ctx, tbcb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (tbcb *TrackedBreachesCreateBulk) SaveX(ctx context.Context) []*TrackedBreaches {
|
|
v, err := tbcb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (tbcb *TrackedBreachesCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := tbcb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (tbcb *TrackedBreachesCreateBulk) ExecX(ctx context.Context) {
|
|
if err := tbcb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|