Skip to main content
Glama

Storyden

by Southclaws
Mozilla Public License 2.0
227
eventparticipant_create.go23.5 kB
// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/Southclaws/storyden/internal/ent/account" "github.com/Southclaws/storyden/internal/ent/event" "github.com/Southclaws/storyden/internal/ent/eventparticipant" "github.com/rs/xid" ) // EventParticipantCreate is the builder for creating a EventParticipant entity. type EventParticipantCreate struct { config mutation *EventParticipantMutation hooks []Hook conflict []sql.ConflictOption } // SetCreatedAt sets the "created_at" field. func (_c *EventParticipantCreate) SetCreatedAt(v time.Time) *EventParticipantCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *EventParticipantCreate) SetNillableCreatedAt(v *time.Time) *EventParticipantCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetRole sets the "role" field. func (_c *EventParticipantCreate) SetRole(v string) *EventParticipantCreate { _c.mutation.SetRole(v) return _c } // SetStatus sets the "status" field. func (_c *EventParticipantCreate) SetStatus(v string) *EventParticipantCreate { _c.mutation.SetStatus(v) return _c } // SetAccountID sets the "account_id" field. func (_c *EventParticipantCreate) SetAccountID(v xid.ID) *EventParticipantCreate { _c.mutation.SetAccountID(v) return _c } // SetEventID sets the "event_id" field. func (_c *EventParticipantCreate) SetEventID(v xid.ID) *EventParticipantCreate { _c.mutation.SetEventID(v) return _c } // SetID sets the "id" field. func (_c *EventParticipantCreate) SetID(v xid.ID) *EventParticipantCreate { _c.mutation.SetID(v) return _c } // SetNillableID sets the "id" field if the given value is not nil. func (_c *EventParticipantCreate) SetNillableID(v *xid.ID) *EventParticipantCreate { if v != nil { _c.SetID(*v) } return _c } // SetAccount sets the "account" edge to the Account entity. func (_c *EventParticipantCreate) SetAccount(v *Account) *EventParticipantCreate { return _c.SetAccountID(v.ID) } // SetEvent sets the "event" edge to the Event entity. func (_c *EventParticipantCreate) SetEvent(v *Event) *EventParticipantCreate { return _c.SetEventID(v.ID) } // Mutation returns the EventParticipantMutation object of the builder. func (_c *EventParticipantCreate) Mutation() *EventParticipantMutation { return _c.mutation } // Save creates the EventParticipant in the database. func (_c *EventParticipantCreate) Save(ctx context.Context) (*EventParticipant, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *EventParticipantCreate) SaveX(ctx context.Context) *EventParticipant { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *EventParticipantCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *EventParticipantCreate) 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 *EventParticipantCreate) defaults() { if _, ok := _c.mutation.CreatedAt(); !ok { v := eventparticipant.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.ID(); !ok { v := eventparticipant.DefaultID() _c.mutation.SetID(v) } } // check runs all checks and user-defined validators on the builder. func (_c *EventParticipantCreate) check() error { if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "EventParticipant.created_at"`)} } if _, ok := _c.mutation.Role(); !ok { return &ValidationError{Name: "role", err: errors.New(`ent: missing required field "EventParticipant.role"`)} } if _, ok := _c.mutation.Status(); !ok { return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "EventParticipant.status"`)} } if _, ok := _c.mutation.AccountID(); !ok { return &ValidationError{Name: "account_id", err: errors.New(`ent: missing required field "EventParticipant.account_id"`)} } if _, ok := _c.mutation.EventID(); !ok { return &ValidationError{Name: "event_id", err: errors.New(`ent: missing required field "EventParticipant.event_id"`)} } if v, ok := _c.mutation.ID(); ok { if err := eventparticipant.IDValidator(v.String()); err != nil { return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "EventParticipant.id": %w`, err)} } } if len(_c.mutation.AccountIDs()) == 0 { return &ValidationError{Name: "account", err: errors.New(`ent: missing required edge "EventParticipant.account"`)} } if len(_c.mutation.EventIDs()) == 0 { return &ValidationError{Name: "event", err: errors.New(`ent: missing required edge "EventParticipant.event"`)} } return nil } func (_c *EventParticipantCreate) sqlSave(ctx context.Context) (*EventParticipant, 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.(*xid.ID); 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 *EventParticipantCreate) createSpec() (*EventParticipant, *sqlgraph.CreateSpec) { var ( _node = &EventParticipant{config: _c.config} _spec = sqlgraph.NewCreateSpec(eventparticipant.Table, sqlgraph.NewFieldSpec(eventparticipant.FieldID, field.TypeString)) ) _spec.OnConflict = _c.conflict if id, ok := _c.mutation.ID(); ok { _node.ID = id _spec.ID.Value = &id } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(eventparticipant.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.Role(); ok { _spec.SetField(eventparticipant.FieldRole, field.TypeString, value) _node.Role = value } if value, ok := _c.mutation.Status(); ok { _spec.SetField(eventparticipant.FieldStatus, field.TypeString, value) _node.Status = value } if nodes := _c.mutation.AccountIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: eventparticipant.AccountTable, Columns: []string{eventparticipant.AccountColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.AccountID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.EventIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: eventparticipant.EventTable, Columns: []string{eventparticipant.EventColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(event.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.EventID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.EventParticipant.Create(). // SetCreatedAt(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. // sql.ResolveWithNewValues(), // ). // // Override some of the fields with custom // // update values. // Update(func(u *ent.EventParticipantUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *EventParticipantCreate) OnConflict(opts ...sql.ConflictOption) *EventParticipantUpsertOne { _c.conflict = opts return &EventParticipantUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.EventParticipant.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *EventParticipantCreate) OnConflictColumns(columns ...string) *EventParticipantUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &EventParticipantUpsertOne{ create: _c, } } type ( // EventParticipantUpsertOne is the builder for "upsert"-ing // one EventParticipant node. EventParticipantUpsertOne struct { create *EventParticipantCreate } // EventParticipantUpsert is the "OnConflict" setter. EventParticipantUpsert struct { *sql.UpdateSet } ) // SetRole sets the "role" field. func (u *EventParticipantUpsert) SetRole(v string) *EventParticipantUpsert { u.Set(eventparticipant.FieldRole, v) return u } // UpdateRole sets the "role" field to the value that was provided on create. func (u *EventParticipantUpsert) UpdateRole() *EventParticipantUpsert { u.SetExcluded(eventparticipant.FieldRole) return u } // SetStatus sets the "status" field. func (u *EventParticipantUpsert) SetStatus(v string) *EventParticipantUpsert { u.Set(eventparticipant.FieldStatus, v) return u } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *EventParticipantUpsert) UpdateStatus() *EventParticipantUpsert { u.SetExcluded(eventparticipant.FieldStatus) return u } // SetAccountID sets the "account_id" field. func (u *EventParticipantUpsert) SetAccountID(v xid.ID) *EventParticipantUpsert { u.Set(eventparticipant.FieldAccountID, v) return u } // UpdateAccountID sets the "account_id" field to the value that was provided on create. func (u *EventParticipantUpsert) UpdateAccountID() *EventParticipantUpsert { u.SetExcluded(eventparticipant.FieldAccountID) return u } // SetEventID sets the "event_id" field. func (u *EventParticipantUpsert) SetEventID(v xid.ID) *EventParticipantUpsert { u.Set(eventparticipant.FieldEventID, v) return u } // UpdateEventID sets the "event_id" field to the value that was provided on create. func (u *EventParticipantUpsert) UpdateEventID() *EventParticipantUpsert { u.SetExcluded(eventparticipant.FieldEventID) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. // Using this option is equivalent to using: // // client.EventParticipant.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(eventparticipant.FieldID) // }), // ). // Exec(ctx) func (u *EventParticipantUpsertOne) UpdateNewValues() *EventParticipantUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { if _, exists := u.create.mutation.ID(); exists { s.SetIgnore(eventparticipant.FieldID) } if _, exists := u.create.mutation.CreatedAt(); exists { s.SetIgnore(eventparticipant.FieldCreatedAt) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.EventParticipant.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *EventParticipantUpsertOne) Ignore() *EventParticipantUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u } // DoNothing configures the conflict_action to `DO NOTHING`. // Supported only by SQLite and PostgreSQL. func (u *EventParticipantUpsertOne) DoNothing() *EventParticipantUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the EventParticipantCreate.OnConflict // documentation for more info. func (u *EventParticipantUpsertOne) Update(set func(*EventParticipantUpsert)) *EventParticipantUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&EventParticipantUpsert{UpdateSet: update}) })) return u } // SetRole sets the "role" field. func (u *EventParticipantUpsertOne) SetRole(v string) *EventParticipantUpsertOne { return u.Update(func(s *EventParticipantUpsert) { s.SetRole(v) }) } // UpdateRole sets the "role" field to the value that was provided on create. func (u *EventParticipantUpsertOne) UpdateRole() *EventParticipantUpsertOne { return u.Update(func(s *EventParticipantUpsert) { s.UpdateRole() }) } // SetStatus sets the "status" field. func (u *EventParticipantUpsertOne) SetStatus(v string) *EventParticipantUpsertOne { return u.Update(func(s *EventParticipantUpsert) { s.SetStatus(v) }) } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *EventParticipantUpsertOne) UpdateStatus() *EventParticipantUpsertOne { return u.Update(func(s *EventParticipantUpsert) { s.UpdateStatus() }) } // SetAccountID sets the "account_id" field. func (u *EventParticipantUpsertOne) SetAccountID(v xid.ID) *EventParticipantUpsertOne { return u.Update(func(s *EventParticipantUpsert) { s.SetAccountID(v) }) } // UpdateAccountID sets the "account_id" field to the value that was provided on create. func (u *EventParticipantUpsertOne) UpdateAccountID() *EventParticipantUpsertOne { return u.Update(func(s *EventParticipantUpsert) { s.UpdateAccountID() }) } // SetEventID sets the "event_id" field. func (u *EventParticipantUpsertOne) SetEventID(v xid.ID) *EventParticipantUpsertOne { return u.Update(func(s *EventParticipantUpsert) { s.SetEventID(v) }) } // UpdateEventID sets the "event_id" field to the value that was provided on create. func (u *EventParticipantUpsertOne) UpdateEventID() *EventParticipantUpsertOne { return u.Update(func(s *EventParticipantUpsert) { s.UpdateEventID() }) } // Exec executes the query. func (u *EventParticipantUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for EventParticipantCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *EventParticipantUpsertOne) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } } // Exec executes the UPSERT query and returns the inserted/updated ID. func (u *EventParticipantUpsertOne) ID(ctx context.Context) (id xid.ID, err error) { if u.create.driver.Dialect() == dialect.MySQL { // In case of "ON CONFLICT", there is no way to get back non-numeric ID // fields from the database since MySQL does not support the RETURNING clause. return id, errors.New("ent: EventParticipantUpsertOne.ID is not supported by MySQL driver. Use EventParticipantUpsertOne.Exec instead") } node, err := u.create.Save(ctx) if err != nil { return id, err } return node.ID, nil } // IDX is like ID, but panics if an error occurs. func (u *EventParticipantUpsertOne) IDX(ctx context.Context) xid.ID { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // EventParticipantCreateBulk is the builder for creating many EventParticipant entities in bulk. type EventParticipantCreateBulk struct { config err error builders []*EventParticipantCreate conflict []sql.ConflictOption } // Save creates the EventParticipant entities in the database. func (_c *EventParticipantCreateBulk) Save(ctx context.Context) ([]*EventParticipant, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*EventParticipant, 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.(*EventParticipantMutation) 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} spec.OnConflict = _c.conflict // 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 *EventParticipantCreateBulk) SaveX(ctx context.Context) []*EventParticipant { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *EventParticipantCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *EventParticipantCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.EventParticipant.CreateBulk(builders...). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. // sql.ResolveWithNewValues(), // ). // // Override some of the fields with custom // // update values. // Update(func(u *ent.EventParticipantUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *EventParticipantCreateBulk) OnConflict(opts ...sql.ConflictOption) *EventParticipantUpsertBulk { _c.conflict = opts return &EventParticipantUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.EventParticipant.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *EventParticipantCreateBulk) OnConflictColumns(columns ...string) *EventParticipantUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &EventParticipantUpsertBulk{ create: _c, } } // EventParticipantUpsertBulk is the builder for "upsert"-ing // a bulk of EventParticipant nodes. type EventParticipantUpsertBulk struct { create *EventParticipantCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.EventParticipant.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(eventparticipant.FieldID) // }), // ). // Exec(ctx) func (u *EventParticipantUpsertBulk) UpdateNewValues() *EventParticipantUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { for _, b := range u.create.builders { if _, exists := b.mutation.ID(); exists { s.SetIgnore(eventparticipant.FieldID) } if _, exists := b.mutation.CreatedAt(); exists { s.SetIgnore(eventparticipant.FieldCreatedAt) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.EventParticipant.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *EventParticipantUpsertBulk) Ignore() *EventParticipantUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u } // DoNothing configures the conflict_action to `DO NOTHING`. // Supported only by SQLite and PostgreSQL. func (u *EventParticipantUpsertBulk) DoNothing() *EventParticipantUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the EventParticipantCreateBulk.OnConflict // documentation for more info. func (u *EventParticipantUpsertBulk) Update(set func(*EventParticipantUpsert)) *EventParticipantUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&EventParticipantUpsert{UpdateSet: update}) })) return u } // SetRole sets the "role" field. func (u *EventParticipantUpsertBulk) SetRole(v string) *EventParticipantUpsertBulk { return u.Update(func(s *EventParticipantUpsert) { s.SetRole(v) }) } // UpdateRole sets the "role" field to the value that was provided on create. func (u *EventParticipantUpsertBulk) UpdateRole() *EventParticipantUpsertBulk { return u.Update(func(s *EventParticipantUpsert) { s.UpdateRole() }) } // SetStatus sets the "status" field. func (u *EventParticipantUpsertBulk) SetStatus(v string) *EventParticipantUpsertBulk { return u.Update(func(s *EventParticipantUpsert) { s.SetStatus(v) }) } // UpdateStatus sets the "status" field to the value that was provided on create. func (u *EventParticipantUpsertBulk) UpdateStatus() *EventParticipantUpsertBulk { return u.Update(func(s *EventParticipantUpsert) { s.UpdateStatus() }) } // SetAccountID sets the "account_id" field. func (u *EventParticipantUpsertBulk) SetAccountID(v xid.ID) *EventParticipantUpsertBulk { return u.Update(func(s *EventParticipantUpsert) { s.SetAccountID(v) }) } // UpdateAccountID sets the "account_id" field to the value that was provided on create. func (u *EventParticipantUpsertBulk) UpdateAccountID() *EventParticipantUpsertBulk { return u.Update(func(s *EventParticipantUpsert) { s.UpdateAccountID() }) } // SetEventID sets the "event_id" field. func (u *EventParticipantUpsertBulk) SetEventID(v xid.ID) *EventParticipantUpsertBulk { return u.Update(func(s *EventParticipantUpsert) { s.SetEventID(v) }) } // UpdateEventID sets the "event_id" field to the value that was provided on create. func (u *EventParticipantUpsertBulk) UpdateEventID() *EventParticipantUpsertBulk { return u.Update(func(s *EventParticipantUpsert) { s.UpdateEventID() }) } // Exec executes the query. func (u *EventParticipantUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { return u.create.err } for i, b := range u.create.builders { if len(b.conflict) != 0 { return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the EventParticipantCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for EventParticipantCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *EventParticipantUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Southclaws/storyden'

If you have feedback or need assistance with the MCP directory API, please join our Discord server