Skip to main content
Glama

Storyden

by Southclaws
Mozilla Public License 2.0
227
accountroles_create.go21.6 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/accountroles" "github.com/Southclaws/storyden/internal/ent/role" "github.com/rs/xid" ) // AccountRolesCreate is the builder for creating a AccountRoles entity. type AccountRolesCreate struct { config mutation *AccountRolesMutation hooks []Hook conflict []sql.ConflictOption } // SetCreatedAt sets the "created_at" field. func (_c *AccountRolesCreate) SetCreatedAt(v time.Time) *AccountRolesCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *AccountRolesCreate) SetNillableCreatedAt(v *time.Time) *AccountRolesCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetAccountID sets the "account_id" field. func (_c *AccountRolesCreate) SetAccountID(v xid.ID) *AccountRolesCreate { _c.mutation.SetAccountID(v) return _c } // SetRoleID sets the "role_id" field. func (_c *AccountRolesCreate) SetRoleID(v xid.ID) *AccountRolesCreate { _c.mutation.SetRoleID(v) return _c } // SetBadge sets the "badge" field. func (_c *AccountRolesCreate) SetBadge(v bool) *AccountRolesCreate { _c.mutation.SetBadge(v) return _c } // SetNillableBadge sets the "badge" field if the given value is not nil. func (_c *AccountRolesCreate) SetNillableBadge(v *bool) *AccountRolesCreate { if v != nil { _c.SetBadge(*v) } return _c } // SetID sets the "id" field. func (_c *AccountRolesCreate) SetID(v xid.ID) *AccountRolesCreate { _c.mutation.SetID(v) return _c } // SetNillableID sets the "id" field if the given value is not nil. func (_c *AccountRolesCreate) SetNillableID(v *xid.ID) *AccountRolesCreate { if v != nil { _c.SetID(*v) } return _c } // SetAccount sets the "account" edge to the Account entity. func (_c *AccountRolesCreate) SetAccount(v *Account) *AccountRolesCreate { return _c.SetAccountID(v.ID) } // SetRole sets the "role" edge to the Role entity. func (_c *AccountRolesCreate) SetRole(v *Role) *AccountRolesCreate { return _c.SetRoleID(v.ID) } // Mutation returns the AccountRolesMutation object of the builder. func (_c *AccountRolesCreate) Mutation() *AccountRolesMutation { return _c.mutation } // Save creates the AccountRoles in the database. func (_c *AccountRolesCreate) Save(ctx context.Context) (*AccountRoles, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *AccountRolesCreate) SaveX(ctx context.Context) *AccountRoles { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *AccountRolesCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *AccountRolesCreate) 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 *AccountRolesCreate) defaults() { if _, ok := _c.mutation.CreatedAt(); !ok { v := accountroles.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.ID(); !ok { v := accountroles.DefaultID() _c.mutation.SetID(v) } } // check runs all checks and user-defined validators on the builder. func (_c *AccountRolesCreate) check() error { if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AccountRoles.created_at"`)} } if _, ok := _c.mutation.AccountID(); !ok { return &ValidationError{Name: "account_id", err: errors.New(`ent: missing required field "AccountRoles.account_id"`)} } if _, ok := _c.mutation.RoleID(); !ok { return &ValidationError{Name: "role_id", err: errors.New(`ent: missing required field "AccountRoles.role_id"`)} } if v, ok := _c.mutation.ID(); ok { if err := accountroles.IDValidator(v.String()); err != nil { return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "AccountRoles.id": %w`, err)} } } if len(_c.mutation.AccountIDs()) == 0 { return &ValidationError{Name: "account", err: errors.New(`ent: missing required edge "AccountRoles.account"`)} } if len(_c.mutation.RoleIDs()) == 0 { return &ValidationError{Name: "role", err: errors.New(`ent: missing required edge "AccountRoles.role"`)} } return nil } func (_c *AccountRolesCreate) sqlSave(ctx context.Context) (*AccountRoles, 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 *AccountRolesCreate) createSpec() (*AccountRoles, *sqlgraph.CreateSpec) { var ( _node = &AccountRoles{config: _c.config} _spec = sqlgraph.NewCreateSpec(accountroles.Table, sqlgraph.NewFieldSpec(accountroles.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(accountroles.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.Badge(); ok { _spec.SetField(accountroles.FieldBadge, field.TypeBool, value) _node.Badge = &value } if nodes := _c.mutation.AccountIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: accountroles.AccountTable, Columns: []string{accountroles.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.RoleIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: accountroles.RoleTable, Columns: []string{accountroles.RoleColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(role.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.RoleID = 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.AccountRoles.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.AccountRolesUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *AccountRolesCreate) OnConflict(opts ...sql.ConflictOption) *AccountRolesUpsertOne { _c.conflict = opts return &AccountRolesUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.AccountRoles.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *AccountRolesCreate) OnConflictColumns(columns ...string) *AccountRolesUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &AccountRolesUpsertOne{ create: _c, } } type ( // AccountRolesUpsertOne is the builder for "upsert"-ing // one AccountRoles node. AccountRolesUpsertOne struct { create *AccountRolesCreate } // AccountRolesUpsert is the "OnConflict" setter. AccountRolesUpsert struct { *sql.UpdateSet } ) // SetAccountID sets the "account_id" field. func (u *AccountRolesUpsert) SetAccountID(v xid.ID) *AccountRolesUpsert { u.Set(accountroles.FieldAccountID, v) return u } // UpdateAccountID sets the "account_id" field to the value that was provided on create. func (u *AccountRolesUpsert) UpdateAccountID() *AccountRolesUpsert { u.SetExcluded(accountroles.FieldAccountID) return u } // SetRoleID sets the "role_id" field. func (u *AccountRolesUpsert) SetRoleID(v xid.ID) *AccountRolesUpsert { u.Set(accountroles.FieldRoleID, v) return u } // UpdateRoleID sets the "role_id" field to the value that was provided on create. func (u *AccountRolesUpsert) UpdateRoleID() *AccountRolesUpsert { u.SetExcluded(accountroles.FieldRoleID) return u } // SetBadge sets the "badge" field. func (u *AccountRolesUpsert) SetBadge(v bool) *AccountRolesUpsert { u.Set(accountroles.FieldBadge, v) return u } // UpdateBadge sets the "badge" field to the value that was provided on create. func (u *AccountRolesUpsert) UpdateBadge() *AccountRolesUpsert { u.SetExcluded(accountroles.FieldBadge) return u } // ClearBadge clears the value of the "badge" field. func (u *AccountRolesUpsert) ClearBadge() *AccountRolesUpsert { u.SetNull(accountroles.FieldBadge) 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.AccountRoles.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(accountroles.FieldID) // }), // ). // Exec(ctx) func (u *AccountRolesUpsertOne) UpdateNewValues() *AccountRolesUpsertOne { 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(accountroles.FieldID) } if _, exists := u.create.mutation.CreatedAt(); exists { s.SetIgnore(accountroles.FieldCreatedAt) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.AccountRoles.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *AccountRolesUpsertOne) Ignore() *AccountRolesUpsertOne { 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 *AccountRolesUpsertOne) DoNothing() *AccountRolesUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the AccountRolesCreate.OnConflict // documentation for more info. func (u *AccountRolesUpsertOne) Update(set func(*AccountRolesUpsert)) *AccountRolesUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&AccountRolesUpsert{UpdateSet: update}) })) return u } // SetAccountID sets the "account_id" field. func (u *AccountRolesUpsertOne) SetAccountID(v xid.ID) *AccountRolesUpsertOne { return u.Update(func(s *AccountRolesUpsert) { s.SetAccountID(v) }) } // UpdateAccountID sets the "account_id" field to the value that was provided on create. func (u *AccountRolesUpsertOne) UpdateAccountID() *AccountRolesUpsertOne { return u.Update(func(s *AccountRolesUpsert) { s.UpdateAccountID() }) } // SetRoleID sets the "role_id" field. func (u *AccountRolesUpsertOne) SetRoleID(v xid.ID) *AccountRolesUpsertOne { return u.Update(func(s *AccountRolesUpsert) { s.SetRoleID(v) }) } // UpdateRoleID sets the "role_id" field to the value that was provided on create. func (u *AccountRolesUpsertOne) UpdateRoleID() *AccountRolesUpsertOne { return u.Update(func(s *AccountRolesUpsert) { s.UpdateRoleID() }) } // SetBadge sets the "badge" field. func (u *AccountRolesUpsertOne) SetBadge(v bool) *AccountRolesUpsertOne { return u.Update(func(s *AccountRolesUpsert) { s.SetBadge(v) }) } // UpdateBadge sets the "badge" field to the value that was provided on create. func (u *AccountRolesUpsertOne) UpdateBadge() *AccountRolesUpsertOne { return u.Update(func(s *AccountRolesUpsert) { s.UpdateBadge() }) } // ClearBadge clears the value of the "badge" field. func (u *AccountRolesUpsertOne) ClearBadge() *AccountRolesUpsertOne { return u.Update(func(s *AccountRolesUpsert) { s.ClearBadge() }) } // Exec executes the query. func (u *AccountRolesUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for AccountRolesCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *AccountRolesUpsertOne) 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 *AccountRolesUpsertOne) 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: AccountRolesUpsertOne.ID is not supported by MySQL driver. Use AccountRolesUpsertOne.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 *AccountRolesUpsertOne) IDX(ctx context.Context) xid.ID { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // AccountRolesCreateBulk is the builder for creating many AccountRoles entities in bulk. type AccountRolesCreateBulk struct { config err error builders []*AccountRolesCreate conflict []sql.ConflictOption } // Save creates the AccountRoles entities in the database. func (_c *AccountRolesCreateBulk) Save(ctx context.Context) ([]*AccountRoles, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*AccountRoles, 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.(*AccountRolesMutation) 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 *AccountRolesCreateBulk) SaveX(ctx context.Context) []*AccountRoles { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *AccountRolesCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *AccountRolesCreateBulk) 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.AccountRoles.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.AccountRolesUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *AccountRolesCreateBulk) OnConflict(opts ...sql.ConflictOption) *AccountRolesUpsertBulk { _c.conflict = opts return &AccountRolesUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.AccountRoles.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *AccountRolesCreateBulk) OnConflictColumns(columns ...string) *AccountRolesUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &AccountRolesUpsertBulk{ create: _c, } } // AccountRolesUpsertBulk is the builder for "upsert"-ing // a bulk of AccountRoles nodes. type AccountRolesUpsertBulk struct { create *AccountRolesCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.AccountRoles.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(accountroles.FieldID) // }), // ). // Exec(ctx) func (u *AccountRolesUpsertBulk) UpdateNewValues() *AccountRolesUpsertBulk { 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(accountroles.FieldID) } if _, exists := b.mutation.CreatedAt(); exists { s.SetIgnore(accountroles.FieldCreatedAt) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.AccountRoles.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *AccountRolesUpsertBulk) Ignore() *AccountRolesUpsertBulk { 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 *AccountRolesUpsertBulk) DoNothing() *AccountRolesUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the AccountRolesCreateBulk.OnConflict // documentation for more info. func (u *AccountRolesUpsertBulk) Update(set func(*AccountRolesUpsert)) *AccountRolesUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&AccountRolesUpsert{UpdateSet: update}) })) return u } // SetAccountID sets the "account_id" field. func (u *AccountRolesUpsertBulk) SetAccountID(v xid.ID) *AccountRolesUpsertBulk { return u.Update(func(s *AccountRolesUpsert) { s.SetAccountID(v) }) } // UpdateAccountID sets the "account_id" field to the value that was provided on create. func (u *AccountRolesUpsertBulk) UpdateAccountID() *AccountRolesUpsertBulk { return u.Update(func(s *AccountRolesUpsert) { s.UpdateAccountID() }) } // SetRoleID sets the "role_id" field. func (u *AccountRolesUpsertBulk) SetRoleID(v xid.ID) *AccountRolesUpsertBulk { return u.Update(func(s *AccountRolesUpsert) { s.SetRoleID(v) }) } // UpdateRoleID sets the "role_id" field to the value that was provided on create. func (u *AccountRolesUpsertBulk) UpdateRoleID() *AccountRolesUpsertBulk { return u.Update(func(s *AccountRolesUpsert) { s.UpdateRoleID() }) } // SetBadge sets the "badge" field. func (u *AccountRolesUpsertBulk) SetBadge(v bool) *AccountRolesUpsertBulk { return u.Update(func(s *AccountRolesUpsert) { s.SetBadge(v) }) } // UpdateBadge sets the "badge" field to the value that was provided on create. func (u *AccountRolesUpsertBulk) UpdateBadge() *AccountRolesUpsertBulk { return u.Update(func(s *AccountRolesUpsert) { s.UpdateBadge() }) } // ClearBadge clears the value of the "badge" field. func (u *AccountRolesUpsertBulk) ClearBadge() *AccountRolesUpsertBulk { return u.Update(func(s *AccountRolesUpsert) { s.ClearBadge() }) } // Exec executes the query. func (u *AccountRolesUpsertBulk) 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 AccountRolesCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for AccountRolesCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *AccountRolesUpsertBulk) 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