mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 19:39:31 +08:00
878 lines
28 KiB
Go
878 lines
28 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/project"
|
|
"github.com/chaitin/MonkeyCode/backend/db/projectcollaborator"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ProjectCollaboratorCreate is the builder for creating a ProjectCollaborator entity.
|
|
type ProjectCollaboratorCreate struct {
|
|
config
|
|
mutation *ProjectCollaboratorMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_c *ProjectCollaboratorCreate) SetDeletedAt(v time.Time) *ProjectCollaboratorCreate {
|
|
_c.mutation.SetDeletedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_c *ProjectCollaboratorCreate) SetNillableDeletedAt(v *time.Time) *ProjectCollaboratorCreate {
|
|
if v != nil {
|
|
_c.SetDeletedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetProjectID sets the "project_id" field.
|
|
func (_c *ProjectCollaboratorCreate) SetProjectID(v uuid.UUID) *ProjectCollaboratorCreate {
|
|
_c.mutation.SetProjectID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *ProjectCollaboratorCreate) SetUserID(v uuid.UUID) *ProjectCollaboratorCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (_c *ProjectCollaboratorCreate) SetRole(v consts.ProjectCollaboratorRole) *ProjectCollaboratorCreate {
|
|
_c.mutation.SetRole(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableRole sets the "role" field if the given value is not nil.
|
|
func (_c *ProjectCollaboratorCreate) SetNillableRole(v *consts.ProjectCollaboratorRole) *ProjectCollaboratorCreate {
|
|
if v != nil {
|
|
_c.SetRole(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *ProjectCollaboratorCreate) SetCreatedAt(v time.Time) *ProjectCollaboratorCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *ProjectCollaboratorCreate) SetNillableCreatedAt(v *time.Time) *ProjectCollaboratorCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *ProjectCollaboratorCreate) SetUpdatedAt(v time.Time) *ProjectCollaboratorCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *ProjectCollaboratorCreate) SetNillableUpdatedAt(v *time.Time) *ProjectCollaboratorCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *ProjectCollaboratorCreate) SetID(v uuid.UUID) *ProjectCollaboratorCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (_c *ProjectCollaboratorCreate) SetUser(v *User) *ProjectCollaboratorCreate {
|
|
return _c.SetUserID(v.ID)
|
|
}
|
|
|
|
// SetProject sets the "project" edge to the Project entity.
|
|
func (_c *ProjectCollaboratorCreate) SetProject(v *Project) *ProjectCollaboratorCreate {
|
|
return _c.SetProjectID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the ProjectCollaboratorMutation object of the builder.
|
|
func (_c *ProjectCollaboratorCreate) Mutation() *ProjectCollaboratorMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the ProjectCollaborator in the database.
|
|
func (_c *ProjectCollaboratorCreate) Save(ctx context.Context) (*ProjectCollaborator, error) {
|
|
if err := _c.defaults(); err != nil {
|
|
return nil, err
|
|
}
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *ProjectCollaboratorCreate) SaveX(ctx context.Context) *ProjectCollaborator {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ProjectCollaboratorCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ProjectCollaboratorCreate) 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 *ProjectCollaboratorCreate) defaults() error {
|
|
if _, ok := _c.mutation.Role(); !ok {
|
|
v := projectcollaborator.DefaultRole
|
|
_c.mutation.SetRole(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
if projectcollaborator.DefaultCreatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized projectcollaborator.DefaultCreatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := projectcollaborator.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
if projectcollaborator.DefaultUpdatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized projectcollaborator.DefaultUpdatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := projectcollaborator.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *ProjectCollaboratorCreate) check() error {
|
|
if _, ok := _c.mutation.ProjectID(); !ok {
|
|
return &ValidationError{Name: "project_id", err: errors.New(`db: missing required field "ProjectCollaborator.project_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "ProjectCollaborator.user_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Role(); !ok {
|
|
return &ValidationError{Name: "role", err: errors.New(`db: missing required field "ProjectCollaborator.role"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "ProjectCollaborator.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "ProjectCollaborator.updated_at"`)}
|
|
}
|
|
if len(_c.mutation.UserIDs()) == 0 {
|
|
return &ValidationError{Name: "user", err: errors.New(`db: missing required edge "ProjectCollaborator.user"`)}
|
|
}
|
|
if len(_c.mutation.ProjectIDs()) == 0 {
|
|
return &ValidationError{Name: "project", err: errors.New(`db: missing required edge "ProjectCollaborator.project"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *ProjectCollaboratorCreate) sqlSave(ctx context.Context) (*ProjectCollaborator, 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 *ProjectCollaboratorCreate) createSpec() (*ProjectCollaborator, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &ProjectCollaborator{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(projectcollaborator.Table, sqlgraph.NewFieldSpec(projectcollaborator.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.DeletedAt(); ok {
|
|
_spec.SetField(projectcollaborator.FieldDeletedAt, field.TypeTime, value)
|
|
_node.DeletedAt = value
|
|
}
|
|
if value, ok := _c.mutation.Role(); ok {
|
|
_spec.SetField(projectcollaborator.FieldRole, field.TypeString, value)
|
|
_node.Role = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(projectcollaborator.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(projectcollaborator.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: projectcollaborator.UserTable,
|
|
Columns: []string{projectcollaborator.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)
|
|
}
|
|
if nodes := _c.mutation.ProjectIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: projectcollaborator.ProjectTable,
|
|
Columns: []string{projectcollaborator.ProjectColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.ProjectID = 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.ProjectCollaborator.Create().
|
|
// SetDeletedAt(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.ProjectCollaboratorUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ProjectCollaboratorCreate) OnConflict(opts ...sql.ConflictOption) *ProjectCollaboratorUpsertOne {
|
|
_c.conflict = opts
|
|
return &ProjectCollaboratorUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.ProjectCollaborator.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ProjectCollaboratorCreate) OnConflictColumns(columns ...string) *ProjectCollaboratorUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ProjectCollaboratorUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// ProjectCollaboratorUpsertOne is the builder for "upsert"-ing
|
|
// one ProjectCollaborator node.
|
|
ProjectCollaboratorUpsertOne struct {
|
|
create *ProjectCollaboratorCreate
|
|
}
|
|
|
|
// ProjectCollaboratorUpsert is the "OnConflict" setter.
|
|
ProjectCollaboratorUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ProjectCollaboratorUpsert) SetDeletedAt(v time.Time) *ProjectCollaboratorUpsert {
|
|
u.Set(projectcollaborator.FieldDeletedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsert) UpdateDeletedAt() *ProjectCollaboratorUpsert {
|
|
u.SetExcluded(projectcollaborator.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ProjectCollaboratorUpsert) ClearDeletedAt() *ProjectCollaboratorUpsert {
|
|
u.SetNull(projectcollaborator.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// SetProjectID sets the "project_id" field.
|
|
func (u *ProjectCollaboratorUpsert) SetProjectID(v uuid.UUID) *ProjectCollaboratorUpsert {
|
|
u.Set(projectcollaborator.FieldProjectID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateProjectID sets the "project_id" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsert) UpdateProjectID() *ProjectCollaboratorUpsert {
|
|
u.SetExcluded(projectcollaborator.FieldProjectID)
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ProjectCollaboratorUpsert) SetUserID(v uuid.UUID) *ProjectCollaboratorUpsert {
|
|
u.Set(projectcollaborator.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsert) UpdateUserID() *ProjectCollaboratorUpsert {
|
|
u.SetExcluded(projectcollaborator.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (u *ProjectCollaboratorUpsert) SetRole(v consts.ProjectCollaboratorRole) *ProjectCollaboratorUpsert {
|
|
u.Set(projectcollaborator.FieldRole, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateRole sets the "role" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsert) UpdateRole() *ProjectCollaboratorUpsert {
|
|
u.SetExcluded(projectcollaborator.FieldRole)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ProjectCollaboratorUpsert) SetCreatedAt(v time.Time) *ProjectCollaboratorUpsert {
|
|
u.Set(projectcollaborator.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsert) UpdateCreatedAt() *ProjectCollaboratorUpsert {
|
|
u.SetExcluded(projectcollaborator.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ProjectCollaboratorUpsert) SetUpdatedAt(v time.Time) *ProjectCollaboratorUpsert {
|
|
u.Set(projectcollaborator.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsert) UpdateUpdatedAt() *ProjectCollaboratorUpsert {
|
|
u.SetExcluded(projectcollaborator.FieldUpdatedAt)
|
|
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.ProjectCollaborator.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(projectcollaborator.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ProjectCollaboratorUpsertOne) UpdateNewValues() *ProjectCollaboratorUpsertOne {
|
|
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(projectcollaborator.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.ProjectCollaborator.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ProjectCollaboratorUpsertOne) Ignore() *ProjectCollaboratorUpsertOne {
|
|
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 *ProjectCollaboratorUpsertOne) DoNothing() *ProjectCollaboratorUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ProjectCollaboratorCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *ProjectCollaboratorUpsertOne) Update(set func(*ProjectCollaboratorUpsert)) *ProjectCollaboratorUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ProjectCollaboratorUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ProjectCollaboratorUpsertOne) SetDeletedAt(v time.Time) *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertOne) UpdateDeletedAt() *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ProjectCollaboratorUpsertOne) ClearDeletedAt() *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetProjectID sets the "project_id" field.
|
|
func (u *ProjectCollaboratorUpsertOne) SetProjectID(v uuid.UUID) *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetProjectID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateProjectID sets the "project_id" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertOne) UpdateProjectID() *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateProjectID()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ProjectCollaboratorUpsertOne) SetUserID(v uuid.UUID) *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertOne) UpdateUserID() *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (u *ProjectCollaboratorUpsertOne) SetRole(v consts.ProjectCollaboratorRole) *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetRole(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRole sets the "role" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertOne) UpdateRole() *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateRole()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ProjectCollaboratorUpsertOne) SetCreatedAt(v time.Time) *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertOne) UpdateCreatedAt() *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ProjectCollaboratorUpsertOne) SetUpdatedAt(v time.Time) *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertOne) UpdateUpdatedAt() *ProjectCollaboratorUpsertOne {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ProjectCollaboratorUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for ProjectCollaboratorCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ProjectCollaboratorUpsertOne) 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 *ProjectCollaboratorUpsertOne) 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: ProjectCollaboratorUpsertOne.ID is not supported by MySQL driver. Use ProjectCollaboratorUpsertOne.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 *ProjectCollaboratorUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// ProjectCollaboratorCreateBulk is the builder for creating many ProjectCollaborator entities in bulk.
|
|
type ProjectCollaboratorCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ProjectCollaboratorCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the ProjectCollaborator entities in the database.
|
|
func (_c *ProjectCollaboratorCreateBulk) Save(ctx context.Context) ([]*ProjectCollaborator, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*ProjectCollaborator, 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.(*ProjectCollaboratorMutation)
|
|
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 *ProjectCollaboratorCreateBulk) SaveX(ctx context.Context) []*ProjectCollaborator {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ProjectCollaboratorCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ProjectCollaboratorCreateBulk) 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.ProjectCollaborator.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.ProjectCollaboratorUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ProjectCollaboratorCreateBulk) OnConflict(opts ...sql.ConflictOption) *ProjectCollaboratorUpsertBulk {
|
|
_c.conflict = opts
|
|
return &ProjectCollaboratorUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.ProjectCollaborator.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ProjectCollaboratorCreateBulk) OnConflictColumns(columns ...string) *ProjectCollaboratorUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ProjectCollaboratorUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// ProjectCollaboratorUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of ProjectCollaborator nodes.
|
|
type ProjectCollaboratorUpsertBulk struct {
|
|
create *ProjectCollaboratorCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.ProjectCollaborator.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(projectcollaborator.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ProjectCollaboratorUpsertBulk) UpdateNewValues() *ProjectCollaboratorUpsertBulk {
|
|
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(projectcollaborator.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.ProjectCollaborator.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ProjectCollaboratorUpsertBulk) Ignore() *ProjectCollaboratorUpsertBulk {
|
|
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 *ProjectCollaboratorUpsertBulk) DoNothing() *ProjectCollaboratorUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ProjectCollaboratorCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *ProjectCollaboratorUpsertBulk) Update(set func(*ProjectCollaboratorUpsert)) *ProjectCollaboratorUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ProjectCollaboratorUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ProjectCollaboratorUpsertBulk) SetDeletedAt(v time.Time) *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertBulk) UpdateDeletedAt() *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ProjectCollaboratorUpsertBulk) ClearDeletedAt() *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetProjectID sets the "project_id" field.
|
|
func (u *ProjectCollaboratorUpsertBulk) SetProjectID(v uuid.UUID) *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetProjectID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateProjectID sets the "project_id" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertBulk) UpdateProjectID() *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateProjectID()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ProjectCollaboratorUpsertBulk) SetUserID(v uuid.UUID) *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertBulk) UpdateUserID() *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (u *ProjectCollaboratorUpsertBulk) SetRole(v consts.ProjectCollaboratorRole) *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetRole(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRole sets the "role" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertBulk) UpdateRole() *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateRole()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ProjectCollaboratorUpsertBulk) SetCreatedAt(v time.Time) *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertBulk) UpdateCreatedAt() *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ProjectCollaboratorUpsertBulk) SetUpdatedAt(v time.Time) *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ProjectCollaboratorUpsertBulk) UpdateUpdatedAt() *ProjectCollaboratorUpsertBulk {
|
|
return u.Update(func(s *ProjectCollaboratorUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ProjectCollaboratorUpsertBulk) 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 ProjectCollaboratorCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for ProjectCollaboratorCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ProjectCollaboratorUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|