diff --git a/backend/internal/data/ent/item.go b/backend/internal/data/ent/item.go deleted file mode 100644 index 27c4f38d..00000000 --- a/backend/internal/data/ent/item.go +++ /dev/null @@ -1,542 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "github.com/google/uuid" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" -) - -// Item is the model entity for the Item schema. -type Item struct { - config `json:"-"` - // ID of the ent. - ID uuid.UUID `json:"id,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at,omitempty"` - // Name holds the value of the "name" field. - Name string `json:"name,omitempty"` - // Description holds the value of the "description" field. - Description string `json:"description,omitempty"` - // ImportRef holds the value of the "import_ref" field. - ImportRef string `json:"import_ref,omitempty"` - // Notes holds the value of the "notes" field. - Notes string `json:"notes,omitempty"` - // Quantity holds the value of the "quantity" field. - Quantity int `json:"quantity,omitempty"` - // Insured holds the value of the "insured" field. - Insured bool `json:"insured,omitempty"` - // Archived holds the value of the "archived" field. - Archived bool `json:"archived,omitempty"` - // AssetID holds the value of the "asset_id" field. - AssetID int `json:"asset_id,omitempty"` - // SyncChildItemsLocations holds the value of the "sync_child_items_locations" field. - SyncChildItemsLocations bool `json:"sync_child_items_locations,omitempty"` - // SerialNumber holds the value of the "serial_number" field. - SerialNumber string `json:"serial_number,omitempty"` - // ModelNumber holds the value of the "model_number" field. - ModelNumber string `json:"model_number,omitempty"` - // Manufacturer holds the value of the "manufacturer" field. - Manufacturer string `json:"manufacturer,omitempty"` - // LifetimeWarranty holds the value of the "lifetime_warranty" field. - LifetimeWarranty bool `json:"lifetime_warranty,omitempty"` - // WarrantyExpires holds the value of the "warranty_expires" field. - WarrantyExpires time.Time `json:"warranty_expires,omitempty"` - // WarrantyDetails holds the value of the "warranty_details" field. - WarrantyDetails string `json:"warranty_details,omitempty"` - // PurchaseTime holds the value of the "purchase_time" field. - PurchaseTime time.Time `json:"purchase_time,omitempty"` - // PurchaseFrom holds the value of the "purchase_from" field. - PurchaseFrom string `json:"purchase_from,omitempty"` - // PurchasePrice holds the value of the "purchase_price" field. - PurchasePrice float64 `json:"purchase_price,omitempty"` - // SoldTime holds the value of the "sold_time" field. - SoldTime time.Time `json:"sold_time,omitempty"` - // SoldTo holds the value of the "sold_to" field. - SoldTo string `json:"sold_to,omitempty"` - // SoldPrice holds the value of the "sold_price" field. - SoldPrice float64 `json:"sold_price,omitempty"` - // SoldNotes holds the value of the "sold_notes" field. - SoldNotes string `json:"sold_notes,omitempty"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the ItemQuery when eager-loading is set. - Edges ItemEdges `json:"edges"` - group_items *uuid.UUID - item_children *uuid.UUID - location_items *uuid.UUID - selectValues sql.SelectValues -} - -// ItemEdges holds the relations/edges for other nodes in the graph. -type ItemEdges struct { - // Group holds the value of the group edge. - Group *Group `json:"group,omitempty"` - // Parent holds the value of the parent edge. - Parent *Item `json:"parent,omitempty"` - // Children holds the value of the children edge. - Children []*Item `json:"children,omitempty"` - // Label holds the value of the label edge. - Label []*Label `json:"label,omitempty"` - // Location holds the value of the location edge. - Location *Location `json:"location,omitempty"` - // Fields holds the value of the fields edge. - Fields []*ItemField `json:"fields,omitempty"` - // MaintenanceEntries holds the value of the maintenance_entries edge. - MaintenanceEntries []*MaintenanceEntry `json:"maintenance_entries,omitempty"` - // Attachments holds the value of the attachments edge. - Attachments []*Attachment `json:"attachments,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [8]bool -} - -// GroupOrErr returns the Group value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e ItemEdges) GroupOrErr() (*Group, error) { - if e.Group != nil { - return e.Group, nil - } else if e.loadedTypes[0] { - return nil, &NotFoundError{label: group.Label} - } - return nil, &NotLoadedError{edge: "group"} -} - -// ParentOrErr returns the Parent value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e ItemEdges) ParentOrErr() (*Item, error) { - if e.Parent != nil { - return e.Parent, nil - } else if e.loadedTypes[1] { - return nil, &NotFoundError{label: item.Label} - } - return nil, &NotLoadedError{edge: "parent"} -} - -// ChildrenOrErr returns the Children value or an error if the edge -// was not loaded in eager-loading. -func (e ItemEdges) ChildrenOrErr() ([]*Item, error) { - if e.loadedTypes[2] { - return e.Children, nil - } - return nil, &NotLoadedError{edge: "children"} -} - -// LabelOrErr returns the Label value or an error if the edge -// was not loaded in eager-loading. -func (e ItemEdges) LabelOrErr() ([]*Label, error) { - if e.loadedTypes[3] { - return e.Label, nil - } - return nil, &NotLoadedError{edge: "label"} -} - -// LocationOrErr returns the Location value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e ItemEdges) LocationOrErr() (*Location, error) { - if e.Location != nil { - return e.Location, nil - } else if e.loadedTypes[4] { - return nil, &NotFoundError{label: location.Label} - } - return nil, &NotLoadedError{edge: "location"} -} - -// FieldsOrErr returns the Fields value or an error if the edge -// was not loaded in eager-loading. -func (e ItemEdges) FieldsOrErr() ([]*ItemField, error) { - if e.loadedTypes[5] { - return e.Fields, nil - } - return nil, &NotLoadedError{edge: "fields"} -} - -// MaintenanceEntriesOrErr returns the MaintenanceEntries value or an error if the edge -// was not loaded in eager-loading. -func (e ItemEdges) MaintenanceEntriesOrErr() ([]*MaintenanceEntry, error) { - if e.loadedTypes[6] { - return e.MaintenanceEntries, nil - } - return nil, &NotLoadedError{edge: "maintenance_entries"} -} - -// AttachmentsOrErr returns the Attachments value or an error if the edge -// was not loaded in eager-loading. -func (e ItemEdges) AttachmentsOrErr() ([]*Attachment, error) { - if e.loadedTypes[7] { - return e.Attachments, nil - } - return nil, &NotLoadedError{edge: "attachments"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*Item) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case item.FieldInsured, item.FieldArchived, item.FieldSyncChildItemsLocations, item.FieldLifetimeWarranty: - values[i] = new(sql.NullBool) - case item.FieldPurchasePrice, item.FieldSoldPrice: - values[i] = new(sql.NullFloat64) - case item.FieldQuantity, item.FieldAssetID: - values[i] = new(sql.NullInt64) - case item.FieldName, item.FieldDescription, item.FieldImportRef, item.FieldNotes, item.FieldSerialNumber, item.FieldModelNumber, item.FieldManufacturer, item.FieldWarrantyDetails, item.FieldPurchaseFrom, item.FieldSoldTo, item.FieldSoldNotes: - values[i] = new(sql.NullString) - case item.FieldCreatedAt, item.FieldUpdatedAt, item.FieldWarrantyExpires, item.FieldPurchaseTime, item.FieldSoldTime: - values[i] = new(sql.NullTime) - case item.FieldID: - values[i] = new(uuid.UUID) - case item.ForeignKeys[0]: // group_items - values[i] = &sql.NullScanner{S: new(uuid.UUID)} - case item.ForeignKeys[1]: // item_children - values[i] = &sql.NullScanner{S: new(uuid.UUID)} - case item.ForeignKeys[2]: // location_items - values[i] = &sql.NullScanner{S: new(uuid.UUID)} - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Item fields. -func (_m *Item) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case item.FieldID: - if value, ok := values[i].(*uuid.UUID); !ok { - return fmt.Errorf("unexpected type %T for field id", values[i]) - } else if value != nil { - _m.ID = *value - } - case item.FieldCreatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[i]) - } else if value.Valid { - _m.CreatedAt = value.Time - } - case item.FieldUpdatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[i]) - } else if value.Valid { - _m.UpdatedAt = value.Time - } - case item.FieldName: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field name", values[i]) - } else if value.Valid { - _m.Name = value.String - } - case item.FieldDescription: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field description", values[i]) - } else if value.Valid { - _m.Description = value.String - } - case item.FieldImportRef: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field import_ref", values[i]) - } else if value.Valid { - _m.ImportRef = value.String - } - case item.FieldNotes: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field notes", values[i]) - } else if value.Valid { - _m.Notes = value.String - } - case item.FieldQuantity: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field quantity", values[i]) - } else if value.Valid { - _m.Quantity = int(value.Int64) - } - case item.FieldInsured: - if value, ok := values[i].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field insured", values[i]) - } else if value.Valid { - _m.Insured = value.Bool - } - case item.FieldArchived: - if value, ok := values[i].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field archived", values[i]) - } else if value.Valid { - _m.Archived = value.Bool - } - case item.FieldAssetID: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field asset_id", values[i]) - } else if value.Valid { - _m.AssetID = int(value.Int64) - } - case item.FieldSyncChildItemsLocations: - if value, ok := values[i].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field sync_child_items_locations", values[i]) - } else if value.Valid { - _m.SyncChildItemsLocations = value.Bool - } - case item.FieldSerialNumber: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field serial_number", values[i]) - } else if value.Valid { - _m.SerialNumber = value.String - } - case item.FieldModelNumber: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field model_number", values[i]) - } else if value.Valid { - _m.ModelNumber = value.String - } - case item.FieldManufacturer: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field manufacturer", values[i]) - } else if value.Valid { - _m.Manufacturer = value.String - } - case item.FieldLifetimeWarranty: - if value, ok := values[i].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field lifetime_warranty", values[i]) - } else if value.Valid { - _m.LifetimeWarranty = value.Bool - } - case item.FieldWarrantyExpires: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field warranty_expires", values[i]) - } else if value.Valid { - _m.WarrantyExpires = value.Time - } - case item.FieldWarrantyDetails: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field warranty_details", values[i]) - } else if value.Valid { - _m.WarrantyDetails = value.String - } - case item.FieldPurchaseTime: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field purchase_time", values[i]) - } else if value.Valid { - _m.PurchaseTime = value.Time - } - case item.FieldPurchaseFrom: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field purchase_from", values[i]) - } else if value.Valid { - _m.PurchaseFrom = value.String - } - case item.FieldPurchasePrice: - if value, ok := values[i].(*sql.NullFloat64); !ok { - return fmt.Errorf("unexpected type %T for field purchase_price", values[i]) - } else if value.Valid { - _m.PurchasePrice = value.Float64 - } - case item.FieldSoldTime: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field sold_time", values[i]) - } else if value.Valid { - _m.SoldTime = value.Time - } - case item.FieldSoldTo: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field sold_to", values[i]) - } else if value.Valid { - _m.SoldTo = value.String - } - case item.FieldSoldPrice: - if value, ok := values[i].(*sql.NullFloat64); !ok { - return fmt.Errorf("unexpected type %T for field sold_price", values[i]) - } else if value.Valid { - _m.SoldPrice = value.Float64 - } - case item.FieldSoldNotes: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field sold_notes", values[i]) - } else if value.Valid { - _m.SoldNotes = value.String - } - case item.ForeignKeys[0]: - if value, ok := values[i].(*sql.NullScanner); !ok { - return fmt.Errorf("unexpected type %T for field group_items", values[i]) - } else if value.Valid { - _m.group_items = new(uuid.UUID) - *_m.group_items = *value.S.(*uuid.UUID) - } - case item.ForeignKeys[1]: - if value, ok := values[i].(*sql.NullScanner); !ok { - return fmt.Errorf("unexpected type %T for field item_children", values[i]) - } else if value.Valid { - _m.item_children = new(uuid.UUID) - *_m.item_children = *value.S.(*uuid.UUID) - } - case item.ForeignKeys[2]: - if value, ok := values[i].(*sql.NullScanner); !ok { - return fmt.Errorf("unexpected type %T for field location_items", values[i]) - } else if value.Valid { - _m.location_items = new(uuid.UUID) - *_m.location_items = *value.S.(*uuid.UUID) - } - default: - _m.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the Item. -// This includes values selected through modifiers, order, etc. -func (_m *Item) Value(name string) (ent.Value, error) { - return _m.selectValues.Get(name) -} - -// QueryGroup queries the "group" edge of the Item entity. -func (_m *Item) QueryGroup() *GroupQuery { - return NewItemClient(_m.config).QueryGroup(_m) -} - -// QueryParent queries the "parent" edge of the Item entity. -func (_m *Item) QueryParent() *ItemQuery { - return NewItemClient(_m.config).QueryParent(_m) -} - -// QueryChildren queries the "children" edge of the Item entity. -func (_m *Item) QueryChildren() *ItemQuery { - return NewItemClient(_m.config).QueryChildren(_m) -} - -// QueryLabel queries the "label" edge of the Item entity. -func (_m *Item) QueryLabel() *LabelQuery { - return NewItemClient(_m.config).QueryLabel(_m) -} - -// QueryLocation queries the "location" edge of the Item entity. -func (_m *Item) QueryLocation() *LocationQuery { - return NewItemClient(_m.config).QueryLocation(_m) -} - -// QueryFields queries the "fields" edge of the Item entity. -func (_m *Item) QueryFields() *ItemFieldQuery { - return NewItemClient(_m.config).QueryFields(_m) -} - -// QueryMaintenanceEntries queries the "maintenance_entries" edge of the Item entity. -func (_m *Item) QueryMaintenanceEntries() *MaintenanceEntryQuery { - return NewItemClient(_m.config).QueryMaintenanceEntries(_m) -} - -// QueryAttachments queries the "attachments" edge of the Item entity. -func (_m *Item) QueryAttachments() *AttachmentQuery { - return NewItemClient(_m.config).QueryAttachments(_m) -} - -// Update returns a builder for updating this Item. -// Note that you need to call Item.Unwrap() before calling this method if this Item -// was returned from a transaction, and the transaction was committed or rolled back. -func (_m *Item) Update() *ItemUpdateOne { - return NewItemClient(_m.config).UpdateOne(_m) -} - -// Unwrap unwraps the Item entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (_m *Item) Unwrap() *Item { - _tx, ok := _m.config.driver.(*txDriver) - if !ok { - panic("ent: Item is not a transactional entity") - } - _m.config.driver = _tx.drv - return _m -} - -// String implements the fmt.Stringer. -func (_m *Item) String() string { - var builder strings.Builder - builder.WriteString("Item(") - builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) - builder.WriteString("created_at=") - builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("updated_at=") - builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("name=") - builder.WriteString(_m.Name) - builder.WriteString(", ") - builder.WriteString("description=") - builder.WriteString(_m.Description) - builder.WriteString(", ") - builder.WriteString("import_ref=") - builder.WriteString(_m.ImportRef) - builder.WriteString(", ") - builder.WriteString("notes=") - builder.WriteString(_m.Notes) - builder.WriteString(", ") - builder.WriteString("quantity=") - builder.WriteString(fmt.Sprintf("%v", _m.Quantity)) - builder.WriteString(", ") - builder.WriteString("insured=") - builder.WriteString(fmt.Sprintf("%v", _m.Insured)) - builder.WriteString(", ") - builder.WriteString("archived=") - builder.WriteString(fmt.Sprintf("%v", _m.Archived)) - builder.WriteString(", ") - builder.WriteString("asset_id=") - builder.WriteString(fmt.Sprintf("%v", _m.AssetID)) - builder.WriteString(", ") - builder.WriteString("sync_child_items_locations=") - builder.WriteString(fmt.Sprintf("%v", _m.SyncChildItemsLocations)) - builder.WriteString(", ") - builder.WriteString("serial_number=") - builder.WriteString(_m.SerialNumber) - builder.WriteString(", ") - builder.WriteString("model_number=") - builder.WriteString(_m.ModelNumber) - builder.WriteString(", ") - builder.WriteString("manufacturer=") - builder.WriteString(_m.Manufacturer) - builder.WriteString(", ") - builder.WriteString("lifetime_warranty=") - builder.WriteString(fmt.Sprintf("%v", _m.LifetimeWarranty)) - builder.WriteString(", ") - builder.WriteString("warranty_expires=") - builder.WriteString(_m.WarrantyExpires.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("warranty_details=") - builder.WriteString(_m.WarrantyDetails) - builder.WriteString(", ") - builder.WriteString("purchase_time=") - builder.WriteString(_m.PurchaseTime.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("purchase_from=") - builder.WriteString(_m.PurchaseFrom) - builder.WriteString(", ") - builder.WriteString("purchase_price=") - builder.WriteString(fmt.Sprintf("%v", _m.PurchasePrice)) - builder.WriteString(", ") - builder.WriteString("sold_time=") - builder.WriteString(_m.SoldTime.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("sold_to=") - builder.WriteString(_m.SoldTo) - builder.WriteString(", ") - builder.WriteString("sold_price=") - builder.WriteString(fmt.Sprintf("%v", _m.SoldPrice)) - builder.WriteString(", ") - builder.WriteString("sold_notes=") - builder.WriteString(_m.SoldNotes) - builder.WriteByte(')') - return builder.String() -} - -// Items is a parsable slice of Item. -type Items []*Item diff --git a/backend/internal/data/ent/item_create.go b/backend/internal/data/ent/item_create.go deleted file mode 100644 index 48a77a8e..00000000 --- a/backend/internal/data/ent/item_create.go +++ /dev/null @@ -1,1007 +0,0 @@ -// 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/group" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" -) - -// ItemCreate is the builder for creating a Item entity. -type ItemCreate struct { - config - mutation *ItemMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (_c *ItemCreate) SetCreatedAt(v time.Time) *ItemCreate { - _c.mutation.SetCreatedAt(v) - return _c -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (_c *ItemCreate) SetNillableCreatedAt(v *time.Time) *ItemCreate { - if v != nil { - _c.SetCreatedAt(*v) - } - return _c -} - -// SetUpdatedAt sets the "updated_at" field. -func (_c *ItemCreate) SetUpdatedAt(v time.Time) *ItemCreate { - _c.mutation.SetUpdatedAt(v) - return _c -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (_c *ItemCreate) SetNillableUpdatedAt(v *time.Time) *ItemCreate { - if v != nil { - _c.SetUpdatedAt(*v) - } - return _c -} - -// SetName sets the "name" field. -func (_c *ItemCreate) SetName(v string) *ItemCreate { - _c.mutation.SetName(v) - return _c -} - -// SetDescription sets the "description" field. -func (_c *ItemCreate) SetDescription(v string) *ItemCreate { - _c.mutation.SetDescription(v) - return _c -} - -// SetNillableDescription sets the "description" field if the given value is not nil. -func (_c *ItemCreate) SetNillableDescription(v *string) *ItemCreate { - if v != nil { - _c.SetDescription(*v) - } - return _c -} - -// SetImportRef sets the "import_ref" field. -func (_c *ItemCreate) SetImportRef(v string) *ItemCreate { - _c.mutation.SetImportRef(v) - return _c -} - -// SetNillableImportRef sets the "import_ref" field if the given value is not nil. -func (_c *ItemCreate) SetNillableImportRef(v *string) *ItemCreate { - if v != nil { - _c.SetImportRef(*v) - } - return _c -} - -// SetNotes sets the "notes" field. -func (_c *ItemCreate) SetNotes(v string) *ItemCreate { - _c.mutation.SetNotes(v) - return _c -} - -// SetNillableNotes sets the "notes" field if the given value is not nil. -func (_c *ItemCreate) SetNillableNotes(v *string) *ItemCreate { - if v != nil { - _c.SetNotes(*v) - } - return _c -} - -// SetQuantity sets the "quantity" field. -func (_c *ItemCreate) SetQuantity(v int) *ItemCreate { - _c.mutation.SetQuantity(v) - return _c -} - -// SetNillableQuantity sets the "quantity" field if the given value is not nil. -func (_c *ItemCreate) SetNillableQuantity(v *int) *ItemCreate { - if v != nil { - _c.SetQuantity(*v) - } - return _c -} - -// SetInsured sets the "insured" field. -func (_c *ItemCreate) SetInsured(v bool) *ItemCreate { - _c.mutation.SetInsured(v) - return _c -} - -// SetNillableInsured sets the "insured" field if the given value is not nil. -func (_c *ItemCreate) SetNillableInsured(v *bool) *ItemCreate { - if v != nil { - _c.SetInsured(*v) - } - return _c -} - -// SetArchived sets the "archived" field. -func (_c *ItemCreate) SetArchived(v bool) *ItemCreate { - _c.mutation.SetArchived(v) - return _c -} - -// SetNillableArchived sets the "archived" field if the given value is not nil. -func (_c *ItemCreate) SetNillableArchived(v *bool) *ItemCreate { - if v != nil { - _c.SetArchived(*v) - } - return _c -} - -// SetAssetID sets the "asset_id" field. -func (_c *ItemCreate) SetAssetID(v int) *ItemCreate { - _c.mutation.SetAssetID(v) - return _c -} - -// SetNillableAssetID sets the "asset_id" field if the given value is not nil. -func (_c *ItemCreate) SetNillableAssetID(v *int) *ItemCreate { - if v != nil { - _c.SetAssetID(*v) - } - return _c -} - -// SetSyncChildItemsLocations sets the "sync_child_items_locations" field. -func (_c *ItemCreate) SetSyncChildItemsLocations(v bool) *ItemCreate { - _c.mutation.SetSyncChildItemsLocations(v) - return _c -} - -// SetNillableSyncChildItemsLocations sets the "sync_child_items_locations" field if the given value is not nil. -func (_c *ItemCreate) SetNillableSyncChildItemsLocations(v *bool) *ItemCreate { - if v != nil { - _c.SetSyncChildItemsLocations(*v) - } - return _c -} - -// SetSerialNumber sets the "serial_number" field. -func (_c *ItemCreate) SetSerialNumber(v string) *ItemCreate { - _c.mutation.SetSerialNumber(v) - return _c -} - -// SetNillableSerialNumber sets the "serial_number" field if the given value is not nil. -func (_c *ItemCreate) SetNillableSerialNumber(v *string) *ItemCreate { - if v != nil { - _c.SetSerialNumber(*v) - } - return _c -} - -// SetModelNumber sets the "model_number" field. -func (_c *ItemCreate) SetModelNumber(v string) *ItemCreate { - _c.mutation.SetModelNumber(v) - return _c -} - -// SetNillableModelNumber sets the "model_number" field if the given value is not nil. -func (_c *ItemCreate) SetNillableModelNumber(v *string) *ItemCreate { - if v != nil { - _c.SetModelNumber(*v) - } - return _c -} - -// SetManufacturer sets the "manufacturer" field. -func (_c *ItemCreate) SetManufacturer(v string) *ItemCreate { - _c.mutation.SetManufacturer(v) - return _c -} - -// SetNillableManufacturer sets the "manufacturer" field if the given value is not nil. -func (_c *ItemCreate) SetNillableManufacturer(v *string) *ItemCreate { - if v != nil { - _c.SetManufacturer(*v) - } - return _c -} - -// SetLifetimeWarranty sets the "lifetime_warranty" field. -func (_c *ItemCreate) SetLifetimeWarranty(v bool) *ItemCreate { - _c.mutation.SetLifetimeWarranty(v) - return _c -} - -// SetNillableLifetimeWarranty sets the "lifetime_warranty" field if the given value is not nil. -func (_c *ItemCreate) SetNillableLifetimeWarranty(v *bool) *ItemCreate { - if v != nil { - _c.SetLifetimeWarranty(*v) - } - return _c -} - -// SetWarrantyExpires sets the "warranty_expires" field. -func (_c *ItemCreate) SetWarrantyExpires(v time.Time) *ItemCreate { - _c.mutation.SetWarrantyExpires(v) - return _c -} - -// SetNillableWarrantyExpires sets the "warranty_expires" field if the given value is not nil. -func (_c *ItemCreate) SetNillableWarrantyExpires(v *time.Time) *ItemCreate { - if v != nil { - _c.SetWarrantyExpires(*v) - } - return _c -} - -// SetWarrantyDetails sets the "warranty_details" field. -func (_c *ItemCreate) SetWarrantyDetails(v string) *ItemCreate { - _c.mutation.SetWarrantyDetails(v) - return _c -} - -// SetNillableWarrantyDetails sets the "warranty_details" field if the given value is not nil. -func (_c *ItemCreate) SetNillableWarrantyDetails(v *string) *ItemCreate { - if v != nil { - _c.SetWarrantyDetails(*v) - } - return _c -} - -// SetPurchaseTime sets the "purchase_time" field. -func (_c *ItemCreate) SetPurchaseTime(v time.Time) *ItemCreate { - _c.mutation.SetPurchaseTime(v) - return _c -} - -// SetNillablePurchaseTime sets the "purchase_time" field if the given value is not nil. -func (_c *ItemCreate) SetNillablePurchaseTime(v *time.Time) *ItemCreate { - if v != nil { - _c.SetPurchaseTime(*v) - } - return _c -} - -// SetPurchaseFrom sets the "purchase_from" field. -func (_c *ItemCreate) SetPurchaseFrom(v string) *ItemCreate { - _c.mutation.SetPurchaseFrom(v) - return _c -} - -// SetNillablePurchaseFrom sets the "purchase_from" field if the given value is not nil. -func (_c *ItemCreate) SetNillablePurchaseFrom(v *string) *ItemCreate { - if v != nil { - _c.SetPurchaseFrom(*v) - } - return _c -} - -// SetPurchasePrice sets the "purchase_price" field. -func (_c *ItemCreate) SetPurchasePrice(v float64) *ItemCreate { - _c.mutation.SetPurchasePrice(v) - return _c -} - -// SetNillablePurchasePrice sets the "purchase_price" field if the given value is not nil. -func (_c *ItemCreate) SetNillablePurchasePrice(v *float64) *ItemCreate { - if v != nil { - _c.SetPurchasePrice(*v) - } - return _c -} - -// SetSoldTime sets the "sold_time" field. -func (_c *ItemCreate) SetSoldTime(v time.Time) *ItemCreate { - _c.mutation.SetSoldTime(v) - return _c -} - -// SetNillableSoldTime sets the "sold_time" field if the given value is not nil. -func (_c *ItemCreate) SetNillableSoldTime(v *time.Time) *ItemCreate { - if v != nil { - _c.SetSoldTime(*v) - } - return _c -} - -// SetSoldTo sets the "sold_to" field. -func (_c *ItemCreate) SetSoldTo(v string) *ItemCreate { - _c.mutation.SetSoldTo(v) - return _c -} - -// SetNillableSoldTo sets the "sold_to" field if the given value is not nil. -func (_c *ItemCreate) SetNillableSoldTo(v *string) *ItemCreate { - if v != nil { - _c.SetSoldTo(*v) - } - return _c -} - -// SetSoldPrice sets the "sold_price" field. -func (_c *ItemCreate) SetSoldPrice(v float64) *ItemCreate { - _c.mutation.SetSoldPrice(v) - return _c -} - -// SetNillableSoldPrice sets the "sold_price" field if the given value is not nil. -func (_c *ItemCreate) SetNillableSoldPrice(v *float64) *ItemCreate { - if v != nil { - _c.SetSoldPrice(*v) - } - return _c -} - -// SetSoldNotes sets the "sold_notes" field. -func (_c *ItemCreate) SetSoldNotes(v string) *ItemCreate { - _c.mutation.SetSoldNotes(v) - return _c -} - -// SetNillableSoldNotes sets the "sold_notes" field if the given value is not nil. -func (_c *ItemCreate) SetNillableSoldNotes(v *string) *ItemCreate { - if v != nil { - _c.SetSoldNotes(*v) - } - return _c -} - -// SetID sets the "id" field. -func (_c *ItemCreate) SetID(v uuid.UUID) *ItemCreate { - _c.mutation.SetID(v) - return _c -} - -// SetNillableID sets the "id" field if the given value is not nil. -func (_c *ItemCreate) SetNillableID(v *uuid.UUID) *ItemCreate { - if v != nil { - _c.SetID(*v) - } - return _c -} - -// SetGroupID sets the "group" edge to the Group entity by ID. -func (_c *ItemCreate) SetGroupID(id uuid.UUID) *ItemCreate { - _c.mutation.SetGroupID(id) - return _c -} - -// SetGroup sets the "group" edge to the Group entity. -func (_c *ItemCreate) SetGroup(v *Group) *ItemCreate { - return _c.SetGroupID(v.ID) -} - -// SetParentID sets the "parent" edge to the Item entity by ID. -func (_c *ItemCreate) SetParentID(id uuid.UUID) *ItemCreate { - _c.mutation.SetParentID(id) - return _c -} - -// SetNillableParentID sets the "parent" edge to the Item entity by ID if the given value is not nil. -func (_c *ItemCreate) SetNillableParentID(id *uuid.UUID) *ItemCreate { - if id != nil { - _c = _c.SetParentID(*id) - } - return _c -} - -// SetParent sets the "parent" edge to the Item entity. -func (_c *ItemCreate) SetParent(v *Item) *ItemCreate { - return _c.SetParentID(v.ID) -} - -// AddChildIDs adds the "children" edge to the Item entity by IDs. -func (_c *ItemCreate) AddChildIDs(ids ...uuid.UUID) *ItemCreate { - _c.mutation.AddChildIDs(ids...) - return _c -} - -// AddChildren adds the "children" edges to the Item entity. -func (_c *ItemCreate) AddChildren(v ...*Item) *ItemCreate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _c.AddChildIDs(ids...) -} - -// AddLabelIDs adds the "label" edge to the Label entity by IDs. -func (_c *ItemCreate) AddLabelIDs(ids ...uuid.UUID) *ItemCreate { - _c.mutation.AddLabelIDs(ids...) - return _c -} - -// AddLabel adds the "label" edges to the Label entity. -func (_c *ItemCreate) AddLabel(v ...*Label) *ItemCreate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _c.AddLabelIDs(ids...) -} - -// SetLocationID sets the "location" edge to the Location entity by ID. -func (_c *ItemCreate) SetLocationID(id uuid.UUID) *ItemCreate { - _c.mutation.SetLocationID(id) - return _c -} - -// SetNillableLocationID sets the "location" edge to the Location entity by ID if the given value is not nil. -func (_c *ItemCreate) SetNillableLocationID(id *uuid.UUID) *ItemCreate { - if id != nil { - _c = _c.SetLocationID(*id) - } - return _c -} - -// SetLocation sets the "location" edge to the Location entity. -func (_c *ItemCreate) SetLocation(v *Location) *ItemCreate { - return _c.SetLocationID(v.ID) -} - -// AddFieldIDs adds the "fields" edge to the ItemField entity by IDs. -func (_c *ItemCreate) AddFieldIDs(ids ...uuid.UUID) *ItemCreate { - _c.mutation.AddFieldIDs(ids...) - return _c -} - -// AddFields adds the "fields" edges to the ItemField entity. -func (_c *ItemCreate) AddFields(v ...*ItemField) *ItemCreate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _c.AddFieldIDs(ids...) -} - -// AddMaintenanceEntryIDs adds the "maintenance_entries" edge to the MaintenanceEntry entity by IDs. -func (_c *ItemCreate) AddMaintenanceEntryIDs(ids ...uuid.UUID) *ItemCreate { - _c.mutation.AddMaintenanceEntryIDs(ids...) - return _c -} - -// AddMaintenanceEntries adds the "maintenance_entries" edges to the MaintenanceEntry entity. -func (_c *ItemCreate) AddMaintenanceEntries(v ...*MaintenanceEntry) *ItemCreate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _c.AddMaintenanceEntryIDs(ids...) -} - -// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs. -func (_c *ItemCreate) AddAttachmentIDs(ids ...uuid.UUID) *ItemCreate { - _c.mutation.AddAttachmentIDs(ids...) - return _c -} - -// AddAttachments adds the "attachments" edges to the Attachment entity. -func (_c *ItemCreate) AddAttachments(v ...*Attachment) *ItemCreate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _c.AddAttachmentIDs(ids...) -} - -// Mutation returns the ItemMutation object of the builder. -func (_c *ItemCreate) Mutation() *ItemMutation { - return _c.mutation -} - -// Save creates the Item in the database. -func (_c *ItemCreate) Save(ctx context.Context) (*Item, error) { - _c.defaults() - return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (_c *ItemCreate) SaveX(ctx context.Context) *Item { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *ItemCreate) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *ItemCreate) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_c *ItemCreate) defaults() { - if _, ok := _c.mutation.CreatedAt(); !ok { - v := item.DefaultCreatedAt() - _c.mutation.SetCreatedAt(v) - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - v := item.DefaultUpdatedAt() - _c.mutation.SetUpdatedAt(v) - } - if _, ok := _c.mutation.Quantity(); !ok { - v := item.DefaultQuantity - _c.mutation.SetQuantity(v) - } - if _, ok := _c.mutation.Insured(); !ok { - v := item.DefaultInsured - _c.mutation.SetInsured(v) - } - if _, ok := _c.mutation.Archived(); !ok { - v := item.DefaultArchived - _c.mutation.SetArchived(v) - } - if _, ok := _c.mutation.AssetID(); !ok { - v := item.DefaultAssetID - _c.mutation.SetAssetID(v) - } - if _, ok := _c.mutation.SyncChildItemsLocations(); !ok { - v := item.DefaultSyncChildItemsLocations - _c.mutation.SetSyncChildItemsLocations(v) - } - if _, ok := _c.mutation.LifetimeWarranty(); !ok { - v := item.DefaultLifetimeWarranty - _c.mutation.SetLifetimeWarranty(v) - } - if _, ok := _c.mutation.PurchasePrice(); !ok { - v := item.DefaultPurchasePrice - _c.mutation.SetPurchasePrice(v) - } - if _, ok := _c.mutation.SoldPrice(); !ok { - v := item.DefaultSoldPrice - _c.mutation.SetSoldPrice(v) - } - if _, ok := _c.mutation.ID(); !ok { - v := item.DefaultID() - _c.mutation.SetID(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_c *ItemCreate) check() error { - if _, ok := _c.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Item.created_at"`)} - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Item.updated_at"`)} - } - if _, ok := _c.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Item.name"`)} - } - if v, ok := _c.mutation.Name(); ok { - if err := item.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Item.name": %w`, err)} - } - } - if v, ok := _c.mutation.Description(); ok { - if err := item.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Item.description": %w`, err)} - } - } - if v, ok := _c.mutation.ImportRef(); ok { - if err := item.ImportRefValidator(v); err != nil { - return &ValidationError{Name: "import_ref", err: fmt.Errorf(`ent: validator failed for field "Item.import_ref": %w`, err)} - } - } - if v, ok := _c.mutation.Notes(); ok { - if err := item.NotesValidator(v); err != nil { - return &ValidationError{Name: "notes", err: fmt.Errorf(`ent: validator failed for field "Item.notes": %w`, err)} - } - } - if _, ok := _c.mutation.Quantity(); !ok { - return &ValidationError{Name: "quantity", err: errors.New(`ent: missing required field "Item.quantity"`)} - } - if _, ok := _c.mutation.Insured(); !ok { - return &ValidationError{Name: "insured", err: errors.New(`ent: missing required field "Item.insured"`)} - } - if _, ok := _c.mutation.Archived(); !ok { - return &ValidationError{Name: "archived", err: errors.New(`ent: missing required field "Item.archived"`)} - } - if _, ok := _c.mutation.AssetID(); !ok { - return &ValidationError{Name: "asset_id", err: errors.New(`ent: missing required field "Item.asset_id"`)} - } - if _, ok := _c.mutation.SyncChildItemsLocations(); !ok { - return &ValidationError{Name: "sync_child_items_locations", err: errors.New(`ent: missing required field "Item.sync_child_items_locations"`)} - } - if v, ok := _c.mutation.SerialNumber(); ok { - if err := item.SerialNumberValidator(v); err != nil { - return &ValidationError{Name: "serial_number", err: fmt.Errorf(`ent: validator failed for field "Item.serial_number": %w`, err)} - } - } - if v, ok := _c.mutation.ModelNumber(); ok { - if err := item.ModelNumberValidator(v); err != nil { - return &ValidationError{Name: "model_number", err: fmt.Errorf(`ent: validator failed for field "Item.model_number": %w`, err)} - } - } - if v, ok := _c.mutation.Manufacturer(); ok { - if err := item.ManufacturerValidator(v); err != nil { - return &ValidationError{Name: "manufacturer", err: fmt.Errorf(`ent: validator failed for field "Item.manufacturer": %w`, err)} - } - } - if _, ok := _c.mutation.LifetimeWarranty(); !ok { - return &ValidationError{Name: "lifetime_warranty", err: errors.New(`ent: missing required field "Item.lifetime_warranty"`)} - } - if v, ok := _c.mutation.WarrantyDetails(); ok { - if err := item.WarrantyDetailsValidator(v); err != nil { - return &ValidationError{Name: "warranty_details", err: fmt.Errorf(`ent: validator failed for field "Item.warranty_details": %w`, err)} - } - } - if _, ok := _c.mutation.PurchasePrice(); !ok { - return &ValidationError{Name: "purchase_price", err: errors.New(`ent: missing required field "Item.purchase_price"`)} - } - if _, ok := _c.mutation.SoldPrice(); !ok { - return &ValidationError{Name: "sold_price", err: errors.New(`ent: missing required field "Item.sold_price"`)} - } - if v, ok := _c.mutation.SoldNotes(); ok { - if err := item.SoldNotesValidator(v); err != nil { - return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Item.sold_notes": %w`, err)} - } - } - if len(_c.mutation.GroupIDs()) == 0 { - return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Item.group"`)} - } - return nil -} - -func (_c *ItemCreate) sqlSave(ctx context.Context) (*Item, error) { - if err := _c.check(); err != nil { - return nil, err - } - _node, _spec := _c.createSpec() - if err := sqlgraph.CreateNode(ctx, _c.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 - } - } - _c.mutation.id = &_node.ID - _c.mutation.done = true - return _node, nil -} - -func (_c *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) { - var ( - _node = &Item{config: _c.config} - _spec = sqlgraph.NewCreateSpec(item.Table, sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID)) - ) - if id, ok := _c.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = &id - } - if value, ok := _c.mutation.CreatedAt(); ok { - _spec.SetField(item.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := _c.mutation.UpdatedAt(); ok { - _spec.SetField(item.FieldUpdatedAt, field.TypeTime, value) - _node.UpdatedAt = value - } - if value, ok := _c.mutation.Name(); ok { - _spec.SetField(item.FieldName, field.TypeString, value) - _node.Name = value - } - if value, ok := _c.mutation.Description(); ok { - _spec.SetField(item.FieldDescription, field.TypeString, value) - _node.Description = value - } - if value, ok := _c.mutation.ImportRef(); ok { - _spec.SetField(item.FieldImportRef, field.TypeString, value) - _node.ImportRef = value - } - if value, ok := _c.mutation.Notes(); ok { - _spec.SetField(item.FieldNotes, field.TypeString, value) - _node.Notes = value - } - if value, ok := _c.mutation.Quantity(); ok { - _spec.SetField(item.FieldQuantity, field.TypeInt, value) - _node.Quantity = value - } - if value, ok := _c.mutation.Insured(); ok { - _spec.SetField(item.FieldInsured, field.TypeBool, value) - _node.Insured = value - } - if value, ok := _c.mutation.Archived(); ok { - _spec.SetField(item.FieldArchived, field.TypeBool, value) - _node.Archived = value - } - if value, ok := _c.mutation.AssetID(); ok { - _spec.SetField(item.FieldAssetID, field.TypeInt, value) - _node.AssetID = value - } - if value, ok := _c.mutation.SyncChildItemsLocations(); ok { - _spec.SetField(item.FieldSyncChildItemsLocations, field.TypeBool, value) - _node.SyncChildItemsLocations = value - } - if value, ok := _c.mutation.SerialNumber(); ok { - _spec.SetField(item.FieldSerialNumber, field.TypeString, value) - _node.SerialNumber = value - } - if value, ok := _c.mutation.ModelNumber(); ok { - _spec.SetField(item.FieldModelNumber, field.TypeString, value) - _node.ModelNumber = value - } - if value, ok := _c.mutation.Manufacturer(); ok { - _spec.SetField(item.FieldManufacturer, field.TypeString, value) - _node.Manufacturer = value - } - if value, ok := _c.mutation.LifetimeWarranty(); ok { - _spec.SetField(item.FieldLifetimeWarranty, field.TypeBool, value) - _node.LifetimeWarranty = value - } - if value, ok := _c.mutation.WarrantyExpires(); ok { - _spec.SetField(item.FieldWarrantyExpires, field.TypeTime, value) - _node.WarrantyExpires = value - } - if value, ok := _c.mutation.WarrantyDetails(); ok { - _spec.SetField(item.FieldWarrantyDetails, field.TypeString, value) - _node.WarrantyDetails = value - } - if value, ok := _c.mutation.PurchaseTime(); ok { - _spec.SetField(item.FieldPurchaseTime, field.TypeTime, value) - _node.PurchaseTime = value - } - if value, ok := _c.mutation.PurchaseFrom(); ok { - _spec.SetField(item.FieldPurchaseFrom, field.TypeString, value) - _node.PurchaseFrom = value - } - if value, ok := _c.mutation.PurchasePrice(); ok { - _spec.SetField(item.FieldPurchasePrice, field.TypeFloat64, value) - _node.PurchasePrice = value - } - if value, ok := _c.mutation.SoldTime(); ok { - _spec.SetField(item.FieldSoldTime, field.TypeTime, value) - _node.SoldTime = value - } - if value, ok := _c.mutation.SoldTo(); ok { - _spec.SetField(item.FieldSoldTo, field.TypeString, value) - _node.SoldTo = value - } - if value, ok := _c.mutation.SoldPrice(); ok { - _spec.SetField(item.FieldSoldPrice, field.TypeFloat64, value) - _node.SoldPrice = value - } - if value, ok := _c.mutation.SoldNotes(); ok { - _spec.SetField(item.FieldSoldNotes, field.TypeString, value) - _node.SoldNotes = value - } - if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.GroupTable, - Columns: []string{item.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_items = &nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := _c.mutation.ParentIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.ParentTable, - Columns: []string{item.ParentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _node.item_children = &nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := _c.mutation.ChildrenIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.ChildrenTable, - Columns: []string{item.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := _c.mutation.LabelIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: item.LabelTable, - Columns: item.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 := _c.mutation.LocationIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.LocationTable, - Columns: []string{item.LocationColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _node.location_items = &nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := _c.mutation.FieldsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.FieldsTable, - Columns: []string{item.FieldsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := _c.mutation.MaintenanceEntriesIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.MaintenanceEntriesTable, - Columns: []string{item.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 := _c.mutation.AttachmentsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.AttachmentsTable, - Columns: []string{item.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 -} - -// ItemCreateBulk is the builder for creating many Item entities in bulk. -type ItemCreateBulk struct { - config - err error - builders []*ItemCreate -} - -// Save creates the Item entities in the database. -func (_c *ItemCreateBulk) Save(ctx context.Context) ([]*Item, error) { - if _c.err != nil { - return nil, _c.err - } - specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) - nodes := make([]*Item, len(_c.builders)) - mutators := make([]Mutator, len(_c.builders)) - for i := range _c.builders { - func(i int, root context.Context) { - builder := _c.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ItemMutation) - 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, _c.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, _c.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, _c.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (_c *ItemCreateBulk) SaveX(ctx context.Context) []*Item { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *ItemCreateBulk) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *ItemCreateBulk) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/backend/internal/data/ent/item_delete.go b/backend/internal/data/ent/item_delete.go deleted file mode 100644 index 7a01bffe..00000000 --- a/backend/internal/data/ent/item_delete.go +++ /dev/null @@ -1,88 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" -) - -// ItemDelete is the builder for deleting a Item entity. -type ItemDelete struct { - config - hooks []Hook - mutation *ItemMutation -} - -// Where appends a list predicates to the ItemDelete builder. -func (_d *ItemDelete) Where(ps ...predicate.Item) *ItemDelete { - _d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (_d *ItemDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *ItemDelete) ExecX(ctx context.Context) int { - n, err := _d.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (_d *ItemDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(item.Table, sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID)) - if ps := _d.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - _d.mutation.done = true - return affected, err -} - -// ItemDeleteOne is the builder for deleting a single Item entity. -type ItemDeleteOne struct { - _d *ItemDelete -} - -// Where appends a list predicates to the ItemDelete builder. -func (_d *ItemDeleteOne) Where(ps ...predicate.Item) *ItemDeleteOne { - _d._d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query. -func (_d *ItemDeleteOne) Exec(ctx context.Context) error { - n, err := _d._d.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{item.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *ItemDeleteOne) ExecX(ctx context.Context) { - if err := _d.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/backend/internal/data/ent/item_query.go b/backend/internal/data/ent/item_query.go deleted file mode 100644 index 8cb32410..00000000 --- a/backend/internal/data/ent/item_query.go +++ /dev/null @@ -1,1168 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "database/sql/driver" - "fmt" - "math" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "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/group" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" -) - -// ItemQuery is the builder for querying Item entities. -type ItemQuery struct { - config - ctx *QueryContext - order []item.OrderOption - inters []Interceptor - predicates []predicate.Item - withGroup *GroupQuery - withParent *ItemQuery - withChildren *ItemQuery - withLabel *LabelQuery - withLocation *LocationQuery - withFields *ItemFieldQuery - withMaintenanceEntries *MaintenanceEntryQuery - withAttachments *AttachmentQuery - withFKs bool - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the ItemQuery builder. -func (_q *ItemQuery) Where(ps ...predicate.Item) *ItemQuery { - _q.predicates = append(_q.predicates, ps...) - return _q -} - -// Limit the number of records to be returned by this query. -func (_q *ItemQuery) Limit(limit int) *ItemQuery { - _q.ctx.Limit = &limit - return _q -} - -// Offset to start from. -func (_q *ItemQuery) Offset(offset int) *ItemQuery { - _q.ctx.Offset = &offset - return _q -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (_q *ItemQuery) Unique(unique bool) *ItemQuery { - _q.ctx.Unique = &unique - return _q -} - -// Order specifies how the records should be ordered. -func (_q *ItemQuery) Order(o ...item.OrderOption) *ItemQuery { - _q.order = append(_q.order, o...) - return _q -} - -// QueryGroup chains the current query on the "group" edge. -func (_q *ItemQuery) QueryGroup() *GroupQuery { - query := (&GroupClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(item.Table, item.FieldID, selector), - sqlgraph.To(group.Table, group.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, item.GroupTable, item.GroupColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryParent chains the current query on the "parent" edge. -func (_q *ItemQuery) QueryParent() *ItemQuery { - query := (&ItemClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(item.Table, item.FieldID, selector), - sqlgraph.To(item.Table, item.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, item.ParentTable, item.ParentColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryChildren chains the current query on the "children" edge. -func (_q *ItemQuery) QueryChildren() *ItemQuery { - query := (&ItemClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(item.Table, item.FieldID, selector), - sqlgraph.To(item.Table, item.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, item.ChildrenTable, item.ChildrenColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryLabel chains the current query on the "label" edge. -func (_q *ItemQuery) QueryLabel() *LabelQuery { - query := (&LabelClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(item.Table, item.FieldID, selector), - sqlgraph.To(label.Table, label.FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, item.LabelTable, item.LabelPrimaryKey...), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryLocation chains the current query on the "location" edge. -func (_q *ItemQuery) QueryLocation() *LocationQuery { - query := (&LocationClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(item.Table, item.FieldID, selector), - sqlgraph.To(location.Table, location.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, item.LocationTable, item.LocationColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryFields chains the current query on the "fields" edge. -func (_q *ItemQuery) QueryFields() *ItemFieldQuery { - query := (&ItemFieldClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(item.Table, item.FieldID, selector), - sqlgraph.To(itemfield.Table, itemfield.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, item.FieldsTable, item.FieldsColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryMaintenanceEntries chains the current query on the "maintenance_entries" edge. -func (_q *ItemQuery) QueryMaintenanceEntries() *MaintenanceEntryQuery { - query := (&MaintenanceEntryClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(item.Table, item.FieldID, selector), - sqlgraph.To(maintenanceentry.Table, maintenanceentry.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, item.MaintenanceEntriesTable, item.MaintenanceEntriesColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryAttachments chains the current query on the "attachments" edge. -func (_q *ItemQuery) QueryAttachments() *AttachmentQuery { - query := (&AttachmentClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(item.Table, item.FieldID, selector), - sqlgraph.To(attachment.Table, attachment.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, item.AttachmentsTable, item.AttachmentsColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first Item entity from the query. -// Returns a *NotFoundError when no Item was found. -func (_q *ItemQuery) First(ctx context.Context) (*Item, error) { - nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{item.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (_q *ItemQuery) FirstX(ctx context.Context) *Item { - node, err := _q.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first Item ID from the query. -// Returns a *NotFoundError when no Item ID was found. -func (_q *ItemQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { - var ids []uuid.UUID - if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{item.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (_q *ItemQuery) FirstIDX(ctx context.Context) uuid.UUID { - id, err := _q.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single Item entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one Item entity is found. -// Returns a *NotFoundError when no Item entities are found. -func (_q *ItemQuery) Only(ctx context.Context) (*Item, error) { - nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{item.Label} - default: - return nil, &NotSingularError{item.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (_q *ItemQuery) OnlyX(ctx context.Context) *Item { - node, err := _q.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only Item ID in the query. -// Returns a *NotSingularError when more than one Item ID is found. -// Returns a *NotFoundError when no entities are found. -func (_q *ItemQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { - var ids []uuid.UUID - if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{item.Label} - default: - err = &NotSingularError{item.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *ItemQuery) OnlyIDX(ctx context.Context) uuid.UUID { - id, err := _q.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of Items. -func (_q *ItemQuery) All(ctx context.Context) ([]*Item, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*Item, *ItemQuery]() - return withInterceptors[[]*Item](ctx, _q, qr, _q.inters) -} - -// AllX is like All, but panics if an error occurs. -func (_q *ItemQuery) AllX(ctx context.Context) []*Item { - nodes, err := _q.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of Item IDs. -func (_q *ItemQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { - if _q.ctx.Unique == nil && _q.path != nil { - _q.Unique(true) - } - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) - if err = _q.Select(item.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (_q *ItemQuery) IDsX(ctx context.Context) []uuid.UUID { - ids, err := _q.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (_q *ItemQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) - if err := _q.prepareQuery(ctx); err != nil { - return 0, err - } - return withInterceptors[int](ctx, _q, querierCount[*ItemQuery](), _q.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (_q *ItemQuery) CountX(ctx context.Context) int { - count, err := _q.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (_q *ItemQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) - switch _, err := _q.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -// ExistX is like Exist, but panics if an error occurs. -func (_q *ItemQuery) ExistX(ctx context.Context) bool { - exist, err := _q.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the ItemQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (_q *ItemQuery) Clone() *ItemQuery { - if _q == nil { - return nil - } - return &ItemQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]item.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.Item{}, _q.predicates...), - withGroup: _q.withGroup.Clone(), - withParent: _q.withParent.Clone(), - withChildren: _q.withChildren.Clone(), - withLabel: _q.withLabel.Clone(), - withLocation: _q.withLocation.Clone(), - withFields: _q.withFields.Clone(), - withMaintenanceEntries: _q.withMaintenanceEntries.Clone(), - withAttachments: _q.withAttachments.Clone(), - // clone intermediate query. - sql: _q.sql.Clone(), - path: _q.path, - } -} - -// WithGroup tells the query-builder to eager-load the nodes that are connected to -// the "group" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *ItemQuery) WithGroup(opts ...func(*GroupQuery)) *ItemQuery { - query := (&GroupClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withGroup = query - return _q -} - -// WithParent tells the query-builder to eager-load the nodes that are connected to -// the "parent" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *ItemQuery) WithParent(opts ...func(*ItemQuery)) *ItemQuery { - query := (&ItemClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withParent = query - return _q -} - -// WithChildren tells the query-builder to eager-load the nodes that are connected to -// the "children" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *ItemQuery) WithChildren(opts ...func(*ItemQuery)) *ItemQuery { - query := (&ItemClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withChildren = query - return _q -} - -// WithLabel tells the query-builder to eager-load the nodes that are connected to -// the "label" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *ItemQuery) WithLabel(opts ...func(*LabelQuery)) *ItemQuery { - query := (&LabelClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withLabel = query - return _q -} - -// WithLocation tells the query-builder to eager-load the nodes that are connected to -// the "location" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *ItemQuery) WithLocation(opts ...func(*LocationQuery)) *ItemQuery { - query := (&LocationClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withLocation = query - return _q -} - -// WithFields tells the query-builder to eager-load the nodes that are connected to -// the "fields" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *ItemQuery) WithFields(opts ...func(*ItemFieldQuery)) *ItemQuery { - query := (&ItemFieldClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withFields = query - return _q -} - -// WithMaintenanceEntries tells the query-builder to eager-load the nodes that are connected to -// the "maintenance_entries" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *ItemQuery) WithMaintenanceEntries(opts ...func(*MaintenanceEntryQuery)) *ItemQuery { - query := (&MaintenanceEntryClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withMaintenanceEntries = query - return _q -} - -// WithAttachments tells the query-builder to eager-load the nodes that are connected to -// the "attachments" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *ItemQuery) WithAttachments(opts ...func(*AttachmentQuery)) *ItemQuery { - query := (&AttachmentClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withAttachments = query - return _q -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.Item.Query(). -// GroupBy(item.FieldCreatedAt). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (_q *ItemQuery) GroupBy(field string, fields ...string) *ItemGroupBy { - _q.ctx.Fields = append([]string{field}, fields...) - grbuild := &ItemGroupBy{build: _q} - grbuild.flds = &_q.ctx.Fields - grbuild.label = item.Label - grbuild.scan = grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// } -// -// client.Item.Query(). -// Select(item.FieldCreatedAt). -// Scan(ctx, &v) -func (_q *ItemQuery) Select(fields ...string) *ItemSelect { - _q.ctx.Fields = append(_q.ctx.Fields, fields...) - sbuild := &ItemSelect{ItemQuery: _q} - sbuild.label = item.Label - sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a ItemSelect configured with the given aggregations. -func (_q *ItemQuery) Aggregate(fns ...AggregateFunc) *ItemSelect { - return _q.Select().Aggregate(fns...) -} - -func (_q *ItemQuery) prepareQuery(ctx context.Context) error { - for _, inter := range _q.inters { - if inter == nil { - return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") - } - if trv, ok := inter.(Traverser); ok { - if err := trv.Traverse(ctx, _q); err != nil { - return err - } - } - } - for _, f := range _q.ctx.Fields { - if !item.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if _q.path != nil { - prev, err := _q.path(ctx) - if err != nil { - return err - } - _q.sql = prev - } - return nil -} - -func (_q *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, error) { - var ( - nodes = []*Item{} - withFKs = _q.withFKs - _spec = _q.querySpec() - loadedTypes = [8]bool{ - _q.withGroup != nil, - _q.withParent != nil, - _q.withChildren != nil, - _q.withLabel != nil, - _q.withLocation != nil, - _q.withFields != nil, - _q.withMaintenanceEntries != nil, - _q.withAttachments != nil, - } - ) - if _q.withGroup != nil || _q.withParent != nil || _q.withLocation != nil { - withFKs = true - } - if withFKs { - _spec.Node.Columns = append(_spec.Node.Columns, item.ForeignKeys...) - } - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*Item).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &Item{config: _q.config} - nodes = append(nodes, node) - node.Edges.loadedTypes = loadedTypes - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - if query := _q.withGroup; query != nil { - if err := _q.loadGroup(ctx, query, nodes, nil, - func(n *Item, e *Group) { n.Edges.Group = e }); err != nil { - return nil, err - } - } - if query := _q.withParent; query != nil { - if err := _q.loadParent(ctx, query, nodes, nil, - func(n *Item, e *Item) { n.Edges.Parent = e }); err != nil { - return nil, err - } - } - if query := _q.withChildren; query != nil { - if err := _q.loadChildren(ctx, query, nodes, - func(n *Item) { n.Edges.Children = []*Item{} }, - func(n *Item, e *Item) { n.Edges.Children = append(n.Edges.Children, e) }); err != nil { - return nil, err - } - } - if query := _q.withLabel; query != nil { - if err := _q.loadLabel(ctx, query, nodes, - func(n *Item) { n.Edges.Label = []*Label{} }, - func(n *Item, e *Label) { n.Edges.Label = append(n.Edges.Label, e) }); err != nil { - return nil, err - } - } - if query := _q.withLocation; query != nil { - if err := _q.loadLocation(ctx, query, nodes, nil, - func(n *Item, e *Location) { n.Edges.Location = e }); err != nil { - return nil, err - } - } - if query := _q.withFields; query != nil { - if err := _q.loadFields(ctx, query, nodes, - func(n *Item) { n.Edges.Fields = []*ItemField{} }, - func(n *Item, e *ItemField) { n.Edges.Fields = append(n.Edges.Fields, e) }); err != nil { - return nil, err - } - } - if query := _q.withMaintenanceEntries; query != nil { - if err := _q.loadMaintenanceEntries(ctx, query, nodes, - func(n *Item) { n.Edges.MaintenanceEntries = []*MaintenanceEntry{} }, - func(n *Item, e *MaintenanceEntry) { n.Edges.MaintenanceEntries = append(n.Edges.MaintenanceEntries, e) }); err != nil { - return nil, err - } - } - if query := _q.withAttachments; query != nil { - if err := _q.loadAttachments(ctx, query, nodes, - func(n *Item) { n.Edges.Attachments = []*Attachment{} }, - func(n *Item, e *Attachment) { n.Edges.Attachments = append(n.Edges.Attachments, e) }); err != nil { - return nil, err - } - } - return nodes, nil -} - -func (_q *ItemQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*Item, init func(*Item), assign func(*Item, *Group)) error { - ids := make([]uuid.UUID, 0, len(nodes)) - nodeids := make(map[uuid.UUID][]*Item) - for i := range nodes { - if nodes[i].group_items == nil { - continue - } - fk := *nodes[i].group_items - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - if len(ids) == 0 { - return nil - } - query.Where(group.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return fmt.Errorf(`unexpected foreign-key "group_items" returned %v`, n.ID) - } - for i := range nodes { - assign(nodes[i], n) - } - } - return nil -} -func (_q *ItemQuery) loadParent(ctx context.Context, query *ItemQuery, nodes []*Item, init func(*Item), assign func(*Item, *Item)) error { - ids := make([]uuid.UUID, 0, len(nodes)) - nodeids := make(map[uuid.UUID][]*Item) - for i := range nodes { - if nodes[i].item_children == nil { - continue - } - fk := *nodes[i].item_children - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - if len(ids) == 0 { - return nil - } - query.Where(item.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return fmt.Errorf(`unexpected foreign-key "item_children" returned %v`, n.ID) - } - for i := range nodes { - assign(nodes[i], n) - } - } - return nil -} -func (_q *ItemQuery) loadChildren(ctx context.Context, query *ItemQuery, nodes []*Item, init func(*Item), assign func(*Item, *Item)) error { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[uuid.UUID]*Item) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - if init != nil { - init(nodes[i]) - } - } - query.withFKs = true - query.Where(predicate.Item(func(s *sql.Selector) { - s.Where(sql.InValues(s.C(item.ChildrenColumn), fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - fk := n.item_children - if fk == nil { - return fmt.Errorf(`foreign-key "item_children" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "item_children" returned %v for node %v`, *fk, n.ID) - } - assign(node, n) - } - return nil -} -func (_q *ItemQuery) loadLabel(ctx context.Context, query *LabelQuery, nodes []*Item, init func(*Item), assign func(*Item, *Label)) error { - edgeIDs := make([]driver.Value, len(nodes)) - byID := make(map[uuid.UUID]*Item) - nids := make(map[uuid.UUID]map[*Item]struct{}) - for i, node := range nodes { - edgeIDs[i] = node.ID - byID[node.ID] = node - if init != nil { - init(node) - } - } - query.Where(func(s *sql.Selector) { - joinT := sql.Table(item.LabelTable) - s.Join(joinT).On(s.C(label.FieldID), joinT.C(item.LabelPrimaryKey[0])) - s.Where(sql.InValues(joinT.C(item.LabelPrimaryKey[1]), edgeIDs...)) - columns := s.SelectedColumns() - s.Select(joinT.C(item.LabelPrimaryKey[1])) - s.AppendSelect(columns...) - s.SetDistinct(false) - }) - if err := query.prepareQuery(ctx); err != nil { - return err - } - qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { - assign := spec.Assign - values := spec.ScanValues - spec.ScanValues = func(columns []string) ([]any, error) { - values, err := values(columns[1:]) - if err != nil { - return nil, err - } - return append([]any{new(uuid.UUID)}, values...), nil - } - spec.Assign = func(columns []string, values []any) error { - outValue := *values[0].(*uuid.UUID) - inValue := *values[1].(*uuid.UUID) - if nids[inValue] == nil { - nids[inValue] = map[*Item]struct{}{byID[outValue]: {}} - return assign(columns[1:], values[1:]) - } - nids[inValue][byID[outValue]] = struct{}{} - return nil - } - }) - }) - neighbors, err := withInterceptors[[]*Label](ctx, query, qr, query.inters) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nids[n.ID] - if !ok { - return fmt.Errorf(`unexpected "label" node returned %v`, n.ID) - } - for kn := range nodes { - assign(kn, n) - } - } - return nil -} -func (_q *ItemQuery) loadLocation(ctx context.Context, query *LocationQuery, nodes []*Item, init func(*Item), assign func(*Item, *Location)) error { - ids := make([]uuid.UUID, 0, len(nodes)) - nodeids := make(map[uuid.UUID][]*Item) - for i := range nodes { - if nodes[i].location_items == nil { - continue - } - fk := *nodes[i].location_items - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - if len(ids) == 0 { - return nil - } - query.Where(location.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return fmt.Errorf(`unexpected foreign-key "location_items" returned %v`, n.ID) - } - for i := range nodes { - assign(nodes[i], n) - } - } - return nil -} -func (_q *ItemQuery) loadFields(ctx context.Context, query *ItemFieldQuery, nodes []*Item, init func(*Item), assign func(*Item, *ItemField)) error { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[uuid.UUID]*Item) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - if init != nil { - init(nodes[i]) - } - } - query.withFKs = true - query.Where(predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.InValues(s.C(item.FieldsColumn), fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - fk := n.item_fields - if fk == nil { - return fmt.Errorf(`foreign-key "item_fields" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "item_fields" returned %v for node %v`, *fk, n.ID) - } - assign(node, n) - } - return nil -} -func (_q *ItemQuery) loadMaintenanceEntries(ctx context.Context, query *MaintenanceEntryQuery, nodes []*Item, init func(*Item), assign func(*Item, *MaintenanceEntry)) error { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[uuid.UUID]*Item) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - if init != nil { - init(nodes[i]) - } - } - if len(query.ctx.Fields) > 0 { - query.ctx.AppendFieldOnce(maintenanceentry.FieldItemID) - } - query.Where(predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.InValues(s.C(item.MaintenanceEntriesColumn), fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - fk := n.ItemID - node, ok := nodeids[fk] - if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "item_id" returned %v for node %v`, fk, n.ID) - } - assign(node, n) - } - return nil -} -func (_q *ItemQuery) loadAttachments(ctx context.Context, query *AttachmentQuery, nodes []*Item, init func(*Item), assign func(*Item, *Attachment)) error { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[uuid.UUID]*Item) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - if init != nil { - init(nodes[i]) - } - } - query.withFKs = true - query.Where(predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.InValues(s.C(item.AttachmentsColumn), fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - fk := n.item_attachments - if fk == nil { - return fmt.Errorf(`foreign-key "item_attachments" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "item_attachments" returned %v for node %v`, *fk, n.ID) - } - assign(node, n) - } - return nil -} - -func (_q *ItemQuery) sqlCount(ctx context.Context) (int, error) { - _spec := _q.querySpec() - _spec.Node.Columns = _q.ctx.Fields - if len(_q.ctx.Fields) > 0 { - _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique - } - return sqlgraph.CountNodes(ctx, _q.driver, _spec) -} - -func (_q *ItemQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(item.Table, item.Columns, sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID)) - _spec.From = _q.sql - if unique := _q.ctx.Unique; unique != nil { - _spec.Unique = *unique - } else if _q.path != nil { - _spec.Unique = true - } - if fields := _q.ctx.Fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, item.FieldID) - for i := range fields { - if fields[i] != item.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := _q.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := _q.ctx.Limit; limit != nil { - _spec.Limit = *limit - } - if offset := _q.ctx.Offset; offset != nil { - _spec.Offset = *offset - } - if ps := _q.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (_q *ItemQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(_q.driver.Dialect()) - t1 := builder.Table(item.Table) - columns := _q.ctx.Fields - if len(columns) == 0 { - columns = item.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if _q.sql != nil { - selector = _q.sql - selector.Select(selector.Columns(columns...)...) - } - if _q.ctx.Unique != nil && *_q.ctx.Unique { - selector.Distinct() - } - for _, p := range _q.predicates { - p(selector) - } - for _, p := range _q.order { - p(selector) - } - if offset := _q.ctx.Offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := _q.ctx.Limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// ItemGroupBy is the group-by builder for Item entities. -type ItemGroupBy struct { - selector - build *ItemQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (_g *ItemGroupBy) Aggregate(fns ...AggregateFunc) *ItemGroupBy { - _g.fns = append(_g.fns, fns...) - return _g -} - -// Scan applies the selector query and scans the result into the given value. -func (_g *ItemGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) - if err := _g.build.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*ItemQuery, *ItemGroupBy](ctx, _g.build, _g, _g.build.inters, v) -} - -func (_g *ItemGroupBy) sqlScan(ctx context.Context, root *ItemQuery, v any) error { - selector := root.sqlQuery(ctx).Select() - aggregation := make([]string, 0, len(_g.fns)) - for _, fn := range _g.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) - for _, f := range *_g.flds { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - selector.GroupBy(selector.Columns(*_g.flds...)...) - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -// ItemSelect is the builder for selecting fields of Item entities. -type ItemSelect struct { - *ItemQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (_s *ItemSelect) Aggregate(fns ...AggregateFunc) *ItemSelect { - _s.fns = append(_s.fns, fns...) - return _s -} - -// Scan applies the selector query and scans the result into the given value. -func (_s *ItemSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) - if err := _s.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*ItemQuery, *ItemSelect](ctx, _s.ItemQuery, _s, _s.inters, v) -} - -func (_s *ItemSelect) sqlScan(ctx context.Context, root *ItemQuery, v any) error { - selector := root.sqlQuery(ctx) - aggregation := make([]string, 0, len(_s.fns)) - for _, fn := range _s.fns { - aggregation = append(aggregation, fn(selector)) - } - switch n := len(*_s.selector.flds); { - case n == 0 && len(aggregation) > 0: - selector.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - selector.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := _s.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/backend/internal/data/ent/item_update.go b/backend/internal/data/ent/item_update.go deleted file mode 100644 index 1ff6c01b..00000000 --- a/backend/internal/data/ent/item_update.go +++ /dev/null @@ -1,2511 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "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/group" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" -) - -// ItemUpdate is the builder for updating Item entities. -type ItemUpdate struct { - config - hooks []Hook - mutation *ItemMutation -} - -// Where appends a list predicates to the ItemUpdate builder. -func (_u *ItemUpdate) Where(ps ...predicate.Item) *ItemUpdate { - _u.mutation.Where(ps...) - return _u -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *ItemUpdate) SetUpdatedAt(v time.Time) *ItemUpdate { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetName sets the "name" field. -func (_u *ItemUpdate) SetName(v string) *ItemUpdate { - _u.mutation.SetName(v) - return _u -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableName(v *string) *ItemUpdate { - if v != nil { - _u.SetName(*v) - } - return _u -} - -// SetDescription sets the "description" field. -func (_u *ItemUpdate) SetDescription(v string) *ItemUpdate { - _u.mutation.SetDescription(v) - return _u -} - -// SetNillableDescription sets the "description" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableDescription(v *string) *ItemUpdate { - if v != nil { - _u.SetDescription(*v) - } - return _u -} - -// ClearDescription clears the value of the "description" field. -func (_u *ItemUpdate) ClearDescription() *ItemUpdate { - _u.mutation.ClearDescription() - return _u -} - -// SetImportRef sets the "import_ref" field. -func (_u *ItemUpdate) SetImportRef(v string) *ItemUpdate { - _u.mutation.SetImportRef(v) - return _u -} - -// SetNillableImportRef sets the "import_ref" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableImportRef(v *string) *ItemUpdate { - if v != nil { - _u.SetImportRef(*v) - } - return _u -} - -// ClearImportRef clears the value of the "import_ref" field. -func (_u *ItemUpdate) ClearImportRef() *ItemUpdate { - _u.mutation.ClearImportRef() - return _u -} - -// SetNotes sets the "notes" field. -func (_u *ItemUpdate) SetNotes(v string) *ItemUpdate { - _u.mutation.SetNotes(v) - return _u -} - -// SetNillableNotes sets the "notes" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableNotes(v *string) *ItemUpdate { - if v != nil { - _u.SetNotes(*v) - } - return _u -} - -// ClearNotes clears the value of the "notes" field. -func (_u *ItemUpdate) ClearNotes() *ItemUpdate { - _u.mutation.ClearNotes() - return _u -} - -// SetQuantity sets the "quantity" field. -func (_u *ItemUpdate) SetQuantity(v int) *ItemUpdate { - _u.mutation.ResetQuantity() - _u.mutation.SetQuantity(v) - return _u -} - -// SetNillableQuantity sets the "quantity" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableQuantity(v *int) *ItemUpdate { - if v != nil { - _u.SetQuantity(*v) - } - return _u -} - -// AddQuantity adds value to the "quantity" field. -func (_u *ItemUpdate) AddQuantity(v int) *ItemUpdate { - _u.mutation.AddQuantity(v) - return _u -} - -// SetInsured sets the "insured" field. -func (_u *ItemUpdate) SetInsured(v bool) *ItemUpdate { - _u.mutation.SetInsured(v) - return _u -} - -// SetNillableInsured sets the "insured" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableInsured(v *bool) *ItemUpdate { - if v != nil { - _u.SetInsured(*v) - } - return _u -} - -// SetArchived sets the "archived" field. -func (_u *ItemUpdate) SetArchived(v bool) *ItemUpdate { - _u.mutation.SetArchived(v) - return _u -} - -// SetNillableArchived sets the "archived" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableArchived(v *bool) *ItemUpdate { - if v != nil { - _u.SetArchived(*v) - } - return _u -} - -// SetAssetID sets the "asset_id" field. -func (_u *ItemUpdate) SetAssetID(v int) *ItemUpdate { - _u.mutation.ResetAssetID() - _u.mutation.SetAssetID(v) - return _u -} - -// SetNillableAssetID sets the "asset_id" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableAssetID(v *int) *ItemUpdate { - if v != nil { - _u.SetAssetID(*v) - } - return _u -} - -// AddAssetID adds value to the "asset_id" field. -func (_u *ItemUpdate) AddAssetID(v int) *ItemUpdate { - _u.mutation.AddAssetID(v) - return _u -} - -// SetSyncChildItemsLocations sets the "sync_child_items_locations" field. -func (_u *ItemUpdate) SetSyncChildItemsLocations(v bool) *ItemUpdate { - _u.mutation.SetSyncChildItemsLocations(v) - return _u -} - -// SetNillableSyncChildItemsLocations sets the "sync_child_items_locations" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableSyncChildItemsLocations(v *bool) *ItemUpdate { - if v != nil { - _u.SetSyncChildItemsLocations(*v) - } - return _u -} - -// SetSerialNumber sets the "serial_number" field. -func (_u *ItemUpdate) SetSerialNumber(v string) *ItemUpdate { - _u.mutation.SetSerialNumber(v) - return _u -} - -// SetNillableSerialNumber sets the "serial_number" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableSerialNumber(v *string) *ItemUpdate { - if v != nil { - _u.SetSerialNumber(*v) - } - return _u -} - -// ClearSerialNumber clears the value of the "serial_number" field. -func (_u *ItemUpdate) ClearSerialNumber() *ItemUpdate { - _u.mutation.ClearSerialNumber() - return _u -} - -// SetModelNumber sets the "model_number" field. -func (_u *ItemUpdate) SetModelNumber(v string) *ItemUpdate { - _u.mutation.SetModelNumber(v) - return _u -} - -// SetNillableModelNumber sets the "model_number" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableModelNumber(v *string) *ItemUpdate { - if v != nil { - _u.SetModelNumber(*v) - } - return _u -} - -// ClearModelNumber clears the value of the "model_number" field. -func (_u *ItemUpdate) ClearModelNumber() *ItemUpdate { - _u.mutation.ClearModelNumber() - return _u -} - -// SetManufacturer sets the "manufacturer" field. -func (_u *ItemUpdate) SetManufacturer(v string) *ItemUpdate { - _u.mutation.SetManufacturer(v) - return _u -} - -// SetNillableManufacturer sets the "manufacturer" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableManufacturer(v *string) *ItemUpdate { - if v != nil { - _u.SetManufacturer(*v) - } - return _u -} - -// ClearManufacturer clears the value of the "manufacturer" field. -func (_u *ItemUpdate) ClearManufacturer() *ItemUpdate { - _u.mutation.ClearManufacturer() - return _u -} - -// SetLifetimeWarranty sets the "lifetime_warranty" field. -func (_u *ItemUpdate) SetLifetimeWarranty(v bool) *ItemUpdate { - _u.mutation.SetLifetimeWarranty(v) - return _u -} - -// SetNillableLifetimeWarranty sets the "lifetime_warranty" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableLifetimeWarranty(v *bool) *ItemUpdate { - if v != nil { - _u.SetLifetimeWarranty(*v) - } - return _u -} - -// SetWarrantyExpires sets the "warranty_expires" field. -func (_u *ItemUpdate) SetWarrantyExpires(v time.Time) *ItemUpdate { - _u.mutation.SetWarrantyExpires(v) - return _u -} - -// SetNillableWarrantyExpires sets the "warranty_expires" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableWarrantyExpires(v *time.Time) *ItemUpdate { - if v != nil { - _u.SetWarrantyExpires(*v) - } - return _u -} - -// ClearWarrantyExpires clears the value of the "warranty_expires" field. -func (_u *ItemUpdate) ClearWarrantyExpires() *ItemUpdate { - _u.mutation.ClearWarrantyExpires() - return _u -} - -// SetWarrantyDetails sets the "warranty_details" field. -func (_u *ItemUpdate) SetWarrantyDetails(v string) *ItemUpdate { - _u.mutation.SetWarrantyDetails(v) - return _u -} - -// SetNillableWarrantyDetails sets the "warranty_details" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableWarrantyDetails(v *string) *ItemUpdate { - if v != nil { - _u.SetWarrantyDetails(*v) - } - return _u -} - -// ClearWarrantyDetails clears the value of the "warranty_details" field. -func (_u *ItemUpdate) ClearWarrantyDetails() *ItemUpdate { - _u.mutation.ClearWarrantyDetails() - return _u -} - -// SetPurchaseTime sets the "purchase_time" field. -func (_u *ItemUpdate) SetPurchaseTime(v time.Time) *ItemUpdate { - _u.mutation.SetPurchaseTime(v) - return _u -} - -// SetNillablePurchaseTime sets the "purchase_time" field if the given value is not nil. -func (_u *ItemUpdate) SetNillablePurchaseTime(v *time.Time) *ItemUpdate { - if v != nil { - _u.SetPurchaseTime(*v) - } - return _u -} - -// ClearPurchaseTime clears the value of the "purchase_time" field. -func (_u *ItemUpdate) ClearPurchaseTime() *ItemUpdate { - _u.mutation.ClearPurchaseTime() - return _u -} - -// SetPurchaseFrom sets the "purchase_from" field. -func (_u *ItemUpdate) SetPurchaseFrom(v string) *ItemUpdate { - _u.mutation.SetPurchaseFrom(v) - return _u -} - -// SetNillablePurchaseFrom sets the "purchase_from" field if the given value is not nil. -func (_u *ItemUpdate) SetNillablePurchaseFrom(v *string) *ItemUpdate { - if v != nil { - _u.SetPurchaseFrom(*v) - } - return _u -} - -// ClearPurchaseFrom clears the value of the "purchase_from" field. -func (_u *ItemUpdate) ClearPurchaseFrom() *ItemUpdate { - _u.mutation.ClearPurchaseFrom() - return _u -} - -// SetPurchasePrice sets the "purchase_price" field. -func (_u *ItemUpdate) SetPurchasePrice(v float64) *ItemUpdate { - _u.mutation.ResetPurchasePrice() - _u.mutation.SetPurchasePrice(v) - return _u -} - -// SetNillablePurchasePrice sets the "purchase_price" field if the given value is not nil. -func (_u *ItemUpdate) SetNillablePurchasePrice(v *float64) *ItemUpdate { - if v != nil { - _u.SetPurchasePrice(*v) - } - return _u -} - -// AddPurchasePrice adds value to the "purchase_price" field. -func (_u *ItemUpdate) AddPurchasePrice(v float64) *ItemUpdate { - _u.mutation.AddPurchasePrice(v) - return _u -} - -// SetSoldTime sets the "sold_time" field. -func (_u *ItemUpdate) SetSoldTime(v time.Time) *ItemUpdate { - _u.mutation.SetSoldTime(v) - return _u -} - -// SetNillableSoldTime sets the "sold_time" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableSoldTime(v *time.Time) *ItemUpdate { - if v != nil { - _u.SetSoldTime(*v) - } - return _u -} - -// ClearSoldTime clears the value of the "sold_time" field. -func (_u *ItemUpdate) ClearSoldTime() *ItemUpdate { - _u.mutation.ClearSoldTime() - return _u -} - -// SetSoldTo sets the "sold_to" field. -func (_u *ItemUpdate) SetSoldTo(v string) *ItemUpdate { - _u.mutation.SetSoldTo(v) - return _u -} - -// SetNillableSoldTo sets the "sold_to" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableSoldTo(v *string) *ItemUpdate { - if v != nil { - _u.SetSoldTo(*v) - } - return _u -} - -// ClearSoldTo clears the value of the "sold_to" field. -func (_u *ItemUpdate) ClearSoldTo() *ItemUpdate { - _u.mutation.ClearSoldTo() - return _u -} - -// SetSoldPrice sets the "sold_price" field. -func (_u *ItemUpdate) SetSoldPrice(v float64) *ItemUpdate { - _u.mutation.ResetSoldPrice() - _u.mutation.SetSoldPrice(v) - return _u -} - -// SetNillableSoldPrice sets the "sold_price" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableSoldPrice(v *float64) *ItemUpdate { - if v != nil { - _u.SetSoldPrice(*v) - } - return _u -} - -// AddSoldPrice adds value to the "sold_price" field. -func (_u *ItemUpdate) AddSoldPrice(v float64) *ItemUpdate { - _u.mutation.AddSoldPrice(v) - return _u -} - -// SetSoldNotes sets the "sold_notes" field. -func (_u *ItemUpdate) SetSoldNotes(v string) *ItemUpdate { - _u.mutation.SetSoldNotes(v) - return _u -} - -// SetNillableSoldNotes sets the "sold_notes" field if the given value is not nil. -func (_u *ItemUpdate) SetNillableSoldNotes(v *string) *ItemUpdate { - if v != nil { - _u.SetSoldNotes(*v) - } - return _u -} - -// ClearSoldNotes clears the value of the "sold_notes" field. -func (_u *ItemUpdate) ClearSoldNotes() *ItemUpdate { - _u.mutation.ClearSoldNotes() - return _u -} - -// SetGroupID sets the "group" edge to the Group entity by ID. -func (_u *ItemUpdate) SetGroupID(id uuid.UUID) *ItemUpdate { - _u.mutation.SetGroupID(id) - return _u -} - -// SetGroup sets the "group" edge to the Group entity. -func (_u *ItemUpdate) SetGroup(v *Group) *ItemUpdate { - return _u.SetGroupID(v.ID) -} - -// SetParentID sets the "parent" edge to the Item entity by ID. -func (_u *ItemUpdate) SetParentID(id uuid.UUID) *ItemUpdate { - _u.mutation.SetParentID(id) - return _u -} - -// SetNillableParentID sets the "parent" edge to the Item entity by ID if the given value is not nil. -func (_u *ItemUpdate) SetNillableParentID(id *uuid.UUID) *ItemUpdate { - if id != nil { - _u = _u.SetParentID(*id) - } - return _u -} - -// SetParent sets the "parent" edge to the Item entity. -func (_u *ItemUpdate) SetParent(v *Item) *ItemUpdate { - return _u.SetParentID(v.ID) -} - -// AddChildIDs adds the "children" edge to the Item entity by IDs. -func (_u *ItemUpdate) AddChildIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.AddChildIDs(ids...) - return _u -} - -// AddChildren adds the "children" edges to the Item entity. -func (_u *ItemUpdate) AddChildren(v ...*Item) *ItemUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddChildIDs(ids...) -} - -// AddLabelIDs adds the "label" edge to the Label entity by IDs. -func (_u *ItemUpdate) AddLabelIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.AddLabelIDs(ids...) - return _u -} - -// AddLabel adds the "label" edges to the Label entity. -func (_u *ItemUpdate) AddLabel(v ...*Label) *ItemUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddLabelIDs(ids...) -} - -// SetLocationID sets the "location" edge to the Location entity by ID. -func (_u *ItemUpdate) SetLocationID(id uuid.UUID) *ItemUpdate { - _u.mutation.SetLocationID(id) - return _u -} - -// SetNillableLocationID sets the "location" edge to the Location entity by ID if the given value is not nil. -func (_u *ItemUpdate) SetNillableLocationID(id *uuid.UUID) *ItemUpdate { - if id != nil { - _u = _u.SetLocationID(*id) - } - return _u -} - -// SetLocation sets the "location" edge to the Location entity. -func (_u *ItemUpdate) SetLocation(v *Location) *ItemUpdate { - return _u.SetLocationID(v.ID) -} - -// AddFieldIDs adds the "fields" edge to the ItemField entity by IDs. -func (_u *ItemUpdate) AddFieldIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.AddFieldIDs(ids...) - return _u -} - -// AddFields adds the "fields" edges to the ItemField entity. -func (_u *ItemUpdate) AddFields(v ...*ItemField) *ItemUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddFieldIDs(ids...) -} - -// AddMaintenanceEntryIDs adds the "maintenance_entries" edge to the MaintenanceEntry entity by IDs. -func (_u *ItemUpdate) AddMaintenanceEntryIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.AddMaintenanceEntryIDs(ids...) - return _u -} - -// AddMaintenanceEntries adds the "maintenance_entries" edges to the MaintenanceEntry entity. -func (_u *ItemUpdate) AddMaintenanceEntries(v ...*MaintenanceEntry) *ItemUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddMaintenanceEntryIDs(ids...) -} - -// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs. -func (_u *ItemUpdate) AddAttachmentIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.AddAttachmentIDs(ids...) - return _u -} - -// AddAttachments adds the "attachments" edges to the Attachment entity. -func (_u *ItemUpdate) AddAttachments(v ...*Attachment) *ItemUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddAttachmentIDs(ids...) -} - -// Mutation returns the ItemMutation object of the builder. -func (_u *ItemUpdate) Mutation() *ItemMutation { - return _u.mutation -} - -// ClearGroup clears the "group" edge to the Group entity. -func (_u *ItemUpdate) ClearGroup() *ItemUpdate { - _u.mutation.ClearGroup() - return _u -} - -// ClearParent clears the "parent" edge to the Item entity. -func (_u *ItemUpdate) ClearParent() *ItemUpdate { - _u.mutation.ClearParent() - return _u -} - -// ClearChildren clears all "children" edges to the Item entity. -func (_u *ItemUpdate) ClearChildren() *ItemUpdate { - _u.mutation.ClearChildren() - return _u -} - -// RemoveChildIDs removes the "children" edge to Item entities by IDs. -func (_u *ItemUpdate) RemoveChildIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.RemoveChildIDs(ids...) - return _u -} - -// RemoveChildren removes "children" edges to Item entities. -func (_u *ItemUpdate) RemoveChildren(v ...*Item) *ItemUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveChildIDs(ids...) -} - -// ClearLabel clears all "label" edges to the Label entity. -func (_u *ItemUpdate) ClearLabel() *ItemUpdate { - _u.mutation.ClearLabel() - return _u -} - -// RemoveLabelIDs removes the "label" edge to Label entities by IDs. -func (_u *ItemUpdate) RemoveLabelIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.RemoveLabelIDs(ids...) - return _u -} - -// RemoveLabel removes "label" edges to Label entities. -func (_u *ItemUpdate) RemoveLabel(v ...*Label) *ItemUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveLabelIDs(ids...) -} - -// ClearLocation clears the "location" edge to the Location entity. -func (_u *ItemUpdate) ClearLocation() *ItemUpdate { - _u.mutation.ClearLocation() - return _u -} - -// ClearFields clears all "fields" edges to the ItemField entity. -func (_u *ItemUpdate) ClearFields() *ItemUpdate { - _u.mutation.ClearFields() - return _u -} - -// RemoveFieldIDs removes the "fields" edge to ItemField entities by IDs. -func (_u *ItemUpdate) RemoveFieldIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.RemoveFieldIDs(ids...) - return _u -} - -// RemoveFields removes "fields" edges to ItemField entities. -func (_u *ItemUpdate) RemoveFields(v ...*ItemField) *ItemUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveFieldIDs(ids...) -} - -// ClearMaintenanceEntries clears all "maintenance_entries" edges to the MaintenanceEntry entity. -func (_u *ItemUpdate) ClearMaintenanceEntries() *ItemUpdate { - _u.mutation.ClearMaintenanceEntries() - return _u -} - -// RemoveMaintenanceEntryIDs removes the "maintenance_entries" edge to MaintenanceEntry entities by IDs. -func (_u *ItemUpdate) RemoveMaintenanceEntryIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.RemoveMaintenanceEntryIDs(ids...) - return _u -} - -// RemoveMaintenanceEntries removes "maintenance_entries" edges to MaintenanceEntry entities. -func (_u *ItemUpdate) RemoveMaintenanceEntries(v ...*MaintenanceEntry) *ItemUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveMaintenanceEntryIDs(ids...) -} - -// ClearAttachments clears all "attachments" edges to the Attachment entity. -func (_u *ItemUpdate) ClearAttachments() *ItemUpdate { - _u.mutation.ClearAttachments() - return _u -} - -// RemoveAttachmentIDs removes the "attachments" edge to Attachment entities by IDs. -func (_u *ItemUpdate) RemoveAttachmentIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.RemoveAttachmentIDs(ids...) - return _u -} - -// RemoveAttachments removes "attachments" edges to Attachment entities. -func (_u *ItemUpdate) RemoveAttachments(v ...*Attachment) *ItemUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveAttachmentIDs(ids...) -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (_u *ItemUpdate) Save(ctx context.Context) (int, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *ItemUpdate) SaveX(ctx context.Context) int { - affected, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (_u *ItemUpdate) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *ItemUpdate) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *ItemUpdate) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := item.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_u *ItemUpdate) check() error { - if v, ok := _u.mutation.Name(); ok { - if err := item.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Item.name": %w`, err)} - } - } - if v, ok := _u.mutation.Description(); ok { - if err := item.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Item.description": %w`, err)} - } - } - if v, ok := _u.mutation.ImportRef(); ok { - if err := item.ImportRefValidator(v); err != nil { - return &ValidationError{Name: "import_ref", err: fmt.Errorf(`ent: validator failed for field "Item.import_ref": %w`, err)} - } - } - if v, ok := _u.mutation.Notes(); ok { - if err := item.NotesValidator(v); err != nil { - return &ValidationError{Name: "notes", err: fmt.Errorf(`ent: validator failed for field "Item.notes": %w`, err)} - } - } - if v, ok := _u.mutation.SerialNumber(); ok { - if err := item.SerialNumberValidator(v); err != nil { - return &ValidationError{Name: "serial_number", err: fmt.Errorf(`ent: validator failed for field "Item.serial_number": %w`, err)} - } - } - if v, ok := _u.mutation.ModelNumber(); ok { - if err := item.ModelNumberValidator(v); err != nil { - return &ValidationError{Name: "model_number", err: fmt.Errorf(`ent: validator failed for field "Item.model_number": %w`, err)} - } - } - if v, ok := _u.mutation.Manufacturer(); ok { - if err := item.ManufacturerValidator(v); err != nil { - return &ValidationError{Name: "manufacturer", err: fmt.Errorf(`ent: validator failed for field "Item.manufacturer": %w`, err)} - } - } - if v, ok := _u.mutation.WarrantyDetails(); ok { - if err := item.WarrantyDetailsValidator(v); err != nil { - return &ValidationError{Name: "warranty_details", err: fmt.Errorf(`ent: validator failed for field "Item.warranty_details": %w`, err)} - } - } - if v, ok := _u.mutation.SoldNotes(); ok { - if err := item.SoldNotesValidator(v); err != nil { - return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Item.sold_notes": %w`, err)} - } - } - if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 { - return errors.New(`ent: clearing a required unique edge "Item.group"`) - } - return nil -} - -func (_u *ItemUpdate) sqlSave(ctx context.Context) (_node int, err error) { - if err := _u.check(); err != nil { - return _node, err - } - _spec := sqlgraph.NewUpdateSpec(item.Table, item.Columns, sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID)) - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(item.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Name(); ok { - _spec.SetField(item.FieldName, field.TypeString, value) - } - if value, ok := _u.mutation.Description(); ok { - _spec.SetField(item.FieldDescription, field.TypeString, value) - } - if _u.mutation.DescriptionCleared() { - _spec.ClearField(item.FieldDescription, field.TypeString) - } - if value, ok := _u.mutation.ImportRef(); ok { - _spec.SetField(item.FieldImportRef, field.TypeString, value) - } - if _u.mutation.ImportRefCleared() { - _spec.ClearField(item.FieldImportRef, field.TypeString) - } - if value, ok := _u.mutation.Notes(); ok { - _spec.SetField(item.FieldNotes, field.TypeString, value) - } - if _u.mutation.NotesCleared() { - _spec.ClearField(item.FieldNotes, field.TypeString) - } - if value, ok := _u.mutation.Quantity(); ok { - _spec.SetField(item.FieldQuantity, field.TypeInt, value) - } - if value, ok := _u.mutation.AddedQuantity(); ok { - _spec.AddField(item.FieldQuantity, field.TypeInt, value) - } - if value, ok := _u.mutation.Insured(); ok { - _spec.SetField(item.FieldInsured, field.TypeBool, value) - } - if value, ok := _u.mutation.Archived(); ok { - _spec.SetField(item.FieldArchived, field.TypeBool, value) - } - if value, ok := _u.mutation.AssetID(); ok { - _spec.SetField(item.FieldAssetID, field.TypeInt, value) - } - if value, ok := _u.mutation.AddedAssetID(); ok { - _spec.AddField(item.FieldAssetID, field.TypeInt, value) - } - if value, ok := _u.mutation.SyncChildItemsLocations(); ok { - _spec.SetField(item.FieldSyncChildItemsLocations, field.TypeBool, value) - } - if value, ok := _u.mutation.SerialNumber(); ok { - _spec.SetField(item.FieldSerialNumber, field.TypeString, value) - } - if _u.mutation.SerialNumberCleared() { - _spec.ClearField(item.FieldSerialNumber, field.TypeString) - } - if value, ok := _u.mutation.ModelNumber(); ok { - _spec.SetField(item.FieldModelNumber, field.TypeString, value) - } - if _u.mutation.ModelNumberCleared() { - _spec.ClearField(item.FieldModelNumber, field.TypeString) - } - if value, ok := _u.mutation.Manufacturer(); ok { - _spec.SetField(item.FieldManufacturer, field.TypeString, value) - } - if _u.mutation.ManufacturerCleared() { - _spec.ClearField(item.FieldManufacturer, field.TypeString) - } - if value, ok := _u.mutation.LifetimeWarranty(); ok { - _spec.SetField(item.FieldLifetimeWarranty, field.TypeBool, value) - } - if value, ok := _u.mutation.WarrantyExpires(); ok { - _spec.SetField(item.FieldWarrantyExpires, field.TypeTime, value) - } - if _u.mutation.WarrantyExpiresCleared() { - _spec.ClearField(item.FieldWarrantyExpires, field.TypeTime) - } - if value, ok := _u.mutation.WarrantyDetails(); ok { - _spec.SetField(item.FieldWarrantyDetails, field.TypeString, value) - } - if _u.mutation.WarrantyDetailsCleared() { - _spec.ClearField(item.FieldWarrantyDetails, field.TypeString) - } - if value, ok := _u.mutation.PurchaseTime(); ok { - _spec.SetField(item.FieldPurchaseTime, field.TypeTime, value) - } - if _u.mutation.PurchaseTimeCleared() { - _spec.ClearField(item.FieldPurchaseTime, field.TypeTime) - } - if value, ok := _u.mutation.PurchaseFrom(); ok { - _spec.SetField(item.FieldPurchaseFrom, field.TypeString, value) - } - if _u.mutation.PurchaseFromCleared() { - _spec.ClearField(item.FieldPurchaseFrom, field.TypeString) - } - if value, ok := _u.mutation.PurchasePrice(); ok { - _spec.SetField(item.FieldPurchasePrice, field.TypeFloat64, value) - } - if value, ok := _u.mutation.AddedPurchasePrice(); ok { - _spec.AddField(item.FieldPurchasePrice, field.TypeFloat64, value) - } - if value, ok := _u.mutation.SoldTime(); ok { - _spec.SetField(item.FieldSoldTime, field.TypeTime, value) - } - if _u.mutation.SoldTimeCleared() { - _spec.ClearField(item.FieldSoldTime, field.TypeTime) - } - if value, ok := _u.mutation.SoldTo(); ok { - _spec.SetField(item.FieldSoldTo, field.TypeString, value) - } - if _u.mutation.SoldToCleared() { - _spec.ClearField(item.FieldSoldTo, field.TypeString) - } - if value, ok := _u.mutation.SoldPrice(); ok { - _spec.SetField(item.FieldSoldPrice, field.TypeFloat64, value) - } - if value, ok := _u.mutation.AddedSoldPrice(); ok { - _spec.AddField(item.FieldSoldPrice, field.TypeFloat64, value) - } - if value, ok := _u.mutation.SoldNotes(); ok { - _spec.SetField(item.FieldSoldNotes, field.TypeString, value) - } - if _u.mutation.SoldNotesCleared() { - _spec.ClearField(item.FieldSoldNotes, field.TypeString) - } - if _u.mutation.GroupCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.GroupTable, - Columns: []string{item.GroupColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.GroupTable, - Columns: []string{item.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) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.ParentCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.ParentTable, - Columns: []string{item.ParentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.ParentTable, - Columns: []string{item.ParentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.ChildrenCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.ChildrenTable, - Columns: []string{item.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.ChildrenTable, - Columns: []string{item.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.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 := _u.mutation.ChildrenIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.ChildrenTable, - Columns: []string{item.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.LabelCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: item.LabelTable, - Columns: item.LabelPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedLabelIDs(); len(nodes) > 0 && !_u.mutation.LabelCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: item.LabelTable, - Columns: item.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.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.LabelIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: item.LabelTable, - Columns: item.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.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.LocationCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.LocationTable, - Columns: []string{item.LocationColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.LocationIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.LocationTable, - Columns: []string{item.LocationColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.FieldsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.FieldsTable, - Columns: []string{item.FieldsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedFieldsIDs(); len(nodes) > 0 && !_u.mutation.FieldsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.FieldsTable, - Columns: []string{item.FieldsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(itemfield.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 := _u.mutation.FieldsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.FieldsTable, - Columns: []string{item.FieldsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.MaintenanceEntriesCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.MaintenanceEntriesTable, - Columns: []string{item.MaintenanceEntriesColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(maintenanceentry.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedMaintenanceEntriesIDs(); len(nodes) > 0 && !_u.mutation.MaintenanceEntriesCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.MaintenanceEntriesTable, - Columns: []string{item.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.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.MaintenanceEntriesIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.MaintenanceEntriesTable, - Columns: []string{item.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.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.AttachmentsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.AttachmentsTable, - Columns: []string{item.AttachmentsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedAttachmentsIDs(); len(nodes) > 0 && !_u.mutation.AttachmentsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.AttachmentsTable, - Columns: []string{item.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.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.AttachmentsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.AttachmentsTable, - Columns: []string{item.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.Add = append(_spec.Edges.Add, edge) - } - if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{item.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - _u.mutation.done = true - return _node, nil -} - -// ItemUpdateOne is the builder for updating a single Item entity. -type ItemUpdateOne struct { - config - fields []string - hooks []Hook - mutation *ItemMutation -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *ItemUpdateOne) SetUpdatedAt(v time.Time) *ItemUpdateOne { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetName sets the "name" field. -func (_u *ItemUpdateOne) SetName(v string) *ItemUpdateOne { - _u.mutation.SetName(v) - return _u -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableName(v *string) *ItemUpdateOne { - if v != nil { - _u.SetName(*v) - } - return _u -} - -// SetDescription sets the "description" field. -func (_u *ItemUpdateOne) SetDescription(v string) *ItemUpdateOne { - _u.mutation.SetDescription(v) - return _u -} - -// SetNillableDescription sets the "description" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableDescription(v *string) *ItemUpdateOne { - if v != nil { - _u.SetDescription(*v) - } - return _u -} - -// ClearDescription clears the value of the "description" field. -func (_u *ItemUpdateOne) ClearDescription() *ItemUpdateOne { - _u.mutation.ClearDescription() - return _u -} - -// SetImportRef sets the "import_ref" field. -func (_u *ItemUpdateOne) SetImportRef(v string) *ItemUpdateOne { - _u.mutation.SetImportRef(v) - return _u -} - -// SetNillableImportRef sets the "import_ref" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableImportRef(v *string) *ItemUpdateOne { - if v != nil { - _u.SetImportRef(*v) - } - return _u -} - -// ClearImportRef clears the value of the "import_ref" field. -func (_u *ItemUpdateOne) ClearImportRef() *ItemUpdateOne { - _u.mutation.ClearImportRef() - return _u -} - -// SetNotes sets the "notes" field. -func (_u *ItemUpdateOne) SetNotes(v string) *ItemUpdateOne { - _u.mutation.SetNotes(v) - return _u -} - -// SetNillableNotes sets the "notes" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableNotes(v *string) *ItemUpdateOne { - if v != nil { - _u.SetNotes(*v) - } - return _u -} - -// ClearNotes clears the value of the "notes" field. -func (_u *ItemUpdateOne) ClearNotes() *ItemUpdateOne { - _u.mutation.ClearNotes() - return _u -} - -// SetQuantity sets the "quantity" field. -func (_u *ItemUpdateOne) SetQuantity(v int) *ItemUpdateOne { - _u.mutation.ResetQuantity() - _u.mutation.SetQuantity(v) - return _u -} - -// SetNillableQuantity sets the "quantity" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableQuantity(v *int) *ItemUpdateOne { - if v != nil { - _u.SetQuantity(*v) - } - return _u -} - -// AddQuantity adds value to the "quantity" field. -func (_u *ItemUpdateOne) AddQuantity(v int) *ItemUpdateOne { - _u.mutation.AddQuantity(v) - return _u -} - -// SetInsured sets the "insured" field. -func (_u *ItemUpdateOne) SetInsured(v bool) *ItemUpdateOne { - _u.mutation.SetInsured(v) - return _u -} - -// SetNillableInsured sets the "insured" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableInsured(v *bool) *ItemUpdateOne { - if v != nil { - _u.SetInsured(*v) - } - return _u -} - -// SetArchived sets the "archived" field. -func (_u *ItemUpdateOne) SetArchived(v bool) *ItemUpdateOne { - _u.mutation.SetArchived(v) - return _u -} - -// SetNillableArchived sets the "archived" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableArchived(v *bool) *ItemUpdateOne { - if v != nil { - _u.SetArchived(*v) - } - return _u -} - -// SetAssetID sets the "asset_id" field. -func (_u *ItemUpdateOne) SetAssetID(v int) *ItemUpdateOne { - _u.mutation.ResetAssetID() - _u.mutation.SetAssetID(v) - return _u -} - -// SetNillableAssetID sets the "asset_id" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableAssetID(v *int) *ItemUpdateOne { - if v != nil { - _u.SetAssetID(*v) - } - return _u -} - -// AddAssetID adds value to the "asset_id" field. -func (_u *ItemUpdateOne) AddAssetID(v int) *ItemUpdateOne { - _u.mutation.AddAssetID(v) - return _u -} - -// SetSyncChildItemsLocations sets the "sync_child_items_locations" field. -func (_u *ItemUpdateOne) SetSyncChildItemsLocations(v bool) *ItemUpdateOne { - _u.mutation.SetSyncChildItemsLocations(v) - return _u -} - -// SetNillableSyncChildItemsLocations sets the "sync_child_items_locations" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableSyncChildItemsLocations(v *bool) *ItemUpdateOne { - if v != nil { - _u.SetSyncChildItemsLocations(*v) - } - return _u -} - -// SetSerialNumber sets the "serial_number" field. -func (_u *ItemUpdateOne) SetSerialNumber(v string) *ItemUpdateOne { - _u.mutation.SetSerialNumber(v) - return _u -} - -// SetNillableSerialNumber sets the "serial_number" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableSerialNumber(v *string) *ItemUpdateOne { - if v != nil { - _u.SetSerialNumber(*v) - } - return _u -} - -// ClearSerialNumber clears the value of the "serial_number" field. -func (_u *ItemUpdateOne) ClearSerialNumber() *ItemUpdateOne { - _u.mutation.ClearSerialNumber() - return _u -} - -// SetModelNumber sets the "model_number" field. -func (_u *ItemUpdateOne) SetModelNumber(v string) *ItemUpdateOne { - _u.mutation.SetModelNumber(v) - return _u -} - -// SetNillableModelNumber sets the "model_number" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableModelNumber(v *string) *ItemUpdateOne { - if v != nil { - _u.SetModelNumber(*v) - } - return _u -} - -// ClearModelNumber clears the value of the "model_number" field. -func (_u *ItemUpdateOne) ClearModelNumber() *ItemUpdateOne { - _u.mutation.ClearModelNumber() - return _u -} - -// SetManufacturer sets the "manufacturer" field. -func (_u *ItemUpdateOne) SetManufacturer(v string) *ItemUpdateOne { - _u.mutation.SetManufacturer(v) - return _u -} - -// SetNillableManufacturer sets the "manufacturer" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableManufacturer(v *string) *ItemUpdateOne { - if v != nil { - _u.SetManufacturer(*v) - } - return _u -} - -// ClearManufacturer clears the value of the "manufacturer" field. -func (_u *ItemUpdateOne) ClearManufacturer() *ItemUpdateOne { - _u.mutation.ClearManufacturer() - return _u -} - -// SetLifetimeWarranty sets the "lifetime_warranty" field. -func (_u *ItemUpdateOne) SetLifetimeWarranty(v bool) *ItemUpdateOne { - _u.mutation.SetLifetimeWarranty(v) - return _u -} - -// SetNillableLifetimeWarranty sets the "lifetime_warranty" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableLifetimeWarranty(v *bool) *ItemUpdateOne { - if v != nil { - _u.SetLifetimeWarranty(*v) - } - return _u -} - -// SetWarrantyExpires sets the "warranty_expires" field. -func (_u *ItemUpdateOne) SetWarrantyExpires(v time.Time) *ItemUpdateOne { - _u.mutation.SetWarrantyExpires(v) - return _u -} - -// SetNillableWarrantyExpires sets the "warranty_expires" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableWarrantyExpires(v *time.Time) *ItemUpdateOne { - if v != nil { - _u.SetWarrantyExpires(*v) - } - return _u -} - -// ClearWarrantyExpires clears the value of the "warranty_expires" field. -func (_u *ItemUpdateOne) ClearWarrantyExpires() *ItemUpdateOne { - _u.mutation.ClearWarrantyExpires() - return _u -} - -// SetWarrantyDetails sets the "warranty_details" field. -func (_u *ItemUpdateOne) SetWarrantyDetails(v string) *ItemUpdateOne { - _u.mutation.SetWarrantyDetails(v) - return _u -} - -// SetNillableWarrantyDetails sets the "warranty_details" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableWarrantyDetails(v *string) *ItemUpdateOne { - if v != nil { - _u.SetWarrantyDetails(*v) - } - return _u -} - -// ClearWarrantyDetails clears the value of the "warranty_details" field. -func (_u *ItemUpdateOne) ClearWarrantyDetails() *ItemUpdateOne { - _u.mutation.ClearWarrantyDetails() - return _u -} - -// SetPurchaseTime sets the "purchase_time" field. -func (_u *ItemUpdateOne) SetPurchaseTime(v time.Time) *ItemUpdateOne { - _u.mutation.SetPurchaseTime(v) - return _u -} - -// SetNillablePurchaseTime sets the "purchase_time" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillablePurchaseTime(v *time.Time) *ItemUpdateOne { - if v != nil { - _u.SetPurchaseTime(*v) - } - return _u -} - -// ClearPurchaseTime clears the value of the "purchase_time" field. -func (_u *ItemUpdateOne) ClearPurchaseTime() *ItemUpdateOne { - _u.mutation.ClearPurchaseTime() - return _u -} - -// SetPurchaseFrom sets the "purchase_from" field. -func (_u *ItemUpdateOne) SetPurchaseFrom(v string) *ItemUpdateOne { - _u.mutation.SetPurchaseFrom(v) - return _u -} - -// SetNillablePurchaseFrom sets the "purchase_from" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillablePurchaseFrom(v *string) *ItemUpdateOne { - if v != nil { - _u.SetPurchaseFrom(*v) - } - return _u -} - -// ClearPurchaseFrom clears the value of the "purchase_from" field. -func (_u *ItemUpdateOne) ClearPurchaseFrom() *ItemUpdateOne { - _u.mutation.ClearPurchaseFrom() - return _u -} - -// SetPurchasePrice sets the "purchase_price" field. -func (_u *ItemUpdateOne) SetPurchasePrice(v float64) *ItemUpdateOne { - _u.mutation.ResetPurchasePrice() - _u.mutation.SetPurchasePrice(v) - return _u -} - -// SetNillablePurchasePrice sets the "purchase_price" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillablePurchasePrice(v *float64) *ItemUpdateOne { - if v != nil { - _u.SetPurchasePrice(*v) - } - return _u -} - -// AddPurchasePrice adds value to the "purchase_price" field. -func (_u *ItemUpdateOne) AddPurchasePrice(v float64) *ItemUpdateOne { - _u.mutation.AddPurchasePrice(v) - return _u -} - -// SetSoldTime sets the "sold_time" field. -func (_u *ItemUpdateOne) SetSoldTime(v time.Time) *ItemUpdateOne { - _u.mutation.SetSoldTime(v) - return _u -} - -// SetNillableSoldTime sets the "sold_time" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableSoldTime(v *time.Time) *ItemUpdateOne { - if v != nil { - _u.SetSoldTime(*v) - } - return _u -} - -// ClearSoldTime clears the value of the "sold_time" field. -func (_u *ItemUpdateOne) ClearSoldTime() *ItemUpdateOne { - _u.mutation.ClearSoldTime() - return _u -} - -// SetSoldTo sets the "sold_to" field. -func (_u *ItemUpdateOne) SetSoldTo(v string) *ItemUpdateOne { - _u.mutation.SetSoldTo(v) - return _u -} - -// SetNillableSoldTo sets the "sold_to" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableSoldTo(v *string) *ItemUpdateOne { - if v != nil { - _u.SetSoldTo(*v) - } - return _u -} - -// ClearSoldTo clears the value of the "sold_to" field. -func (_u *ItemUpdateOne) ClearSoldTo() *ItemUpdateOne { - _u.mutation.ClearSoldTo() - return _u -} - -// SetSoldPrice sets the "sold_price" field. -func (_u *ItemUpdateOne) SetSoldPrice(v float64) *ItemUpdateOne { - _u.mutation.ResetSoldPrice() - _u.mutation.SetSoldPrice(v) - return _u -} - -// SetNillableSoldPrice sets the "sold_price" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableSoldPrice(v *float64) *ItemUpdateOne { - if v != nil { - _u.SetSoldPrice(*v) - } - return _u -} - -// AddSoldPrice adds value to the "sold_price" field. -func (_u *ItemUpdateOne) AddSoldPrice(v float64) *ItemUpdateOne { - _u.mutation.AddSoldPrice(v) - return _u -} - -// SetSoldNotes sets the "sold_notes" field. -func (_u *ItemUpdateOne) SetSoldNotes(v string) *ItemUpdateOne { - _u.mutation.SetSoldNotes(v) - return _u -} - -// SetNillableSoldNotes sets the "sold_notes" field if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableSoldNotes(v *string) *ItemUpdateOne { - if v != nil { - _u.SetSoldNotes(*v) - } - return _u -} - -// ClearSoldNotes clears the value of the "sold_notes" field. -func (_u *ItemUpdateOne) ClearSoldNotes() *ItemUpdateOne { - _u.mutation.ClearSoldNotes() - return _u -} - -// SetGroupID sets the "group" edge to the Group entity by ID. -func (_u *ItemUpdateOne) SetGroupID(id uuid.UUID) *ItemUpdateOne { - _u.mutation.SetGroupID(id) - return _u -} - -// SetGroup sets the "group" edge to the Group entity. -func (_u *ItemUpdateOne) SetGroup(v *Group) *ItemUpdateOne { - return _u.SetGroupID(v.ID) -} - -// SetParentID sets the "parent" edge to the Item entity by ID. -func (_u *ItemUpdateOne) SetParentID(id uuid.UUID) *ItemUpdateOne { - _u.mutation.SetParentID(id) - return _u -} - -// SetNillableParentID sets the "parent" edge to the Item entity by ID if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableParentID(id *uuid.UUID) *ItemUpdateOne { - if id != nil { - _u = _u.SetParentID(*id) - } - return _u -} - -// SetParent sets the "parent" edge to the Item entity. -func (_u *ItemUpdateOne) SetParent(v *Item) *ItemUpdateOne { - return _u.SetParentID(v.ID) -} - -// AddChildIDs adds the "children" edge to the Item entity by IDs. -func (_u *ItemUpdateOne) AddChildIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.AddChildIDs(ids...) - return _u -} - -// AddChildren adds the "children" edges to the Item entity. -func (_u *ItemUpdateOne) AddChildren(v ...*Item) *ItemUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddChildIDs(ids...) -} - -// AddLabelIDs adds the "label" edge to the Label entity by IDs. -func (_u *ItemUpdateOne) AddLabelIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.AddLabelIDs(ids...) - return _u -} - -// AddLabel adds the "label" edges to the Label entity. -func (_u *ItemUpdateOne) AddLabel(v ...*Label) *ItemUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddLabelIDs(ids...) -} - -// SetLocationID sets the "location" edge to the Location entity by ID. -func (_u *ItemUpdateOne) SetLocationID(id uuid.UUID) *ItemUpdateOne { - _u.mutation.SetLocationID(id) - return _u -} - -// SetNillableLocationID sets the "location" edge to the Location entity by ID if the given value is not nil. -func (_u *ItemUpdateOne) SetNillableLocationID(id *uuid.UUID) *ItemUpdateOne { - if id != nil { - _u = _u.SetLocationID(*id) - } - return _u -} - -// SetLocation sets the "location" edge to the Location entity. -func (_u *ItemUpdateOne) SetLocation(v *Location) *ItemUpdateOne { - return _u.SetLocationID(v.ID) -} - -// AddFieldIDs adds the "fields" edge to the ItemField entity by IDs. -func (_u *ItemUpdateOne) AddFieldIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.AddFieldIDs(ids...) - return _u -} - -// AddFields adds the "fields" edges to the ItemField entity. -func (_u *ItemUpdateOne) AddFields(v ...*ItemField) *ItemUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddFieldIDs(ids...) -} - -// AddMaintenanceEntryIDs adds the "maintenance_entries" edge to the MaintenanceEntry entity by IDs. -func (_u *ItemUpdateOne) AddMaintenanceEntryIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.AddMaintenanceEntryIDs(ids...) - return _u -} - -// AddMaintenanceEntries adds the "maintenance_entries" edges to the MaintenanceEntry entity. -func (_u *ItemUpdateOne) AddMaintenanceEntries(v ...*MaintenanceEntry) *ItemUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddMaintenanceEntryIDs(ids...) -} - -// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs. -func (_u *ItemUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.AddAttachmentIDs(ids...) - return _u -} - -// AddAttachments adds the "attachments" edges to the Attachment entity. -func (_u *ItemUpdateOne) AddAttachments(v ...*Attachment) *ItemUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddAttachmentIDs(ids...) -} - -// Mutation returns the ItemMutation object of the builder. -func (_u *ItemUpdateOne) Mutation() *ItemMutation { - return _u.mutation -} - -// ClearGroup clears the "group" edge to the Group entity. -func (_u *ItemUpdateOne) ClearGroup() *ItemUpdateOne { - _u.mutation.ClearGroup() - return _u -} - -// ClearParent clears the "parent" edge to the Item entity. -func (_u *ItemUpdateOne) ClearParent() *ItemUpdateOne { - _u.mutation.ClearParent() - return _u -} - -// ClearChildren clears all "children" edges to the Item entity. -func (_u *ItemUpdateOne) ClearChildren() *ItemUpdateOne { - _u.mutation.ClearChildren() - return _u -} - -// RemoveChildIDs removes the "children" edge to Item entities by IDs. -func (_u *ItemUpdateOne) RemoveChildIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.RemoveChildIDs(ids...) - return _u -} - -// RemoveChildren removes "children" edges to Item entities. -func (_u *ItemUpdateOne) RemoveChildren(v ...*Item) *ItemUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveChildIDs(ids...) -} - -// ClearLabel clears all "label" edges to the Label entity. -func (_u *ItemUpdateOne) ClearLabel() *ItemUpdateOne { - _u.mutation.ClearLabel() - return _u -} - -// RemoveLabelIDs removes the "label" edge to Label entities by IDs. -func (_u *ItemUpdateOne) RemoveLabelIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.RemoveLabelIDs(ids...) - return _u -} - -// RemoveLabel removes "label" edges to Label entities. -func (_u *ItemUpdateOne) RemoveLabel(v ...*Label) *ItemUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveLabelIDs(ids...) -} - -// ClearLocation clears the "location" edge to the Location entity. -func (_u *ItemUpdateOne) ClearLocation() *ItemUpdateOne { - _u.mutation.ClearLocation() - return _u -} - -// ClearFields clears all "fields" edges to the ItemField entity. -func (_u *ItemUpdateOne) ClearFields() *ItemUpdateOne { - _u.mutation.ClearFields() - return _u -} - -// RemoveFieldIDs removes the "fields" edge to ItemField entities by IDs. -func (_u *ItemUpdateOne) RemoveFieldIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.RemoveFieldIDs(ids...) - return _u -} - -// RemoveFields removes "fields" edges to ItemField entities. -func (_u *ItemUpdateOne) RemoveFields(v ...*ItemField) *ItemUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveFieldIDs(ids...) -} - -// ClearMaintenanceEntries clears all "maintenance_entries" edges to the MaintenanceEntry entity. -func (_u *ItemUpdateOne) ClearMaintenanceEntries() *ItemUpdateOne { - _u.mutation.ClearMaintenanceEntries() - return _u -} - -// RemoveMaintenanceEntryIDs removes the "maintenance_entries" edge to MaintenanceEntry entities by IDs. -func (_u *ItemUpdateOne) RemoveMaintenanceEntryIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.RemoveMaintenanceEntryIDs(ids...) - return _u -} - -// RemoveMaintenanceEntries removes "maintenance_entries" edges to MaintenanceEntry entities. -func (_u *ItemUpdateOne) RemoveMaintenanceEntries(v ...*MaintenanceEntry) *ItemUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveMaintenanceEntryIDs(ids...) -} - -// ClearAttachments clears all "attachments" edges to the Attachment entity. -func (_u *ItemUpdateOne) ClearAttachments() *ItemUpdateOne { - _u.mutation.ClearAttachments() - return _u -} - -// RemoveAttachmentIDs removes the "attachments" edge to Attachment entities by IDs. -func (_u *ItemUpdateOne) RemoveAttachmentIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.RemoveAttachmentIDs(ids...) - return _u -} - -// RemoveAttachments removes "attachments" edges to Attachment entities. -func (_u *ItemUpdateOne) RemoveAttachments(v ...*Attachment) *ItemUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveAttachmentIDs(ids...) -} - -// Where appends a list predicates to the ItemUpdate builder. -func (_u *ItemUpdateOne) Where(ps ...predicate.Item) *ItemUpdateOne { - _u.mutation.Where(ps...) - return _u -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (_u *ItemUpdateOne) Select(field string, fields ...string) *ItemUpdateOne { - _u.fields = append([]string{field}, fields...) - return _u -} - -// Save executes the query and returns the updated Item entity. -func (_u *ItemUpdateOne) Save(ctx context.Context) (*Item, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *ItemUpdateOne) SaveX(ctx context.Context) *Item { - node, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (_u *ItemUpdateOne) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *ItemUpdateOne) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *ItemUpdateOne) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := item.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_u *ItemUpdateOne) check() error { - if v, ok := _u.mutation.Name(); ok { - if err := item.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Item.name": %w`, err)} - } - } - if v, ok := _u.mutation.Description(); ok { - if err := item.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Item.description": %w`, err)} - } - } - if v, ok := _u.mutation.ImportRef(); ok { - if err := item.ImportRefValidator(v); err != nil { - return &ValidationError{Name: "import_ref", err: fmt.Errorf(`ent: validator failed for field "Item.import_ref": %w`, err)} - } - } - if v, ok := _u.mutation.Notes(); ok { - if err := item.NotesValidator(v); err != nil { - return &ValidationError{Name: "notes", err: fmt.Errorf(`ent: validator failed for field "Item.notes": %w`, err)} - } - } - if v, ok := _u.mutation.SerialNumber(); ok { - if err := item.SerialNumberValidator(v); err != nil { - return &ValidationError{Name: "serial_number", err: fmt.Errorf(`ent: validator failed for field "Item.serial_number": %w`, err)} - } - } - if v, ok := _u.mutation.ModelNumber(); ok { - if err := item.ModelNumberValidator(v); err != nil { - return &ValidationError{Name: "model_number", err: fmt.Errorf(`ent: validator failed for field "Item.model_number": %w`, err)} - } - } - if v, ok := _u.mutation.Manufacturer(); ok { - if err := item.ManufacturerValidator(v); err != nil { - return &ValidationError{Name: "manufacturer", err: fmt.Errorf(`ent: validator failed for field "Item.manufacturer": %w`, err)} - } - } - if v, ok := _u.mutation.WarrantyDetails(); ok { - if err := item.WarrantyDetailsValidator(v); err != nil { - return &ValidationError{Name: "warranty_details", err: fmt.Errorf(`ent: validator failed for field "Item.warranty_details": %w`, err)} - } - } - if v, ok := _u.mutation.SoldNotes(); ok { - if err := item.SoldNotesValidator(v); err != nil { - return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Item.sold_notes": %w`, err)} - } - } - if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 { - return errors.New(`ent: clearing a required unique edge "Item.group"`) - } - return nil -} - -func (_u *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error) { - if err := _u.check(); err != nil { - return _node, err - } - _spec := sqlgraph.NewUpdateSpec(item.Table, item.Columns, sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID)) - id, ok := _u.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Item.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := _u.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, item.FieldID) - for _, f := range fields { - if !item.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != item.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(item.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Name(); ok { - _spec.SetField(item.FieldName, field.TypeString, value) - } - if value, ok := _u.mutation.Description(); ok { - _spec.SetField(item.FieldDescription, field.TypeString, value) - } - if _u.mutation.DescriptionCleared() { - _spec.ClearField(item.FieldDescription, field.TypeString) - } - if value, ok := _u.mutation.ImportRef(); ok { - _spec.SetField(item.FieldImportRef, field.TypeString, value) - } - if _u.mutation.ImportRefCleared() { - _spec.ClearField(item.FieldImportRef, field.TypeString) - } - if value, ok := _u.mutation.Notes(); ok { - _spec.SetField(item.FieldNotes, field.TypeString, value) - } - if _u.mutation.NotesCleared() { - _spec.ClearField(item.FieldNotes, field.TypeString) - } - if value, ok := _u.mutation.Quantity(); ok { - _spec.SetField(item.FieldQuantity, field.TypeInt, value) - } - if value, ok := _u.mutation.AddedQuantity(); ok { - _spec.AddField(item.FieldQuantity, field.TypeInt, value) - } - if value, ok := _u.mutation.Insured(); ok { - _spec.SetField(item.FieldInsured, field.TypeBool, value) - } - if value, ok := _u.mutation.Archived(); ok { - _spec.SetField(item.FieldArchived, field.TypeBool, value) - } - if value, ok := _u.mutation.AssetID(); ok { - _spec.SetField(item.FieldAssetID, field.TypeInt, value) - } - if value, ok := _u.mutation.AddedAssetID(); ok { - _spec.AddField(item.FieldAssetID, field.TypeInt, value) - } - if value, ok := _u.mutation.SyncChildItemsLocations(); ok { - _spec.SetField(item.FieldSyncChildItemsLocations, field.TypeBool, value) - } - if value, ok := _u.mutation.SerialNumber(); ok { - _spec.SetField(item.FieldSerialNumber, field.TypeString, value) - } - if _u.mutation.SerialNumberCleared() { - _spec.ClearField(item.FieldSerialNumber, field.TypeString) - } - if value, ok := _u.mutation.ModelNumber(); ok { - _spec.SetField(item.FieldModelNumber, field.TypeString, value) - } - if _u.mutation.ModelNumberCleared() { - _spec.ClearField(item.FieldModelNumber, field.TypeString) - } - if value, ok := _u.mutation.Manufacturer(); ok { - _spec.SetField(item.FieldManufacturer, field.TypeString, value) - } - if _u.mutation.ManufacturerCleared() { - _spec.ClearField(item.FieldManufacturer, field.TypeString) - } - if value, ok := _u.mutation.LifetimeWarranty(); ok { - _spec.SetField(item.FieldLifetimeWarranty, field.TypeBool, value) - } - if value, ok := _u.mutation.WarrantyExpires(); ok { - _spec.SetField(item.FieldWarrantyExpires, field.TypeTime, value) - } - if _u.mutation.WarrantyExpiresCleared() { - _spec.ClearField(item.FieldWarrantyExpires, field.TypeTime) - } - if value, ok := _u.mutation.WarrantyDetails(); ok { - _spec.SetField(item.FieldWarrantyDetails, field.TypeString, value) - } - if _u.mutation.WarrantyDetailsCleared() { - _spec.ClearField(item.FieldWarrantyDetails, field.TypeString) - } - if value, ok := _u.mutation.PurchaseTime(); ok { - _spec.SetField(item.FieldPurchaseTime, field.TypeTime, value) - } - if _u.mutation.PurchaseTimeCleared() { - _spec.ClearField(item.FieldPurchaseTime, field.TypeTime) - } - if value, ok := _u.mutation.PurchaseFrom(); ok { - _spec.SetField(item.FieldPurchaseFrom, field.TypeString, value) - } - if _u.mutation.PurchaseFromCleared() { - _spec.ClearField(item.FieldPurchaseFrom, field.TypeString) - } - if value, ok := _u.mutation.PurchasePrice(); ok { - _spec.SetField(item.FieldPurchasePrice, field.TypeFloat64, value) - } - if value, ok := _u.mutation.AddedPurchasePrice(); ok { - _spec.AddField(item.FieldPurchasePrice, field.TypeFloat64, value) - } - if value, ok := _u.mutation.SoldTime(); ok { - _spec.SetField(item.FieldSoldTime, field.TypeTime, value) - } - if _u.mutation.SoldTimeCleared() { - _spec.ClearField(item.FieldSoldTime, field.TypeTime) - } - if value, ok := _u.mutation.SoldTo(); ok { - _spec.SetField(item.FieldSoldTo, field.TypeString, value) - } - if _u.mutation.SoldToCleared() { - _spec.ClearField(item.FieldSoldTo, field.TypeString) - } - if value, ok := _u.mutation.SoldPrice(); ok { - _spec.SetField(item.FieldSoldPrice, field.TypeFloat64, value) - } - if value, ok := _u.mutation.AddedSoldPrice(); ok { - _spec.AddField(item.FieldSoldPrice, field.TypeFloat64, value) - } - if value, ok := _u.mutation.SoldNotes(); ok { - _spec.SetField(item.FieldSoldNotes, field.TypeString, value) - } - if _u.mutation.SoldNotesCleared() { - _spec.ClearField(item.FieldSoldNotes, field.TypeString) - } - if _u.mutation.GroupCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.GroupTable, - Columns: []string{item.GroupColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.GroupTable, - Columns: []string{item.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) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.ParentCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.ParentTable, - Columns: []string{item.ParentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.ParentTable, - Columns: []string{item.ParentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.ChildrenCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.ChildrenTable, - Columns: []string{item.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.ChildrenTable, - Columns: []string{item.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.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 := _u.mutation.ChildrenIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.ChildrenTable, - Columns: []string{item.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.LabelCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: item.LabelTable, - Columns: item.LabelPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedLabelIDs(); len(nodes) > 0 && !_u.mutation.LabelCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: item.LabelTable, - Columns: item.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.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.LabelIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: item.LabelTable, - Columns: item.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.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.LocationCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.LocationTable, - Columns: []string{item.LocationColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.LocationIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: item.LocationTable, - Columns: []string{item.LocationColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.FieldsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.FieldsTable, - Columns: []string{item.FieldsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedFieldsIDs(); len(nodes) > 0 && !_u.mutation.FieldsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.FieldsTable, - Columns: []string{item.FieldsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(itemfield.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 := _u.mutation.FieldsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.FieldsTable, - Columns: []string{item.FieldsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.MaintenanceEntriesCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.MaintenanceEntriesTable, - Columns: []string{item.MaintenanceEntriesColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(maintenanceentry.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedMaintenanceEntriesIDs(); len(nodes) > 0 && !_u.mutation.MaintenanceEntriesCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.MaintenanceEntriesTable, - Columns: []string{item.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.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.MaintenanceEntriesIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.MaintenanceEntriesTable, - Columns: []string{item.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.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.AttachmentsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.AttachmentsTable, - Columns: []string{item.AttachmentsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedAttachmentsIDs(); len(nodes) > 0 && !_u.mutation.AttachmentsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.AttachmentsTable, - Columns: []string{item.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.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.AttachmentsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: item.AttachmentsTable, - Columns: []string{item.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.Add = append(_spec.Edges.Add, edge) - } - _node = &Item{config: _u.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{item.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - _u.mutation.done = true - return _node, nil -} diff --git a/backend/internal/data/ent/itemfield_create.go b/backend/internal/data/ent/itemfield_create.go deleted file mode 100644 index 1daf082b..00000000 --- a/backend/internal/data/ent/itemfield_create.go +++ /dev/null @@ -1,438 +0,0 @@ -// 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/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" -) - -// ItemFieldCreate is the builder for creating a ItemField entity. -type ItemFieldCreate struct { - config - mutation *ItemFieldMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (_c *ItemFieldCreate) SetCreatedAt(v time.Time) *ItemFieldCreate { - _c.mutation.SetCreatedAt(v) - return _c -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (_c *ItemFieldCreate) SetNillableCreatedAt(v *time.Time) *ItemFieldCreate { - if v != nil { - _c.SetCreatedAt(*v) - } - return _c -} - -// SetUpdatedAt sets the "updated_at" field. -func (_c *ItemFieldCreate) SetUpdatedAt(v time.Time) *ItemFieldCreate { - _c.mutation.SetUpdatedAt(v) - return _c -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (_c *ItemFieldCreate) SetNillableUpdatedAt(v *time.Time) *ItemFieldCreate { - if v != nil { - _c.SetUpdatedAt(*v) - } - return _c -} - -// SetName sets the "name" field. -func (_c *ItemFieldCreate) SetName(v string) *ItemFieldCreate { - _c.mutation.SetName(v) - return _c -} - -// SetDescription sets the "description" field. -func (_c *ItemFieldCreate) SetDescription(v string) *ItemFieldCreate { - _c.mutation.SetDescription(v) - return _c -} - -// SetNillableDescription sets the "description" field if the given value is not nil. -func (_c *ItemFieldCreate) SetNillableDescription(v *string) *ItemFieldCreate { - if v != nil { - _c.SetDescription(*v) - } - return _c -} - -// SetType sets the "type" field. -func (_c *ItemFieldCreate) SetType(v itemfield.Type) *ItemFieldCreate { - _c.mutation.SetType(v) - return _c -} - -// SetTextValue sets the "text_value" field. -func (_c *ItemFieldCreate) SetTextValue(v string) *ItemFieldCreate { - _c.mutation.SetTextValue(v) - return _c -} - -// SetNillableTextValue sets the "text_value" field if the given value is not nil. -func (_c *ItemFieldCreate) SetNillableTextValue(v *string) *ItemFieldCreate { - if v != nil { - _c.SetTextValue(*v) - } - return _c -} - -// SetNumberValue sets the "number_value" field. -func (_c *ItemFieldCreate) SetNumberValue(v int) *ItemFieldCreate { - _c.mutation.SetNumberValue(v) - return _c -} - -// SetNillableNumberValue sets the "number_value" field if the given value is not nil. -func (_c *ItemFieldCreate) SetNillableNumberValue(v *int) *ItemFieldCreate { - if v != nil { - _c.SetNumberValue(*v) - } - return _c -} - -// SetBooleanValue sets the "boolean_value" field. -func (_c *ItemFieldCreate) SetBooleanValue(v bool) *ItemFieldCreate { - _c.mutation.SetBooleanValue(v) - return _c -} - -// SetNillableBooleanValue sets the "boolean_value" field if the given value is not nil. -func (_c *ItemFieldCreate) SetNillableBooleanValue(v *bool) *ItemFieldCreate { - if v != nil { - _c.SetBooleanValue(*v) - } - return _c -} - -// SetTimeValue sets the "time_value" field. -func (_c *ItemFieldCreate) SetTimeValue(v time.Time) *ItemFieldCreate { - _c.mutation.SetTimeValue(v) - return _c -} - -// SetNillableTimeValue sets the "time_value" field if the given value is not nil. -func (_c *ItemFieldCreate) SetNillableTimeValue(v *time.Time) *ItemFieldCreate { - if v != nil { - _c.SetTimeValue(*v) - } - return _c -} - -// SetID sets the "id" field. -func (_c *ItemFieldCreate) SetID(v uuid.UUID) *ItemFieldCreate { - _c.mutation.SetID(v) - return _c -} - -// SetNillableID sets the "id" field if the given value is not nil. -func (_c *ItemFieldCreate) SetNillableID(v *uuid.UUID) *ItemFieldCreate { - if v != nil { - _c.SetID(*v) - } - return _c -} - -// SetItemID sets the "item" edge to the Item entity by ID. -func (_c *ItemFieldCreate) SetItemID(id uuid.UUID) *ItemFieldCreate { - _c.mutation.SetItemID(id) - return _c -} - -// SetNillableItemID sets the "item" edge to the Item entity by ID if the given value is not nil. -func (_c *ItemFieldCreate) SetNillableItemID(id *uuid.UUID) *ItemFieldCreate { - if id != nil { - _c = _c.SetItemID(*id) - } - return _c -} - -// SetItem sets the "item" edge to the Item entity. -func (_c *ItemFieldCreate) SetItem(v *Item) *ItemFieldCreate { - return _c.SetItemID(v.ID) -} - -// Mutation returns the ItemFieldMutation object of the builder. -func (_c *ItemFieldCreate) Mutation() *ItemFieldMutation { - return _c.mutation -} - -// Save creates the ItemField in the database. -func (_c *ItemFieldCreate) Save(ctx context.Context) (*ItemField, error) { - _c.defaults() - return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (_c *ItemFieldCreate) SaveX(ctx context.Context) *ItemField { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *ItemFieldCreate) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *ItemFieldCreate) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_c *ItemFieldCreate) defaults() { - if _, ok := _c.mutation.CreatedAt(); !ok { - v := itemfield.DefaultCreatedAt() - _c.mutation.SetCreatedAt(v) - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - v := itemfield.DefaultUpdatedAt() - _c.mutation.SetUpdatedAt(v) - } - if _, ok := _c.mutation.BooleanValue(); !ok { - v := itemfield.DefaultBooleanValue - _c.mutation.SetBooleanValue(v) - } - if _, ok := _c.mutation.TimeValue(); !ok { - v := itemfield.DefaultTimeValue() - _c.mutation.SetTimeValue(v) - } - if _, ok := _c.mutation.ID(); !ok { - v := itemfield.DefaultID() - _c.mutation.SetID(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_c *ItemFieldCreate) check() error { - if _, ok := _c.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ItemField.created_at"`)} - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "ItemField.updated_at"`)} - } - if _, ok := _c.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "ItemField.name"`)} - } - if v, ok := _c.mutation.Name(); ok { - if err := itemfield.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ItemField.name": %w`, err)} - } - } - if v, ok := _c.mutation.Description(); ok { - if err := itemfield.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ItemField.description": %w`, err)} - } - } - if _, ok := _c.mutation.GetType(); !ok { - return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "ItemField.type"`)} - } - if v, ok := _c.mutation.GetType(); ok { - if err := itemfield.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ItemField.type": %w`, err)} - } - } - if v, ok := _c.mutation.TextValue(); ok { - if err := itemfield.TextValueValidator(v); err != nil { - return &ValidationError{Name: "text_value", err: fmt.Errorf(`ent: validator failed for field "ItemField.text_value": %w`, err)} - } - } - if _, ok := _c.mutation.BooleanValue(); !ok { - return &ValidationError{Name: "boolean_value", err: errors.New(`ent: missing required field "ItemField.boolean_value"`)} - } - if _, ok := _c.mutation.TimeValue(); !ok { - return &ValidationError{Name: "time_value", err: errors.New(`ent: missing required field "ItemField.time_value"`)} - } - return nil -} - -func (_c *ItemFieldCreate) sqlSave(ctx context.Context) (*ItemField, error) { - if err := _c.check(); err != nil { - return nil, err - } - _node, _spec := _c.createSpec() - if err := sqlgraph.CreateNode(ctx, _c.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 - } - } - _c.mutation.id = &_node.ID - _c.mutation.done = true - return _node, nil -} - -func (_c *ItemFieldCreate) createSpec() (*ItemField, *sqlgraph.CreateSpec) { - var ( - _node = &ItemField{config: _c.config} - _spec = sqlgraph.NewCreateSpec(itemfield.Table, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID)) - ) - if id, ok := _c.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = &id - } - if value, ok := _c.mutation.CreatedAt(); ok { - _spec.SetField(itemfield.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := _c.mutation.UpdatedAt(); ok { - _spec.SetField(itemfield.FieldUpdatedAt, field.TypeTime, value) - _node.UpdatedAt = value - } - if value, ok := _c.mutation.Name(); ok { - _spec.SetField(itemfield.FieldName, field.TypeString, value) - _node.Name = value - } - if value, ok := _c.mutation.Description(); ok { - _spec.SetField(itemfield.FieldDescription, field.TypeString, value) - _node.Description = value - } - if value, ok := _c.mutation.GetType(); ok { - _spec.SetField(itemfield.FieldType, field.TypeEnum, value) - _node.Type = value - } - if value, ok := _c.mutation.TextValue(); ok { - _spec.SetField(itemfield.FieldTextValue, field.TypeString, value) - _node.TextValue = value - } - if value, ok := _c.mutation.NumberValue(); ok { - _spec.SetField(itemfield.FieldNumberValue, field.TypeInt, value) - _node.NumberValue = value - } - if value, ok := _c.mutation.BooleanValue(); ok { - _spec.SetField(itemfield.FieldBooleanValue, field.TypeBool, value) - _node.BooleanValue = value - } - if value, ok := _c.mutation.TimeValue(); ok { - _spec.SetField(itemfield.FieldTimeValue, field.TypeTime, value) - _node.TimeValue = value - } - if nodes := _c.mutation.ItemIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: itemfield.ItemTable, - Columns: []string{itemfield.ItemColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _node.item_fields = &nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// ItemFieldCreateBulk is the builder for creating many ItemField entities in bulk. -type ItemFieldCreateBulk struct { - config - err error - builders []*ItemFieldCreate -} - -// Save creates the ItemField entities in the database. -func (_c *ItemFieldCreateBulk) Save(ctx context.Context) ([]*ItemField, error) { - if _c.err != nil { - return nil, _c.err - } - specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) - nodes := make([]*ItemField, len(_c.builders)) - mutators := make([]Mutator, len(_c.builders)) - for i := range _c.builders { - func(i int, root context.Context) { - builder := _c.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ItemFieldMutation) - 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, _c.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, _c.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, _c.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (_c *ItemFieldCreateBulk) SaveX(ctx context.Context) []*ItemField { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *ItemFieldCreateBulk) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *ItemFieldCreateBulk) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/backend/internal/data/ent/itemfield_delete.go b/backend/internal/data/ent/itemfield_delete.go deleted file mode 100644 index 048cb13d..00000000 --- a/backend/internal/data/ent/itemfield_delete.go +++ /dev/null @@ -1,88 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" -) - -// ItemFieldDelete is the builder for deleting a ItemField entity. -type ItemFieldDelete struct { - config - hooks []Hook - mutation *ItemFieldMutation -} - -// Where appends a list predicates to the ItemFieldDelete builder. -func (_d *ItemFieldDelete) Where(ps ...predicate.ItemField) *ItemFieldDelete { - _d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (_d *ItemFieldDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *ItemFieldDelete) ExecX(ctx context.Context) int { - n, err := _d.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (_d *ItemFieldDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(itemfield.Table, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID)) - if ps := _d.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - _d.mutation.done = true - return affected, err -} - -// ItemFieldDeleteOne is the builder for deleting a single ItemField entity. -type ItemFieldDeleteOne struct { - _d *ItemFieldDelete -} - -// Where appends a list predicates to the ItemFieldDelete builder. -func (_d *ItemFieldDeleteOne) Where(ps ...predicate.ItemField) *ItemFieldDeleteOne { - _d._d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query. -func (_d *ItemFieldDeleteOne) Exec(ctx context.Context) error { - n, err := _d._d.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{itemfield.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *ItemFieldDeleteOne) ExecX(ctx context.Context) { - if err := _d.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/backend/internal/data/ent/itemfield_query.go b/backend/internal/data/ent/itemfield_query.go deleted file mode 100644 index 39a85914..00000000 --- a/backend/internal/data/ent/itemfield_query.go +++ /dev/null @@ -1,615 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "math" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/google/uuid" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" -) - -// ItemFieldQuery is the builder for querying ItemField entities. -type ItemFieldQuery struct { - config - ctx *QueryContext - order []itemfield.OrderOption - inters []Interceptor - predicates []predicate.ItemField - withItem *ItemQuery - withFKs bool - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the ItemFieldQuery builder. -func (_q *ItemFieldQuery) Where(ps ...predicate.ItemField) *ItemFieldQuery { - _q.predicates = append(_q.predicates, ps...) - return _q -} - -// Limit the number of records to be returned by this query. -func (_q *ItemFieldQuery) Limit(limit int) *ItemFieldQuery { - _q.ctx.Limit = &limit - return _q -} - -// Offset to start from. -func (_q *ItemFieldQuery) Offset(offset int) *ItemFieldQuery { - _q.ctx.Offset = &offset - return _q -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (_q *ItemFieldQuery) Unique(unique bool) *ItemFieldQuery { - _q.ctx.Unique = &unique - return _q -} - -// Order specifies how the records should be ordered. -func (_q *ItemFieldQuery) Order(o ...itemfield.OrderOption) *ItemFieldQuery { - _q.order = append(_q.order, o...) - return _q -} - -// QueryItem chains the current query on the "item" edge. -func (_q *ItemFieldQuery) QueryItem() *ItemQuery { - query := (&ItemClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(itemfield.Table, itemfield.FieldID, selector), - sqlgraph.To(item.Table, item.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, itemfield.ItemTable, itemfield.ItemColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first ItemField entity from the query. -// Returns a *NotFoundError when no ItemField was found. -func (_q *ItemFieldQuery) First(ctx context.Context) (*ItemField, error) { - nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{itemfield.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (_q *ItemFieldQuery) FirstX(ctx context.Context) *ItemField { - node, err := _q.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first ItemField ID from the query. -// Returns a *NotFoundError when no ItemField ID was found. -func (_q *ItemFieldQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { - var ids []uuid.UUID - if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{itemfield.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (_q *ItemFieldQuery) FirstIDX(ctx context.Context) uuid.UUID { - id, err := _q.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single ItemField entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one ItemField entity is found. -// Returns a *NotFoundError when no ItemField entities are found. -func (_q *ItemFieldQuery) Only(ctx context.Context) (*ItemField, error) { - nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{itemfield.Label} - default: - return nil, &NotSingularError{itemfield.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (_q *ItemFieldQuery) OnlyX(ctx context.Context) *ItemField { - node, err := _q.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only ItemField ID in the query. -// Returns a *NotSingularError when more than one ItemField ID is found. -// Returns a *NotFoundError when no entities are found. -func (_q *ItemFieldQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { - var ids []uuid.UUID - if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{itemfield.Label} - default: - err = &NotSingularError{itemfield.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *ItemFieldQuery) OnlyIDX(ctx context.Context) uuid.UUID { - id, err := _q.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of ItemFields. -func (_q *ItemFieldQuery) All(ctx context.Context) ([]*ItemField, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*ItemField, *ItemFieldQuery]() - return withInterceptors[[]*ItemField](ctx, _q, qr, _q.inters) -} - -// AllX is like All, but panics if an error occurs. -func (_q *ItemFieldQuery) AllX(ctx context.Context) []*ItemField { - nodes, err := _q.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of ItemField IDs. -func (_q *ItemFieldQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { - if _q.ctx.Unique == nil && _q.path != nil { - _q.Unique(true) - } - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) - if err = _q.Select(itemfield.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (_q *ItemFieldQuery) IDsX(ctx context.Context) []uuid.UUID { - ids, err := _q.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (_q *ItemFieldQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) - if err := _q.prepareQuery(ctx); err != nil { - return 0, err - } - return withInterceptors[int](ctx, _q, querierCount[*ItemFieldQuery](), _q.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (_q *ItemFieldQuery) CountX(ctx context.Context) int { - count, err := _q.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (_q *ItemFieldQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) - switch _, err := _q.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -// ExistX is like Exist, but panics if an error occurs. -func (_q *ItemFieldQuery) ExistX(ctx context.Context) bool { - exist, err := _q.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the ItemFieldQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (_q *ItemFieldQuery) Clone() *ItemFieldQuery { - if _q == nil { - return nil - } - return &ItemFieldQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]itemfield.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.ItemField{}, _q.predicates...), - withItem: _q.withItem.Clone(), - // clone intermediate query. - sql: _q.sql.Clone(), - path: _q.path, - } -} - -// WithItem tells the query-builder to eager-load the nodes that are connected to -// the "item" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *ItemFieldQuery) WithItem(opts ...func(*ItemQuery)) *ItemFieldQuery { - query := (&ItemClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withItem = query - return _q -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.ItemField.Query(). -// GroupBy(itemfield.FieldCreatedAt). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (_q *ItemFieldQuery) GroupBy(field string, fields ...string) *ItemFieldGroupBy { - _q.ctx.Fields = append([]string{field}, fields...) - grbuild := &ItemFieldGroupBy{build: _q} - grbuild.flds = &_q.ctx.Fields - grbuild.label = itemfield.Label - grbuild.scan = grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// } -// -// client.ItemField.Query(). -// Select(itemfield.FieldCreatedAt). -// Scan(ctx, &v) -func (_q *ItemFieldQuery) Select(fields ...string) *ItemFieldSelect { - _q.ctx.Fields = append(_q.ctx.Fields, fields...) - sbuild := &ItemFieldSelect{ItemFieldQuery: _q} - sbuild.label = itemfield.Label - sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a ItemFieldSelect configured with the given aggregations. -func (_q *ItemFieldQuery) Aggregate(fns ...AggregateFunc) *ItemFieldSelect { - return _q.Select().Aggregate(fns...) -} - -func (_q *ItemFieldQuery) prepareQuery(ctx context.Context) error { - for _, inter := range _q.inters { - if inter == nil { - return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") - } - if trv, ok := inter.(Traverser); ok { - if err := trv.Traverse(ctx, _q); err != nil { - return err - } - } - } - for _, f := range _q.ctx.Fields { - if !itemfield.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if _q.path != nil { - prev, err := _q.path(ctx) - if err != nil { - return err - } - _q.sql = prev - } - return nil -} - -func (_q *ItemFieldQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ItemField, error) { - var ( - nodes = []*ItemField{} - withFKs = _q.withFKs - _spec = _q.querySpec() - loadedTypes = [1]bool{ - _q.withItem != nil, - } - ) - if _q.withItem != nil { - withFKs = true - } - if withFKs { - _spec.Node.Columns = append(_spec.Node.Columns, itemfield.ForeignKeys...) - } - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*ItemField).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &ItemField{config: _q.config} - nodes = append(nodes, node) - node.Edges.loadedTypes = loadedTypes - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - if query := _q.withItem; query != nil { - if err := _q.loadItem(ctx, query, nodes, nil, - func(n *ItemField, e *Item) { n.Edges.Item = e }); err != nil { - return nil, err - } - } - return nodes, nil -} - -func (_q *ItemFieldQuery) loadItem(ctx context.Context, query *ItemQuery, nodes []*ItemField, init func(*ItemField), assign func(*ItemField, *Item)) error { - ids := make([]uuid.UUID, 0, len(nodes)) - nodeids := make(map[uuid.UUID][]*ItemField) - for i := range nodes { - if nodes[i].item_fields == nil { - continue - } - fk := *nodes[i].item_fields - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - if len(ids) == 0 { - return nil - } - query.Where(item.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return fmt.Errorf(`unexpected foreign-key "item_fields" returned %v`, n.ID) - } - for i := range nodes { - assign(nodes[i], n) - } - } - return nil -} - -func (_q *ItemFieldQuery) sqlCount(ctx context.Context) (int, error) { - _spec := _q.querySpec() - _spec.Node.Columns = _q.ctx.Fields - if len(_q.ctx.Fields) > 0 { - _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique - } - return sqlgraph.CountNodes(ctx, _q.driver, _spec) -} - -func (_q *ItemFieldQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(itemfield.Table, itemfield.Columns, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID)) - _spec.From = _q.sql - if unique := _q.ctx.Unique; unique != nil { - _spec.Unique = *unique - } else if _q.path != nil { - _spec.Unique = true - } - if fields := _q.ctx.Fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, itemfield.FieldID) - for i := range fields { - if fields[i] != itemfield.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := _q.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := _q.ctx.Limit; limit != nil { - _spec.Limit = *limit - } - if offset := _q.ctx.Offset; offset != nil { - _spec.Offset = *offset - } - if ps := _q.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (_q *ItemFieldQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(_q.driver.Dialect()) - t1 := builder.Table(itemfield.Table) - columns := _q.ctx.Fields - if len(columns) == 0 { - columns = itemfield.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if _q.sql != nil { - selector = _q.sql - selector.Select(selector.Columns(columns...)...) - } - if _q.ctx.Unique != nil && *_q.ctx.Unique { - selector.Distinct() - } - for _, p := range _q.predicates { - p(selector) - } - for _, p := range _q.order { - p(selector) - } - if offset := _q.ctx.Offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := _q.ctx.Limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// ItemFieldGroupBy is the group-by builder for ItemField entities. -type ItemFieldGroupBy struct { - selector - build *ItemFieldQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (_g *ItemFieldGroupBy) Aggregate(fns ...AggregateFunc) *ItemFieldGroupBy { - _g.fns = append(_g.fns, fns...) - return _g -} - -// Scan applies the selector query and scans the result into the given value. -func (_g *ItemFieldGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) - if err := _g.build.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*ItemFieldQuery, *ItemFieldGroupBy](ctx, _g.build, _g, _g.build.inters, v) -} - -func (_g *ItemFieldGroupBy) sqlScan(ctx context.Context, root *ItemFieldQuery, v any) error { - selector := root.sqlQuery(ctx).Select() - aggregation := make([]string, 0, len(_g.fns)) - for _, fn := range _g.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) - for _, f := range *_g.flds { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - selector.GroupBy(selector.Columns(*_g.flds...)...) - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -// ItemFieldSelect is the builder for selecting fields of ItemField entities. -type ItemFieldSelect struct { - *ItemFieldQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (_s *ItemFieldSelect) Aggregate(fns ...AggregateFunc) *ItemFieldSelect { - _s.fns = append(_s.fns, fns...) - return _s -} - -// Scan applies the selector query and scans the result into the given value. -func (_s *ItemFieldSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) - if err := _s.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*ItemFieldQuery, *ItemFieldSelect](ctx, _s.ItemFieldQuery, _s, _s.inters, v) -} - -func (_s *ItemFieldSelect) sqlScan(ctx context.Context, root *ItemFieldQuery, v any) error { - selector := root.sqlQuery(ctx) - aggregation := make([]string, 0, len(_s.fns)) - for _, fn := range _s.fns { - aggregation = append(aggregation, fn(selector)) - } - switch n := len(*_s.selector.flds); { - case n == 0 && len(aggregation) > 0: - selector.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - selector.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := _s.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/backend/internal/data/ent/itemfield_update.go b/backend/internal/data/ent/itemfield_update.go deleted file mode 100644 index 941c4328..00000000 --- a/backend/internal/data/ent/itemfield_update.go +++ /dev/null @@ -1,690 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/google/uuid" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" -) - -// ItemFieldUpdate is the builder for updating ItemField entities. -type ItemFieldUpdate struct { - config - hooks []Hook - mutation *ItemFieldMutation -} - -// Where appends a list predicates to the ItemFieldUpdate builder. -func (_u *ItemFieldUpdate) Where(ps ...predicate.ItemField) *ItemFieldUpdate { - _u.mutation.Where(ps...) - return _u -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *ItemFieldUpdate) SetUpdatedAt(v time.Time) *ItemFieldUpdate { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetName sets the "name" field. -func (_u *ItemFieldUpdate) SetName(v string) *ItemFieldUpdate { - _u.mutation.SetName(v) - return _u -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_u *ItemFieldUpdate) SetNillableName(v *string) *ItemFieldUpdate { - if v != nil { - _u.SetName(*v) - } - return _u -} - -// SetDescription sets the "description" field. -func (_u *ItemFieldUpdate) SetDescription(v string) *ItemFieldUpdate { - _u.mutation.SetDescription(v) - return _u -} - -// SetNillableDescription sets the "description" field if the given value is not nil. -func (_u *ItemFieldUpdate) SetNillableDescription(v *string) *ItemFieldUpdate { - if v != nil { - _u.SetDescription(*v) - } - return _u -} - -// ClearDescription clears the value of the "description" field. -func (_u *ItemFieldUpdate) ClearDescription() *ItemFieldUpdate { - _u.mutation.ClearDescription() - return _u -} - -// SetType sets the "type" field. -func (_u *ItemFieldUpdate) SetType(v itemfield.Type) *ItemFieldUpdate { - _u.mutation.SetType(v) - return _u -} - -// SetNillableType sets the "type" field if the given value is not nil. -func (_u *ItemFieldUpdate) SetNillableType(v *itemfield.Type) *ItemFieldUpdate { - if v != nil { - _u.SetType(*v) - } - return _u -} - -// SetTextValue sets the "text_value" field. -func (_u *ItemFieldUpdate) SetTextValue(v string) *ItemFieldUpdate { - _u.mutation.SetTextValue(v) - return _u -} - -// SetNillableTextValue sets the "text_value" field if the given value is not nil. -func (_u *ItemFieldUpdate) SetNillableTextValue(v *string) *ItemFieldUpdate { - if v != nil { - _u.SetTextValue(*v) - } - return _u -} - -// ClearTextValue clears the value of the "text_value" field. -func (_u *ItemFieldUpdate) ClearTextValue() *ItemFieldUpdate { - _u.mutation.ClearTextValue() - return _u -} - -// SetNumberValue sets the "number_value" field. -func (_u *ItemFieldUpdate) SetNumberValue(v int) *ItemFieldUpdate { - _u.mutation.ResetNumberValue() - _u.mutation.SetNumberValue(v) - return _u -} - -// SetNillableNumberValue sets the "number_value" field if the given value is not nil. -func (_u *ItemFieldUpdate) SetNillableNumberValue(v *int) *ItemFieldUpdate { - if v != nil { - _u.SetNumberValue(*v) - } - return _u -} - -// AddNumberValue adds value to the "number_value" field. -func (_u *ItemFieldUpdate) AddNumberValue(v int) *ItemFieldUpdate { - _u.mutation.AddNumberValue(v) - return _u -} - -// ClearNumberValue clears the value of the "number_value" field. -func (_u *ItemFieldUpdate) ClearNumberValue() *ItemFieldUpdate { - _u.mutation.ClearNumberValue() - return _u -} - -// SetBooleanValue sets the "boolean_value" field. -func (_u *ItemFieldUpdate) SetBooleanValue(v bool) *ItemFieldUpdate { - _u.mutation.SetBooleanValue(v) - return _u -} - -// SetNillableBooleanValue sets the "boolean_value" field if the given value is not nil. -func (_u *ItemFieldUpdate) SetNillableBooleanValue(v *bool) *ItemFieldUpdate { - if v != nil { - _u.SetBooleanValue(*v) - } - return _u -} - -// SetTimeValue sets the "time_value" field. -func (_u *ItemFieldUpdate) SetTimeValue(v time.Time) *ItemFieldUpdate { - _u.mutation.SetTimeValue(v) - return _u -} - -// SetNillableTimeValue sets the "time_value" field if the given value is not nil. -func (_u *ItemFieldUpdate) SetNillableTimeValue(v *time.Time) *ItemFieldUpdate { - if v != nil { - _u.SetTimeValue(*v) - } - return _u -} - -// SetItemID sets the "item" edge to the Item entity by ID. -func (_u *ItemFieldUpdate) SetItemID(id uuid.UUID) *ItemFieldUpdate { - _u.mutation.SetItemID(id) - return _u -} - -// SetNillableItemID sets the "item" edge to the Item entity by ID if the given value is not nil. -func (_u *ItemFieldUpdate) SetNillableItemID(id *uuid.UUID) *ItemFieldUpdate { - if id != nil { - _u = _u.SetItemID(*id) - } - return _u -} - -// SetItem sets the "item" edge to the Item entity. -func (_u *ItemFieldUpdate) SetItem(v *Item) *ItemFieldUpdate { - return _u.SetItemID(v.ID) -} - -// Mutation returns the ItemFieldMutation object of the builder. -func (_u *ItemFieldUpdate) Mutation() *ItemFieldMutation { - return _u.mutation -} - -// ClearItem clears the "item" edge to the Item entity. -func (_u *ItemFieldUpdate) ClearItem() *ItemFieldUpdate { - _u.mutation.ClearItem() - return _u -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (_u *ItemFieldUpdate) Save(ctx context.Context) (int, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *ItemFieldUpdate) SaveX(ctx context.Context) int { - affected, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (_u *ItemFieldUpdate) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *ItemFieldUpdate) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *ItemFieldUpdate) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := itemfield.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_u *ItemFieldUpdate) check() error { - if v, ok := _u.mutation.Name(); ok { - if err := itemfield.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ItemField.name": %w`, err)} - } - } - if v, ok := _u.mutation.Description(); ok { - if err := itemfield.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ItemField.description": %w`, err)} - } - } - if v, ok := _u.mutation.GetType(); ok { - if err := itemfield.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ItemField.type": %w`, err)} - } - } - if v, ok := _u.mutation.TextValue(); ok { - if err := itemfield.TextValueValidator(v); err != nil { - return &ValidationError{Name: "text_value", err: fmt.Errorf(`ent: validator failed for field "ItemField.text_value": %w`, err)} - } - } - return nil -} - -func (_u *ItemFieldUpdate) sqlSave(ctx context.Context) (_node int, err error) { - if err := _u.check(); err != nil { - return _node, err - } - _spec := sqlgraph.NewUpdateSpec(itemfield.Table, itemfield.Columns, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID)) - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(itemfield.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Name(); ok { - _spec.SetField(itemfield.FieldName, field.TypeString, value) - } - if value, ok := _u.mutation.Description(); ok { - _spec.SetField(itemfield.FieldDescription, field.TypeString, value) - } - if _u.mutation.DescriptionCleared() { - _spec.ClearField(itemfield.FieldDescription, field.TypeString) - } - if value, ok := _u.mutation.GetType(); ok { - _spec.SetField(itemfield.FieldType, field.TypeEnum, value) - } - if value, ok := _u.mutation.TextValue(); ok { - _spec.SetField(itemfield.FieldTextValue, field.TypeString, value) - } - if _u.mutation.TextValueCleared() { - _spec.ClearField(itemfield.FieldTextValue, field.TypeString) - } - if value, ok := _u.mutation.NumberValue(); ok { - _spec.SetField(itemfield.FieldNumberValue, field.TypeInt, value) - } - if value, ok := _u.mutation.AddedNumberValue(); ok { - _spec.AddField(itemfield.FieldNumberValue, field.TypeInt, value) - } - if _u.mutation.NumberValueCleared() { - _spec.ClearField(itemfield.FieldNumberValue, field.TypeInt) - } - if value, ok := _u.mutation.BooleanValue(); ok { - _spec.SetField(itemfield.FieldBooleanValue, field.TypeBool, value) - } - if value, ok := _u.mutation.TimeValue(); ok { - _spec.SetField(itemfield.FieldTimeValue, field.TypeTime, value) - } - if _u.mutation.ItemCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: itemfield.ItemTable, - Columns: []string{itemfield.ItemColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.ItemIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: itemfield.ItemTable, - Columns: []string{itemfield.ItemColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{itemfield.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - _u.mutation.done = true - return _node, nil -} - -// ItemFieldUpdateOne is the builder for updating a single ItemField entity. -type ItemFieldUpdateOne struct { - config - fields []string - hooks []Hook - mutation *ItemFieldMutation -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *ItemFieldUpdateOne) SetUpdatedAt(v time.Time) *ItemFieldUpdateOne { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetName sets the "name" field. -func (_u *ItemFieldUpdateOne) SetName(v string) *ItemFieldUpdateOne { - _u.mutation.SetName(v) - return _u -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_u *ItemFieldUpdateOne) SetNillableName(v *string) *ItemFieldUpdateOne { - if v != nil { - _u.SetName(*v) - } - return _u -} - -// SetDescription sets the "description" field. -func (_u *ItemFieldUpdateOne) SetDescription(v string) *ItemFieldUpdateOne { - _u.mutation.SetDescription(v) - return _u -} - -// SetNillableDescription sets the "description" field if the given value is not nil. -func (_u *ItemFieldUpdateOne) SetNillableDescription(v *string) *ItemFieldUpdateOne { - if v != nil { - _u.SetDescription(*v) - } - return _u -} - -// ClearDescription clears the value of the "description" field. -func (_u *ItemFieldUpdateOne) ClearDescription() *ItemFieldUpdateOne { - _u.mutation.ClearDescription() - return _u -} - -// SetType sets the "type" field. -func (_u *ItemFieldUpdateOne) SetType(v itemfield.Type) *ItemFieldUpdateOne { - _u.mutation.SetType(v) - return _u -} - -// SetNillableType sets the "type" field if the given value is not nil. -func (_u *ItemFieldUpdateOne) SetNillableType(v *itemfield.Type) *ItemFieldUpdateOne { - if v != nil { - _u.SetType(*v) - } - return _u -} - -// SetTextValue sets the "text_value" field. -func (_u *ItemFieldUpdateOne) SetTextValue(v string) *ItemFieldUpdateOne { - _u.mutation.SetTextValue(v) - return _u -} - -// SetNillableTextValue sets the "text_value" field if the given value is not nil. -func (_u *ItemFieldUpdateOne) SetNillableTextValue(v *string) *ItemFieldUpdateOne { - if v != nil { - _u.SetTextValue(*v) - } - return _u -} - -// ClearTextValue clears the value of the "text_value" field. -func (_u *ItemFieldUpdateOne) ClearTextValue() *ItemFieldUpdateOne { - _u.mutation.ClearTextValue() - return _u -} - -// SetNumberValue sets the "number_value" field. -func (_u *ItemFieldUpdateOne) SetNumberValue(v int) *ItemFieldUpdateOne { - _u.mutation.ResetNumberValue() - _u.mutation.SetNumberValue(v) - return _u -} - -// SetNillableNumberValue sets the "number_value" field if the given value is not nil. -func (_u *ItemFieldUpdateOne) SetNillableNumberValue(v *int) *ItemFieldUpdateOne { - if v != nil { - _u.SetNumberValue(*v) - } - return _u -} - -// AddNumberValue adds value to the "number_value" field. -func (_u *ItemFieldUpdateOne) AddNumberValue(v int) *ItemFieldUpdateOne { - _u.mutation.AddNumberValue(v) - return _u -} - -// ClearNumberValue clears the value of the "number_value" field. -func (_u *ItemFieldUpdateOne) ClearNumberValue() *ItemFieldUpdateOne { - _u.mutation.ClearNumberValue() - return _u -} - -// SetBooleanValue sets the "boolean_value" field. -func (_u *ItemFieldUpdateOne) SetBooleanValue(v bool) *ItemFieldUpdateOne { - _u.mutation.SetBooleanValue(v) - return _u -} - -// SetNillableBooleanValue sets the "boolean_value" field if the given value is not nil. -func (_u *ItemFieldUpdateOne) SetNillableBooleanValue(v *bool) *ItemFieldUpdateOne { - if v != nil { - _u.SetBooleanValue(*v) - } - return _u -} - -// SetTimeValue sets the "time_value" field. -func (_u *ItemFieldUpdateOne) SetTimeValue(v time.Time) *ItemFieldUpdateOne { - _u.mutation.SetTimeValue(v) - return _u -} - -// SetNillableTimeValue sets the "time_value" field if the given value is not nil. -func (_u *ItemFieldUpdateOne) SetNillableTimeValue(v *time.Time) *ItemFieldUpdateOne { - if v != nil { - _u.SetTimeValue(*v) - } - return _u -} - -// SetItemID sets the "item" edge to the Item entity by ID. -func (_u *ItemFieldUpdateOne) SetItemID(id uuid.UUID) *ItemFieldUpdateOne { - _u.mutation.SetItemID(id) - return _u -} - -// SetNillableItemID sets the "item" edge to the Item entity by ID if the given value is not nil. -func (_u *ItemFieldUpdateOne) SetNillableItemID(id *uuid.UUID) *ItemFieldUpdateOne { - if id != nil { - _u = _u.SetItemID(*id) - } - return _u -} - -// SetItem sets the "item" edge to the Item entity. -func (_u *ItemFieldUpdateOne) SetItem(v *Item) *ItemFieldUpdateOne { - return _u.SetItemID(v.ID) -} - -// Mutation returns the ItemFieldMutation object of the builder. -func (_u *ItemFieldUpdateOne) Mutation() *ItemFieldMutation { - return _u.mutation -} - -// ClearItem clears the "item" edge to the Item entity. -func (_u *ItemFieldUpdateOne) ClearItem() *ItemFieldUpdateOne { - _u.mutation.ClearItem() - return _u -} - -// Where appends a list predicates to the ItemFieldUpdate builder. -func (_u *ItemFieldUpdateOne) Where(ps ...predicate.ItemField) *ItemFieldUpdateOne { - _u.mutation.Where(ps...) - return _u -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (_u *ItemFieldUpdateOne) Select(field string, fields ...string) *ItemFieldUpdateOne { - _u.fields = append([]string{field}, fields...) - return _u -} - -// Save executes the query and returns the updated ItemField entity. -func (_u *ItemFieldUpdateOne) Save(ctx context.Context) (*ItemField, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *ItemFieldUpdateOne) SaveX(ctx context.Context) *ItemField { - node, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (_u *ItemFieldUpdateOne) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *ItemFieldUpdateOne) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *ItemFieldUpdateOne) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := itemfield.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_u *ItemFieldUpdateOne) check() error { - if v, ok := _u.mutation.Name(); ok { - if err := itemfield.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ItemField.name": %w`, err)} - } - } - if v, ok := _u.mutation.Description(); ok { - if err := itemfield.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ItemField.description": %w`, err)} - } - } - if v, ok := _u.mutation.GetType(); ok { - if err := itemfield.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ItemField.type": %w`, err)} - } - } - if v, ok := _u.mutation.TextValue(); ok { - if err := itemfield.TextValueValidator(v); err != nil { - return &ValidationError{Name: "text_value", err: fmt.Errorf(`ent: validator failed for field "ItemField.text_value": %w`, err)} - } - } - return nil -} - -func (_u *ItemFieldUpdateOne) sqlSave(ctx context.Context) (_node *ItemField, err error) { - if err := _u.check(); err != nil { - return _node, err - } - _spec := sqlgraph.NewUpdateSpec(itemfield.Table, itemfield.Columns, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID)) - id, ok := _u.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ItemField.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := _u.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, itemfield.FieldID) - for _, f := range fields { - if !itemfield.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != itemfield.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(itemfield.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Name(); ok { - _spec.SetField(itemfield.FieldName, field.TypeString, value) - } - if value, ok := _u.mutation.Description(); ok { - _spec.SetField(itemfield.FieldDescription, field.TypeString, value) - } - if _u.mutation.DescriptionCleared() { - _spec.ClearField(itemfield.FieldDescription, field.TypeString) - } - if value, ok := _u.mutation.GetType(); ok { - _spec.SetField(itemfield.FieldType, field.TypeEnum, value) - } - if value, ok := _u.mutation.TextValue(); ok { - _spec.SetField(itemfield.FieldTextValue, field.TypeString, value) - } - if _u.mutation.TextValueCleared() { - _spec.ClearField(itemfield.FieldTextValue, field.TypeString) - } - if value, ok := _u.mutation.NumberValue(); ok { - _spec.SetField(itemfield.FieldNumberValue, field.TypeInt, value) - } - if value, ok := _u.mutation.AddedNumberValue(); ok { - _spec.AddField(itemfield.FieldNumberValue, field.TypeInt, value) - } - if _u.mutation.NumberValueCleared() { - _spec.ClearField(itemfield.FieldNumberValue, field.TypeInt) - } - if value, ok := _u.mutation.BooleanValue(); ok { - _spec.SetField(itemfield.FieldBooleanValue, field.TypeBool, value) - } - if value, ok := _u.mutation.TimeValue(); ok { - _spec.SetField(itemfield.FieldTimeValue, field.TypeTime, value) - } - if _u.mutation.ItemCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: itemfield.ItemTable, - Columns: []string{itemfield.ItemColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.ItemIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: itemfield.ItemTable, - Columns: []string{itemfield.ItemColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &ItemField{config: _u.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{itemfield.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - _u.mutation.done = true - return _node, nil -} diff --git a/backend/internal/data/ent/location.go b/backend/internal/data/ent/location.go deleted file mode 100644 index e0e24001..00000000 --- a/backend/internal/data/ent/location.go +++ /dev/null @@ -1,239 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "github.com/google/uuid" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" -) - -// Location is the model entity for the Location schema. -type Location struct { - config `json:"-"` - // ID of the ent. - ID uuid.UUID `json:"id,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at,omitempty"` - // Name holds the value of the "name" field. - Name string `json:"name,omitempty"` - // Description holds the value of the "description" field. - Description string `json:"description,omitempty"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the LocationQuery when eager-loading is set. - Edges LocationEdges `json:"edges"` - group_locations *uuid.UUID - location_children *uuid.UUID - selectValues sql.SelectValues -} - -// LocationEdges holds the relations/edges for other nodes in the graph. -type LocationEdges struct { - // Group holds the value of the group edge. - Group *Group `json:"group,omitempty"` - // Parent holds the value of the parent edge. - Parent *Location `json:"parent,omitempty"` - // Children holds the value of the children edge. - Children []*Location `json:"children,omitempty"` - // Items holds the value of the items edge. - Items []*Item `json:"items,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [4]bool -} - -// GroupOrErr returns the Group value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e LocationEdges) GroupOrErr() (*Group, error) { - if e.Group != nil { - return e.Group, nil - } else if e.loadedTypes[0] { - return nil, &NotFoundError{label: group.Label} - } - return nil, &NotLoadedError{edge: "group"} -} - -// ParentOrErr returns the Parent value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e LocationEdges) ParentOrErr() (*Location, error) { - if e.Parent != nil { - return e.Parent, nil - } else if e.loadedTypes[1] { - return nil, &NotFoundError{label: location.Label} - } - return nil, &NotLoadedError{edge: "parent"} -} - -// ChildrenOrErr returns the Children value or an error if the edge -// was not loaded in eager-loading. -func (e LocationEdges) ChildrenOrErr() ([]*Location, error) { - if e.loadedTypes[2] { - return e.Children, nil - } - return nil, &NotLoadedError{edge: "children"} -} - -// ItemsOrErr returns the Items value or an error if the edge -// was not loaded in eager-loading. -func (e LocationEdges) ItemsOrErr() ([]*Item, error) { - if e.loadedTypes[3] { - return e.Items, nil - } - return nil, &NotLoadedError{edge: "items"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*Location) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case location.FieldName, location.FieldDescription: - values[i] = new(sql.NullString) - case location.FieldCreatedAt, location.FieldUpdatedAt: - values[i] = new(sql.NullTime) - case location.FieldID: - values[i] = new(uuid.UUID) - case location.ForeignKeys[0]: // group_locations - values[i] = &sql.NullScanner{S: new(uuid.UUID)} - case location.ForeignKeys[1]: // location_children - values[i] = &sql.NullScanner{S: new(uuid.UUID)} - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Location fields. -func (_m *Location) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case location.FieldID: - if value, ok := values[i].(*uuid.UUID); !ok { - return fmt.Errorf("unexpected type %T for field id", values[i]) - } else if value != nil { - _m.ID = *value - } - case location.FieldCreatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[i]) - } else if value.Valid { - _m.CreatedAt = value.Time - } - case location.FieldUpdatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[i]) - } else if value.Valid { - _m.UpdatedAt = value.Time - } - case location.FieldName: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field name", values[i]) - } else if value.Valid { - _m.Name = value.String - } - case location.FieldDescription: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field description", values[i]) - } else if value.Valid { - _m.Description = value.String - } - case location.ForeignKeys[0]: - if value, ok := values[i].(*sql.NullScanner); !ok { - return fmt.Errorf("unexpected type %T for field group_locations", values[i]) - } else if value.Valid { - _m.group_locations = new(uuid.UUID) - *_m.group_locations = *value.S.(*uuid.UUID) - } - case location.ForeignKeys[1]: - if value, ok := values[i].(*sql.NullScanner); !ok { - return fmt.Errorf("unexpected type %T for field location_children", values[i]) - } else if value.Valid { - _m.location_children = new(uuid.UUID) - *_m.location_children = *value.S.(*uuid.UUID) - } - default: - _m.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the Location. -// This includes values selected through modifiers, order, etc. -func (_m *Location) Value(name string) (ent.Value, error) { - return _m.selectValues.Get(name) -} - -// QueryGroup queries the "group" edge of the Location entity. -func (_m *Location) QueryGroup() *GroupQuery { - return NewLocationClient(_m.config).QueryGroup(_m) -} - -// QueryParent queries the "parent" edge of the Location entity. -func (_m *Location) QueryParent() *LocationQuery { - return NewLocationClient(_m.config).QueryParent(_m) -} - -// QueryChildren queries the "children" edge of the Location entity. -func (_m *Location) QueryChildren() *LocationQuery { - return NewLocationClient(_m.config).QueryChildren(_m) -} - -// QueryItems queries the "items" edge of the Location entity. -func (_m *Location) QueryItems() *ItemQuery { - return NewLocationClient(_m.config).QueryItems(_m) -} - -// Update returns a builder for updating this Location. -// Note that you need to call Location.Unwrap() before calling this method if this Location -// was returned from a transaction, and the transaction was committed or rolled back. -func (_m *Location) Update() *LocationUpdateOne { - return NewLocationClient(_m.config).UpdateOne(_m) -} - -// Unwrap unwraps the Location entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (_m *Location) Unwrap() *Location { - _tx, ok := _m.config.driver.(*txDriver) - if !ok { - panic("ent: Location is not a transactional entity") - } - _m.config.driver = _tx.drv - return _m -} - -// String implements the fmt.Stringer. -func (_m *Location) String() string { - var builder strings.Builder - builder.WriteString("Location(") - builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) - builder.WriteString("created_at=") - builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("updated_at=") - builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("name=") - builder.WriteString(_m.Name) - builder.WriteString(", ") - builder.WriteString("description=") - builder.WriteString(_m.Description) - builder.WriteByte(')') - return builder.String() -} - -// Locations is a parsable slice of Location. -type Locations []*Location diff --git a/backend/internal/data/ent/location_create.go b/backend/internal/data/ent/location_create.go deleted file mode 100644 index 901925be..00000000 --- a/backend/internal/data/ent/location_create.go +++ /dev/null @@ -1,423 +0,0 @@ -// 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/group" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" -) - -// LocationCreate is the builder for creating a Location entity. -type LocationCreate struct { - config - mutation *LocationMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (_c *LocationCreate) SetCreatedAt(v time.Time) *LocationCreate { - _c.mutation.SetCreatedAt(v) - return _c -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (_c *LocationCreate) SetNillableCreatedAt(v *time.Time) *LocationCreate { - if v != nil { - _c.SetCreatedAt(*v) - } - return _c -} - -// SetUpdatedAt sets the "updated_at" field. -func (_c *LocationCreate) SetUpdatedAt(v time.Time) *LocationCreate { - _c.mutation.SetUpdatedAt(v) - return _c -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (_c *LocationCreate) SetNillableUpdatedAt(v *time.Time) *LocationCreate { - if v != nil { - _c.SetUpdatedAt(*v) - } - return _c -} - -// SetName sets the "name" field. -func (_c *LocationCreate) SetName(v string) *LocationCreate { - _c.mutation.SetName(v) - return _c -} - -// SetDescription sets the "description" field. -func (_c *LocationCreate) SetDescription(v string) *LocationCreate { - _c.mutation.SetDescription(v) - return _c -} - -// SetNillableDescription sets the "description" field if the given value is not nil. -func (_c *LocationCreate) SetNillableDescription(v *string) *LocationCreate { - if v != nil { - _c.SetDescription(*v) - } - return _c -} - -// SetID sets the "id" field. -func (_c *LocationCreate) SetID(v uuid.UUID) *LocationCreate { - _c.mutation.SetID(v) - return _c -} - -// SetNillableID sets the "id" field if the given value is not nil. -func (_c *LocationCreate) SetNillableID(v *uuid.UUID) *LocationCreate { - if v != nil { - _c.SetID(*v) - } - return _c -} - -// SetGroupID sets the "group" edge to the Group entity by ID. -func (_c *LocationCreate) SetGroupID(id uuid.UUID) *LocationCreate { - _c.mutation.SetGroupID(id) - return _c -} - -// SetGroup sets the "group" edge to the Group entity. -func (_c *LocationCreate) SetGroup(v *Group) *LocationCreate { - return _c.SetGroupID(v.ID) -} - -// SetParentID sets the "parent" edge to the Location entity by ID. -func (_c *LocationCreate) SetParentID(id uuid.UUID) *LocationCreate { - _c.mutation.SetParentID(id) - return _c -} - -// SetNillableParentID sets the "parent" edge to the Location entity by ID if the given value is not nil. -func (_c *LocationCreate) SetNillableParentID(id *uuid.UUID) *LocationCreate { - if id != nil { - _c = _c.SetParentID(*id) - } - return _c -} - -// SetParent sets the "parent" edge to the Location entity. -func (_c *LocationCreate) SetParent(v *Location) *LocationCreate { - return _c.SetParentID(v.ID) -} - -// AddChildIDs adds the "children" edge to the Location entity by IDs. -func (_c *LocationCreate) AddChildIDs(ids ...uuid.UUID) *LocationCreate { - _c.mutation.AddChildIDs(ids...) - return _c -} - -// AddChildren adds the "children" edges to the Location entity. -func (_c *LocationCreate) AddChildren(v ...*Location) *LocationCreate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _c.AddChildIDs(ids...) -} - -// AddItemIDs adds the "items" edge to the Item entity by IDs. -func (_c *LocationCreate) AddItemIDs(ids ...uuid.UUID) *LocationCreate { - _c.mutation.AddItemIDs(ids...) - return _c -} - -// AddItems adds the "items" edges to the Item entity. -func (_c *LocationCreate) AddItems(v ...*Item) *LocationCreate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _c.AddItemIDs(ids...) -} - -// Mutation returns the LocationMutation object of the builder. -func (_c *LocationCreate) Mutation() *LocationMutation { - return _c.mutation -} - -// Save creates the Location in the database. -func (_c *LocationCreate) Save(ctx context.Context) (*Location, error) { - _c.defaults() - return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (_c *LocationCreate) SaveX(ctx context.Context) *Location { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *LocationCreate) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *LocationCreate) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_c *LocationCreate) defaults() { - if _, ok := _c.mutation.CreatedAt(); !ok { - v := location.DefaultCreatedAt() - _c.mutation.SetCreatedAt(v) - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - v := location.DefaultUpdatedAt() - _c.mutation.SetUpdatedAt(v) - } - if _, ok := _c.mutation.ID(); !ok { - v := location.DefaultID() - _c.mutation.SetID(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_c *LocationCreate) check() error { - if _, ok := _c.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Location.created_at"`)} - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Location.updated_at"`)} - } - if _, ok := _c.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Location.name"`)} - } - if v, ok := _c.mutation.Name(); ok { - if err := location.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Location.name": %w`, err)} - } - } - if v, ok := _c.mutation.Description(); ok { - if err := location.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Location.description": %w`, err)} - } - } - if len(_c.mutation.GroupIDs()) == 0 { - return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Location.group"`)} - } - return nil -} - -func (_c *LocationCreate) sqlSave(ctx context.Context) (*Location, error) { - if err := _c.check(); err != nil { - return nil, err - } - _node, _spec := _c.createSpec() - if err := sqlgraph.CreateNode(ctx, _c.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 - } - } - _c.mutation.id = &_node.ID - _c.mutation.done = true - return _node, nil -} - -func (_c *LocationCreate) createSpec() (*Location, *sqlgraph.CreateSpec) { - var ( - _node = &Location{config: _c.config} - _spec = sqlgraph.NewCreateSpec(location.Table, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID)) - ) - if id, ok := _c.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = &id - } - if value, ok := _c.mutation.CreatedAt(); ok { - _spec.SetField(location.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := _c.mutation.UpdatedAt(); ok { - _spec.SetField(location.FieldUpdatedAt, field.TypeTime, value) - _node.UpdatedAt = value - } - if value, ok := _c.mutation.Name(); ok { - _spec.SetField(location.FieldName, field.TypeString, value) - _node.Name = value - } - if value, ok := _c.mutation.Description(); ok { - _spec.SetField(location.FieldDescription, field.TypeString, value) - _node.Description = value - } - if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: location.GroupTable, - Columns: []string{location.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_locations = &nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := _c.mutation.ParentIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: location.ParentTable, - Columns: []string{location.ParentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _node.location_children = &nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := _c.mutation.ChildrenIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ChildrenTable, - Columns: []string{location.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := _c.mutation.ItemsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ItemsTable, - Columns: []string{location.ItemsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// LocationCreateBulk is the builder for creating many Location entities in bulk. -type LocationCreateBulk struct { - config - err error - builders []*LocationCreate -} - -// Save creates the Location entities in the database. -func (_c *LocationCreateBulk) Save(ctx context.Context) ([]*Location, error) { - if _c.err != nil { - return nil, _c.err - } - specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) - nodes := make([]*Location, len(_c.builders)) - mutators := make([]Mutator, len(_c.builders)) - for i := range _c.builders { - func(i int, root context.Context) { - builder := _c.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*LocationMutation) - 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, _c.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, _c.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, _c.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (_c *LocationCreateBulk) SaveX(ctx context.Context) []*Location { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *LocationCreateBulk) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *LocationCreateBulk) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/backend/internal/data/ent/location_delete.go b/backend/internal/data/ent/location_delete.go deleted file mode 100644 index 4292d82e..00000000 --- a/backend/internal/data/ent/location_delete.go +++ /dev/null @@ -1,88 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" -) - -// LocationDelete is the builder for deleting a Location entity. -type LocationDelete struct { - config - hooks []Hook - mutation *LocationMutation -} - -// Where appends a list predicates to the LocationDelete builder. -func (_d *LocationDelete) Where(ps ...predicate.Location) *LocationDelete { - _d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (_d *LocationDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *LocationDelete) ExecX(ctx context.Context) int { - n, err := _d.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (_d *LocationDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(location.Table, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID)) - if ps := _d.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - _d.mutation.done = true - return affected, err -} - -// LocationDeleteOne is the builder for deleting a single Location entity. -type LocationDeleteOne struct { - _d *LocationDelete -} - -// Where appends a list predicates to the LocationDelete builder. -func (_d *LocationDeleteOne) Where(ps ...predicate.Location) *LocationDeleteOne { - _d._d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query. -func (_d *LocationDeleteOne) Exec(ctx context.Context) error { - n, err := _d._d.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{location.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *LocationDeleteOne) ExecX(ctx context.Context) { - if err := _d.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/backend/internal/data/ent/location_query.go b/backend/internal/data/ent/location_query.go deleted file mode 100644 index 4e226d27..00000000 --- a/backend/internal/data/ent/location_query.go +++ /dev/null @@ -1,839 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "database/sql/driver" - "fmt" - "math" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/google/uuid" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" -) - -// LocationQuery is the builder for querying Location entities. -type LocationQuery struct { - config - ctx *QueryContext - order []location.OrderOption - inters []Interceptor - predicates []predicate.Location - withGroup *GroupQuery - withParent *LocationQuery - withChildren *LocationQuery - withItems *ItemQuery - withFKs bool - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the LocationQuery builder. -func (_q *LocationQuery) Where(ps ...predicate.Location) *LocationQuery { - _q.predicates = append(_q.predicates, ps...) - return _q -} - -// Limit the number of records to be returned by this query. -func (_q *LocationQuery) Limit(limit int) *LocationQuery { - _q.ctx.Limit = &limit - return _q -} - -// Offset to start from. -func (_q *LocationQuery) Offset(offset int) *LocationQuery { - _q.ctx.Offset = &offset - return _q -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (_q *LocationQuery) Unique(unique bool) *LocationQuery { - _q.ctx.Unique = &unique - return _q -} - -// Order specifies how the records should be ordered. -func (_q *LocationQuery) Order(o ...location.OrderOption) *LocationQuery { - _q.order = append(_q.order, o...) - return _q -} - -// QueryGroup chains the current query on the "group" edge. -func (_q *LocationQuery) QueryGroup() *GroupQuery { - query := (&GroupClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(location.Table, location.FieldID, selector), - sqlgraph.To(group.Table, group.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, location.GroupTable, location.GroupColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryParent chains the current query on the "parent" edge. -func (_q *LocationQuery) QueryParent() *LocationQuery { - query := (&LocationClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(location.Table, location.FieldID, selector), - sqlgraph.To(location.Table, location.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, location.ParentTable, location.ParentColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryChildren chains the current query on the "children" edge. -func (_q *LocationQuery) QueryChildren() *LocationQuery { - query := (&LocationClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(location.Table, location.FieldID, selector), - sqlgraph.To(location.Table, location.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, location.ChildrenTable, location.ChildrenColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryItems chains the current query on the "items" edge. -func (_q *LocationQuery) QueryItems() *ItemQuery { - query := (&ItemClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(location.Table, location.FieldID, selector), - sqlgraph.To(item.Table, item.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, location.ItemsTable, location.ItemsColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first Location entity from the query. -// Returns a *NotFoundError when no Location was found. -func (_q *LocationQuery) First(ctx context.Context) (*Location, error) { - nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{location.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (_q *LocationQuery) FirstX(ctx context.Context) *Location { - node, err := _q.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first Location ID from the query. -// Returns a *NotFoundError when no Location ID was found. -func (_q *LocationQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { - var ids []uuid.UUID - if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{location.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (_q *LocationQuery) FirstIDX(ctx context.Context) uuid.UUID { - id, err := _q.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single Location entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one Location entity is found. -// Returns a *NotFoundError when no Location entities are found. -func (_q *LocationQuery) Only(ctx context.Context) (*Location, error) { - nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{location.Label} - default: - return nil, &NotSingularError{location.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (_q *LocationQuery) OnlyX(ctx context.Context) *Location { - node, err := _q.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only Location ID in the query. -// Returns a *NotSingularError when more than one Location ID is found. -// Returns a *NotFoundError when no entities are found. -func (_q *LocationQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { - var ids []uuid.UUID - if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{location.Label} - default: - err = &NotSingularError{location.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *LocationQuery) OnlyIDX(ctx context.Context) uuid.UUID { - id, err := _q.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of Locations. -func (_q *LocationQuery) All(ctx context.Context) ([]*Location, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*Location, *LocationQuery]() - return withInterceptors[[]*Location](ctx, _q, qr, _q.inters) -} - -// AllX is like All, but panics if an error occurs. -func (_q *LocationQuery) AllX(ctx context.Context) []*Location { - nodes, err := _q.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of Location IDs. -func (_q *LocationQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { - if _q.ctx.Unique == nil && _q.path != nil { - _q.Unique(true) - } - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) - if err = _q.Select(location.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (_q *LocationQuery) IDsX(ctx context.Context) []uuid.UUID { - ids, err := _q.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (_q *LocationQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) - if err := _q.prepareQuery(ctx); err != nil { - return 0, err - } - return withInterceptors[int](ctx, _q, querierCount[*LocationQuery](), _q.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (_q *LocationQuery) CountX(ctx context.Context) int { - count, err := _q.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (_q *LocationQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) - switch _, err := _q.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -// ExistX is like Exist, but panics if an error occurs. -func (_q *LocationQuery) ExistX(ctx context.Context) bool { - exist, err := _q.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the LocationQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (_q *LocationQuery) Clone() *LocationQuery { - if _q == nil { - return nil - } - return &LocationQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]location.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.Location{}, _q.predicates...), - withGroup: _q.withGroup.Clone(), - withParent: _q.withParent.Clone(), - withChildren: _q.withChildren.Clone(), - withItems: _q.withItems.Clone(), - // clone intermediate query. - sql: _q.sql.Clone(), - path: _q.path, - } -} - -// WithGroup tells the query-builder to eager-load the nodes that are connected to -// the "group" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *LocationQuery) WithGroup(opts ...func(*GroupQuery)) *LocationQuery { - query := (&GroupClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withGroup = query - return _q -} - -// WithParent tells the query-builder to eager-load the nodes that are connected to -// the "parent" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *LocationQuery) WithParent(opts ...func(*LocationQuery)) *LocationQuery { - query := (&LocationClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withParent = query - return _q -} - -// WithChildren tells the query-builder to eager-load the nodes that are connected to -// the "children" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *LocationQuery) WithChildren(opts ...func(*LocationQuery)) *LocationQuery { - query := (&LocationClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withChildren = query - return _q -} - -// WithItems tells the query-builder to eager-load the nodes that are connected to -// the "items" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *LocationQuery) WithItems(opts ...func(*ItemQuery)) *LocationQuery { - query := (&ItemClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withItems = query - return _q -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.Location.Query(). -// GroupBy(location.FieldCreatedAt). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (_q *LocationQuery) GroupBy(field string, fields ...string) *LocationGroupBy { - _q.ctx.Fields = append([]string{field}, fields...) - grbuild := &LocationGroupBy{build: _q} - grbuild.flds = &_q.ctx.Fields - grbuild.label = location.Label - grbuild.scan = grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// } -// -// client.Location.Query(). -// Select(location.FieldCreatedAt). -// Scan(ctx, &v) -func (_q *LocationQuery) Select(fields ...string) *LocationSelect { - _q.ctx.Fields = append(_q.ctx.Fields, fields...) - sbuild := &LocationSelect{LocationQuery: _q} - sbuild.label = location.Label - sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a LocationSelect configured with the given aggregations. -func (_q *LocationQuery) Aggregate(fns ...AggregateFunc) *LocationSelect { - return _q.Select().Aggregate(fns...) -} - -func (_q *LocationQuery) prepareQuery(ctx context.Context) error { - for _, inter := range _q.inters { - if inter == nil { - return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") - } - if trv, ok := inter.(Traverser); ok { - if err := trv.Traverse(ctx, _q); err != nil { - return err - } - } - } - for _, f := range _q.ctx.Fields { - if !location.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if _q.path != nil { - prev, err := _q.path(ctx) - if err != nil { - return err - } - _q.sql = prev - } - return nil -} - -func (_q *LocationQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Location, error) { - var ( - nodes = []*Location{} - withFKs = _q.withFKs - _spec = _q.querySpec() - loadedTypes = [4]bool{ - _q.withGroup != nil, - _q.withParent != nil, - _q.withChildren != nil, - _q.withItems != nil, - } - ) - if _q.withGroup != nil || _q.withParent != nil { - withFKs = true - } - if withFKs { - _spec.Node.Columns = append(_spec.Node.Columns, location.ForeignKeys...) - } - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*Location).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &Location{config: _q.config} - nodes = append(nodes, node) - node.Edges.loadedTypes = loadedTypes - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - if query := _q.withGroup; query != nil { - if err := _q.loadGroup(ctx, query, nodes, nil, - func(n *Location, e *Group) { n.Edges.Group = e }); err != nil { - return nil, err - } - } - if query := _q.withParent; query != nil { - if err := _q.loadParent(ctx, query, nodes, nil, - func(n *Location, e *Location) { n.Edges.Parent = e }); err != nil { - return nil, err - } - } - if query := _q.withChildren; query != nil { - if err := _q.loadChildren(ctx, query, nodes, - func(n *Location) { n.Edges.Children = []*Location{} }, - func(n *Location, e *Location) { n.Edges.Children = append(n.Edges.Children, e) }); err != nil { - return nil, err - } - } - if query := _q.withItems; query != nil { - if err := _q.loadItems(ctx, query, nodes, - func(n *Location) { n.Edges.Items = []*Item{} }, - func(n *Location, e *Item) { n.Edges.Items = append(n.Edges.Items, e) }); err != nil { - return nil, err - } - } - return nodes, nil -} - -func (_q *LocationQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*Location, init func(*Location), assign func(*Location, *Group)) error { - ids := make([]uuid.UUID, 0, len(nodes)) - nodeids := make(map[uuid.UUID][]*Location) - for i := range nodes { - if nodes[i].group_locations == nil { - continue - } - fk := *nodes[i].group_locations - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - if len(ids) == 0 { - return nil - } - query.Where(group.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return fmt.Errorf(`unexpected foreign-key "group_locations" returned %v`, n.ID) - } - for i := range nodes { - assign(nodes[i], n) - } - } - return nil -} -func (_q *LocationQuery) loadParent(ctx context.Context, query *LocationQuery, nodes []*Location, init func(*Location), assign func(*Location, *Location)) error { - ids := make([]uuid.UUID, 0, len(nodes)) - nodeids := make(map[uuid.UUID][]*Location) - for i := range nodes { - if nodes[i].location_children == nil { - continue - } - fk := *nodes[i].location_children - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - if len(ids) == 0 { - return nil - } - query.Where(location.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return fmt.Errorf(`unexpected foreign-key "location_children" returned %v`, n.ID) - } - for i := range nodes { - assign(nodes[i], n) - } - } - return nil -} -func (_q *LocationQuery) loadChildren(ctx context.Context, query *LocationQuery, nodes []*Location, init func(*Location), assign func(*Location, *Location)) error { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[uuid.UUID]*Location) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - if init != nil { - init(nodes[i]) - } - } - query.withFKs = true - query.Where(predicate.Location(func(s *sql.Selector) { - s.Where(sql.InValues(s.C(location.ChildrenColumn), fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - fk := n.location_children - if fk == nil { - return fmt.Errorf(`foreign-key "location_children" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "location_children" returned %v for node %v`, *fk, n.ID) - } - assign(node, n) - } - return nil -} -func (_q *LocationQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []*Location, init func(*Location), assign func(*Location, *Item)) error { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[uuid.UUID]*Location) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - if init != nil { - init(nodes[i]) - } - } - query.withFKs = true - query.Where(predicate.Item(func(s *sql.Selector) { - s.Where(sql.InValues(s.C(location.ItemsColumn), fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - fk := n.location_items - if fk == nil { - return fmt.Errorf(`foreign-key "location_items" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "location_items" returned %v for node %v`, *fk, n.ID) - } - assign(node, n) - } - return nil -} - -func (_q *LocationQuery) sqlCount(ctx context.Context) (int, error) { - _spec := _q.querySpec() - _spec.Node.Columns = _q.ctx.Fields - if len(_q.ctx.Fields) > 0 { - _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique - } - return sqlgraph.CountNodes(ctx, _q.driver, _spec) -} - -func (_q *LocationQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(location.Table, location.Columns, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID)) - _spec.From = _q.sql - if unique := _q.ctx.Unique; unique != nil { - _spec.Unique = *unique - } else if _q.path != nil { - _spec.Unique = true - } - if fields := _q.ctx.Fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, location.FieldID) - for i := range fields { - if fields[i] != location.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := _q.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := _q.ctx.Limit; limit != nil { - _spec.Limit = *limit - } - if offset := _q.ctx.Offset; offset != nil { - _spec.Offset = *offset - } - if ps := _q.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (_q *LocationQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(_q.driver.Dialect()) - t1 := builder.Table(location.Table) - columns := _q.ctx.Fields - if len(columns) == 0 { - columns = location.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if _q.sql != nil { - selector = _q.sql - selector.Select(selector.Columns(columns...)...) - } - if _q.ctx.Unique != nil && *_q.ctx.Unique { - selector.Distinct() - } - for _, p := range _q.predicates { - p(selector) - } - for _, p := range _q.order { - p(selector) - } - if offset := _q.ctx.Offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := _q.ctx.Limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// LocationGroupBy is the group-by builder for Location entities. -type LocationGroupBy struct { - selector - build *LocationQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (_g *LocationGroupBy) Aggregate(fns ...AggregateFunc) *LocationGroupBy { - _g.fns = append(_g.fns, fns...) - return _g -} - -// Scan applies the selector query and scans the result into the given value. -func (_g *LocationGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) - if err := _g.build.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*LocationQuery, *LocationGroupBy](ctx, _g.build, _g, _g.build.inters, v) -} - -func (_g *LocationGroupBy) sqlScan(ctx context.Context, root *LocationQuery, v any) error { - selector := root.sqlQuery(ctx).Select() - aggregation := make([]string, 0, len(_g.fns)) - for _, fn := range _g.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) - for _, f := range *_g.flds { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - selector.GroupBy(selector.Columns(*_g.flds...)...) - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -// LocationSelect is the builder for selecting fields of Location entities. -type LocationSelect struct { - *LocationQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (_s *LocationSelect) Aggregate(fns ...AggregateFunc) *LocationSelect { - _s.fns = append(_s.fns, fns...) - return _s -} - -// Scan applies the selector query and scans the result into the given value. -func (_s *LocationSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) - if err := _s.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*LocationQuery, *LocationSelect](ctx, _s.LocationQuery, _s, _s.inters, v) -} - -func (_s *LocationSelect) sqlScan(ctx context.Context, root *LocationQuery, v any) error { - selector := root.sqlQuery(ctx) - aggregation := make([]string, 0, len(_s.fns)) - for _, fn := range _s.fns { - aggregation = append(aggregation, fn(selector)) - } - switch n := len(*_s.selector.flds); { - case n == 0 && len(aggregation) > 0: - selector.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - selector.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := _s.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/backend/internal/data/ent/location_update.go b/backend/internal/data/ent/location_update.go deleted file mode 100644 index badd8bd0..00000000 --- a/backend/internal/data/ent/location_update.go +++ /dev/null @@ -1,867 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/google/uuid" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" -) - -// LocationUpdate is the builder for updating Location entities. -type LocationUpdate struct { - config - hooks []Hook - mutation *LocationMutation -} - -// Where appends a list predicates to the LocationUpdate builder. -func (_u *LocationUpdate) Where(ps ...predicate.Location) *LocationUpdate { - _u.mutation.Where(ps...) - return _u -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *LocationUpdate) SetUpdatedAt(v time.Time) *LocationUpdate { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetName sets the "name" field. -func (_u *LocationUpdate) SetName(v string) *LocationUpdate { - _u.mutation.SetName(v) - return _u -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_u *LocationUpdate) SetNillableName(v *string) *LocationUpdate { - if v != nil { - _u.SetName(*v) - } - return _u -} - -// SetDescription sets the "description" field. -func (_u *LocationUpdate) SetDescription(v string) *LocationUpdate { - _u.mutation.SetDescription(v) - return _u -} - -// SetNillableDescription sets the "description" field if the given value is not nil. -func (_u *LocationUpdate) SetNillableDescription(v *string) *LocationUpdate { - if v != nil { - _u.SetDescription(*v) - } - return _u -} - -// ClearDescription clears the value of the "description" field. -func (_u *LocationUpdate) ClearDescription() *LocationUpdate { - _u.mutation.ClearDescription() - return _u -} - -// SetGroupID sets the "group" edge to the Group entity by ID. -func (_u *LocationUpdate) SetGroupID(id uuid.UUID) *LocationUpdate { - _u.mutation.SetGroupID(id) - return _u -} - -// SetGroup sets the "group" edge to the Group entity. -func (_u *LocationUpdate) SetGroup(v *Group) *LocationUpdate { - return _u.SetGroupID(v.ID) -} - -// SetParentID sets the "parent" edge to the Location entity by ID. -func (_u *LocationUpdate) SetParentID(id uuid.UUID) *LocationUpdate { - _u.mutation.SetParentID(id) - return _u -} - -// SetNillableParentID sets the "parent" edge to the Location entity by ID if the given value is not nil. -func (_u *LocationUpdate) SetNillableParentID(id *uuid.UUID) *LocationUpdate { - if id != nil { - _u = _u.SetParentID(*id) - } - return _u -} - -// SetParent sets the "parent" edge to the Location entity. -func (_u *LocationUpdate) SetParent(v *Location) *LocationUpdate { - return _u.SetParentID(v.ID) -} - -// AddChildIDs adds the "children" edge to the Location entity by IDs. -func (_u *LocationUpdate) AddChildIDs(ids ...uuid.UUID) *LocationUpdate { - _u.mutation.AddChildIDs(ids...) - return _u -} - -// AddChildren adds the "children" edges to the Location entity. -func (_u *LocationUpdate) AddChildren(v ...*Location) *LocationUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddChildIDs(ids...) -} - -// AddItemIDs adds the "items" edge to the Item entity by IDs. -func (_u *LocationUpdate) AddItemIDs(ids ...uuid.UUID) *LocationUpdate { - _u.mutation.AddItemIDs(ids...) - return _u -} - -// AddItems adds the "items" edges to the Item entity. -func (_u *LocationUpdate) AddItems(v ...*Item) *LocationUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddItemIDs(ids...) -} - -// Mutation returns the LocationMutation object of the builder. -func (_u *LocationUpdate) Mutation() *LocationMutation { - return _u.mutation -} - -// ClearGroup clears the "group" edge to the Group entity. -func (_u *LocationUpdate) ClearGroup() *LocationUpdate { - _u.mutation.ClearGroup() - return _u -} - -// ClearParent clears the "parent" edge to the Location entity. -func (_u *LocationUpdate) ClearParent() *LocationUpdate { - _u.mutation.ClearParent() - return _u -} - -// ClearChildren clears all "children" edges to the Location entity. -func (_u *LocationUpdate) ClearChildren() *LocationUpdate { - _u.mutation.ClearChildren() - return _u -} - -// RemoveChildIDs removes the "children" edge to Location entities by IDs. -func (_u *LocationUpdate) RemoveChildIDs(ids ...uuid.UUID) *LocationUpdate { - _u.mutation.RemoveChildIDs(ids...) - return _u -} - -// RemoveChildren removes "children" edges to Location entities. -func (_u *LocationUpdate) RemoveChildren(v ...*Location) *LocationUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveChildIDs(ids...) -} - -// ClearItems clears all "items" edges to the Item entity. -func (_u *LocationUpdate) ClearItems() *LocationUpdate { - _u.mutation.ClearItems() - return _u -} - -// RemoveItemIDs removes the "items" edge to Item entities by IDs. -func (_u *LocationUpdate) RemoveItemIDs(ids ...uuid.UUID) *LocationUpdate { - _u.mutation.RemoveItemIDs(ids...) - return _u -} - -// RemoveItems removes "items" edges to Item entities. -func (_u *LocationUpdate) RemoveItems(v ...*Item) *LocationUpdate { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveItemIDs(ids...) -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (_u *LocationUpdate) Save(ctx context.Context) (int, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *LocationUpdate) SaveX(ctx context.Context) int { - affected, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (_u *LocationUpdate) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *LocationUpdate) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *LocationUpdate) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := location.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_u *LocationUpdate) check() error { - if v, ok := _u.mutation.Name(); ok { - if err := location.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Location.name": %w`, err)} - } - } - if v, ok := _u.mutation.Description(); ok { - if err := location.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Location.description": %w`, err)} - } - } - if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 { - return errors.New(`ent: clearing a required unique edge "Location.group"`) - } - return nil -} - -func (_u *LocationUpdate) sqlSave(ctx context.Context) (_node int, err error) { - if err := _u.check(); err != nil { - return _node, err - } - _spec := sqlgraph.NewUpdateSpec(location.Table, location.Columns, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID)) - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(location.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Name(); ok { - _spec.SetField(location.FieldName, field.TypeString, value) - } - if value, ok := _u.mutation.Description(); ok { - _spec.SetField(location.FieldDescription, field.TypeString, value) - } - if _u.mutation.DescriptionCleared() { - _spec.ClearField(location.FieldDescription, field.TypeString) - } - if _u.mutation.GroupCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: location.GroupTable, - Columns: []string{location.GroupColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: location.GroupTable, - Columns: []string{location.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) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.ParentCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: location.ParentTable, - Columns: []string{location.ParentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: location.ParentTable, - Columns: []string{location.ParentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.ChildrenCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ChildrenTable, - Columns: []string{location.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ChildrenTable, - Columns: []string{location.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.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 := _u.mutation.ChildrenIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ChildrenTable, - Columns: []string{location.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.ItemsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ItemsTable, - Columns: []string{location.ItemsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedItemsIDs(); len(nodes) > 0 && !_u.mutation.ItemsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ItemsTable, - Columns: []string{location.ItemsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.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 := _u.mutation.ItemsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ItemsTable, - Columns: []string{location.ItemsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{location.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - _u.mutation.done = true - return _node, nil -} - -// LocationUpdateOne is the builder for updating a single Location entity. -type LocationUpdateOne struct { - config - fields []string - hooks []Hook - mutation *LocationMutation -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *LocationUpdateOne) SetUpdatedAt(v time.Time) *LocationUpdateOne { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetName sets the "name" field. -func (_u *LocationUpdateOne) SetName(v string) *LocationUpdateOne { - _u.mutation.SetName(v) - return _u -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_u *LocationUpdateOne) SetNillableName(v *string) *LocationUpdateOne { - if v != nil { - _u.SetName(*v) - } - return _u -} - -// SetDescription sets the "description" field. -func (_u *LocationUpdateOne) SetDescription(v string) *LocationUpdateOne { - _u.mutation.SetDescription(v) - return _u -} - -// SetNillableDescription sets the "description" field if the given value is not nil. -func (_u *LocationUpdateOne) SetNillableDescription(v *string) *LocationUpdateOne { - if v != nil { - _u.SetDescription(*v) - } - return _u -} - -// ClearDescription clears the value of the "description" field. -func (_u *LocationUpdateOne) ClearDescription() *LocationUpdateOne { - _u.mutation.ClearDescription() - return _u -} - -// SetGroupID sets the "group" edge to the Group entity by ID. -func (_u *LocationUpdateOne) SetGroupID(id uuid.UUID) *LocationUpdateOne { - _u.mutation.SetGroupID(id) - return _u -} - -// SetGroup sets the "group" edge to the Group entity. -func (_u *LocationUpdateOne) SetGroup(v *Group) *LocationUpdateOne { - return _u.SetGroupID(v.ID) -} - -// SetParentID sets the "parent" edge to the Location entity by ID. -func (_u *LocationUpdateOne) SetParentID(id uuid.UUID) *LocationUpdateOne { - _u.mutation.SetParentID(id) - return _u -} - -// SetNillableParentID sets the "parent" edge to the Location entity by ID if the given value is not nil. -func (_u *LocationUpdateOne) SetNillableParentID(id *uuid.UUID) *LocationUpdateOne { - if id != nil { - _u = _u.SetParentID(*id) - } - return _u -} - -// SetParent sets the "parent" edge to the Location entity. -func (_u *LocationUpdateOne) SetParent(v *Location) *LocationUpdateOne { - return _u.SetParentID(v.ID) -} - -// AddChildIDs adds the "children" edge to the Location entity by IDs. -func (_u *LocationUpdateOne) AddChildIDs(ids ...uuid.UUID) *LocationUpdateOne { - _u.mutation.AddChildIDs(ids...) - return _u -} - -// AddChildren adds the "children" edges to the Location entity. -func (_u *LocationUpdateOne) AddChildren(v ...*Location) *LocationUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddChildIDs(ids...) -} - -// AddItemIDs adds the "items" edge to the Item entity by IDs. -func (_u *LocationUpdateOne) AddItemIDs(ids ...uuid.UUID) *LocationUpdateOne { - _u.mutation.AddItemIDs(ids...) - return _u -} - -// AddItems adds the "items" edges to the Item entity. -func (_u *LocationUpdateOne) AddItems(v ...*Item) *LocationUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddItemIDs(ids...) -} - -// Mutation returns the LocationMutation object of the builder. -func (_u *LocationUpdateOne) Mutation() *LocationMutation { - return _u.mutation -} - -// ClearGroup clears the "group" edge to the Group entity. -func (_u *LocationUpdateOne) ClearGroup() *LocationUpdateOne { - _u.mutation.ClearGroup() - return _u -} - -// ClearParent clears the "parent" edge to the Location entity. -func (_u *LocationUpdateOne) ClearParent() *LocationUpdateOne { - _u.mutation.ClearParent() - return _u -} - -// ClearChildren clears all "children" edges to the Location entity. -func (_u *LocationUpdateOne) ClearChildren() *LocationUpdateOne { - _u.mutation.ClearChildren() - return _u -} - -// RemoveChildIDs removes the "children" edge to Location entities by IDs. -func (_u *LocationUpdateOne) RemoveChildIDs(ids ...uuid.UUID) *LocationUpdateOne { - _u.mutation.RemoveChildIDs(ids...) - return _u -} - -// RemoveChildren removes "children" edges to Location entities. -func (_u *LocationUpdateOne) RemoveChildren(v ...*Location) *LocationUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveChildIDs(ids...) -} - -// ClearItems clears all "items" edges to the Item entity. -func (_u *LocationUpdateOne) ClearItems() *LocationUpdateOne { - _u.mutation.ClearItems() - return _u -} - -// RemoveItemIDs removes the "items" edge to Item entities by IDs. -func (_u *LocationUpdateOne) RemoveItemIDs(ids ...uuid.UUID) *LocationUpdateOne { - _u.mutation.RemoveItemIDs(ids...) - return _u -} - -// RemoveItems removes "items" edges to Item entities. -func (_u *LocationUpdateOne) RemoveItems(v ...*Item) *LocationUpdateOne { - ids := make([]uuid.UUID, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveItemIDs(ids...) -} - -// Where appends a list predicates to the LocationUpdate builder. -func (_u *LocationUpdateOne) Where(ps ...predicate.Location) *LocationUpdateOne { - _u.mutation.Where(ps...) - return _u -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (_u *LocationUpdateOne) Select(field string, fields ...string) *LocationUpdateOne { - _u.fields = append([]string{field}, fields...) - return _u -} - -// Save executes the query and returns the updated Location entity. -func (_u *LocationUpdateOne) Save(ctx context.Context) (*Location, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *LocationUpdateOne) SaveX(ctx context.Context) *Location { - node, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (_u *LocationUpdateOne) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *LocationUpdateOne) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *LocationUpdateOne) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := location.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_u *LocationUpdateOne) check() error { - if v, ok := _u.mutation.Name(); ok { - if err := location.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Location.name": %w`, err)} - } - } - if v, ok := _u.mutation.Description(); ok { - if err := location.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Location.description": %w`, err)} - } - } - if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 { - return errors.New(`ent: clearing a required unique edge "Location.group"`) - } - return nil -} - -func (_u *LocationUpdateOne) sqlSave(ctx context.Context) (_node *Location, err error) { - if err := _u.check(); err != nil { - return _node, err - } - _spec := sqlgraph.NewUpdateSpec(location.Table, location.Columns, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID)) - id, ok := _u.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Location.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := _u.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, location.FieldID) - for _, f := range fields { - if !location.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != location.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(location.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Name(); ok { - _spec.SetField(location.FieldName, field.TypeString, value) - } - if value, ok := _u.mutation.Description(); ok { - _spec.SetField(location.FieldDescription, field.TypeString, value) - } - if _u.mutation.DescriptionCleared() { - _spec.ClearField(location.FieldDescription, field.TypeString) - } - if _u.mutation.GroupCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: location.GroupTable, - Columns: []string{location.GroupColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: location.GroupTable, - Columns: []string{location.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) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.ParentCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: location.ParentTable, - Columns: []string{location.ParentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: location.ParentTable, - Columns: []string{location.ParentColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.ChildrenCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ChildrenTable, - Columns: []string{location.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ChildrenTable, - Columns: []string{location.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.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 := _u.mutation.ChildrenIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ChildrenTable, - Columns: []string{location.ChildrenColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.ItemsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ItemsTable, - Columns: []string{location.ItemsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedItemsIDs(); len(nodes) > 0 && !_u.mutation.ItemsCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ItemsTable, - Columns: []string{location.ItemsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.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 := _u.mutation.ItemsIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: location.ItemsTable, - Columns: []string{location.ItemsColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &Location{config: _u.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{location.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - _u.mutation.done = true - return _node, nil -}