mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 19:39:31 +08:00
从内部项目迁移模型配置和镜像配置模块,包括个人用户设置和团队级管理, 涵盖完整 CRUD、健康检查、供应商模型列表、所有权模型和 Swagger 注释。 - Ent schema: model, image, team_model, team_image, team_group_model, team_group_image - Domain 层: 接口、请求/响应类型、From 转换器 - Setting 模块: 个人模型/镜像 repo、usecase(代理重试、健康检查)、handler - Team 模块: 团队模型/镜像 repo、usecase、handler(TeamAuth + 审计中间件) - SQL 迁移: 000002_model_image up/down
660 lines
20 KiB
Go
660 lines
20 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
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/chaitin/MonkeyCode/backend/db/image"
|
|
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
|
|
"github.com/chaitin/MonkeyCode/backend/db/teamgroupimage"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// TeamGroupImageCreate is the builder for creating a TeamGroupImage entity.
|
|
type TeamGroupImageCreate struct {
|
|
config
|
|
mutation *TeamGroupImageMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetGroupID sets the "group_id" field.
|
|
func (_c *TeamGroupImageCreate) SetGroupID(v uuid.UUID) *TeamGroupImageCreate {
|
|
_c.mutation.SetGroupID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetImageID sets the "image_id" field.
|
|
func (_c *TeamGroupImageCreate) SetImageID(v uuid.UUID) *TeamGroupImageCreate {
|
|
_c.mutation.SetImageID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *TeamGroupImageCreate) SetCreatedAt(v time.Time) *TeamGroupImageCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *TeamGroupImageCreate) SetNillableCreatedAt(v *time.Time) *TeamGroupImageCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *TeamGroupImageCreate) SetID(v uuid.UUID) *TeamGroupImageCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetGroup sets the "group" edge to the TeamGroup entity.
|
|
func (_c *TeamGroupImageCreate) SetGroup(v *TeamGroup) *TeamGroupImageCreate {
|
|
return _c.SetGroupID(v.ID)
|
|
}
|
|
|
|
// SetImage sets the "image" edge to the Image entity.
|
|
func (_c *TeamGroupImageCreate) SetImage(v *Image) *TeamGroupImageCreate {
|
|
return _c.SetImageID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the TeamGroupImageMutation object of the builder.
|
|
func (_c *TeamGroupImageCreate) Mutation() *TeamGroupImageMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the TeamGroupImage in the database.
|
|
func (_c *TeamGroupImageCreate) Save(ctx context.Context) (*TeamGroupImage, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *TeamGroupImageCreate) SaveX(ctx context.Context) *TeamGroupImage {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *TeamGroupImageCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *TeamGroupImageCreate) 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 *TeamGroupImageCreate) defaults() {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := teamgroupimage.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *TeamGroupImageCreate) check() error {
|
|
if _, ok := _c.mutation.GroupID(); !ok {
|
|
return &ValidationError{Name: "group_id", err: errors.New(`db: missing required field "TeamGroupImage.group_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.ImageID(); !ok {
|
|
return &ValidationError{Name: "image_id", err: errors.New(`db: missing required field "TeamGroupImage.image_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "TeamGroupImage.created_at"`)}
|
|
}
|
|
if len(_c.mutation.GroupIDs()) == 0 {
|
|
return &ValidationError{Name: "group", err: errors.New(`db: missing required edge "TeamGroupImage.group"`)}
|
|
}
|
|
if len(_c.mutation.ImageIDs()) == 0 {
|
|
return &ValidationError{Name: "image", err: errors.New(`db: missing required edge "TeamGroupImage.image"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *TeamGroupImageCreate) sqlSave(ctx context.Context) (*TeamGroupImage, 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.(*uuid.UUID); 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 *TeamGroupImageCreate) createSpec() (*TeamGroupImage, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &TeamGroupImage{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(teamgroupimage.Table, sqlgraph.NewFieldSpec(teamgroupimage.FieldID, field.TypeUUID))
|
|
)
|
|
_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(teamgroupimage.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teamgroupimage.GroupTable,
|
|
Columns: []string{teamgroupimage.GroupColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.GroupID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.ImageIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teamgroupimage.ImageTable,
|
|
Columns: []string{teamgroupimage.ImageColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(image.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.ImageID = 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.TeamGroupImage.Create().
|
|
// SetGroupID(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.TeamGroupImageUpsert) {
|
|
// SetGroupID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *TeamGroupImageCreate) OnConflict(opts ...sql.ConflictOption) *TeamGroupImageUpsertOne {
|
|
_c.conflict = opts
|
|
return &TeamGroupImageUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.TeamGroupImage.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *TeamGroupImageCreate) OnConflictColumns(columns ...string) *TeamGroupImageUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &TeamGroupImageUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// TeamGroupImageUpsertOne is the builder for "upsert"-ing
|
|
// one TeamGroupImage node.
|
|
TeamGroupImageUpsertOne struct {
|
|
create *TeamGroupImageCreate
|
|
}
|
|
|
|
// TeamGroupImageUpsert is the "OnConflict" setter.
|
|
TeamGroupImageUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetGroupID sets the "group_id" field.
|
|
func (u *TeamGroupImageUpsert) SetGroupID(v uuid.UUID) *TeamGroupImageUpsert {
|
|
u.Set(teamgroupimage.FieldGroupID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
|
|
func (u *TeamGroupImageUpsert) UpdateGroupID() *TeamGroupImageUpsert {
|
|
u.SetExcluded(teamgroupimage.FieldGroupID)
|
|
return u
|
|
}
|
|
|
|
// SetImageID sets the "image_id" field.
|
|
func (u *TeamGroupImageUpsert) SetImageID(v uuid.UUID) *TeamGroupImageUpsert {
|
|
u.Set(teamgroupimage.FieldImageID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateImageID sets the "image_id" field to the value that was provided on create.
|
|
func (u *TeamGroupImageUpsert) UpdateImageID() *TeamGroupImageUpsert {
|
|
u.SetExcluded(teamgroupimage.FieldImageID)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *TeamGroupImageUpsert) SetCreatedAt(v time.Time) *TeamGroupImageUpsert {
|
|
u.Set(teamgroupimage.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *TeamGroupImageUpsert) UpdateCreatedAt() *TeamGroupImageUpsert {
|
|
u.SetExcluded(teamgroupimage.FieldCreatedAt)
|
|
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.TeamGroupImage.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(teamgroupimage.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *TeamGroupImageUpsertOne) UpdateNewValues() *TeamGroupImageUpsertOne {
|
|
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(teamgroupimage.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.TeamGroupImage.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *TeamGroupImageUpsertOne) Ignore() *TeamGroupImageUpsertOne {
|
|
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 *TeamGroupImageUpsertOne) DoNothing() *TeamGroupImageUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the TeamGroupImageCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *TeamGroupImageUpsertOne) Update(set func(*TeamGroupImageUpsert)) *TeamGroupImageUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&TeamGroupImageUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetGroupID sets the "group_id" field.
|
|
func (u *TeamGroupImageUpsertOne) SetGroupID(v uuid.UUID) *TeamGroupImageUpsertOne {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.SetGroupID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
|
|
func (u *TeamGroupImageUpsertOne) UpdateGroupID() *TeamGroupImageUpsertOne {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.UpdateGroupID()
|
|
})
|
|
}
|
|
|
|
// SetImageID sets the "image_id" field.
|
|
func (u *TeamGroupImageUpsertOne) SetImageID(v uuid.UUID) *TeamGroupImageUpsertOne {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.SetImageID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateImageID sets the "image_id" field to the value that was provided on create.
|
|
func (u *TeamGroupImageUpsertOne) UpdateImageID() *TeamGroupImageUpsertOne {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.UpdateImageID()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *TeamGroupImageUpsertOne) SetCreatedAt(v time.Time) *TeamGroupImageUpsertOne {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *TeamGroupImageUpsertOne) UpdateCreatedAt() *TeamGroupImageUpsertOne {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *TeamGroupImageUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for TeamGroupImageCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *TeamGroupImageUpsertOne) 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 *TeamGroupImageUpsertOne) ID(ctx context.Context) (id uuid.UUID, 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("db: TeamGroupImageUpsertOne.ID is not supported by MySQL driver. Use TeamGroupImageUpsertOne.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 *TeamGroupImageUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// TeamGroupImageCreateBulk is the builder for creating many TeamGroupImage entities in bulk.
|
|
type TeamGroupImageCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*TeamGroupImageCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the TeamGroupImage entities in the database.
|
|
func (_c *TeamGroupImageCreateBulk) Save(ctx context.Context) ([]*TeamGroupImage, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*TeamGroupImage, 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.(*TeamGroupImageMutation)
|
|
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 *TeamGroupImageCreateBulk) SaveX(ctx context.Context) []*TeamGroupImage {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *TeamGroupImageCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *TeamGroupImageCreateBulk) 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.TeamGroupImage.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.TeamGroupImageUpsert) {
|
|
// SetGroupID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *TeamGroupImageCreateBulk) OnConflict(opts ...sql.ConflictOption) *TeamGroupImageUpsertBulk {
|
|
_c.conflict = opts
|
|
return &TeamGroupImageUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.TeamGroupImage.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *TeamGroupImageCreateBulk) OnConflictColumns(columns ...string) *TeamGroupImageUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &TeamGroupImageUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// TeamGroupImageUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of TeamGroupImage nodes.
|
|
type TeamGroupImageUpsertBulk struct {
|
|
create *TeamGroupImageCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.TeamGroupImage.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(teamgroupimage.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *TeamGroupImageUpsertBulk) UpdateNewValues() *TeamGroupImageUpsertBulk {
|
|
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(teamgroupimage.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.TeamGroupImage.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *TeamGroupImageUpsertBulk) Ignore() *TeamGroupImageUpsertBulk {
|
|
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 *TeamGroupImageUpsertBulk) DoNothing() *TeamGroupImageUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the TeamGroupImageCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *TeamGroupImageUpsertBulk) Update(set func(*TeamGroupImageUpsert)) *TeamGroupImageUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&TeamGroupImageUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetGroupID sets the "group_id" field.
|
|
func (u *TeamGroupImageUpsertBulk) SetGroupID(v uuid.UUID) *TeamGroupImageUpsertBulk {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.SetGroupID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
|
|
func (u *TeamGroupImageUpsertBulk) UpdateGroupID() *TeamGroupImageUpsertBulk {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.UpdateGroupID()
|
|
})
|
|
}
|
|
|
|
// SetImageID sets the "image_id" field.
|
|
func (u *TeamGroupImageUpsertBulk) SetImageID(v uuid.UUID) *TeamGroupImageUpsertBulk {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.SetImageID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateImageID sets the "image_id" field to the value that was provided on create.
|
|
func (u *TeamGroupImageUpsertBulk) UpdateImageID() *TeamGroupImageUpsertBulk {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.UpdateImageID()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *TeamGroupImageUpsertBulk) SetCreatedAt(v time.Time) *TeamGroupImageUpsertBulk {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *TeamGroupImageUpsertBulk) UpdateCreatedAt() *TeamGroupImageUpsertBulk {
|
|
return u.Update(func(s *TeamGroupImageUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *TeamGroupImageUpsertBulk) 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("db: OnConflict was set for builder %d. Set it on the TeamGroupImageCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for TeamGroupImageCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *TeamGroupImageUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|