mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 19:39:31 +08:00
714 lines
21 KiB
Go
714 lines
21 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/consts"
|
|
"github.com/chaitin/MonkeyCode/backend/db/team"
|
|
"github.com/chaitin/MonkeyCode/backend/db/teammember"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// TeamMemberCreate is the builder for creating a TeamMember entity.
|
|
type TeamMemberCreate struct {
|
|
config
|
|
mutation *TeamMemberMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetTeamID sets the "team_id" field.
|
|
func (_c *TeamMemberCreate) SetTeamID(v uuid.UUID) *TeamMemberCreate {
|
|
_c.mutation.SetTeamID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *TeamMemberCreate) SetUserID(v uuid.UUID) *TeamMemberCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (_c *TeamMemberCreate) SetRole(v consts.TeamMemberRole) *TeamMemberCreate {
|
|
_c.mutation.SetRole(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *TeamMemberCreate) SetCreatedAt(v time.Time) *TeamMemberCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *TeamMemberCreate) SetNillableCreatedAt(v *time.Time) *TeamMemberCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *TeamMemberCreate) SetID(v uuid.UUID) *TeamMemberCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetTeam sets the "team" edge to the Team entity.
|
|
func (_c *TeamMemberCreate) SetTeam(v *Team) *TeamMemberCreate {
|
|
return _c.SetTeamID(v.ID)
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (_c *TeamMemberCreate) SetUser(v *User) *TeamMemberCreate {
|
|
return _c.SetUserID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the TeamMemberMutation object of the builder.
|
|
func (_c *TeamMemberCreate) Mutation() *TeamMemberMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the TeamMember in the database.
|
|
func (_c *TeamMemberCreate) Save(ctx context.Context) (*TeamMember, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *TeamMemberCreate) SaveX(ctx context.Context) *TeamMember {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *TeamMemberCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *TeamMemberCreate) 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 *TeamMemberCreate) defaults() {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := teammember.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *TeamMemberCreate) check() error {
|
|
if _, ok := _c.mutation.TeamID(); !ok {
|
|
return &ValidationError{Name: "team_id", err: errors.New(`db: missing required field "TeamMember.team_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "TeamMember.user_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Role(); !ok {
|
|
return &ValidationError{Name: "role", err: errors.New(`db: missing required field "TeamMember.role"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "TeamMember.created_at"`)}
|
|
}
|
|
if len(_c.mutation.TeamIDs()) == 0 {
|
|
return &ValidationError{Name: "team", err: errors.New(`db: missing required edge "TeamMember.team"`)}
|
|
}
|
|
if len(_c.mutation.UserIDs()) == 0 {
|
|
return &ValidationError{Name: "user", err: errors.New(`db: missing required edge "TeamMember.user"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *TeamMemberCreate) sqlSave(ctx context.Context) (*TeamMember, 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 *TeamMemberCreate) createSpec() (*TeamMember, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &TeamMember{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(teammember.Table, sqlgraph.NewFieldSpec(teammember.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.Role(); ok {
|
|
_spec.SetField(teammember.FieldRole, field.TypeString, value)
|
|
_node.Role = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(teammember.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if nodes := _c.mutation.TeamIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teammember.TeamTable,
|
|
Columns: []string{teammember.TeamColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.TeamID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teammember.UserTable,
|
|
Columns: []string{teammember.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.UserID = 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.TeamMember.Create().
|
|
// SetTeamID(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.TeamMemberUpsert) {
|
|
// SetTeamID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *TeamMemberCreate) OnConflict(opts ...sql.ConflictOption) *TeamMemberUpsertOne {
|
|
_c.conflict = opts
|
|
return &TeamMemberUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.TeamMember.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *TeamMemberCreate) OnConflictColumns(columns ...string) *TeamMemberUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &TeamMemberUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// TeamMemberUpsertOne is the builder for "upsert"-ing
|
|
// one TeamMember node.
|
|
TeamMemberUpsertOne struct {
|
|
create *TeamMemberCreate
|
|
}
|
|
|
|
// TeamMemberUpsert is the "OnConflict" setter.
|
|
TeamMemberUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetTeamID sets the "team_id" field.
|
|
func (u *TeamMemberUpsert) SetTeamID(v uuid.UUID) *TeamMemberUpsert {
|
|
u.Set(teammember.FieldTeamID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateTeamID sets the "team_id" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsert) UpdateTeamID() *TeamMemberUpsert {
|
|
u.SetExcluded(teammember.FieldTeamID)
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *TeamMemberUpsert) SetUserID(v uuid.UUID) *TeamMemberUpsert {
|
|
u.Set(teammember.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsert) UpdateUserID() *TeamMemberUpsert {
|
|
u.SetExcluded(teammember.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (u *TeamMemberUpsert) SetRole(v consts.TeamMemberRole) *TeamMemberUpsert {
|
|
u.Set(teammember.FieldRole, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateRole sets the "role" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsert) UpdateRole() *TeamMemberUpsert {
|
|
u.SetExcluded(teammember.FieldRole)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *TeamMemberUpsert) SetCreatedAt(v time.Time) *TeamMemberUpsert {
|
|
u.Set(teammember.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsert) UpdateCreatedAt() *TeamMemberUpsert {
|
|
u.SetExcluded(teammember.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.TeamMember.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(teammember.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *TeamMemberUpsertOne) UpdateNewValues() *TeamMemberUpsertOne {
|
|
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(teammember.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.TeamMember.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *TeamMemberUpsertOne) Ignore() *TeamMemberUpsertOne {
|
|
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 *TeamMemberUpsertOne) DoNothing() *TeamMemberUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the TeamMemberCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *TeamMemberUpsertOne) Update(set func(*TeamMemberUpsert)) *TeamMemberUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&TeamMemberUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetTeamID sets the "team_id" field.
|
|
func (u *TeamMemberUpsertOne) SetTeamID(v uuid.UUID) *TeamMemberUpsertOne {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.SetTeamID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTeamID sets the "team_id" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsertOne) UpdateTeamID() *TeamMemberUpsertOne {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.UpdateTeamID()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *TeamMemberUpsertOne) SetUserID(v uuid.UUID) *TeamMemberUpsertOne {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsertOne) UpdateUserID() *TeamMemberUpsertOne {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (u *TeamMemberUpsertOne) SetRole(v consts.TeamMemberRole) *TeamMemberUpsertOne {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.SetRole(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRole sets the "role" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsertOne) UpdateRole() *TeamMemberUpsertOne {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.UpdateRole()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *TeamMemberUpsertOne) SetCreatedAt(v time.Time) *TeamMemberUpsertOne {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsertOne) UpdateCreatedAt() *TeamMemberUpsertOne {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *TeamMemberUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for TeamMemberCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *TeamMemberUpsertOne) 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 *TeamMemberUpsertOne) 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: TeamMemberUpsertOne.ID is not supported by MySQL driver. Use TeamMemberUpsertOne.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 *TeamMemberUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// TeamMemberCreateBulk is the builder for creating many TeamMember entities in bulk.
|
|
type TeamMemberCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*TeamMemberCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the TeamMember entities in the database.
|
|
func (_c *TeamMemberCreateBulk) Save(ctx context.Context) ([]*TeamMember, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*TeamMember, 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.(*TeamMemberMutation)
|
|
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 *TeamMemberCreateBulk) SaveX(ctx context.Context) []*TeamMember {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *TeamMemberCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *TeamMemberCreateBulk) 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.TeamMember.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.TeamMemberUpsert) {
|
|
// SetTeamID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *TeamMemberCreateBulk) OnConflict(opts ...sql.ConflictOption) *TeamMemberUpsertBulk {
|
|
_c.conflict = opts
|
|
return &TeamMemberUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.TeamMember.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *TeamMemberCreateBulk) OnConflictColumns(columns ...string) *TeamMemberUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &TeamMemberUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// TeamMemberUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of TeamMember nodes.
|
|
type TeamMemberUpsertBulk struct {
|
|
create *TeamMemberCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.TeamMember.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(teammember.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *TeamMemberUpsertBulk) UpdateNewValues() *TeamMemberUpsertBulk {
|
|
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(teammember.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.TeamMember.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *TeamMemberUpsertBulk) Ignore() *TeamMemberUpsertBulk {
|
|
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 *TeamMemberUpsertBulk) DoNothing() *TeamMemberUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the TeamMemberCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *TeamMemberUpsertBulk) Update(set func(*TeamMemberUpsert)) *TeamMemberUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&TeamMemberUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetTeamID sets the "team_id" field.
|
|
func (u *TeamMemberUpsertBulk) SetTeamID(v uuid.UUID) *TeamMemberUpsertBulk {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.SetTeamID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTeamID sets the "team_id" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsertBulk) UpdateTeamID() *TeamMemberUpsertBulk {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.UpdateTeamID()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *TeamMemberUpsertBulk) SetUserID(v uuid.UUID) *TeamMemberUpsertBulk {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsertBulk) UpdateUserID() *TeamMemberUpsertBulk {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (u *TeamMemberUpsertBulk) SetRole(v consts.TeamMemberRole) *TeamMemberUpsertBulk {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.SetRole(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRole sets the "role" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsertBulk) UpdateRole() *TeamMemberUpsertBulk {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.UpdateRole()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *TeamMemberUpsertBulk) SetCreatedAt(v time.Time) *TeamMemberUpsertBulk {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *TeamMemberUpsertBulk) UpdateCreatedAt() *TeamMemberUpsertBulk {
|
|
return u.Update(func(s *TeamMemberUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *TeamMemberUpsertBulk) 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 TeamMemberCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for TeamMemberCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *TeamMemberUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|