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
// 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/question"
"github.com/rs/xid"
)
// QuestionCreate is the builder for creating a Question entity.
type QuestionCreate struct {
config
mutation *QuestionMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (qc *QuestionCreate) SetCreatedAt(t time.Time) *QuestionCreate {
qc.mutation.SetCreatedAt(t)
return qc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (qc *QuestionCreate) SetNillableCreatedAt(t *time.Time) *QuestionCreate {
if t != nil {
qc.SetCreatedAt(*t)
}
return qc
}
// SetIndexedAt sets the "indexed_at" field.
func (qc *QuestionCreate) SetIndexedAt(t time.Time) *QuestionCreate {
qc.mutation.SetIndexedAt(t)
return qc
}
// SetNillableIndexedAt sets the "indexed_at" field if the given value is not nil.
func (qc *QuestionCreate) SetNillableIndexedAt(t *time.Time) *QuestionCreate {
if t != nil {
qc.SetIndexedAt(*t)
}
return qc
}
// SetSlug sets the "slug" field.
func (qc *QuestionCreate) SetSlug(s string) *QuestionCreate {
qc.mutation.SetSlug(s)
return qc
}
// SetQuery sets the "query" field.
func (qc *QuestionCreate) SetQuery(s string) *QuestionCreate {
qc.mutation.SetQuery(s)
return qc
}
// SetResult sets the "result" field.
func (qc *QuestionCreate) SetResult(s string) *QuestionCreate {
qc.mutation.SetResult(s)
return qc
}
// SetMetadata sets the "metadata" field.
func (qc *QuestionCreate) SetMetadata(m map[string]interface{}) *QuestionCreate {
qc.mutation.SetMetadata(m)
return qc
}
// SetAccountID sets the "account_id" field.
func (qc *QuestionCreate) SetAccountID(x xid.ID) *QuestionCreate {
qc.mutation.SetAccountID(x)
return qc
}
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
func (qc *QuestionCreate) SetNillableAccountID(x *xid.ID) *QuestionCreate {
if x != nil {
qc.SetAccountID(*x)
}
return qc
}
// SetParentQuestionID sets the "parent_question_id" field.
func (qc *QuestionCreate) SetParentQuestionID(x xid.ID) *QuestionCreate {
qc.mutation.SetParentQuestionID(x)
return qc
}
// SetNillableParentQuestionID sets the "parent_question_id" field if the given value is not nil.
func (qc *QuestionCreate) SetNillableParentQuestionID(x *xid.ID) *QuestionCreate {
if x != nil {
qc.SetParentQuestionID(*x)
}
return qc
}
// SetID sets the "id" field.
func (qc *QuestionCreate) SetID(x xid.ID) *QuestionCreate {
qc.mutation.SetID(x)
return qc
}
// SetNillableID sets the "id" field if the given value is not nil.
func (qc *QuestionCreate) SetNillableID(x *xid.ID) *QuestionCreate {
if x != nil {
qc.SetID(*x)
}
return qc
}
// SetAuthorID sets the "author" edge to the Account entity by ID.
func (qc *QuestionCreate) SetAuthorID(id xid.ID) *QuestionCreate {
qc.mutation.SetAuthorID(id)
return qc
}
// SetNillableAuthorID sets the "author" edge to the Account entity by ID if the given value is not nil.
func (qc *QuestionCreate) SetNillableAuthorID(id *xid.ID) *QuestionCreate {
if id != nil {
qc = qc.SetAuthorID(*id)
}
return qc
}
// SetAuthor sets the "author" edge to the Account entity.
func (qc *QuestionCreate) SetAuthor(a *Account) *QuestionCreate {
return qc.SetAuthorID(a.ID)
}
// SetParentID sets the "parent" edge to the Question entity by ID.
func (qc *QuestionCreate) SetParentID(id xid.ID) *QuestionCreate {
qc.mutation.SetParentID(id)
return qc
}
// SetNillableParentID sets the "parent" edge to the Question entity by ID if the given value is not nil.
func (qc *QuestionCreate) SetNillableParentID(id *xid.ID) *QuestionCreate {
if id != nil {
qc = qc.SetParentID(*id)
}
return qc
}
// SetParent sets the "parent" edge to the Question entity.
func (qc *QuestionCreate) SetParent(q *Question) *QuestionCreate {
return qc.SetParentID(q.ID)
}
// AddParentQuestionIDs adds the "parent_question" edge to the Question entity by IDs.
func (qc *QuestionCreate) AddParentQuestionIDs(ids ...xid.ID) *QuestionCreate {
qc.mutation.AddParentQuestionIDs(ids...)
return qc
}
// AddParentQuestion adds the "parent_question" edges to the Question entity.
func (qc *QuestionCreate) AddParentQuestion(q ...*Question) *QuestionCreate {
ids := make([]xid.ID, len(q))
for i := range q {
ids[i] = q[i].ID
}
return qc.AddParentQuestionIDs(ids...)
}
// Mutation returns the QuestionMutation object of the builder.
func (qc *QuestionCreate) Mutation() *QuestionMutation {
return qc.mutation
}
// Save creates the Question in the database.
func (qc *QuestionCreate) Save(ctx context.Context) (*Question, error) {
qc.defaults()
return withHooks(ctx, qc.sqlSave, qc.mutation, qc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (qc *QuestionCreate) SaveX(ctx context.Context) *Question {
v, err := qc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (qc *QuestionCreate) Exec(ctx context.Context) error {
_, err := qc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (qc *QuestionCreate) ExecX(ctx context.Context) {
if err := qc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (qc *QuestionCreate) defaults() {
if _, ok := qc.mutation.CreatedAt(); !ok {
v := question.DefaultCreatedAt()
qc.mutation.SetCreatedAt(v)
}
if _, ok := qc.mutation.ID(); !ok {
v := question.DefaultID()
qc.mutation.SetID(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (qc *QuestionCreate) check() error {
if _, ok := qc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Question.created_at"`)}
}
if _, ok := qc.mutation.Slug(); !ok {
return &ValidationError{Name: "slug", err: errors.New(`ent: missing required field "Question.slug"`)}
}
if _, ok := qc.mutation.Query(); !ok {
return &ValidationError{Name: "query", err: errors.New(`ent: missing required field "Question.query"`)}
}
if _, ok := qc.mutation.Result(); !ok {
return &ValidationError{Name: "result", err: errors.New(`ent: missing required field "Question.result"`)}
}
if v, ok := qc.mutation.ID(); ok {
if err := question.IDValidator(v.String()); err != nil {
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "Question.id": %w`, err)}
}
}
return nil
}
func (qc *QuestionCreate) sqlSave(ctx context.Context) (*Question, error) {
if err := qc.check(); err != nil {
return nil, err
}
_node, _spec := qc.createSpec()
if err := sqlgraph.CreateNode(ctx, qc.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
}
}
qc.mutation.id = &_node.ID
qc.mutation.done = true
return _node, nil
}
func (qc *QuestionCreate) createSpec() (*Question, *sqlgraph.CreateSpec) {
var (
_node = &Question{config: qc.config}
_spec = sqlgraph.NewCreateSpec(question.Table, sqlgraph.NewFieldSpec(question.FieldID, field.TypeString))
)
_spec.OnConflict = qc.conflict
if id, ok := qc.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = &id
}
if value, ok := qc.mutation.CreatedAt(); ok {
_spec.SetField(question.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := qc.mutation.IndexedAt(); ok {
_spec.SetField(question.FieldIndexedAt, field.TypeTime, value)
_node.IndexedAt = &value
}
if value, ok := qc.mutation.Slug(); ok {
_spec.SetField(question.FieldSlug, field.TypeString, value)
_node.Slug = value
}
if value, ok := qc.mutation.Query(); ok {
_spec.SetField(question.FieldQuery, field.TypeString, value)
_node.Query = value
}
if value, ok := qc.mutation.Result(); ok {
_spec.SetField(question.FieldResult, field.TypeString, value)
_node.Result = value
}
if value, ok := qc.mutation.Metadata(); ok {
_spec.SetField(question.FieldMetadata, field.TypeJSON, value)
_node.Metadata = value
}
if nodes := qc.mutation.AuthorIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: question.AuthorTable,
Columns: []string{question.AuthorColumn},
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 := qc.mutation.ParentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: question.ParentTable,
Columns: []string{question.ParentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(question.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.ParentQuestionID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := qc.mutation.ParentQuestionIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: question.ParentQuestionTable,
Columns: []string{question.ParentQuestionColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(question.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.Question.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.QuestionUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (qc *QuestionCreate) OnConflict(opts ...sql.ConflictOption) *QuestionUpsertOne {
qc.conflict = opts
return &QuestionUpsertOne{
create: qc,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Question.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (qc *QuestionCreate) OnConflictColumns(columns ...string) *QuestionUpsertOne {
qc.conflict = append(qc.conflict, sql.ConflictColumns(columns...))
return &QuestionUpsertOne{
create: qc,
}
}
type (
// QuestionUpsertOne is the builder for "upsert"-ing
// one Question node.
QuestionUpsertOne struct {
create *QuestionCreate
}
// QuestionUpsert is the "OnConflict" setter.
QuestionUpsert struct {
*sql.UpdateSet
}
)
// SetIndexedAt sets the "indexed_at" field.
func (u *QuestionUpsert) SetIndexedAt(v time.Time) *QuestionUpsert {
u.Set(question.FieldIndexedAt, v)
return u
}
// UpdateIndexedAt sets the "indexed_at" field to the value that was provided on create.
func (u *QuestionUpsert) UpdateIndexedAt() *QuestionUpsert {
u.SetExcluded(question.FieldIndexedAt)
return u
}
// ClearIndexedAt clears the value of the "indexed_at" field.
func (u *QuestionUpsert) ClearIndexedAt() *QuestionUpsert {
u.SetNull(question.FieldIndexedAt)
return u
}
// SetSlug sets the "slug" field.
func (u *QuestionUpsert) SetSlug(v string) *QuestionUpsert {
u.Set(question.FieldSlug, v)
return u
}
// UpdateSlug sets the "slug" field to the value that was provided on create.
func (u *QuestionUpsert) UpdateSlug() *QuestionUpsert {
u.SetExcluded(question.FieldSlug)
return u
}
// SetQuery sets the "query" field.
func (u *QuestionUpsert) SetQuery(v string) *QuestionUpsert {
u.Set(question.FieldQuery, v)
return u
}
// UpdateQuery sets the "query" field to the value that was provided on create.
func (u *QuestionUpsert) UpdateQuery() *QuestionUpsert {
u.SetExcluded(question.FieldQuery)
return u
}
// SetResult sets the "result" field.
func (u *QuestionUpsert) SetResult(v string) *QuestionUpsert {
u.Set(question.FieldResult, v)
return u
}
// UpdateResult sets the "result" field to the value that was provided on create.
func (u *QuestionUpsert) UpdateResult() *QuestionUpsert {
u.SetExcluded(question.FieldResult)
return u
}
// SetMetadata sets the "metadata" field.
func (u *QuestionUpsert) SetMetadata(v map[string]interface{}) *QuestionUpsert {
u.Set(question.FieldMetadata, v)
return u
}
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
func (u *QuestionUpsert) UpdateMetadata() *QuestionUpsert {
u.SetExcluded(question.FieldMetadata)
return u
}
// ClearMetadata clears the value of the "metadata" field.
func (u *QuestionUpsert) ClearMetadata() *QuestionUpsert {
u.SetNull(question.FieldMetadata)
return u
}
// SetAccountID sets the "account_id" field.
func (u *QuestionUpsert) SetAccountID(v xid.ID) *QuestionUpsert {
u.Set(question.FieldAccountID, v)
return u
}
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
func (u *QuestionUpsert) UpdateAccountID() *QuestionUpsert {
u.SetExcluded(question.FieldAccountID)
return u
}
// ClearAccountID clears the value of the "account_id" field.
func (u *QuestionUpsert) ClearAccountID() *QuestionUpsert {
u.SetNull(question.FieldAccountID)
return u
}
// SetParentQuestionID sets the "parent_question_id" field.
func (u *QuestionUpsert) SetParentQuestionID(v xid.ID) *QuestionUpsert {
u.Set(question.FieldParentQuestionID, v)
return u
}
// UpdateParentQuestionID sets the "parent_question_id" field to the value that was provided on create.
func (u *QuestionUpsert) UpdateParentQuestionID() *QuestionUpsert {
u.SetExcluded(question.FieldParentQuestionID)
return u
}
// ClearParentQuestionID clears the value of the "parent_question_id" field.
func (u *QuestionUpsert) ClearParentQuestionID() *QuestionUpsert {
u.SetNull(question.FieldParentQuestionID)
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.Question.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(question.FieldID)
// }),
// ).
// Exec(ctx)
func (u *QuestionUpsertOne) UpdateNewValues() *QuestionUpsertOne {
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(question.FieldID)
}
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(question.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Question.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *QuestionUpsertOne) Ignore() *QuestionUpsertOne {
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 *QuestionUpsertOne) DoNothing() *QuestionUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the QuestionCreate.OnConflict
// documentation for more info.
func (u *QuestionUpsertOne) Update(set func(*QuestionUpsert)) *QuestionUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&QuestionUpsert{UpdateSet: update})
}))
return u
}
// SetIndexedAt sets the "indexed_at" field.
func (u *QuestionUpsertOne) SetIndexedAt(v time.Time) *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.SetIndexedAt(v)
})
}
// UpdateIndexedAt sets the "indexed_at" field to the value that was provided on create.
func (u *QuestionUpsertOne) UpdateIndexedAt() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.UpdateIndexedAt()
})
}
// ClearIndexedAt clears the value of the "indexed_at" field.
func (u *QuestionUpsertOne) ClearIndexedAt() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.ClearIndexedAt()
})
}
// SetSlug sets the "slug" field.
func (u *QuestionUpsertOne) SetSlug(v string) *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.SetSlug(v)
})
}
// UpdateSlug sets the "slug" field to the value that was provided on create.
func (u *QuestionUpsertOne) UpdateSlug() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.UpdateSlug()
})
}
// SetQuery sets the "query" field.
func (u *QuestionUpsertOne) SetQuery(v string) *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.SetQuery(v)
})
}
// UpdateQuery sets the "query" field to the value that was provided on create.
func (u *QuestionUpsertOne) UpdateQuery() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.UpdateQuery()
})
}
// SetResult sets the "result" field.
func (u *QuestionUpsertOne) SetResult(v string) *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.SetResult(v)
})
}
// UpdateResult sets the "result" field to the value that was provided on create.
func (u *QuestionUpsertOne) UpdateResult() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.UpdateResult()
})
}
// SetMetadata sets the "metadata" field.
func (u *QuestionUpsertOne) SetMetadata(v map[string]interface{}) *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.SetMetadata(v)
})
}
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
func (u *QuestionUpsertOne) UpdateMetadata() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.UpdateMetadata()
})
}
// ClearMetadata clears the value of the "metadata" field.
func (u *QuestionUpsertOne) ClearMetadata() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.ClearMetadata()
})
}
// SetAccountID sets the "account_id" field.
func (u *QuestionUpsertOne) SetAccountID(v xid.ID) *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.SetAccountID(v)
})
}
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
func (u *QuestionUpsertOne) UpdateAccountID() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.UpdateAccountID()
})
}
// ClearAccountID clears the value of the "account_id" field.
func (u *QuestionUpsertOne) ClearAccountID() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.ClearAccountID()
})
}
// SetParentQuestionID sets the "parent_question_id" field.
func (u *QuestionUpsertOne) SetParentQuestionID(v xid.ID) *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.SetParentQuestionID(v)
})
}
// UpdateParentQuestionID sets the "parent_question_id" field to the value that was provided on create.
func (u *QuestionUpsertOne) UpdateParentQuestionID() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.UpdateParentQuestionID()
})
}
// ClearParentQuestionID clears the value of the "parent_question_id" field.
func (u *QuestionUpsertOne) ClearParentQuestionID() *QuestionUpsertOne {
return u.Update(func(s *QuestionUpsert) {
s.ClearParentQuestionID()
})
}
// Exec executes the query.
func (u *QuestionUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for QuestionCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *QuestionUpsertOne) 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 *QuestionUpsertOne) 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: QuestionUpsertOne.ID is not supported by MySQL driver. Use QuestionUpsertOne.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 *QuestionUpsertOne) IDX(ctx context.Context) xid.ID {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// QuestionCreateBulk is the builder for creating many Question entities in bulk.
type QuestionCreateBulk struct {
config
err error
builders []*QuestionCreate
conflict []sql.ConflictOption
}
// Save creates the Question entities in the database.
func (qcb *QuestionCreateBulk) Save(ctx context.Context) ([]*Question, error) {
if qcb.err != nil {
return nil, qcb.err
}
specs := make([]*sqlgraph.CreateSpec, len(qcb.builders))
nodes := make([]*Question, len(qcb.builders))
mutators := make([]Mutator, len(qcb.builders))
for i := range qcb.builders {
func(i int, root context.Context) {
builder := qcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*QuestionMutation)
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, qcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = qcb.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, qcb.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, qcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (qcb *QuestionCreateBulk) SaveX(ctx context.Context) []*Question {
v, err := qcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (qcb *QuestionCreateBulk) Exec(ctx context.Context) error {
_, err := qcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (qcb *QuestionCreateBulk) ExecX(ctx context.Context) {
if err := qcb.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Question.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.QuestionUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (qcb *QuestionCreateBulk) OnConflict(opts ...sql.ConflictOption) *QuestionUpsertBulk {
qcb.conflict = opts
return &QuestionUpsertBulk{
create: qcb,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Question.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (qcb *QuestionCreateBulk) OnConflictColumns(columns ...string) *QuestionUpsertBulk {
qcb.conflict = append(qcb.conflict, sql.ConflictColumns(columns...))
return &QuestionUpsertBulk{
create: qcb,
}
}
// QuestionUpsertBulk is the builder for "upsert"-ing
// a bulk of Question nodes.
type QuestionUpsertBulk struct {
create *QuestionCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.Question.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(question.FieldID)
// }),
// ).
// Exec(ctx)
func (u *QuestionUpsertBulk) UpdateNewValues() *QuestionUpsertBulk {
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(question.FieldID)
}
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(question.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Question.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *QuestionUpsertBulk) Ignore() *QuestionUpsertBulk {
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 *QuestionUpsertBulk) DoNothing() *QuestionUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the QuestionCreateBulk.OnConflict
// documentation for more info.
func (u *QuestionUpsertBulk) Update(set func(*QuestionUpsert)) *QuestionUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&QuestionUpsert{UpdateSet: update})
}))
return u
}
// SetIndexedAt sets the "indexed_at" field.
func (u *QuestionUpsertBulk) SetIndexedAt(v time.Time) *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.SetIndexedAt(v)
})
}
// UpdateIndexedAt sets the "indexed_at" field to the value that was provided on create.
func (u *QuestionUpsertBulk) UpdateIndexedAt() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.UpdateIndexedAt()
})
}
// ClearIndexedAt clears the value of the "indexed_at" field.
func (u *QuestionUpsertBulk) ClearIndexedAt() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.ClearIndexedAt()
})
}
// SetSlug sets the "slug" field.
func (u *QuestionUpsertBulk) SetSlug(v string) *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.SetSlug(v)
})
}
// UpdateSlug sets the "slug" field to the value that was provided on create.
func (u *QuestionUpsertBulk) UpdateSlug() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.UpdateSlug()
})
}
// SetQuery sets the "query" field.
func (u *QuestionUpsertBulk) SetQuery(v string) *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.SetQuery(v)
})
}
// UpdateQuery sets the "query" field to the value that was provided on create.
func (u *QuestionUpsertBulk) UpdateQuery() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.UpdateQuery()
})
}
// SetResult sets the "result" field.
func (u *QuestionUpsertBulk) SetResult(v string) *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.SetResult(v)
})
}
// UpdateResult sets the "result" field to the value that was provided on create.
func (u *QuestionUpsertBulk) UpdateResult() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.UpdateResult()
})
}
// SetMetadata sets the "metadata" field.
func (u *QuestionUpsertBulk) SetMetadata(v map[string]interface{}) *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.SetMetadata(v)
})
}
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
func (u *QuestionUpsertBulk) UpdateMetadata() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.UpdateMetadata()
})
}
// ClearMetadata clears the value of the "metadata" field.
func (u *QuestionUpsertBulk) ClearMetadata() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.ClearMetadata()
})
}
// SetAccountID sets the "account_id" field.
func (u *QuestionUpsertBulk) SetAccountID(v xid.ID) *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.SetAccountID(v)
})
}
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
func (u *QuestionUpsertBulk) UpdateAccountID() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.UpdateAccountID()
})
}
// ClearAccountID clears the value of the "account_id" field.
func (u *QuestionUpsertBulk) ClearAccountID() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.ClearAccountID()
})
}
// SetParentQuestionID sets the "parent_question_id" field.
func (u *QuestionUpsertBulk) SetParentQuestionID(v xid.ID) *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.SetParentQuestionID(v)
})
}
// UpdateParentQuestionID sets the "parent_question_id" field to the value that was provided on create.
func (u *QuestionUpsertBulk) UpdateParentQuestionID() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.UpdateParentQuestionID()
})
}
// ClearParentQuestionID clears the value of the "parent_question_id" field.
func (u *QuestionUpsertBulk) ClearParentQuestionID() *QuestionUpsertBulk {
return u.Update(func(s *QuestionUpsert) {
s.ClearParentQuestionID()
})
}
// Exec executes the query.
func (u *QuestionUpsertBulk) 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 QuestionCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for QuestionCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *QuestionUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}