Files
upstream-ent/entc/integration/customid/ent/bloblink_create.go
upstream-mirror 4b3ad0b611
Some checks failed
Atlas CI Public / lint (push) Failing after 13s
Atlas CI Public / sync (push) Has been skipped
snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 22:12:36 +05:00

601 lines
17 KiB
Go

// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/entc/integration/customid/ent/blob"
"entgo.io/ent/entc/integration/customid/ent/bloblink"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// BlobLinkCreate is the builder for creating a BlobLink entity.
type BlobLinkCreate struct {
config
mutation *BlobLinkMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (_c *BlobLinkCreate) SetCreatedAt(v time.Time) *BlobLinkCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *BlobLinkCreate) SetNillableCreatedAt(v *time.Time) *BlobLinkCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetBlobID sets the "blob_id" field.
func (_c *BlobLinkCreate) SetBlobID(v uuid.UUID) *BlobLinkCreate {
_c.mutation.SetBlobID(v)
return _c
}
// SetLinkID sets the "link_id" field.
func (_c *BlobLinkCreate) SetLinkID(v uuid.UUID) *BlobLinkCreate {
_c.mutation.SetLinkID(v)
return _c
}
// SetBlob sets the "blob" edge to the Blob entity.
func (_c *BlobLinkCreate) SetBlob(v *Blob) *BlobLinkCreate {
return _c.SetBlobID(v.ID)
}
// SetLink sets the "link" edge to the Blob entity.
func (_c *BlobLinkCreate) SetLink(v *Blob) *BlobLinkCreate {
return _c.SetLinkID(v.ID)
}
// Mutation returns the BlobLinkMutation object of the builder.
func (_c *BlobLinkCreate) Mutation() *BlobLinkMutation {
return _c.mutation
}
// Save creates the BlobLink in the database.
func (_c *BlobLinkCreate) Save(ctx context.Context) (*BlobLink, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *BlobLinkCreate) SaveX(ctx context.Context) *BlobLink {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *BlobLinkCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *BlobLinkCreate) 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 *BlobLinkCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := bloblink.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *BlobLinkCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "BlobLink.created_at"`)}
}
if _, ok := _c.mutation.BlobID(); !ok {
return &ValidationError{Name: "blob_id", err: errors.New(`ent: missing required field "BlobLink.blob_id"`)}
}
if _, ok := _c.mutation.LinkID(); !ok {
return &ValidationError{Name: "link_id", err: errors.New(`ent: missing required field "BlobLink.link_id"`)}
}
if len(_c.mutation.BlobIDs()) == 0 {
return &ValidationError{Name: "blob", err: errors.New(`ent: missing required edge "BlobLink.blob"`)}
}
if len(_c.mutation.LinkIDs()) == 0 {
return &ValidationError{Name: "link", err: errors.New(`ent: missing required edge "BlobLink.link"`)}
}
return nil
}
func (_c *BlobLinkCreate) sqlSave(ctx context.Context) (*BlobLink, 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
}
return _node, nil
}
func (_c *BlobLinkCreate) createSpec() (*BlobLink, *sqlgraph.CreateSpec) {
var (
_node = &BlobLink{config: _c.config}
_spec = sqlgraph.NewCreateSpec(bloblink.Table, nil)
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(bloblink.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if nodes := _c.mutation.BlobIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: bloblink.BlobTable,
Columns: []string{bloblink.BlobColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(blob.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.BlobID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.LinkIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: bloblink.LinkTable,
Columns: []string{bloblink.LinkColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(blob.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.LinkID = 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.BlobLink.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.BlobLinkUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *BlobLinkCreate) OnConflict(opts ...sql.ConflictOption) *BlobLinkUpsertOne {
_c.conflict = opts
return &BlobLinkUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.BlobLink.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *BlobLinkCreate) OnConflictColumns(columns ...string) *BlobLinkUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &BlobLinkUpsertOne{
create: _c,
}
}
type (
// BlobLinkUpsertOne is the builder for "upsert"-ing
// one BlobLink node.
BlobLinkUpsertOne struct {
create *BlobLinkCreate
}
// BlobLinkUpsert is the "OnConflict" setter.
BlobLinkUpsert struct {
*sql.UpdateSet
}
)
// SetCreatedAt sets the "created_at" field.
func (u *BlobLinkUpsert) SetCreatedAt(v time.Time) *BlobLinkUpsert {
u.Set(bloblink.FieldCreatedAt, v)
return u
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *BlobLinkUpsert) UpdateCreatedAt() *BlobLinkUpsert {
u.SetExcluded(bloblink.FieldCreatedAt)
return u
}
// SetBlobID sets the "blob_id" field.
func (u *BlobLinkUpsert) SetBlobID(v uuid.UUID) *BlobLinkUpsert {
u.Set(bloblink.FieldBlobID, v)
return u
}
// UpdateBlobID sets the "blob_id" field to the value that was provided on create.
func (u *BlobLinkUpsert) UpdateBlobID() *BlobLinkUpsert {
u.SetExcluded(bloblink.FieldBlobID)
return u
}
// SetLinkID sets the "link_id" field.
func (u *BlobLinkUpsert) SetLinkID(v uuid.UUID) *BlobLinkUpsert {
u.Set(bloblink.FieldLinkID, v)
return u
}
// UpdateLinkID sets the "link_id" field to the value that was provided on create.
func (u *BlobLinkUpsert) UpdateLinkID() *BlobLinkUpsert {
u.SetExcluded(bloblink.FieldLinkID)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.BlobLink.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *BlobLinkUpsertOne) UpdateNewValues() *BlobLinkUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.BlobLink.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *BlobLinkUpsertOne) Ignore() *BlobLinkUpsertOne {
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 *BlobLinkUpsertOne) DoNothing() *BlobLinkUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the BlobLinkCreate.OnConflict
// documentation for more info.
func (u *BlobLinkUpsertOne) Update(set func(*BlobLinkUpsert)) *BlobLinkUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&BlobLinkUpsert{UpdateSet: update})
}))
return u
}
// SetCreatedAt sets the "created_at" field.
func (u *BlobLinkUpsertOne) SetCreatedAt(v time.Time) *BlobLinkUpsertOne {
return u.Update(func(s *BlobLinkUpsert) {
s.SetCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *BlobLinkUpsertOne) UpdateCreatedAt() *BlobLinkUpsertOne {
return u.Update(func(s *BlobLinkUpsert) {
s.UpdateCreatedAt()
})
}
// SetBlobID sets the "blob_id" field.
func (u *BlobLinkUpsertOne) SetBlobID(v uuid.UUID) *BlobLinkUpsertOne {
return u.Update(func(s *BlobLinkUpsert) {
s.SetBlobID(v)
})
}
// UpdateBlobID sets the "blob_id" field to the value that was provided on create.
func (u *BlobLinkUpsertOne) UpdateBlobID() *BlobLinkUpsertOne {
return u.Update(func(s *BlobLinkUpsert) {
s.UpdateBlobID()
})
}
// SetLinkID sets the "link_id" field.
func (u *BlobLinkUpsertOne) SetLinkID(v uuid.UUID) *BlobLinkUpsertOne {
return u.Update(func(s *BlobLinkUpsert) {
s.SetLinkID(v)
})
}
// UpdateLinkID sets the "link_id" field to the value that was provided on create.
func (u *BlobLinkUpsertOne) UpdateLinkID() *BlobLinkUpsertOne {
return u.Update(func(s *BlobLinkUpsert) {
s.UpdateLinkID()
})
}
// Exec executes the query.
func (u *BlobLinkUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for BlobLinkCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *BlobLinkUpsertOne) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// BlobLinkCreateBulk is the builder for creating many BlobLink entities in bulk.
type BlobLinkCreateBulk struct {
config
err error
builders []*BlobLinkCreate
conflict []sql.ConflictOption
}
// Save creates the BlobLink entities in the database.
func (_c *BlobLinkCreateBulk) Save(ctx context.Context) ([]*BlobLink, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*BlobLink, 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.(*BlobLinkMutation)
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.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 *BlobLinkCreateBulk) SaveX(ctx context.Context) []*BlobLink {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *BlobLinkCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *BlobLinkCreateBulk) 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.BlobLink.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.BlobLinkUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *BlobLinkCreateBulk) OnConflict(opts ...sql.ConflictOption) *BlobLinkUpsertBulk {
_c.conflict = opts
return &BlobLinkUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.BlobLink.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *BlobLinkCreateBulk) OnConflictColumns(columns ...string) *BlobLinkUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &BlobLinkUpsertBulk{
create: _c,
}
}
// BlobLinkUpsertBulk is the builder for "upsert"-ing
// a bulk of BlobLink nodes.
type BlobLinkUpsertBulk struct {
create *BlobLinkCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.BlobLink.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *BlobLinkUpsertBulk) UpdateNewValues() *BlobLinkUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.BlobLink.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *BlobLinkUpsertBulk) Ignore() *BlobLinkUpsertBulk {
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 *BlobLinkUpsertBulk) DoNothing() *BlobLinkUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the BlobLinkCreateBulk.OnConflict
// documentation for more info.
func (u *BlobLinkUpsertBulk) Update(set func(*BlobLinkUpsert)) *BlobLinkUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&BlobLinkUpsert{UpdateSet: update})
}))
return u
}
// SetCreatedAt sets the "created_at" field.
func (u *BlobLinkUpsertBulk) SetCreatedAt(v time.Time) *BlobLinkUpsertBulk {
return u.Update(func(s *BlobLinkUpsert) {
s.SetCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *BlobLinkUpsertBulk) UpdateCreatedAt() *BlobLinkUpsertBulk {
return u.Update(func(s *BlobLinkUpsert) {
s.UpdateCreatedAt()
})
}
// SetBlobID sets the "blob_id" field.
func (u *BlobLinkUpsertBulk) SetBlobID(v uuid.UUID) *BlobLinkUpsertBulk {
return u.Update(func(s *BlobLinkUpsert) {
s.SetBlobID(v)
})
}
// UpdateBlobID sets the "blob_id" field to the value that was provided on create.
func (u *BlobLinkUpsertBulk) UpdateBlobID() *BlobLinkUpsertBulk {
return u.Update(func(s *BlobLinkUpsert) {
s.UpdateBlobID()
})
}
// SetLinkID sets the "link_id" field.
func (u *BlobLinkUpsertBulk) SetLinkID(v uuid.UUID) *BlobLinkUpsertBulk {
return u.Update(func(s *BlobLinkUpsert) {
s.SetLinkID(v)
})
}
// UpdateLinkID sets the "link_id" field to the value that was provided on create.
func (u *BlobLinkUpsertBulk) UpdateLinkID() *BlobLinkUpsertBulk {
return u.Update(func(s *BlobLinkUpsert) {
s.UpdateLinkID()
})
}
// Exec executes the query.
func (u *BlobLinkUpsertBulk) 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 BlobLinkCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for BlobLinkCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *BlobLinkUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}