Skip to main content
Glama

Storyden

by Southclaws
Mozilla Public License 2.0
227
setting_create.go15.9 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/setting" ) // SettingCreate is the builder for creating a Setting entity. type SettingCreate struct { config mutation *SettingMutation hooks []Hook conflict []sql.ConflictOption } // SetValue sets the "value" field. func (_c *SettingCreate) SetValue(v string) *SettingCreate { _c.mutation.SetValue(v) return _c } // SetUpdatedAt sets the "updated_at" field. func (_c *SettingCreate) SetUpdatedAt(v time.Time) *SettingCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_c *SettingCreate) SetNillableUpdatedAt(v *time.Time) *SettingCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetID sets the "id" field. func (_c *SettingCreate) SetID(v string) *SettingCreate { _c.mutation.SetID(v) return _c } // Mutation returns the SettingMutation object of the builder. func (_c *SettingCreate) Mutation() *SettingMutation { return _c.mutation } // Save creates the Setting in the database. func (_c *SettingCreate) Save(ctx context.Context) (*Setting, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *SettingCreate) SaveX(ctx context.Context) *Setting { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *SettingCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *SettingCreate) 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 *SettingCreate) defaults() { if _, ok := _c.mutation.UpdatedAt(); !ok { v := setting.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_c *SettingCreate) check() error { if _, ok := _c.mutation.Value(); !ok { return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Setting.value"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Setting.updated_at"`)} } return nil } func (_c *SettingCreate) sqlSave(ctx context.Context) (*Setting, 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.(string); ok { _node.ID = id } else { return nil, fmt.Errorf("unexpected Setting.ID type: %T", _spec.ID.Value) } } _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } func (_c *SettingCreate) createSpec() (*Setting, *sqlgraph.CreateSpec) { var ( _node = &Setting{config: _c.config} _spec = sqlgraph.NewCreateSpec(setting.Table, sqlgraph.NewFieldSpec(setting.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.Value(); ok { _spec.SetField(setting.FieldValue, field.TypeString, value) _node.Value = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(setting.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.Setting.Create(). // SetValue(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.SettingUpsert) { // SetValue(v+v). // }). // Exec(ctx) func (_c *SettingCreate) OnConflict(opts ...sql.ConflictOption) *SettingUpsertOne { _c.conflict = opts return &SettingUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.Setting.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *SettingCreate) OnConflictColumns(columns ...string) *SettingUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &SettingUpsertOne{ create: _c, } } type ( // SettingUpsertOne is the builder for "upsert"-ing // one Setting node. SettingUpsertOne struct { create *SettingCreate } // SettingUpsert is the "OnConflict" setter. SettingUpsert struct { *sql.UpdateSet } ) // SetValue sets the "value" field. func (u *SettingUpsert) SetValue(v string) *SettingUpsert { u.Set(setting.FieldValue, v) return u } // UpdateValue sets the "value" field to the value that was provided on create. func (u *SettingUpsert) UpdateValue() *SettingUpsert { u.SetExcluded(setting.FieldValue) return u } // SetUpdatedAt sets the "updated_at" field. func (u *SettingUpsert) SetUpdatedAt(v time.Time) *SettingUpsert { u.Set(setting.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *SettingUpsert) UpdateUpdatedAt() *SettingUpsert { u.SetExcluded(setting.FieldUpdatedAt) 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.Setting.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(setting.FieldID) // }), // ). // Exec(ctx) func (u *SettingUpsertOne) UpdateNewValues() *SettingUpsertOne { 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(setting.FieldID) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.Setting.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *SettingUpsertOne) Ignore() *SettingUpsertOne { 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 *SettingUpsertOne) DoNothing() *SettingUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the SettingCreate.OnConflict // documentation for more info. func (u *SettingUpsertOne) Update(set func(*SettingUpsert)) *SettingUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&SettingUpsert{UpdateSet: update}) })) return u } // SetValue sets the "value" field. func (u *SettingUpsertOne) SetValue(v string) *SettingUpsertOne { return u.Update(func(s *SettingUpsert) { s.SetValue(v) }) } // UpdateValue sets the "value" field to the value that was provided on create. func (u *SettingUpsertOne) UpdateValue() *SettingUpsertOne { return u.Update(func(s *SettingUpsert) { s.UpdateValue() }) } // SetUpdatedAt sets the "updated_at" field. func (u *SettingUpsertOne) SetUpdatedAt(v time.Time) *SettingUpsertOne { return u.Update(func(s *SettingUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *SettingUpsertOne) UpdateUpdatedAt() *SettingUpsertOne { return u.Update(func(s *SettingUpsert) { s.UpdateUpdatedAt() }) } // Exec executes the query. func (u *SettingUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for SettingCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *SettingUpsertOne) 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 *SettingUpsertOne) ID(ctx context.Context) (id string, 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: SettingUpsertOne.ID is not supported by MySQL driver. Use SettingUpsertOne.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 *SettingUpsertOne) IDX(ctx context.Context) string { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // SettingCreateBulk is the builder for creating many Setting entities in bulk. type SettingCreateBulk struct { config err error builders []*SettingCreate conflict []sql.ConflictOption } // Save creates the Setting entities in the database. func (_c *SettingCreateBulk) Save(ctx context.Context) ([]*Setting, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*Setting, 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.(*SettingMutation) 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 *SettingCreateBulk) SaveX(ctx context.Context) []*Setting { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *SettingCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *SettingCreateBulk) 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.Setting.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.SettingUpsert) { // SetValue(v+v). // }). // Exec(ctx) func (_c *SettingCreateBulk) OnConflict(opts ...sql.ConflictOption) *SettingUpsertBulk { _c.conflict = opts return &SettingUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.Setting.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *SettingCreateBulk) OnConflictColumns(columns ...string) *SettingUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &SettingUpsertBulk{ create: _c, } } // SettingUpsertBulk is the builder for "upsert"-ing // a bulk of Setting nodes. type SettingUpsertBulk struct { create *SettingCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.Setting.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(setting.FieldID) // }), // ). // Exec(ctx) func (u *SettingUpsertBulk) UpdateNewValues() *SettingUpsertBulk { 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(setting.FieldID) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.Setting.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *SettingUpsertBulk) Ignore() *SettingUpsertBulk { 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 *SettingUpsertBulk) DoNothing() *SettingUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the SettingCreateBulk.OnConflict // documentation for more info. func (u *SettingUpsertBulk) Update(set func(*SettingUpsert)) *SettingUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&SettingUpsert{UpdateSet: update}) })) return u } // SetValue sets the "value" field. func (u *SettingUpsertBulk) SetValue(v string) *SettingUpsertBulk { return u.Update(func(s *SettingUpsert) { s.SetValue(v) }) } // UpdateValue sets the "value" field to the value that was provided on create. func (u *SettingUpsertBulk) UpdateValue() *SettingUpsertBulk { return u.Update(func(s *SettingUpsert) { s.UpdateValue() }) } // SetUpdatedAt sets the "updated_at" field. func (u *SettingUpsertBulk) SetUpdatedAt(v time.Time) *SettingUpsertBulk { return u.Update(func(s *SettingUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *SettingUpsertBulk) UpdateUpdatedAt() *SettingUpsertBulk { return u.Update(func(s *SettingUpsert) { s.UpdateUpdatedAt() }) } // Exec executes the query. func (u *SettingUpsertBulk) 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 SettingCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for SettingCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *SettingUpsertBulk) 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