Skip to main content
Glama

Storyden

by Southclaws
Mozilla Public License 2.0
227
link_create.go30.7 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/asset" "github.com/Southclaws/storyden/internal/ent/link" "github.com/Southclaws/storyden/internal/ent/node" "github.com/Southclaws/storyden/internal/ent/post" "github.com/rs/xid" ) // LinkCreate is the builder for creating a Link entity. type LinkCreate struct { config mutation *LinkMutation hooks []Hook conflict []sql.ConflictOption } // SetCreatedAt sets the "created_at" field. func (_c *LinkCreate) SetCreatedAt(v time.Time) *LinkCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *LinkCreate) SetNillableCreatedAt(v *time.Time) *LinkCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetURL sets the "url" field. func (_c *LinkCreate) SetURL(v string) *LinkCreate { _c.mutation.SetURL(v) return _c } // SetSlug sets the "slug" field. func (_c *LinkCreate) SetSlug(v string) *LinkCreate { _c.mutation.SetSlug(v) return _c } // SetDomain sets the "domain" field. func (_c *LinkCreate) SetDomain(v string) *LinkCreate { _c.mutation.SetDomain(v) return _c } // SetTitle sets the "title" field. func (_c *LinkCreate) SetTitle(v string) *LinkCreate { _c.mutation.SetTitle(v) return _c } // SetDescription sets the "description" field. func (_c *LinkCreate) SetDescription(v string) *LinkCreate { _c.mutation.SetDescription(v) return _c } // SetPrimaryAssetID sets the "primary_asset_id" field. func (_c *LinkCreate) SetPrimaryAssetID(v xid.ID) *LinkCreate { _c.mutation.SetPrimaryAssetID(v) return _c } // SetNillablePrimaryAssetID sets the "primary_asset_id" field if the given value is not nil. func (_c *LinkCreate) SetNillablePrimaryAssetID(v *xid.ID) *LinkCreate { if v != nil { _c.SetPrimaryAssetID(*v) } return _c } // SetFaviconAssetID sets the "favicon_asset_id" field. func (_c *LinkCreate) SetFaviconAssetID(v xid.ID) *LinkCreate { _c.mutation.SetFaviconAssetID(v) return _c } // SetNillableFaviconAssetID sets the "favicon_asset_id" field if the given value is not nil. func (_c *LinkCreate) SetNillableFaviconAssetID(v *xid.ID) *LinkCreate { if v != nil { _c.SetFaviconAssetID(*v) } return _c } // SetID sets the "id" field. func (_c *LinkCreate) SetID(v xid.ID) *LinkCreate { _c.mutation.SetID(v) return _c } // SetNillableID sets the "id" field if the given value is not nil. func (_c *LinkCreate) SetNillableID(v *xid.ID) *LinkCreate { if v != nil { _c.SetID(*v) } return _c } // AddPostIDs adds the "posts" edge to the Post entity by IDs. func (_c *LinkCreate) AddPostIDs(ids ...xid.ID) *LinkCreate { _c.mutation.AddPostIDs(ids...) return _c } // AddPosts adds the "posts" edges to the Post entity. func (_c *LinkCreate) AddPosts(v ...*Post) *LinkCreate { ids := make([]xid.ID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddPostIDs(ids...) } // AddPostContentReferenceIDs adds the "post_content_references" edge to the Post entity by IDs. func (_c *LinkCreate) AddPostContentReferenceIDs(ids ...xid.ID) *LinkCreate { _c.mutation.AddPostContentReferenceIDs(ids...) return _c } // AddPostContentReferences adds the "post_content_references" edges to the Post entity. func (_c *LinkCreate) AddPostContentReferences(v ...*Post) *LinkCreate { ids := make([]xid.ID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddPostContentReferenceIDs(ids...) } // AddNodeIDs adds the "nodes" edge to the Node entity by IDs. func (_c *LinkCreate) AddNodeIDs(ids ...xid.ID) *LinkCreate { _c.mutation.AddNodeIDs(ids...) return _c } // AddNodes adds the "nodes" edges to the Node entity. func (_c *LinkCreate) AddNodes(v ...*Node) *LinkCreate { ids := make([]xid.ID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddNodeIDs(ids...) } // AddNodeContentReferenceIDs adds the "node_content_references" edge to the Node entity by IDs. func (_c *LinkCreate) AddNodeContentReferenceIDs(ids ...xid.ID) *LinkCreate { _c.mutation.AddNodeContentReferenceIDs(ids...) return _c } // AddNodeContentReferences adds the "node_content_references" edges to the Node entity. func (_c *LinkCreate) AddNodeContentReferences(v ...*Node) *LinkCreate { ids := make([]xid.ID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddNodeContentReferenceIDs(ids...) } // SetPrimaryImageID sets the "primary_image" edge to the Asset entity by ID. func (_c *LinkCreate) SetPrimaryImageID(id xid.ID) *LinkCreate { _c.mutation.SetPrimaryImageID(id) return _c } // SetNillablePrimaryImageID sets the "primary_image" edge to the Asset entity by ID if the given value is not nil. func (_c *LinkCreate) SetNillablePrimaryImageID(id *xid.ID) *LinkCreate { if id != nil { _c = _c.SetPrimaryImageID(*id) } return _c } // SetPrimaryImage sets the "primary_image" edge to the Asset entity. func (_c *LinkCreate) SetPrimaryImage(v *Asset) *LinkCreate { return _c.SetPrimaryImageID(v.ID) } // SetFaviconImageID sets the "favicon_image" edge to the Asset entity by ID. func (_c *LinkCreate) SetFaviconImageID(id xid.ID) *LinkCreate { _c.mutation.SetFaviconImageID(id) return _c } // SetNillableFaviconImageID sets the "favicon_image" edge to the Asset entity by ID if the given value is not nil. func (_c *LinkCreate) SetNillableFaviconImageID(id *xid.ID) *LinkCreate { if id != nil { _c = _c.SetFaviconImageID(*id) } return _c } // SetFaviconImage sets the "favicon_image" edge to the Asset entity. func (_c *LinkCreate) SetFaviconImage(v *Asset) *LinkCreate { return _c.SetFaviconImageID(v.ID) } // AddAssetIDs adds the "assets" edge to the Asset entity by IDs. func (_c *LinkCreate) AddAssetIDs(ids ...xid.ID) *LinkCreate { _c.mutation.AddAssetIDs(ids...) return _c } // AddAssets adds the "assets" edges to the Asset entity. func (_c *LinkCreate) AddAssets(v ...*Asset) *LinkCreate { ids := make([]xid.ID, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddAssetIDs(ids...) } // Mutation returns the LinkMutation object of the builder. func (_c *LinkCreate) Mutation() *LinkMutation { return _c.mutation } // Save creates the Link in the database. func (_c *LinkCreate) Save(ctx context.Context) (*Link, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *LinkCreate) SaveX(ctx context.Context) *Link { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *LinkCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *LinkCreate) 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 *LinkCreate) defaults() { if _, ok := _c.mutation.CreatedAt(); !ok { v := link.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.ID(); !ok { v := link.DefaultID() _c.mutation.SetID(v) } } // check runs all checks and user-defined validators on the builder. func (_c *LinkCreate) check() error { if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Link.created_at"`)} } if _, ok := _c.mutation.URL(); !ok { return &ValidationError{Name: "url", err: errors.New(`ent: missing required field "Link.url"`)} } if _, ok := _c.mutation.Slug(); !ok { return &ValidationError{Name: "slug", err: errors.New(`ent: missing required field "Link.slug"`)} } if _, ok := _c.mutation.Domain(); !ok { return &ValidationError{Name: "domain", err: errors.New(`ent: missing required field "Link.domain"`)} } if _, ok := _c.mutation.Title(); !ok { return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Link.title"`)} } if _, ok := _c.mutation.Description(); !ok { return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "Link.description"`)} } if v, ok := _c.mutation.ID(); ok { if err := link.IDValidator(v.String()); err != nil { return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "Link.id": %w`, err)} } } return nil } func (_c *LinkCreate) sqlSave(ctx context.Context) (*Link, 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 *LinkCreate) createSpec() (*Link, *sqlgraph.CreateSpec) { var ( _node = &Link{config: _c.config} _spec = sqlgraph.NewCreateSpec(link.Table, sqlgraph.NewFieldSpec(link.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(link.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.URL(); ok { _spec.SetField(link.FieldURL, field.TypeString, value) _node.URL = value } if value, ok := _c.mutation.Slug(); ok { _spec.SetField(link.FieldSlug, field.TypeString, value) _node.Slug = value } if value, ok := _c.mutation.Domain(); ok { _spec.SetField(link.FieldDomain, field.TypeString, value) _node.Domain = value } if value, ok := _c.mutation.Title(); ok { _spec.SetField(link.FieldTitle, field.TypeString, value) _node.Title = value } if value, ok := _c.mutation.Description(); ok { _spec.SetField(link.FieldDescription, field.TypeString, value) _node.Description = value } if nodes := _c.mutation.PostsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: link.PostsTable, Columns: []string{link.PostsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.PostContentReferencesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: link.PostContentReferencesTable, Columns: link.PostContentReferencesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.NodesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: link.NodesTable, Columns: []string{link.NodesColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.NodeContentReferencesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: link.NodeContentReferencesTable, Columns: link.NodeContentReferencesPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.PrimaryImageIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: link.PrimaryImageTable, Columns: []string{link.PrimaryImageColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(asset.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.PrimaryAssetID = &nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.FaviconImageIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: link.FaviconImageTable, Columns: []string{link.FaviconImageColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(asset.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.FaviconAssetID = &nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.AssetsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, Table: link.AssetsTable, Columns: link.AssetsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(asset.FieldID, field.TypeString), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _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.Link.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.LinkUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *LinkCreate) OnConflict(opts ...sql.ConflictOption) *LinkUpsertOne { _c.conflict = opts return &LinkUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.Link.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *LinkCreate) OnConflictColumns(columns ...string) *LinkUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &LinkUpsertOne{ create: _c, } } type ( // LinkUpsertOne is the builder for "upsert"-ing // one Link node. LinkUpsertOne struct { create *LinkCreate } // LinkUpsert is the "OnConflict" setter. LinkUpsert struct { *sql.UpdateSet } ) // SetDomain sets the "domain" field. func (u *LinkUpsert) SetDomain(v string) *LinkUpsert { u.Set(link.FieldDomain, v) return u } // UpdateDomain sets the "domain" field to the value that was provided on create. func (u *LinkUpsert) UpdateDomain() *LinkUpsert { u.SetExcluded(link.FieldDomain) return u } // SetTitle sets the "title" field. func (u *LinkUpsert) SetTitle(v string) *LinkUpsert { u.Set(link.FieldTitle, v) return u } // UpdateTitle sets the "title" field to the value that was provided on create. func (u *LinkUpsert) UpdateTitle() *LinkUpsert { u.SetExcluded(link.FieldTitle) return u } // SetDescription sets the "description" field. func (u *LinkUpsert) SetDescription(v string) *LinkUpsert { u.Set(link.FieldDescription, v) return u } // UpdateDescription sets the "description" field to the value that was provided on create. func (u *LinkUpsert) UpdateDescription() *LinkUpsert { u.SetExcluded(link.FieldDescription) return u } // SetPrimaryAssetID sets the "primary_asset_id" field. func (u *LinkUpsert) SetPrimaryAssetID(v xid.ID) *LinkUpsert { u.Set(link.FieldPrimaryAssetID, v) return u } // UpdatePrimaryAssetID sets the "primary_asset_id" field to the value that was provided on create. func (u *LinkUpsert) UpdatePrimaryAssetID() *LinkUpsert { u.SetExcluded(link.FieldPrimaryAssetID) return u } // ClearPrimaryAssetID clears the value of the "primary_asset_id" field. func (u *LinkUpsert) ClearPrimaryAssetID() *LinkUpsert { u.SetNull(link.FieldPrimaryAssetID) return u } // SetFaviconAssetID sets the "favicon_asset_id" field. func (u *LinkUpsert) SetFaviconAssetID(v xid.ID) *LinkUpsert { u.Set(link.FieldFaviconAssetID, v) return u } // UpdateFaviconAssetID sets the "favicon_asset_id" field to the value that was provided on create. func (u *LinkUpsert) UpdateFaviconAssetID() *LinkUpsert { u.SetExcluded(link.FieldFaviconAssetID) return u } // ClearFaviconAssetID clears the value of the "favicon_asset_id" field. func (u *LinkUpsert) ClearFaviconAssetID() *LinkUpsert { u.SetNull(link.FieldFaviconAssetID) 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.Link.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(link.FieldID) // }), // ). // Exec(ctx) func (u *LinkUpsertOne) UpdateNewValues() *LinkUpsertOne { 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(link.FieldID) } if _, exists := u.create.mutation.CreatedAt(); exists { s.SetIgnore(link.FieldCreatedAt) } if _, exists := u.create.mutation.URL(); exists { s.SetIgnore(link.FieldURL) } if _, exists := u.create.mutation.Slug(); exists { s.SetIgnore(link.FieldSlug) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.Link.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *LinkUpsertOne) Ignore() *LinkUpsertOne { 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 *LinkUpsertOne) DoNothing() *LinkUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the LinkCreate.OnConflict // documentation for more info. func (u *LinkUpsertOne) Update(set func(*LinkUpsert)) *LinkUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&LinkUpsert{UpdateSet: update}) })) return u } // SetDomain sets the "domain" field. func (u *LinkUpsertOne) SetDomain(v string) *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.SetDomain(v) }) } // UpdateDomain sets the "domain" field to the value that was provided on create. func (u *LinkUpsertOne) UpdateDomain() *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.UpdateDomain() }) } // SetTitle sets the "title" field. func (u *LinkUpsertOne) SetTitle(v string) *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.SetTitle(v) }) } // UpdateTitle sets the "title" field to the value that was provided on create. func (u *LinkUpsertOne) UpdateTitle() *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.UpdateTitle() }) } // SetDescription sets the "description" field. func (u *LinkUpsertOne) SetDescription(v string) *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.SetDescription(v) }) } // UpdateDescription sets the "description" field to the value that was provided on create. func (u *LinkUpsertOne) UpdateDescription() *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.UpdateDescription() }) } // SetPrimaryAssetID sets the "primary_asset_id" field. func (u *LinkUpsertOne) SetPrimaryAssetID(v xid.ID) *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.SetPrimaryAssetID(v) }) } // UpdatePrimaryAssetID sets the "primary_asset_id" field to the value that was provided on create. func (u *LinkUpsertOne) UpdatePrimaryAssetID() *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.UpdatePrimaryAssetID() }) } // ClearPrimaryAssetID clears the value of the "primary_asset_id" field. func (u *LinkUpsertOne) ClearPrimaryAssetID() *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.ClearPrimaryAssetID() }) } // SetFaviconAssetID sets the "favicon_asset_id" field. func (u *LinkUpsertOne) SetFaviconAssetID(v xid.ID) *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.SetFaviconAssetID(v) }) } // UpdateFaviconAssetID sets the "favicon_asset_id" field to the value that was provided on create. func (u *LinkUpsertOne) UpdateFaviconAssetID() *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.UpdateFaviconAssetID() }) } // ClearFaviconAssetID clears the value of the "favicon_asset_id" field. func (u *LinkUpsertOne) ClearFaviconAssetID() *LinkUpsertOne { return u.Update(func(s *LinkUpsert) { s.ClearFaviconAssetID() }) } // Exec executes the query. func (u *LinkUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for LinkCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *LinkUpsertOne) 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 *LinkUpsertOne) 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: LinkUpsertOne.ID is not supported by MySQL driver. Use LinkUpsertOne.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 *LinkUpsertOne) IDX(ctx context.Context) xid.ID { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // LinkCreateBulk is the builder for creating many Link entities in bulk. type LinkCreateBulk struct { config err error builders []*LinkCreate conflict []sql.ConflictOption } // Save creates the Link entities in the database. func (_c *LinkCreateBulk) Save(ctx context.Context) ([]*Link, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*Link, 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.(*LinkMutation) 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 *LinkCreateBulk) SaveX(ctx context.Context) []*Link { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *LinkCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *LinkCreateBulk) 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.Link.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.LinkUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *LinkCreateBulk) OnConflict(opts ...sql.ConflictOption) *LinkUpsertBulk { _c.conflict = opts return &LinkUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.Link.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *LinkCreateBulk) OnConflictColumns(columns ...string) *LinkUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &LinkUpsertBulk{ create: _c, } } // LinkUpsertBulk is the builder for "upsert"-ing // a bulk of Link nodes. type LinkUpsertBulk struct { create *LinkCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.Link.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(link.FieldID) // }), // ). // Exec(ctx) func (u *LinkUpsertBulk) UpdateNewValues() *LinkUpsertBulk { 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(link.FieldID) } if _, exists := b.mutation.CreatedAt(); exists { s.SetIgnore(link.FieldCreatedAt) } if _, exists := b.mutation.URL(); exists { s.SetIgnore(link.FieldURL) } if _, exists := b.mutation.Slug(); exists { s.SetIgnore(link.FieldSlug) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.Link.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *LinkUpsertBulk) Ignore() *LinkUpsertBulk { 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 *LinkUpsertBulk) DoNothing() *LinkUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the LinkCreateBulk.OnConflict // documentation for more info. func (u *LinkUpsertBulk) Update(set func(*LinkUpsert)) *LinkUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&LinkUpsert{UpdateSet: update}) })) return u } // SetDomain sets the "domain" field. func (u *LinkUpsertBulk) SetDomain(v string) *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.SetDomain(v) }) } // UpdateDomain sets the "domain" field to the value that was provided on create. func (u *LinkUpsertBulk) UpdateDomain() *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.UpdateDomain() }) } // SetTitle sets the "title" field. func (u *LinkUpsertBulk) SetTitle(v string) *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.SetTitle(v) }) } // UpdateTitle sets the "title" field to the value that was provided on create. func (u *LinkUpsertBulk) UpdateTitle() *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.UpdateTitle() }) } // SetDescription sets the "description" field. func (u *LinkUpsertBulk) SetDescription(v string) *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.SetDescription(v) }) } // UpdateDescription sets the "description" field to the value that was provided on create. func (u *LinkUpsertBulk) UpdateDescription() *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.UpdateDescription() }) } // SetPrimaryAssetID sets the "primary_asset_id" field. func (u *LinkUpsertBulk) SetPrimaryAssetID(v xid.ID) *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.SetPrimaryAssetID(v) }) } // UpdatePrimaryAssetID sets the "primary_asset_id" field to the value that was provided on create. func (u *LinkUpsertBulk) UpdatePrimaryAssetID() *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.UpdatePrimaryAssetID() }) } // ClearPrimaryAssetID clears the value of the "primary_asset_id" field. func (u *LinkUpsertBulk) ClearPrimaryAssetID() *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.ClearPrimaryAssetID() }) } // SetFaviconAssetID sets the "favicon_asset_id" field. func (u *LinkUpsertBulk) SetFaviconAssetID(v xid.ID) *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.SetFaviconAssetID(v) }) } // UpdateFaviconAssetID sets the "favicon_asset_id" field to the value that was provided on create. func (u *LinkUpsertBulk) UpdateFaviconAssetID() *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.UpdateFaviconAssetID() }) } // ClearFaviconAssetID clears the value of the "favicon_asset_id" field. func (u *LinkUpsertBulk) ClearFaviconAssetID() *LinkUpsertBulk { return u.Update(func(s *LinkUpsert) { s.ClearFaviconAssetID() }) } // Exec executes the query. func (u *LinkUpsertBulk) 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 LinkCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for LinkCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *LinkUpsertBulk) 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