- 新增过程巡检按步骤上报、数量不符上报、工位退料功能 - 增加工单工程编号三级归属字段 - 新增物料安全库存与缺货预警 - 新增附件管理、退库单管理模块 - 优化生产看板展示逻辑与前端页面文案 - 清理冗余的工艺路线相关代码与备份文件
946 lines
27 KiB
Go
946 lines
27 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_wms/ent/attachment"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// AttachmentCreate is the builder for creating a Attachment entity.
|
|
type AttachmentCreate struct {
|
|
config
|
|
mutation *AttachmentMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetBizType sets the "biz_type" field.
|
|
func (_c *AttachmentCreate) SetBizType(v string) *AttachmentCreate {
|
|
_c.mutation.SetBizType(v)
|
|
return _c
|
|
}
|
|
|
|
// SetBizID sets the "biz_id" field.
|
|
func (_c *AttachmentCreate) SetBizID(v string) *AttachmentCreate {
|
|
_c.mutation.SetBizID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetFileName sets the "file_name" field.
|
|
func (_c *AttachmentCreate) SetFileName(v string) *AttachmentCreate {
|
|
_c.mutation.SetFileName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetFilePath sets the "file_path" field.
|
|
func (_c *AttachmentCreate) SetFilePath(v string) *AttachmentCreate {
|
|
_c.mutation.SetFilePath(v)
|
|
return _c
|
|
}
|
|
|
|
// SetFileSize sets the "file_size" field.
|
|
func (_c *AttachmentCreate) SetFileSize(v int64) *AttachmentCreate {
|
|
_c.mutation.SetFileSize(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableFileSize sets the "file_size" field if the given value is not nil.
|
|
func (_c *AttachmentCreate) SetNillableFileSize(v *int64) *AttachmentCreate {
|
|
if v != nil {
|
|
_c.SetFileSize(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetMimeType sets the "mime_type" field.
|
|
func (_c *AttachmentCreate) SetMimeType(v string) *AttachmentCreate {
|
|
_c.mutation.SetMimeType(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableMimeType sets the "mime_type" field if the given value is not nil.
|
|
func (_c *AttachmentCreate) SetNillableMimeType(v *string) *AttachmentCreate {
|
|
if v != nil {
|
|
_c.SetMimeType(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUploadedBy sets the "uploaded_by" field.
|
|
func (_c *AttachmentCreate) SetUploadedBy(v string) *AttachmentCreate {
|
|
_c.mutation.SetUploadedBy(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUploadedBy sets the "uploaded_by" field if the given value is not nil.
|
|
func (_c *AttachmentCreate) SetNillableUploadedBy(v *string) *AttachmentCreate {
|
|
if v != nil {
|
|
_c.SetUploadedBy(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *AttachmentCreate) SetCreatedAt(v int64) *AttachmentCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *AttachmentCreate) SetNillableCreatedAt(v *int64) *AttachmentCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the AttachmentMutation object of the builder.
|
|
func (_c *AttachmentCreate) Mutation() *AttachmentMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the Attachment in the database.
|
|
func (_c *AttachmentCreate) Save(ctx context.Context) (*Attachment, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *AttachmentCreate) SaveX(ctx context.Context) *Attachment {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AttachmentCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AttachmentCreate) 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 *AttachmentCreate) defaults() {
|
|
if _, ok := _c.mutation.FileSize(); !ok {
|
|
v := attachment.DefaultFileSize
|
|
_c.mutation.SetFileSize(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := attachment.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *AttachmentCreate) check() error {
|
|
if _, ok := _c.mutation.BizType(); !ok {
|
|
return &ValidationError{Name: "biz_type", err: errors.New(`ent: missing required field "Attachment.biz_type"`)}
|
|
}
|
|
if _, ok := _c.mutation.BizID(); !ok {
|
|
return &ValidationError{Name: "biz_id", err: errors.New(`ent: missing required field "Attachment.biz_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.FileName(); !ok {
|
|
return &ValidationError{Name: "file_name", err: errors.New(`ent: missing required field "Attachment.file_name"`)}
|
|
}
|
|
if _, ok := _c.mutation.FilePath(); !ok {
|
|
return &ValidationError{Name: "file_path", err: errors.New(`ent: missing required field "Attachment.file_path"`)}
|
|
}
|
|
if _, ok := _c.mutation.FileSize(); !ok {
|
|
return &ValidationError{Name: "file_size", err: errors.New(`ent: missing required field "Attachment.file_size"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Attachment.created_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *AttachmentCreate) sqlSave(ctx context.Context) (*Attachment, 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
|
|
}
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *AttachmentCreate) createSpec() (*Attachment, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Attachment{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(attachment.Table, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeInt))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if value, ok := _c.mutation.BizType(); ok {
|
|
_spec.SetField(attachment.FieldBizType, field.TypeString, value)
|
|
_node.BizType = value
|
|
}
|
|
if value, ok := _c.mutation.BizID(); ok {
|
|
_spec.SetField(attachment.FieldBizID, field.TypeString, value)
|
|
_node.BizID = value
|
|
}
|
|
if value, ok := _c.mutation.FileName(); ok {
|
|
_spec.SetField(attachment.FieldFileName, field.TypeString, value)
|
|
_node.FileName = value
|
|
}
|
|
if value, ok := _c.mutation.FilePath(); ok {
|
|
_spec.SetField(attachment.FieldFilePath, field.TypeString, value)
|
|
_node.FilePath = value
|
|
}
|
|
if value, ok := _c.mutation.FileSize(); ok {
|
|
_spec.SetField(attachment.FieldFileSize, field.TypeInt64, value)
|
|
_node.FileSize = value
|
|
}
|
|
if value, ok := _c.mutation.MimeType(); ok {
|
|
_spec.SetField(attachment.FieldMimeType, field.TypeString, value)
|
|
_node.MimeType = value
|
|
}
|
|
if value, ok := _c.mutation.UploadedBy(); ok {
|
|
_spec.SetField(attachment.FieldUploadedBy, field.TypeString, value)
|
|
_node.UploadedBy = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(attachment.FieldCreatedAt, field.TypeInt64, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.Attachment.Create().
|
|
// SetBizType(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.AttachmentUpsert) {
|
|
// SetBizType(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *AttachmentCreate) OnConflict(opts ...sql.ConflictOption) *AttachmentUpsertOne {
|
|
_c.conflict = opts
|
|
return &AttachmentUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Attachment.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *AttachmentCreate) OnConflictColumns(columns ...string) *AttachmentUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &AttachmentUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// AttachmentUpsertOne is the builder for "upsert"-ing
|
|
// one Attachment node.
|
|
AttachmentUpsertOne struct {
|
|
create *AttachmentCreate
|
|
}
|
|
|
|
// AttachmentUpsert is the "OnConflict" setter.
|
|
AttachmentUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetBizType sets the "biz_type" field.
|
|
func (u *AttachmentUpsert) SetBizType(v string) *AttachmentUpsert {
|
|
u.Set(attachment.FieldBizType, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateBizType sets the "biz_type" field to the value that was provided on create.
|
|
func (u *AttachmentUpsert) UpdateBizType() *AttachmentUpsert {
|
|
u.SetExcluded(attachment.FieldBizType)
|
|
return u
|
|
}
|
|
|
|
// SetBizID sets the "biz_id" field.
|
|
func (u *AttachmentUpsert) SetBizID(v string) *AttachmentUpsert {
|
|
u.Set(attachment.FieldBizID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateBizID sets the "biz_id" field to the value that was provided on create.
|
|
func (u *AttachmentUpsert) UpdateBizID() *AttachmentUpsert {
|
|
u.SetExcluded(attachment.FieldBizID)
|
|
return u
|
|
}
|
|
|
|
// SetFileName sets the "file_name" field.
|
|
func (u *AttachmentUpsert) SetFileName(v string) *AttachmentUpsert {
|
|
u.Set(attachment.FieldFileName, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateFileName sets the "file_name" field to the value that was provided on create.
|
|
func (u *AttachmentUpsert) UpdateFileName() *AttachmentUpsert {
|
|
u.SetExcluded(attachment.FieldFileName)
|
|
return u
|
|
}
|
|
|
|
// SetFilePath sets the "file_path" field.
|
|
func (u *AttachmentUpsert) SetFilePath(v string) *AttachmentUpsert {
|
|
u.Set(attachment.FieldFilePath, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateFilePath sets the "file_path" field to the value that was provided on create.
|
|
func (u *AttachmentUpsert) UpdateFilePath() *AttachmentUpsert {
|
|
u.SetExcluded(attachment.FieldFilePath)
|
|
return u
|
|
}
|
|
|
|
// SetFileSize sets the "file_size" field.
|
|
func (u *AttachmentUpsert) SetFileSize(v int64) *AttachmentUpsert {
|
|
u.Set(attachment.FieldFileSize, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateFileSize sets the "file_size" field to the value that was provided on create.
|
|
func (u *AttachmentUpsert) UpdateFileSize() *AttachmentUpsert {
|
|
u.SetExcluded(attachment.FieldFileSize)
|
|
return u
|
|
}
|
|
|
|
// AddFileSize adds v to the "file_size" field.
|
|
func (u *AttachmentUpsert) AddFileSize(v int64) *AttachmentUpsert {
|
|
u.Add(attachment.FieldFileSize, v)
|
|
return u
|
|
}
|
|
|
|
// SetMimeType sets the "mime_type" field.
|
|
func (u *AttachmentUpsert) SetMimeType(v string) *AttachmentUpsert {
|
|
u.Set(attachment.FieldMimeType, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateMimeType sets the "mime_type" field to the value that was provided on create.
|
|
func (u *AttachmentUpsert) UpdateMimeType() *AttachmentUpsert {
|
|
u.SetExcluded(attachment.FieldMimeType)
|
|
return u
|
|
}
|
|
|
|
// ClearMimeType clears the value of the "mime_type" field.
|
|
func (u *AttachmentUpsert) ClearMimeType() *AttachmentUpsert {
|
|
u.SetNull(attachment.FieldMimeType)
|
|
return u
|
|
}
|
|
|
|
// SetUploadedBy sets the "uploaded_by" field.
|
|
func (u *AttachmentUpsert) SetUploadedBy(v string) *AttachmentUpsert {
|
|
u.Set(attachment.FieldUploadedBy, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUploadedBy sets the "uploaded_by" field to the value that was provided on create.
|
|
func (u *AttachmentUpsert) UpdateUploadedBy() *AttachmentUpsert {
|
|
u.SetExcluded(attachment.FieldUploadedBy)
|
|
return u
|
|
}
|
|
|
|
// ClearUploadedBy clears the value of the "uploaded_by" field.
|
|
func (u *AttachmentUpsert) ClearUploadedBy() *AttachmentUpsert {
|
|
u.SetNull(attachment.FieldUploadedBy)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AttachmentUpsert) SetCreatedAt(v int64) *AttachmentUpsert {
|
|
u.Set(attachment.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AttachmentUpsert) UpdateCreatedAt() *AttachmentUpsert {
|
|
u.SetExcluded(attachment.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *AttachmentUpsert) AddCreatedAt(v int64) *AttachmentUpsert {
|
|
u.Add(attachment.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Attachment.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *AttachmentUpsertOne) UpdateNewValues() *AttachmentUpsertOne {
|
|
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.Attachment.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *AttachmentUpsertOne) Ignore() *AttachmentUpsertOne {
|
|
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 *AttachmentUpsertOne) DoNothing() *AttachmentUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the AttachmentCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *AttachmentUpsertOne) Update(set func(*AttachmentUpsert)) *AttachmentUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&AttachmentUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetBizType sets the "biz_type" field.
|
|
func (u *AttachmentUpsertOne) SetBizType(v string) *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetBizType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBizType sets the "biz_type" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertOne) UpdateBizType() *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateBizType()
|
|
})
|
|
}
|
|
|
|
// SetBizID sets the "biz_id" field.
|
|
func (u *AttachmentUpsertOne) SetBizID(v string) *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetBizID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBizID sets the "biz_id" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertOne) UpdateBizID() *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateBizID()
|
|
})
|
|
}
|
|
|
|
// SetFileName sets the "file_name" field.
|
|
func (u *AttachmentUpsertOne) SetFileName(v string) *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetFileName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFileName sets the "file_name" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertOne) UpdateFileName() *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateFileName()
|
|
})
|
|
}
|
|
|
|
// SetFilePath sets the "file_path" field.
|
|
func (u *AttachmentUpsertOne) SetFilePath(v string) *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetFilePath(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFilePath sets the "file_path" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertOne) UpdateFilePath() *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateFilePath()
|
|
})
|
|
}
|
|
|
|
// SetFileSize sets the "file_size" field.
|
|
func (u *AttachmentUpsertOne) SetFileSize(v int64) *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetFileSize(v)
|
|
})
|
|
}
|
|
|
|
// AddFileSize adds v to the "file_size" field.
|
|
func (u *AttachmentUpsertOne) AddFileSize(v int64) *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.AddFileSize(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFileSize sets the "file_size" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertOne) UpdateFileSize() *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateFileSize()
|
|
})
|
|
}
|
|
|
|
// SetMimeType sets the "mime_type" field.
|
|
func (u *AttachmentUpsertOne) SetMimeType(v string) *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetMimeType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateMimeType sets the "mime_type" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertOne) UpdateMimeType() *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateMimeType()
|
|
})
|
|
}
|
|
|
|
// ClearMimeType clears the value of the "mime_type" field.
|
|
func (u *AttachmentUpsertOne) ClearMimeType() *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.ClearMimeType()
|
|
})
|
|
}
|
|
|
|
// SetUploadedBy sets the "uploaded_by" field.
|
|
func (u *AttachmentUpsertOne) SetUploadedBy(v string) *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetUploadedBy(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUploadedBy sets the "uploaded_by" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertOne) UpdateUploadedBy() *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateUploadedBy()
|
|
})
|
|
}
|
|
|
|
// ClearUploadedBy clears the value of the "uploaded_by" field.
|
|
func (u *AttachmentUpsertOne) ClearUploadedBy() *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.ClearUploadedBy()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AttachmentUpsertOne) SetCreatedAt(v int64) *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *AttachmentUpsertOne) AddCreatedAt(v int64) *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.AddCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertOne) UpdateCreatedAt() *AttachmentUpsertOne {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *AttachmentUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for AttachmentCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *AttachmentUpsertOne) 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 *AttachmentUpsertOne) ID(ctx context.Context) (id int, err error) {
|
|
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 *AttachmentUpsertOne) IDX(ctx context.Context) int {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// AttachmentCreateBulk is the builder for creating many Attachment entities in bulk.
|
|
type AttachmentCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*AttachmentCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the Attachment entities in the database.
|
|
func (_c *AttachmentCreateBulk) Save(ctx context.Context) ([]*Attachment, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*Attachment, 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.(*AttachmentMutation)
|
|
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
|
|
if specs[i].ID.Value != nil {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int(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 *AttachmentCreateBulk) SaveX(ctx context.Context) []*Attachment {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AttachmentCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AttachmentCreateBulk) 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.Attachment.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.AttachmentUpsert) {
|
|
// SetBizType(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *AttachmentCreateBulk) OnConflict(opts ...sql.ConflictOption) *AttachmentUpsertBulk {
|
|
_c.conflict = opts
|
|
return &AttachmentUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Attachment.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *AttachmentCreateBulk) OnConflictColumns(columns ...string) *AttachmentUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &AttachmentUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// AttachmentUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of Attachment nodes.
|
|
type AttachmentUpsertBulk struct {
|
|
create *AttachmentCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.Attachment.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *AttachmentUpsertBulk) UpdateNewValues() *AttachmentUpsertBulk {
|
|
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.Attachment.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *AttachmentUpsertBulk) Ignore() *AttachmentUpsertBulk {
|
|
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 *AttachmentUpsertBulk) DoNothing() *AttachmentUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the AttachmentCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *AttachmentUpsertBulk) Update(set func(*AttachmentUpsert)) *AttachmentUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&AttachmentUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetBizType sets the "biz_type" field.
|
|
func (u *AttachmentUpsertBulk) SetBizType(v string) *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetBizType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBizType sets the "biz_type" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertBulk) UpdateBizType() *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateBizType()
|
|
})
|
|
}
|
|
|
|
// SetBizID sets the "biz_id" field.
|
|
func (u *AttachmentUpsertBulk) SetBizID(v string) *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetBizID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBizID sets the "biz_id" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertBulk) UpdateBizID() *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateBizID()
|
|
})
|
|
}
|
|
|
|
// SetFileName sets the "file_name" field.
|
|
func (u *AttachmentUpsertBulk) SetFileName(v string) *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetFileName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFileName sets the "file_name" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertBulk) UpdateFileName() *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateFileName()
|
|
})
|
|
}
|
|
|
|
// SetFilePath sets the "file_path" field.
|
|
func (u *AttachmentUpsertBulk) SetFilePath(v string) *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetFilePath(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFilePath sets the "file_path" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertBulk) UpdateFilePath() *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateFilePath()
|
|
})
|
|
}
|
|
|
|
// SetFileSize sets the "file_size" field.
|
|
func (u *AttachmentUpsertBulk) SetFileSize(v int64) *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetFileSize(v)
|
|
})
|
|
}
|
|
|
|
// AddFileSize adds v to the "file_size" field.
|
|
func (u *AttachmentUpsertBulk) AddFileSize(v int64) *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.AddFileSize(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFileSize sets the "file_size" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertBulk) UpdateFileSize() *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateFileSize()
|
|
})
|
|
}
|
|
|
|
// SetMimeType sets the "mime_type" field.
|
|
func (u *AttachmentUpsertBulk) SetMimeType(v string) *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetMimeType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateMimeType sets the "mime_type" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertBulk) UpdateMimeType() *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateMimeType()
|
|
})
|
|
}
|
|
|
|
// ClearMimeType clears the value of the "mime_type" field.
|
|
func (u *AttachmentUpsertBulk) ClearMimeType() *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.ClearMimeType()
|
|
})
|
|
}
|
|
|
|
// SetUploadedBy sets the "uploaded_by" field.
|
|
func (u *AttachmentUpsertBulk) SetUploadedBy(v string) *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetUploadedBy(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUploadedBy sets the "uploaded_by" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertBulk) UpdateUploadedBy() *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateUploadedBy()
|
|
})
|
|
}
|
|
|
|
// ClearUploadedBy clears the value of the "uploaded_by" field.
|
|
func (u *AttachmentUpsertBulk) ClearUploadedBy() *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.ClearUploadedBy()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AttachmentUpsertBulk) SetCreatedAt(v int64) *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *AttachmentUpsertBulk) AddCreatedAt(v int64) *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.AddCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AttachmentUpsertBulk) UpdateCreatedAt() *AttachmentUpsertBulk {
|
|
return u.Update(func(s *AttachmentUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *AttachmentUpsertBulk) 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 AttachmentCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for AttachmentCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *AttachmentUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|