Files
homebox/backend/internal/data/ent/entity_create.go
2025-05-07 21:15:08 -04:00

1072 lines
32 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/attachment"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/entity"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/entityfield"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/group"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/label"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry"
)
// EntityCreate is the builder for creating a Entity entity.
type EntityCreate struct {
config
mutation *EntityMutation
hooks []Hook
}
// SetCreatedAt sets the "created_at" field.
func (ec *EntityCreate) SetCreatedAt(t time.Time) *EntityCreate {
ec.mutation.SetCreatedAt(t)
return ec
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (ec *EntityCreate) SetNillableCreatedAt(t *time.Time) *EntityCreate {
if t != nil {
ec.SetCreatedAt(*t)
}
return ec
}
// SetUpdatedAt sets the "updated_at" field.
func (ec *EntityCreate) SetUpdatedAt(t time.Time) *EntityCreate {
ec.mutation.SetUpdatedAt(t)
return ec
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (ec *EntityCreate) SetNillableUpdatedAt(t *time.Time) *EntityCreate {
if t != nil {
ec.SetUpdatedAt(*t)
}
return ec
}
// SetName sets the "name" field.
func (ec *EntityCreate) SetName(s string) *EntityCreate {
ec.mutation.SetName(s)
return ec
}
// SetDescription sets the "description" field.
func (ec *EntityCreate) SetDescription(s string) *EntityCreate {
ec.mutation.SetDescription(s)
return ec
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (ec *EntityCreate) SetNillableDescription(s *string) *EntityCreate {
if s != nil {
ec.SetDescription(*s)
}
return ec
}
// SetType sets the "type" field.
func (ec *EntityCreate) SetType(e entity.Type) *EntityCreate {
ec.mutation.SetType(e)
return ec
}
// SetNillableType sets the "type" field if the given value is not nil.
func (ec *EntityCreate) SetNillableType(e *entity.Type) *EntityCreate {
if e != nil {
ec.SetType(*e)
}
return ec
}
// SetImportRef sets the "import_ref" field.
func (ec *EntityCreate) SetImportRef(s string) *EntityCreate {
ec.mutation.SetImportRef(s)
return ec
}
// SetNillableImportRef sets the "import_ref" field if the given value is not nil.
func (ec *EntityCreate) SetNillableImportRef(s *string) *EntityCreate {
if s != nil {
ec.SetImportRef(*s)
}
return ec
}
// SetNotes sets the "notes" field.
func (ec *EntityCreate) SetNotes(s string) *EntityCreate {
ec.mutation.SetNotes(s)
return ec
}
// SetNillableNotes sets the "notes" field if the given value is not nil.
func (ec *EntityCreate) SetNillableNotes(s *string) *EntityCreate {
if s != nil {
ec.SetNotes(*s)
}
return ec
}
// SetQuantity sets the "quantity" field.
func (ec *EntityCreate) SetQuantity(i int) *EntityCreate {
ec.mutation.SetQuantity(i)
return ec
}
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
func (ec *EntityCreate) SetNillableQuantity(i *int) *EntityCreate {
if i != nil {
ec.SetQuantity(*i)
}
return ec
}
// SetInsured sets the "insured" field.
func (ec *EntityCreate) SetInsured(b bool) *EntityCreate {
ec.mutation.SetInsured(b)
return ec
}
// SetNillableInsured sets the "insured" field if the given value is not nil.
func (ec *EntityCreate) SetNillableInsured(b *bool) *EntityCreate {
if b != nil {
ec.SetInsured(*b)
}
return ec
}
// SetArchived sets the "archived" field.
func (ec *EntityCreate) SetArchived(b bool) *EntityCreate {
ec.mutation.SetArchived(b)
return ec
}
// SetNillableArchived sets the "archived" field if the given value is not nil.
func (ec *EntityCreate) SetNillableArchived(b *bool) *EntityCreate {
if b != nil {
ec.SetArchived(*b)
}
return ec
}
// SetAssetID sets the "asset_id" field.
func (ec *EntityCreate) SetAssetID(i int) *EntityCreate {
ec.mutation.SetAssetID(i)
return ec
}
// SetNillableAssetID sets the "asset_id" field if the given value is not nil.
func (ec *EntityCreate) SetNillableAssetID(i *int) *EntityCreate {
if i != nil {
ec.SetAssetID(*i)
}
return ec
}
// SetSyncChildEntitiesLocations sets the "sync_child_entities_locations" field.
func (ec *EntityCreate) SetSyncChildEntitiesLocations(b bool) *EntityCreate {
ec.mutation.SetSyncChildEntitiesLocations(b)
return ec
}
// SetNillableSyncChildEntitiesLocations sets the "sync_child_entities_locations" field if the given value is not nil.
func (ec *EntityCreate) SetNillableSyncChildEntitiesLocations(b *bool) *EntityCreate {
if b != nil {
ec.SetSyncChildEntitiesLocations(*b)
}
return ec
}
// SetSerialNumber sets the "serial_number" field.
func (ec *EntityCreate) SetSerialNumber(s string) *EntityCreate {
ec.mutation.SetSerialNumber(s)
return ec
}
// SetNillableSerialNumber sets the "serial_number" field if the given value is not nil.
func (ec *EntityCreate) SetNillableSerialNumber(s *string) *EntityCreate {
if s != nil {
ec.SetSerialNumber(*s)
}
return ec
}
// SetModelNumber sets the "model_number" field.
func (ec *EntityCreate) SetModelNumber(s string) *EntityCreate {
ec.mutation.SetModelNumber(s)
return ec
}
// SetNillableModelNumber sets the "model_number" field if the given value is not nil.
func (ec *EntityCreate) SetNillableModelNumber(s *string) *EntityCreate {
if s != nil {
ec.SetModelNumber(*s)
}
return ec
}
// SetManufacturer sets the "manufacturer" field.
func (ec *EntityCreate) SetManufacturer(s string) *EntityCreate {
ec.mutation.SetManufacturer(s)
return ec
}
// SetNillableManufacturer sets the "manufacturer" field if the given value is not nil.
func (ec *EntityCreate) SetNillableManufacturer(s *string) *EntityCreate {
if s != nil {
ec.SetManufacturer(*s)
}
return ec
}
// SetLifetimeWarranty sets the "lifetime_warranty" field.
func (ec *EntityCreate) SetLifetimeWarranty(b bool) *EntityCreate {
ec.mutation.SetLifetimeWarranty(b)
return ec
}
// SetNillableLifetimeWarranty sets the "lifetime_warranty" field if the given value is not nil.
func (ec *EntityCreate) SetNillableLifetimeWarranty(b *bool) *EntityCreate {
if b != nil {
ec.SetLifetimeWarranty(*b)
}
return ec
}
// SetWarrantyExpires sets the "warranty_expires" field.
func (ec *EntityCreate) SetWarrantyExpires(t time.Time) *EntityCreate {
ec.mutation.SetWarrantyExpires(t)
return ec
}
// SetNillableWarrantyExpires sets the "warranty_expires" field if the given value is not nil.
func (ec *EntityCreate) SetNillableWarrantyExpires(t *time.Time) *EntityCreate {
if t != nil {
ec.SetWarrantyExpires(*t)
}
return ec
}
// SetWarrantyDetails sets the "warranty_details" field.
func (ec *EntityCreate) SetWarrantyDetails(s string) *EntityCreate {
ec.mutation.SetWarrantyDetails(s)
return ec
}
// SetNillableWarrantyDetails sets the "warranty_details" field if the given value is not nil.
func (ec *EntityCreate) SetNillableWarrantyDetails(s *string) *EntityCreate {
if s != nil {
ec.SetWarrantyDetails(*s)
}
return ec
}
// SetPurchaseTime sets the "purchase_time" field.
func (ec *EntityCreate) SetPurchaseTime(t time.Time) *EntityCreate {
ec.mutation.SetPurchaseTime(t)
return ec
}
// SetNillablePurchaseTime sets the "purchase_time" field if the given value is not nil.
func (ec *EntityCreate) SetNillablePurchaseTime(t *time.Time) *EntityCreate {
if t != nil {
ec.SetPurchaseTime(*t)
}
return ec
}
// SetPurchaseFrom sets the "purchase_from" field.
func (ec *EntityCreate) SetPurchaseFrom(s string) *EntityCreate {
ec.mutation.SetPurchaseFrom(s)
return ec
}
// SetNillablePurchaseFrom sets the "purchase_from" field if the given value is not nil.
func (ec *EntityCreate) SetNillablePurchaseFrom(s *string) *EntityCreate {
if s != nil {
ec.SetPurchaseFrom(*s)
}
return ec
}
// SetPurchasePrice sets the "purchase_price" field.
func (ec *EntityCreate) SetPurchasePrice(f float64) *EntityCreate {
ec.mutation.SetPurchasePrice(f)
return ec
}
// SetNillablePurchasePrice sets the "purchase_price" field if the given value is not nil.
func (ec *EntityCreate) SetNillablePurchasePrice(f *float64) *EntityCreate {
if f != nil {
ec.SetPurchasePrice(*f)
}
return ec
}
// SetSoldTime sets the "sold_time" field.
func (ec *EntityCreate) SetSoldTime(t time.Time) *EntityCreate {
ec.mutation.SetSoldTime(t)
return ec
}
// SetNillableSoldTime sets the "sold_time" field if the given value is not nil.
func (ec *EntityCreate) SetNillableSoldTime(t *time.Time) *EntityCreate {
if t != nil {
ec.SetSoldTime(*t)
}
return ec
}
// SetSoldTo sets the "sold_to" field.
func (ec *EntityCreate) SetSoldTo(s string) *EntityCreate {
ec.mutation.SetSoldTo(s)
return ec
}
// SetNillableSoldTo sets the "sold_to" field if the given value is not nil.
func (ec *EntityCreate) SetNillableSoldTo(s *string) *EntityCreate {
if s != nil {
ec.SetSoldTo(*s)
}
return ec
}
// SetSoldPrice sets the "sold_price" field.
func (ec *EntityCreate) SetSoldPrice(f float64) *EntityCreate {
ec.mutation.SetSoldPrice(f)
return ec
}
// SetNillableSoldPrice sets the "sold_price" field if the given value is not nil.
func (ec *EntityCreate) SetNillableSoldPrice(f *float64) *EntityCreate {
if f != nil {
ec.SetSoldPrice(*f)
}
return ec
}
// SetSoldNotes sets the "sold_notes" field.
func (ec *EntityCreate) SetSoldNotes(s string) *EntityCreate {
ec.mutation.SetSoldNotes(s)
return ec
}
// SetNillableSoldNotes sets the "sold_notes" field if the given value is not nil.
func (ec *EntityCreate) SetNillableSoldNotes(s *string) *EntityCreate {
if s != nil {
ec.SetSoldNotes(*s)
}
return ec
}
// SetID sets the "id" field.
func (ec *EntityCreate) SetID(u uuid.UUID) *EntityCreate {
ec.mutation.SetID(u)
return ec
}
// SetNillableID sets the "id" field if the given value is not nil.
func (ec *EntityCreate) SetNillableID(u *uuid.UUID) *EntityCreate {
if u != nil {
ec.SetID(*u)
}
return ec
}
// SetGroupID sets the "group" edge to the Group entity by ID.
func (ec *EntityCreate) SetGroupID(id uuid.UUID) *EntityCreate {
ec.mutation.SetGroupID(id)
return ec
}
// SetGroup sets the "group" edge to the Group entity.
func (ec *EntityCreate) SetGroup(g *Group) *EntityCreate {
return ec.SetGroupID(g.ID)
}
// SetParentID sets the "parent" edge to the Entity entity by ID.
func (ec *EntityCreate) SetParentID(id uuid.UUID) *EntityCreate {
ec.mutation.SetParentID(id)
return ec
}
// SetNillableParentID sets the "parent" edge to the Entity entity by ID if the given value is not nil.
func (ec *EntityCreate) SetNillableParentID(id *uuid.UUID) *EntityCreate {
if id != nil {
ec = ec.SetParentID(*id)
}
return ec
}
// SetParent sets the "parent" edge to the Entity entity.
func (ec *EntityCreate) SetParent(e *Entity) *EntityCreate {
return ec.SetParentID(e.ID)
}
// AddChildIDs adds the "children" edge to the Entity entity by IDs.
func (ec *EntityCreate) AddChildIDs(ids ...uuid.UUID) *EntityCreate {
ec.mutation.AddChildIDs(ids...)
return ec
}
// AddChildren adds the "children" edges to the Entity entity.
func (ec *EntityCreate) AddChildren(e ...*Entity) *EntityCreate {
ids := make([]uuid.UUID, len(e))
for i := range e {
ids[i] = e[i].ID
}
return ec.AddChildIDs(ids...)
}
// SetEntityID sets the "entity" edge to the Entity entity by ID.
func (ec *EntityCreate) SetEntityID(id uuid.UUID) *EntityCreate {
ec.mutation.SetEntityID(id)
return ec
}
// SetNillableEntityID sets the "entity" edge to the Entity entity by ID if the given value is not nil.
func (ec *EntityCreate) SetNillableEntityID(id *uuid.UUID) *EntityCreate {
if id != nil {
ec = ec.SetEntityID(*id)
}
return ec
}
// SetEntity sets the "entity" edge to the Entity entity.
func (ec *EntityCreate) SetEntity(e *Entity) *EntityCreate {
return ec.SetEntityID(e.ID)
}
// SetLocationID sets the "location" edge to the Entity entity by ID.
func (ec *EntityCreate) SetLocationID(id uuid.UUID) *EntityCreate {
ec.mutation.SetLocationID(id)
return ec
}
// SetNillableLocationID sets the "location" edge to the Entity entity by ID if the given value is not nil.
func (ec *EntityCreate) SetNillableLocationID(id *uuid.UUID) *EntityCreate {
if id != nil {
ec = ec.SetLocationID(*id)
}
return ec
}
// SetLocation sets the "location" edge to the Entity entity.
func (ec *EntityCreate) SetLocation(e *Entity) *EntityCreate {
return ec.SetLocationID(e.ID)
}
// AddLabelIDs adds the "label" edge to the Label entity by IDs.
func (ec *EntityCreate) AddLabelIDs(ids ...uuid.UUID) *EntityCreate {
ec.mutation.AddLabelIDs(ids...)
return ec
}
// AddLabel adds the "label" edges to the Label entity.
func (ec *EntityCreate) AddLabel(l ...*Label) *EntityCreate {
ids := make([]uuid.UUID, len(l))
for i := range l {
ids[i] = l[i].ID
}
return ec.AddLabelIDs(ids...)
}
// AddFieldIDs adds the "fields" edge to the EntityField entity by IDs.
func (ec *EntityCreate) AddFieldIDs(ids ...uuid.UUID) *EntityCreate {
ec.mutation.AddFieldIDs(ids...)
return ec
}
// AddFields adds the "fields" edges to the EntityField entity.
func (ec *EntityCreate) AddFields(e ...*EntityField) *EntityCreate {
ids := make([]uuid.UUID, len(e))
for i := range e {
ids[i] = e[i].ID
}
return ec.AddFieldIDs(ids...)
}
// AddMaintenanceEntryIDs adds the "maintenance_entries" edge to the MaintenanceEntry entity by IDs.
func (ec *EntityCreate) AddMaintenanceEntryIDs(ids ...uuid.UUID) *EntityCreate {
ec.mutation.AddMaintenanceEntryIDs(ids...)
return ec
}
// AddMaintenanceEntries adds the "maintenance_entries" edges to the MaintenanceEntry entity.
func (ec *EntityCreate) AddMaintenanceEntries(m ...*MaintenanceEntry) *EntityCreate {
ids := make([]uuid.UUID, len(m))
for i := range m {
ids[i] = m[i].ID
}
return ec.AddMaintenanceEntryIDs(ids...)
}
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
func (ec *EntityCreate) AddAttachmentIDs(ids ...uuid.UUID) *EntityCreate {
ec.mutation.AddAttachmentIDs(ids...)
return ec
}
// AddAttachments adds the "attachments" edges to the Attachment entity.
func (ec *EntityCreate) AddAttachments(a ...*Attachment) *EntityCreate {
ids := make([]uuid.UUID, len(a))
for i := range a {
ids[i] = a[i].ID
}
return ec.AddAttachmentIDs(ids...)
}
// Mutation returns the EntityMutation object of the builder.
func (ec *EntityCreate) Mutation() *EntityMutation {
return ec.mutation
}
// Save creates the Entity in the database.
func (ec *EntityCreate) Save(ctx context.Context) (*Entity, error) {
ec.defaults()
return withHooks(ctx, ec.sqlSave, ec.mutation, ec.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (ec *EntityCreate) SaveX(ctx context.Context) *Entity {
v, err := ec.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (ec *EntityCreate) Exec(ctx context.Context) error {
_, err := ec.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (ec *EntityCreate) ExecX(ctx context.Context) {
if err := ec.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (ec *EntityCreate) defaults() {
if _, ok := ec.mutation.CreatedAt(); !ok {
v := entity.DefaultCreatedAt()
ec.mutation.SetCreatedAt(v)
}
if _, ok := ec.mutation.UpdatedAt(); !ok {
v := entity.DefaultUpdatedAt()
ec.mutation.SetUpdatedAt(v)
}
if _, ok := ec.mutation.GetType(); !ok {
v := entity.DefaultType
ec.mutation.SetType(v)
}
if _, ok := ec.mutation.Quantity(); !ok {
v := entity.DefaultQuantity
ec.mutation.SetQuantity(v)
}
if _, ok := ec.mutation.Insured(); !ok {
v := entity.DefaultInsured
ec.mutation.SetInsured(v)
}
if _, ok := ec.mutation.Archived(); !ok {
v := entity.DefaultArchived
ec.mutation.SetArchived(v)
}
if _, ok := ec.mutation.AssetID(); !ok {
v := entity.DefaultAssetID
ec.mutation.SetAssetID(v)
}
if _, ok := ec.mutation.SyncChildEntitiesLocations(); !ok {
v := entity.DefaultSyncChildEntitiesLocations
ec.mutation.SetSyncChildEntitiesLocations(v)
}
if _, ok := ec.mutation.LifetimeWarranty(); !ok {
v := entity.DefaultLifetimeWarranty
ec.mutation.SetLifetimeWarranty(v)
}
if _, ok := ec.mutation.PurchasePrice(); !ok {
v := entity.DefaultPurchasePrice
ec.mutation.SetPurchasePrice(v)
}
if _, ok := ec.mutation.SoldPrice(); !ok {
v := entity.DefaultSoldPrice
ec.mutation.SetSoldPrice(v)
}
if _, ok := ec.mutation.ID(); !ok {
v := entity.DefaultID()
ec.mutation.SetID(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (ec *EntityCreate) check() error {
if _, ok := ec.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Entity.created_at"`)}
}
if _, ok := ec.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Entity.updated_at"`)}
}
if _, ok := ec.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Entity.name"`)}
}
if v, ok := ec.mutation.Name(); ok {
if err := entity.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Entity.name": %w`, err)}
}
}
if v, ok := ec.mutation.Description(); ok {
if err := entity.DescriptionValidator(v); err != nil {
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Entity.description": %w`, err)}
}
}
if _, ok := ec.mutation.GetType(); !ok {
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Entity.type"`)}
}
if v, ok := ec.mutation.GetType(); ok {
if err := entity.TypeValidator(v); err != nil {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Entity.type": %w`, err)}
}
}
if v, ok := ec.mutation.ImportRef(); ok {
if err := entity.ImportRefValidator(v); err != nil {
return &ValidationError{Name: "import_ref", err: fmt.Errorf(`ent: validator failed for field "Entity.import_ref": %w`, err)}
}
}
if v, ok := ec.mutation.Notes(); ok {
if err := entity.NotesValidator(v); err != nil {
return &ValidationError{Name: "notes", err: fmt.Errorf(`ent: validator failed for field "Entity.notes": %w`, err)}
}
}
if _, ok := ec.mutation.Quantity(); !ok {
return &ValidationError{Name: "quantity", err: errors.New(`ent: missing required field "Entity.quantity"`)}
}
if _, ok := ec.mutation.Insured(); !ok {
return &ValidationError{Name: "insured", err: errors.New(`ent: missing required field "Entity.insured"`)}
}
if _, ok := ec.mutation.Archived(); !ok {
return &ValidationError{Name: "archived", err: errors.New(`ent: missing required field "Entity.archived"`)}
}
if _, ok := ec.mutation.AssetID(); !ok {
return &ValidationError{Name: "asset_id", err: errors.New(`ent: missing required field "Entity.asset_id"`)}
}
if _, ok := ec.mutation.SyncChildEntitiesLocations(); !ok {
return &ValidationError{Name: "sync_child_entities_locations", err: errors.New(`ent: missing required field "Entity.sync_child_entities_locations"`)}
}
if v, ok := ec.mutation.SerialNumber(); ok {
if err := entity.SerialNumberValidator(v); err != nil {
return &ValidationError{Name: "serial_number", err: fmt.Errorf(`ent: validator failed for field "Entity.serial_number": %w`, err)}
}
}
if v, ok := ec.mutation.ModelNumber(); ok {
if err := entity.ModelNumberValidator(v); err != nil {
return &ValidationError{Name: "model_number", err: fmt.Errorf(`ent: validator failed for field "Entity.model_number": %w`, err)}
}
}
if v, ok := ec.mutation.Manufacturer(); ok {
if err := entity.ManufacturerValidator(v); err != nil {
return &ValidationError{Name: "manufacturer", err: fmt.Errorf(`ent: validator failed for field "Entity.manufacturer": %w`, err)}
}
}
if _, ok := ec.mutation.LifetimeWarranty(); !ok {
return &ValidationError{Name: "lifetime_warranty", err: errors.New(`ent: missing required field "Entity.lifetime_warranty"`)}
}
if v, ok := ec.mutation.WarrantyDetails(); ok {
if err := entity.WarrantyDetailsValidator(v); err != nil {
return &ValidationError{Name: "warranty_details", err: fmt.Errorf(`ent: validator failed for field "Entity.warranty_details": %w`, err)}
}
}
if _, ok := ec.mutation.PurchasePrice(); !ok {
return &ValidationError{Name: "purchase_price", err: errors.New(`ent: missing required field "Entity.purchase_price"`)}
}
if _, ok := ec.mutation.SoldPrice(); !ok {
return &ValidationError{Name: "sold_price", err: errors.New(`ent: missing required field "Entity.sold_price"`)}
}
if v, ok := ec.mutation.SoldNotes(); ok {
if err := entity.SoldNotesValidator(v); err != nil {
return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Entity.sold_notes": %w`, err)}
}
}
if len(ec.mutation.GroupIDs()) == 0 {
return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Entity.group"`)}
}
return nil
}
func (ec *EntityCreate) sqlSave(ctx context.Context) (*Entity, error) {
if err := ec.check(); err != nil {
return nil, err
}
_node, _spec := ec.createSpec()
if err := sqlgraph.CreateNode(ctx, ec.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
}
}
ec.mutation.id = &_node.ID
ec.mutation.done = true
return _node, nil
}
func (ec *EntityCreate) createSpec() (*Entity, *sqlgraph.CreateSpec) {
var (
_node = &Entity{config: ec.config}
_spec = sqlgraph.NewCreateSpec(entity.Table, sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID))
)
if id, ok := ec.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = &id
}
if value, ok := ec.mutation.CreatedAt(); ok {
_spec.SetField(entity.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := ec.mutation.UpdatedAt(); ok {
_spec.SetField(entity.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := ec.mutation.Name(); ok {
_spec.SetField(entity.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := ec.mutation.Description(); ok {
_spec.SetField(entity.FieldDescription, field.TypeString, value)
_node.Description = value
}
if value, ok := ec.mutation.GetType(); ok {
_spec.SetField(entity.FieldType, field.TypeEnum, value)
_node.Type = value
}
if value, ok := ec.mutation.ImportRef(); ok {
_spec.SetField(entity.FieldImportRef, field.TypeString, value)
_node.ImportRef = value
}
if value, ok := ec.mutation.Notes(); ok {
_spec.SetField(entity.FieldNotes, field.TypeString, value)
_node.Notes = value
}
if value, ok := ec.mutation.Quantity(); ok {
_spec.SetField(entity.FieldQuantity, field.TypeInt, value)
_node.Quantity = value
}
if value, ok := ec.mutation.Insured(); ok {
_spec.SetField(entity.FieldInsured, field.TypeBool, value)
_node.Insured = value
}
if value, ok := ec.mutation.Archived(); ok {
_spec.SetField(entity.FieldArchived, field.TypeBool, value)
_node.Archived = value
}
if value, ok := ec.mutation.AssetID(); ok {
_spec.SetField(entity.FieldAssetID, field.TypeInt, value)
_node.AssetID = value
}
if value, ok := ec.mutation.SyncChildEntitiesLocations(); ok {
_spec.SetField(entity.FieldSyncChildEntitiesLocations, field.TypeBool, value)
_node.SyncChildEntitiesLocations = value
}
if value, ok := ec.mutation.SerialNumber(); ok {
_spec.SetField(entity.FieldSerialNumber, field.TypeString, value)
_node.SerialNumber = value
}
if value, ok := ec.mutation.ModelNumber(); ok {
_spec.SetField(entity.FieldModelNumber, field.TypeString, value)
_node.ModelNumber = value
}
if value, ok := ec.mutation.Manufacturer(); ok {
_spec.SetField(entity.FieldManufacturer, field.TypeString, value)
_node.Manufacturer = value
}
if value, ok := ec.mutation.LifetimeWarranty(); ok {
_spec.SetField(entity.FieldLifetimeWarranty, field.TypeBool, value)
_node.LifetimeWarranty = value
}
if value, ok := ec.mutation.WarrantyExpires(); ok {
_spec.SetField(entity.FieldWarrantyExpires, field.TypeTime, value)
_node.WarrantyExpires = value
}
if value, ok := ec.mutation.WarrantyDetails(); ok {
_spec.SetField(entity.FieldWarrantyDetails, field.TypeString, value)
_node.WarrantyDetails = value
}
if value, ok := ec.mutation.PurchaseTime(); ok {
_spec.SetField(entity.FieldPurchaseTime, field.TypeTime, value)
_node.PurchaseTime = value
}
if value, ok := ec.mutation.PurchaseFrom(); ok {
_spec.SetField(entity.FieldPurchaseFrom, field.TypeString, value)
_node.PurchaseFrom = value
}
if value, ok := ec.mutation.PurchasePrice(); ok {
_spec.SetField(entity.FieldPurchasePrice, field.TypeFloat64, value)
_node.PurchasePrice = value
}
if value, ok := ec.mutation.SoldTime(); ok {
_spec.SetField(entity.FieldSoldTime, field.TypeTime, value)
_node.SoldTime = value
}
if value, ok := ec.mutation.SoldTo(); ok {
_spec.SetField(entity.FieldSoldTo, field.TypeString, value)
_node.SoldTo = value
}
if value, ok := ec.mutation.SoldPrice(); ok {
_spec.SetField(entity.FieldSoldPrice, field.TypeFloat64, value)
_node.SoldPrice = value
}
if value, ok := ec.mutation.SoldNotes(); ok {
_spec.SetField(entity.FieldSoldNotes, field.TypeString, value)
_node.SoldNotes = value
}
if nodes := ec.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: entity.GroupTable,
Columns: []string{entity.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.group_entities = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := ec.mutation.ParentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: entity.ParentTable,
Columns: []string{entity.ParentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.entity_children = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := ec.mutation.ChildrenIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: entity.ChildrenTable,
Columns: []string{entity.ChildrenColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := ec.mutation.EntityIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: true,
Table: entity.EntityTable,
Columns: []string{entity.EntityColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.entity_location = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := ec.mutation.LocationIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: false,
Table: entity.LocationTable,
Columns: []string{entity.LocationColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := ec.mutation.LabelIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: entity.LabelTable,
Columns: entity.LabelPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := ec.mutation.FieldsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: entity.FieldsTable,
Columns: []string{entity.FieldsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(entityfield.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := ec.mutation.MaintenanceEntriesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: entity.MaintenanceEntriesTable,
Columns: []string{entity.MaintenanceEntriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(maintenanceentry.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := ec.mutation.AttachmentsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: entity.AttachmentsTable,
Columns: []string{entity.AttachmentsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// EntityCreateBulk is the builder for creating many Entity entities in bulk.
type EntityCreateBulk struct {
config
err error
builders []*EntityCreate
}
// Save creates the Entity entities in the database.
func (ecb *EntityCreateBulk) Save(ctx context.Context) ([]*Entity, error) {
if ecb.err != nil {
return nil, ecb.err
}
specs := make([]*sqlgraph.CreateSpec, len(ecb.builders))
nodes := make([]*Entity, len(ecb.builders))
mutators := make([]Mutator, len(ecb.builders))
for i := range ecb.builders {
func(i int, root context.Context) {
builder := ecb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*EntityMutation)
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, ecb.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, ecb.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, ecb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (ecb *EntityCreateBulk) SaveX(ctx context.Context) []*Entity {
v, err := ecb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (ecb *EntityCreateBulk) Exec(ctx context.Context) error {
_, err := ecb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (ecb *EntityCreateBulk) ExecX(ctx context.Context) {
if err := ecb.Exec(ctx); err != nil {
panic(err)
}
}