2022-08-30 18:04:50 +00:00
|
|
|
// 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"
|
2022-10-30 04:05:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
2023-03-07 06:18:58 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/notifier"
|
2022-10-30 04:05:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
2022-08-30 18:04:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GroupCreate is the builder for creating a Group entity.
|
|
|
|
type GroupCreate struct {
|
|
|
|
config
|
|
|
|
mutation *GroupMutation
|
|
|
|
hooks []Hook
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
|
|
func (gc *GroupCreate) SetCreatedAt(t time.Time) *GroupCreate {
|
|
|
|
gc.mutation.SetCreatedAt(t)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
|
|
func (gc *GroupCreate) SetNillableCreatedAt(t *time.Time) *GroupCreate {
|
|
|
|
if t != nil {
|
|
|
|
gc.SetCreatedAt(*t)
|
|
|
|
}
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
|
|
func (gc *GroupCreate) SetUpdatedAt(t time.Time) *GroupCreate {
|
|
|
|
gc.mutation.SetUpdatedAt(t)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
|
|
func (gc *GroupCreate) SetNillableUpdatedAt(t *time.Time) *GroupCreate {
|
|
|
|
if t != nil {
|
|
|
|
gc.SetUpdatedAt(*t)
|
|
|
|
}
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetName sets the "name" field.
|
|
|
|
func (gc *GroupCreate) SetName(s string) *GroupCreate {
|
|
|
|
gc.mutation.SetName(s)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCurrency sets the "currency" field.
|
2024-01-05 17:35:50 +00:00
|
|
|
func (gc *GroupCreate) SetCurrency(s string) *GroupCreate {
|
|
|
|
gc.mutation.SetCurrency(s)
|
2022-08-30 18:04:50 +00:00
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNillableCurrency sets the "currency" field if the given value is not nil.
|
2024-01-05 17:35:50 +00:00
|
|
|
func (gc *GroupCreate) SetNillableCurrency(s *string) *GroupCreate {
|
|
|
|
if s != nil {
|
|
|
|
gc.SetCurrency(*s)
|
2022-08-30 18:04:50 +00:00
|
|
|
}
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetID sets the "id" field.
|
|
|
|
func (gc *GroupCreate) SetID(u uuid.UUID) *GroupCreate {
|
|
|
|
gc.mutation.SetID(u)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNillableID sets the "id" field if the given value is not nil.
|
|
|
|
func (gc *GroupCreate) SetNillableID(u *uuid.UUID) *GroupCreate {
|
|
|
|
if u != nil {
|
|
|
|
gc.SetID(*u)
|
|
|
|
}
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddUserIDs adds the "users" edge to the User entity by IDs.
|
|
|
|
func (gc *GroupCreate) AddUserIDs(ids ...uuid.UUID) *GroupCreate {
|
|
|
|
gc.mutation.AddUserIDs(ids...)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddUsers adds the "users" edges to the User entity.
|
|
|
|
func (gc *GroupCreate) AddUsers(u ...*User) *GroupCreate {
|
|
|
|
ids := make([]uuid.UUID, len(u))
|
|
|
|
for i := range u {
|
|
|
|
ids[i] = u[i].ID
|
|
|
|
}
|
|
|
|
return gc.AddUserIDs(ids...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddLocationIDs adds the "locations" edge to the Location entity by IDs.
|
|
|
|
func (gc *GroupCreate) AddLocationIDs(ids ...uuid.UUID) *GroupCreate {
|
|
|
|
gc.mutation.AddLocationIDs(ids...)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddLocations adds the "locations" edges to the Location entity.
|
|
|
|
func (gc *GroupCreate) AddLocations(l ...*Location) *GroupCreate {
|
|
|
|
ids := make([]uuid.UUID, len(l))
|
|
|
|
for i := range l {
|
|
|
|
ids[i] = l[i].ID
|
|
|
|
}
|
|
|
|
return gc.AddLocationIDs(ids...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddItemIDs adds the "items" edge to the Item entity by IDs.
|
|
|
|
func (gc *GroupCreate) AddItemIDs(ids ...uuid.UUID) *GroupCreate {
|
|
|
|
gc.mutation.AddItemIDs(ids...)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddItems adds the "items" edges to the Item entity.
|
|
|
|
func (gc *GroupCreate) AddItems(i ...*Item) *GroupCreate {
|
|
|
|
ids := make([]uuid.UUID, len(i))
|
|
|
|
for j := range i {
|
|
|
|
ids[j] = i[j].ID
|
|
|
|
}
|
|
|
|
return gc.AddItemIDs(ids...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddLabelIDs adds the "labels" edge to the Label entity by IDs.
|
|
|
|
func (gc *GroupCreate) AddLabelIDs(ids ...uuid.UUID) *GroupCreate {
|
|
|
|
gc.mutation.AddLabelIDs(ids...)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddLabels adds the "labels" edges to the Label entity.
|
|
|
|
func (gc *GroupCreate) AddLabels(l ...*Label) *GroupCreate {
|
|
|
|
ids := make([]uuid.UUID, len(l))
|
|
|
|
for i := range l {
|
|
|
|
ids[i] = l[i].ID
|
|
|
|
}
|
|
|
|
return gc.AddLabelIDs(ids...)
|
|
|
|
}
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
// AddDocumentIDs adds the "documents" edge to the Document entity by IDs.
|
|
|
|
func (gc *GroupCreate) AddDocumentIDs(ids ...uuid.UUID) *GroupCreate {
|
|
|
|
gc.mutation.AddDocumentIDs(ids...)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddDocuments adds the "documents" edges to the Document entity.
|
|
|
|
func (gc *GroupCreate) AddDocuments(d ...*Document) *GroupCreate {
|
|
|
|
ids := make([]uuid.UUID, len(d))
|
|
|
|
for i := range d {
|
|
|
|
ids[i] = d[i].ID
|
|
|
|
}
|
|
|
|
return gc.AddDocumentIDs(ids...)
|
|
|
|
}
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
// AddInvitationTokenIDs adds the "invitation_tokens" edge to the GroupInvitationToken entity by IDs.
|
|
|
|
func (gc *GroupCreate) AddInvitationTokenIDs(ids ...uuid.UUID) *GroupCreate {
|
|
|
|
gc.mutation.AddInvitationTokenIDs(ids...)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddInvitationTokens adds the "invitation_tokens" edges to the GroupInvitationToken entity.
|
|
|
|
func (gc *GroupCreate) AddInvitationTokens(g ...*GroupInvitationToken) *GroupCreate {
|
|
|
|
ids := make([]uuid.UUID, len(g))
|
|
|
|
for i := range g {
|
|
|
|
ids[i] = g[i].ID
|
|
|
|
}
|
|
|
|
return gc.AddInvitationTokenIDs(ids...)
|
|
|
|
}
|
|
|
|
|
2023-03-07 06:18:58 +00:00
|
|
|
// AddNotifierIDs adds the "notifiers" edge to the Notifier entity by IDs.
|
|
|
|
func (gc *GroupCreate) AddNotifierIDs(ids ...uuid.UUID) *GroupCreate {
|
|
|
|
gc.mutation.AddNotifierIDs(ids...)
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddNotifiers adds the "notifiers" edges to the Notifier entity.
|
|
|
|
func (gc *GroupCreate) AddNotifiers(n ...*Notifier) *GroupCreate {
|
|
|
|
ids := make([]uuid.UUID, len(n))
|
|
|
|
for i := range n {
|
|
|
|
ids[i] = n[i].ID
|
|
|
|
}
|
|
|
|
return gc.AddNotifierIDs(ids...)
|
|
|
|
}
|
|
|
|
|
2022-08-30 18:04:50 +00:00
|
|
|
// Mutation returns the GroupMutation object of the builder.
|
|
|
|
func (gc *GroupCreate) Mutation() *GroupMutation {
|
|
|
|
return gc.mutation
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save creates the Group in the database.
|
|
|
|
func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) {
|
|
|
|
gc.defaults()
|
2023-07-23 03:57:51 +00:00
|
|
|
return withHooks(ctx, gc.sqlSave, gc.mutation, gc.hooks)
|
2022-08-30 18:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
|
|
func (gc *GroupCreate) SaveX(ctx context.Context) *Group {
|
|
|
|
v, err := gc.Save(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exec executes the query.
|
|
|
|
func (gc *GroupCreate) Exec(ctx context.Context) error {
|
|
|
|
_, err := gc.Save(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
func (gc *GroupCreate) ExecX(ctx context.Context) {
|
|
|
|
if err := gc.Exec(ctx); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
|
|
func (gc *GroupCreate) defaults() {
|
|
|
|
if _, ok := gc.mutation.CreatedAt(); !ok {
|
|
|
|
v := group.DefaultCreatedAt()
|
|
|
|
gc.mutation.SetCreatedAt(v)
|
|
|
|
}
|
|
|
|
if _, ok := gc.mutation.UpdatedAt(); !ok {
|
|
|
|
v := group.DefaultUpdatedAt()
|
|
|
|
gc.mutation.SetUpdatedAt(v)
|
|
|
|
}
|
|
|
|
if _, ok := gc.mutation.Currency(); !ok {
|
|
|
|
v := group.DefaultCurrency
|
|
|
|
gc.mutation.SetCurrency(v)
|
|
|
|
}
|
|
|
|
if _, ok := gc.mutation.ID(); !ok {
|
|
|
|
v := group.DefaultID()
|
|
|
|
gc.mutation.SetID(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
|
|
func (gc *GroupCreate) check() error {
|
|
|
|
if _, ok := gc.mutation.CreatedAt(); !ok {
|
|
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Group.created_at"`)}
|
|
|
|
}
|
|
|
|
if _, ok := gc.mutation.UpdatedAt(); !ok {
|
|
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Group.updated_at"`)}
|
|
|
|
}
|
|
|
|
if _, ok := gc.mutation.Name(); !ok {
|
|
|
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Group.name"`)}
|
|
|
|
}
|
|
|
|
if v, ok := gc.mutation.Name(); ok {
|
|
|
|
if err := group.NameValidator(v); err != nil {
|
|
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Group.name": %w`, err)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, ok := gc.mutation.Currency(); !ok {
|
|
|
|
return &ValidationError{Name: "currency", err: errors.New(`ent: missing required field "Group.currency"`)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) {
|
2023-01-19 05:44:06 +00:00
|
|
|
if err := gc.check(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-30 18:04:50 +00:00
|
|
|
_node, _spec := gc.createSpec()
|
|
|
|
if err := sqlgraph.CreateNode(ctx, gc.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
|
|
|
|
}
|
|
|
|
}
|
2023-01-19 05:44:06 +00:00
|
|
|
gc.mutation.id = &_node.ID
|
|
|
|
gc.mutation.done = true
|
2022-08-30 18:04:50 +00:00
|
|
|
return _node, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
|
|
|
|
var (
|
|
|
|
_node = &Group{config: gc.config}
|
2023-02-18 06:41:01 +00:00
|
|
|
_spec = sqlgraph.NewCreateSpec(group.Table, sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID))
|
2022-08-30 18:04:50 +00:00
|
|
|
)
|
|
|
|
if id, ok := gc.mutation.ID(); ok {
|
|
|
|
_node.ID = id
|
|
|
|
_spec.ID.Value = &id
|
|
|
|
}
|
|
|
|
if value, ok := gc.mutation.CreatedAt(); ok {
|
2022-12-02 01:45:28 +00:00
|
|
|
_spec.SetField(group.FieldCreatedAt, field.TypeTime, value)
|
2022-08-30 18:04:50 +00:00
|
|
|
_node.CreatedAt = value
|
|
|
|
}
|
|
|
|
if value, ok := gc.mutation.UpdatedAt(); ok {
|
2022-12-02 01:45:28 +00:00
|
|
|
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
|
2022-08-30 18:04:50 +00:00
|
|
|
_node.UpdatedAt = value
|
|
|
|
}
|
|
|
|
if value, ok := gc.mutation.Name(); ok {
|
2022-12-02 01:45:28 +00:00
|
|
|
_spec.SetField(group.FieldName, field.TypeString, value)
|
2022-08-30 18:04:50 +00:00
|
|
|
_node.Name = value
|
|
|
|
}
|
|
|
|
if value, ok := gc.mutation.Currency(); ok {
|
2024-01-05 17:35:50 +00:00
|
|
|
_spec.SetField(group.FieldCurrency, field.TypeString, value)
|
2022-08-30 18:04:50 +00:00
|
|
|
_node.Currency = value
|
|
|
|
}
|
|
|
|
if nodes := gc.mutation.UsersIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: group.UsersTable,
|
|
|
|
Columns: []string{group.UsersColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2023-03-23 04:49:49 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
2022-08-30 18:04:50 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
|
|
|
if nodes := gc.mutation.LocationsIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: group.LocationsTable,
|
|
|
|
Columns: []string{group.LocationsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2023-03-23 04:49:49 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID),
|
2022-08-30 18:04:50 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
|
|
|
if nodes := gc.mutation.ItemsIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: group.ItemsTable,
|
|
|
|
Columns: []string{group.ItemsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2023-03-23 04:49:49 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
2022-08-30 18:04:50 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
|
|
|
if nodes := gc.mutation.LabelsIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: group.LabelsTable,
|
|
|
|
Columns: []string{group.LabelsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2023-03-23 04:49:49 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID),
|
2022-08-30 18:04:50 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
2022-09-12 22:47:27 +00:00
|
|
|
if nodes := gc.mutation.DocumentsIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: group.DocumentsTable,
|
|
|
|
Columns: []string{group.DocumentsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2023-03-23 04:49:49 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeUUID),
|
2022-09-12 22:47:27 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
2022-10-07 02:54:09 +00:00
|
|
|
if nodes := gc.mutation.InvitationTokensIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: group.InvitationTokensTable,
|
|
|
|
Columns: []string{group.InvitationTokensColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2023-03-23 04:49:49 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(groupinvitationtoken.FieldID, field.TypeUUID),
|
2022-10-07 02:54:09 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
2023-03-07 06:18:58 +00:00
|
|
|
if nodes := gc.mutation.NotifiersIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: group.NotifiersTable,
|
|
|
|
Columns: []string{group.NotifiersColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
2023-03-23 04:49:49 +00:00
|
|
|
IDSpec: sqlgraph.NewFieldSpec(notifier.FieldID, field.TypeUUID),
|
2023-03-07 06:18:58 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
|
|
}
|
2022-08-30 18:04:50 +00:00
|
|
|
return _node, _spec
|
|
|
|
}
|
|
|
|
|
|
|
|
// GroupCreateBulk is the builder for creating many Group entities in bulk.
|
|
|
|
type GroupCreateBulk struct {
|
|
|
|
config
|
2023-11-16 02:30:49 +00:00
|
|
|
err error
|
2022-08-30 18:04:50 +00:00
|
|
|
builders []*GroupCreate
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save creates the Group entities in the database.
|
|
|
|
func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) {
|
2023-11-16 02:30:49 +00:00
|
|
|
if gcb.err != nil {
|
|
|
|
return nil, gcb.err
|
|
|
|
}
|
2022-08-30 18:04:50 +00:00
|
|
|
specs := make([]*sqlgraph.CreateSpec, len(gcb.builders))
|
|
|
|
nodes := make([]*Group, len(gcb.builders))
|
|
|
|
mutators := make([]Mutator, len(gcb.builders))
|
|
|
|
for i := range gcb.builders {
|
|
|
|
func(i int, root context.Context) {
|
|
|
|
builder := gcb.builders[i]
|
|
|
|
builder.defaults()
|
|
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
|
|
mutation, ok := m.(*GroupMutation)
|
|
|
|
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
|
2023-07-23 03:57:51 +00:00
|
|
|
nodes[i], specs[i] = builder.createSpec()
|
2022-08-30 18:04:50 +00:00
|
|
|
if i < len(mutators)-1 {
|
|
|
|
_, err = mutators[i+1].Mutate(root, gcb.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, gcb.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, gcb.builders[0].mutation); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodes, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
|
|
func (gcb *GroupCreateBulk) SaveX(ctx context.Context) []*Group {
|
|
|
|
v, err := gcb.Save(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exec executes the query.
|
|
|
|
func (gcb *GroupCreateBulk) Exec(ctx context.Context) error {
|
|
|
|
_, err := gcb.Save(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
func (gcb *GroupCreateBulk) ExecX(ctx context.Context) {
|
|
|
|
if err := gcb.Exec(ctx); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|