mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 11:28:46 +08:00
- 新增 git_bots, git_bot_users, git_bot_tasks, project_git_bots 表 - 添加 user, host, project 到 gitbot 的关联边 - 使用 soft delete 和 created_at 游标
1539 lines
44 KiB
Go
1539 lines
44 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/gitbot"
|
|
"github.com/chaitin/MonkeyCode/backend/db/gitidentity"
|
|
"github.com/chaitin/MonkeyCode/backend/db/image"
|
|
"github.com/chaitin/MonkeyCode/backend/db/project"
|
|
"github.com/chaitin/MonkeyCode/backend/db/projectcollaborator"
|
|
"github.com/chaitin/MonkeyCode/backend/db/projectgitbot"
|
|
"github.com/chaitin/MonkeyCode/backend/db/projectissue"
|
|
"github.com/chaitin/MonkeyCode/backend/db/projecttask"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ProjectCreate is the builder for creating a Project entity.
|
|
type ProjectCreate struct {
|
|
config
|
|
mutation *ProjectMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_c *ProjectCreate) SetDeletedAt(v time.Time) *ProjectCreate {
|
|
_c.mutation.SetDeletedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_c *ProjectCreate) SetNillableDeletedAt(v *time.Time) *ProjectCreate {
|
|
if v != nil {
|
|
_c.SetDeletedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *ProjectCreate) SetUserID(v uuid.UUID) *ProjectCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_c *ProjectCreate) SetName(v string) *ProjectCreate {
|
|
_c.mutation.SetName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_c *ProjectCreate) SetDescription(v string) *ProjectCreate {
|
|
_c.mutation.SetDescription(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_c *ProjectCreate) SetNillableDescription(v *string) *ProjectCreate {
|
|
if v != nil {
|
|
_c.SetDescription(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetPlatform sets the "platform" field.
|
|
func (_c *ProjectCreate) SetPlatform(v consts.GitPlatform) *ProjectCreate {
|
|
_c.mutation.SetPlatform(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillablePlatform sets the "platform" field if the given value is not nil.
|
|
func (_c *ProjectCreate) SetNillablePlatform(v *consts.GitPlatform) *ProjectCreate {
|
|
if v != nil {
|
|
_c.SetPlatform(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetRepoURL sets the "repo_url" field.
|
|
func (_c *ProjectCreate) SetRepoURL(v string) *ProjectCreate {
|
|
_c.mutation.SetRepoURL(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableRepoURL sets the "repo_url" field if the given value is not nil.
|
|
func (_c *ProjectCreate) SetNillableRepoURL(v *string) *ProjectCreate {
|
|
if v != nil {
|
|
_c.SetRepoURL(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetBranch sets the "branch" field.
|
|
func (_c *ProjectCreate) SetBranch(v string) *ProjectCreate {
|
|
_c.mutation.SetBranch(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableBranch sets the "branch" field if the given value is not nil.
|
|
func (_c *ProjectCreate) SetNillableBranch(v *string) *ProjectCreate {
|
|
if v != nil {
|
|
_c.SetBranch(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetGitIdentityID sets the "git_identity_id" field.
|
|
func (_c *ProjectCreate) SetGitIdentityID(v uuid.UUID) *ProjectCreate {
|
|
_c.mutation.SetGitIdentityID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableGitIdentityID sets the "git_identity_id" field if the given value is not nil.
|
|
func (_c *ProjectCreate) SetNillableGitIdentityID(v *uuid.UUID) *ProjectCreate {
|
|
if v != nil {
|
|
_c.SetGitIdentityID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetImageID sets the "image_id" field.
|
|
func (_c *ProjectCreate) SetImageID(v uuid.UUID) *ProjectCreate {
|
|
_c.mutation.SetImageID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableImageID sets the "image_id" field if the given value is not nil.
|
|
func (_c *ProjectCreate) SetNillableImageID(v *uuid.UUID) *ProjectCreate {
|
|
if v != nil {
|
|
_c.SetImageID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetEnvVariables sets the "env_variables" field.
|
|
func (_c *ProjectCreate) SetEnvVariables(v map[string]interface{}) *ProjectCreate {
|
|
_c.mutation.SetEnvVariables(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *ProjectCreate) SetCreatedAt(v time.Time) *ProjectCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *ProjectCreate) SetNillableCreatedAt(v *time.Time) *ProjectCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *ProjectCreate) SetUpdatedAt(v time.Time) *ProjectCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *ProjectCreate) SetNillableUpdatedAt(v *time.Time) *ProjectCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *ProjectCreate) SetID(v uuid.UUID) *ProjectCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (_c *ProjectCreate) SetUser(v *User) *ProjectCreate {
|
|
return _c.SetUserID(v.ID)
|
|
}
|
|
|
|
// SetGitIdentity sets the "git_identity" edge to the GitIdentity entity.
|
|
func (_c *ProjectCreate) SetGitIdentity(v *GitIdentity) *ProjectCreate {
|
|
return _c.SetGitIdentityID(v.ID)
|
|
}
|
|
|
|
// SetImage sets the "image" edge to the Image entity.
|
|
func (_c *ProjectCreate) SetImage(v *Image) *ProjectCreate {
|
|
return _c.SetImageID(v.ID)
|
|
}
|
|
|
|
// AddIssueIDs adds the "issues" edge to the ProjectIssue entity by IDs.
|
|
func (_c *ProjectCreate) AddIssueIDs(ids ...uuid.UUID) *ProjectCreate {
|
|
_c.mutation.AddIssueIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddIssues adds the "issues" edges to the ProjectIssue entity.
|
|
func (_c *ProjectCreate) AddIssues(v ...*ProjectIssue) *ProjectCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddIssueIDs(ids...)
|
|
}
|
|
|
|
// AddCollaboratorIDs adds the "collaborators" edge to the ProjectCollaborator entity by IDs.
|
|
func (_c *ProjectCreate) AddCollaboratorIDs(ids ...uuid.UUID) *ProjectCreate {
|
|
_c.mutation.AddCollaboratorIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddCollaborators adds the "collaborators" edges to the ProjectCollaborator entity.
|
|
func (_c *ProjectCreate) AddCollaborators(v ...*ProjectCollaborator) *ProjectCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddCollaboratorIDs(ids...)
|
|
}
|
|
|
|
// AddProjectTaskIDs adds the "project_tasks" edge to the ProjectTask entity by IDs.
|
|
func (_c *ProjectCreate) AddProjectTaskIDs(ids ...uuid.UUID) *ProjectCreate {
|
|
_c.mutation.AddProjectTaskIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddProjectTasks adds the "project_tasks" edges to the ProjectTask entity.
|
|
func (_c *ProjectCreate) AddProjectTasks(v ...*ProjectTask) *ProjectCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddProjectTaskIDs(ids...)
|
|
}
|
|
|
|
// AddGitBotIDs adds the "git_bots" edge to the GitBot entity by IDs.
|
|
func (_c *ProjectCreate) AddGitBotIDs(ids ...uuid.UUID) *ProjectCreate {
|
|
_c.mutation.AddGitBotIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddGitBots adds the "git_bots" edges to the GitBot entity.
|
|
func (_c *ProjectCreate) AddGitBots(v ...*GitBot) *ProjectCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddGitBotIDs(ids...)
|
|
}
|
|
|
|
// AddProjectGitBotIDs adds the "project_git_bots" edge to the ProjectGitBot entity by IDs.
|
|
func (_c *ProjectCreate) AddProjectGitBotIDs(ids ...uuid.UUID) *ProjectCreate {
|
|
_c.mutation.AddProjectGitBotIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddProjectGitBots adds the "project_git_bots" edges to the ProjectGitBot entity.
|
|
func (_c *ProjectCreate) AddProjectGitBots(v ...*ProjectGitBot) *ProjectCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddProjectGitBotIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the ProjectMutation object of the builder.
|
|
func (_c *ProjectCreate) Mutation() *ProjectMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the Project in the database.
|
|
func (_c *ProjectCreate) Save(ctx context.Context) (*Project, 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 *ProjectCreate) SaveX(ctx context.Context) *Project {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ProjectCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ProjectCreate) 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 *ProjectCreate) defaults() error {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
if project.DefaultCreatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized project.DefaultCreatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := project.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
if project.DefaultUpdatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized project.DefaultUpdatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := project.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *ProjectCreate) check() error {
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "Project.user_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Name(); !ok {
|
|
return &ValidationError{Name: "name", err: errors.New(`db: missing required field "Project.name"`)}
|
|
}
|
|
if v, ok := _c.mutation.Name(); ok {
|
|
if err := project.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Project.name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "Project.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "Project.updated_at"`)}
|
|
}
|
|
if len(_c.mutation.UserIDs()) == 0 {
|
|
return &ValidationError{Name: "user", err: errors.New(`db: missing required edge "Project.user"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *ProjectCreate) sqlSave(ctx context.Context) (*Project, 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 *ProjectCreate) createSpec() (*Project, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Project{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(project.Table, sqlgraph.NewFieldSpec(project.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(project.FieldDeletedAt, field.TypeTime, value)
|
|
_node.DeletedAt = value
|
|
}
|
|
if value, ok := _c.mutation.Name(); ok {
|
|
_spec.SetField(project.FieldName, field.TypeString, value)
|
|
_node.Name = value
|
|
}
|
|
if value, ok := _c.mutation.Description(); ok {
|
|
_spec.SetField(project.FieldDescription, field.TypeString, value)
|
|
_node.Description = value
|
|
}
|
|
if value, ok := _c.mutation.Platform(); ok {
|
|
_spec.SetField(project.FieldPlatform, field.TypeString, value)
|
|
_node.Platform = value
|
|
}
|
|
if value, ok := _c.mutation.RepoURL(); ok {
|
|
_spec.SetField(project.FieldRepoURL, field.TypeString, value)
|
|
_node.RepoURL = value
|
|
}
|
|
if value, ok := _c.mutation.Branch(); ok {
|
|
_spec.SetField(project.FieldBranch, field.TypeString, value)
|
|
_node.Branch = value
|
|
}
|
|
if value, ok := _c.mutation.EnvVariables(); ok {
|
|
_spec.SetField(project.FieldEnvVariables, field.TypeJSON, value)
|
|
_node.EnvVariables = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(project.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(project.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: project.UserTable,
|
|
Columns: []string{project.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.GitIdentityIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: project.GitIdentityTable,
|
|
Columns: []string{project.GitIdentityColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(gitidentity.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.GitIdentityID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.ImageIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: project.ImageTable,
|
|
Columns: []string{project.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)
|
|
}
|
|
if nodes := _c.mutation.IssuesIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: project.IssuesTable,
|
|
Columns: []string{project.IssuesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(projectissue.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.CollaboratorsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: project.CollaboratorsTable,
|
|
Columns: []string{project.CollaboratorsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(projectcollaborator.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.ProjectTasksIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: project.ProjectTasksTable,
|
|
Columns: []string{project.ProjectTasksColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(projecttask.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.GitBotsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: project.GitBotsTable,
|
|
Columns: project.GitBotsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(gitbot.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &ProjectGitBotCreate{config: _c.config, mutation: newProjectGitBotMutation(_c.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
if specE.ID.Value != nil {
|
|
edge.Target.Fields = append(edge.Target.Fields, specE.ID)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.ProjectGitBotsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: true,
|
|
Table: project.ProjectGitBotsTable,
|
|
Columns: []string{project.ProjectGitBotsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(projectgitbot.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_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.Project.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.ProjectUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ProjectCreate) OnConflict(opts ...sql.ConflictOption) *ProjectUpsertOne {
|
|
_c.conflict = opts
|
|
return &ProjectUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Project.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ProjectCreate) OnConflictColumns(columns ...string) *ProjectUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ProjectUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// ProjectUpsertOne is the builder for "upsert"-ing
|
|
// one Project node.
|
|
ProjectUpsertOne struct {
|
|
create *ProjectCreate
|
|
}
|
|
|
|
// ProjectUpsert is the "OnConflict" setter.
|
|
ProjectUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ProjectUpsert) SetDeletedAt(v time.Time) *ProjectUpsert {
|
|
u.Set(project.FieldDeletedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateDeletedAt() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ProjectUpsert) ClearDeletedAt() *ProjectUpsert {
|
|
u.SetNull(project.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ProjectUpsert) SetUserID(v uuid.UUID) *ProjectUpsert {
|
|
u.Set(project.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateUserID() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *ProjectUpsert) SetName(v string) *ProjectUpsert {
|
|
u.Set(project.FieldName, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateName() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldName)
|
|
return u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (u *ProjectUpsert) SetDescription(v string) *ProjectUpsert {
|
|
u.Set(project.FieldDescription, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateDescription() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldDescription)
|
|
return u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (u *ProjectUpsert) ClearDescription() *ProjectUpsert {
|
|
u.SetNull(project.FieldDescription)
|
|
return u
|
|
}
|
|
|
|
// SetPlatform sets the "platform" field.
|
|
func (u *ProjectUpsert) SetPlatform(v consts.GitPlatform) *ProjectUpsert {
|
|
u.Set(project.FieldPlatform, v)
|
|
return u
|
|
}
|
|
|
|
// UpdatePlatform sets the "platform" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdatePlatform() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldPlatform)
|
|
return u
|
|
}
|
|
|
|
// ClearPlatform clears the value of the "platform" field.
|
|
func (u *ProjectUpsert) ClearPlatform() *ProjectUpsert {
|
|
u.SetNull(project.FieldPlatform)
|
|
return u
|
|
}
|
|
|
|
// SetRepoURL sets the "repo_url" field.
|
|
func (u *ProjectUpsert) SetRepoURL(v string) *ProjectUpsert {
|
|
u.Set(project.FieldRepoURL, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateRepoURL sets the "repo_url" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateRepoURL() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldRepoURL)
|
|
return u
|
|
}
|
|
|
|
// ClearRepoURL clears the value of the "repo_url" field.
|
|
func (u *ProjectUpsert) ClearRepoURL() *ProjectUpsert {
|
|
u.SetNull(project.FieldRepoURL)
|
|
return u
|
|
}
|
|
|
|
// SetBranch sets the "branch" field.
|
|
func (u *ProjectUpsert) SetBranch(v string) *ProjectUpsert {
|
|
u.Set(project.FieldBranch, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateBranch sets the "branch" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateBranch() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldBranch)
|
|
return u
|
|
}
|
|
|
|
// ClearBranch clears the value of the "branch" field.
|
|
func (u *ProjectUpsert) ClearBranch() *ProjectUpsert {
|
|
u.SetNull(project.FieldBranch)
|
|
return u
|
|
}
|
|
|
|
// SetGitIdentityID sets the "git_identity_id" field.
|
|
func (u *ProjectUpsert) SetGitIdentityID(v uuid.UUID) *ProjectUpsert {
|
|
u.Set(project.FieldGitIdentityID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateGitIdentityID sets the "git_identity_id" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateGitIdentityID() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldGitIdentityID)
|
|
return u
|
|
}
|
|
|
|
// ClearGitIdentityID clears the value of the "git_identity_id" field.
|
|
func (u *ProjectUpsert) ClearGitIdentityID() *ProjectUpsert {
|
|
u.SetNull(project.FieldGitIdentityID)
|
|
return u
|
|
}
|
|
|
|
// SetImageID sets the "image_id" field.
|
|
func (u *ProjectUpsert) SetImageID(v uuid.UUID) *ProjectUpsert {
|
|
u.Set(project.FieldImageID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateImageID sets the "image_id" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateImageID() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldImageID)
|
|
return u
|
|
}
|
|
|
|
// ClearImageID clears the value of the "image_id" field.
|
|
func (u *ProjectUpsert) ClearImageID() *ProjectUpsert {
|
|
u.SetNull(project.FieldImageID)
|
|
return u
|
|
}
|
|
|
|
// SetEnvVariables sets the "env_variables" field.
|
|
func (u *ProjectUpsert) SetEnvVariables(v map[string]interface{}) *ProjectUpsert {
|
|
u.Set(project.FieldEnvVariables, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateEnvVariables sets the "env_variables" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateEnvVariables() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldEnvVariables)
|
|
return u
|
|
}
|
|
|
|
// ClearEnvVariables clears the value of the "env_variables" field.
|
|
func (u *ProjectUpsert) ClearEnvVariables() *ProjectUpsert {
|
|
u.SetNull(project.FieldEnvVariables)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ProjectUpsert) SetCreatedAt(v time.Time) *ProjectUpsert {
|
|
u.Set(project.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateCreatedAt() *ProjectUpsert {
|
|
u.SetExcluded(project.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ProjectUpsert) SetUpdatedAt(v time.Time) *ProjectUpsert {
|
|
u.Set(project.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ProjectUpsert) UpdateUpdatedAt() *ProjectUpsert {
|
|
u.SetExcluded(project.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.Project.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(project.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ProjectUpsertOne) UpdateNewValues() *ProjectUpsertOne {
|
|
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(project.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Project.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ProjectUpsertOne) Ignore() *ProjectUpsertOne {
|
|
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 *ProjectUpsertOne) DoNothing() *ProjectUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ProjectCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *ProjectUpsertOne) Update(set func(*ProjectUpsert)) *ProjectUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ProjectUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ProjectUpsertOne) SetDeletedAt(v time.Time) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateDeletedAt() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ProjectUpsertOne) ClearDeletedAt() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ProjectUpsertOne) SetUserID(v uuid.UUID) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateUserID() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *ProjectUpsertOne) SetName(v string) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateName() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateName()
|
|
})
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (u *ProjectUpsertOne) SetDescription(v string) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetDescription(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateDescription() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateDescription()
|
|
})
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (u *ProjectUpsertOne) ClearDescription() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearDescription()
|
|
})
|
|
}
|
|
|
|
// SetPlatform sets the "platform" field.
|
|
func (u *ProjectUpsertOne) SetPlatform(v consts.GitPlatform) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetPlatform(v)
|
|
})
|
|
}
|
|
|
|
// UpdatePlatform sets the "platform" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdatePlatform() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdatePlatform()
|
|
})
|
|
}
|
|
|
|
// ClearPlatform clears the value of the "platform" field.
|
|
func (u *ProjectUpsertOne) ClearPlatform() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearPlatform()
|
|
})
|
|
}
|
|
|
|
// SetRepoURL sets the "repo_url" field.
|
|
func (u *ProjectUpsertOne) SetRepoURL(v string) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetRepoURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRepoURL sets the "repo_url" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateRepoURL() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateRepoURL()
|
|
})
|
|
}
|
|
|
|
// ClearRepoURL clears the value of the "repo_url" field.
|
|
func (u *ProjectUpsertOne) ClearRepoURL() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearRepoURL()
|
|
})
|
|
}
|
|
|
|
// SetBranch sets the "branch" field.
|
|
func (u *ProjectUpsertOne) SetBranch(v string) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetBranch(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBranch sets the "branch" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateBranch() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateBranch()
|
|
})
|
|
}
|
|
|
|
// ClearBranch clears the value of the "branch" field.
|
|
func (u *ProjectUpsertOne) ClearBranch() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearBranch()
|
|
})
|
|
}
|
|
|
|
// SetGitIdentityID sets the "git_identity_id" field.
|
|
func (u *ProjectUpsertOne) SetGitIdentityID(v uuid.UUID) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetGitIdentityID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateGitIdentityID sets the "git_identity_id" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateGitIdentityID() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateGitIdentityID()
|
|
})
|
|
}
|
|
|
|
// ClearGitIdentityID clears the value of the "git_identity_id" field.
|
|
func (u *ProjectUpsertOne) ClearGitIdentityID() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearGitIdentityID()
|
|
})
|
|
}
|
|
|
|
// SetImageID sets the "image_id" field.
|
|
func (u *ProjectUpsertOne) SetImageID(v uuid.UUID) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetImageID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateImageID sets the "image_id" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateImageID() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateImageID()
|
|
})
|
|
}
|
|
|
|
// ClearImageID clears the value of the "image_id" field.
|
|
func (u *ProjectUpsertOne) ClearImageID() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearImageID()
|
|
})
|
|
}
|
|
|
|
// SetEnvVariables sets the "env_variables" field.
|
|
func (u *ProjectUpsertOne) SetEnvVariables(v map[string]interface{}) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetEnvVariables(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEnvVariables sets the "env_variables" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateEnvVariables() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateEnvVariables()
|
|
})
|
|
}
|
|
|
|
// ClearEnvVariables clears the value of the "env_variables" field.
|
|
func (u *ProjectUpsertOne) ClearEnvVariables() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearEnvVariables()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ProjectUpsertOne) SetCreatedAt(v time.Time) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateCreatedAt() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ProjectUpsertOne) SetUpdatedAt(v time.Time) *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ProjectUpsertOne) UpdateUpdatedAt() *ProjectUpsertOne {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ProjectUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for ProjectCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ProjectUpsertOne) 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 *ProjectUpsertOne) 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: ProjectUpsertOne.ID is not supported by MySQL driver. Use ProjectUpsertOne.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 *ProjectUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// ProjectCreateBulk is the builder for creating many Project entities in bulk.
|
|
type ProjectCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ProjectCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the Project entities in the database.
|
|
func (_c *ProjectCreateBulk) Save(ctx context.Context) ([]*Project, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*Project, 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.(*ProjectMutation)
|
|
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 *ProjectCreateBulk) SaveX(ctx context.Context) []*Project {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ProjectCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ProjectCreateBulk) 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.Project.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.ProjectUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ProjectCreateBulk) OnConflict(opts ...sql.ConflictOption) *ProjectUpsertBulk {
|
|
_c.conflict = opts
|
|
return &ProjectUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Project.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ProjectCreateBulk) OnConflictColumns(columns ...string) *ProjectUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ProjectUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// ProjectUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of Project nodes.
|
|
type ProjectUpsertBulk struct {
|
|
create *ProjectCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.Project.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(project.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ProjectUpsertBulk) UpdateNewValues() *ProjectUpsertBulk {
|
|
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(project.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Project.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ProjectUpsertBulk) Ignore() *ProjectUpsertBulk {
|
|
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 *ProjectUpsertBulk) DoNothing() *ProjectUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ProjectCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *ProjectUpsertBulk) Update(set func(*ProjectUpsert)) *ProjectUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ProjectUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ProjectUpsertBulk) SetDeletedAt(v time.Time) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateDeletedAt() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ProjectUpsertBulk) ClearDeletedAt() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ProjectUpsertBulk) SetUserID(v uuid.UUID) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateUserID() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *ProjectUpsertBulk) SetName(v string) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateName() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateName()
|
|
})
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (u *ProjectUpsertBulk) SetDescription(v string) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetDescription(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateDescription() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateDescription()
|
|
})
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (u *ProjectUpsertBulk) ClearDescription() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearDescription()
|
|
})
|
|
}
|
|
|
|
// SetPlatform sets the "platform" field.
|
|
func (u *ProjectUpsertBulk) SetPlatform(v consts.GitPlatform) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetPlatform(v)
|
|
})
|
|
}
|
|
|
|
// UpdatePlatform sets the "platform" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdatePlatform() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdatePlatform()
|
|
})
|
|
}
|
|
|
|
// ClearPlatform clears the value of the "platform" field.
|
|
func (u *ProjectUpsertBulk) ClearPlatform() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearPlatform()
|
|
})
|
|
}
|
|
|
|
// SetRepoURL sets the "repo_url" field.
|
|
func (u *ProjectUpsertBulk) SetRepoURL(v string) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetRepoURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRepoURL sets the "repo_url" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateRepoURL() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateRepoURL()
|
|
})
|
|
}
|
|
|
|
// ClearRepoURL clears the value of the "repo_url" field.
|
|
func (u *ProjectUpsertBulk) ClearRepoURL() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearRepoURL()
|
|
})
|
|
}
|
|
|
|
// SetBranch sets the "branch" field.
|
|
func (u *ProjectUpsertBulk) SetBranch(v string) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetBranch(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBranch sets the "branch" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateBranch() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateBranch()
|
|
})
|
|
}
|
|
|
|
// ClearBranch clears the value of the "branch" field.
|
|
func (u *ProjectUpsertBulk) ClearBranch() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearBranch()
|
|
})
|
|
}
|
|
|
|
// SetGitIdentityID sets the "git_identity_id" field.
|
|
func (u *ProjectUpsertBulk) SetGitIdentityID(v uuid.UUID) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetGitIdentityID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateGitIdentityID sets the "git_identity_id" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateGitIdentityID() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateGitIdentityID()
|
|
})
|
|
}
|
|
|
|
// ClearGitIdentityID clears the value of the "git_identity_id" field.
|
|
func (u *ProjectUpsertBulk) ClearGitIdentityID() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearGitIdentityID()
|
|
})
|
|
}
|
|
|
|
// SetImageID sets the "image_id" field.
|
|
func (u *ProjectUpsertBulk) SetImageID(v uuid.UUID) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetImageID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateImageID sets the "image_id" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateImageID() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateImageID()
|
|
})
|
|
}
|
|
|
|
// ClearImageID clears the value of the "image_id" field.
|
|
func (u *ProjectUpsertBulk) ClearImageID() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearImageID()
|
|
})
|
|
}
|
|
|
|
// SetEnvVariables sets the "env_variables" field.
|
|
func (u *ProjectUpsertBulk) SetEnvVariables(v map[string]interface{}) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetEnvVariables(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEnvVariables sets the "env_variables" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateEnvVariables() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateEnvVariables()
|
|
})
|
|
}
|
|
|
|
// ClearEnvVariables clears the value of the "env_variables" field.
|
|
func (u *ProjectUpsertBulk) ClearEnvVariables() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.ClearEnvVariables()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ProjectUpsertBulk) SetCreatedAt(v time.Time) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateCreatedAt() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ProjectUpsertBulk) SetUpdatedAt(v time.Time) *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ProjectUpsertBulk) UpdateUpdatedAt() *ProjectUpsertBulk {
|
|
return u.Update(func(s *ProjectUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ProjectUpsertBulk) 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 ProjectCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for ProjectCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ProjectUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|