Merge pull request #697 from chaitin/codex/backend-logic-commits

补齐团队 Skills 后端存储逻辑
This commit is contained in:
Yoko authored and GitHub committed 2026-06-12 20:05:42 +08:00
commit ca7f390d6f
68 files changed
+18635 -97

No files matched your search

+245
View File
@@ -0,0 +1,245 @@
package v1
import (
"encoding/json"
"fmt"
"io"
"mime/multipart"
"github.com/GoYoko/web"
"github.com/google/uuid"
"github.com/samber/do"
"github.com/chaitin/MonkeyCode/backend/config"
"github.com/chaitin/MonkeyCode/backend/domain"
"github.com/chaitin/MonkeyCode/backend/errcode"
"github.com/chaitin/MonkeyCode/backend/middleware"
)
type TeamSkillHandler struct {
usecase domain.TeamSkillUsecase
cfg *config.Config
}
func NewTeamSkillHandler(i *do.Injector) (*TeamSkillHandler, error) {
w := do.MustInvoke[*web.Web](i)
auth := do.MustInvoke[*middleware.AuthMiddleware](i)
audit := do.MustInvoke[*middleware.AuditMiddleware](i)
h := &TeamSkillHandler{
usecase: do.MustInvoke[domain.TeamSkillUsecase](i),
cfg: do.MustInvoke[*config.Config](i),
}
g := w.Group("/api/v1/teams/skills")
g.Use(auth.TeamAuth())
g.GET("", web.BaseHandler(h.List))
g.POST("", web.BindHandler(h.Add), audit.Audit("add_team_skill"))
g.POST("/package", web.BindHandler(h.AddPackage), audit.Audit("add_team_skill_package"))
g.PUT("/:skill_id", web.BindHandler(h.Update), audit.Audit("update_team_skill"))
g.DELETE("/:skill_id", web.BindHandler(h.Delete), audit.Audit("delete_team_skill"))
return h, nil
}
type addTeamSkillPackageFormReq struct {
Name string `form:"name" validate:"required"`
Description string `form:"description" validate:"required"`
Tags string `form:"tags"`
Content string `form:"content" validate:"required"`
GroupIDs string `form:"group_ids"`
SourceType string `form:"source_type" validate:"required"`
SourceLabel string `form:"source_label" validate:"required"`
SkillMDPath string `form:"skill_md_path"`
File *multipart.FileHeader `form:"file" validate:"required"`
}
// List 获取团队 Skill 列表
//
// @Summary 获取团队 Skill 列表
// @Description 获取团队 Skill 列表
// @Tags 【Team 管理员】Skill 管理
// @Accept json
// @Produce json
// @Security MonkeyCodeAITeamAuth
// @Success 200 {object} web.Resp{data=domain.ListTeamSkillsResp} "成功"
// @Failure 401 {object} web.Resp "未授权"
// @Failure 500 {object} web.Resp "服务器内部错误"
// @Router /api/v1/teams/skills [get]
func (h *TeamSkillHandler) List(c *web.Context) error {
teamUser := middleware.GetTeamUser(c)
resp, err := h.usecase.List(c.Request().Context(), teamUser)
if err != nil {
return err
}
return c.Success(resp)
}
// Add 添加团队 Skill
//
// @Summary 添加团队 Skill
// @Description 添加团队 Skill
// @Tags 【Team 管理员】Skill 管理
// @Accept json
// @Produce json
// @Security MonkeyCodeAITeamAuth
// @Param req body domain.AddTeamSkillReq true "请求参数"
// @Success 200 {object} web.Resp{data=domain.TeamSkill} "成功"
// @Failure 401 {object} web.Resp "未授权"
// @Failure 500 {object} web.Resp "服务器内部错误"
// @Router /api/v1/teams/skills [post]
func (h *TeamSkillHandler) Add(c *web.Context, req domain.AddTeamSkillReq) error {
teamUser := middleware.GetTeamUser(c)
resp, err := h.usecase.Add(c.Request().Context(), teamUser, &req)
if err != nil {
return err
}
return c.Success(resp)
}
// AddPackage 上传团队 Skill zip 包
//
// @Summary 上传团队 Skill zip 包
// @Description 上传团队 Skill zip 包
// @Tags 【Team 管理员】Skill 管理
// @Accept multipart/form-data
// @Produce json
// @Security MonkeyCodeAITeamAuth
// @Param name formData string true "Skill 名称"
// @Param description formData string true "Skill 描述"
// @Param tags formData string false "JSON 字符串数组"
// @Param content formData string true "SKILL.md 原文"
// @Param group_ids formData string false "JSON 字符串数组"
// @Param source_type formData string true "来源类型"
// @Param source_label formData string true "来源标签"
// @Param skill_md_path formData string false "zip 内 SKILL.md 路径"
// @Param file formData file true "Skill zip 包"
// @Success 200 {object} web.Resp{data=domain.TeamSkill} "成功"
// @Failure 401 {object} web.Resp "未授权"
// @Failure 500 {object} web.Resp "服务器内部错误"
// @Router /api/v1/teams/skills/package [post]
func (h *TeamSkillHandler) AddPackage(c *web.Context, req addTeamSkillPackageFormReq) error {
teamUser := middleware.GetTeamUser(c)
data, err := h.readPackageFile(req.File)
if err != nil {
return err
}
tags, err := parseStringSlice(req.Tags)
if err != nil {
return err
}
groupIDs, err := parseUUIDSlice(req.GroupIDs)
if err != nil {
return err
}
resp, err := h.usecase.AddPackage(c.Request().Context(), teamUser, &domain.AddTeamSkillPackageReq{
AddTeamSkillReq: domain.AddTeamSkillReq{
Name: req.Name,
Description: req.Description,
Tags: tags,
Content: req.Content,
GroupIDs: groupIDs,
SourceType: req.SourceType,
SourceLabel: req.SourceLabel,
SkillMDPath: req.SkillMDPath,
},
PackageFilename: req.File.Filename,
PackageData: data,
})
if err != nil {
return err
}
return c.Success(resp)
}
// Update 更新团队 Skill
//
// @Summary 更新团队 Skill
// @Description 更新团队 Skill
// @Tags 【Team 管理员】Skill 管理
// @Accept json
// @Produce json
// @Security MonkeyCodeAITeamAuth
// @Param skill_id path string true "Skill ID"
// @Param req body domain.UpdateTeamSkillReq true "请求参数"
// @Success 200 {object} web.Resp{data=domain.TeamSkill} "成功"
// @Failure 401 {object} web.Resp "未授权"
// @Failure 500 {object} web.Resp "服务器内部错误"
// @Router /api/v1/teams/skills/{skill_id} [put]
func (h *TeamSkillHandler) Update(c *web.Context, req domain.UpdateTeamSkillReq) error {
teamUser := middleware.GetTeamUser(c)
resp, err := h.usecase.Update(c.Request().Context(), teamUser, &req)
if err != nil {
return err
}
return c.Success(resp)
}
// Delete 删除团队 Skill
//
// @Summary 删除团队 Skill
// @Description 删除团队 Skill
// @Tags 【Team 管理员】Skill 管理
// @Accept json
// @Produce json
// @Security MonkeyCodeAITeamAuth
// @Param skill_id path string true "Skill ID"
// @Success 200 {object} web.Resp{} "成功"
// @Failure 401 {object} web.Resp "未授权"
// @Failure 500 {object} web.Resp "服务器内部错误"
// @Router /api/v1/teams/skills/{skill_id} [delete]
func (h *TeamSkillHandler) Delete(c *web.Context, req domain.DeleteTeamSkillReq) error {
teamUser := middleware.GetTeamUser(c)
if err := h.usecase.Delete(c.Request().Context(), teamUser, &req); err != nil {
return err
}
return c.Success(nil)
}
func (h *TeamSkillHandler) readPackageFile(fileHeader *multipart.FileHeader) ([]byte, error) {
if fileHeader == nil {
return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("file is required"))
}
maxSize := h.cfg.ObjectStorage.MaxSize
if maxSize <= 0 {
maxSize = 50 << 20
}
if fileHeader.Size > maxSize {
return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("file exceeds limit"))
}
file, err := fileHeader.Open()
if err != nil {
return nil, err
}
defer file.Close()
data, err := io.ReadAll(io.LimitReader(file, maxSize+1))
if err != nil {
return nil, err
}
if int64(len(data)) > maxSize {
return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("file exceeds limit"))
}
return data, nil
}
func parseStringSlice(raw string) ([]string, error) {
if raw == "" {
return nil, nil
}
var values []string
if err := json.Unmarshal([]byte(raw), &values); err != nil {
return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("invalid string array"))
}
return values, nil
}
func parseUUIDSlice(raw string) ([]uuid.UUID, error) {
if raw == "" {
return nil, nil
}
var values []uuid.UUID
if err := json.Unmarshal([]byte(raw), &values); err != nil {
return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("invalid uuid array"))
}
return values, nil
}
+4
View File
@@ -24,6 +24,9 @@ func ProvideTeam(i *do.Injector) {
do.Provide(i, repo.NewTeamImageRepo)
do.Provide(i, usecase.NewTeamImageUsecase)
do.Provide(i, v1.NewTeamImageHandler)
do.Provide(i, repo.NewTeamSkillRepo)
do.Provide(i, usecase.NewTeamSkillUsecase)
do.Provide(i, v1.NewTeamSkillHandler)
do.Provide(i, repo.NewTeamHostRepo)
do.Provide(i, usecase.NewTeamHostUsecase)
do.Provide(i, v1.NewTeamHostHandler)
@@ -47,6 +50,7 @@ func InvokeTeam(i *do.Injector) {
do.MustInvoke[*v1.TeamDashboardHandler](i)
do.MustInvoke[*v1.TeamModelHandler](i)
do.MustInvoke[*v1.TeamImageHandler](i)
do.MustInvoke[*v1.TeamSkillHandler](i)
do.MustInvoke[*v1.TeamHostHandler](i)
do.MustInvoke[*v1.TeamPolicyHandler](i)
do.MustInvoke[*v1.TeamOIDCHandler](i)
+118
View File
@@ -15,6 +15,7 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/teamgrouphost"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupimage"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/chaitin/MonkeyCode/backend/domain"
"github.com/chaitin/MonkeyCode/backend/pkg/taskflow"
)
@@ -184,6 +185,112 @@ func TestTeamHostUpsertUsesDefaultGroupForNewHost(t *testing.T) {
}
}
func TestTeamSkillCreateUsesDefaultGroupWhenGroupIDsEmpty(t *testing.T) {
ctx := context.Background()
client := newTeamRepoTestDB(t)
teamID := createTeamRepoTestTeam(t, client)
userID := createTeamRepoTestUser(t, client)
group := createTeamRepoDefaultGroup(t, client, teamID)
repo := &teamSkillRepo{
db: client,
logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
}
skill, err := repo.Create(ctx, teamID, userID, &domain.AddTeamSkillReq{
Name: "code-review",
Description: "Review code changes",
Content: "---\nname: code-review\ndescription: Review code changes\n---\n",
Tags: []string{"review", "go"},
SourceType: "markdown",
SourceLabel: "SKILL.md",
})
if err != nil {
t.Fatal(err)
}
if exists := teamRepoSkillInGroup(t, client, group.ID, skill.ID); !exists {
t.Fatal("skill was not added to default group")
}
}
func TestTeamSkillCreateKeepsExplicitGroup(t *testing.T) {
ctx := context.Background()
client := newTeamRepoTestDB(t)
teamID := createTeamRepoTestTeam(t, client)
userID := createTeamRepoTestUser(t, client)
defaultGroup := createTeamRepoDefaultGroup(t, client, teamID)
customGroup := createTeamRepoGroup(t, client, teamID, "Skill 分组")
repo := &teamSkillRepo{
db: client,
logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
}
skill, err := repo.Create(ctx, teamID, userID, &domain.AddTeamSkillReq{
Name: "frontend-polish",
Description: "Polish frontend UX",
Content: "---\nname: frontend-polish\ndescription: Polish frontend UX\n---\n",
GroupIDs: []uuid.UUID{customGroup.ID},
SourceType: "markdown",
SourceLabel: "SKILL.md",
})
if err != nil {
t.Fatal(err)
}
if exists := teamRepoSkillInGroup(t, client, customGroup.ID, skill.ID); !exists {
t.Fatal("skill was not added to explicit group")
}
if exists := teamRepoSkillInGroup(t, client, defaultGroup.ID, skill.ID); exists {
t.Fatal("skill was added to default group despite explicit group")
}
}
func TestTeamSkillUpdateReplacesGroups(t *testing.T) {
ctx := context.Background()
client := newTeamRepoTestDB(t)
teamID := createTeamRepoTestTeam(t, client)
userID := createTeamRepoTestUser(t, client)
oldGroup := createTeamRepoGroup(t, client, teamID, "旧分组")
newGroup := createTeamRepoGroup(t, client, teamID, "新分组")
repo := &teamSkillRepo{
db: client,
logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
}
skill, err := repo.Create(ctx, teamID, userID, &domain.AddTeamSkillReq{
Name: "plan-writer",
Description: "Write plans",
Content: "---\nname: plan-writer\ndescription: Write plans\n---\n",
GroupIDs: []uuid.UUID{oldGroup.ID},
SourceType: "markdown",
SourceLabel: "SKILL.md",
})
if err != nil {
t.Fatal(err)
}
updated, err := repo.Update(ctx, teamID, &domain.UpdateTeamSkillReq{
SkillID: skill.ID,
Name: "plan-writer-v2",
Description: "Write implementation plans",
Tags: []string{"planning"},
GroupIDs: []uuid.UUID{newGroup.ID},
})
if err != nil {
t.Fatal(err)
}
if updated.Name != "plan-writer-v2" {
t.Fatalf("skill name = %q, want plan-writer-v2", updated.Name)
}
if exists := teamRepoSkillInGroup(t, client, oldGroup.ID, skill.ID); exists {
t.Fatal("skill still belongs to old group")
}
if exists := teamRepoSkillInGroup(t, client, newGroup.ID, skill.ID); !exists {
t.Fatal("skill was not added to new group")
}
}
func createTeamRepoTestUser(t *testing.T, client *db.Client) uuid.UUID {
t.Helper()
userID := uuid.New()
@@ -239,3 +346,14 @@ func teamRepoModelInGroup(t *testing.T, client *db.Client, groupID, modelID uuid
}
return exists
}
func teamRepoSkillInGroup(t *testing.T, client *db.Client, groupID, skillID uuid.UUID) bool {
t.Helper()
exists, err := client.TeamGroupSkill.Query().
Where(teamgroupskill.GroupIDEQ(groupID), teamgroupskill.SkillIDEQ(skillID)).
Exist(context.Background())
if err != nil {
t.Fatal(err)
}
return exists
}
+208
View File
@@ -0,0 +1,208 @@
package repo
import (
"context"
"log/slog"
"entgo.io/ent/dialect/sql"
"github.com/google/uuid"
"github.com/samber/do"
"github.com/chaitin/MonkeyCode/backend/db"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/chaitin/MonkeyCode/backend/domain"
"github.com/chaitin/MonkeyCode/backend/errcode"
"github.com/chaitin/MonkeyCode/backend/pkg/cvt"
"github.com/chaitin/MonkeyCode/backend/pkg/entx"
)
type teamSkillRepo struct {
db *db.Client
logger *slog.Logger
}
func NewTeamSkillRepo(i *do.Injector) (domain.TeamSkillRepo, error) {
return &teamSkillRepo{
db: do.MustInvoke[*db.Client](i),
logger: do.MustInvoke[*slog.Logger](i),
}, nil
}
func (r *teamSkillRepo) List(ctx context.Context, teamID uuid.UUID) ([]*db.Skill, error) {
tss, err := r.db.TeamSkill.Query().
WithSkill(func(sq *db.SkillQuery) {
sq.WithGroups()
}).
Where(teamskill.TeamID(teamID)).
Order(teamskill.ByCreatedAt(sql.OrderDesc())).
All(ctx)
if err != nil {
return nil, errcode.ErrDatabaseQuery.Wrap(err)
}
return cvt.Iter(tss, func(_ int, ts *db.TeamSkill) *db.Skill {
return ts.Edges.Skill
}), nil
}
func (r *teamSkillRepo) Create(ctx context.Context, teamID, userID uuid.UUID, req *domain.AddTeamSkillReq) (*db.Skill, error) {
var skillID uuid.UUID
err := entx.WithTx2(ctx, r.db, func(tx *db.Tx) error {
groupIDs, err := resolveTeamSkillGroupIDs(ctx, tx, teamID, req.GroupIDs)
if err != nil {
return err
}
newSkill, err := tx.Skill.Create().
SetID(uuid.New()).
SetUserID(userID).
SetName(req.Name).
SetDescription(req.Description).
SetTags(req.Tags).
SetContent(req.Content).
SetPackageObjectKey(req.PackageObjectKey).
SetPackageURL(req.PackageURL).
SetSourceType(req.SourceType).
SetSourceLabel(req.SourceLabel).
SetSkillMdPath(req.SkillMDPath).
Save(ctx)
if err != nil {
return err
}
skillID = newSkill.ID
if err := tx.TeamSkill.Create().
SetID(uuid.New()).
SetTeamID(teamID).
SetSkillID(newSkill.ID).
Exec(ctx); err != nil {
return err
}
return replaceTeamSkillGroups(ctx, tx, newSkill.ID, groupIDs)
})
if err != nil {
r.logger.Error("create team skill", "error", err)
return nil, errcode.ErrDatabaseOperation.Wrap(err)
}
return r.get(ctx, teamID, skillID)
}
func (r *teamSkillRepo) Update(ctx context.Context, teamID uuid.UUID, req *domain.UpdateTeamSkillReq) (*db.Skill, error) {
err := entx.WithTx2(ctx, r.db, func(tx *db.Tx) error {
groupIDs, err := resolveTeamSkillGroupIDs(ctx, tx, teamID, req.GroupIDs)
if err != nil {
return err
}
upt := tx.Skill.UpdateOneID(req.SkillID).Where(skill.HasTeamsWith(team.ID(teamID)))
if req.Name != "" {
upt.SetName(req.Name)
}
if req.Description != "" {
upt.SetDescription(req.Description)
}
if req.Tags != nil {
upt.SetTags(req.Tags)
}
if req.Content != "" {
upt.SetContent(req.Content)
}
if req.SourceType != "" {
upt.SetSourceType(req.SourceType)
}
if req.SourceLabel != "" {
upt.SetSourceLabel(req.SourceLabel)
}
if req.SkillMDPath != nil {
upt.SetSkillMdPath(*req.SkillMDPath)
}
if err := upt.Exec(ctx); err != nil {
return err
}
if req.GroupIDs != nil {
return replaceTeamSkillGroups(ctx, tx, req.SkillID, groupIDs)
}
return nil
})
if err != nil {
return nil, errcode.ErrDatabaseOperation.Wrap(err)
}
return r.get(ctx, teamID, req.SkillID)
}
func (r *teamSkillRepo) Delete(ctx context.Context, teamID, skillID uuid.UUID) error {
err := entx.WithTx2(ctx, r.db, func(tx *db.Tx) error {
if err := tx.Skill.DeleteOneID(skillID).Where(skill.HasTeamsWith(team.ID(teamID))).Exec(ctx); err != nil {
return err
}
if _, err := tx.TeamSkill.Delete().
Where(teamskill.TeamID(teamID)).
Where(teamskill.SkillID(skillID)).
Exec(ctx); err != nil {
return err
}
_, err := tx.TeamGroupSkill.Delete().Where(teamgroupskill.SkillIDEQ(skillID)).Exec(ctx)
return err
})
if err != nil {
r.logger.Error("delete team skill", "error", err)
return errcode.ErrDatabaseOperation.Wrap(err)
}
return nil
}
func (r *teamSkillRepo) get(ctx context.Context, teamID, skillID uuid.UUID) (*db.Skill, error) {
ts, err := r.db.TeamSkill.Query().
WithSkill(func(sq *db.SkillQuery) {
sq.WithGroups()
}).
Where(teamskill.TeamID(teamID)).
Where(teamskill.SkillID(skillID)).
First(ctx)
if err != nil {
return nil, errcode.ErrDatabaseQuery.Wrap(err)
}
return ts.Edges.Skill, nil
}
func resolveTeamSkillGroupIDs(ctx context.Context, tx *db.Tx, teamID uuid.UUID, reqGroupIDs []uuid.UUID) ([]uuid.UUID, error) {
useDefaultGroup := len(reqGroupIDs) == 0
groups, err := tx.TeamGroup.Query().
Where(teamgroup.TeamID(teamID)).
Where(teamgroup.IDIn(reqGroupIDs...)).
All(ctx)
if err != nil {
return nil, err
}
groupIDs := cvt.Iter(groups, func(_ int, group *db.TeamGroup) uuid.UUID {
return group.ID
})
if useDefaultGroup {
return ensureDefaultGroupIDs(ctx, tx, teamID, groupIDs)
}
return groupIDs, nil
}
func replaceTeamSkillGroups(ctx context.Context, tx *db.Tx, skillID uuid.UUID, groupIDs []uuid.UUID) error {
if _, err := tx.TeamGroupSkill.Delete().Where(teamgroupskill.SkillIDEQ(skillID)).Exec(ctx); err != nil {
return err
}
builders := make([]*db.TeamGroupSkillCreate, 0, len(groupIDs))
for _, groupID := range groupIDs {
builders = append(builders, tx.TeamGroupSkill.Create().
SetID(uuid.New()).
SetGroupID(groupID).
SetSkillID(skillID))
}
if len(builders) == 0 {
return nil
}
_, err := tx.TeamGroupSkill.CreateBulk(builders...).Save(ctx)
return err
}
+184
View File
@@ -0,0 +1,184 @@
package usecase
import (
"archive/zip"
"bytes"
"context"
"fmt"
"log/slog"
"path/filepath"
"strings"
"github.com/google/uuid"
"github.com/samber/do"
"github.com/chaitin/MonkeyCode/backend/config"
"github.com/chaitin/MonkeyCode/backend/db"
"github.com/chaitin/MonkeyCode/backend/domain"
"github.com/chaitin/MonkeyCode/backend/errcode"
"github.com/chaitin/MonkeyCode/backend/pkg/cvt"
"github.com/chaitin/MonkeyCode/backend/pkg/oss"
)
const skillPackagePrefix = "skills"
type teamSkillUsecase struct {
repo domain.TeamSkillRepo
packageStore skillPackageStore
logger *slog.Logger
}
func NewTeamSkillUsecase(i *do.Injector) (domain.TeamSkillUsecase, error) {
cfg := do.MustInvoke[*config.Config](i)
var store skillPackageStore
if cfg.ObjectStorage.Enabled {
client, err := oss.NewS3Compatible(context.Background(), cfg.ObjectStorage, oss.S3Option{
ForcePathStyle: cfg.ObjectStorage.ForcePathStyle,
InitBucket: cfg.ObjectStorage.InitBucket,
})
if err != nil {
return nil, err
}
store = &ossSkillPackageStore{client: client.WithAccessEndpoint(cfg.ObjectStorage.AccessEndpoint)}
}
return &teamSkillUsecase{
repo: do.MustInvoke[domain.TeamSkillRepo](i),
packageStore: store,
logger: do.MustInvoke[*slog.Logger](i),
}, nil
}
func (u *teamSkillUsecase) Add(ctx context.Context, teamUser *domain.TeamUser, req *domain.AddTeamSkillReq) (*domain.TeamSkill, error) {
if req.PackageObjectKey == "" {
if u.packageStore == nil {
return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("object storage is disabled"))
}
data, err := packageSkillMarkdownContent(req.Content)
if err != nil {
return nil, err
}
objectKey, url, err := u.packageStore.Put(ctx, skillPackageFilename(req.Name), data)
if err != nil {
return nil, err
}
req.PackageObjectKey = objectKey
req.PackageURL = url
}
skill, err := u.repo.Create(ctx, teamUser.GetTeamID(), teamUser.User.ID, req)
if err != nil {
return nil, err
}
return cvt.From(skill, &domain.TeamSkill{}), nil
}
func (u *teamSkillUsecase) AddPackage(ctx context.Context, teamUser *domain.TeamUser, req *domain.AddTeamSkillPackageReq) (*domain.TeamSkill, error) {
if u.packageStore == nil {
return nil, errcode.ErrBadRequest.Wrap(fmt.Errorf("object storage is disabled"))
}
if err := validateSkillZipPackage(req.PackageData); err != nil {
return nil, err
}
filename := skillPackageFilename(req.PackageFilename)
if strings.TrimSpace(req.Name) != "" {
filename = skillPackageFilename(req.Name)
}
objectKey, url, err := u.packageStore.Put(ctx, filename, req.PackageData)
if err != nil {
return nil, err
}
req.PackageObjectKey = objectKey
req.PackageURL = url
return u.Add(ctx, teamUser, &req.AddTeamSkillReq)
}
func (u *teamSkillUsecase) List(ctx context.Context, teamUser *domain.TeamUser) (*domain.ListTeamSkillsResp, error) {
skills, err := u.repo.List(ctx, teamUser.GetTeamID())
if err != nil {
return nil, err
}
return &domain.ListTeamSkillsResp{
Skills: cvt.Iter(skills, func(_ int, skill *db.Skill) *domain.TeamSkill {
return cvt.From(skill, &domain.TeamSkill{})
}),
}, nil
}
func (u *teamSkillUsecase) Update(ctx context.Context, teamUser *domain.TeamUser, req *domain.UpdateTeamSkillReq) (*domain.TeamSkill, error) {
skill, err := u.repo.Update(ctx, teamUser.GetTeamID(), req)
if err != nil {
return nil, err
}
return cvt.From(skill, &domain.TeamSkill{}), nil
}
func (u *teamSkillUsecase) Delete(ctx context.Context, teamUser *domain.TeamUser, req *domain.DeleteTeamSkillReq) error {
return u.repo.Delete(ctx, teamUser.GetTeamID(), req.SkillID)
}
type skillPackageStore interface {
Put(ctx context.Context, filename string, data []byte) (objectKey string, url string, err error)
}
type ossSkillPackageStore struct {
client *oss.Client
}
func (s *ossSkillPackageStore) Put(ctx context.Context, filename string, data []byte) (string, string, error) {
if s == nil || s.client == nil {
return "", "", errcode.ErrBadRequest.Wrap(fmt.Errorf("object storage is disabled"))
}
if err := s.client.PutFile(ctx, skillPackagePrefix, filename, bytes.NewReader(data)); err != nil {
return "", "", err
}
objectKey := strings.Trim(filepath.ToSlash(filepath.Join(skillPackagePrefix, filepath.Base(filename))), "/")
return objectKey, s.client.GetURL(skillPackagePrefix, filename), nil
}
func packageSkillMarkdownContent(content string) ([]byte, error) {
var buf bytes.Buffer
zw := zip.NewWriter(&buf)
w, err := zw.Create("SKILL.md")
if err != nil {
return nil, err
}
if _, err := w.Write([]byte(content)); err != nil {
_ = zw.Close()
return nil, err
}
if err := zw.Close(); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func validateSkillZipPackage(data []byte) error {
reader, err := zip.NewReader(bytes.NewReader(data), int64(len(data)))
if err != nil {
return errcode.ErrBadRequest.Wrap(fmt.Errorf("invalid skill zip package"))
}
for _, file := range reader.File {
if file.FileInfo().IsDir() {
continue
}
if strings.EqualFold(filepath.Base(file.Name), "SKILL.md") {
return nil
}
}
return errcode.ErrBadRequest.Wrap(fmt.Errorf("zip package missing SKILL.md"))
}
func skillPackageFilename(name string) string {
name = strings.TrimSpace(name)
if name == "" {
name = "skill"
} else if ext := filepath.Ext(name); strings.EqualFold(ext, ".zip") {
name = strings.TrimSuffix(name, ext)
}
replacer := strings.NewReplacer("/", "-", "\\", "-", ":", "-", " ", "-")
name = strings.Trim(replacer.Replace(name), ".-")
if name == "" {
name = "skill"
}
return fmt.Sprintf("%s-%s.zip", name, uuid.NewString())
}
@@ -0,0 +1,194 @@
package usecase
import (
"archive/zip"
"bytes"
"context"
"io"
"log/slog"
"strings"
"testing"
"github.com/google/uuid"
"github.com/chaitin/MonkeyCode/backend/db"
"github.com/chaitin/MonkeyCode/backend/domain"
)
func TestPackageSkillMarkdownContentCreatesRootSkillMarkdown(t *testing.T) {
content := "---\nname: reviewer\ndescription: Review code\n---\n"
data, err := packageSkillMarkdownContent(content)
if err != nil {
t.Fatal(err)
}
got := readZipFile(t, data, "SKILL.md")
if got != content {
t.Fatalf("SKILL.md content = %q, want %q", got, content)
}
}
func TestTeamSkillUsecaseAddUploadsPackageAndKeepsContent(t *testing.T) {
ctx := context.Background()
teamID := uuid.New()
userID := uuid.New()
repo := &teamSkillRepoStub{}
store := &skillPackageStoreStub{}
u := &teamSkillUsecase{
repo: repo,
packageStore: store,
logger: slog.Default(),
}
content := "---\nname: planner\ndescription: Write plans\n---\n"
_, err := u.Add(ctx, &domain.TeamUser{
User: &domain.User{ID: userID},
Team: &domain.Team{ID: teamID},
}, &domain.AddTeamSkillReq{
Name: "planner",
Description: "Write plans",
Content: content,
SourceType: "text",
SourceLabel: "粘贴文本",
})
if err != nil {
t.Fatal(err)
}
if repo.createdReq == nil {
t.Fatal("repo Create was not called")
}
if repo.createdReq.Content != content {
t.Fatalf("content = %q, want original content", repo.createdReq.Content)
}
if !strings.HasPrefix(repo.createdReq.PackageObjectKey, "skills/planner-") || !strings.HasSuffix(repo.createdReq.PackageObjectKey, ".zip") {
t.Fatalf("package object key = %q", repo.createdReq.PackageObjectKey)
}
if !strings.HasPrefix(repo.createdReq.PackageURL, "https://oss.example.com/skills/planner-") || !strings.HasSuffix(repo.createdReq.PackageURL, ".zip") {
t.Fatalf("package url = %q", repo.createdReq.PackageURL)
}
if got := readZipFile(t, store.data, "SKILL.md"); got != content {
t.Fatalf("uploaded SKILL.md content = %q, want %q", got, content)
}
}
func TestTeamSkillUsecaseAddPackageUploadsOriginalZipAndKeepsContent(t *testing.T) {
ctx := context.Background()
teamID := uuid.New()
userID := uuid.New()
repo := &teamSkillRepoStub{}
store := &skillPackageStoreStub{}
u := &teamSkillUsecase{
repo: repo,
packageStore: store,
logger: slog.Default(),
}
content := "---\nname: packaged\ndescription: Packaged skill\n---\n"
zipData := makeSkillZip(t, content, "references/guide.md", "guide")
_, err := u.AddPackage(ctx, &domain.TeamUser{
User: &domain.User{ID: userID},
Team: &domain.Team{ID: teamID},
}, &domain.AddTeamSkillPackageReq{
AddTeamSkillReq: domain.AddTeamSkillReq{
Name: "packaged",
Description: "Packaged skill",
Content: content,
SourceType: "zip",
SourceLabel: "packaged.zip",
},
PackageFilename: "packaged.zip",
PackageData: zipData,
})
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(store.data, zipData) {
t.Fatal("uploaded data is not the original zip package")
}
if repo.createdReq.Content != content {
t.Fatalf("content = %q, want original SKILL.md content", repo.createdReq.Content)
}
if got := readZipFile(t, store.data, "references/guide.md"); got != "guide" {
t.Fatalf("zip reference file = %q, want guide", got)
}
}
type teamSkillRepoStub struct {
domain.TeamSkillRepo
createdReq *domain.AddTeamSkillReq
}
func makeSkillZip(t *testing.T, skillContent string, extraName string, extraContent string) []byte {
t.Helper()
var buf bytes.Buffer
zw := zip.NewWriter(&buf)
for name, content := range map[string]string{
"SKILL.md": skillContent,
extraName: extraContent,
} {
w, err := zw.Create(name)
if err != nil {
t.Fatal(err)
}
if _, err := w.Write([]byte(content)); err != nil {
t.Fatal(err)
}
}
if err := zw.Close(); err != nil {
t.Fatal(err)
}
return buf.Bytes()
}
func (r *teamSkillRepoStub) Create(ctx context.Context, teamID, userID uuid.UUID, req *domain.AddTeamSkillReq) (*db.Skill, error) {
r.createdReq = req
return &db.Skill{
ID: uuid.New(),
UserID: userID,
Name: req.Name,
Description: req.Description,
Tags: req.Tags,
Content: req.Content,
SourceType: req.SourceType,
SourceLabel: req.SourceLabel,
SkillMdPath: req.SkillMDPath,
PackageObjectKey: req.PackageObjectKey,
PackageURL: req.PackageURL,
}, nil
}
type skillPackageStoreStub struct {
data []byte
}
func (s *skillPackageStoreStub) Put(ctx context.Context, filename string, data []byte) (string, string, error) {
s.data = append([]byte(nil), data...)
return "skills/" + filename, "https://oss.example.com/skills/" + filename, nil
}
func readZipFile(t *testing.T, data []byte, name string) string {
t.Helper()
reader, err := zip.NewReader(bytes.NewReader(data), int64(len(data)))
if err != nil {
t.Fatal(err)
}
for _, file := range reader.File {
if file.Name != name {
continue
}
rc, err := file.Open()
if err != nil {
t.Fatal(err)
}
defer rc.Close()
content, err := io.ReadAll(rc)
if err != nil {
t.Fatal(err)
}
return string(content)
}
t.Fatalf("%s not found in zip", name)
return ""
}
+663 -14
View File
@@ -39,6 +39,7 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/projectissue"
"github.com/chaitin/MonkeyCode/backend/db/projectissuecomment"
"github.com/chaitin/MonkeyCode/backend/db/projecttask"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/task"
"github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch"
"github.com/chaitin/MonkeyCode/backend/db/taskusagestat"
@@ -49,11 +50,13 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/teamgroupimage"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmember"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/chaitin/MonkeyCode/backend/db/teamhost"
"github.com/chaitin/MonkeyCode/backend/db/teamimage"
"github.com/chaitin/MonkeyCode/backend/db/teammember"
"github.com/chaitin/MonkeyCode/backend/db/teammodel"
"github.com/chaitin/MonkeyCode/backend/db/teamoidcconfig"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/chaitin/MonkeyCode/backend/db/useridentity"
"github.com/chaitin/MonkeyCode/backend/db/virtualmachine"
@@ -112,6 +115,8 @@ type Client struct {
ProjectIssueComment *ProjectIssueCommentClient
// ProjectTask is the client for interacting with the ProjectTask builders.
ProjectTask *ProjectTaskClient
// Skill is the client for interacting with the Skill builders.
Skill *SkillClient
// Task is the client for interacting with the Task builders.
Task *TaskClient
// TaskModelSwitch is the client for interacting with the TaskModelSwitch builders.
@@ -132,6 +137,8 @@ type Client struct {
TeamGroupMember *TeamGroupMemberClient
// TeamGroupModel is the client for interacting with the TeamGroupModel builders.
TeamGroupModel *TeamGroupModelClient
// TeamGroupSkill is the client for interacting with the TeamGroupSkill builders.
TeamGroupSkill *TeamGroupSkillClient
// TeamHost is the client for interacting with the TeamHost builders.
TeamHost *TeamHostClient
// TeamImage is the client for interacting with the TeamImage builders.
@@ -142,6 +149,8 @@ type Client struct {
TeamModel *TeamModelClient
// TeamOIDCConfig is the client for interacting with the TeamOIDCConfig builders.
TeamOIDCConfig *TeamOIDCConfigClient
// TeamSkill is the client for interacting with the TeamSkill builders.
TeamSkill *TeamSkillClient
// User is the client for interacting with the User builders.
User *UserClient
// UserIdentity is the client for interacting with the UserIdentity builders.
@@ -182,6 +191,7 @@ func (c *Client) init() {
c.ProjectIssue = NewProjectIssueClient(c.config)
c.ProjectIssueComment = NewProjectIssueCommentClient(c.config)
c.ProjectTask = NewProjectTaskClient(c.config)
c.Skill = NewSkillClient(c.config)
c.Task = NewTaskClient(c.config)
c.TaskModelSwitch = NewTaskModelSwitchClient(c.config)
c.TaskUsageStat = NewTaskUsageStatClient(c.config)
@@ -192,11 +202,13 @@ func (c *Client) init() {
c.TeamGroupImage = NewTeamGroupImageClient(c.config)
c.TeamGroupMember = NewTeamGroupMemberClient(c.config)
c.TeamGroupModel = NewTeamGroupModelClient(c.config)
c.TeamGroupSkill = NewTeamGroupSkillClient(c.config)
c.TeamHost = NewTeamHostClient(c.config)
c.TeamImage = NewTeamImageClient(c.config)
c.TeamMember = NewTeamMemberClient(c.config)
c.TeamModel = NewTeamModelClient(c.config)
c.TeamOIDCConfig = NewTeamOIDCConfigClient(c.config)
c.TeamSkill = NewTeamSkillClient(c.config)
c.User = NewUserClient(c.config)
c.UserIdentity = NewUserIdentityClient(c.config)
c.VirtualMachine = NewVirtualMachineClient(c.config)
@@ -315,6 +327,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
ProjectIssue: NewProjectIssueClient(cfg),
ProjectIssueComment: NewProjectIssueCommentClient(cfg),
ProjectTask: NewProjectTaskClient(cfg),
Skill: NewSkillClient(cfg),
Task: NewTaskClient(cfg),
TaskModelSwitch: NewTaskModelSwitchClient(cfg),
TaskUsageStat: NewTaskUsageStatClient(cfg),
@@ -325,11 +338,13 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
TeamGroupImage: NewTeamGroupImageClient(cfg),
TeamGroupMember: NewTeamGroupMemberClient(cfg),
TeamGroupModel: NewTeamGroupModelClient(cfg),
TeamGroupSkill: NewTeamGroupSkillClient(cfg),
TeamHost: NewTeamHostClient(cfg),
TeamImage: NewTeamImageClient(cfg),
TeamMember: NewTeamMemberClient(cfg),
TeamModel: NewTeamModelClient(cfg),
TeamOIDCConfig: NewTeamOIDCConfigClient(cfg),
TeamSkill: NewTeamSkillClient(cfg),
User: NewUserClient(cfg),
UserIdentity: NewUserIdentityClient(cfg),
VirtualMachine: NewVirtualMachineClient(cfg),
@@ -375,6 +390,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
ProjectIssue: NewProjectIssueClient(cfg),
ProjectIssueComment: NewProjectIssueCommentClient(cfg),
ProjectTask: NewProjectTaskClient(cfg),
Skill: NewSkillClient(cfg),
Task: NewTaskClient(cfg),
TaskModelSwitch: NewTaskModelSwitchClient(cfg),
TaskUsageStat: NewTaskUsageStatClient(cfg),
@@ -385,11 +401,13 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
TeamGroupImage: NewTeamGroupImageClient(cfg),
TeamGroupMember: NewTeamGroupMemberClient(cfg),
TeamGroupModel: NewTeamGroupModelClient(cfg),
TeamGroupSkill: NewTeamGroupSkillClient(cfg),
TeamHost: NewTeamHostClient(cfg),
TeamImage: NewTeamImageClient(cfg),
TeamMember: NewTeamMemberClient(cfg),
TeamModel: NewTeamModelClient(cfg),
TeamOIDCConfig: NewTeamOIDCConfigClient(cfg),
TeamSkill: NewTeamSkillClient(cfg),
User: NewUserClient(cfg),
UserIdentity: NewUserIdentityClient(cfg),
VirtualMachine: NewVirtualMachineClient(cfg),
@@ -426,11 +444,11 @@ func (c *Client) Use(hooks ...Hook) {
c.Image, c.MCPTool, c.MCPUpstream, c.MCPUserToolSetting, c.Model,
c.ModelApiKey, c.ModelPricing, c.NotifyChannel, c.NotifySendLog,
c.NotifySubscription, c.Project, c.ProjectCollaborator, c.ProjectGitBot,
c.ProjectIssue, c.ProjectIssueComment, c.ProjectTask, c.Task,
c.ProjectIssue, c.ProjectIssueComment, c.ProjectTask, c.Skill, c.Task,
c.TaskModelSwitch, c.TaskUsageStat, c.TaskVirtualMachine, c.Team, c.TeamGroup,
c.TeamGroupHost, c.TeamGroupImage, c.TeamGroupMember, c.TeamGroupModel,
c.TeamHost, c.TeamImage, c.TeamMember, c.TeamModel, c.TeamOIDCConfig, c.User,
c.UserIdentity, c.VirtualMachine,
c.TeamGroupSkill, c.TeamHost, c.TeamImage, c.TeamMember, c.TeamModel,
c.TeamOIDCConfig, c.TeamSkill, c.User, c.UserIdentity, c.VirtualMachine,
} {
n.Use(hooks...)
}
@@ -444,11 +462,11 @@ func (c *Client) Intercept(interceptors ...Interceptor) {
c.Image, c.MCPTool, c.MCPUpstream, c.MCPUserToolSetting, c.Model,
c.ModelApiKey, c.ModelPricing, c.NotifyChannel, c.NotifySendLog,
c.NotifySubscription, c.Project, c.ProjectCollaborator, c.ProjectGitBot,
c.ProjectIssue, c.ProjectIssueComment, c.ProjectTask, c.Task,
c.ProjectIssue, c.ProjectIssueComment, c.ProjectTask, c.Skill, c.Task,
c.TaskModelSwitch, c.TaskUsageStat, c.TaskVirtualMachine, c.Team, c.TeamGroup,
c.TeamGroupHost, c.TeamGroupImage, c.TeamGroupMember, c.TeamGroupModel,
c.TeamHost, c.TeamImage, c.TeamMember, c.TeamModel, c.TeamOIDCConfig, c.User,
c.UserIdentity, c.VirtualMachine,
c.TeamGroupSkill, c.TeamHost, c.TeamImage, c.TeamMember, c.TeamModel,
c.TeamOIDCConfig, c.TeamSkill, c.User, c.UserIdentity, c.VirtualMachine,
} {
n.Intercept(interceptors...)
}
@@ -503,6 +521,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return c.ProjectIssueComment.mutate(ctx, m)
case *ProjectTaskMutation:
return c.ProjectTask.mutate(ctx, m)
case *SkillMutation:
return c.Skill.mutate(ctx, m)
case *TaskMutation:
return c.Task.mutate(ctx, m)
case *TaskModelSwitchMutation:
@@ -523,6 +543,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return c.TeamGroupMember.mutate(ctx, m)
case *TeamGroupModelMutation:
return c.TeamGroupModel.mutate(ctx, m)
case *TeamGroupSkillMutation:
return c.TeamGroupSkill.mutate(ctx, m)
case *TeamHostMutation:
return c.TeamHost.mutate(ctx, m)
case *TeamImageMutation:
@@ -533,6 +555,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return c.TeamModel.mutate(ctx, m)
case *TeamOIDCConfigMutation:
return c.TeamOIDCConfig.mutate(ctx, m)
case *TeamSkillMutation:
return c.TeamSkill.mutate(ctx, m)
case *UserMutation:
return c.User.mutate(ctx, m)
case *UserIdentityMutation:
@@ -4799,6 +4823,221 @@ func (c *ProjectTaskClient) mutate(ctx context.Context, m *ProjectTaskMutation)
}
}
// SkillClient is a client for the Skill schema.
type SkillClient struct {
config
}
// NewSkillClient returns a client for the Skill from the given config.
func NewSkillClient(c config) *SkillClient {
return &SkillClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `skill.Hooks(f(g(h())))`.
func (c *SkillClient) Use(hooks ...Hook) {
c.hooks.Skill = append(c.hooks.Skill, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `skill.Intercept(f(g(h())))`.
func (c *SkillClient) Intercept(interceptors ...Interceptor) {
c.inters.Skill = append(c.inters.Skill, interceptors...)
}
// Create returns a builder for creating a Skill entity.
func (c *SkillClient) Create() *SkillCreate {
mutation := newSkillMutation(c.config, OpCreate)
return &SkillCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Skill entities.
func (c *SkillClient) CreateBulk(builders ...*SkillCreate) *SkillCreateBulk {
return &SkillCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *SkillClient) MapCreateBulk(slice any, setFunc func(*SkillCreate, int)) *SkillCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &SkillCreateBulk{err: fmt.Errorf("calling to SkillClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*SkillCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &SkillCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Skill.
func (c *SkillClient) Update() *SkillUpdate {
mutation := newSkillMutation(c.config, OpUpdate)
return &SkillUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *SkillClient) UpdateOne(_m *Skill) *SkillUpdateOne {
mutation := newSkillMutation(c.config, OpUpdateOne, withSkill(_m))
return &SkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *SkillClient) UpdateOneID(id uuid.UUID) *SkillUpdateOne {
mutation := newSkillMutation(c.config, OpUpdateOne, withSkillID(id))
return &SkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Skill.
func (c *SkillClient) Delete() *SkillDelete {
mutation := newSkillMutation(c.config, OpDelete)
return &SkillDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *SkillClient) DeleteOne(_m *Skill) *SkillDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *SkillClient) DeleteOneID(id uuid.UUID) *SkillDeleteOne {
builder := c.Delete().Where(skill.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &SkillDeleteOne{builder}
}
// Query returns a query builder for Skill.
func (c *SkillClient) Query() *SkillQuery {
return &SkillQuery{
config: c.config,
ctx: &QueryContext{Type: TypeSkill},
inters: c.Interceptors(),
}
}
// Get returns a Skill entity by its id.
func (c *SkillClient) Get(ctx context.Context, id uuid.UUID) (*Skill, error) {
return c.Query().Where(skill.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *SkillClient) GetX(ctx context.Context, id uuid.UUID) *Skill {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryUser queries the user edge of a Skill.
func (c *SkillClient) QueryUser(_m *Skill) *UserQuery {
query := (&UserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(skill.Table, skill.FieldID, id),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, skill.UserTable, skill.UserColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryTeams queries the teams edge of a Skill.
func (c *SkillClient) QueryTeams(_m *Skill) *TeamQuery {
query := (&TeamClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(skill.Table, skill.FieldID, id),
sqlgraph.To(team.Table, team.FieldID),
sqlgraph.Edge(sqlgraph.M2M, true, skill.TeamsTable, skill.TeamsPrimaryKey...),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryGroups queries the groups edge of a Skill.
func (c *SkillClient) QueryGroups(_m *Skill) *TeamGroupQuery {
query := (&TeamGroupClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(skill.Table, skill.FieldID, id),
sqlgraph.To(teamgroup.Table, teamgroup.FieldID),
sqlgraph.Edge(sqlgraph.M2M, true, skill.GroupsTable, skill.GroupsPrimaryKey...),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryTeamSkills queries the team_skills edge of a Skill.
func (c *SkillClient) QueryTeamSkills(_m *Skill) *TeamSkillQuery {
query := (&TeamSkillClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(skill.Table, skill.FieldID, id),
sqlgraph.To(teamskill.Table, teamskill.FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, skill.TeamSkillsTable, skill.TeamSkillsColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryTeamGroupSkills queries the team_group_skills edge of a Skill.
func (c *SkillClient) QueryTeamGroupSkills(_m *Skill) *TeamGroupSkillQuery {
query := (&TeamGroupSkillClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(skill.Table, skill.FieldID, id),
sqlgraph.To(teamgroupskill.Table, teamgroupskill.FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, skill.TeamGroupSkillsTable, skill.TeamGroupSkillsColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *SkillClient) Hooks() []Hook {
hooks := c.hooks.Skill
return append(hooks[:len(hooks):len(hooks)], skill.Hooks[:]...)
}
// Interceptors returns the client interceptors.
func (c *SkillClient) Interceptors() []Interceptor {
inters := c.inters.Skill
return append(inters[:len(inters):len(inters)], skill.Interceptors[:]...)
}
func (c *SkillClient) mutate(ctx context.Context, m *SkillMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&SkillCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&SkillUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&SkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&SkillDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("db: unknown Skill mutation op: %q", m.Op())
}
}
// TaskClient is a client for the Task schema.
type TaskClient struct {
config
@@ -5713,6 +5952,22 @@ func (c *TeamClient) QueryImages(_m *Team) *ImageQuery {
return query
}
// QuerySkills queries the skills edge of a Team.
func (c *TeamClient) QuerySkills(_m *Team) *SkillQuery {
query := (&SkillClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(team.Table, team.FieldID, id),
sqlgraph.To(skill.Table, skill.FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, team.SkillsTable, team.SkillsPrimaryKey...),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryTeamMembers queries the team_members edge of a Team.
func (c *TeamClient) QueryTeamMembers(_m *Team) *TeamMemberQuery {
query := (&TeamMemberClient{config: c.config}).Query()
@@ -5761,6 +6016,22 @@ func (c *TeamClient) QueryTeamImages(_m *Team) *TeamImageQuery {
return query
}
// QueryTeamSkills queries the team_skills edge of a Team.
func (c *TeamClient) QueryTeamSkills(_m *Team) *TeamSkillQuery {
query := (&TeamSkillClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(team.Table, team.FieldID, id),
sqlgraph.To(teamskill.Table, teamskill.FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, team.TeamSkillsTable, team.TeamSkillsColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *TeamClient) Hooks() []Hook {
hooks := c.hooks.Team
@@ -5976,6 +6247,22 @@ func (c *TeamGroupClient) QueryHosts(_m *TeamGroup) *HostQuery {
return query
}
// QuerySkills queries the skills edge of a TeamGroup.
func (c *TeamGroupClient) QuerySkills(_m *TeamGroup) *SkillQuery {
query := (&SkillClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(teamgroup.Table, teamgroup.FieldID, id),
sqlgraph.To(skill.Table, skill.FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, teamgroup.SkillsTable, teamgroup.SkillsPrimaryKey...),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryTeamGroupMembers queries the team_group_members edge of a TeamGroup.
func (c *TeamGroupClient) QueryTeamGroupMembers(_m *TeamGroup) *TeamGroupMemberQuery {
query := (&TeamGroupMemberClient{config: c.config}).Query()
@@ -6040,6 +6327,22 @@ func (c *TeamGroupClient) QueryTeamGroupHosts(_m *TeamGroup) *TeamGroupHostQuery
return query
}
// QueryTeamGroupSkills queries the team_group_skills edge of a TeamGroup.
func (c *TeamGroupClient) QueryTeamGroupSkills(_m *TeamGroup) *TeamGroupSkillQuery {
query := (&TeamGroupSkillClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(teamgroup.Table, teamgroup.FieldID, id),
sqlgraph.To(teamgroupskill.Table, teamgroupskill.FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, teamgroup.TeamGroupSkillsTable, teamgroup.TeamGroupSkillsColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *TeamGroupClient) Hooks() []Hook {
hooks := c.hooks.TeamGroup
@@ -6727,6 +7030,171 @@ func (c *TeamGroupModelClient) mutate(ctx context.Context, m *TeamGroupModelMuta
}
}
// TeamGroupSkillClient is a client for the TeamGroupSkill schema.
type TeamGroupSkillClient struct {
config
}
// NewTeamGroupSkillClient returns a client for the TeamGroupSkill from the given config.
func NewTeamGroupSkillClient(c config) *TeamGroupSkillClient {
return &TeamGroupSkillClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `teamgroupskill.Hooks(f(g(h())))`.
func (c *TeamGroupSkillClient) Use(hooks ...Hook) {
c.hooks.TeamGroupSkill = append(c.hooks.TeamGroupSkill, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `teamgroupskill.Intercept(f(g(h())))`.
func (c *TeamGroupSkillClient) Intercept(interceptors ...Interceptor) {
c.inters.TeamGroupSkill = append(c.inters.TeamGroupSkill, interceptors...)
}
// Create returns a builder for creating a TeamGroupSkill entity.
func (c *TeamGroupSkillClient) Create() *TeamGroupSkillCreate {
mutation := newTeamGroupSkillMutation(c.config, OpCreate)
return &TeamGroupSkillCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of TeamGroupSkill entities.
func (c *TeamGroupSkillClient) CreateBulk(builders ...*TeamGroupSkillCreate) *TeamGroupSkillCreateBulk {
return &TeamGroupSkillCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *TeamGroupSkillClient) MapCreateBulk(slice any, setFunc func(*TeamGroupSkillCreate, int)) *TeamGroupSkillCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &TeamGroupSkillCreateBulk{err: fmt.Errorf("calling to TeamGroupSkillClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*TeamGroupSkillCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &TeamGroupSkillCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for TeamGroupSkill.
func (c *TeamGroupSkillClient) Update() *TeamGroupSkillUpdate {
mutation := newTeamGroupSkillMutation(c.config, OpUpdate)
return &TeamGroupSkillUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *TeamGroupSkillClient) UpdateOne(_m *TeamGroupSkill) *TeamGroupSkillUpdateOne {
mutation := newTeamGroupSkillMutation(c.config, OpUpdateOne, withTeamGroupSkill(_m))
return &TeamGroupSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *TeamGroupSkillClient) UpdateOneID(id uuid.UUID) *TeamGroupSkillUpdateOne {
mutation := newTeamGroupSkillMutation(c.config, OpUpdateOne, withTeamGroupSkillID(id))
return &TeamGroupSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for TeamGroupSkill.
func (c *TeamGroupSkillClient) Delete() *TeamGroupSkillDelete {
mutation := newTeamGroupSkillMutation(c.config, OpDelete)
return &TeamGroupSkillDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *TeamGroupSkillClient) DeleteOne(_m *TeamGroupSkill) *TeamGroupSkillDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *TeamGroupSkillClient) DeleteOneID(id uuid.UUID) *TeamGroupSkillDeleteOne {
builder := c.Delete().Where(teamgroupskill.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &TeamGroupSkillDeleteOne{builder}
}
// Query returns a query builder for TeamGroupSkill.
func (c *TeamGroupSkillClient) Query() *TeamGroupSkillQuery {
return &TeamGroupSkillQuery{
config: c.config,
ctx: &QueryContext{Type: TypeTeamGroupSkill},
inters: c.Interceptors(),
}
}
// Get returns a TeamGroupSkill entity by its id.
func (c *TeamGroupSkillClient) Get(ctx context.Context, id uuid.UUID) (*TeamGroupSkill, error) {
return c.Query().Where(teamgroupskill.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *TeamGroupSkillClient) GetX(ctx context.Context, id uuid.UUID) *TeamGroupSkill {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryGroup queries the group edge of a TeamGroupSkill.
func (c *TeamGroupSkillClient) QueryGroup(_m *TeamGroupSkill) *TeamGroupQuery {
query := (&TeamGroupClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(teamgroupskill.Table, teamgroupskill.FieldID, id),
sqlgraph.To(teamgroup.Table, teamgroup.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, teamgroupskill.GroupTable, teamgroupskill.GroupColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QuerySkill queries the skill edge of a TeamGroupSkill.
func (c *TeamGroupSkillClient) QuerySkill(_m *TeamGroupSkill) *SkillQuery {
query := (&SkillClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(teamgroupskill.Table, teamgroupskill.FieldID, id),
sqlgraph.To(skill.Table, skill.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, teamgroupskill.SkillTable, teamgroupskill.SkillColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *TeamGroupSkillClient) Hooks() []Hook {
return c.hooks.TeamGroupSkill
}
// Interceptors returns the client interceptors.
func (c *TeamGroupSkillClient) Interceptors() []Interceptor {
return c.inters.TeamGroupSkill
}
func (c *TeamGroupSkillClient) mutate(ctx context.Context, m *TeamGroupSkillMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&TeamGroupSkillCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&TeamGroupSkillUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&TeamGroupSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&TeamGroupSkillDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("db: unknown TeamGroupSkill mutation op: %q", m.Op())
}
}
// TeamHostClient is a client for the TeamHost schema.
type TeamHostClient struct {
config
@@ -7536,6 +8004,171 @@ func (c *TeamOIDCConfigClient) mutate(ctx context.Context, m *TeamOIDCConfigMuta
}
}
// TeamSkillClient is a client for the TeamSkill schema.
type TeamSkillClient struct {
config
}
// NewTeamSkillClient returns a client for the TeamSkill from the given config.
func NewTeamSkillClient(c config) *TeamSkillClient {
return &TeamSkillClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `teamskill.Hooks(f(g(h())))`.
func (c *TeamSkillClient) Use(hooks ...Hook) {
c.hooks.TeamSkill = append(c.hooks.TeamSkill, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `teamskill.Intercept(f(g(h())))`.
func (c *TeamSkillClient) Intercept(interceptors ...Interceptor) {
c.inters.TeamSkill = append(c.inters.TeamSkill, interceptors...)
}
// Create returns a builder for creating a TeamSkill entity.
func (c *TeamSkillClient) Create() *TeamSkillCreate {
mutation := newTeamSkillMutation(c.config, OpCreate)
return &TeamSkillCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of TeamSkill entities.
func (c *TeamSkillClient) CreateBulk(builders ...*TeamSkillCreate) *TeamSkillCreateBulk {
return &TeamSkillCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *TeamSkillClient) MapCreateBulk(slice any, setFunc func(*TeamSkillCreate, int)) *TeamSkillCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &TeamSkillCreateBulk{err: fmt.Errorf("calling to TeamSkillClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*TeamSkillCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &TeamSkillCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for TeamSkill.
func (c *TeamSkillClient) Update() *TeamSkillUpdate {
mutation := newTeamSkillMutation(c.config, OpUpdate)
return &TeamSkillUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *TeamSkillClient) UpdateOne(_m *TeamSkill) *TeamSkillUpdateOne {
mutation := newTeamSkillMutation(c.config, OpUpdateOne, withTeamSkill(_m))
return &TeamSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *TeamSkillClient) UpdateOneID(id uuid.UUID) *TeamSkillUpdateOne {
mutation := newTeamSkillMutation(c.config, OpUpdateOne, withTeamSkillID(id))
return &TeamSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for TeamSkill.
func (c *TeamSkillClient) Delete() *TeamSkillDelete {
mutation := newTeamSkillMutation(c.config, OpDelete)
return &TeamSkillDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *TeamSkillClient) DeleteOne(_m *TeamSkill) *TeamSkillDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *TeamSkillClient) DeleteOneID(id uuid.UUID) *TeamSkillDeleteOne {
builder := c.Delete().Where(teamskill.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &TeamSkillDeleteOne{builder}
}
// Query returns a query builder for TeamSkill.
func (c *TeamSkillClient) Query() *TeamSkillQuery {
return &TeamSkillQuery{
config: c.config,
ctx: &QueryContext{Type: TypeTeamSkill},
inters: c.Interceptors(),
}
}
// Get returns a TeamSkill entity by its id.
func (c *TeamSkillClient) Get(ctx context.Context, id uuid.UUID) (*TeamSkill, error) {
return c.Query().Where(teamskill.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *TeamSkillClient) GetX(ctx context.Context, id uuid.UUID) *TeamSkill {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryTeam queries the team edge of a TeamSkill.
func (c *TeamSkillClient) QueryTeam(_m *TeamSkill) *TeamQuery {
query := (&TeamClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(teamskill.Table, teamskill.FieldID, id),
sqlgraph.To(team.Table, team.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, teamskill.TeamTable, teamskill.TeamColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QuerySkill queries the skill edge of a TeamSkill.
func (c *TeamSkillClient) QuerySkill(_m *TeamSkill) *SkillQuery {
query := (&SkillClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(teamskill.Table, teamskill.FieldID, id),
sqlgraph.To(skill.Table, skill.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, teamskill.SkillTable, teamskill.SkillColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *TeamSkillClient) Hooks() []Hook {
return c.hooks.TeamSkill
}
// Interceptors returns the client interceptors.
func (c *TeamSkillClient) Interceptors() []Interceptor {
return c.inters.TeamSkill
}
func (c *TeamSkillClient) mutate(ctx context.Context, m *TeamSkillMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&TeamSkillCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&TeamSkillUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&TeamSkillUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&TeamSkillDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("db: unknown TeamSkill mutation op: %q", m.Op())
}
}
// UserClient is a client for the User schema.
type UserClient struct {
config
@@ -7740,6 +8373,22 @@ func (c *UserClient) QueryImages(_m *User) *ImageQuery {
return query
}
// QuerySkills queries the skills edge of a User.
func (c *UserClient) QuerySkills(_m *User) *SkillQuery {
query := (&SkillClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(user.Table, user.FieldID, id),
sqlgraph.To(skill.Table, skill.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, user.SkillsTable, user.SkillsColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryHosts queries the hosts edge of a User.
func (c *UserClient) QueryHosts(_m *User) *HostQuery {
query := (&HostClient{config: c.config}).Query()
@@ -8395,21 +9044,21 @@ type (
Audit, GitBot, GitBotTask, GitBotUser, GitIdentity, GitTask, Host, Image,
MCPTool, MCPUpstream, MCPUserToolSetting, Model, ModelApiKey, ModelPricing,
NotifyChannel, NotifySendLog, NotifySubscription, Project, ProjectCollaborator,
ProjectGitBot, ProjectIssue, ProjectIssueComment, ProjectTask, Task,
ProjectGitBot, ProjectIssue, ProjectIssueComment, ProjectTask, Skill, Task,
TaskModelSwitch, TaskUsageStat, TaskVirtualMachine, Team, TeamGroup,
TeamGroupHost, TeamGroupImage, TeamGroupMember, TeamGroupModel, TeamHost,
TeamImage, TeamMember, TeamModel, TeamOIDCConfig, User, UserIdentity,
VirtualMachine []ent.Hook
TeamGroupHost, TeamGroupImage, TeamGroupMember, TeamGroupModel, TeamGroupSkill,
TeamHost, TeamImage, TeamMember, TeamModel, TeamOIDCConfig, TeamSkill, User,
UserIdentity, VirtualMachine []ent.Hook
}
inters struct {
Audit, GitBot, GitBotTask, GitBotUser, GitIdentity, GitTask, Host, Image,
MCPTool, MCPUpstream, MCPUserToolSetting, Model, ModelApiKey, ModelPricing,
NotifyChannel, NotifySendLog, NotifySubscription, Project, ProjectCollaborator,
ProjectGitBot, ProjectIssue, ProjectIssueComment, ProjectTask, Task,
ProjectGitBot, ProjectIssue, ProjectIssueComment, ProjectTask, Skill, Task,
TaskModelSwitch, TaskUsageStat, TaskVirtualMachine, Team, TeamGroup,
TeamGroupHost, TeamGroupImage, TeamGroupMember, TeamGroupModel, TeamHost,
TeamImage, TeamMember, TeamModel, TeamOIDCConfig, User, UserIdentity,
VirtualMachine []ent.Interceptor
TeamGroupHost, TeamGroupImage, TeamGroupMember, TeamGroupModel, TeamGroupSkill,
TeamHost, TeamImage, TeamMember, TeamModel, TeamOIDCConfig, TeamSkill, User,
UserIdentity, VirtualMachine []ent.Interceptor
}
)
+92
View File
@@ -22,10 +22,12 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/project"
"github.com/chaitin/MonkeyCode/backend/db/projectissue"
"github.com/chaitin/MonkeyCode/backend/db/projectissuecomment"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/task"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamgrouphost"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/google/uuid"
)
@@ -618,6 +620,51 @@ func (q *ProjectIssueCommentQuery) After(ctx context.Context, cursor string, lim
return nodes, res, nil
}
func (q *SkillQuery) After(ctx context.Context, cursor string, limit int) ([]*Skill, *Cursor, error) {
i, err := unmarshalCreatedAt(cursor)
if err != nil {
return nil, nil, err
}
q.Order(skill.ByCreatedAt(sql.OrderDesc()), skill.ByID(sql.OrderDesc()))
q.Limit(limit + 1)
if i != nil {
q.Where(func(s *sql.Selector) {
s.Where(sql.Or(
sql.LT(s.C("created_at"), i.CreatedAt),
sql.And(
sql.EQ(s.C("created_at"), i.CreatedAt),
sql.LT(s.C("id"), i.ID),
),
))
})
}
nodes, err := q.All(ctx)
if err != nil {
return nil, nil, err
}
res := &Cursor{}
if len(nodes) > limit {
res.HasNextPage = true
nodes = nodes[:limit]
}
if len(nodes) > 0 {
last := nodes[len(nodes)-1]
i := &createdAtCursor{
CreatedAt: last.CreatedAt,
ID: last.ID,
}
cursor, err := i.marshal()
if err != nil {
return nil, nil, err
}
res.Cursor = cursor
}
return nodes, res, nil
}
func (q *TaskQuery) After(ctx context.Context, cursor string, limit int) ([]*Task, *Cursor, error) {
i, err := unmarshalCreatedAt(cursor)
if err != nil {
@@ -797,3 +844,48 @@ func (q *TeamGroupModelQuery) After(ctx context.Context, cursor string, limit in
}
return nodes, res, nil
}
func (q *TeamGroupSkillQuery) After(ctx context.Context, cursor string, limit int) ([]*TeamGroupSkill, *Cursor, error) {
i, err := unmarshalCreatedAt(cursor)
if err != nil {
return nil, nil, err
}
q.Order(teamgroupskill.ByCreatedAt(sql.OrderDesc()), teamgroupskill.ByID(sql.OrderDesc()))
q.Limit(limit + 1)
if i != nil {
q.Where(func(s *sql.Selector) {
s.Where(sql.Or(
sql.LT(s.C("created_at"), i.CreatedAt),
sql.And(
sql.EQ(s.C("created_at"), i.CreatedAt),
sql.LT(s.C("id"), i.ID),
),
))
})
}
nodes, err := q.All(ctx)
if err != nil {
return nil, nil, err
}
res := &Cursor{}
if len(nodes) > limit {
res.HasNextPage = true
nodes = nodes[:limit]
}
if len(nodes) > 0 {
last := nodes[len(nodes)-1]
i := &createdAtCursor{
CreatedAt: last.CreatedAt,
ID: last.ID,
}
cursor, err := i.marshal()
if err != nil {
return nil, nil, err
}
res.Cursor = cursor
}
return nodes, res, nil
}
+6
View File
@@ -35,6 +35,7 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/projectissue"
"github.com/chaitin/MonkeyCode/backend/db/projectissuecomment"
"github.com/chaitin/MonkeyCode/backend/db/projecttask"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/task"
"github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch"
"github.com/chaitin/MonkeyCode/backend/db/taskusagestat"
@@ -45,11 +46,13 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/teamgroupimage"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmember"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/chaitin/MonkeyCode/backend/db/teamhost"
"github.com/chaitin/MonkeyCode/backend/db/teamimage"
"github.com/chaitin/MonkeyCode/backend/db/teammember"
"github.com/chaitin/MonkeyCode/backend/db/teammodel"
"github.com/chaitin/MonkeyCode/backend/db/teamoidcconfig"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/chaitin/MonkeyCode/backend/db/useridentity"
"github.com/chaitin/MonkeyCode/backend/db/virtualmachine"
@@ -136,6 +139,7 @@ func checkColumn(t, c string) error {
projectissue.Table: projectissue.ValidColumn,
projectissuecomment.Table: projectissuecomment.ValidColumn,
projecttask.Table: projecttask.ValidColumn,
skill.Table: skill.ValidColumn,
task.Table: task.ValidColumn,
taskmodelswitch.Table: taskmodelswitch.ValidColumn,
taskusagestat.Table: taskusagestat.ValidColumn,
@@ -146,11 +150,13 @@ func checkColumn(t, c string) error {
teamgroupimage.Table: teamgroupimage.ValidColumn,
teamgroupmember.Table: teamgroupmember.ValidColumn,
teamgroupmodel.Table: teamgroupmodel.ValidColumn,
teamgroupskill.Table: teamgroupskill.ValidColumn,
teamhost.Table: teamhost.ValidColumn,
teamimage.Table: teamimage.ValidColumn,
teammember.Table: teammember.ValidColumn,
teammodel.Table: teammodel.ValidColumn,
teamoidcconfig.Table: teamoidcconfig.ValidColumn,
teamskill.Table: teamskill.ValidColumn,
user.Table: user.ValidColumn,
useridentity.Table: useridentity.ValidColumn,
virtualmachine.Table: virtualmachine.ValidColumn,
+36
View File
@@ -285,6 +285,18 @@ func (f ProjectTaskFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, e
return nil, fmt.Errorf("unexpected mutation type %T. expect *db.ProjectTaskMutation", m)
}
// The SkillFunc type is an adapter to allow the use of ordinary
// function as Skill mutator.
type SkillFunc func(context.Context, *db.SkillMutation) (db.Value, error)
// Mutate calls f(ctx, m).
func (f SkillFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) {
if mv, ok := m.(*db.SkillMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *db.SkillMutation", m)
}
// The TaskFunc type is an adapter to allow the use of ordinary
// function as Task mutator.
type TaskFunc func(context.Context, *db.TaskMutation) (db.Value, error)
@@ -405,6 +417,18 @@ func (f TeamGroupModelFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value
return nil, fmt.Errorf("unexpected mutation type %T. expect *db.TeamGroupModelMutation", m)
}
// The TeamGroupSkillFunc type is an adapter to allow the use of ordinary
// function as TeamGroupSkill mutator.
type TeamGroupSkillFunc func(context.Context, *db.TeamGroupSkillMutation) (db.Value, error)
// Mutate calls f(ctx, m).
func (f TeamGroupSkillFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) {
if mv, ok := m.(*db.TeamGroupSkillMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *db.TeamGroupSkillMutation", m)
}
// The TeamHostFunc type is an adapter to allow the use of ordinary
// function as TeamHost mutator.
type TeamHostFunc func(context.Context, *db.TeamHostMutation) (db.Value, error)
@@ -465,6 +489,18 @@ func (f TeamOIDCConfigFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value
return nil, fmt.Errorf("unexpected mutation type %T. expect *db.TeamOIDCConfigMutation", m)
}
// The TeamSkillFunc type is an adapter to allow the use of ordinary
// function as TeamSkill mutator.
type TeamSkillFunc func(context.Context, *db.TeamSkillMutation) (db.Value, error)
// Mutate calls f(ctx, m).
func (f TeamSkillFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) {
if mv, ok := m.(*db.TeamSkillMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *db.TeamSkillMutation", m)
}
// The UserFunc type is an adapter to allow the use of ordinary
// function as User mutator.
type UserFunc func(context.Context, *db.UserMutation) (db.Value, error)
+90
View File
@@ -32,6 +32,7 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/projectissue"
"github.com/chaitin/MonkeyCode/backend/db/projectissuecomment"
"github.com/chaitin/MonkeyCode/backend/db/projecttask"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/task"
"github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch"
"github.com/chaitin/MonkeyCode/backend/db/taskusagestat"
@@ -42,11 +43,13 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/teamgroupimage"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmember"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/chaitin/MonkeyCode/backend/db/teamhost"
"github.com/chaitin/MonkeyCode/backend/db/teamimage"
"github.com/chaitin/MonkeyCode/backend/db/teammember"
"github.com/chaitin/MonkeyCode/backend/db/teammodel"
"github.com/chaitin/MonkeyCode/backend/db/teamoidcconfig"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/chaitin/MonkeyCode/backend/db/useridentity"
"github.com/chaitin/MonkeyCode/backend/db/virtualmachine"
@@ -729,6 +732,33 @@ func (f TraverseProjectTask) Traverse(ctx context.Context, q db.Query) error {
return fmt.Errorf("unexpected query type %T. expect *db.ProjectTaskQuery", q)
}
// The SkillFunc type is an adapter to allow the use of ordinary function as a Querier.
type SkillFunc func(context.Context, *db.SkillQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f SkillFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.SkillQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.SkillQuery", q)
}
// The TraverseSkill type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSkill func(context.Context, *db.SkillQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSkill) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseSkill) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.SkillQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.SkillQuery", q)
}
// The TaskFunc type is an adapter to allow the use of ordinary function as a Querier.
type TaskFunc func(context.Context, *db.TaskQuery) (db.Value, error)
@@ -999,6 +1029,33 @@ func (f TraverseTeamGroupModel) Traverse(ctx context.Context, q db.Query) error
return fmt.Errorf("unexpected query type %T. expect *db.TeamGroupModelQuery", q)
}
// The TeamGroupSkillFunc type is an adapter to allow the use of ordinary function as a Querier.
type TeamGroupSkillFunc func(context.Context, *db.TeamGroupSkillQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f TeamGroupSkillFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.TeamGroupSkillQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.TeamGroupSkillQuery", q)
}
// The TraverseTeamGroupSkill type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTeamGroupSkill func(context.Context, *db.TeamGroupSkillQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTeamGroupSkill) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseTeamGroupSkill) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.TeamGroupSkillQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.TeamGroupSkillQuery", q)
}
// The TeamHostFunc type is an adapter to allow the use of ordinary function as a Querier.
type TeamHostFunc func(context.Context, *db.TeamHostQuery) (db.Value, error)
@@ -1134,6 +1191,33 @@ func (f TraverseTeamOIDCConfig) Traverse(ctx context.Context, q db.Query) error
return fmt.Errorf("unexpected query type %T. expect *db.TeamOIDCConfigQuery", q)
}
// The TeamSkillFunc type is an adapter to allow the use of ordinary function as a Querier.
type TeamSkillFunc func(context.Context, *db.TeamSkillQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f TeamSkillFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.TeamSkillQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.TeamSkillQuery", q)
}
// The TraverseTeamSkill type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTeamSkill func(context.Context, *db.TeamSkillQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTeamSkill) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseTeamSkill) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.TeamSkillQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.TeamSkillQuery", q)
}
// The UserFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserFunc func(context.Context, *db.UserQuery) (db.Value, error)
@@ -1264,6 +1348,8 @@ func NewQuery(q db.Query) (Query, error) {
return &query[*db.ProjectIssueCommentQuery, predicate.ProjectIssueComment, projectissuecomment.OrderOption]{typ: db.TypeProjectIssueComment, tq: q}, nil
case *db.ProjectTaskQuery:
return &query[*db.ProjectTaskQuery, predicate.ProjectTask, projecttask.OrderOption]{typ: db.TypeProjectTask, tq: q}, nil
case *db.SkillQuery:
return &query[*db.SkillQuery, predicate.Skill, skill.OrderOption]{typ: db.TypeSkill, tq: q}, nil
case *db.TaskQuery:
return &query[*db.TaskQuery, predicate.Task, task.OrderOption]{typ: db.TypeTask, tq: q}, nil
case *db.TaskModelSwitchQuery:
@@ -1284,6 +1370,8 @@ func NewQuery(q db.Query) (Query, error) {
return &query[*db.TeamGroupMemberQuery, predicate.TeamGroupMember, teamgroupmember.OrderOption]{typ: db.TypeTeamGroupMember, tq: q}, nil
case *db.TeamGroupModelQuery:
return &query[*db.TeamGroupModelQuery, predicate.TeamGroupModel, teamgroupmodel.OrderOption]{typ: db.TypeTeamGroupModel, tq: q}, nil
case *db.TeamGroupSkillQuery:
return &query[*db.TeamGroupSkillQuery, predicate.TeamGroupSkill, teamgroupskill.OrderOption]{typ: db.TypeTeamGroupSkill, tq: q}, nil
case *db.TeamHostQuery:
return &query[*db.TeamHostQuery, predicate.TeamHost, teamhost.OrderOption]{typ: db.TypeTeamHost, tq: q}, nil
case *db.TeamImageQuery:
@@ -1294,6 +1382,8 @@ func NewQuery(q db.Query) (Query, error) {
return &query[*db.TeamModelQuery, predicate.TeamModel, teammodel.OrderOption]{typ: db.TypeTeamModel, tq: q}, nil
case *db.TeamOIDCConfigQuery:
return &query[*db.TeamOIDCConfigQuery, predicate.TeamOIDCConfig, teamoidcconfig.OrderOption]{typ: db.TypeTeamOIDCConfig, tq: q}, nil
case *db.TeamSkillQuery:
return &query[*db.TeamSkillQuery, predicate.TeamSkill, teamskill.OrderOption]{typ: db.TypeTeamSkill, tq: q}, nil
case *db.UserQuery:
return &query[*db.UserQuery, predicate.User, user.OrderOption]{typ: db.TypeUser, tq: q}, nil
case *db.UserIdentityQuery:
+116
View File
@@ -783,6 +783,37 @@ var (
},
},
}
// SkillsColumns holds the columns for the "skills" table.
SkillsColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID, Unique: true},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
{Name: "name", Type: field.TypeString},
{Name: "description", Type: field.TypeString, Size: 2147483647},
{Name: "tags", Type: field.TypeJSON, Nullable: true},
{Name: "content", Type: field.TypeString, Size: 2147483647},
{Name: "package_object_key", Type: field.TypeString, Nullable: true},
{Name: "package_url", Type: field.TypeString, Nullable: true},
{Name: "source_type", Type: field.TypeString},
{Name: "source_label", Type: field.TypeString},
{Name: "skill_md_path", Type: field.TypeString, Nullable: true},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
{Name: "user_id", Type: field.TypeUUID},
}
// SkillsTable holds the schema information for the "skills" table.
SkillsTable = &schema.Table{
Name: "skills",
Columns: SkillsColumns,
PrimaryKey: []*schema.Column{SkillsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "skills_users_skills",
Columns: []*schema.Column{SkillsColumns[13]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
},
}
// TasksColumns holds the columns for the "tasks" table.
TasksColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID},
@@ -1114,6 +1145,40 @@ var (
},
},
}
// TeamGroupSkillsColumns holds the columns for the "team_group_skills" table.
TeamGroupSkillsColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID, Unique: true},
{Name: "created_at", Type: field.TypeTime},
{Name: "group_id", Type: field.TypeUUID},
{Name: "skill_id", Type: field.TypeUUID},
}
// TeamGroupSkillsTable holds the schema information for the "team_group_skills" table.
TeamGroupSkillsTable = &schema.Table{
Name: "team_group_skills",
Columns: TeamGroupSkillsColumns,
PrimaryKey: []*schema.Column{TeamGroupSkillsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "team_group_skills_team_groups_group",
Columns: []*schema.Column{TeamGroupSkillsColumns[2]},
RefColumns: []*schema.Column{TeamGroupsColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "team_group_skills_skills_skill",
Columns: []*schema.Column{TeamGroupSkillsColumns[3]},
RefColumns: []*schema.Column{SkillsColumns[0]},
OnDelete: schema.NoAction,
},
},
Indexes: []*schema.Index{
{
Name: "teamgroupskill_group_id_skill_id",
Unique: true,
Columns: []*schema.Column{TeamGroupSkillsColumns[2], TeamGroupSkillsColumns[3]},
},
},
}
// TeamHostsColumns holds the columns for the "team_hosts" table.
TeamHostsColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID, Unique: true},
@@ -1281,6 +1346,40 @@ var (
},
},
}
// TeamSkillsColumns holds the columns for the "team_skills" table.
TeamSkillsColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID},
{Name: "created_at", Type: field.TypeTime},
{Name: "team_id", Type: field.TypeUUID},
{Name: "skill_id", Type: field.TypeUUID},
}
// TeamSkillsTable holds the schema information for the "team_skills" table.
TeamSkillsTable = &schema.Table{
Name: "team_skills",
Columns: TeamSkillsColumns,
PrimaryKey: []*schema.Column{TeamSkillsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "team_skills_teams_team",
Columns: []*schema.Column{TeamSkillsColumns[2]},
RefColumns: []*schema.Column{TeamsColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "team_skills_skills_skill",
Columns: []*schema.Column{TeamSkillsColumns[3]},
RefColumns: []*schema.Column{SkillsColumns[0]},
OnDelete: schema.NoAction,
},
},
Indexes: []*schema.Index{
{
Name: "teamskill_team_id_skill_id",
Unique: true,
Columns: []*schema.Column{TeamSkillsColumns[2], TeamSkillsColumns[3]},
},
},
}
// UsersColumns holds the columns for the "users" table.
UsersColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID, Unique: true},
@@ -1415,6 +1514,7 @@ var (
ProjectIssuesTable,
ProjectIssueCommentsTable,
ProjectTasksTable,
SkillsTable,
TasksTable,
TaskModelSwitchesTable,
TaskUsageStatsTable,
@@ -1425,11 +1525,13 @@ var (
TeamGroupImagesTable,
TeamGroupMembersTable,
TeamGroupModelsTable,
TeamGroupSkillsTable,
TeamHostsTable,
TeamImagesTable,
TeamMembersTable,
TeamModelsTable,
TeamOidcConfigsTable,
TeamSkillsTable,
UsersTable,
UserIdentitiesTable,
VirtualmachinesTable,
@@ -1541,6 +1643,10 @@ func init() {
ProjectTasksTable.Annotation = &entsql.Annotation{
Table: "project_tasks",
}
SkillsTable.ForeignKeys[0].RefTable = UsersTable
SkillsTable.Annotation = &entsql.Annotation{
Table: "skills",
}
TasksTable.ForeignKeys[0].RefTable = UsersTable
TasksTable.Annotation = &entsql.Annotation{
Table: "tasks",
@@ -1587,6 +1693,11 @@ func init() {
TeamGroupModelsTable.Annotation = &entsql.Annotation{
Table: "team_group_models",
}
TeamGroupSkillsTable.ForeignKeys[0].RefTable = TeamGroupsTable
TeamGroupSkillsTable.ForeignKeys[1].RefTable = SkillsTable
TeamGroupSkillsTable.Annotation = &entsql.Annotation{
Table: "team_group_skills",
}
TeamHostsTable.ForeignKeys[0].RefTable = TeamsTable
TeamHostsTable.ForeignKeys[1].RefTable = HostsTable
TeamHostsTable.Annotation = &entsql.Annotation{
@@ -1611,6 +1722,11 @@ func init() {
TeamOidcConfigsTable.Annotation = &entsql.Annotation{
Table: "team_oidc_configs",
}
TeamSkillsTable.ForeignKeys[0].RefTable = TeamsTable
TeamSkillsTable.ForeignKeys[1].RefTable = SkillsTable
TeamSkillsTable.Annotation = &entsql.Annotation{
Table: "team_skills",
}
UsersTable.Annotation = &entsql.Annotation{
Table: "users",
}
+2993 -9
View File
File diff suppressed because it is too large. Load diff
+42
View File
@@ -333,6 +333,20 @@ func (_m *ProjectTaskQuery) Page(ctx context.Context, page, size int) ([]*Projec
return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil
}
func (_m *SkillQuery) Page(ctx context.Context, page, size int) ([]*Skill, *PageInfo, error) {
cnt, err := _m.Count(ctx)
if err != nil {
return nil, nil, err
}
offset := size * (page - 1)
rs, err := _m.Offset(offset).Limit(size).All(ctx)
if err != nil {
return nil, nil, err
}
has := (page * size) < cnt
return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil
}
func (_m *TaskQuery) Page(ctx context.Context, page, size int) ([]*Task, *PageInfo, error) {
cnt, err := _m.Count(ctx)
if err != nil {
@@ -473,6 +487,20 @@ func (_m *TeamGroupModelQuery) Page(ctx context.Context, page, size int) ([]*Tea
return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil
}
func (_m *TeamGroupSkillQuery) Page(ctx context.Context, page, size int) ([]*TeamGroupSkill, *PageInfo, error) {
cnt, err := _m.Count(ctx)
if err != nil {
return nil, nil, err
}
offset := size * (page - 1)
rs, err := _m.Offset(offset).Limit(size).All(ctx)
if err != nil {
return nil, nil, err
}
has := (page * size) < cnt
return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil
}
func (_m *TeamHostQuery) Page(ctx context.Context, page, size int) ([]*TeamHost, *PageInfo, error) {
cnt, err := _m.Count(ctx)
if err != nil {
@@ -543,6 +571,20 @@ func (_m *TeamOIDCConfigQuery) Page(ctx context.Context, page, size int) ([]*Tea
return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil
}
func (_m *TeamSkillQuery) Page(ctx context.Context, page, size int) ([]*TeamSkill, *PageInfo, error) {
cnt, err := _m.Count(ctx)
if err != nil {
return nil, nil, err
}
offset := size * (page - 1)
rs, err := _m.Offset(offset).Limit(size).All(ctx)
if err != nil {
return nil, nil, err
}
has := (page * size) < cnt
return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil
}
func (_m *UserQuery) Page(ctx context.Context, page, size int) ([]*User, *PageInfo, error) {
cnt, err := _m.Count(ctx)
if err != nil {
+9
View File
@@ -75,6 +75,9 @@ type ProjectIssueComment func(*sql.Selector)
// ProjectTask is the predicate function for projecttask builders.
type ProjectTask func(*sql.Selector)
// Skill is the predicate function for skill builders.
type Skill func(*sql.Selector)
// Task is the predicate function for task builders.
type Task func(*sql.Selector)
@@ -105,6 +108,9 @@ type TeamGroupMember func(*sql.Selector)
// TeamGroupModel is the predicate function for teamgroupmodel builders.
type TeamGroupModel func(*sql.Selector)
// TeamGroupSkill is the predicate function for teamgroupskill builders.
type TeamGroupSkill func(*sql.Selector)
// TeamHost is the predicate function for teamhost builders.
type TeamHost func(*sql.Selector)
@@ -120,6 +126,9 @@ type TeamModel func(*sql.Selector)
// TeamOIDCConfig is the predicate function for teamoidcconfig builders.
type TeamOIDCConfig func(*sql.Selector)
// TeamSkill is the predicate function for teamskill builders.
type TeamSkill func(*sql.Selector)
// User is the predicate function for user builders.
type User func(*sql.Selector)
+52
View File
@@ -29,6 +29,7 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/projectissue"
"github.com/chaitin/MonkeyCode/backend/db/projectissuecomment"
"github.com/chaitin/MonkeyCode/backend/db/projecttask"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/task"
"github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch"
"github.com/chaitin/MonkeyCode/backend/db/taskusagestat"
@@ -39,11 +40,13 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/teamgroupimage"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmember"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/chaitin/MonkeyCode/backend/db/teamhost"
"github.com/chaitin/MonkeyCode/backend/db/teamimage"
"github.com/chaitin/MonkeyCode/backend/db/teammember"
"github.com/chaitin/MonkeyCode/backend/db/teammodel"
"github.com/chaitin/MonkeyCode/backend/db/teamoidcconfig"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/chaitin/MonkeyCode/backend/db/useridentity"
"github.com/chaitin/MonkeyCode/backend/db/virtualmachine"
@@ -657,6 +660,43 @@ func init() {
projecttaskDescCreatedAt := projecttaskFields[11].Descriptor()
// projecttask.DefaultCreatedAt holds the default value on creation for the created_at field.
projecttask.DefaultCreatedAt = projecttaskDescCreatedAt.Default.(func() time.Time)
skillMixin := schema.Skill{}.Mixin()
skillMixinHooks0 := skillMixin[0].Hooks()
skill.Hooks[0] = skillMixinHooks0[0]
skillMixinInters0 := skillMixin[0].Interceptors()
skill.Interceptors[0] = skillMixinInters0[0]
skillFields := schema.Skill{}.Fields()
_ = skillFields
// skillDescName is the schema descriptor for name field.
skillDescName := skillFields[2].Descriptor()
// skill.NameValidator is a validator for the "name" field. It is called by the builders before save.
skill.NameValidator = skillDescName.Validators[0].(func(string) error)
// skillDescDescription is the schema descriptor for description field.
skillDescDescription := skillFields[3].Descriptor()
// skill.DescriptionValidator is a validator for the "description" field. It is called by the builders before save.
skill.DescriptionValidator = skillDescDescription.Validators[0].(func(string) error)
// skillDescContent is the schema descriptor for content field.
skillDescContent := skillFields[5].Descriptor()
// skill.ContentValidator is a validator for the "content" field. It is called by the builders before save.
skill.ContentValidator = skillDescContent.Validators[0].(func(string) error)
// skillDescSourceType is the schema descriptor for source_type field.
skillDescSourceType := skillFields[8].Descriptor()
// skill.SourceTypeValidator is a validator for the "source_type" field. It is called by the builders before save.
skill.SourceTypeValidator = skillDescSourceType.Validators[0].(func(string) error)
// skillDescSourceLabel is the schema descriptor for source_label field.
skillDescSourceLabel := skillFields[9].Descriptor()
// skill.SourceLabelValidator is a validator for the "source_label" field. It is called by the builders before save.
skill.SourceLabelValidator = skillDescSourceLabel.Validators[0].(func(string) error)
// skillDescCreatedAt is the schema descriptor for created_at field.
skillDescCreatedAt := skillFields[11].Descriptor()
// skill.DefaultCreatedAt holds the default value on creation for the created_at field.
skill.DefaultCreatedAt = skillDescCreatedAt.Default.(func() time.Time)
// skillDescUpdatedAt is the schema descriptor for updated_at field.
skillDescUpdatedAt := skillFields[12].Descriptor()
// skill.DefaultUpdatedAt holds the default value on creation for the updated_at field.
skill.DefaultUpdatedAt = skillDescUpdatedAt.Default.(func() time.Time)
// skill.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
skill.UpdateDefaultUpdatedAt = skillDescUpdatedAt.UpdateDefault.(func() time.Time)
taskMixin := schema.Task{}.Mixin()
taskMixinHooks0 := taskMixin[0].Hooks()
task.Hooks[0] = taskMixinHooks0[0]
@@ -822,6 +862,12 @@ func init() {
teamgroupmodelDescCreatedAt := teamgroupmodelFields[3].Descriptor()
// teamgroupmodel.DefaultCreatedAt holds the default value on creation for the created_at field.
teamgroupmodel.DefaultCreatedAt = teamgroupmodelDescCreatedAt.Default.(func() time.Time)
teamgroupskillFields := schema.TeamGroupSkill{}.Fields()
_ = teamgroupskillFields
// teamgroupskillDescCreatedAt is the schema descriptor for created_at field.
teamgroupskillDescCreatedAt := teamgroupskillFields[3].Descriptor()
// teamgroupskill.DefaultCreatedAt holds the default value on creation for the created_at field.
teamgroupskill.DefaultCreatedAt = teamgroupskillDescCreatedAt.Default.(func() time.Time)
teamhostFields := schema.TeamHost{}.Fields()
_ = teamhostFields
// teamhostDescCreatedAt is the schema descriptor for created_at field.
@@ -886,6 +932,12 @@ func init() {
teamoidcconfig.DefaultUpdatedAt = teamoidcconfigDescUpdatedAt.Default.(func() time.Time)
// teamoidcconfig.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
teamoidcconfig.UpdateDefaultUpdatedAt = teamoidcconfigDescUpdatedAt.UpdateDefault.(func() time.Time)
teamskillFields := schema.TeamSkill{}.Fields()
_ = teamskillFields
// teamskillDescCreatedAt is the schema descriptor for created_at field.
teamskillDescCreatedAt := teamskillFields[3].Descriptor()
// teamskill.DefaultCreatedAt holds the default value on creation for the created_at field.
teamskill.DefaultCreatedAt = teamskillDescCreatedAt.Default.(func() time.Time)
userMixin := schema.User{}.Mixin()
userMixinHooks0 := userMixin[0].Hooks()
user.Hooks[0] = userMixinHooks0[0]
+337
View File
@@ -0,0 +1,337 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/google/uuid"
)
// Skill is the model entity for the Skill schema.
type Skill struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// DeletedAt holds the value of the "deleted_at" field.
DeletedAt time.Time `json:"deleted_at,omitempty"`
// UserID holds the value of the "user_id" field.
UserID uuid.UUID `json:"user_id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Description holds the value of the "description" field.
Description string `json:"description,omitempty"`
// Tags holds the value of the "tags" field.
Tags []string `json:"tags,omitempty"`
// Content holds the value of the "content" field.
Content string `json:"content,omitempty"`
// PackageObjectKey holds the value of the "package_object_key" field.
PackageObjectKey string `json:"package_object_key,omitempty"`
// PackageURL holds the value of the "package_url" field.
PackageURL string `json:"package_url,omitempty"`
// SourceType holds the value of the "source_type" field.
SourceType string `json:"source_type,omitempty"`
// SourceLabel holds the value of the "source_label" field.
SourceLabel string `json:"source_label,omitempty"`
// SkillMdPath holds the value of the "skill_md_path" field.
SkillMdPath string `json:"skill_md_path,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the SkillQuery when eager-loading is set.
Edges SkillEdges `json:"edges"`
selectValues sql.SelectValues
}
// SkillEdges holds the relations/edges for other nodes in the graph.
type SkillEdges struct {
// User holds the value of the user edge.
User *User `json:"user,omitempty"`
// Teams holds the value of the teams edge.
Teams []*Team `json:"teams,omitempty"`
// Groups holds the value of the groups edge.
Groups []*TeamGroup `json:"groups,omitempty"`
// TeamSkills holds the value of the team_skills edge.
TeamSkills []*TeamSkill `json:"team_skills,omitempty"`
// TeamGroupSkills holds the value of the team_group_skills edge.
TeamGroupSkills []*TeamGroupSkill `json:"team_group_skills,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [5]bool
}
// UserOrErr returns the User value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e SkillEdges) UserOrErr() (*User, error) {
if e.User != nil {
return e.User, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: user.Label}
}
return nil, &NotLoadedError{edge: "user"}
}
// TeamsOrErr returns the Teams value or an error if the edge
// was not loaded in eager-loading.
func (e SkillEdges) TeamsOrErr() ([]*Team, error) {
if e.loadedTypes[1] {
return e.Teams, nil
}
return nil, &NotLoadedError{edge: "teams"}
}
// GroupsOrErr returns the Groups value or an error if the edge
// was not loaded in eager-loading.
func (e SkillEdges) GroupsOrErr() ([]*TeamGroup, error) {
if e.loadedTypes[2] {
return e.Groups, nil
}
return nil, &NotLoadedError{edge: "groups"}
}
// TeamSkillsOrErr returns the TeamSkills value or an error if the edge
// was not loaded in eager-loading.
func (e SkillEdges) TeamSkillsOrErr() ([]*TeamSkill, error) {
if e.loadedTypes[3] {
return e.TeamSkills, nil
}
return nil, &NotLoadedError{edge: "team_skills"}
}
// TeamGroupSkillsOrErr returns the TeamGroupSkills value or an error if the edge
// was not loaded in eager-loading.
func (e SkillEdges) TeamGroupSkillsOrErr() ([]*TeamGroupSkill, error) {
if e.loadedTypes[4] {
return e.TeamGroupSkills, nil
}
return nil, &NotLoadedError{edge: "team_group_skills"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Skill) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case skill.FieldTags:
values[i] = new([]byte)
case skill.FieldName, skill.FieldDescription, skill.FieldContent, skill.FieldPackageObjectKey, skill.FieldPackageURL, skill.FieldSourceType, skill.FieldSourceLabel, skill.FieldSkillMdPath:
values[i] = new(sql.NullString)
case skill.FieldDeletedAt, skill.FieldCreatedAt, skill.FieldUpdatedAt:
values[i] = new(sql.NullTime)
case skill.FieldID, skill.FieldUserID:
values[i] = new(uuid.UUID)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Skill fields.
func (_m *Skill) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case skill.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
_m.ID = *value
}
case skill.FieldDeletedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
} else if value.Valid {
_m.DeletedAt = value.Time
}
case skill.FieldUserID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field user_id", values[i])
} else if value != nil {
_m.UserID = *value
}
case skill.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case skill.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
_m.Description = value.String
}
case skill.FieldTags:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field tags", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &_m.Tags); err != nil {
return fmt.Errorf("unmarshal field tags: %w", err)
}
}
case skill.FieldContent:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field content", values[i])
} else if value.Valid {
_m.Content = value.String
}
case skill.FieldPackageObjectKey:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field package_object_key", values[i])
} else if value.Valid {
_m.PackageObjectKey = value.String
}
case skill.FieldPackageURL:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field package_url", values[i])
} else if value.Valid {
_m.PackageURL = value.String
}
case skill.FieldSourceType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field source_type", values[i])
} else if value.Valid {
_m.SourceType = value.String
}
case skill.FieldSourceLabel:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field source_label", values[i])
} else if value.Valid {
_m.SourceLabel = value.String
}
case skill.FieldSkillMdPath:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field skill_md_path", values[i])
} else if value.Valid {
_m.SkillMdPath = value.String
}
case skill.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case skill.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
_m.UpdatedAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Skill.
// This includes values selected through modifiers, order, etc.
func (_m *Skill) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryUser queries the "user" edge of the Skill entity.
func (_m *Skill) QueryUser() *UserQuery {
return NewSkillClient(_m.config).QueryUser(_m)
}
// QueryTeams queries the "teams" edge of the Skill entity.
func (_m *Skill) QueryTeams() *TeamQuery {
return NewSkillClient(_m.config).QueryTeams(_m)
}
// QueryGroups queries the "groups" edge of the Skill entity.
func (_m *Skill) QueryGroups() *TeamGroupQuery {
return NewSkillClient(_m.config).QueryGroups(_m)
}
// QueryTeamSkills queries the "team_skills" edge of the Skill entity.
func (_m *Skill) QueryTeamSkills() *TeamSkillQuery {
return NewSkillClient(_m.config).QueryTeamSkills(_m)
}
// QueryTeamGroupSkills queries the "team_group_skills" edge of the Skill entity.
func (_m *Skill) QueryTeamGroupSkills() *TeamGroupSkillQuery {
return NewSkillClient(_m.config).QueryTeamGroupSkills(_m)
}
// Update returns a builder for updating this Skill.
// Note that you need to call Skill.Unwrap() before calling this method if this Skill
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Skill) Update() *SkillUpdateOne {
return NewSkillClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Skill entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *Skill) Unwrap() *Skill {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("db: Skill is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Skill) String() string {
var builder strings.Builder
builder.WriteString("Skill(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("deleted_at=")
builder.WriteString(_m.DeletedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("user_id=")
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("description=")
builder.WriteString(_m.Description)
builder.WriteString(", ")
builder.WriteString("tags=")
builder.WriteString(fmt.Sprintf("%v", _m.Tags))
builder.WriteString(", ")
builder.WriteString("content=")
builder.WriteString(_m.Content)
builder.WriteString(", ")
builder.WriteString("package_object_key=")
builder.WriteString(_m.PackageObjectKey)
builder.WriteString(", ")
builder.WriteString("package_url=")
builder.WriteString(_m.PackageURL)
builder.WriteString(", ")
builder.WriteString("source_type=")
builder.WriteString(_m.SourceType)
builder.WriteString(", ")
builder.WriteString("source_label=")
builder.WriteString(_m.SourceLabel)
builder.WriteString(", ")
builder.WriteString("skill_md_path=")
builder.WriteString(_m.SkillMdPath)
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// Skills is a parsable slice of Skill.
type Skills []*Skill
+316
View File
@@ -0,0 +1,316 @@
// Code generated by ent, DO NOT EDIT.
package skill
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the skill type in the database.
Label = "skill"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldDeletedAt holds the string denoting the deleted_at field in the database.
FieldDeletedAt = "deleted_at"
// FieldUserID holds the string denoting the user_id field in the database.
FieldUserID = "user_id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldDescription holds the string denoting the description field in the database.
FieldDescription = "description"
// FieldTags holds the string denoting the tags field in the database.
FieldTags = "tags"
// FieldContent holds the string denoting the content field in the database.
FieldContent = "content"
// FieldPackageObjectKey holds the string denoting the package_object_key field in the database.
FieldPackageObjectKey = "package_object_key"
// FieldPackageURL holds the string denoting the package_url field in the database.
FieldPackageURL = "package_url"
// FieldSourceType holds the string denoting the source_type field in the database.
FieldSourceType = "source_type"
// FieldSourceLabel holds the string denoting the source_label field in the database.
FieldSourceLabel = "source_label"
// FieldSkillMdPath holds the string denoting the skill_md_path field in the database.
FieldSkillMdPath = "skill_md_path"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// EdgeUser holds the string denoting the user edge name in mutations.
EdgeUser = "user"
// EdgeTeams holds the string denoting the teams edge name in mutations.
EdgeTeams = "teams"
// EdgeGroups holds the string denoting the groups edge name in mutations.
EdgeGroups = "groups"
// EdgeTeamSkills holds the string denoting the team_skills edge name in mutations.
EdgeTeamSkills = "team_skills"
// EdgeTeamGroupSkills holds the string denoting the team_group_skills edge name in mutations.
EdgeTeamGroupSkills = "team_group_skills"
// Table holds the table name of the skill in the database.
Table = "skills"
// UserTable is the table that holds the user relation/edge.
UserTable = "skills"
// UserInverseTable is the table name for the User entity.
// It exists in this package in order to avoid circular dependency with the "user" package.
UserInverseTable = "users"
// UserColumn is the table column denoting the user relation/edge.
UserColumn = "user_id"
// TeamsTable is the table that holds the teams relation/edge. The primary key declared below.
TeamsTable = "team_skills"
// TeamsInverseTable is the table name for the Team entity.
// It exists in this package in order to avoid circular dependency with the "team" package.
TeamsInverseTable = "teams"
// GroupsTable is the table that holds the groups relation/edge. The primary key declared below.
GroupsTable = "team_group_skills"
// GroupsInverseTable is the table name for the TeamGroup entity.
// It exists in this package in order to avoid circular dependency with the "teamgroup" package.
GroupsInverseTable = "team_groups"
// TeamSkillsTable is the table that holds the team_skills relation/edge.
TeamSkillsTable = "team_skills"
// TeamSkillsInverseTable is the table name for the TeamSkill entity.
// It exists in this package in order to avoid circular dependency with the "teamskill" package.
TeamSkillsInverseTable = "team_skills"
// TeamSkillsColumn is the table column denoting the team_skills relation/edge.
TeamSkillsColumn = "skill_id"
// TeamGroupSkillsTable is the table that holds the team_group_skills relation/edge.
TeamGroupSkillsTable = "team_group_skills"
// TeamGroupSkillsInverseTable is the table name for the TeamGroupSkill entity.
// It exists in this package in order to avoid circular dependency with the "teamgroupskill" package.
TeamGroupSkillsInverseTable = "team_group_skills"
// TeamGroupSkillsColumn is the table column denoting the team_group_skills relation/edge.
TeamGroupSkillsColumn = "skill_id"
)
// Columns holds all SQL columns for skill fields.
var Columns = []string{
FieldID,
FieldDeletedAt,
FieldUserID,
FieldName,
FieldDescription,
FieldTags,
FieldContent,
FieldPackageObjectKey,
FieldPackageURL,
FieldSourceType,
FieldSourceLabel,
FieldSkillMdPath,
FieldCreatedAt,
FieldUpdatedAt,
}
var (
// TeamsPrimaryKey and TeamsColumn2 are the table columns denoting the
// primary key for the teams relation (M2M).
TeamsPrimaryKey = []string{"team_id", "skill_id"}
// GroupsPrimaryKey and GroupsColumn2 are the table columns denoting the
// primary key for the groups relation (M2M).
GroupsPrimaryKey = []string{"group_id", "skill_id"}
)
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
// Note that the variables below are initialized by the runtime
// package on the initialization of the application. Therefore,
// it should be imported in the main as follows:
//
// import _ "github.com/chaitin/MonkeyCode/backend/db/runtime"
var (
Hooks [1]ent.Hook
Interceptors [1]ent.Interceptor
// NameValidator is a validator for the "name" field. It is called by the builders before save.
NameValidator func(string) error
// DescriptionValidator is a validator for the "description" field. It is called by the builders before save.
DescriptionValidator func(string) error
// ContentValidator is a validator for the "content" field. It is called by the builders before save.
ContentValidator func(string) error
// SourceTypeValidator is a validator for the "source_type" field. It is called by the builders before save.
SourceTypeValidator func(string) error
// SourceLabelValidator is a validator for the "source_label" field. It is called by the builders before save.
SourceLabelValidator func(string) error
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
)
// OrderOption defines the ordering options for the Skill queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByDeletedAt orders the results by the deleted_at field.
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
}
// ByUserID orders the results by the user_id field.
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUserID, opts...).ToFunc()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByDescription orders the results by the description field.
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDescription, opts...).ToFunc()
}
// ByContent orders the results by the content field.
func ByContent(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldContent, opts...).ToFunc()
}
// ByPackageObjectKey orders the results by the package_object_key field.
func ByPackageObjectKey(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPackageObjectKey, opts...).ToFunc()
}
// ByPackageURL orders the results by the package_url field.
func ByPackageURL(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPackageURL, opts...).ToFunc()
}
// BySourceType orders the results by the source_type field.
func BySourceType(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSourceType, opts...).ToFunc()
}
// BySourceLabel orders the results by the source_label field.
func BySourceLabel(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSourceLabel, opts...).ToFunc()
}
// BySkillMdPath orders the results by the skill_md_path field.
func BySkillMdPath(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSkillMdPath, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByUserField orders the results by user field.
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
}
}
// ByTeamsCount orders the results by teams count.
func ByTeamsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newTeamsStep(), opts...)
}
}
// ByTeams orders the results by teams terms.
func ByTeams(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newTeamsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByGroupsCount orders the results by groups count.
func ByGroupsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newGroupsStep(), opts...)
}
}
// ByGroups orders the results by groups terms.
func ByGroups(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newGroupsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByTeamSkillsCount orders the results by team_skills count.
func ByTeamSkillsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newTeamSkillsStep(), opts...)
}
}
// ByTeamSkills orders the results by team_skills terms.
func ByTeamSkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newTeamSkillsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByTeamGroupSkillsCount orders the results by team_group_skills count.
func ByTeamGroupSkillsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newTeamGroupSkillsStep(), opts...)
}
}
// ByTeamGroupSkills orders the results by team_group_skills terms.
func ByTeamGroupSkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newTeamGroupSkillsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newUserStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(UserInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
)
}
func newTeamsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(TeamsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2M, true, TeamsTable, TeamsPrimaryKey...),
)
}
func newGroupsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(GroupsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2M, true, GroupsTable, GroupsPrimaryKey...),
)
}
func newTeamSkillsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(TeamSkillsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, TeamSkillsTable, TeamSkillsColumn),
)
}
func newTeamGroupSkillsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(TeamGroupSkillsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, TeamGroupSkillsTable, TeamGroupSkillsColumn),
)
}
+957
View File
@@ -0,0 +1,957 @@
// Code generated by ent, DO NOT EDIT.
package skill
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/google/uuid"
)
// ID filters vertices based on their ID field.
func ID(id uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldID, id))
}
// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
func DeletedAt(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldDeletedAt, v))
}
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
func UserID(v uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldUserID, v))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldName, v))
}
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
func Description(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldDescription, v))
}
// Content applies equality check predicate on the "content" field. It's identical to ContentEQ.
func Content(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldContent, v))
}
// PackageObjectKey applies equality check predicate on the "package_object_key" field. It's identical to PackageObjectKeyEQ.
func PackageObjectKey(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldPackageObjectKey, v))
}
// PackageURL applies equality check predicate on the "package_url" field. It's identical to PackageURLEQ.
func PackageURL(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldPackageURL, v))
}
// SourceType applies equality check predicate on the "source_type" field. It's identical to SourceTypeEQ.
func SourceType(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldSourceType, v))
}
// SourceLabel applies equality check predicate on the "source_label" field. It's identical to SourceLabelEQ.
func SourceLabel(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldSourceLabel, v))
}
// SkillMdPath applies equality check predicate on the "skill_md_path" field. It's identical to SkillMdPathEQ.
func SkillMdPath(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldSkillMdPath, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldUpdatedAt, v))
}
// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
func DeletedAtEQ(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldDeletedAt, v))
}
// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
func DeletedAtNEQ(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldDeletedAt, v))
}
// DeletedAtIn applies the In predicate on the "deleted_at" field.
func DeletedAtIn(vs ...time.Time) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldDeletedAt, vs...))
}
// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
func DeletedAtNotIn(vs ...time.Time) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldDeletedAt, vs...))
}
// DeletedAtGT applies the GT predicate on the "deleted_at" field.
func DeletedAtGT(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldDeletedAt, v))
}
// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
func DeletedAtGTE(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldDeletedAt, v))
}
// DeletedAtLT applies the LT predicate on the "deleted_at" field.
func DeletedAtLT(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldDeletedAt, v))
}
// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
func DeletedAtLTE(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldDeletedAt, v))
}
// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
func DeletedAtIsNil() predicate.Skill {
return predicate.Skill(sql.FieldIsNull(FieldDeletedAt))
}
// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
func DeletedAtNotNil() predicate.Skill {
return predicate.Skill(sql.FieldNotNull(FieldDeletedAt))
}
// UserIDEQ applies the EQ predicate on the "user_id" field.
func UserIDEQ(v uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldUserID, v))
}
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
func UserIDNEQ(v uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldUserID, v))
}
// UserIDIn applies the In predicate on the "user_id" field.
func UserIDIn(vs ...uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldUserID, vs...))
}
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
func UserIDNotIn(vs ...uuid.UUID) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldUserID, vs...))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.Skill {
return predicate.Skill(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldContainsFold(FieldName, v))
}
// DescriptionEQ applies the EQ predicate on the "description" field.
func DescriptionEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldDescription, v))
}
// DescriptionNEQ applies the NEQ predicate on the "description" field.
func DescriptionNEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldDescription, v))
}
// DescriptionIn applies the In predicate on the "description" field.
func DescriptionIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldDescription, vs...))
}
// DescriptionNotIn applies the NotIn predicate on the "description" field.
func DescriptionNotIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldDescription, vs...))
}
// DescriptionGT applies the GT predicate on the "description" field.
func DescriptionGT(v string) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldDescription, v))
}
// DescriptionGTE applies the GTE predicate on the "description" field.
func DescriptionGTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldDescription, v))
}
// DescriptionLT applies the LT predicate on the "description" field.
func DescriptionLT(v string) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldDescription, v))
}
// DescriptionLTE applies the LTE predicate on the "description" field.
func DescriptionLTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldDescription, v))
}
// DescriptionContains applies the Contains predicate on the "description" field.
func DescriptionContains(v string) predicate.Skill {
return predicate.Skill(sql.FieldContains(FieldDescription, v))
}
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
func DescriptionHasPrefix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasPrefix(FieldDescription, v))
}
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
func DescriptionHasSuffix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasSuffix(FieldDescription, v))
}
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
func DescriptionEqualFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldEqualFold(FieldDescription, v))
}
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
func DescriptionContainsFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldContainsFold(FieldDescription, v))
}
// TagsIsNil applies the IsNil predicate on the "tags" field.
func TagsIsNil() predicate.Skill {
return predicate.Skill(sql.FieldIsNull(FieldTags))
}
// TagsNotNil applies the NotNil predicate on the "tags" field.
func TagsNotNil() predicate.Skill {
return predicate.Skill(sql.FieldNotNull(FieldTags))
}
// ContentEQ applies the EQ predicate on the "content" field.
func ContentEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldContent, v))
}
// ContentNEQ applies the NEQ predicate on the "content" field.
func ContentNEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldContent, v))
}
// ContentIn applies the In predicate on the "content" field.
func ContentIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldContent, vs...))
}
// ContentNotIn applies the NotIn predicate on the "content" field.
func ContentNotIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldContent, vs...))
}
// ContentGT applies the GT predicate on the "content" field.
func ContentGT(v string) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldContent, v))
}
// ContentGTE applies the GTE predicate on the "content" field.
func ContentGTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldContent, v))
}
// ContentLT applies the LT predicate on the "content" field.
func ContentLT(v string) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldContent, v))
}
// ContentLTE applies the LTE predicate on the "content" field.
func ContentLTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldContent, v))
}
// ContentContains applies the Contains predicate on the "content" field.
func ContentContains(v string) predicate.Skill {
return predicate.Skill(sql.FieldContains(FieldContent, v))
}
// ContentHasPrefix applies the HasPrefix predicate on the "content" field.
func ContentHasPrefix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasPrefix(FieldContent, v))
}
// ContentHasSuffix applies the HasSuffix predicate on the "content" field.
func ContentHasSuffix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasSuffix(FieldContent, v))
}
// ContentEqualFold applies the EqualFold predicate on the "content" field.
func ContentEqualFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldEqualFold(FieldContent, v))
}
// ContentContainsFold applies the ContainsFold predicate on the "content" field.
func ContentContainsFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldContainsFold(FieldContent, v))
}
// PackageObjectKeyEQ applies the EQ predicate on the "package_object_key" field.
func PackageObjectKeyEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldPackageObjectKey, v))
}
// PackageObjectKeyNEQ applies the NEQ predicate on the "package_object_key" field.
func PackageObjectKeyNEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldPackageObjectKey, v))
}
// PackageObjectKeyIn applies the In predicate on the "package_object_key" field.
func PackageObjectKeyIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldPackageObjectKey, vs...))
}
// PackageObjectKeyNotIn applies the NotIn predicate on the "package_object_key" field.
func PackageObjectKeyNotIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldPackageObjectKey, vs...))
}
// PackageObjectKeyGT applies the GT predicate on the "package_object_key" field.
func PackageObjectKeyGT(v string) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldPackageObjectKey, v))
}
// PackageObjectKeyGTE applies the GTE predicate on the "package_object_key" field.
func PackageObjectKeyGTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldPackageObjectKey, v))
}
// PackageObjectKeyLT applies the LT predicate on the "package_object_key" field.
func PackageObjectKeyLT(v string) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldPackageObjectKey, v))
}
// PackageObjectKeyLTE applies the LTE predicate on the "package_object_key" field.
func PackageObjectKeyLTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldPackageObjectKey, v))
}
// PackageObjectKeyContains applies the Contains predicate on the "package_object_key" field.
func PackageObjectKeyContains(v string) predicate.Skill {
return predicate.Skill(sql.FieldContains(FieldPackageObjectKey, v))
}
// PackageObjectKeyHasPrefix applies the HasPrefix predicate on the "package_object_key" field.
func PackageObjectKeyHasPrefix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasPrefix(FieldPackageObjectKey, v))
}
// PackageObjectKeyHasSuffix applies the HasSuffix predicate on the "package_object_key" field.
func PackageObjectKeyHasSuffix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasSuffix(FieldPackageObjectKey, v))
}
// PackageObjectKeyIsNil applies the IsNil predicate on the "package_object_key" field.
func PackageObjectKeyIsNil() predicate.Skill {
return predicate.Skill(sql.FieldIsNull(FieldPackageObjectKey))
}
// PackageObjectKeyNotNil applies the NotNil predicate on the "package_object_key" field.
func PackageObjectKeyNotNil() predicate.Skill {
return predicate.Skill(sql.FieldNotNull(FieldPackageObjectKey))
}
// PackageObjectKeyEqualFold applies the EqualFold predicate on the "package_object_key" field.
func PackageObjectKeyEqualFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldEqualFold(FieldPackageObjectKey, v))
}
// PackageObjectKeyContainsFold applies the ContainsFold predicate on the "package_object_key" field.
func PackageObjectKeyContainsFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldContainsFold(FieldPackageObjectKey, v))
}
// PackageURLEQ applies the EQ predicate on the "package_url" field.
func PackageURLEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldPackageURL, v))
}
// PackageURLNEQ applies the NEQ predicate on the "package_url" field.
func PackageURLNEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldPackageURL, v))
}
// PackageURLIn applies the In predicate on the "package_url" field.
func PackageURLIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldPackageURL, vs...))
}
// PackageURLNotIn applies the NotIn predicate on the "package_url" field.
func PackageURLNotIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldPackageURL, vs...))
}
// PackageURLGT applies the GT predicate on the "package_url" field.
func PackageURLGT(v string) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldPackageURL, v))
}
// PackageURLGTE applies the GTE predicate on the "package_url" field.
func PackageURLGTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldPackageURL, v))
}
// PackageURLLT applies the LT predicate on the "package_url" field.
func PackageURLLT(v string) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldPackageURL, v))
}
// PackageURLLTE applies the LTE predicate on the "package_url" field.
func PackageURLLTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldPackageURL, v))
}
// PackageURLContains applies the Contains predicate on the "package_url" field.
func PackageURLContains(v string) predicate.Skill {
return predicate.Skill(sql.FieldContains(FieldPackageURL, v))
}
// PackageURLHasPrefix applies the HasPrefix predicate on the "package_url" field.
func PackageURLHasPrefix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasPrefix(FieldPackageURL, v))
}
// PackageURLHasSuffix applies the HasSuffix predicate on the "package_url" field.
func PackageURLHasSuffix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasSuffix(FieldPackageURL, v))
}
// PackageURLIsNil applies the IsNil predicate on the "package_url" field.
func PackageURLIsNil() predicate.Skill {
return predicate.Skill(sql.FieldIsNull(FieldPackageURL))
}
// PackageURLNotNil applies the NotNil predicate on the "package_url" field.
func PackageURLNotNil() predicate.Skill {
return predicate.Skill(sql.FieldNotNull(FieldPackageURL))
}
// PackageURLEqualFold applies the EqualFold predicate on the "package_url" field.
func PackageURLEqualFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldEqualFold(FieldPackageURL, v))
}
// PackageURLContainsFold applies the ContainsFold predicate on the "package_url" field.
func PackageURLContainsFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldContainsFold(FieldPackageURL, v))
}
// SourceTypeEQ applies the EQ predicate on the "source_type" field.
func SourceTypeEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldSourceType, v))
}
// SourceTypeNEQ applies the NEQ predicate on the "source_type" field.
func SourceTypeNEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldSourceType, v))
}
// SourceTypeIn applies the In predicate on the "source_type" field.
func SourceTypeIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldSourceType, vs...))
}
// SourceTypeNotIn applies the NotIn predicate on the "source_type" field.
func SourceTypeNotIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldSourceType, vs...))
}
// SourceTypeGT applies the GT predicate on the "source_type" field.
func SourceTypeGT(v string) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldSourceType, v))
}
// SourceTypeGTE applies the GTE predicate on the "source_type" field.
func SourceTypeGTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldSourceType, v))
}
// SourceTypeLT applies the LT predicate on the "source_type" field.
func SourceTypeLT(v string) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldSourceType, v))
}
// SourceTypeLTE applies the LTE predicate on the "source_type" field.
func SourceTypeLTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldSourceType, v))
}
// SourceTypeContains applies the Contains predicate on the "source_type" field.
func SourceTypeContains(v string) predicate.Skill {
return predicate.Skill(sql.FieldContains(FieldSourceType, v))
}
// SourceTypeHasPrefix applies the HasPrefix predicate on the "source_type" field.
func SourceTypeHasPrefix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasPrefix(FieldSourceType, v))
}
// SourceTypeHasSuffix applies the HasSuffix predicate on the "source_type" field.
func SourceTypeHasSuffix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasSuffix(FieldSourceType, v))
}
// SourceTypeEqualFold applies the EqualFold predicate on the "source_type" field.
func SourceTypeEqualFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldEqualFold(FieldSourceType, v))
}
// SourceTypeContainsFold applies the ContainsFold predicate on the "source_type" field.
func SourceTypeContainsFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldContainsFold(FieldSourceType, v))
}
// SourceLabelEQ applies the EQ predicate on the "source_label" field.
func SourceLabelEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldSourceLabel, v))
}
// SourceLabelNEQ applies the NEQ predicate on the "source_label" field.
func SourceLabelNEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldSourceLabel, v))
}
// SourceLabelIn applies the In predicate on the "source_label" field.
func SourceLabelIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldSourceLabel, vs...))
}
// SourceLabelNotIn applies the NotIn predicate on the "source_label" field.
func SourceLabelNotIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldSourceLabel, vs...))
}
// SourceLabelGT applies the GT predicate on the "source_label" field.
func SourceLabelGT(v string) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldSourceLabel, v))
}
// SourceLabelGTE applies the GTE predicate on the "source_label" field.
func SourceLabelGTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldSourceLabel, v))
}
// SourceLabelLT applies the LT predicate on the "source_label" field.
func SourceLabelLT(v string) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldSourceLabel, v))
}
// SourceLabelLTE applies the LTE predicate on the "source_label" field.
func SourceLabelLTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldSourceLabel, v))
}
// SourceLabelContains applies the Contains predicate on the "source_label" field.
func SourceLabelContains(v string) predicate.Skill {
return predicate.Skill(sql.FieldContains(FieldSourceLabel, v))
}
// SourceLabelHasPrefix applies the HasPrefix predicate on the "source_label" field.
func SourceLabelHasPrefix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasPrefix(FieldSourceLabel, v))
}
// SourceLabelHasSuffix applies the HasSuffix predicate on the "source_label" field.
func SourceLabelHasSuffix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasSuffix(FieldSourceLabel, v))
}
// SourceLabelEqualFold applies the EqualFold predicate on the "source_label" field.
func SourceLabelEqualFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldEqualFold(FieldSourceLabel, v))
}
// SourceLabelContainsFold applies the ContainsFold predicate on the "source_label" field.
func SourceLabelContainsFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldContainsFold(FieldSourceLabel, v))
}
// SkillMdPathEQ applies the EQ predicate on the "skill_md_path" field.
func SkillMdPathEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldSkillMdPath, v))
}
// SkillMdPathNEQ applies the NEQ predicate on the "skill_md_path" field.
func SkillMdPathNEQ(v string) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldSkillMdPath, v))
}
// SkillMdPathIn applies the In predicate on the "skill_md_path" field.
func SkillMdPathIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldSkillMdPath, vs...))
}
// SkillMdPathNotIn applies the NotIn predicate on the "skill_md_path" field.
func SkillMdPathNotIn(vs ...string) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldSkillMdPath, vs...))
}
// SkillMdPathGT applies the GT predicate on the "skill_md_path" field.
func SkillMdPathGT(v string) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldSkillMdPath, v))
}
// SkillMdPathGTE applies the GTE predicate on the "skill_md_path" field.
func SkillMdPathGTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldSkillMdPath, v))
}
// SkillMdPathLT applies the LT predicate on the "skill_md_path" field.
func SkillMdPathLT(v string) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldSkillMdPath, v))
}
// SkillMdPathLTE applies the LTE predicate on the "skill_md_path" field.
func SkillMdPathLTE(v string) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldSkillMdPath, v))
}
// SkillMdPathContains applies the Contains predicate on the "skill_md_path" field.
func SkillMdPathContains(v string) predicate.Skill {
return predicate.Skill(sql.FieldContains(FieldSkillMdPath, v))
}
// SkillMdPathHasPrefix applies the HasPrefix predicate on the "skill_md_path" field.
func SkillMdPathHasPrefix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasPrefix(FieldSkillMdPath, v))
}
// SkillMdPathHasSuffix applies the HasSuffix predicate on the "skill_md_path" field.
func SkillMdPathHasSuffix(v string) predicate.Skill {
return predicate.Skill(sql.FieldHasSuffix(FieldSkillMdPath, v))
}
// SkillMdPathIsNil applies the IsNil predicate on the "skill_md_path" field.
func SkillMdPathIsNil() predicate.Skill {
return predicate.Skill(sql.FieldIsNull(FieldSkillMdPath))
}
// SkillMdPathNotNil applies the NotNil predicate on the "skill_md_path" field.
func SkillMdPathNotNil() predicate.Skill {
return predicate.Skill(sql.FieldNotNull(FieldSkillMdPath))
}
// SkillMdPathEqualFold applies the EqualFold predicate on the "skill_md_path" field.
func SkillMdPathEqualFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldEqualFold(FieldSkillMdPath, v))
}
// SkillMdPathContainsFold applies the ContainsFold predicate on the "skill_md_path" field.
func SkillMdPathContainsFold(v string) predicate.Skill {
return predicate.Skill(sql.FieldContainsFold(FieldSkillMdPath, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.Skill {
return predicate.Skill(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.Skill {
return predicate.Skill(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.Skill {
return predicate.Skill(sql.FieldLTE(FieldUpdatedAt, v))
}
// HasUser applies the HasEdge predicate on the "user" edge.
func HasUser() predicate.Skill {
return predicate.Skill(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
func HasUserWith(preds ...predicate.User) predicate.Skill {
return predicate.Skill(func(s *sql.Selector) {
step := newUserStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasTeams applies the HasEdge predicate on the "teams" edge.
func HasTeams() predicate.Skill {
return predicate.Skill(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2M, true, TeamsTable, TeamsPrimaryKey...),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasTeamsWith applies the HasEdge predicate on the "teams" edge with a given conditions (other predicates).
func HasTeamsWith(preds ...predicate.Team) predicate.Skill {
return predicate.Skill(func(s *sql.Selector) {
step := newTeamsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasGroups applies the HasEdge predicate on the "groups" edge.
func HasGroups() predicate.Skill {
return predicate.Skill(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2M, true, GroupsTable, GroupsPrimaryKey...),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasGroupsWith applies the HasEdge predicate on the "groups" edge with a given conditions (other predicates).
func HasGroupsWith(preds ...predicate.TeamGroup) predicate.Skill {
return predicate.Skill(func(s *sql.Selector) {
step := newGroupsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasTeamSkills applies the HasEdge predicate on the "team_skills" edge.
func HasTeamSkills() predicate.Skill {
return predicate.Skill(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, TeamSkillsTable, TeamSkillsColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasTeamSkillsWith applies the HasEdge predicate on the "team_skills" edge with a given conditions (other predicates).
func HasTeamSkillsWith(preds ...predicate.TeamSkill) predicate.Skill {
return predicate.Skill(func(s *sql.Selector) {
step := newTeamSkillsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasTeamGroupSkills applies the HasEdge predicate on the "team_group_skills" edge.
func HasTeamGroupSkills() predicate.Skill {
return predicate.Skill(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, TeamGroupSkillsTable, TeamGroupSkillsColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasTeamGroupSkillsWith applies the HasEdge predicate on the "team_group_skills" edge with a given conditions (other predicates).
func HasTeamGroupSkillsWith(preds ...predicate.TeamGroupSkill) predicate.Skill {
return predicate.Skill(func(s *sql.Selector) {
step := newTeamGroupSkillsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Skill) predicate.Skill {
return predicate.Skill(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.Skill) predicate.Skill {
return predicate.Skill(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Skill) predicate.Skill {
return predicate.Skill(sql.NotPredicates(p))
}
File diff suppressed because it is too large. Load diff
+88
View File
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/skill"
)
// SkillDelete is the builder for deleting a Skill entity.
type SkillDelete struct {
config
hooks []Hook
mutation *SkillMutation
}
// Where appends a list predicates to the SkillDelete builder.
func (_d *SkillDelete) Where(ps ...predicate.Skill) *SkillDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *SkillDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *SkillDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *SkillDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(skill.Table, sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// SkillDeleteOne is the builder for deleting a single Skill entity.
type SkillDeleteOne struct {
_d *SkillDelete
}
// Where appends a list predicates to the SkillDelete builder.
func (_d *SkillDeleteOne) Where(ps ...predicate.Skill) *SkillDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *SkillDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{skill.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *SkillDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+36 -4
View File
@@ -52,15 +52,19 @@ type TeamEdges struct {
Models []*Model `json:"models,omitempty"`
// Images holds the value of the images edge.
Images []*Image `json:"images,omitempty"`
// Skills holds the value of the skills edge.
Skills []*Skill `json:"skills,omitempty"`
// TeamMembers holds the value of the team_members edge.
TeamMembers []*TeamMember `json:"team_members,omitempty"`
// TeamModels holds the value of the team_models edge.
TeamModels []*TeamModel `json:"team_models,omitempty"`
// TeamImages holds the value of the team_images edge.
TeamImages []*TeamImage `json:"team_images,omitempty"`
// TeamSkills holds the value of the team_skills edge.
TeamSkills []*TeamSkill `json:"team_skills,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [7]bool
loadedTypes [9]bool
}
// GroupsOrErr returns the Groups value or an error if the edge
@@ -99,10 +103,19 @@ func (e TeamEdges) ImagesOrErr() ([]*Image, error) {
return nil, &NotLoadedError{edge: "images"}
}
// SkillsOrErr returns the Skills value or an error if the edge
// was not loaded in eager-loading.
func (e TeamEdges) SkillsOrErr() ([]*Skill, error) {
if e.loadedTypes[4] {
return e.Skills, nil
}
return nil, &NotLoadedError{edge: "skills"}
}
// TeamMembersOrErr returns the TeamMembers value or an error if the edge
// was not loaded in eager-loading.
func (e TeamEdges) TeamMembersOrErr() ([]*TeamMember, error) {
if e.loadedTypes[4] {
if e.loadedTypes[5] {
return e.TeamMembers, nil
}
return nil, &NotLoadedError{edge: "team_members"}
@@ -111,7 +124,7 @@ func (e TeamEdges) TeamMembersOrErr() ([]*TeamMember, error) {
// TeamModelsOrErr returns the TeamModels value or an error if the edge
// was not loaded in eager-loading.
func (e TeamEdges) TeamModelsOrErr() ([]*TeamModel, error) {
if e.loadedTypes[5] {
if e.loadedTypes[6] {
return e.TeamModels, nil
}
return nil, &NotLoadedError{edge: "team_models"}
@@ -120,12 +133,21 @@ func (e TeamEdges) TeamModelsOrErr() ([]*TeamModel, error) {
// TeamImagesOrErr returns the TeamImages value or an error if the edge
// was not loaded in eager-loading.
func (e TeamEdges) TeamImagesOrErr() ([]*TeamImage, error) {
if e.loadedTypes[6] {
if e.loadedTypes[7] {
return e.TeamImages, nil
}
return nil, &NotLoadedError{edge: "team_images"}
}
// TeamSkillsOrErr returns the TeamSkills value or an error if the edge
// was not loaded in eager-loading.
func (e TeamEdges) TeamSkillsOrErr() ([]*TeamSkill, error) {
if e.loadedTypes[8] {
return e.TeamSkills, nil
}
return nil, &NotLoadedError{edge: "team_skills"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Team) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
@@ -249,6 +271,11 @@ func (_m *Team) QueryImages() *ImageQuery {
return NewTeamClient(_m.config).QueryImages(_m)
}
// QuerySkills queries the "skills" edge of the Team entity.
func (_m *Team) QuerySkills() *SkillQuery {
return NewTeamClient(_m.config).QuerySkills(_m)
}
// QueryTeamMembers queries the "team_members" edge of the Team entity.
func (_m *Team) QueryTeamMembers() *TeamMemberQuery {
return NewTeamClient(_m.config).QueryTeamMembers(_m)
@@ -264,6 +291,11 @@ func (_m *Team) QueryTeamImages() *TeamImageQuery {
return NewTeamClient(_m.config).QueryTeamImages(_m)
}
// QueryTeamSkills queries the "team_skills" edge of the Team entity.
func (_m *Team) QueryTeamSkills() *TeamSkillQuery {
return NewTeamClient(_m.config).QueryTeamSkills(_m)
}
// Update returns a builder for updating this Team.
// Note that you need to call Team.Unwrap() before calling this method if this Team
// was returned from a transaction, and the transaction was committed or rolled back.
+61
View File
@@ -41,12 +41,16 @@ const (
EdgeModels = "models"
// EdgeImages holds the string denoting the images edge name in mutations.
EdgeImages = "images"
// EdgeSkills holds the string denoting the skills edge name in mutations.
EdgeSkills = "skills"
// EdgeTeamMembers holds the string denoting the team_members edge name in mutations.
EdgeTeamMembers = "team_members"
// EdgeTeamModels holds the string denoting the team_models edge name in mutations.
EdgeTeamModels = "team_models"
// EdgeTeamImages holds the string denoting the team_images edge name in mutations.
EdgeTeamImages = "team_images"
// EdgeTeamSkills holds the string denoting the team_skills edge name in mutations.
EdgeTeamSkills = "team_skills"
// Table holds the table name of the team in the database.
Table = "teams"
// GroupsTable is the table that holds the groups relation/edge.
@@ -71,6 +75,11 @@ const (
// ImagesInverseTable is the table name for the Image entity.
// It exists in this package in order to avoid circular dependency with the "image" package.
ImagesInverseTable = "images"
// SkillsTable is the table that holds the skills relation/edge. The primary key declared below.
SkillsTable = "team_skills"
// SkillsInverseTable is the table name for the Skill entity.
// It exists in this package in order to avoid circular dependency with the "skill" package.
SkillsInverseTable = "skills"
// TeamMembersTable is the table that holds the team_members relation/edge.
TeamMembersTable = "team_members"
// TeamMembersInverseTable is the table name for the TeamMember entity.
@@ -92,6 +101,13 @@ const (
TeamImagesInverseTable = "team_images"
// TeamImagesColumn is the table column denoting the team_images relation/edge.
TeamImagesColumn = "team_id"
// TeamSkillsTable is the table that holds the team_skills relation/edge.
TeamSkillsTable = "team_skills"
// TeamSkillsInverseTable is the table name for the TeamSkill entity.
// It exists in this package in order to avoid circular dependency with the "teamskill" package.
TeamSkillsInverseTable = "team_skills"
// TeamSkillsColumn is the table column denoting the team_skills relation/edge.
TeamSkillsColumn = "team_id"
)
// Columns holds all SQL columns for team fields.
@@ -118,6 +134,9 @@ var (
// ImagesPrimaryKey and ImagesColumn2 are the table columns denoting the
// primary key for the images relation (M2M).
ImagesPrimaryKey = []string{"team_id", "image_id"}
// SkillsPrimaryKey and SkillsColumn2 are the table columns denoting the
// primary key for the skills relation (M2M).
SkillsPrimaryKey = []string{"team_id", "skill_id"}
)
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -263,6 +282,20 @@ func ByImages(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
}
}
// BySkillsCount orders the results by skills count.
func BySkillsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newSkillsStep(), opts...)
}
}
// BySkills orders the results by skills terms.
func BySkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newSkillsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByTeamMembersCount orders the results by team_members count.
func ByTeamMembersCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
@@ -304,6 +337,20 @@ func ByTeamImages(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
sqlgraph.OrderByNeighborTerms(s, newTeamImagesStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByTeamSkillsCount orders the results by team_skills count.
func ByTeamSkillsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newTeamSkillsStep(), opts...)
}
}
// ByTeamSkills orders the results by team_skills terms.
func ByTeamSkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newTeamSkillsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newGroupsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
@@ -332,6 +379,13 @@ func newImagesStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.M2M, false, ImagesTable, ImagesPrimaryKey...),
)
}
func newSkillsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(SkillsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, SkillsTable, SkillsPrimaryKey...),
)
}
func newTeamMembersStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
@@ -353,3 +407,10 @@ func newTeamImagesStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.O2M, true, TeamImagesTable, TeamImagesColumn),
)
}
func newTeamSkillsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(TeamSkillsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, TeamSkillsTable, TeamSkillsColumn),
)
}
+46
View File
@@ -528,6 +528,29 @@ func HasImagesWith(preds ...predicate.Image) predicate.Team {
})
}
// HasSkills applies the HasEdge predicate on the "skills" edge.
func HasSkills() predicate.Team {
return predicate.Team(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, SkillsTable, SkillsPrimaryKey...),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasSkillsWith applies the HasEdge predicate on the "skills" edge with a given conditions (other predicates).
func HasSkillsWith(preds ...predicate.Skill) predicate.Team {
return predicate.Team(func(s *sql.Selector) {
step := newSkillsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasTeamMembers applies the HasEdge predicate on the "team_members" edge.
func HasTeamMembers() predicate.Team {
return predicate.Team(func(s *sql.Selector) {
@@ -597,6 +620,29 @@ func HasTeamImagesWith(preds ...predicate.TeamImage) predicate.Team {
})
}
// HasTeamSkills applies the HasEdge predicate on the "team_skills" edge.
func HasTeamSkills() predicate.Team {
return predicate.Team(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, TeamSkillsTable, TeamSkillsColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasTeamSkillsWith applies the HasEdge predicate on the "team_skills" edge with a given conditions (other predicates).
func HasTeamSkillsWith(preds ...predicate.TeamSkill) predicate.Team {
return predicate.Team(func(s *sql.Selector) {
step := newTeamSkillsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Team) predicate.Team {
return predicate.Team(sql.AndPredicates(predicates...))
+68
View File
@@ -14,11 +14,13 @@ import (
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/image"
"github.com/chaitin/MonkeyCode/backend/db/model"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamimage"
"github.com/chaitin/MonkeyCode/backend/db/teammember"
"github.com/chaitin/MonkeyCode/backend/db/teammodel"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/google/uuid"
)
@@ -207,6 +209,21 @@ func (_c *TeamCreate) AddImages(v ...*Image) *TeamCreate {
return _c.AddImageIDs(ids...)
}
// AddSkillIDs adds the "skills" edge to the Skill entity by IDs.
func (_c *TeamCreate) AddSkillIDs(ids ...uuid.UUID) *TeamCreate {
_c.mutation.AddSkillIDs(ids...)
return _c
}
// AddSkills adds the "skills" edges to the Skill entity.
func (_c *TeamCreate) AddSkills(v ...*Skill) *TeamCreate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddSkillIDs(ids...)
}
// AddTeamMemberIDs adds the "team_members" edge to the TeamMember entity by IDs.
func (_c *TeamCreate) AddTeamMemberIDs(ids ...uuid.UUID) *TeamCreate {
_c.mutation.AddTeamMemberIDs(ids...)
@@ -252,6 +269,21 @@ func (_c *TeamCreate) AddTeamImages(v ...*TeamImage) *TeamCreate {
return _c.AddTeamImageIDs(ids...)
}
// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by IDs.
func (_c *TeamCreate) AddTeamSkillIDs(ids ...uuid.UUID) *TeamCreate {
_c.mutation.AddTeamSkillIDs(ids...)
return _c
}
// AddTeamSkills adds the "team_skills" edges to the TeamSkill entity.
func (_c *TeamCreate) AddTeamSkills(v ...*TeamSkill) *TeamCreate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddTeamSkillIDs(ids...)
}
// Mutation returns the TeamMutation object of the builder.
func (_c *TeamCreate) Mutation() *TeamMutation {
return _c.mutation
@@ -501,6 +533,26 @@ func (_c *TeamCreate) createSpec() (*Team, *sqlgraph.CreateSpec) {
edge.Target.Fields = specE.Fields
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.SkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: team.SkillsTable,
Columns: team.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &TeamSkillCreate{config: _c.config, mutation: newTeamSkillMutation(_c.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.TeamMembersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -549,6 +601,22 @@ func (_c *TeamCreate) createSpec() (*Team, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.TeamSkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: team.TeamSkillsTable,
Columns: []string{team.TeamSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
+180 -1
View File
@@ -16,11 +16,13 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/image"
"github.com/chaitin/MonkeyCode/backend/db/model"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamimage"
"github.com/chaitin/MonkeyCode/backend/db/teammember"
"github.com/chaitin/MonkeyCode/backend/db/teammodel"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/google/uuid"
)
@@ -36,9 +38,11 @@ type TeamQuery struct {
withMembers *UserQuery
withModels *ModelQuery
withImages *ImageQuery
withSkills *SkillQuery
withTeamMembers *TeamMemberQuery
withTeamModels *TeamModelQuery
withTeamImages *TeamImageQuery
withTeamSkills *TeamSkillQuery
modifiers []func(*sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
@@ -164,6 +168,28 @@ func (_q *TeamQuery) QueryImages() *ImageQuery {
return query
}
// QuerySkills chains the current query on the "skills" edge.
func (_q *TeamQuery) QuerySkills() *SkillQuery {
query := (&SkillClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(team.Table, team.FieldID, selector),
sqlgraph.To(skill.Table, skill.FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, team.SkillsTable, team.SkillsPrimaryKey...),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryTeamMembers chains the current query on the "team_members" edge.
func (_q *TeamQuery) QueryTeamMembers() *TeamMemberQuery {
query := (&TeamMemberClient{config: _q.config}).Query()
@@ -230,6 +256,28 @@ func (_q *TeamQuery) QueryTeamImages() *TeamImageQuery {
return query
}
// QueryTeamSkills chains the current query on the "team_skills" edge.
func (_q *TeamQuery) QueryTeamSkills() *TeamSkillQuery {
query := (&TeamSkillClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(team.Table, team.FieldID, selector),
sqlgraph.To(teamskill.Table, teamskill.FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, team.TeamSkillsTable, team.TeamSkillsColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first Team entity from the query.
// Returns a *NotFoundError when no Team was found.
func (_q *TeamQuery) First(ctx context.Context) (*Team, error) {
@@ -426,9 +474,11 @@ func (_q *TeamQuery) Clone() *TeamQuery {
withMembers: _q.withMembers.Clone(),
withModels: _q.withModels.Clone(),
withImages: _q.withImages.Clone(),
withSkills: _q.withSkills.Clone(),
withTeamMembers: _q.withTeamMembers.Clone(),
withTeamModels: _q.withTeamModels.Clone(),
withTeamImages: _q.withTeamImages.Clone(),
withTeamSkills: _q.withTeamSkills.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
@@ -480,6 +530,17 @@ func (_q *TeamQuery) WithImages(opts ...func(*ImageQuery)) *TeamQuery {
return _q
}
// WithSkills tells the query-builder to eager-load the nodes that are connected to
// the "skills" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *TeamQuery) WithSkills(opts ...func(*SkillQuery)) *TeamQuery {
query := (&SkillClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withSkills = query
return _q
}
// WithTeamMembers tells the query-builder to eager-load the nodes that are connected to
// the "team_members" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *TeamQuery) WithTeamMembers(opts ...func(*TeamMemberQuery)) *TeamQuery {
@@ -513,6 +574,17 @@ func (_q *TeamQuery) WithTeamImages(opts ...func(*TeamImageQuery)) *TeamQuery {
return _q
}
// WithTeamSkills tells the query-builder to eager-load the nodes that are connected to
// the "team_skills" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *TeamQuery) WithTeamSkills(opts ...func(*TeamSkillQuery)) *TeamQuery {
query := (&TeamSkillClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withTeamSkills = query
return _q
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
@@ -591,14 +663,16 @@ func (_q *TeamQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Team, e
var (
nodes = []*Team{}
_spec = _q.querySpec()
loadedTypes = [7]bool{
loadedTypes = [9]bool{
_q.withGroups != nil,
_q.withMembers != nil,
_q.withModels != nil,
_q.withImages != nil,
_q.withSkills != nil,
_q.withTeamMembers != nil,
_q.withTeamModels != nil,
_q.withTeamImages != nil,
_q.withTeamSkills != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
@@ -650,6 +724,13 @@ func (_q *TeamQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Team, e
return nil, err
}
}
if query := _q.withSkills; query != nil {
if err := _q.loadSkills(ctx, query, nodes,
func(n *Team) { n.Edges.Skills = []*Skill{} },
func(n *Team, e *Skill) { n.Edges.Skills = append(n.Edges.Skills, e) }); err != nil {
return nil, err
}
}
if query := _q.withTeamMembers; query != nil {
if err := _q.loadTeamMembers(ctx, query, nodes,
func(n *Team) { n.Edges.TeamMembers = []*TeamMember{} },
@@ -671,6 +752,13 @@ func (_q *TeamQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Team, e
return nil, err
}
}
if query := _q.withTeamSkills; query != nil {
if err := _q.loadTeamSkills(ctx, query, nodes,
func(n *Team) { n.Edges.TeamSkills = []*TeamSkill{} },
func(n *Team, e *TeamSkill) { n.Edges.TeamSkills = append(n.Edges.TeamSkills, e) }); err != nil {
return nil, err
}
}
return nodes, nil
}
@@ -887,6 +975,67 @@ func (_q *TeamQuery) loadImages(ctx context.Context, query *ImageQuery, nodes []
}
return nil
}
func (_q *TeamQuery) loadSkills(ctx context.Context, query *SkillQuery, nodes []*Team, init func(*Team), assign func(*Team, *Skill)) error {
edgeIDs := make([]driver.Value, len(nodes))
byID := make(map[uuid.UUID]*Team)
nids := make(map[uuid.UUID]map[*Team]struct{})
for i, node := range nodes {
edgeIDs[i] = node.ID
byID[node.ID] = node
if init != nil {
init(node)
}
}
query.Where(func(s *sql.Selector) {
joinT := sql.Table(team.SkillsTable)
s.Join(joinT).On(s.C(skill.FieldID), joinT.C(team.SkillsPrimaryKey[1]))
s.Where(sql.InValues(joinT.C(team.SkillsPrimaryKey[0]), edgeIDs...))
columns := s.SelectedColumns()
s.Select(joinT.C(team.SkillsPrimaryKey[0]))
s.AppendSelect(columns...)
s.SetDistinct(false)
})
if err := query.prepareQuery(ctx); err != nil {
return err
}
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
assign := spec.Assign
values := spec.ScanValues
spec.ScanValues = func(columns []string) ([]any, error) {
values, err := values(columns[1:])
if err != nil {
return nil, err
}
return append([]any{new(uuid.UUID)}, values...), nil
}
spec.Assign = func(columns []string, values []any) error {
outValue := *values[0].(*uuid.UUID)
inValue := *values[1].(*uuid.UUID)
if nids[inValue] == nil {
nids[inValue] = map[*Team]struct{}{byID[outValue]: {}}
return assign(columns[1:], values[1:])
}
nids[inValue][byID[outValue]] = struct{}{}
return nil
}
})
})
neighbors, err := withInterceptors[[]*Skill](ctx, query, qr, query.inters)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nids[n.ID]
if !ok {
return fmt.Errorf(`unexpected "skills" node returned %v`, n.ID)
}
for kn := range nodes {
assign(kn, n)
}
}
return nil
}
func (_q *TeamQuery) loadTeamMembers(ctx context.Context, query *TeamMemberQuery, nodes []*Team, init func(*Team), assign func(*Team, *TeamMember)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[uuid.UUID]*Team)
@@ -977,6 +1126,36 @@ func (_q *TeamQuery) loadTeamImages(ctx context.Context, query *TeamImageQuery,
}
return nil
}
func (_q *TeamQuery) loadTeamSkills(ctx context.Context, query *TeamSkillQuery, nodes []*Team, init func(*Team), assign func(*Team, *TeamSkill)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[uuid.UUID]*Team)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
if init != nil {
init(nodes[i])
}
}
if len(query.ctx.Fields) > 0 {
query.ctx.AppendFieldOnce(teamskill.FieldTeamID)
}
query.Where(predicate.TeamSkill(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(team.TeamSkillsColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.TeamID
node, ok := nodeids[fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "team_id" returned %v for node %v`, fk, n.ID)
}
assign(node, n)
}
return nil
}
func (_q *TeamQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
+350
View File
@@ -14,11 +14,13 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/image"
"github.com/chaitin/MonkeyCode/backend/db/model"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamimage"
"github.com/chaitin/MonkeyCode/backend/db/teammember"
"github.com/chaitin/MonkeyCode/backend/db/teammodel"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/google/uuid"
)
@@ -250,6 +252,21 @@ func (_u *TeamUpdate) AddImages(v ...*Image) *TeamUpdate {
return _u.AddImageIDs(ids...)
}
// AddSkillIDs adds the "skills" edge to the Skill entity by IDs.
func (_u *TeamUpdate) AddSkillIDs(ids ...uuid.UUID) *TeamUpdate {
_u.mutation.AddSkillIDs(ids...)
return _u
}
// AddSkills adds the "skills" edges to the Skill entity.
func (_u *TeamUpdate) AddSkills(v ...*Skill) *TeamUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddSkillIDs(ids...)
}
// AddTeamMemberIDs adds the "team_members" edge to the TeamMember entity by IDs.
func (_u *TeamUpdate) AddTeamMemberIDs(ids ...uuid.UUID) *TeamUpdate {
_u.mutation.AddTeamMemberIDs(ids...)
@@ -295,6 +312,21 @@ func (_u *TeamUpdate) AddTeamImages(v ...*TeamImage) *TeamUpdate {
return _u.AddTeamImageIDs(ids...)
}
// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by IDs.
func (_u *TeamUpdate) AddTeamSkillIDs(ids ...uuid.UUID) *TeamUpdate {
_u.mutation.AddTeamSkillIDs(ids...)
return _u
}
// AddTeamSkills adds the "team_skills" edges to the TeamSkill entity.
func (_u *TeamUpdate) AddTeamSkills(v ...*TeamSkill) *TeamUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddTeamSkillIDs(ids...)
}
// Mutation returns the TeamMutation object of the builder.
func (_u *TeamUpdate) Mutation() *TeamMutation {
return _u.mutation
@@ -384,6 +416,27 @@ func (_u *TeamUpdate) RemoveImages(v ...*Image) *TeamUpdate {
return _u.RemoveImageIDs(ids...)
}
// ClearSkills clears all "skills" edges to the Skill entity.
func (_u *TeamUpdate) ClearSkills() *TeamUpdate {
_u.mutation.ClearSkills()
return _u
}
// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs.
func (_u *TeamUpdate) RemoveSkillIDs(ids ...uuid.UUID) *TeamUpdate {
_u.mutation.RemoveSkillIDs(ids...)
return _u
}
// RemoveSkills removes "skills" edges to Skill entities.
func (_u *TeamUpdate) RemoveSkills(v ...*Skill) *TeamUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveSkillIDs(ids...)
}
// ClearTeamMembers clears all "team_members" edges to the TeamMember entity.
func (_u *TeamUpdate) ClearTeamMembers() *TeamUpdate {
_u.mutation.ClearTeamMembers()
@@ -447,6 +500,27 @@ func (_u *TeamUpdate) RemoveTeamImages(v ...*TeamImage) *TeamUpdate {
return _u.RemoveTeamImageIDs(ids...)
}
// ClearTeamSkills clears all "team_skills" edges to the TeamSkill entity.
func (_u *TeamUpdate) ClearTeamSkills() *TeamUpdate {
_u.mutation.ClearTeamSkills()
return _u
}
// RemoveTeamSkillIDs removes the "team_skills" edge to TeamSkill entities by IDs.
func (_u *TeamUpdate) RemoveTeamSkillIDs(ids ...uuid.UUID) *TeamUpdate {
_u.mutation.RemoveTeamSkillIDs(ids...)
return _u
}
// RemoveTeamSkills removes "team_skills" edges to TeamSkill entities.
func (_u *TeamUpdate) RemoveTeamSkills(v ...*TeamSkill) *TeamUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveTeamSkillIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *TeamUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
@@ -757,6 +831,63 @@ func (_u *TeamUpdate) sqlSave(ctx context.Context) (_node int, err error) {
edge.Target.Fields = specE.Fields
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: team.SkillsTable,
Columns: team.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: team.SkillsTable,
Columns: team.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: team.SkillsTable,
Columns: team.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.TeamMembersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -892,6 +1023,51 @@ func (_u *TeamUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.TeamSkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: team.TeamSkillsTable,
Columns: []string{team.TeamSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedTeamSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamSkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: team.TeamSkillsTable,
Columns: []string{team.TeamSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.TeamSkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: team.TeamSkillsTable,
Columns: []string{team.TeamSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
@@ -1127,6 +1303,21 @@ func (_u *TeamUpdateOne) AddImages(v ...*Image) *TeamUpdateOne {
return _u.AddImageIDs(ids...)
}
// AddSkillIDs adds the "skills" edge to the Skill entity by IDs.
func (_u *TeamUpdateOne) AddSkillIDs(ids ...uuid.UUID) *TeamUpdateOne {
_u.mutation.AddSkillIDs(ids...)
return _u
}
// AddSkills adds the "skills" edges to the Skill entity.
func (_u *TeamUpdateOne) AddSkills(v ...*Skill) *TeamUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddSkillIDs(ids...)
}
// AddTeamMemberIDs adds the "team_members" edge to the TeamMember entity by IDs.
func (_u *TeamUpdateOne) AddTeamMemberIDs(ids ...uuid.UUID) *TeamUpdateOne {
_u.mutation.AddTeamMemberIDs(ids...)
@@ -1172,6 +1363,21 @@ func (_u *TeamUpdateOne) AddTeamImages(v ...*TeamImage) *TeamUpdateOne {
return _u.AddTeamImageIDs(ids...)
}
// AddTeamSkillIDs adds the "team_skills" edge to the TeamSkill entity by IDs.
func (_u *TeamUpdateOne) AddTeamSkillIDs(ids ...uuid.UUID) *TeamUpdateOne {
_u.mutation.AddTeamSkillIDs(ids...)
return _u
}
// AddTeamSkills adds the "team_skills" edges to the TeamSkill entity.
func (_u *TeamUpdateOne) AddTeamSkills(v ...*TeamSkill) *TeamUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddTeamSkillIDs(ids...)
}
// Mutation returns the TeamMutation object of the builder.
func (_u *TeamUpdateOne) Mutation() *TeamMutation {
return _u.mutation
@@ -1261,6 +1467,27 @@ func (_u *TeamUpdateOne) RemoveImages(v ...*Image) *TeamUpdateOne {
return _u.RemoveImageIDs(ids...)
}
// ClearSkills clears all "skills" edges to the Skill entity.
func (_u *TeamUpdateOne) ClearSkills() *TeamUpdateOne {
_u.mutation.ClearSkills()
return _u
}
// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs.
func (_u *TeamUpdateOne) RemoveSkillIDs(ids ...uuid.UUID) *TeamUpdateOne {
_u.mutation.RemoveSkillIDs(ids...)
return _u
}
// RemoveSkills removes "skills" edges to Skill entities.
func (_u *TeamUpdateOne) RemoveSkills(v ...*Skill) *TeamUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveSkillIDs(ids...)
}
// ClearTeamMembers clears all "team_members" edges to the TeamMember entity.
func (_u *TeamUpdateOne) ClearTeamMembers() *TeamUpdateOne {
_u.mutation.ClearTeamMembers()
@@ -1324,6 +1551,27 @@ func (_u *TeamUpdateOne) RemoveTeamImages(v ...*TeamImage) *TeamUpdateOne {
return _u.RemoveTeamImageIDs(ids...)
}
// ClearTeamSkills clears all "team_skills" edges to the TeamSkill entity.
func (_u *TeamUpdateOne) ClearTeamSkills() *TeamUpdateOne {
_u.mutation.ClearTeamSkills()
return _u
}
// RemoveTeamSkillIDs removes the "team_skills" edge to TeamSkill entities by IDs.
func (_u *TeamUpdateOne) RemoveTeamSkillIDs(ids ...uuid.UUID) *TeamUpdateOne {
_u.mutation.RemoveTeamSkillIDs(ids...)
return _u
}
// RemoveTeamSkills removes "team_skills" edges to TeamSkill entities.
func (_u *TeamUpdateOne) RemoveTeamSkills(v ...*TeamSkill) *TeamUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveTeamSkillIDs(ids...)
}
// Where appends a list predicates to the TeamUpdate builder.
func (_u *TeamUpdateOne) Where(ps ...predicate.Team) *TeamUpdateOne {
_u.mutation.Where(ps...)
@@ -1664,6 +1912,63 @@ func (_u *TeamUpdateOne) sqlSave(ctx context.Context) (_node *Team, err error) {
edge.Target.Fields = specE.Fields
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: team.SkillsTable,
Columns: team.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: team.SkillsTable,
Columns: team.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: team.SkillsTable,
Columns: team.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &TeamSkillCreate{config: _u.config, mutation: newTeamSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.TeamMembersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -1799,6 +2104,51 @@ func (_u *TeamUpdateOne) sqlSave(ctx context.Context) (_node *Team, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.TeamSkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: team.TeamSkillsTable,
Columns: []string{team.TeamSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedTeamSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamSkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: team.TeamSkillsTable,
Columns: []string{team.TeamSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.TeamSkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: team.TeamSkillsTable,
Columns: []string{team.TeamSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
_node = &Team{config: _u.config}
_spec.Assign = _node.assignValues
+37 -5
View File
@@ -47,6 +47,8 @@ type TeamGroupEdges struct {
Images []*Image `json:"images,omitempty"`
// Hosts holds the value of the hosts edge.
Hosts []*Host `json:"hosts,omitempty"`
// Skills holds the value of the skills edge.
Skills []*Skill `json:"skills,omitempty"`
// TeamGroupMembers holds the value of the team_group_members edge.
TeamGroupMembers []*TeamGroupMember `json:"team_group_members,omitempty"`
// TeamGroupModels holds the value of the team_group_models edge.
@@ -55,9 +57,11 @@ type TeamGroupEdges struct {
TeamGroupImages []*TeamGroupImage `json:"team_group_images,omitempty"`
// TeamGroupHosts holds the value of the team_group_hosts edge.
TeamGroupHosts []*TeamGroupHost `json:"team_group_hosts,omitempty"`
// TeamGroupSkills holds the value of the team_group_skills edge.
TeamGroupSkills []*TeamGroupSkill `json:"team_group_skills,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [9]bool
loadedTypes [11]bool
}
// MembersOrErr returns the Members value or an error if the edge
@@ -107,10 +111,19 @@ func (e TeamGroupEdges) HostsOrErr() ([]*Host, error) {
return nil, &NotLoadedError{edge: "hosts"}
}
// SkillsOrErr returns the Skills value or an error if the edge
// was not loaded in eager-loading.
func (e TeamGroupEdges) SkillsOrErr() ([]*Skill, error) {
if e.loadedTypes[5] {
return e.Skills, nil
}
return nil, &NotLoadedError{edge: "skills"}
}
// TeamGroupMembersOrErr returns the TeamGroupMembers value or an error if the edge
// was not loaded in eager-loading.
func (e TeamGroupEdges) TeamGroupMembersOrErr() ([]*TeamGroupMember, error) {
if e.loadedTypes[5] {
if e.loadedTypes[6] {
return e.TeamGroupMembers, nil
}
return nil, &NotLoadedError{edge: "team_group_members"}
@@ -119,7 +132,7 @@ func (e TeamGroupEdges) TeamGroupMembersOrErr() ([]*TeamGroupMember, error) {
// TeamGroupModelsOrErr returns the TeamGroupModels value or an error if the edge
// was not loaded in eager-loading.
func (e TeamGroupEdges) TeamGroupModelsOrErr() ([]*TeamGroupModel, error) {
if e.loadedTypes[6] {
if e.loadedTypes[7] {
return e.TeamGroupModels, nil
}
return nil, &NotLoadedError{edge: "team_group_models"}
@@ -128,7 +141,7 @@ func (e TeamGroupEdges) TeamGroupModelsOrErr() ([]*TeamGroupModel, error) {
// TeamGroupImagesOrErr returns the TeamGroupImages value or an error if the edge
// was not loaded in eager-loading.
func (e TeamGroupEdges) TeamGroupImagesOrErr() ([]*TeamGroupImage, error) {
if e.loadedTypes[7] {
if e.loadedTypes[8] {
return e.TeamGroupImages, nil
}
return nil, &NotLoadedError{edge: "team_group_images"}
@@ -137,12 +150,21 @@ func (e TeamGroupEdges) TeamGroupImagesOrErr() ([]*TeamGroupImage, error) {
// TeamGroupHostsOrErr returns the TeamGroupHosts value or an error if the edge
// was not loaded in eager-loading.
func (e TeamGroupEdges) TeamGroupHostsOrErr() ([]*TeamGroupHost, error) {
if e.loadedTypes[8] {
if e.loadedTypes[9] {
return e.TeamGroupHosts, nil
}
return nil, &NotLoadedError{edge: "team_group_hosts"}
}
// TeamGroupSkillsOrErr returns the TeamGroupSkills value or an error if the edge
// was not loaded in eager-loading.
func (e TeamGroupEdges) TeamGroupSkillsOrErr() ([]*TeamGroupSkill, error) {
if e.loadedTypes[10] {
return e.TeamGroupSkills, nil
}
return nil, &NotLoadedError{edge: "team_group_skills"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*TeamGroup) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
@@ -243,6 +265,11 @@ func (_m *TeamGroup) QueryHosts() *HostQuery {
return NewTeamGroupClient(_m.config).QueryHosts(_m)
}
// QuerySkills queries the "skills" edge of the TeamGroup entity.
func (_m *TeamGroup) QuerySkills() *SkillQuery {
return NewTeamGroupClient(_m.config).QuerySkills(_m)
}
// QueryTeamGroupMembers queries the "team_group_members" edge of the TeamGroup entity.
func (_m *TeamGroup) QueryTeamGroupMembers() *TeamGroupMemberQuery {
return NewTeamGroupClient(_m.config).QueryTeamGroupMembers(_m)
@@ -263,6 +290,11 @@ func (_m *TeamGroup) QueryTeamGroupHosts() *TeamGroupHostQuery {
return NewTeamGroupClient(_m.config).QueryTeamGroupHosts(_m)
}
// QueryTeamGroupSkills queries the "team_group_skills" edge of the TeamGroup entity.
func (_m *TeamGroup) QueryTeamGroupSkills() *TeamGroupSkillQuery {
return NewTeamGroupClient(_m.config).QueryTeamGroupSkills(_m)
}
// Update returns a builder for updating this TeamGroup.
// Note that you need to call TeamGroup.Unwrap() before calling this method if this TeamGroup
// was returned from a transaction, and the transaction was committed or rolled back.
+61
View File
@@ -35,6 +35,8 @@ const (
EdgeImages = "images"
// EdgeHosts holds the string denoting the hosts edge name in mutations.
EdgeHosts = "hosts"
// EdgeSkills holds the string denoting the skills edge name in mutations.
EdgeSkills = "skills"
// EdgeTeamGroupMembers holds the string denoting the team_group_members edge name in mutations.
EdgeTeamGroupMembers = "team_group_members"
// EdgeTeamGroupModels holds the string denoting the team_group_models edge name in mutations.
@@ -43,6 +45,8 @@ const (
EdgeTeamGroupImages = "team_group_images"
// EdgeTeamGroupHosts holds the string denoting the team_group_hosts edge name in mutations.
EdgeTeamGroupHosts = "team_group_hosts"
// EdgeTeamGroupSkills holds the string denoting the team_group_skills edge name in mutations.
EdgeTeamGroupSkills = "team_group_skills"
// Table holds the table name of the teamgroup in the database.
Table = "team_groups"
// MembersTable is the table that holds the members relation/edge. The primary key declared below.
@@ -72,6 +76,11 @@ const (
// HostsInverseTable is the table name for the Host entity.
// It exists in this package in order to avoid circular dependency with the "host" package.
HostsInverseTable = "hosts"
// SkillsTable is the table that holds the skills relation/edge. The primary key declared below.
SkillsTable = "team_group_skills"
// SkillsInverseTable is the table name for the Skill entity.
// It exists in this package in order to avoid circular dependency with the "skill" package.
SkillsInverseTable = "skills"
// TeamGroupMembersTable is the table that holds the team_group_members relation/edge.
TeamGroupMembersTable = "team_group_members"
// TeamGroupMembersInverseTable is the table name for the TeamGroupMember entity.
@@ -100,6 +109,13 @@ const (
TeamGroupHostsInverseTable = "team_group_hosts"
// TeamGroupHostsColumn is the table column denoting the team_group_hosts relation/edge.
TeamGroupHostsColumn = "group_id"
// TeamGroupSkillsTable is the table that holds the team_group_skills relation/edge.
TeamGroupSkillsTable = "team_group_skills"
// TeamGroupSkillsInverseTable is the table name for the TeamGroupSkill entity.
// It exists in this package in order to avoid circular dependency with the "teamgroupskill" package.
TeamGroupSkillsInverseTable = "team_group_skills"
// TeamGroupSkillsColumn is the table column denoting the team_group_skills relation/edge.
TeamGroupSkillsColumn = "group_id"
)
// Columns holds all SQL columns for teamgroup fields.
@@ -125,6 +141,9 @@ var (
// HostsPrimaryKey and HostsColumn2 are the table columns denoting the
// primary key for the hosts relation (M2M).
HostsPrimaryKey = []string{"group_id", "host_id"}
// SkillsPrimaryKey and SkillsColumn2 are the table columns denoting the
// primary key for the skills relation (M2M).
SkillsPrimaryKey = []string{"group_id", "skill_id"}
)
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -249,6 +268,20 @@ func ByHosts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
}
}
// BySkillsCount orders the results by skills count.
func BySkillsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newSkillsStep(), opts...)
}
}
// BySkills orders the results by skills terms.
func BySkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newSkillsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByTeamGroupMembersCount orders the results by team_group_members count.
func ByTeamGroupMembersCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
@@ -304,6 +337,20 @@ func ByTeamGroupHosts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
sqlgraph.OrderByNeighborTerms(s, newTeamGroupHostsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByTeamGroupSkillsCount orders the results by team_group_skills count.
func ByTeamGroupSkillsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newTeamGroupSkillsStep(), opts...)
}
}
// ByTeamGroupSkills orders the results by team_group_skills terms.
func ByTeamGroupSkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newTeamGroupSkillsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newMembersStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
@@ -339,6 +386,13 @@ func newHostsStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.M2M, false, HostsTable, HostsPrimaryKey...),
)
}
func newSkillsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(SkillsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, SkillsTable, SkillsPrimaryKey...),
)
}
func newTeamGroupMembersStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
@@ -367,3 +421,10 @@ func newTeamGroupHostsStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.O2M, true, TeamGroupHostsTable, TeamGroupHostsColumn),
)
}
func newTeamGroupSkillsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(TeamGroupSkillsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, TeamGroupSkillsTable, TeamGroupSkillsColumn),
)
}
+46
View File
@@ -411,6 +411,29 @@ func HasHostsWith(preds ...predicate.Host) predicate.TeamGroup {
})
}
// HasSkills applies the HasEdge predicate on the "skills" edge.
func HasSkills() predicate.TeamGroup {
return predicate.TeamGroup(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, SkillsTable, SkillsPrimaryKey...),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasSkillsWith applies the HasEdge predicate on the "skills" edge with a given conditions (other predicates).
func HasSkillsWith(preds ...predicate.Skill) predicate.TeamGroup {
return predicate.TeamGroup(func(s *sql.Selector) {
step := newSkillsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasTeamGroupMembers applies the HasEdge predicate on the "team_group_members" edge.
func HasTeamGroupMembers() predicate.TeamGroup {
return predicate.TeamGroup(func(s *sql.Selector) {
@@ -503,6 +526,29 @@ func HasTeamGroupHostsWith(preds ...predicate.TeamGroupHost) predicate.TeamGroup
})
}
// HasTeamGroupSkills applies the HasEdge predicate on the "team_group_skills" edge.
func HasTeamGroupSkills() predicate.TeamGroup {
return predicate.TeamGroup(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, TeamGroupSkillsTable, TeamGroupSkillsColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasTeamGroupSkillsWith applies the HasEdge predicate on the "team_group_skills" edge with a given conditions (other predicates).
func HasTeamGroupSkillsWith(preds ...predicate.TeamGroupSkill) predicate.TeamGroup {
return predicate.TeamGroup(func(s *sql.Selector) {
step := newTeamGroupSkillsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.TeamGroup) predicate.TeamGroup {
return predicate.TeamGroup(sql.AndPredicates(predicates...))
+68
View File
@@ -15,12 +15,14 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/host"
"github.com/chaitin/MonkeyCode/backend/db/image"
"github.com/chaitin/MonkeyCode/backend/db/model"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamgrouphost"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupimage"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmember"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/google/uuid"
)
@@ -158,6 +160,21 @@ func (_c *TeamGroupCreate) AddHosts(v ...*Host) *TeamGroupCreate {
return _c.AddHostIDs(ids...)
}
// AddSkillIDs adds the "skills" edge to the Skill entity by IDs.
func (_c *TeamGroupCreate) AddSkillIDs(ids ...uuid.UUID) *TeamGroupCreate {
_c.mutation.AddSkillIDs(ids...)
return _c
}
// AddSkills adds the "skills" edges to the Skill entity.
func (_c *TeamGroupCreate) AddSkills(v ...*Skill) *TeamGroupCreate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddSkillIDs(ids...)
}
// AddTeamGroupMemberIDs adds the "team_group_members" edge to the TeamGroupMember entity by IDs.
func (_c *TeamGroupCreate) AddTeamGroupMemberIDs(ids ...uuid.UUID) *TeamGroupCreate {
_c.mutation.AddTeamGroupMemberIDs(ids...)
@@ -218,6 +235,21 @@ func (_c *TeamGroupCreate) AddTeamGroupHosts(v ...*TeamGroupHost) *TeamGroupCrea
return _c.AddTeamGroupHostIDs(ids...)
}
// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by IDs.
func (_c *TeamGroupCreate) AddTeamGroupSkillIDs(ids ...uuid.UUID) *TeamGroupCreate {
_c.mutation.AddTeamGroupSkillIDs(ids...)
return _c
}
// AddTeamGroupSkills adds the "team_group_skills" edges to the TeamGroupSkill entity.
func (_c *TeamGroupCreate) AddTeamGroupSkills(v ...*TeamGroupSkill) *TeamGroupCreate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddTeamGroupSkillIDs(ids...)
}
// Mutation returns the TeamGroupMutation object of the builder.
func (_c *TeamGroupCreate) Mutation() *TeamGroupMutation {
return _c.mutation
@@ -438,6 +470,26 @@ func (_c *TeamGroupCreate) createSpec() (*TeamGroup, *sqlgraph.CreateSpec) {
edge.Target.Fields = specE.Fields
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.SkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: teamgroup.SkillsTable,
Columns: teamgroup.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &TeamGroupSkillCreate{config: _c.config, mutation: newTeamGroupSkillMutation(_c.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.TeamGroupMembersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -502,6 +554,22 @@ func (_c *TeamGroupCreate) createSpec() (*TeamGroup, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.TeamGroupSkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: teamgroup.TeamGroupSkillsTable,
Columns: []string{teamgroup.TeamGroupSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
+180 -1
View File
@@ -17,12 +17,14 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/image"
"github.com/chaitin/MonkeyCode/backend/db/model"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamgrouphost"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupimage"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmember"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/google/uuid"
)
@@ -39,10 +41,12 @@ type TeamGroupQuery struct {
withModels *ModelQuery
withImages *ImageQuery
withHosts *HostQuery
withSkills *SkillQuery
withTeamGroupMembers *TeamGroupMemberQuery
withTeamGroupModels *TeamGroupModelQuery
withTeamGroupImages *TeamGroupImageQuery
withTeamGroupHosts *TeamGroupHostQuery
withTeamGroupSkills *TeamGroupSkillQuery
modifiers []func(*sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
@@ -190,6 +194,28 @@ func (_q *TeamGroupQuery) QueryHosts() *HostQuery {
return query
}
// QuerySkills chains the current query on the "skills" edge.
func (_q *TeamGroupQuery) QuerySkills() *SkillQuery {
query := (&SkillClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(teamgroup.Table, teamgroup.FieldID, selector),
sqlgraph.To(skill.Table, skill.FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, teamgroup.SkillsTable, teamgroup.SkillsPrimaryKey...),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryTeamGroupMembers chains the current query on the "team_group_members" edge.
func (_q *TeamGroupQuery) QueryTeamGroupMembers() *TeamGroupMemberQuery {
query := (&TeamGroupMemberClient{config: _q.config}).Query()
@@ -278,6 +304,28 @@ func (_q *TeamGroupQuery) QueryTeamGroupHosts() *TeamGroupHostQuery {
return query
}
// QueryTeamGroupSkills chains the current query on the "team_group_skills" edge.
func (_q *TeamGroupQuery) QueryTeamGroupSkills() *TeamGroupSkillQuery {
query := (&TeamGroupSkillClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(teamgroup.Table, teamgroup.FieldID, selector),
sqlgraph.To(teamgroupskill.Table, teamgroupskill.FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, teamgroup.TeamGroupSkillsTable, teamgroup.TeamGroupSkillsColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first TeamGroup entity from the query.
// Returns a *NotFoundError when no TeamGroup was found.
func (_q *TeamGroupQuery) First(ctx context.Context) (*TeamGroup, error) {
@@ -475,10 +523,12 @@ func (_q *TeamGroupQuery) Clone() *TeamGroupQuery {
withModels: _q.withModels.Clone(),
withImages: _q.withImages.Clone(),
withHosts: _q.withHosts.Clone(),
withSkills: _q.withSkills.Clone(),
withTeamGroupMembers: _q.withTeamGroupMembers.Clone(),
withTeamGroupModels: _q.withTeamGroupModels.Clone(),
withTeamGroupImages: _q.withTeamGroupImages.Clone(),
withTeamGroupHosts: _q.withTeamGroupHosts.Clone(),
withTeamGroupSkills: _q.withTeamGroupSkills.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
@@ -541,6 +591,17 @@ func (_q *TeamGroupQuery) WithHosts(opts ...func(*HostQuery)) *TeamGroupQuery {
return _q
}
// WithSkills tells the query-builder to eager-load the nodes that are connected to
// the "skills" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *TeamGroupQuery) WithSkills(opts ...func(*SkillQuery)) *TeamGroupQuery {
query := (&SkillClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withSkills = query
return _q
}
// WithTeamGroupMembers tells the query-builder to eager-load the nodes that are connected to
// the "team_group_members" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *TeamGroupQuery) WithTeamGroupMembers(opts ...func(*TeamGroupMemberQuery)) *TeamGroupQuery {
@@ -585,6 +646,17 @@ func (_q *TeamGroupQuery) WithTeamGroupHosts(opts ...func(*TeamGroupHostQuery))
return _q
}
// WithTeamGroupSkills tells the query-builder to eager-load the nodes that are connected to
// the "team_group_skills" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *TeamGroupQuery) WithTeamGroupSkills(opts ...func(*TeamGroupSkillQuery)) *TeamGroupQuery {
query := (&TeamGroupSkillClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withTeamGroupSkills = query
return _q
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
@@ -663,16 +735,18 @@ func (_q *TeamGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Te
var (
nodes = []*TeamGroup{}
_spec = _q.querySpec()
loadedTypes = [9]bool{
loadedTypes = [11]bool{
_q.withMembers != nil,
_q.withTeam != nil,
_q.withModels != nil,
_q.withImages != nil,
_q.withHosts != nil,
_q.withSkills != nil,
_q.withTeamGroupMembers != nil,
_q.withTeamGroupModels != nil,
_q.withTeamGroupImages != nil,
_q.withTeamGroupHosts != nil,
_q.withTeamGroupSkills != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
@@ -730,6 +804,13 @@ func (_q *TeamGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Te
return nil, err
}
}
if query := _q.withSkills; query != nil {
if err := _q.loadSkills(ctx, query, nodes,
func(n *TeamGroup) { n.Edges.Skills = []*Skill{} },
func(n *TeamGroup, e *Skill) { n.Edges.Skills = append(n.Edges.Skills, e) }); err != nil {
return nil, err
}
}
if query := _q.withTeamGroupMembers; query != nil {
if err := _q.loadTeamGroupMembers(ctx, query, nodes,
func(n *TeamGroup) { n.Edges.TeamGroupMembers = []*TeamGroupMember{} },
@@ -758,6 +839,13 @@ func (_q *TeamGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Te
return nil, err
}
}
if query := _q.withTeamGroupSkills; query != nil {
if err := _q.loadTeamGroupSkills(ctx, query, nodes,
func(n *TeamGroup) { n.Edges.TeamGroupSkills = []*TeamGroupSkill{} },
func(n *TeamGroup, e *TeamGroupSkill) { n.Edges.TeamGroupSkills = append(n.Edges.TeamGroupSkills, e) }); err != nil {
return nil, err
}
}
return nodes, nil
}
@@ -1034,6 +1122,67 @@ func (_q *TeamGroupQuery) loadHosts(ctx context.Context, query *HostQuery, nodes
}
return nil
}
func (_q *TeamGroupQuery) loadSkills(ctx context.Context, query *SkillQuery, nodes []*TeamGroup, init func(*TeamGroup), assign func(*TeamGroup, *Skill)) error {
edgeIDs := make([]driver.Value, len(nodes))
byID := make(map[uuid.UUID]*TeamGroup)
nids := make(map[uuid.UUID]map[*TeamGroup]struct{})
for i, node := range nodes {
edgeIDs[i] = node.ID
byID[node.ID] = node
if init != nil {
init(node)
}
}
query.Where(func(s *sql.Selector) {
joinT := sql.Table(teamgroup.SkillsTable)
s.Join(joinT).On(s.C(skill.FieldID), joinT.C(teamgroup.SkillsPrimaryKey[1]))
s.Where(sql.InValues(joinT.C(teamgroup.SkillsPrimaryKey[0]), edgeIDs...))
columns := s.SelectedColumns()
s.Select(joinT.C(teamgroup.SkillsPrimaryKey[0]))
s.AppendSelect(columns...)
s.SetDistinct(false)
})
if err := query.prepareQuery(ctx); err != nil {
return err
}
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
assign := spec.Assign
values := spec.ScanValues
spec.ScanValues = func(columns []string) ([]any, error) {
values, err := values(columns[1:])
if err != nil {
return nil, err
}
return append([]any{new(uuid.UUID)}, values...), nil
}
spec.Assign = func(columns []string, values []any) error {
outValue := *values[0].(*uuid.UUID)
inValue := *values[1].(*uuid.UUID)
if nids[inValue] == nil {
nids[inValue] = map[*TeamGroup]struct{}{byID[outValue]: {}}
return assign(columns[1:], values[1:])
}
nids[inValue][byID[outValue]] = struct{}{}
return nil
}
})
})
neighbors, err := withInterceptors[[]*Skill](ctx, query, qr, query.inters)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nids[n.ID]
if !ok {
return fmt.Errorf(`unexpected "skills" node returned %v`, n.ID)
}
for kn := range nodes {
assign(kn, n)
}
}
return nil
}
func (_q *TeamGroupQuery) loadTeamGroupMembers(ctx context.Context, query *TeamGroupMemberQuery, nodes []*TeamGroup, init func(*TeamGroup), assign func(*TeamGroup, *TeamGroupMember)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[uuid.UUID]*TeamGroup)
@@ -1154,6 +1303,36 @@ func (_q *TeamGroupQuery) loadTeamGroupHosts(ctx context.Context, query *TeamGro
}
return nil
}
func (_q *TeamGroupQuery) loadTeamGroupSkills(ctx context.Context, query *TeamGroupSkillQuery, nodes []*TeamGroup, init func(*TeamGroup), assign func(*TeamGroup, *TeamGroupSkill)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[uuid.UUID]*TeamGroup)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
if init != nil {
init(nodes[i])
}
}
if len(query.ctx.Fields) > 0 {
query.ctx.AppendFieldOnce(teamgroupskill.FieldGroupID)
}
query.Where(predicate.TeamGroupSkill(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(teamgroup.TeamGroupSkillsColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.GroupID
node, ok := nodeids[fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "group_id" returned %v for node %v`, fk, n.ID)
}
assign(node, n)
}
return nil
}
func (_q *TeamGroupQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
+350
View File
@@ -15,12 +15,14 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/image"
"github.com/chaitin/MonkeyCode/backend/db/model"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamgrouphost"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupimage"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmember"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/google/uuid"
)
@@ -172,6 +174,21 @@ func (_u *TeamGroupUpdate) AddHosts(v ...*Host) *TeamGroupUpdate {
return _u.AddHostIDs(ids...)
}
// AddSkillIDs adds the "skills" edge to the Skill entity by IDs.
func (_u *TeamGroupUpdate) AddSkillIDs(ids ...uuid.UUID) *TeamGroupUpdate {
_u.mutation.AddSkillIDs(ids...)
return _u
}
// AddSkills adds the "skills" edges to the Skill entity.
func (_u *TeamGroupUpdate) AddSkills(v ...*Skill) *TeamGroupUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddSkillIDs(ids...)
}
// AddTeamGroupMemberIDs adds the "team_group_members" edge to the TeamGroupMember entity by IDs.
func (_u *TeamGroupUpdate) AddTeamGroupMemberIDs(ids ...uuid.UUID) *TeamGroupUpdate {
_u.mutation.AddTeamGroupMemberIDs(ids...)
@@ -232,6 +249,21 @@ func (_u *TeamGroupUpdate) AddTeamGroupHosts(v ...*TeamGroupHost) *TeamGroupUpda
return _u.AddTeamGroupHostIDs(ids...)
}
// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by IDs.
func (_u *TeamGroupUpdate) AddTeamGroupSkillIDs(ids ...uuid.UUID) *TeamGroupUpdate {
_u.mutation.AddTeamGroupSkillIDs(ids...)
return _u
}
// AddTeamGroupSkills adds the "team_group_skills" edges to the TeamGroupSkill entity.
func (_u *TeamGroupUpdate) AddTeamGroupSkills(v ...*TeamGroupSkill) *TeamGroupUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddTeamGroupSkillIDs(ids...)
}
// Mutation returns the TeamGroupMutation object of the builder.
func (_u *TeamGroupUpdate) Mutation() *TeamGroupMutation {
return _u.mutation
@@ -327,6 +359,27 @@ func (_u *TeamGroupUpdate) RemoveHosts(v ...*Host) *TeamGroupUpdate {
return _u.RemoveHostIDs(ids...)
}
// ClearSkills clears all "skills" edges to the Skill entity.
func (_u *TeamGroupUpdate) ClearSkills() *TeamGroupUpdate {
_u.mutation.ClearSkills()
return _u
}
// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs.
func (_u *TeamGroupUpdate) RemoveSkillIDs(ids ...uuid.UUID) *TeamGroupUpdate {
_u.mutation.RemoveSkillIDs(ids...)
return _u
}
// RemoveSkills removes "skills" edges to Skill entities.
func (_u *TeamGroupUpdate) RemoveSkills(v ...*Skill) *TeamGroupUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveSkillIDs(ids...)
}
// ClearTeamGroupMembers clears all "team_group_members" edges to the TeamGroupMember entity.
func (_u *TeamGroupUpdate) ClearTeamGroupMembers() *TeamGroupUpdate {
_u.mutation.ClearTeamGroupMembers()
@@ -411,6 +464,27 @@ func (_u *TeamGroupUpdate) RemoveTeamGroupHosts(v ...*TeamGroupHost) *TeamGroupU
return _u.RemoveTeamGroupHostIDs(ids...)
}
// ClearTeamGroupSkills clears all "team_group_skills" edges to the TeamGroupSkill entity.
func (_u *TeamGroupUpdate) ClearTeamGroupSkills() *TeamGroupUpdate {
_u.mutation.ClearTeamGroupSkills()
return _u
}
// RemoveTeamGroupSkillIDs removes the "team_group_skills" edge to TeamGroupSkill entities by IDs.
func (_u *TeamGroupUpdate) RemoveTeamGroupSkillIDs(ids ...uuid.UUID) *TeamGroupUpdate {
_u.mutation.RemoveTeamGroupSkillIDs(ids...)
return _u
}
// RemoveTeamGroupSkills removes "team_group_skills" edges to TeamGroupSkill entities.
func (_u *TeamGroupUpdate) RemoveTeamGroupSkills(v ...*TeamGroupSkill) *TeamGroupUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveTeamGroupSkillIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *TeamGroupUpdate) Save(ctx context.Context) (int, error) {
if err := _u.defaults(); err != nil {
@@ -751,6 +825,63 @@ func (_u *TeamGroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
edge.Target.Fields = specE.Fields
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: teamgroup.SkillsTable,
Columns: teamgroup.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: teamgroup.SkillsTable,
Columns: teamgroup.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: teamgroup.SkillsTable,
Columns: teamgroup.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.TeamGroupMembersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -931,6 +1062,51 @@ func (_u *TeamGroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.TeamGroupSkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: teamgroup.TeamGroupSkillsTable,
Columns: []string{teamgroup.TeamGroupSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedTeamGroupSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamGroupSkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: teamgroup.TeamGroupSkillsTable,
Columns: []string{teamgroup.TeamGroupSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.TeamGroupSkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: teamgroup.TeamGroupSkillsTable,
Columns: []string{teamgroup.TeamGroupSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
@@ -1086,6 +1262,21 @@ func (_u *TeamGroupUpdateOne) AddHosts(v ...*Host) *TeamGroupUpdateOne {
return _u.AddHostIDs(ids...)
}
// AddSkillIDs adds the "skills" edge to the Skill entity by IDs.
func (_u *TeamGroupUpdateOne) AddSkillIDs(ids ...uuid.UUID) *TeamGroupUpdateOne {
_u.mutation.AddSkillIDs(ids...)
return _u
}
// AddSkills adds the "skills" edges to the Skill entity.
func (_u *TeamGroupUpdateOne) AddSkills(v ...*Skill) *TeamGroupUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddSkillIDs(ids...)
}
// AddTeamGroupMemberIDs adds the "team_group_members" edge to the TeamGroupMember entity by IDs.
func (_u *TeamGroupUpdateOne) AddTeamGroupMemberIDs(ids ...uuid.UUID) *TeamGroupUpdateOne {
_u.mutation.AddTeamGroupMemberIDs(ids...)
@@ -1146,6 +1337,21 @@ func (_u *TeamGroupUpdateOne) AddTeamGroupHosts(v ...*TeamGroupHost) *TeamGroupU
return _u.AddTeamGroupHostIDs(ids...)
}
// AddTeamGroupSkillIDs adds the "team_group_skills" edge to the TeamGroupSkill entity by IDs.
func (_u *TeamGroupUpdateOne) AddTeamGroupSkillIDs(ids ...uuid.UUID) *TeamGroupUpdateOne {
_u.mutation.AddTeamGroupSkillIDs(ids...)
return _u
}
// AddTeamGroupSkills adds the "team_group_skills" edges to the TeamGroupSkill entity.
func (_u *TeamGroupUpdateOne) AddTeamGroupSkills(v ...*TeamGroupSkill) *TeamGroupUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddTeamGroupSkillIDs(ids...)
}
// Mutation returns the TeamGroupMutation object of the builder.
func (_u *TeamGroupUpdateOne) Mutation() *TeamGroupMutation {
return _u.mutation
@@ -1241,6 +1447,27 @@ func (_u *TeamGroupUpdateOne) RemoveHosts(v ...*Host) *TeamGroupUpdateOne {
return _u.RemoveHostIDs(ids...)
}
// ClearSkills clears all "skills" edges to the Skill entity.
func (_u *TeamGroupUpdateOne) ClearSkills() *TeamGroupUpdateOne {
_u.mutation.ClearSkills()
return _u
}
// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs.
func (_u *TeamGroupUpdateOne) RemoveSkillIDs(ids ...uuid.UUID) *TeamGroupUpdateOne {
_u.mutation.RemoveSkillIDs(ids...)
return _u
}
// RemoveSkills removes "skills" edges to Skill entities.
func (_u *TeamGroupUpdateOne) RemoveSkills(v ...*Skill) *TeamGroupUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveSkillIDs(ids...)
}
// ClearTeamGroupMembers clears all "team_group_members" edges to the TeamGroupMember entity.
func (_u *TeamGroupUpdateOne) ClearTeamGroupMembers() *TeamGroupUpdateOne {
_u.mutation.ClearTeamGroupMembers()
@@ -1325,6 +1552,27 @@ func (_u *TeamGroupUpdateOne) RemoveTeamGroupHosts(v ...*TeamGroupHost) *TeamGro
return _u.RemoveTeamGroupHostIDs(ids...)
}
// ClearTeamGroupSkills clears all "team_group_skills" edges to the TeamGroupSkill entity.
func (_u *TeamGroupUpdateOne) ClearTeamGroupSkills() *TeamGroupUpdateOne {
_u.mutation.ClearTeamGroupSkills()
return _u
}
// RemoveTeamGroupSkillIDs removes the "team_group_skills" edge to TeamGroupSkill entities by IDs.
func (_u *TeamGroupUpdateOne) RemoveTeamGroupSkillIDs(ids ...uuid.UUID) *TeamGroupUpdateOne {
_u.mutation.RemoveTeamGroupSkillIDs(ids...)
return _u
}
// RemoveTeamGroupSkills removes "team_group_skills" edges to TeamGroupSkill entities.
func (_u *TeamGroupUpdateOne) RemoveTeamGroupSkills(v ...*TeamGroupSkill) *TeamGroupUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveTeamGroupSkillIDs(ids...)
}
// Where appends a list predicates to the TeamGroupUpdate builder.
func (_u *TeamGroupUpdateOne) Where(ps ...predicate.TeamGroup) *TeamGroupUpdateOne {
_u.mutation.Where(ps...)
@@ -1695,6 +1943,63 @@ func (_u *TeamGroupUpdateOne) sqlSave(ctx context.Context) (_node *TeamGroup, er
edge.Target.Fields = specE.Fields
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: teamgroup.SkillsTable,
Columns: teamgroup.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: teamgroup.SkillsTable,
Columns: teamgroup.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: teamgroup.SkillsTable,
Columns: teamgroup.SkillsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
createE := &TeamGroupSkillCreate{config: _u.config, mutation: newTeamGroupSkillMutation(_u.config, OpCreate)}
createE.defaults()
_, specE := createE.createSpec()
edge.Target.Fields = specE.Fields
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.TeamGroupMembersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -1875,6 +2180,51 @@ func (_u *TeamGroupUpdateOne) sqlSave(ctx context.Context) (_node *TeamGroup, er
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.TeamGroupSkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: teamgroup.TeamGroupSkillsTable,
Columns: []string{teamgroup.TeamGroupSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedTeamGroupSkillsIDs(); len(nodes) > 0 && !_u.mutation.TeamGroupSkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: teamgroup.TeamGroupSkillsTable,
Columns: []string{teamgroup.TeamGroupSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.TeamGroupSkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: teamgroup.TeamGroupSkillsTable,
Columns: []string{teamgroup.TeamGroupSkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
_node = &TeamGroup{config: _u.config}
_spec.Assign = _node.assignValues
+175
View File
@@ -0,0 +1,175 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/google/uuid"
)
// TeamGroupSkill is the model entity for the TeamGroupSkill schema.
type TeamGroupSkill struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// GroupID holds the value of the "group_id" field.
GroupID uuid.UUID `json:"group_id,omitempty"`
// SkillID holds the value of the "skill_id" field.
SkillID uuid.UUID `json:"skill_id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the TeamGroupSkillQuery when eager-loading is set.
Edges TeamGroupSkillEdges `json:"edges"`
selectValues sql.SelectValues
}
// TeamGroupSkillEdges holds the relations/edges for other nodes in the graph.
type TeamGroupSkillEdges struct {
// Group holds the value of the group edge.
Group *TeamGroup `json:"group,omitempty"`
// Skill holds the value of the skill edge.
Skill *Skill `json:"skill,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// GroupOrErr returns the Group value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TeamGroupSkillEdges) GroupOrErr() (*TeamGroup, error) {
if e.Group != nil {
return e.Group, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: teamgroup.Label}
}
return nil, &NotLoadedError{edge: "group"}
}
// SkillOrErr returns the Skill value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TeamGroupSkillEdges) SkillOrErr() (*Skill, error) {
if e.Skill != nil {
return e.Skill, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: skill.Label}
}
return nil, &NotLoadedError{edge: "skill"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*TeamGroupSkill) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case teamgroupskill.FieldCreatedAt:
values[i] = new(sql.NullTime)
case teamgroupskill.FieldID, teamgroupskill.FieldGroupID, teamgroupskill.FieldSkillID:
values[i] = new(uuid.UUID)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the TeamGroupSkill fields.
func (_m *TeamGroupSkill) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case teamgroupskill.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
_m.ID = *value
}
case teamgroupskill.FieldGroupID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field group_id", values[i])
} else if value != nil {
_m.GroupID = *value
}
case teamgroupskill.FieldSkillID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field skill_id", values[i])
} else if value != nil {
_m.SkillID = *value
}
case teamgroupskill.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the TeamGroupSkill.
// This includes values selected through modifiers, order, etc.
func (_m *TeamGroupSkill) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryGroup queries the "group" edge of the TeamGroupSkill entity.
func (_m *TeamGroupSkill) QueryGroup() *TeamGroupQuery {
return NewTeamGroupSkillClient(_m.config).QueryGroup(_m)
}
// QuerySkill queries the "skill" edge of the TeamGroupSkill entity.
func (_m *TeamGroupSkill) QuerySkill() *SkillQuery {
return NewTeamGroupSkillClient(_m.config).QuerySkill(_m)
}
// Update returns a builder for updating this TeamGroupSkill.
// Note that you need to call TeamGroupSkill.Unwrap() before calling this method if this TeamGroupSkill
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *TeamGroupSkill) Update() *TeamGroupSkillUpdateOne {
return NewTeamGroupSkillClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the TeamGroupSkill entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *TeamGroupSkill) Unwrap() *TeamGroupSkill {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("db: TeamGroupSkill is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *TeamGroupSkill) String() string {
var builder strings.Builder
builder.WriteString("TeamGroupSkill(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("group_id=")
builder.WriteString(fmt.Sprintf("%v", _m.GroupID))
builder.WriteString(", ")
builder.WriteString("skill_id=")
builder.WriteString(fmt.Sprintf("%v", _m.SkillID))
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// TeamGroupSkills is a parsable slice of TeamGroupSkill.
type TeamGroupSkills []*TeamGroupSkill
+117
View File
@@ -0,0 +1,117 @@
// Code generated by ent, DO NOT EDIT.
package teamgroupskill
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the teamgroupskill type in the database.
Label = "team_group_skill"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldGroupID holds the string denoting the group_id field in the database.
FieldGroupID = "group_id"
// FieldSkillID holds the string denoting the skill_id field in the database.
FieldSkillID = "skill_id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// EdgeGroup holds the string denoting the group edge name in mutations.
EdgeGroup = "group"
// EdgeSkill holds the string denoting the skill edge name in mutations.
EdgeSkill = "skill"
// Table holds the table name of the teamgroupskill in the database.
Table = "team_group_skills"
// GroupTable is the table that holds the group relation/edge.
GroupTable = "team_group_skills"
// GroupInverseTable is the table name for the TeamGroup entity.
// It exists in this package in order to avoid circular dependency with the "teamgroup" package.
GroupInverseTable = "team_groups"
// GroupColumn is the table column denoting the group relation/edge.
GroupColumn = "group_id"
// SkillTable is the table that holds the skill relation/edge.
SkillTable = "team_group_skills"
// SkillInverseTable is the table name for the Skill entity.
// It exists in this package in order to avoid circular dependency with the "skill" package.
SkillInverseTable = "skills"
// SkillColumn is the table column denoting the skill relation/edge.
SkillColumn = "skill_id"
)
// Columns holds all SQL columns for teamgroupskill fields.
var Columns = []string{
FieldID,
FieldGroupID,
FieldSkillID,
FieldCreatedAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
)
// OrderOption defines the ordering options for the TeamGroupSkill queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByGroupID orders the results by the group_id field.
func ByGroupID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldGroupID, opts...).ToFunc()
}
// BySkillID orders the results by the skill_id field.
func BySkillID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSkillID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByGroupField orders the results by group field.
func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...))
}
}
// BySkillField orders the results by skill field.
func BySkillField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newSkillStep(), sql.OrderByField(field, opts...))
}
}
func newGroupStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(GroupInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn),
)
}
func newSkillStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(SkillInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, SkillTable, SkillColumn),
)
}
+213
View File
@@ -0,0 +1,213 @@
// Code generated by ent, DO NOT EDIT.
package teamgroupskill
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/google/uuid"
)
// ID filters vertices based on their ID field.
func ID(id uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldLTE(FieldID, id))
}
// GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ.
func GroupID(v uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldEQ(FieldGroupID, v))
}
// SkillID applies equality check predicate on the "skill_id" field. It's identical to SkillIDEQ.
func SkillID(v uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldEQ(FieldSkillID, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldEQ(FieldCreatedAt, v))
}
// GroupIDEQ applies the EQ predicate on the "group_id" field.
func GroupIDEQ(v uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldEQ(FieldGroupID, v))
}
// GroupIDNEQ applies the NEQ predicate on the "group_id" field.
func GroupIDNEQ(v uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldNEQ(FieldGroupID, v))
}
// GroupIDIn applies the In predicate on the "group_id" field.
func GroupIDIn(vs ...uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldIn(FieldGroupID, vs...))
}
// GroupIDNotIn applies the NotIn predicate on the "group_id" field.
func GroupIDNotIn(vs ...uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldNotIn(FieldGroupID, vs...))
}
// SkillIDEQ applies the EQ predicate on the "skill_id" field.
func SkillIDEQ(v uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldEQ(FieldSkillID, v))
}
// SkillIDNEQ applies the NEQ predicate on the "skill_id" field.
func SkillIDNEQ(v uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldNEQ(FieldSkillID, v))
}
// SkillIDIn applies the In predicate on the "skill_id" field.
func SkillIDIn(vs ...uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldIn(FieldSkillID, vs...))
}
// SkillIDNotIn applies the NotIn predicate on the "skill_id" field.
func SkillIDNotIn(vs ...uuid.UUID) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldNotIn(FieldSkillID, vs...))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.FieldLTE(FieldCreatedAt, v))
}
// HasGroup applies the HasEdge predicate on the "group" edge.
func HasGroup() predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates).
func HasGroupWith(preds ...predicate.TeamGroup) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(func(s *sql.Selector) {
step := newGroupStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasSkill applies the HasEdge predicate on the "skill" edge.
func HasSkill() predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, SkillTable, SkillColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasSkillWith applies the HasEdge predicate on the "skill" edge with a given conditions (other predicates).
func HasSkillWith(preds ...predicate.Skill) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(func(s *sql.Selector) {
step := newSkillStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.TeamGroupSkill) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.TeamGroupSkill) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.TeamGroupSkill) predicate.TeamGroupSkill {
return predicate.TeamGroupSkill(sql.NotPredicates(p))
}
+659
View File
@@ -0,0 +1,659 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/google/uuid"
)
// TeamGroupSkillCreate is the builder for creating a TeamGroupSkill entity.
type TeamGroupSkillCreate struct {
config
mutation *TeamGroupSkillMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetGroupID sets the "group_id" field.
func (_c *TeamGroupSkillCreate) SetGroupID(v uuid.UUID) *TeamGroupSkillCreate {
_c.mutation.SetGroupID(v)
return _c
}
// SetSkillID sets the "skill_id" field.
func (_c *TeamGroupSkillCreate) SetSkillID(v uuid.UUID) *TeamGroupSkillCreate {
_c.mutation.SetSkillID(v)
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *TeamGroupSkillCreate) SetCreatedAt(v time.Time) *TeamGroupSkillCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *TeamGroupSkillCreate) SetNillableCreatedAt(v *time.Time) *TeamGroupSkillCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *TeamGroupSkillCreate) SetID(v uuid.UUID) *TeamGroupSkillCreate {
_c.mutation.SetID(v)
return _c
}
// SetGroup sets the "group" edge to the TeamGroup entity.
func (_c *TeamGroupSkillCreate) SetGroup(v *TeamGroup) *TeamGroupSkillCreate {
return _c.SetGroupID(v.ID)
}
// SetSkill sets the "skill" edge to the Skill entity.
func (_c *TeamGroupSkillCreate) SetSkill(v *Skill) *TeamGroupSkillCreate {
return _c.SetSkillID(v.ID)
}
// Mutation returns the TeamGroupSkillMutation object of the builder.
func (_c *TeamGroupSkillCreate) Mutation() *TeamGroupSkillMutation {
return _c.mutation
}
// Save creates the TeamGroupSkill in the database.
func (_c *TeamGroupSkillCreate) Save(ctx context.Context) (*TeamGroupSkill, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *TeamGroupSkillCreate) SaveX(ctx context.Context) *TeamGroupSkill {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *TeamGroupSkillCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *TeamGroupSkillCreate) 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 *TeamGroupSkillCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := teamgroupskill.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *TeamGroupSkillCreate) check() error {
if _, ok := _c.mutation.GroupID(); !ok {
return &ValidationError{Name: "group_id", err: errors.New(`db: missing required field "TeamGroupSkill.group_id"`)}
}
if _, ok := _c.mutation.SkillID(); !ok {
return &ValidationError{Name: "skill_id", err: errors.New(`db: missing required field "TeamGroupSkill.skill_id"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "TeamGroupSkill.created_at"`)}
}
if len(_c.mutation.GroupIDs()) == 0 {
return &ValidationError{Name: "group", err: errors.New(`db: missing required edge "TeamGroupSkill.group"`)}
}
if len(_c.mutation.SkillIDs()) == 0 {
return &ValidationError{Name: "skill", err: errors.New(`db: missing required edge "TeamGroupSkill.skill"`)}
}
return nil
}
func (_c *TeamGroupSkillCreate) sqlSave(ctx context.Context) (*TeamGroupSkill, 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 *TeamGroupSkillCreate) createSpec() (*TeamGroupSkill, *sqlgraph.CreateSpec) {
var (
_node = &TeamGroupSkill{config: _c.config}
_spec = sqlgraph.NewCreateSpec(teamgroupskill.Table, sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID))
)
_spec.OnConflict = _c.conflict
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = &id
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(teamgroupskill.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamgroupskill.GroupTable,
Columns: []string{teamgroupskill.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.GroupID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.SkillIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamgroupskill.SkillTable,
Columns: []string{teamgroupskill.SkillColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.SkillID = 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.TeamGroupSkill.Create().
// SetGroupID(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.TeamGroupSkillUpsert) {
// SetGroupID(v+v).
// }).
// Exec(ctx)
func (_c *TeamGroupSkillCreate) OnConflict(opts ...sql.ConflictOption) *TeamGroupSkillUpsertOne {
_c.conflict = opts
return &TeamGroupSkillUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.TeamGroupSkill.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *TeamGroupSkillCreate) OnConflictColumns(columns ...string) *TeamGroupSkillUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &TeamGroupSkillUpsertOne{
create: _c,
}
}
type (
// TeamGroupSkillUpsertOne is the builder for "upsert"-ing
// one TeamGroupSkill node.
TeamGroupSkillUpsertOne struct {
create *TeamGroupSkillCreate
}
// TeamGroupSkillUpsert is the "OnConflict" setter.
TeamGroupSkillUpsert struct {
*sql.UpdateSet
}
)
// SetGroupID sets the "group_id" field.
func (u *TeamGroupSkillUpsert) SetGroupID(v uuid.UUID) *TeamGroupSkillUpsert {
u.Set(teamgroupskill.FieldGroupID, v)
return u
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *TeamGroupSkillUpsert) UpdateGroupID() *TeamGroupSkillUpsert {
u.SetExcluded(teamgroupskill.FieldGroupID)
return u
}
// SetSkillID sets the "skill_id" field.
func (u *TeamGroupSkillUpsert) SetSkillID(v uuid.UUID) *TeamGroupSkillUpsert {
u.Set(teamgroupskill.FieldSkillID, v)
return u
}
// UpdateSkillID sets the "skill_id" field to the value that was provided on create.
func (u *TeamGroupSkillUpsert) UpdateSkillID() *TeamGroupSkillUpsert {
u.SetExcluded(teamgroupskill.FieldSkillID)
return u
}
// SetCreatedAt sets the "created_at" field.
func (u *TeamGroupSkillUpsert) SetCreatedAt(v time.Time) *TeamGroupSkillUpsert {
u.Set(teamgroupskill.FieldCreatedAt, v)
return u
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *TeamGroupSkillUpsert) UpdateCreatedAt() *TeamGroupSkillUpsert {
u.SetExcluded(teamgroupskill.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.TeamGroupSkill.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(teamgroupskill.FieldID)
// }),
// ).
// Exec(ctx)
func (u *TeamGroupSkillUpsertOne) UpdateNewValues() *TeamGroupSkillUpsertOne {
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(teamgroupskill.FieldID)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.TeamGroupSkill.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *TeamGroupSkillUpsertOne) Ignore() *TeamGroupSkillUpsertOne {
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 *TeamGroupSkillUpsertOne) DoNothing() *TeamGroupSkillUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the TeamGroupSkillCreate.OnConflict
// documentation for more info.
func (u *TeamGroupSkillUpsertOne) Update(set func(*TeamGroupSkillUpsert)) *TeamGroupSkillUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&TeamGroupSkillUpsert{UpdateSet: update})
}))
return u
}
// SetGroupID sets the "group_id" field.
func (u *TeamGroupSkillUpsertOne) SetGroupID(v uuid.UUID) *TeamGroupSkillUpsertOne {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.SetGroupID(v)
})
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *TeamGroupSkillUpsertOne) UpdateGroupID() *TeamGroupSkillUpsertOne {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.UpdateGroupID()
})
}
// SetSkillID sets the "skill_id" field.
func (u *TeamGroupSkillUpsertOne) SetSkillID(v uuid.UUID) *TeamGroupSkillUpsertOne {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.SetSkillID(v)
})
}
// UpdateSkillID sets the "skill_id" field to the value that was provided on create.
func (u *TeamGroupSkillUpsertOne) UpdateSkillID() *TeamGroupSkillUpsertOne {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.UpdateSkillID()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *TeamGroupSkillUpsertOne) SetCreatedAt(v time.Time) *TeamGroupSkillUpsertOne {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.SetCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *TeamGroupSkillUpsertOne) UpdateCreatedAt() *TeamGroupSkillUpsertOne {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.UpdateCreatedAt()
})
}
// Exec executes the query.
func (u *TeamGroupSkillUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("db: missing options for TeamGroupSkillCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *TeamGroupSkillUpsertOne) 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 *TeamGroupSkillUpsertOne) 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: TeamGroupSkillUpsertOne.ID is not supported by MySQL driver. Use TeamGroupSkillUpsertOne.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 *TeamGroupSkillUpsertOne) IDX(ctx context.Context) uuid.UUID {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// TeamGroupSkillCreateBulk is the builder for creating many TeamGroupSkill entities in bulk.
type TeamGroupSkillCreateBulk struct {
config
err error
builders []*TeamGroupSkillCreate
conflict []sql.ConflictOption
}
// Save creates the TeamGroupSkill entities in the database.
func (_c *TeamGroupSkillCreateBulk) Save(ctx context.Context) ([]*TeamGroupSkill, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*TeamGroupSkill, 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.(*TeamGroupSkillMutation)
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 *TeamGroupSkillCreateBulk) SaveX(ctx context.Context) []*TeamGroupSkill {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *TeamGroupSkillCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *TeamGroupSkillCreateBulk) 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.TeamGroupSkill.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.TeamGroupSkillUpsert) {
// SetGroupID(v+v).
// }).
// Exec(ctx)
func (_c *TeamGroupSkillCreateBulk) OnConflict(opts ...sql.ConflictOption) *TeamGroupSkillUpsertBulk {
_c.conflict = opts
return &TeamGroupSkillUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.TeamGroupSkill.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *TeamGroupSkillCreateBulk) OnConflictColumns(columns ...string) *TeamGroupSkillUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &TeamGroupSkillUpsertBulk{
create: _c,
}
}
// TeamGroupSkillUpsertBulk is the builder for "upsert"-ing
// a bulk of TeamGroupSkill nodes.
type TeamGroupSkillUpsertBulk struct {
create *TeamGroupSkillCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.TeamGroupSkill.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(teamgroupskill.FieldID)
// }),
// ).
// Exec(ctx)
func (u *TeamGroupSkillUpsertBulk) UpdateNewValues() *TeamGroupSkillUpsertBulk {
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(teamgroupskill.FieldID)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.TeamGroupSkill.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *TeamGroupSkillUpsertBulk) Ignore() *TeamGroupSkillUpsertBulk {
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 *TeamGroupSkillUpsertBulk) DoNothing() *TeamGroupSkillUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the TeamGroupSkillCreateBulk.OnConflict
// documentation for more info.
func (u *TeamGroupSkillUpsertBulk) Update(set func(*TeamGroupSkillUpsert)) *TeamGroupSkillUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&TeamGroupSkillUpsert{UpdateSet: update})
}))
return u
}
// SetGroupID sets the "group_id" field.
func (u *TeamGroupSkillUpsertBulk) SetGroupID(v uuid.UUID) *TeamGroupSkillUpsertBulk {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.SetGroupID(v)
})
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *TeamGroupSkillUpsertBulk) UpdateGroupID() *TeamGroupSkillUpsertBulk {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.UpdateGroupID()
})
}
// SetSkillID sets the "skill_id" field.
func (u *TeamGroupSkillUpsertBulk) SetSkillID(v uuid.UUID) *TeamGroupSkillUpsertBulk {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.SetSkillID(v)
})
}
// UpdateSkillID sets the "skill_id" field to the value that was provided on create.
func (u *TeamGroupSkillUpsertBulk) UpdateSkillID() *TeamGroupSkillUpsertBulk {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.UpdateSkillID()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *TeamGroupSkillUpsertBulk) SetCreatedAt(v time.Time) *TeamGroupSkillUpsertBulk {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.SetCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *TeamGroupSkillUpsertBulk) UpdateCreatedAt() *TeamGroupSkillUpsertBulk {
return u.Update(func(s *TeamGroupSkillUpsert) {
s.UpdateCreatedAt()
})
}
// Exec executes the query.
func (u *TeamGroupSkillUpsertBulk) 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 TeamGroupSkillCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("db: missing options for TeamGroupSkillCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *TeamGroupSkillUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
+88
View File
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
)
// TeamGroupSkillDelete is the builder for deleting a TeamGroupSkill entity.
type TeamGroupSkillDelete struct {
config
hooks []Hook
mutation *TeamGroupSkillMutation
}
// Where appends a list predicates to the TeamGroupSkillDelete builder.
func (_d *TeamGroupSkillDelete) Where(ps ...predicate.TeamGroupSkill) *TeamGroupSkillDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *TeamGroupSkillDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *TeamGroupSkillDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *TeamGroupSkillDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(teamgroupskill.Table, sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// TeamGroupSkillDeleteOne is the builder for deleting a single TeamGroupSkill entity.
type TeamGroupSkillDeleteOne struct {
_d *TeamGroupSkillDelete
}
// Where appends a list predicates to the TeamGroupSkillDelete builder.
func (_d *TeamGroupSkillDeleteOne) Where(ps ...predicate.TeamGroupSkill) *TeamGroupSkillDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *TeamGroupSkillDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{teamgroupskill.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *TeamGroupSkillDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
+732
View File
@@ -0,0 +1,732 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/google/uuid"
)
// TeamGroupSkillQuery is the builder for querying TeamGroupSkill entities.
type TeamGroupSkillQuery struct {
config
ctx *QueryContext
order []teamgroupskill.OrderOption
inters []Interceptor
predicates []predicate.TeamGroupSkill
withGroup *TeamGroupQuery
withSkill *SkillQuery
modifiers []func(*sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the TeamGroupSkillQuery builder.
func (_q *TeamGroupSkillQuery) Where(ps ...predicate.TeamGroupSkill) *TeamGroupSkillQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *TeamGroupSkillQuery) Limit(limit int) *TeamGroupSkillQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *TeamGroupSkillQuery) Offset(offset int) *TeamGroupSkillQuery {
_q.ctx.Offset = &offset
return _q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (_q *TeamGroupSkillQuery) Unique(unique bool) *TeamGroupSkillQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *TeamGroupSkillQuery) Order(o ...teamgroupskill.OrderOption) *TeamGroupSkillQuery {
_q.order = append(_q.order, o...)
return _q
}
// QueryGroup chains the current query on the "group" edge.
func (_q *TeamGroupSkillQuery) QueryGroup() *TeamGroupQuery {
query := (&TeamGroupClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(teamgroupskill.Table, teamgroupskill.FieldID, selector),
sqlgraph.To(teamgroup.Table, teamgroup.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, teamgroupskill.GroupTable, teamgroupskill.GroupColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QuerySkill chains the current query on the "skill" edge.
func (_q *TeamGroupSkillQuery) QuerySkill() *SkillQuery {
query := (&SkillClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(teamgroupskill.Table, teamgroupskill.FieldID, selector),
sqlgraph.To(skill.Table, skill.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, teamgroupskill.SkillTable, teamgroupskill.SkillColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first TeamGroupSkill entity from the query.
// Returns a *NotFoundError when no TeamGroupSkill was found.
func (_q *TeamGroupSkillQuery) First(ctx context.Context) (*TeamGroupSkill, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{teamgroupskill.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *TeamGroupSkillQuery) FirstX(ctx context.Context) *TeamGroupSkill {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first TeamGroupSkill ID from the query.
// Returns a *NotFoundError when no TeamGroupSkill ID was found.
func (_q *TeamGroupSkillQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{teamgroupskill.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *TeamGroupSkillQuery) FirstIDX(ctx context.Context) uuid.UUID {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single TeamGroupSkill entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one TeamGroupSkill entity is found.
// Returns a *NotFoundError when no TeamGroupSkill entities are found.
func (_q *TeamGroupSkillQuery) Only(ctx context.Context) (*TeamGroupSkill, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{teamgroupskill.Label}
default:
return nil, &NotSingularError{teamgroupskill.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *TeamGroupSkillQuery) OnlyX(ctx context.Context) *TeamGroupSkill {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only TeamGroupSkill ID in the query.
// Returns a *NotSingularError when more than one TeamGroupSkill ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *TeamGroupSkillQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{teamgroupskill.Label}
default:
err = &NotSingularError{teamgroupskill.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *TeamGroupSkillQuery) OnlyIDX(ctx context.Context) uuid.UUID {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of TeamGroupSkills.
func (_q *TeamGroupSkillQuery) All(ctx context.Context) ([]*TeamGroupSkill, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*TeamGroupSkill, *TeamGroupSkillQuery]()
return withInterceptors[[]*TeamGroupSkill](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *TeamGroupSkillQuery) AllX(ctx context.Context) []*TeamGroupSkill {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of TeamGroupSkill IDs.
func (_q *TeamGroupSkillQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(teamgroupskill.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *TeamGroupSkillQuery) IDsX(ctx context.Context) []uuid.UUID {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *TeamGroupSkillQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*TeamGroupSkillQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *TeamGroupSkillQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *TeamGroupSkillQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("db: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *TeamGroupSkillQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the TeamGroupSkillQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *TeamGroupSkillQuery) Clone() *TeamGroupSkillQuery {
if _q == nil {
return nil
}
return &TeamGroupSkillQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]teamgroupskill.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.TeamGroupSkill{}, _q.predicates...),
withGroup: _q.withGroup.Clone(),
withSkill: _q.withSkill.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
modifiers: append([]func(*sql.Selector){}, _q.modifiers...),
}
}
// WithGroup tells the query-builder to eager-load the nodes that are connected to
// the "group" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *TeamGroupSkillQuery) WithGroup(opts ...func(*TeamGroupQuery)) *TeamGroupSkillQuery {
query := (&TeamGroupClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withGroup = query
return _q
}
// WithSkill tells the query-builder to eager-load the nodes that are connected to
// the "skill" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *TeamGroupSkillQuery) WithSkill(opts ...func(*SkillQuery)) *TeamGroupSkillQuery {
query := (&SkillClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withSkill = query
return _q
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// GroupID uuid.UUID `json:"group_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.TeamGroupSkill.Query().
// GroupBy(teamgroupskill.FieldGroupID).
// Aggregate(db.Count()).
// Scan(ctx, &v)
func (_q *TeamGroupSkillQuery) GroupBy(field string, fields ...string) *TeamGroupSkillGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &TeamGroupSkillGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = teamgroupskill.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// GroupID uuid.UUID `json:"group_id,omitempty"`
// }
//
// client.TeamGroupSkill.Query().
// Select(teamgroupskill.FieldGroupID).
// Scan(ctx, &v)
func (_q *TeamGroupSkillQuery) Select(fields ...string) *TeamGroupSkillSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &TeamGroupSkillSelect{TeamGroupSkillQuery: _q}
sbuild.label = teamgroupskill.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a TeamGroupSkillSelect configured with the given aggregations.
func (_q *TeamGroupSkillQuery) Aggregate(fns ...AggregateFunc) *TeamGroupSkillSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *TeamGroupSkillQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !teamgroupskill.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *TeamGroupSkillQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TeamGroupSkill, error) {
var (
nodes = []*TeamGroupSkill{}
_spec = _q.querySpec()
loadedTypes = [2]bool{
_q.withGroup != nil,
_q.withSkill != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*TeamGroupSkill).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &TeamGroupSkill{config: _q.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
if len(_q.modifiers) > 0 {
_spec.Modifiers = _q.modifiers
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := _q.withGroup; query != nil {
if err := _q.loadGroup(ctx, query, nodes, nil,
func(n *TeamGroupSkill, e *TeamGroup) { n.Edges.Group = e }); err != nil {
return nil, err
}
}
if query := _q.withSkill; query != nil {
if err := _q.loadSkill(ctx, query, nodes, nil,
func(n *TeamGroupSkill, e *Skill) { n.Edges.Skill = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (_q *TeamGroupSkillQuery) loadGroup(ctx context.Context, query *TeamGroupQuery, nodes []*TeamGroupSkill, init func(*TeamGroupSkill), assign func(*TeamGroupSkill, *TeamGroup)) error {
ids := make([]uuid.UUID, 0, len(nodes))
nodeids := make(map[uuid.UUID][]*TeamGroupSkill)
for i := range nodes {
fk := nodes[i].GroupID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(teamgroup.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "group_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *TeamGroupSkillQuery) loadSkill(ctx context.Context, query *SkillQuery, nodes []*TeamGroupSkill, init func(*TeamGroupSkill), assign func(*TeamGroupSkill, *Skill)) error {
ids := make([]uuid.UUID, 0, len(nodes))
nodeids := make(map[uuid.UUID][]*TeamGroupSkill)
for i := range nodes {
fk := nodes[i].SkillID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(skill.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "skill_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *TeamGroupSkillQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
if len(_q.modifiers) > 0 {
_spec.Modifiers = _q.modifiers
}
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *TeamGroupSkillQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(teamgroupskill.Table, teamgroupskill.Columns, sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, teamgroupskill.FieldID)
for i := range fields {
if fields[i] != teamgroupskill.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
if _q.withGroup != nil {
_spec.Node.AddColumnOnce(teamgroupskill.FieldGroupID)
}
if _q.withSkill != nil {
_spec.Node.AddColumnOnce(teamgroupskill.FieldSkillID)
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *TeamGroupSkillQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(teamgroupskill.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = teamgroupskill.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, m := range _q.modifiers {
m(selector)
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func (_q *TeamGroupSkillQuery) ForUpdate(opts ...sql.LockOption) *TeamGroupSkillQuery {
if _q.driver.Dialect() == dialect.Postgres {
_q.Unique(false)
}
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
s.ForUpdate(opts...)
})
return _q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func (_q *TeamGroupSkillQuery) ForShare(opts ...sql.LockOption) *TeamGroupSkillQuery {
if _q.driver.Dialect() == dialect.Postgres {
_q.Unique(false)
}
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
s.ForShare(opts...)
})
return _q
}
// Modify adds a query modifier for attaching custom logic to queries.
func (_q *TeamGroupSkillQuery) Modify(modifiers ...func(s *sql.Selector)) *TeamGroupSkillSelect {
_q.modifiers = append(_q.modifiers, modifiers...)
return _q.Select()
}
// TeamGroupSkillGroupBy is the group-by builder for TeamGroupSkill entities.
type TeamGroupSkillGroupBy struct {
selector
build *TeamGroupSkillQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *TeamGroupSkillGroupBy) Aggregate(fns ...AggregateFunc) *TeamGroupSkillGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *TeamGroupSkillGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*TeamGroupSkillQuery, *TeamGroupSkillGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *TeamGroupSkillGroupBy) sqlScan(ctx context.Context, root *TeamGroupSkillQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// TeamGroupSkillSelect is the builder for selecting fields of TeamGroupSkill entities.
type TeamGroupSkillSelect struct {
*TeamGroupSkillQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *TeamGroupSkillSelect) Aggregate(fns ...AggregateFunc) *TeamGroupSkillSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *TeamGroupSkillSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*TeamGroupSkillQuery, *TeamGroupSkillSelect](ctx, _s.TeamGroupSkillQuery, _s, _s.inters, v)
}
func (_s *TeamGroupSkillSelect) sqlScan(ctx context.Context, root *TeamGroupSkillQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// Modify adds a query modifier for attaching custom logic to queries.
func (_s *TeamGroupSkillSelect) Modify(modifiers ...func(s *sql.Selector)) *TeamGroupSkillSelect {
_s.modifiers = append(_s.modifiers, modifiers...)
return _s
}
+473
View File
@@ -0,0 +1,473 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
"github.com/chaitin/MonkeyCode/backend/db/teamgroupskill"
"github.com/google/uuid"
)
// TeamGroupSkillUpdate is the builder for updating TeamGroupSkill entities.
type TeamGroupSkillUpdate struct {
config
hooks []Hook
mutation *TeamGroupSkillMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the TeamGroupSkillUpdate builder.
func (_u *TeamGroupSkillUpdate) Where(ps ...predicate.TeamGroupSkill) *TeamGroupSkillUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetGroupID sets the "group_id" field.
func (_u *TeamGroupSkillUpdate) SetGroupID(v uuid.UUID) *TeamGroupSkillUpdate {
_u.mutation.SetGroupID(v)
return _u
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *TeamGroupSkillUpdate) SetNillableGroupID(v *uuid.UUID) *TeamGroupSkillUpdate {
if v != nil {
_u.SetGroupID(*v)
}
return _u
}
// SetSkillID sets the "skill_id" field.
func (_u *TeamGroupSkillUpdate) SetSkillID(v uuid.UUID) *TeamGroupSkillUpdate {
_u.mutation.SetSkillID(v)
return _u
}
// SetNillableSkillID sets the "skill_id" field if the given value is not nil.
func (_u *TeamGroupSkillUpdate) SetNillableSkillID(v *uuid.UUID) *TeamGroupSkillUpdate {
if v != nil {
_u.SetSkillID(*v)
}
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *TeamGroupSkillUpdate) SetCreatedAt(v time.Time) *TeamGroupSkillUpdate {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *TeamGroupSkillUpdate) SetNillableCreatedAt(v *time.Time) *TeamGroupSkillUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetGroup sets the "group" edge to the TeamGroup entity.
func (_u *TeamGroupSkillUpdate) SetGroup(v *TeamGroup) *TeamGroupSkillUpdate {
return _u.SetGroupID(v.ID)
}
// SetSkill sets the "skill" edge to the Skill entity.
func (_u *TeamGroupSkillUpdate) SetSkill(v *Skill) *TeamGroupSkillUpdate {
return _u.SetSkillID(v.ID)
}
// Mutation returns the TeamGroupSkillMutation object of the builder.
func (_u *TeamGroupSkillUpdate) Mutation() *TeamGroupSkillMutation {
return _u.mutation
}
// ClearGroup clears the "group" edge to the TeamGroup entity.
func (_u *TeamGroupSkillUpdate) ClearGroup() *TeamGroupSkillUpdate {
_u.mutation.ClearGroup()
return _u
}
// ClearSkill clears the "skill" edge to the Skill entity.
func (_u *TeamGroupSkillUpdate) ClearSkill() *TeamGroupSkillUpdate {
_u.mutation.ClearSkill()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *TeamGroupSkillUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *TeamGroupSkillUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *TeamGroupSkillUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *TeamGroupSkillUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *TeamGroupSkillUpdate) check() error {
if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "TeamGroupSkill.group"`)
}
if _u.mutation.SkillCleared() && len(_u.mutation.SkillIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "TeamGroupSkill.skill"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *TeamGroupSkillUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *TeamGroupSkillUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *TeamGroupSkillUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(teamgroupskill.Table, teamgroupskill.Columns, sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(teamgroupskill.FieldCreatedAt, field.TypeTime, value)
}
if _u.mutation.GroupCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamgroupskill.GroupTable,
Columns: []string{teamgroupskill.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamgroupskill.GroupTable,
Columns: []string{teamgroupskill.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SkillCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamgroupskill.SkillTable,
Columns: []string{teamgroupskill.SkillColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SkillIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamgroupskill.SkillTable,
Columns: []string{teamgroupskill.SkillColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{teamgroupskill.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// TeamGroupSkillUpdateOne is the builder for updating a single TeamGroupSkill entity.
type TeamGroupSkillUpdateOne struct {
config
fields []string
hooks []Hook
mutation *TeamGroupSkillMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetGroupID sets the "group_id" field.
func (_u *TeamGroupSkillUpdateOne) SetGroupID(v uuid.UUID) *TeamGroupSkillUpdateOne {
_u.mutation.SetGroupID(v)
return _u
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *TeamGroupSkillUpdateOne) SetNillableGroupID(v *uuid.UUID) *TeamGroupSkillUpdateOne {
if v != nil {
_u.SetGroupID(*v)
}
return _u
}
// SetSkillID sets the "skill_id" field.
func (_u *TeamGroupSkillUpdateOne) SetSkillID(v uuid.UUID) *TeamGroupSkillUpdateOne {
_u.mutation.SetSkillID(v)
return _u
}
// SetNillableSkillID sets the "skill_id" field if the given value is not nil.
func (_u *TeamGroupSkillUpdateOne) SetNillableSkillID(v *uuid.UUID) *TeamGroupSkillUpdateOne {
if v != nil {
_u.SetSkillID(*v)
}
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *TeamGroupSkillUpdateOne) SetCreatedAt(v time.Time) *TeamGroupSkillUpdateOne {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *TeamGroupSkillUpdateOne) SetNillableCreatedAt(v *time.Time) *TeamGroupSkillUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetGroup sets the "group" edge to the TeamGroup entity.
func (_u *TeamGroupSkillUpdateOne) SetGroup(v *TeamGroup) *TeamGroupSkillUpdateOne {
return _u.SetGroupID(v.ID)
}
// SetSkill sets the "skill" edge to the Skill entity.
func (_u *TeamGroupSkillUpdateOne) SetSkill(v *Skill) *TeamGroupSkillUpdateOne {
return _u.SetSkillID(v.ID)
}
// Mutation returns the TeamGroupSkillMutation object of the builder.
func (_u *TeamGroupSkillUpdateOne) Mutation() *TeamGroupSkillMutation {
return _u.mutation
}
// ClearGroup clears the "group" edge to the TeamGroup entity.
func (_u *TeamGroupSkillUpdateOne) ClearGroup() *TeamGroupSkillUpdateOne {
_u.mutation.ClearGroup()
return _u
}
// ClearSkill clears the "skill" edge to the Skill entity.
func (_u *TeamGroupSkillUpdateOne) ClearSkill() *TeamGroupSkillUpdateOne {
_u.mutation.ClearSkill()
return _u
}
// Where appends a list predicates to the TeamGroupSkillUpdate builder.
func (_u *TeamGroupSkillUpdateOne) Where(ps ...predicate.TeamGroupSkill) *TeamGroupSkillUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *TeamGroupSkillUpdateOne) Select(field string, fields ...string) *TeamGroupSkillUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated TeamGroupSkill entity.
func (_u *TeamGroupSkillUpdateOne) Save(ctx context.Context) (*TeamGroupSkill, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *TeamGroupSkillUpdateOne) SaveX(ctx context.Context) *TeamGroupSkill {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *TeamGroupSkillUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *TeamGroupSkillUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *TeamGroupSkillUpdateOne) check() error {
if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "TeamGroupSkill.group"`)
}
if _u.mutation.SkillCleared() && len(_u.mutation.SkillIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "TeamGroupSkill.skill"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *TeamGroupSkillUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *TeamGroupSkillUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *TeamGroupSkillUpdateOne) sqlSave(ctx context.Context) (_node *TeamGroupSkill, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(teamgroupskill.Table, teamgroupskill.Columns, sqlgraph.NewFieldSpec(teamgroupskill.FieldID, field.TypeUUID))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "TeamGroupSkill.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, teamgroupskill.FieldID)
for _, f := range fields {
if !teamgroupskill.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != teamgroupskill.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(teamgroupskill.FieldCreatedAt, field.TypeTime, value)
}
if _u.mutation.GroupCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamgroupskill.GroupTable,
Columns: []string{teamgroupskill.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamgroupskill.GroupTable,
Columns: []string{teamgroupskill.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SkillCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamgroupskill.SkillTable,
Columns: []string{teamgroupskill.SkillColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SkillIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamgroupskill.SkillTable,
Columns: []string{teamgroupskill.SkillColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
_node = &TeamGroupSkill{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{teamgroupskill.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+175
View File
@@ -0,0 +1,175 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/google/uuid"
)
// TeamSkill is the model entity for the TeamSkill schema.
type TeamSkill struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// TeamID holds the value of the "team_id" field.
TeamID uuid.UUID `json:"team_id,omitempty"`
// SkillID holds the value of the "skill_id" field.
SkillID uuid.UUID `json:"skill_id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the TeamSkillQuery when eager-loading is set.
Edges TeamSkillEdges `json:"edges"`
selectValues sql.SelectValues
}
// TeamSkillEdges holds the relations/edges for other nodes in the graph.
type TeamSkillEdges struct {
// Team holds the value of the team edge.
Team *Team `json:"team,omitempty"`
// Skill holds the value of the skill edge.
Skill *Skill `json:"skill,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// TeamOrErr returns the Team value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TeamSkillEdges) TeamOrErr() (*Team, error) {
if e.Team != nil {
return e.Team, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: team.Label}
}
return nil, &NotLoadedError{edge: "team"}
}
// SkillOrErr returns the Skill value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TeamSkillEdges) SkillOrErr() (*Skill, error) {
if e.Skill != nil {
return e.Skill, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: skill.Label}
}
return nil, &NotLoadedError{edge: "skill"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*TeamSkill) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case teamskill.FieldCreatedAt:
values[i] = new(sql.NullTime)
case teamskill.FieldID, teamskill.FieldTeamID, teamskill.FieldSkillID:
values[i] = new(uuid.UUID)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the TeamSkill fields.
func (_m *TeamSkill) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case teamskill.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
_m.ID = *value
}
case teamskill.FieldTeamID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field team_id", values[i])
} else if value != nil {
_m.TeamID = *value
}
case teamskill.FieldSkillID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field skill_id", values[i])
} else if value != nil {
_m.SkillID = *value
}
case teamskill.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the TeamSkill.
// This includes values selected through modifiers, order, etc.
func (_m *TeamSkill) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryTeam queries the "team" edge of the TeamSkill entity.
func (_m *TeamSkill) QueryTeam() *TeamQuery {
return NewTeamSkillClient(_m.config).QueryTeam(_m)
}
// QuerySkill queries the "skill" edge of the TeamSkill entity.
func (_m *TeamSkill) QuerySkill() *SkillQuery {
return NewTeamSkillClient(_m.config).QuerySkill(_m)
}
// Update returns a builder for updating this TeamSkill.
// Note that you need to call TeamSkill.Unwrap() before calling this method if this TeamSkill
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *TeamSkill) Update() *TeamSkillUpdateOne {
return NewTeamSkillClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the TeamSkill entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *TeamSkill) Unwrap() *TeamSkill {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("db: TeamSkill is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *TeamSkill) String() string {
var builder strings.Builder
builder.WriteString("TeamSkill(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("team_id=")
builder.WriteString(fmt.Sprintf("%v", _m.TeamID))
builder.WriteString(", ")
builder.WriteString("skill_id=")
builder.WriteString(fmt.Sprintf("%v", _m.SkillID))
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// TeamSkills is a parsable slice of TeamSkill.
type TeamSkills []*TeamSkill
+117
View File
@@ -0,0 +1,117 @@
// Code generated by ent, DO NOT EDIT.
package teamskill
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the teamskill type in the database.
Label = "team_skill"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldTeamID holds the string denoting the team_id field in the database.
FieldTeamID = "team_id"
// FieldSkillID holds the string denoting the skill_id field in the database.
FieldSkillID = "skill_id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// EdgeTeam holds the string denoting the team edge name in mutations.
EdgeTeam = "team"
// EdgeSkill holds the string denoting the skill edge name in mutations.
EdgeSkill = "skill"
// Table holds the table name of the teamskill in the database.
Table = "team_skills"
// TeamTable is the table that holds the team relation/edge.
TeamTable = "team_skills"
// TeamInverseTable is the table name for the Team entity.
// It exists in this package in order to avoid circular dependency with the "team" package.
TeamInverseTable = "teams"
// TeamColumn is the table column denoting the team relation/edge.
TeamColumn = "team_id"
// SkillTable is the table that holds the skill relation/edge.
SkillTable = "team_skills"
// SkillInverseTable is the table name for the Skill entity.
// It exists in this package in order to avoid circular dependency with the "skill" package.
SkillInverseTable = "skills"
// SkillColumn is the table column denoting the skill relation/edge.
SkillColumn = "skill_id"
)
// Columns holds all SQL columns for teamskill fields.
var Columns = []string{
FieldID,
FieldTeamID,
FieldSkillID,
FieldCreatedAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
)
// OrderOption defines the ordering options for the TeamSkill queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByTeamID orders the results by the team_id field.
func ByTeamID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTeamID, opts...).ToFunc()
}
// BySkillID orders the results by the skill_id field.
func BySkillID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSkillID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByTeamField orders the results by team field.
func ByTeamField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newTeamStep(), sql.OrderByField(field, opts...))
}
}
// BySkillField orders the results by skill field.
func BySkillField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newSkillStep(), sql.OrderByField(field, opts...))
}
}
func newTeamStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(TeamInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, TeamTable, TeamColumn),
)
}
func newSkillStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(SkillInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, SkillTable, SkillColumn),
)
}
+213
View File
@@ -0,0 +1,213 @@
// Code generated by ent, DO NOT EDIT.
package teamskill
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/google/uuid"
)
// ID filters vertices based on their ID field.
func ID(id uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldLTE(FieldID, id))
}
// TeamID applies equality check predicate on the "team_id" field. It's identical to TeamIDEQ.
func TeamID(v uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldEQ(FieldTeamID, v))
}
// SkillID applies equality check predicate on the "skill_id" field. It's identical to SkillIDEQ.
func SkillID(v uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldEQ(FieldSkillID, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldEQ(FieldCreatedAt, v))
}
// TeamIDEQ applies the EQ predicate on the "team_id" field.
func TeamIDEQ(v uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldEQ(FieldTeamID, v))
}
// TeamIDNEQ applies the NEQ predicate on the "team_id" field.
func TeamIDNEQ(v uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldNEQ(FieldTeamID, v))
}
// TeamIDIn applies the In predicate on the "team_id" field.
func TeamIDIn(vs ...uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldIn(FieldTeamID, vs...))
}
// TeamIDNotIn applies the NotIn predicate on the "team_id" field.
func TeamIDNotIn(vs ...uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldNotIn(FieldTeamID, vs...))
}
// SkillIDEQ applies the EQ predicate on the "skill_id" field.
func SkillIDEQ(v uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldEQ(FieldSkillID, v))
}
// SkillIDNEQ applies the NEQ predicate on the "skill_id" field.
func SkillIDNEQ(v uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldNEQ(FieldSkillID, v))
}
// SkillIDIn applies the In predicate on the "skill_id" field.
func SkillIDIn(vs ...uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldIn(FieldSkillID, vs...))
}
// SkillIDNotIn applies the NotIn predicate on the "skill_id" field.
func SkillIDNotIn(vs ...uuid.UUID) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldNotIn(FieldSkillID, vs...))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.TeamSkill {
return predicate.TeamSkill(sql.FieldLTE(FieldCreatedAt, v))
}
// HasTeam applies the HasEdge predicate on the "team" edge.
func HasTeam() predicate.TeamSkill {
return predicate.TeamSkill(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, TeamTable, TeamColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasTeamWith applies the HasEdge predicate on the "team" edge with a given conditions (other predicates).
func HasTeamWith(preds ...predicate.Team) predicate.TeamSkill {
return predicate.TeamSkill(func(s *sql.Selector) {
step := newTeamStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasSkill applies the HasEdge predicate on the "skill" edge.
func HasSkill() predicate.TeamSkill {
return predicate.TeamSkill(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, SkillTable, SkillColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasSkillWith applies the HasEdge predicate on the "skill" edge with a given conditions (other predicates).
func HasSkillWith(preds ...predicate.Skill) predicate.TeamSkill {
return predicate.TeamSkill(func(s *sql.Selector) {
step := newSkillStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.TeamSkill) predicate.TeamSkill {
return predicate.TeamSkill(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.TeamSkill) predicate.TeamSkill {
return predicate.TeamSkill(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.TeamSkill) predicate.TeamSkill {
return predicate.TeamSkill(sql.NotPredicates(p))
}
+659
View File
@@ -0,0 +1,659 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/google/uuid"
)
// TeamSkillCreate is the builder for creating a TeamSkill entity.
type TeamSkillCreate struct {
config
mutation *TeamSkillMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetTeamID sets the "team_id" field.
func (_c *TeamSkillCreate) SetTeamID(v uuid.UUID) *TeamSkillCreate {
_c.mutation.SetTeamID(v)
return _c
}
// SetSkillID sets the "skill_id" field.
func (_c *TeamSkillCreate) SetSkillID(v uuid.UUID) *TeamSkillCreate {
_c.mutation.SetSkillID(v)
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *TeamSkillCreate) SetCreatedAt(v time.Time) *TeamSkillCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *TeamSkillCreate) SetNillableCreatedAt(v *time.Time) *TeamSkillCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *TeamSkillCreate) SetID(v uuid.UUID) *TeamSkillCreate {
_c.mutation.SetID(v)
return _c
}
// SetTeam sets the "team" edge to the Team entity.
func (_c *TeamSkillCreate) SetTeam(v *Team) *TeamSkillCreate {
return _c.SetTeamID(v.ID)
}
// SetSkill sets the "skill" edge to the Skill entity.
func (_c *TeamSkillCreate) SetSkill(v *Skill) *TeamSkillCreate {
return _c.SetSkillID(v.ID)
}
// Mutation returns the TeamSkillMutation object of the builder.
func (_c *TeamSkillCreate) Mutation() *TeamSkillMutation {
return _c.mutation
}
// Save creates the TeamSkill in the database.
func (_c *TeamSkillCreate) Save(ctx context.Context) (*TeamSkill, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *TeamSkillCreate) SaveX(ctx context.Context) *TeamSkill {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *TeamSkillCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *TeamSkillCreate) 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 *TeamSkillCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := teamskill.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *TeamSkillCreate) check() error {
if _, ok := _c.mutation.TeamID(); !ok {
return &ValidationError{Name: "team_id", err: errors.New(`db: missing required field "TeamSkill.team_id"`)}
}
if _, ok := _c.mutation.SkillID(); !ok {
return &ValidationError{Name: "skill_id", err: errors.New(`db: missing required field "TeamSkill.skill_id"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "TeamSkill.created_at"`)}
}
if len(_c.mutation.TeamIDs()) == 0 {
return &ValidationError{Name: "team", err: errors.New(`db: missing required edge "TeamSkill.team"`)}
}
if len(_c.mutation.SkillIDs()) == 0 {
return &ValidationError{Name: "skill", err: errors.New(`db: missing required edge "TeamSkill.skill"`)}
}
return nil
}
func (_c *TeamSkillCreate) sqlSave(ctx context.Context) (*TeamSkill, 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 *TeamSkillCreate) createSpec() (*TeamSkill, *sqlgraph.CreateSpec) {
var (
_node = &TeamSkill{config: _c.config}
_spec = sqlgraph.NewCreateSpec(teamskill.Table, sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID))
)
_spec.OnConflict = _c.conflict
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = &id
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(teamskill.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if nodes := _c.mutation.TeamIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamskill.TeamTable,
Columns: []string{teamskill.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.SkillIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamskill.SkillTable,
Columns: []string{teamskill.SkillColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.SkillID = 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.TeamSkill.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.TeamSkillUpsert) {
// SetTeamID(v+v).
// }).
// Exec(ctx)
func (_c *TeamSkillCreate) OnConflict(opts ...sql.ConflictOption) *TeamSkillUpsertOne {
_c.conflict = opts
return &TeamSkillUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.TeamSkill.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *TeamSkillCreate) OnConflictColumns(columns ...string) *TeamSkillUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &TeamSkillUpsertOne{
create: _c,
}
}
type (
// TeamSkillUpsertOne is the builder for "upsert"-ing
// one TeamSkill node.
TeamSkillUpsertOne struct {
create *TeamSkillCreate
}
// TeamSkillUpsert is the "OnConflict" setter.
TeamSkillUpsert struct {
*sql.UpdateSet
}
)
// SetTeamID sets the "team_id" field.
func (u *TeamSkillUpsert) SetTeamID(v uuid.UUID) *TeamSkillUpsert {
u.Set(teamskill.FieldTeamID, v)
return u
}
// UpdateTeamID sets the "team_id" field to the value that was provided on create.
func (u *TeamSkillUpsert) UpdateTeamID() *TeamSkillUpsert {
u.SetExcluded(teamskill.FieldTeamID)
return u
}
// SetSkillID sets the "skill_id" field.
func (u *TeamSkillUpsert) SetSkillID(v uuid.UUID) *TeamSkillUpsert {
u.Set(teamskill.FieldSkillID, v)
return u
}
// UpdateSkillID sets the "skill_id" field to the value that was provided on create.
func (u *TeamSkillUpsert) UpdateSkillID() *TeamSkillUpsert {
u.SetExcluded(teamskill.FieldSkillID)
return u
}
// SetCreatedAt sets the "created_at" field.
func (u *TeamSkillUpsert) SetCreatedAt(v time.Time) *TeamSkillUpsert {
u.Set(teamskill.FieldCreatedAt, v)
return u
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *TeamSkillUpsert) UpdateCreatedAt() *TeamSkillUpsert {
u.SetExcluded(teamskill.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.TeamSkill.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(teamskill.FieldID)
// }),
// ).
// Exec(ctx)
func (u *TeamSkillUpsertOne) UpdateNewValues() *TeamSkillUpsertOne {
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(teamskill.FieldID)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.TeamSkill.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *TeamSkillUpsertOne) Ignore() *TeamSkillUpsertOne {
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 *TeamSkillUpsertOne) DoNothing() *TeamSkillUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the TeamSkillCreate.OnConflict
// documentation for more info.
func (u *TeamSkillUpsertOne) Update(set func(*TeamSkillUpsert)) *TeamSkillUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&TeamSkillUpsert{UpdateSet: update})
}))
return u
}
// SetTeamID sets the "team_id" field.
func (u *TeamSkillUpsertOne) SetTeamID(v uuid.UUID) *TeamSkillUpsertOne {
return u.Update(func(s *TeamSkillUpsert) {
s.SetTeamID(v)
})
}
// UpdateTeamID sets the "team_id" field to the value that was provided on create.
func (u *TeamSkillUpsertOne) UpdateTeamID() *TeamSkillUpsertOne {
return u.Update(func(s *TeamSkillUpsert) {
s.UpdateTeamID()
})
}
// SetSkillID sets the "skill_id" field.
func (u *TeamSkillUpsertOne) SetSkillID(v uuid.UUID) *TeamSkillUpsertOne {
return u.Update(func(s *TeamSkillUpsert) {
s.SetSkillID(v)
})
}
// UpdateSkillID sets the "skill_id" field to the value that was provided on create.
func (u *TeamSkillUpsertOne) UpdateSkillID() *TeamSkillUpsertOne {
return u.Update(func(s *TeamSkillUpsert) {
s.UpdateSkillID()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *TeamSkillUpsertOne) SetCreatedAt(v time.Time) *TeamSkillUpsertOne {
return u.Update(func(s *TeamSkillUpsert) {
s.SetCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *TeamSkillUpsertOne) UpdateCreatedAt() *TeamSkillUpsertOne {
return u.Update(func(s *TeamSkillUpsert) {
s.UpdateCreatedAt()
})
}
// Exec executes the query.
func (u *TeamSkillUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("db: missing options for TeamSkillCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *TeamSkillUpsertOne) 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 *TeamSkillUpsertOne) 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: TeamSkillUpsertOne.ID is not supported by MySQL driver. Use TeamSkillUpsertOne.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 *TeamSkillUpsertOne) IDX(ctx context.Context) uuid.UUID {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// TeamSkillCreateBulk is the builder for creating many TeamSkill entities in bulk.
type TeamSkillCreateBulk struct {
config
err error
builders []*TeamSkillCreate
conflict []sql.ConflictOption
}
// Save creates the TeamSkill entities in the database.
func (_c *TeamSkillCreateBulk) Save(ctx context.Context) ([]*TeamSkill, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*TeamSkill, 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.(*TeamSkillMutation)
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 *TeamSkillCreateBulk) SaveX(ctx context.Context) []*TeamSkill {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *TeamSkillCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *TeamSkillCreateBulk) 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.TeamSkill.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.TeamSkillUpsert) {
// SetTeamID(v+v).
// }).
// Exec(ctx)
func (_c *TeamSkillCreateBulk) OnConflict(opts ...sql.ConflictOption) *TeamSkillUpsertBulk {
_c.conflict = opts
return &TeamSkillUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.TeamSkill.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *TeamSkillCreateBulk) OnConflictColumns(columns ...string) *TeamSkillUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &TeamSkillUpsertBulk{
create: _c,
}
}
// TeamSkillUpsertBulk is the builder for "upsert"-ing
// a bulk of TeamSkill nodes.
type TeamSkillUpsertBulk struct {
create *TeamSkillCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.TeamSkill.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(teamskill.FieldID)
// }),
// ).
// Exec(ctx)
func (u *TeamSkillUpsertBulk) UpdateNewValues() *TeamSkillUpsertBulk {
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(teamskill.FieldID)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.TeamSkill.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *TeamSkillUpsertBulk) Ignore() *TeamSkillUpsertBulk {
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 *TeamSkillUpsertBulk) DoNothing() *TeamSkillUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the TeamSkillCreateBulk.OnConflict
// documentation for more info.
func (u *TeamSkillUpsertBulk) Update(set func(*TeamSkillUpsert)) *TeamSkillUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&TeamSkillUpsert{UpdateSet: update})
}))
return u
}
// SetTeamID sets the "team_id" field.
func (u *TeamSkillUpsertBulk) SetTeamID(v uuid.UUID) *TeamSkillUpsertBulk {
return u.Update(func(s *TeamSkillUpsert) {
s.SetTeamID(v)
})
}
// UpdateTeamID sets the "team_id" field to the value that was provided on create.
func (u *TeamSkillUpsertBulk) UpdateTeamID() *TeamSkillUpsertBulk {
return u.Update(func(s *TeamSkillUpsert) {
s.UpdateTeamID()
})
}
// SetSkillID sets the "skill_id" field.
func (u *TeamSkillUpsertBulk) SetSkillID(v uuid.UUID) *TeamSkillUpsertBulk {
return u.Update(func(s *TeamSkillUpsert) {
s.SetSkillID(v)
})
}
// UpdateSkillID sets the "skill_id" field to the value that was provided on create.
func (u *TeamSkillUpsertBulk) UpdateSkillID() *TeamSkillUpsertBulk {
return u.Update(func(s *TeamSkillUpsert) {
s.UpdateSkillID()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *TeamSkillUpsertBulk) SetCreatedAt(v time.Time) *TeamSkillUpsertBulk {
return u.Update(func(s *TeamSkillUpsert) {
s.SetCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *TeamSkillUpsertBulk) UpdateCreatedAt() *TeamSkillUpsertBulk {
return u.Update(func(s *TeamSkillUpsert) {
s.UpdateCreatedAt()
})
}
// Exec executes the query.
func (u *TeamSkillUpsertBulk) 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 TeamSkillCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("db: missing options for TeamSkillCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *TeamSkillUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
+88
View File
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
)
// TeamSkillDelete is the builder for deleting a TeamSkill entity.
type TeamSkillDelete struct {
config
hooks []Hook
mutation *TeamSkillMutation
}
// Where appends a list predicates to the TeamSkillDelete builder.
func (_d *TeamSkillDelete) Where(ps ...predicate.TeamSkill) *TeamSkillDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *TeamSkillDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *TeamSkillDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *TeamSkillDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(teamskill.Table, sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// TeamSkillDeleteOne is the builder for deleting a single TeamSkill entity.
type TeamSkillDeleteOne struct {
_d *TeamSkillDelete
}
// Where appends a list predicates to the TeamSkillDelete builder.
func (_d *TeamSkillDeleteOne) Where(ps ...predicate.TeamSkill) *TeamSkillDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *TeamSkillDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{teamskill.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *TeamSkillDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
+732
View File
@@ -0,0 +1,732 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/google/uuid"
)
// TeamSkillQuery is the builder for querying TeamSkill entities.
type TeamSkillQuery struct {
config
ctx *QueryContext
order []teamskill.OrderOption
inters []Interceptor
predicates []predicate.TeamSkill
withTeam *TeamQuery
withSkill *SkillQuery
modifiers []func(*sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the TeamSkillQuery builder.
func (_q *TeamSkillQuery) Where(ps ...predicate.TeamSkill) *TeamSkillQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *TeamSkillQuery) Limit(limit int) *TeamSkillQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *TeamSkillQuery) Offset(offset int) *TeamSkillQuery {
_q.ctx.Offset = &offset
return _q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (_q *TeamSkillQuery) Unique(unique bool) *TeamSkillQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *TeamSkillQuery) Order(o ...teamskill.OrderOption) *TeamSkillQuery {
_q.order = append(_q.order, o...)
return _q
}
// QueryTeam chains the current query on the "team" edge.
func (_q *TeamSkillQuery) QueryTeam() *TeamQuery {
query := (&TeamClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(teamskill.Table, teamskill.FieldID, selector),
sqlgraph.To(team.Table, team.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, teamskill.TeamTable, teamskill.TeamColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QuerySkill chains the current query on the "skill" edge.
func (_q *TeamSkillQuery) QuerySkill() *SkillQuery {
query := (&SkillClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(teamskill.Table, teamskill.FieldID, selector),
sqlgraph.To(skill.Table, skill.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, teamskill.SkillTable, teamskill.SkillColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first TeamSkill entity from the query.
// Returns a *NotFoundError when no TeamSkill was found.
func (_q *TeamSkillQuery) First(ctx context.Context) (*TeamSkill, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{teamskill.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *TeamSkillQuery) FirstX(ctx context.Context) *TeamSkill {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first TeamSkill ID from the query.
// Returns a *NotFoundError when no TeamSkill ID was found.
func (_q *TeamSkillQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{teamskill.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *TeamSkillQuery) FirstIDX(ctx context.Context) uuid.UUID {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single TeamSkill entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one TeamSkill entity is found.
// Returns a *NotFoundError when no TeamSkill entities are found.
func (_q *TeamSkillQuery) Only(ctx context.Context) (*TeamSkill, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{teamskill.Label}
default:
return nil, &NotSingularError{teamskill.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *TeamSkillQuery) OnlyX(ctx context.Context) *TeamSkill {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only TeamSkill ID in the query.
// Returns a *NotSingularError when more than one TeamSkill ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *TeamSkillQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{teamskill.Label}
default:
err = &NotSingularError{teamskill.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *TeamSkillQuery) OnlyIDX(ctx context.Context) uuid.UUID {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of TeamSkills.
func (_q *TeamSkillQuery) All(ctx context.Context) ([]*TeamSkill, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*TeamSkill, *TeamSkillQuery]()
return withInterceptors[[]*TeamSkill](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *TeamSkillQuery) AllX(ctx context.Context) []*TeamSkill {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of TeamSkill IDs.
func (_q *TeamSkillQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(teamskill.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *TeamSkillQuery) IDsX(ctx context.Context) []uuid.UUID {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *TeamSkillQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*TeamSkillQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *TeamSkillQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *TeamSkillQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("db: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *TeamSkillQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the TeamSkillQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *TeamSkillQuery) Clone() *TeamSkillQuery {
if _q == nil {
return nil
}
return &TeamSkillQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]teamskill.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.TeamSkill{}, _q.predicates...),
withTeam: _q.withTeam.Clone(),
withSkill: _q.withSkill.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
modifiers: append([]func(*sql.Selector){}, _q.modifiers...),
}
}
// WithTeam tells the query-builder to eager-load the nodes that are connected to
// the "team" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *TeamSkillQuery) WithTeam(opts ...func(*TeamQuery)) *TeamSkillQuery {
query := (&TeamClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withTeam = query
return _q
}
// WithSkill tells the query-builder to eager-load the nodes that are connected to
// the "skill" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *TeamSkillQuery) WithSkill(opts ...func(*SkillQuery)) *TeamSkillQuery {
query := (&SkillClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withSkill = query
return _q
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// TeamID uuid.UUID `json:"team_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.TeamSkill.Query().
// GroupBy(teamskill.FieldTeamID).
// Aggregate(db.Count()).
// Scan(ctx, &v)
func (_q *TeamSkillQuery) GroupBy(field string, fields ...string) *TeamSkillGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &TeamSkillGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = teamskill.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// TeamID uuid.UUID `json:"team_id,omitempty"`
// }
//
// client.TeamSkill.Query().
// Select(teamskill.FieldTeamID).
// Scan(ctx, &v)
func (_q *TeamSkillQuery) Select(fields ...string) *TeamSkillSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &TeamSkillSelect{TeamSkillQuery: _q}
sbuild.label = teamskill.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a TeamSkillSelect configured with the given aggregations.
func (_q *TeamSkillQuery) Aggregate(fns ...AggregateFunc) *TeamSkillSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *TeamSkillQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !teamskill.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *TeamSkillQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TeamSkill, error) {
var (
nodes = []*TeamSkill{}
_spec = _q.querySpec()
loadedTypes = [2]bool{
_q.withTeam != nil,
_q.withSkill != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*TeamSkill).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &TeamSkill{config: _q.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
if len(_q.modifiers) > 0 {
_spec.Modifiers = _q.modifiers
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := _q.withTeam; query != nil {
if err := _q.loadTeam(ctx, query, nodes, nil,
func(n *TeamSkill, e *Team) { n.Edges.Team = e }); err != nil {
return nil, err
}
}
if query := _q.withSkill; query != nil {
if err := _q.loadSkill(ctx, query, nodes, nil,
func(n *TeamSkill, e *Skill) { n.Edges.Skill = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (_q *TeamSkillQuery) loadTeam(ctx context.Context, query *TeamQuery, nodes []*TeamSkill, init func(*TeamSkill), assign func(*TeamSkill, *Team)) error {
ids := make([]uuid.UUID, 0, len(nodes))
nodeids := make(map[uuid.UUID][]*TeamSkill)
for i := range nodes {
fk := nodes[i].TeamID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(team.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "team_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *TeamSkillQuery) loadSkill(ctx context.Context, query *SkillQuery, nodes []*TeamSkill, init func(*TeamSkill), assign func(*TeamSkill, *Skill)) error {
ids := make([]uuid.UUID, 0, len(nodes))
nodeids := make(map[uuid.UUID][]*TeamSkill)
for i := range nodes {
fk := nodes[i].SkillID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(skill.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "skill_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *TeamSkillQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
if len(_q.modifiers) > 0 {
_spec.Modifiers = _q.modifiers
}
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *TeamSkillQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(teamskill.Table, teamskill.Columns, sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, teamskill.FieldID)
for i := range fields {
if fields[i] != teamskill.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
if _q.withTeam != nil {
_spec.Node.AddColumnOnce(teamskill.FieldTeamID)
}
if _q.withSkill != nil {
_spec.Node.AddColumnOnce(teamskill.FieldSkillID)
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *TeamSkillQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(teamskill.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = teamskill.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, m := range _q.modifiers {
m(selector)
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func (_q *TeamSkillQuery) ForUpdate(opts ...sql.LockOption) *TeamSkillQuery {
if _q.driver.Dialect() == dialect.Postgres {
_q.Unique(false)
}
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
s.ForUpdate(opts...)
})
return _q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func (_q *TeamSkillQuery) ForShare(opts ...sql.LockOption) *TeamSkillQuery {
if _q.driver.Dialect() == dialect.Postgres {
_q.Unique(false)
}
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
s.ForShare(opts...)
})
return _q
}
// Modify adds a query modifier for attaching custom logic to queries.
func (_q *TeamSkillQuery) Modify(modifiers ...func(s *sql.Selector)) *TeamSkillSelect {
_q.modifiers = append(_q.modifiers, modifiers...)
return _q.Select()
}
// TeamSkillGroupBy is the group-by builder for TeamSkill entities.
type TeamSkillGroupBy struct {
selector
build *TeamSkillQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *TeamSkillGroupBy) Aggregate(fns ...AggregateFunc) *TeamSkillGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *TeamSkillGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*TeamSkillQuery, *TeamSkillGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *TeamSkillGroupBy) sqlScan(ctx context.Context, root *TeamSkillQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// TeamSkillSelect is the builder for selecting fields of TeamSkill entities.
type TeamSkillSelect struct {
*TeamSkillQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *TeamSkillSelect) Aggregate(fns ...AggregateFunc) *TeamSkillSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *TeamSkillSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*TeamSkillQuery, *TeamSkillSelect](ctx, _s.TeamSkillQuery, _s, _s.inters, v)
}
func (_s *TeamSkillSelect) sqlScan(ctx context.Context, root *TeamSkillQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// Modify adds a query modifier for attaching custom logic to queries.
func (_s *TeamSkillSelect) Modify(modifiers ...func(s *sql.Selector)) *TeamSkillSelect {
_s.modifiers = append(_s.modifiers, modifiers...)
return _s
}
+473
View File
@@ -0,0 +1,473 @@
// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/team"
"github.com/chaitin/MonkeyCode/backend/db/teamskill"
"github.com/google/uuid"
)
// TeamSkillUpdate is the builder for updating TeamSkill entities.
type TeamSkillUpdate struct {
config
hooks []Hook
mutation *TeamSkillMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the TeamSkillUpdate builder.
func (_u *TeamSkillUpdate) Where(ps ...predicate.TeamSkill) *TeamSkillUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetTeamID sets the "team_id" field.
func (_u *TeamSkillUpdate) SetTeamID(v uuid.UUID) *TeamSkillUpdate {
_u.mutation.SetTeamID(v)
return _u
}
// SetNillableTeamID sets the "team_id" field if the given value is not nil.
func (_u *TeamSkillUpdate) SetNillableTeamID(v *uuid.UUID) *TeamSkillUpdate {
if v != nil {
_u.SetTeamID(*v)
}
return _u
}
// SetSkillID sets the "skill_id" field.
func (_u *TeamSkillUpdate) SetSkillID(v uuid.UUID) *TeamSkillUpdate {
_u.mutation.SetSkillID(v)
return _u
}
// SetNillableSkillID sets the "skill_id" field if the given value is not nil.
func (_u *TeamSkillUpdate) SetNillableSkillID(v *uuid.UUID) *TeamSkillUpdate {
if v != nil {
_u.SetSkillID(*v)
}
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *TeamSkillUpdate) SetCreatedAt(v time.Time) *TeamSkillUpdate {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *TeamSkillUpdate) SetNillableCreatedAt(v *time.Time) *TeamSkillUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetTeam sets the "team" edge to the Team entity.
func (_u *TeamSkillUpdate) SetTeam(v *Team) *TeamSkillUpdate {
return _u.SetTeamID(v.ID)
}
// SetSkill sets the "skill" edge to the Skill entity.
func (_u *TeamSkillUpdate) SetSkill(v *Skill) *TeamSkillUpdate {
return _u.SetSkillID(v.ID)
}
// Mutation returns the TeamSkillMutation object of the builder.
func (_u *TeamSkillUpdate) Mutation() *TeamSkillMutation {
return _u.mutation
}
// ClearTeam clears the "team" edge to the Team entity.
func (_u *TeamSkillUpdate) ClearTeam() *TeamSkillUpdate {
_u.mutation.ClearTeam()
return _u
}
// ClearSkill clears the "skill" edge to the Skill entity.
func (_u *TeamSkillUpdate) ClearSkill() *TeamSkillUpdate {
_u.mutation.ClearSkill()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *TeamSkillUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *TeamSkillUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *TeamSkillUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *TeamSkillUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *TeamSkillUpdate) check() error {
if _u.mutation.TeamCleared() && len(_u.mutation.TeamIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "TeamSkill.team"`)
}
if _u.mutation.SkillCleared() && len(_u.mutation.SkillIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "TeamSkill.skill"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *TeamSkillUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *TeamSkillUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *TeamSkillUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(teamskill.Table, teamskill.Columns, sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(teamskill.FieldCreatedAt, field.TypeTime, value)
}
if _u.mutation.TeamCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamskill.TeamTable,
Columns: []string{teamskill.TeamColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.TeamIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamskill.TeamTable,
Columns: []string{teamskill.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)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SkillCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamskill.SkillTable,
Columns: []string{teamskill.SkillColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SkillIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamskill.SkillTable,
Columns: []string{teamskill.SkillColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{teamskill.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// TeamSkillUpdateOne is the builder for updating a single TeamSkill entity.
type TeamSkillUpdateOne struct {
config
fields []string
hooks []Hook
mutation *TeamSkillMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetTeamID sets the "team_id" field.
func (_u *TeamSkillUpdateOne) SetTeamID(v uuid.UUID) *TeamSkillUpdateOne {
_u.mutation.SetTeamID(v)
return _u
}
// SetNillableTeamID sets the "team_id" field if the given value is not nil.
func (_u *TeamSkillUpdateOne) SetNillableTeamID(v *uuid.UUID) *TeamSkillUpdateOne {
if v != nil {
_u.SetTeamID(*v)
}
return _u
}
// SetSkillID sets the "skill_id" field.
func (_u *TeamSkillUpdateOne) SetSkillID(v uuid.UUID) *TeamSkillUpdateOne {
_u.mutation.SetSkillID(v)
return _u
}
// SetNillableSkillID sets the "skill_id" field if the given value is not nil.
func (_u *TeamSkillUpdateOne) SetNillableSkillID(v *uuid.UUID) *TeamSkillUpdateOne {
if v != nil {
_u.SetSkillID(*v)
}
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *TeamSkillUpdateOne) SetCreatedAt(v time.Time) *TeamSkillUpdateOne {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *TeamSkillUpdateOne) SetNillableCreatedAt(v *time.Time) *TeamSkillUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetTeam sets the "team" edge to the Team entity.
func (_u *TeamSkillUpdateOne) SetTeam(v *Team) *TeamSkillUpdateOne {
return _u.SetTeamID(v.ID)
}
// SetSkill sets the "skill" edge to the Skill entity.
func (_u *TeamSkillUpdateOne) SetSkill(v *Skill) *TeamSkillUpdateOne {
return _u.SetSkillID(v.ID)
}
// Mutation returns the TeamSkillMutation object of the builder.
func (_u *TeamSkillUpdateOne) Mutation() *TeamSkillMutation {
return _u.mutation
}
// ClearTeam clears the "team" edge to the Team entity.
func (_u *TeamSkillUpdateOne) ClearTeam() *TeamSkillUpdateOne {
_u.mutation.ClearTeam()
return _u
}
// ClearSkill clears the "skill" edge to the Skill entity.
func (_u *TeamSkillUpdateOne) ClearSkill() *TeamSkillUpdateOne {
_u.mutation.ClearSkill()
return _u
}
// Where appends a list predicates to the TeamSkillUpdate builder.
func (_u *TeamSkillUpdateOne) Where(ps ...predicate.TeamSkill) *TeamSkillUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *TeamSkillUpdateOne) Select(field string, fields ...string) *TeamSkillUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated TeamSkill entity.
func (_u *TeamSkillUpdateOne) Save(ctx context.Context) (*TeamSkill, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *TeamSkillUpdateOne) SaveX(ctx context.Context) *TeamSkill {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *TeamSkillUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *TeamSkillUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *TeamSkillUpdateOne) check() error {
if _u.mutation.TeamCleared() && len(_u.mutation.TeamIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "TeamSkill.team"`)
}
if _u.mutation.SkillCleared() && len(_u.mutation.SkillIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "TeamSkill.skill"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *TeamSkillUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *TeamSkillUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *TeamSkillUpdateOne) sqlSave(ctx context.Context) (_node *TeamSkill, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(teamskill.Table, teamskill.Columns, sqlgraph.NewFieldSpec(teamskill.FieldID, field.TypeUUID))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "TeamSkill.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, teamskill.FieldID)
for _, f := range fields {
if !teamskill.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != teamskill.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(teamskill.FieldCreatedAt, field.TypeTime, value)
}
if _u.mutation.TeamCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamskill.TeamTable,
Columns: []string{teamskill.TeamColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.TeamIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamskill.TeamTable,
Columns: []string{teamskill.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)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SkillCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamskill.SkillTable,
Columns: []string{teamskill.SkillColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SkillIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: false,
Table: teamskill.SkillTable,
Columns: []string{teamskill.SkillColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
_node = &TeamSkill{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{teamskill.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+9
View File
@@ -60,6 +60,8 @@ type Tx struct {
ProjectIssueComment *ProjectIssueCommentClient
// ProjectTask is the client for interacting with the ProjectTask builders.
ProjectTask *ProjectTaskClient
// Skill is the client for interacting with the Skill builders.
Skill *SkillClient
// Task is the client for interacting with the Task builders.
Task *TaskClient
// TaskModelSwitch is the client for interacting with the TaskModelSwitch builders.
@@ -80,6 +82,8 @@ type Tx struct {
TeamGroupMember *TeamGroupMemberClient
// TeamGroupModel is the client for interacting with the TeamGroupModel builders.
TeamGroupModel *TeamGroupModelClient
// TeamGroupSkill is the client for interacting with the TeamGroupSkill builders.
TeamGroupSkill *TeamGroupSkillClient
// TeamHost is the client for interacting with the TeamHost builders.
TeamHost *TeamHostClient
// TeamImage is the client for interacting with the TeamImage builders.
@@ -90,6 +94,8 @@ type Tx struct {
TeamModel *TeamModelClient
// TeamOIDCConfig is the client for interacting with the TeamOIDCConfig builders.
TeamOIDCConfig *TeamOIDCConfigClient
// TeamSkill is the client for interacting with the TeamSkill builders.
TeamSkill *TeamSkillClient
// User is the client for interacting with the User builders.
User *UserClient
// UserIdentity is the client for interacting with the UserIdentity builders.
@@ -250,6 +256,7 @@ func (tx *Tx) init() {
tx.ProjectIssue = NewProjectIssueClient(tx.config)
tx.ProjectIssueComment = NewProjectIssueCommentClient(tx.config)
tx.ProjectTask = NewProjectTaskClient(tx.config)
tx.Skill = NewSkillClient(tx.config)
tx.Task = NewTaskClient(tx.config)
tx.TaskModelSwitch = NewTaskModelSwitchClient(tx.config)
tx.TaskUsageStat = NewTaskUsageStatClient(tx.config)
@@ -260,11 +267,13 @@ func (tx *Tx) init() {
tx.TeamGroupImage = NewTeamGroupImageClient(tx.config)
tx.TeamGroupMember = NewTeamGroupMemberClient(tx.config)
tx.TeamGroupModel = NewTeamGroupModelClient(tx.config)
tx.TeamGroupSkill = NewTeamGroupSkillClient(tx.config)
tx.TeamHost = NewTeamHostClient(tx.config)
tx.TeamImage = NewTeamImageClient(tx.config)
tx.TeamMember = NewTeamMemberClient(tx.config)
tx.TeamModel = NewTeamModelClient(tx.config)
tx.TeamOIDCConfig = NewTeamOIDCConfigClient(tx.config)
tx.TeamSkill = NewTeamSkillClient(tx.config)
tx.User = NewUserClient(tx.config)
tx.UserIdentity = NewUserIdentityClient(tx.config)
tx.VirtualMachine = NewVirtualMachineClient(tx.config)
+32 -16
View File
@@ -62,6 +62,8 @@ type UserEdges struct {
Models []*Model `json:"models,omitempty"`
// Images holds the value of the images edge.
Images []*Image `json:"images,omitempty"`
// Skills holds the value of the skills edge.
Skills []*Skill `json:"skills,omitempty"`
// Hosts holds the value of the hosts edge.
Hosts []*Host `json:"hosts,omitempty"`
// Vms holds the value of the vms edge.
@@ -94,7 +96,7 @@ type UserEdges struct {
GitBotUsers []*GitBotUser `json:"git_bot_users,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [21]bool
loadedTypes [22]bool
}
// IdentitiesOrErr returns the Identities value or an error if the edge
@@ -151,10 +153,19 @@ func (e UserEdges) ImagesOrErr() ([]*Image, error) {
return nil, &NotLoadedError{edge: "images"}
}
// SkillsOrErr returns the Skills value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) SkillsOrErr() ([]*Skill, error) {
if e.loadedTypes[6] {
return e.Skills, nil
}
return nil, &NotLoadedError{edge: "skills"}
}
// HostsOrErr returns the Hosts value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) HostsOrErr() ([]*Host, error) {
if e.loadedTypes[6] {
if e.loadedTypes[7] {
return e.Hosts, nil
}
return nil, &NotLoadedError{edge: "hosts"}
@@ -163,7 +174,7 @@ func (e UserEdges) HostsOrErr() ([]*Host, error) {
// VmsOrErr returns the Vms value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) VmsOrErr() ([]*VirtualMachine, error) {
if e.loadedTypes[7] {
if e.loadedTypes[8] {
return e.Vms, nil
}
return nil, &NotLoadedError{edge: "vms"}
@@ -172,7 +183,7 @@ func (e UserEdges) VmsOrErr() ([]*VirtualMachine, error) {
// TasksOrErr returns the Tasks value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) TasksOrErr() ([]*Task, error) {
if e.loadedTypes[8] {
if e.loadedTypes[9] {
return e.Tasks, nil
}
return nil, &NotLoadedError{edge: "tasks"}
@@ -181,7 +192,7 @@ func (e UserEdges) TasksOrErr() ([]*Task, error) {
// TaskModelSwitchesOrErr returns the TaskModelSwitches value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) TaskModelSwitchesOrErr() ([]*TaskModelSwitch, error) {
if e.loadedTypes[9] {
if e.loadedTypes[10] {
return e.TaskModelSwitches, nil
}
return nil, &NotLoadedError{edge: "task_model_switches"}
@@ -190,7 +201,7 @@ func (e UserEdges) TaskModelSwitchesOrErr() ([]*TaskModelSwitch, error) {
// GitIdentitiesOrErr returns the GitIdentities value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) GitIdentitiesOrErr() ([]*GitIdentity, error) {
if e.loadedTypes[10] {
if e.loadedTypes[11] {
return e.GitIdentities, nil
}
return nil, &NotLoadedError{edge: "git_identities"}
@@ -199,7 +210,7 @@ func (e UserEdges) GitIdentitiesOrErr() ([]*GitIdentity, error) {
// ProjectsOrErr returns the Projects value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) ProjectsOrErr() ([]*Project, error) {
if e.loadedTypes[11] {
if e.loadedTypes[12] {
return e.Projects, nil
}
return nil, &NotLoadedError{edge: "projects"}
@@ -208,7 +219,7 @@ func (e UserEdges) ProjectsOrErr() ([]*Project, error) {
// ProjectIssuesOrErr returns the ProjectIssues value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) ProjectIssuesOrErr() ([]*ProjectIssue, error) {
if e.loadedTypes[12] {
if e.loadedTypes[13] {
return e.ProjectIssues, nil
}
return nil, &NotLoadedError{edge: "project_issues"}
@@ -217,7 +228,7 @@ func (e UserEdges) ProjectIssuesOrErr() ([]*ProjectIssue, error) {
// AssignedIssuesOrErr returns the AssignedIssues value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) AssignedIssuesOrErr() ([]*ProjectIssue, error) {
if e.loadedTypes[13] {
if e.loadedTypes[14] {
return e.AssignedIssues, nil
}
return nil, &NotLoadedError{edge: "assigned_issues"}
@@ -226,7 +237,7 @@ func (e UserEdges) AssignedIssuesOrErr() ([]*ProjectIssue, error) {
// ProjectCollaboratorsOrErr returns the ProjectCollaborators value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) ProjectCollaboratorsOrErr() ([]*ProjectCollaborator, error) {
if e.loadedTypes[14] {
if e.loadedTypes[15] {
return e.ProjectCollaborators, nil
}
return nil, &NotLoadedError{edge: "project_collaborators"}
@@ -235,7 +246,7 @@ func (e UserEdges) ProjectCollaboratorsOrErr() ([]*ProjectCollaborator, error) {
// ProjectIssueCommentsOrErr returns the ProjectIssueComments value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) ProjectIssueCommentsOrErr() ([]*ProjectIssueComment, error) {
if e.loadedTypes[15] {
if e.loadedTypes[16] {
return e.ProjectIssueComments, nil
}
return nil, &NotLoadedError{edge: "project_issue_comments"}
@@ -244,7 +255,7 @@ func (e UserEdges) ProjectIssueCommentsOrErr() ([]*ProjectIssueComment, error) {
// GitBotsOrErr returns the GitBots value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) GitBotsOrErr() ([]*GitBot, error) {
if e.loadedTypes[16] {
if e.loadedTypes[17] {
return e.GitBots, nil
}
return nil, &NotLoadedError{edge: "git_bots"}
@@ -253,7 +264,7 @@ func (e UserEdges) GitBotsOrErr() ([]*GitBot, error) {
// McpUpstreamsOrErr returns the McpUpstreams value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) McpUpstreamsOrErr() ([]*MCPUpstream, error) {
if e.loadedTypes[17] {
if e.loadedTypes[18] {
return e.McpUpstreams, nil
}
return nil, &NotLoadedError{edge: "mcp_upstreams"}
@@ -262,7 +273,7 @@ func (e UserEdges) McpUpstreamsOrErr() ([]*MCPUpstream, error) {
// TeamMembersOrErr returns the TeamMembers value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) TeamMembersOrErr() ([]*TeamMember, error) {
if e.loadedTypes[18] {
if e.loadedTypes[19] {
return e.TeamMembers, nil
}
return nil, &NotLoadedError{edge: "team_members"}
@@ -271,7 +282,7 @@ func (e UserEdges) TeamMembersOrErr() ([]*TeamMember, error) {
// TeamGroupMembersOrErr returns the TeamGroupMembers value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) TeamGroupMembersOrErr() ([]*TeamGroupMember, error) {
if e.loadedTypes[19] {
if e.loadedTypes[20] {
return e.TeamGroupMembers, nil
}
return nil, &NotLoadedError{edge: "team_group_members"}
@@ -280,7 +291,7 @@ func (e UserEdges) TeamGroupMembersOrErr() ([]*TeamGroupMember, error) {
// GitBotUsersOrErr returns the GitBotUsers value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) GitBotUsersOrErr() ([]*GitBotUser, error) {
if e.loadedTypes[20] {
if e.loadedTypes[21] {
return e.GitBotUsers, nil
}
return nil, &NotLoadedError{edge: "git_bot_users"}
@@ -433,6 +444,11 @@ func (_m *User) QueryImages() *ImageQuery {
return NewUserClient(_m.config).QueryImages(_m)
}
// QuerySkills queries the "skills" edge of the User entity.
func (_m *User) QuerySkills() *SkillQuery {
return NewUserClient(_m.config).QuerySkills(_m)
}
// QueryHosts queries the "hosts" edge of the User entity.
func (_m *User) QueryHosts() *HostQuery {
return NewUserClient(_m.config).QueryHosts(_m)
+30
View File
@@ -49,6 +49,8 @@ const (
EdgeModels = "models"
// EdgeImages holds the string denoting the images edge name in mutations.
EdgeImages = "images"
// EdgeSkills holds the string denoting the skills edge name in mutations.
EdgeSkills = "skills"
// EdgeHosts holds the string denoting the hosts edge name in mutations.
EdgeHosts = "hosts"
// EdgeVms holds the string denoting the vms edge name in mutations.
@@ -119,6 +121,13 @@ const (
ImagesInverseTable = "images"
// ImagesColumn is the table column denoting the images relation/edge.
ImagesColumn = "user_id"
// SkillsTable is the table that holds the skills relation/edge.
SkillsTable = "skills"
// SkillsInverseTable is the table name for the Skill entity.
// It exists in this package in order to avoid circular dependency with the "skill" package.
SkillsInverseTable = "skills"
// SkillsColumn is the table column denoting the skills relation/edge.
SkillsColumn = "user_id"
// HostsTable is the table that holds the hosts relation/edge.
HostsTable = "hosts"
// HostsInverseTable is the table name for the Host entity.
@@ -424,6 +433,20 @@ func ByImages(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
}
}
// BySkillsCount orders the results by skills count.
func BySkillsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newSkillsStep(), opts...)
}
}
// BySkills orders the results by skills terms.
func BySkills(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newSkillsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByHostsCount orders the results by hosts count.
func ByHostsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
@@ -675,6 +698,13 @@ func newImagesStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.O2M, false, ImagesTable, ImagesColumn),
)
}
func newSkillsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(SkillsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, SkillsTable, SkillsColumn),
)
}
func newHostsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
+23
View File
@@ -855,6 +855,29 @@ func HasImagesWith(preds ...predicate.Image) predicate.User {
})
}
// HasSkills applies the HasEdge predicate on the "skills" edge.
func HasSkills() predicate.User {
return predicate.User(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, SkillsTable, SkillsColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasSkillsWith applies the HasEdge predicate on the "skills" edge with a given conditions (other predicates).
func HasSkillsWith(preds ...predicate.Skill) predicate.User {
return predicate.User(func(s *sql.Selector) {
step := newSkillsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasHosts applies the HasEdge predicate on the "hosts" edge.
func HasHosts() predicate.User {
return predicate.User(func(s *sql.Selector) {
+32
View File
@@ -25,6 +25,7 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/projectcollaborator"
"github.com/chaitin/MonkeyCode/backend/db/projectissue"
"github.com/chaitin/MonkeyCode/backend/db/projectissuecomment"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/task"
"github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch"
"github.com/chaitin/MonkeyCode/backend/db/team"
@@ -263,6 +264,21 @@ func (_c *UserCreate) AddImages(v ...*Image) *UserCreate {
return _c.AddImageIDs(ids...)
}
// AddSkillIDs adds the "skills" edge to the Skill entity by IDs.
func (_c *UserCreate) AddSkillIDs(ids ...uuid.UUID) *UserCreate {
_c.mutation.AddSkillIDs(ids...)
return _c
}
// AddSkills adds the "skills" edges to the Skill entity.
func (_c *UserCreate) AddSkills(v ...*Skill) *UserCreate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddSkillIDs(ids...)
}
// AddHostIDs adds the "hosts" edge to the Host entity by IDs.
func (_c *UserCreate) AddHostIDs(ids ...string) *UserCreate {
_c.mutation.AddHostIDs(ids...)
@@ -755,6 +771,22 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.SkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SkillsTable,
Columns: []string{user.SkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.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.HostsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
+75 -1
View File
@@ -26,6 +26,7 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/projectcollaborator"
"github.com/chaitin/MonkeyCode/backend/db/projectissue"
"github.com/chaitin/MonkeyCode/backend/db/projectissuecomment"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/task"
"github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch"
"github.com/chaitin/MonkeyCode/backend/db/team"
@@ -51,6 +52,7 @@ type UserQuery struct {
withGroups *TeamGroupQuery
withModels *ModelQuery
withImages *ImageQuery
withSkills *SkillQuery
withHosts *HostQuery
withVms *VirtualMachineQuery
withTasks *TaskQuery
@@ -235,6 +237,28 @@ func (_q *UserQuery) QueryImages() *ImageQuery {
return query
}
// QuerySkills chains the current query on the "skills" edge.
func (_q *UserQuery) QuerySkills() *SkillQuery {
query := (&SkillClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(user.Table, user.FieldID, selector),
sqlgraph.To(skill.Table, skill.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, user.SkillsTable, user.SkillsColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryHosts chains the current query on the "hosts" edge.
func (_q *UserQuery) QueryHosts() *HostQuery {
query := (&HostClient{config: _q.config}).Query()
@@ -763,6 +787,7 @@ func (_q *UserQuery) Clone() *UserQuery {
withGroups: _q.withGroups.Clone(),
withModels: _q.withModels.Clone(),
withImages: _q.withImages.Clone(),
withSkills: _q.withSkills.Clone(),
withHosts: _q.withHosts.Clone(),
withVms: _q.withVms.Clone(),
withTasks: _q.withTasks.Clone(),
@@ -851,6 +876,17 @@ func (_q *UserQuery) WithImages(opts ...func(*ImageQuery)) *UserQuery {
return _q
}
// WithSkills tells the query-builder to eager-load the nodes that are connected to
// the "skills" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *UserQuery) WithSkills(opts ...func(*SkillQuery)) *UserQuery {
query := (&SkillClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withSkills = query
return _q
}
// WithHosts tells the query-builder to eager-load the nodes that are connected to
// the "hosts" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *UserQuery) WithHosts(opts ...func(*HostQuery)) *UserQuery {
@@ -1094,13 +1130,14 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
var (
nodes = []*User{}
_spec = _q.querySpec()
loadedTypes = [21]bool{
loadedTypes = [22]bool{
_q.withIdentities != nil,
_q.withAudits != nil,
_q.withTeams != nil,
_q.withGroups != nil,
_q.withModels != nil,
_q.withImages != nil,
_q.withSkills != nil,
_q.withHosts != nil,
_q.withVms != nil,
_q.withTasks != nil,
@@ -1181,6 +1218,13 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
return nil, err
}
}
if query := _q.withSkills; query != nil {
if err := _q.loadSkills(ctx, query, nodes,
func(n *User) { n.Edges.Skills = []*Skill{} },
func(n *User, e *Skill) { n.Edges.Skills = append(n.Edges.Skills, e) }); err != nil {
return nil, err
}
}
if query := _q.withHosts; query != nil {
if err := _q.loadHosts(ctx, query, nodes,
func(n *User) { n.Edges.Hosts = []*Host{} },
@@ -1535,6 +1579,36 @@ func (_q *UserQuery) loadImages(ctx context.Context, query *ImageQuery, nodes []
}
return nil
}
func (_q *UserQuery) loadSkills(ctx context.Context, query *SkillQuery, nodes []*User, init func(*User), assign func(*User, *Skill)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[uuid.UUID]*User)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
if init != nil {
init(nodes[i])
}
}
if len(query.ctx.Fields) > 0 {
query.ctx.AppendFieldOnce(skill.FieldUserID)
}
query.Where(predicate.Skill(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(user.SkillsColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.UserID
node, ok := nodeids[fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "user_id" returned %v for node %v`, fk, n.ID)
}
assign(node, n)
}
return nil
}
func (_q *UserQuery) loadHosts(ctx context.Context, query *HostQuery, nodes []*User, init func(*User), assign func(*User, *Host)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[uuid.UUID]*User)
+163
View File
@@ -25,6 +25,7 @@ import (
"github.com/chaitin/MonkeyCode/backend/db/projectcollaborator"
"github.com/chaitin/MonkeyCode/backend/db/projectissue"
"github.com/chaitin/MonkeyCode/backend/db/projectissuecomment"
"github.com/chaitin/MonkeyCode/backend/db/skill"
"github.com/chaitin/MonkeyCode/backend/db/task"
"github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch"
"github.com/chaitin/MonkeyCode/backend/db/team"
@@ -309,6 +310,21 @@ func (_u *UserUpdate) AddImages(v ...*Image) *UserUpdate {
return _u.AddImageIDs(ids...)
}
// AddSkillIDs adds the "skills" edge to the Skill entity by IDs.
func (_u *UserUpdate) AddSkillIDs(ids ...uuid.UUID) *UserUpdate {
_u.mutation.AddSkillIDs(ids...)
return _u
}
// AddSkills adds the "skills" edges to the Skill entity.
func (_u *UserUpdate) AddSkills(v ...*Skill) *UserUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddSkillIDs(ids...)
}
// AddHostIDs adds the "hosts" edge to the Host entity by IDs.
func (_u *UserUpdate) AddHostIDs(ids ...string) *UserUpdate {
_u.mutation.AddHostIDs(ids...)
@@ -665,6 +681,27 @@ func (_u *UserUpdate) RemoveImages(v ...*Image) *UserUpdate {
return _u.RemoveImageIDs(ids...)
}
// ClearSkills clears all "skills" edges to the Skill entity.
func (_u *UserUpdate) ClearSkills() *UserUpdate {
_u.mutation.ClearSkills()
return _u
}
// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs.
func (_u *UserUpdate) RemoveSkillIDs(ids ...uuid.UUID) *UserUpdate {
_u.mutation.RemoveSkillIDs(ids...)
return _u
}
// RemoveSkills removes "skills" edges to Skill entities.
func (_u *UserUpdate) RemoveSkills(v ...*Skill) *UserUpdate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveSkillIDs(ids...)
}
// ClearHosts clears all "hosts" edges to the Host entity.
func (_u *UserUpdate) ClearHosts() *UserUpdate {
_u.mutation.ClearHosts()
@@ -1392,6 +1429,51 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SkillsTable,
Columns: []string{user.SkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SkillsTable,
Columns: []string{user.SkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SkillsTable,
Columns: []string{user.SkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.HostsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -2368,6 +2450,21 @@ func (_u *UserUpdateOne) AddImages(v ...*Image) *UserUpdateOne {
return _u.AddImageIDs(ids...)
}
// AddSkillIDs adds the "skills" edge to the Skill entity by IDs.
func (_u *UserUpdateOne) AddSkillIDs(ids ...uuid.UUID) *UserUpdateOne {
_u.mutation.AddSkillIDs(ids...)
return _u
}
// AddSkills adds the "skills" edges to the Skill entity.
func (_u *UserUpdateOne) AddSkills(v ...*Skill) *UserUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddSkillIDs(ids...)
}
// AddHostIDs adds the "hosts" edge to the Host entity by IDs.
func (_u *UserUpdateOne) AddHostIDs(ids ...string) *UserUpdateOne {
_u.mutation.AddHostIDs(ids...)
@@ -2724,6 +2821,27 @@ func (_u *UserUpdateOne) RemoveImages(v ...*Image) *UserUpdateOne {
return _u.RemoveImageIDs(ids...)
}
// ClearSkills clears all "skills" edges to the Skill entity.
func (_u *UserUpdateOne) ClearSkills() *UserUpdateOne {
_u.mutation.ClearSkills()
return _u
}
// RemoveSkillIDs removes the "skills" edge to Skill entities by IDs.
func (_u *UserUpdateOne) RemoveSkillIDs(ids ...uuid.UUID) *UserUpdateOne {
_u.mutation.RemoveSkillIDs(ids...)
return _u
}
// RemoveSkills removes "skills" edges to Skill entities.
func (_u *UserUpdateOne) RemoveSkills(v ...*Skill) *UserUpdateOne {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveSkillIDs(ids...)
}
// ClearHosts clears all "hosts" edges to the Host entity.
func (_u *UserUpdateOne) ClearHosts() *UserUpdateOne {
_u.mutation.ClearHosts()
@@ -3481,6 +3599,51 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SkillsTable,
Columns: []string{user.SkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedSkillsIDs(); len(nodes) > 0 && !_u.mutation.SkillsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SkillsTable,
Columns: []string{user.SkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SkillsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SkillsTable,
Columns: []string{user.SkillsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(skill.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.HostsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
+482 -16
View File
@@ -2051,6 +2051,350 @@
}
}
},
"/api/v1/teams/skills": {
"get": {
"security": [
{
"MonkeyCodeAITeamAuth": []
}
],
"description": "获取团队 Skill 列表",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"【Team 管理员】Skill 管理"
],
"summary": "获取团队 Skill 列表",
"responses": {
"200": {
"description": "成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/web.Resp"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/domain.ListTeamSkillsResp"
}
}
}
]
}
},
"401": {
"description": "未授权",
"schema": {
"$ref": "#/definitions/web.Resp"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/web.Resp"
}
}
}
},
"post": {
"security": [
{
"MonkeyCodeAITeamAuth": []
}
],
"description": "添加团队 Skill",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"【Team 管理员】Skill 管理"
],
"summary": "添加团队 Skill",
"parameters": [
{
"description": "请求参数",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/domain.AddTeamSkillReq"
}
}
],
"responses": {
"200": {
"description": "成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/web.Resp"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/domain.TeamSkill"
}
}
}
]
}
},
"401": {
"description": "未授权",
"schema": {
"$ref": "#/definitions/web.Resp"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/web.Resp"
}
}
}
}
},
"/api/v1/teams/skills/package": {
"post": {
"security": [
{
"MonkeyCodeAITeamAuth": []
}
],
"description": "上传团队 Skill zip 包",
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"【Team 管理员】Skill 管理"
],
"summary": "上传团队 Skill zip 包",
"parameters": [
{
"type": "string",
"description": "Skill 名称",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "Skill 描述",
"name": "description",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "JSON 字符串数组",
"name": "tags",
"in": "formData"
},
{
"type": "string",
"description": "SKILL.md 原文",
"name": "content",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "JSON 字符串数组",
"name": "group_ids",
"in": "formData"
},
{
"type": "string",
"description": "来源类型",
"name": "source_type",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "来源标签",
"name": "source_label",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "zip 内 SKILL.md 路径",
"name": "skill_md_path",
"in": "formData"
},
{
"type": "file",
"description": "Skill zip 包",
"name": "file",
"in": "formData",
"required": true
}
],
"responses": {
"200": {
"description": "成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/web.Resp"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/domain.TeamSkill"
}
}
}
]
}
},
"401": {
"description": "未授权",
"schema": {
"$ref": "#/definitions/web.Resp"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/web.Resp"
}
}
}
}
},
"/api/v1/teams/skills/{skill_id}": {
"put": {
"security": [
{
"MonkeyCodeAITeamAuth": []
}
],
"description": "更新团队 Skill",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"【Team 管理员】Skill 管理"
],
"summary": "更新团队 Skill",
"parameters": [
{
"type": "string",
"description": "Skill ID",
"name": "skill_id",
"in": "path",
"required": true
},
{
"description": "请求参数",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/domain.UpdateTeamSkillReq"
}
}
],
"responses": {
"200": {
"description": "成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/web.Resp"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/domain.TeamSkill"
}
}
}
]
}
},
"401": {
"description": "未授权",
"schema": {
"$ref": "#/definitions/web.Resp"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/web.Resp"
}
}
}
},
"delete": {
"security": [
{
"MonkeyCodeAITeamAuth": []
}
],
"description": "删除团队 Skill",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"【Team 管理员】Skill 管理"
],
"summary": "删除团队 Skill",
"parameters": [
{
"type": "string",
"description": "Skill ID",
"name": "skill_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "成功",
"schema": {
"$ref": "#/definitions/web.Resp"
}
},
"401": {
"description": "未授权",
"schema": {
"$ref": "#/definitions/web.Resp"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/web.Resp"
}
}
}
}
},
"/api/v1/teams/task-vm-idle-policy": {
"get": {
"security": [
@@ -9179,14 +9523,6 @@
"x-enum-comments": {
"UserPlatformBaizhi": "百智云平台"
},
"x-enum-descriptions": [
"百智云平台",
"",
"",
"",
"",
""
],
"x-enum-varnames": [
"UserPlatformBaizhi",
"UserPlatformGithub",
@@ -9212,13 +9548,6 @@
"UserRoleIndividual": "个人用户",
"UserRoleSubAccount": "企业子账户"
},
"x-enum-descriptions": [
"个人用户",
"企业用户",
"企业子账户",
"MonkeyCode-AI 管理员账号,用来配置公共资源. 如公共宿主机等",
"全自动 git 任务插入的用户"
],
"x-enum-varnames": [
"UserRoleIndividual",
"UserRoleEnterprise",
@@ -9436,6 +9765,48 @@
}
}
},
"domain.AddTeamSkillReq": {
"type": "object",
"required": [
"content",
"description",
"name",
"source_label",
"source_type"
],
"properties": {
"content": {
"type": "string"
},
"description": {
"type": "string"
},
"group_ids": {
"type": "array",
"items": {
"type": "string"
}
},
"name": {
"type": "string"
},
"skill_md_path": {
"type": "string"
},
"source_label": {
"type": "string"
},
"source_type": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"domain.AddTeamUserReq": {
"type": "object",
"required": [
@@ -10525,6 +10896,17 @@
}
}
},
"domain.ListTeamSkillsResp": {
"type": "object",
"properties": {
"skills": {
"type": "array",
"items": {
"$ref": "#/definitions/domain.TeamSkill"
}
}
}
},
"domain.ListUserMCPUpstreamsResp": {
"type": "object",
"properties": {
@@ -12317,6 +12699,56 @@
}
}
},
"domain.TeamSkill": {
"type": "object",
"properties": {
"content": {
"type": "string"
},
"created_at": {
"type": "integer"
},
"description": {
"type": "string"
},
"groups": {
"type": "array",
"items": {
"$ref": "#/definitions/domain.TeamGroup"
}
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"package_object_key": {
"type": "string"
},
"package_url": {
"type": "string"
},
"skill_md_path": {
"type": "string"
},
"source_label": {
"type": "string"
},
"source_type": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"updated_at": {
"type": "integer"
}
}
},
"domain.TeamTaskItem": {
"type": "object",
"properties": {
@@ -12772,6 +13204,41 @@
}
}
},
"domain.UpdateTeamSkillReq": {
"type": "object",
"properties": {
"content": {
"type": "string"
},
"description": {
"type": "string"
},
"group_ids": {
"type": "array",
"items": {
"type": "string"
}
},
"name": {
"type": "string"
},
"skill_md_path": {
"type": "string"
},
"source_label": {
"type": "string"
},
"source_type": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"domain.UpdateTeamTaskVMIdlePolicyReq": {
"type": "object",
"properties": {
@@ -13209,7 +13676,6 @@
},
"types.ConditionStatus": {
"type": "integer",
"format": "int32",
"enum": [
0,
1,
+103
View File
@@ -0,0 +1,103 @@
package domain
import (
"context"
"github.com/google/uuid"
"github.com/chaitin/MonkeyCode/backend/db"
"github.com/chaitin/MonkeyCode/backend/pkg/cvt"
)
type TeamSkillUsecase interface {
Add(ctx context.Context, teamUser *TeamUser, req *AddTeamSkillReq) (*TeamSkill, error)
AddPackage(ctx context.Context, teamUser *TeamUser, req *AddTeamSkillPackageReq) (*TeamSkill, error)
List(ctx context.Context, teamUser *TeamUser) (*ListTeamSkillsResp, error)
Update(ctx context.Context, teamUser *TeamUser, req *UpdateTeamSkillReq) (*TeamSkill, error)
Delete(ctx context.Context, teamUser *TeamUser, req *DeleteTeamSkillReq) error
}
type TeamSkillRepo interface {
List(ctx context.Context, teamID uuid.UUID) ([]*db.Skill, error)
Create(ctx context.Context, teamID, userID uuid.UUID, req *AddTeamSkillReq) (*db.Skill, error)
Update(ctx context.Context, teamID uuid.UUID, req *UpdateTeamSkillReq) (*db.Skill, error)
Delete(ctx context.Context, teamID, skillID uuid.UUID) error
}
type TeamSkill struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Tags []string `json:"tags"`
Content string `json:"content"`
PackageKey string `json:"package_object_key,omitempty"`
PackageURL string `json:"package_url,omitempty"`
Groups []*TeamGroup `json:"groups"`
SourceType string `json:"source_type"`
SourceLabel string `json:"source_label"`
SkillMDPath string `json:"skill_md_path,omitempty"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
func (t *TeamSkill) From(src *db.Skill) *TeamSkill {
if src == nil {
return t
}
t.ID = src.ID
t.Name = src.Name
t.Description = src.Description
t.Tags = src.Tags
t.Content = src.Content
t.PackageKey = src.PackageObjectKey
t.PackageURL = src.PackageURL
t.SourceType = src.SourceType
t.SourceLabel = src.SourceLabel
t.SkillMDPath = src.SkillMdPath
t.Groups = cvt.Iter(src.Edges.Groups, func(_ int, g *db.TeamGroup) *TeamGroup {
return cvt.From(g, &TeamGroup{})
})
t.CreatedAt = src.CreatedAt.Unix()
t.UpdatedAt = src.UpdatedAt.Unix()
return t
}
type AddTeamSkillReq struct {
Name string `json:"name" form:"name" validate:"required"`
Description string `json:"description" form:"description" validate:"required"`
Tags []string `json:"tags" validate:"omitempty"`
Content string `json:"content" form:"content" validate:"required"`
PackageObjectKey string `json:"package_object_key,omitempty" swaggerignore:"true"`
PackageURL string `json:"package_url,omitempty" swaggerignore:"true"`
GroupIDs []uuid.UUID `json:"group_ids" validate:"omitempty"`
SourceType string `json:"source_type" form:"source_type" validate:"required"`
SourceLabel string `json:"source_label" form:"source_label" validate:"required"`
SkillMDPath string `json:"skill_md_path" form:"skill_md_path" validate:"omitempty"`
}
type AddTeamSkillPackageReq struct {
AddTeamSkillReq
PackageFilename string `json:"-" swaggerignore:"true"`
PackageData []byte `json:"-" swaggerignore:"true"`
}
type ListTeamSkillsResp struct {
Skills []*TeamSkill `json:"skills"`
}
type UpdateTeamSkillReq struct {
SkillID uuid.UUID `param:"skill_id" validate:"required" json:"-" swaggerignore:"true"`
Name string `json:"name" validate:"omitempty"`
Description string `json:"description" validate:"omitempty"`
Tags []string `json:"tags" validate:"omitempty"`
Content string `json:"content" validate:"omitempty"`
GroupIDs []uuid.UUID `json:"group_ids" validate:"omitempty"`
SourceType string `json:"source_type" validate:"omitempty"`
SourceLabel string `json:"source_label" validate:"omitempty"`
SkillMDPath *string `json:"skill_md_path,omitempty" validate:"omitempty"`
}
type DeleteTeamSkillReq struct {
SkillID uuid.UUID `param:"skill_id" validate:"required" json:"-" swaggerignore:"true"`
}
+57
View File
@@ -0,0 +1,57 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
"github.com/chaitin/MonkeyCode/backend/pkg/entx"
)
type Skill struct {
ent.Schema
}
func (Skill) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Table("skills"),
entx.NewCursor(entx.CursorKindCreatedAt),
}
}
func (Skill) Mixin() []ent.Mixin {
return []ent.Mixin{
entx.SoftDeleteMixin2{},
}
}
func (Skill) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Unique(),
field.UUID("user_id", uuid.UUID{}),
field.String("name").NotEmpty(),
field.Text("description").NotEmpty(),
field.JSON("tags", []string{}).Optional(),
field.Text("content").NotEmpty(),
field.String("package_object_key").Optional(),
field.String("package_url").Optional(),
field.String("source_type").NotEmpty(),
field.String("source_label").NotEmpty(),
field.String("skill_md_path").Optional(),
field.Time("created_at").Default(time.Now),
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
}
}
func (Skill) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).Ref("skills").Field("user_id").Unique().Required(),
edge.From("teams", Team.Type).Ref("skills").Through("team_skills", TeamSkill.Type),
edge.From("groups", TeamGroup.Type).Ref("skills").Through("team_group_skills", TeamGroupSkill.Type),
}
}
+1
View File
@@ -52,5 +52,6 @@ func (Team) Edges() []ent.Edge {
edge.From("members", User.Type).Ref("teams").Through("team_members", TeamMember.Type),
edge.To("models", Model.Type).Through("team_models", TeamModel.Type),
edge.To("images", Image.Type).Through("team_images", TeamImage.Type),
edge.To("skills", Skill.Type).Through("team_skills", TeamSkill.Type),
}
}
+1
View File
@@ -50,5 +50,6 @@ func (TeamGroup) Edges() []ent.Edge {
edge.To("models", Model.Type).Through("team_group_models", TeamGroupModel.Type),
edge.To("images", Image.Type).Through("team_group_images", TeamGroupImage.Type),
edge.To("hosts", Host.Type).Through("team_group_hosts", TeamGroupHost.Type),
edge.To("skills", Skill.Type).Through("team_group_skills", TeamGroupSkill.Type),
}
}
+41
View File
@@ -0,0 +1,41 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
"github.com/chaitin/MonkeyCode/backend/pkg/entx"
)
type TeamGroupSkill struct {
ent.Schema
}
func (TeamGroupSkill) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Table("team_group_skills"),
entx.NewCursor(entx.CursorKindCreatedAt),
}
}
func (TeamGroupSkill) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Unique(),
field.UUID("group_id", uuid.UUID{}),
field.UUID("skill_id", uuid.UUID{}),
field.Time("created_at").Default(time.Now),
}
}
func (TeamGroupSkill) Edges() []ent.Edge {
return []ent.Edge{
edge.To("group", TeamGroup.Type).Field("group_id").Unique().Required(),
edge.To("skill", Skill.Type).Field("skill_id").Unique().Required(),
}
}
+38
View File
@@ -0,0 +1,38 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
type TeamSkill struct {
ent.Schema
}
func (TeamSkill) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Table("team_skills"),
}
}
func (TeamSkill) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}),
field.UUID("team_id", uuid.UUID{}),
field.UUID("skill_id", uuid.UUID{}),
field.Time("created_at").Default(time.Now),
}
}
func (TeamSkill) Edges() []ent.Edge {
return []ent.Edge{
edge.To("team", Team.Type).Field("team_id").Unique().Required(),
edge.To("skill", Skill.Type).Field("skill_id").Unique().Required(),
}
}
+1
View File
@@ -57,6 +57,7 @@ func (User) Edges() []ent.Edge {
edge.To("groups", TeamGroup.Type).Through("team_group_members", TeamGroupMember.Type),
edge.To("models", Model.Type),
edge.To("images", Image.Type),
edge.To("skills", Skill.Type),
edge.To("hosts", Host.Type),
edge.To("vms", VirtualMachine.Type),
edge.To("tasks", Task.Type),
@@ -0,0 +1,3 @@
DROP TABLE IF EXISTS team_group_skills;
DROP TABLE IF EXISTS team_skills;
DROP TABLE IF EXISTS skills;
@@ -0,0 +1,38 @@
CREATE TABLE IF NOT EXISTS skills (
id uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
deleted_at timestamp with time zone,
user_id uuid NOT NULL,
name character varying NOT NULL,
description text NOT NULL,
tags jsonb,
content text NOT NULL,
package_object_key character varying,
package_url character varying,
source_type character varying NOT NULL,
source_label character varying NOT NULL,
skill_md_path character varying,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_skills_created_at_id ON skills USING btree (created_at, id);
CREATE INDEX IF NOT EXISTS idx_skills_user_id ON skills USING btree (user_id);
CREATE TABLE IF NOT EXISTS team_skills (
id uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
team_id uuid NOT NULL,
skill_id uuid NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS unique_idx_team_skills_team_skill ON team_skills USING btree (team_id, skill_id);
CREATE TABLE IF NOT EXISTS team_group_skills (
id uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
group_id uuid NOT NULL,
skill_id uuid NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_team_group_skills_created_at_id ON team_group_skills USING btree (created_at, id);
CREATE UNIQUE INDEX IF NOT EXISTS unique_idx_team_group_skills_group_skill ON team_group_skills USING btree (group_id, skill_id);
+172
View File
@@ -271,6 +271,29 @@ export interface DomainAddTeamImageReq {
remark?: string;
}
export interface DomainAddTeamSkillReq {
content: string;
description: string;
group_ids?: string[];
name: string;
skill_md_path?: string;
source_label: string;
source_type: string;
tags?: string[];
}
export interface DomainAddTeamSkillPackageReq {
content: string;
description: string;
file: File;
group_ids?: string;
name: string;
skill_md_path?: string;
source_label: string;
source_type: string;
tags?: string;
}
export interface DomainAddTeamModelReq {
api_key: string;
base_url: string;
@@ -837,6 +860,10 @@ export interface DomainListTeamImagesResp {
images?: DomainTeamImage[];
}
export interface DomainListTeamSkillsResp {
skills?: DomainTeamSkill[];
}
export interface DomainListTeamModelsResp {
models?: DomainTeamModel[];
}
@@ -1690,6 +1717,22 @@ export interface DomainTeamImage {
updated_at?: number;
}
export interface DomainTeamSkill {
content?: string;
created_at?: number;
description?: string;
groups?: DomainTeamGroup[];
id?: string;
name?: string;
package_object_key?: string;
package_url?: string;
skill_md_path?: string;
source_label?: string;
source_type?: string;
tags?: string[];
updated_at?: number;
}
export interface DomainTeamLoginReq {
/** 验证码Token */
captcha_token: string;
@@ -1898,6 +1941,17 @@ export interface DomainUpdateTeamImageReq {
remark?: string;
}
export interface DomainUpdateTeamSkillReq {
content?: string;
description?: string;
group_ids?: string[];
name?: string;
skill_md_path?: string;
source_label?: string;
source_type?: string;
tags?: string[];
}
export interface DomainUpdateTeamModelReq {
api_key?: string;
base_url?: string;
@@ -3518,6 +3572,124 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
...params,
}),
/**
* @description 获取团队 Skill 列表
*
* @tags 【Team 管理员】Skill 管理
* @name V1TeamsSkillsList
* @summary 获取团队 Skill 列表
* @request GET:/api/v1/teams/skills
* @secure
*/
v1TeamsSkillsList: (params: RequestParams = {}) =>
this.request<
GithubComGoYokoWebResp & {
data?: DomainListTeamSkillsResp;
},
GithubComGoYokoWebResp
>({
path: `/api/v1/teams/skills`,
method: "GET",
secure: true,
type: ContentType.Json,
format: "json",
...params,
}),
/**
* @description 添加团队 Skill
*
* @tags 【Team 管理员】Skill 管理
* @name V1TeamsSkillsCreate
* @summary 添加团队 Skill
* @request POST:/api/v1/teams/skills
* @secure
*/
v1TeamsSkillsCreate: (req: DomainAddTeamSkillReq, params: RequestParams = {}) =>
this.request<
GithubComGoYokoWebResp & {
data?: DomainTeamSkill;
},
GithubComGoYokoWebResp
>({
path: `/api/v1/teams/skills`,
method: "POST",
body: req,
secure: true,
type: ContentType.Json,
format: "json",
...params,
}),
/**
* @description 上传团队 Skill zip 包
*
* @tags 【Team 管理员】Skill 管理
* @name V1TeamsSkillsPackageCreate
* @summary 上传团队 Skill zip 包
* @request POST:/api/v1/teams/skills/package
* @secure
*/
v1TeamsSkillsPackageCreate: (req: DomainAddTeamSkillPackageReq, params: RequestParams = {}) =>
this.request<
GithubComGoYokoWebResp & {
data?: DomainTeamSkill;
},
GithubComGoYokoWebResp
>({
path: `/api/v1/teams/skills/package`,
method: "POST",
body: req,
secure: true,
type: ContentType.FormData,
format: "json",
...params,
}),
/**
* @description 更新团队 Skill
*
* @tags 【Team 管理员】Skill 管理
* @name V1TeamsSkillsUpdate
* @summary 更新团队 Skill
* @request PUT:/api/v1/teams/skills/{skill_id}
* @secure
*/
v1TeamsSkillsUpdate: (skillId: string, req: DomainUpdateTeamSkillReq, params: RequestParams = {}) =>
this.request<
GithubComGoYokoWebResp & {
data?: DomainTeamSkill;
},
GithubComGoYokoWebResp
>({
path: `/api/v1/teams/skills/${skillId}`,
method: "PUT",
body: req,
secure: true,
type: ContentType.Json,
format: "json",
...params,
}),
/**
* @description 删除团队 Skill
*
* @tags 【Team 管理员】Skill 管理
* @name V1TeamsSkillsDelete
* @summary 删除团队 Skill
* @request DELETE:/api/v1/teams/skills/{skill_id}
* @secure
*/
v1TeamsSkillsDelete: (skillId: string, params: RequestParams = {}) =>
this.request<GithubComGoYokoWebResp, GithubComGoYokoWebResp>({
path: `/api/v1/teams/skills/${skillId}`,
method: "DELETE",
secure: true,
type: ContentType.Json,
format: "json",
...params,
}),
/**
* @description 获取当前团队企业登录 OIDC 配置
*
+112 -30
View File
@@ -11,7 +11,7 @@ import {
import { IconPencil, IconTrash } from "@tabler/icons-react"
import { toast } from "sonner"
import type { DomainTeamGroup } from "@/api/Api"
import { Api, type DomainTeamGroup, type DomainTeamSkill } from "@/api/Api"
import {
findSkillMarkdownPath,
normalizeSkillTags,
@@ -97,9 +97,26 @@ interface SkillSourceState {
export default function TeamManagerSkills() {
const [skills, setSkills] = useState<ManagedSkill[]>([])
const [loading, setLoading] = useState(true)
const [addDialogOpen, setAddDialogOpen] = useState(false)
const [editingSkill, setEditingSkill] = useState<ManagedSkill | null>(null)
const fetchSkills = async () => {
setLoading(true)
await apiRequest("v1TeamsSkillsList", {}, [], (resp) => {
if (resp.code === 0) {
setSkills((resp.data?.skills || []).map(toManagedSkill))
return
}
toast.error(resp.message || "获取 Skill 列表失败")
})
setLoading(false)
}
useEffect(() => {
void fetchSkills()
}, [])
const handleCreate = (skill: ManagedSkill) => {
setSkills((prev) => [skill, ...prev])
}
@@ -109,8 +126,14 @@ export default function TeamManagerSkills() {
}
const handleDelete = (skillID: string) => {
setSkills((prev) => prev.filter((skill) => skill.id !== skillID))
toast.success("Skill 已删除")
void apiRequest("v1TeamsSkillsDelete", {}, [skillID], (resp) => {
if (resp.code === 0) {
setSkills((prev) => prev.filter((skill) => skill.id !== skillID))
toast.success("Skill 已删除")
return
}
toast.error(resp.message || "删除 Skill 失败")
})
}
return (
@@ -133,7 +156,16 @@ export default function TeamManagerSkills() {
</CardAction>
</CardHeader>
<CardContent>
{skills.length === 0 ? (
{loading ? (
<Empty className="bg-muted">
<EmptyHeader>
<EmptyMedia variant="icon">
<Sparkles className="size-6" />
</EmptyMedia>
<EmptyTitle>正在加载 Skills</EmptyTitle>
</EmptyHeader>
</Empty>
) : skills.length === 0 ? (
<Empty className="bg-muted">
<EmptyHeader>
<EmptyMedia variant="icon">
@@ -260,6 +292,7 @@ function AddSkillDialog({
const [parsing, setParsing] = useState(false)
const [parseError, setParseError] = useState("")
const [pastedText, setPastedText] = useState("")
const [packageFile, setPackageFile] = useState<File | null>(null)
const [source, setSource] = useState<SkillSourceState | null>(null)
const [draft, setDraft] = useState<ParsedSkillMarkdown | null>(null)
const [name, setName] = useState("")
@@ -280,6 +313,7 @@ function AddSkillDialog({
setParsing(false)
setParseError("")
setPastedText("")
setPackageFile(null)
setSource(null)
setDraft(null)
setName("")
@@ -312,10 +346,12 @@ function AddSkillDialog({
setParsing(true)
try {
const parsedFile = await parseSkillFile(file)
setPackageFile(parsedFile.source.type === "zip" ? file : null)
applyParsedSkill(parsedFile.parsed, parsedFile.source)
} catch (error) {
const message = error instanceof Error ? error.message : "Skill 文件解析失败"
setDraft(null)
setPackageFile(null)
setSource(null)
setParseError(message)
toast.error(message)
@@ -329,12 +365,14 @@ function AddSkillDialog({
if (!value.trim()) {
setDraft(null)
setPackageFile(null)
setSource(null)
setParseError("")
return
}
try {
setPackageFile(null)
applyParsedSkill(parseSkillMarkdown(value), {
type: "text",
label: "粘贴文本",
@@ -362,22 +400,52 @@ function AddSkillDialog({
return
}
const now = Math.floor(Date.now() / 1000)
onCreate({
id: createLocalSkillID(),
const tags = normalizeSkillTags(tagsText)
if (source.type === "zip" && packageFile) {
const api = new Api()
void api.api.v1TeamsSkillsPackageCreate({
name: name.trim(),
description: description.trim(),
tags: JSON.stringify(tags),
content: draft.content,
group_ids: JSON.stringify(selectedGroupIds),
source_type: source.type,
source_label: source.label,
skill_md_path: source.skillMdPath,
file: packageFile,
}).then((response) => {
const resp = response.data
if (resp.code === 0 && resp.data) {
onCreate(toManagedSkill(resp.data))
toast.success("Skill 已添加")
handleOpenChange(false)
return
}
toast.error(resp.message || "添加 Skill 失败")
}).catch((error) => {
toast.error(error?.message || "添加 Skill 失败")
})
return
}
void apiRequest("v1TeamsSkillsCreate", {
name: name.trim(),
description: description.trim(),
tags: normalizeSkillTags(tagsText),
groups: resolveSelectedGroups(groups, selectedGroupIds),
sourceType: source.type,
sourceLabel: source.label,
skillMdPath: source.skillMdPath,
createdAt: now,
updatedAt: now,
tags,
content: draft.content,
group_ids: selectedGroupIds,
source_type: source.type,
source_label: source.label,
skill_md_path: source.skillMdPath,
}, [], (resp) => {
if (resp.code === 0 && resp.data) {
onCreate(toManagedSkill(resp.data))
toast.success("Skill 已添加")
handleOpenChange(false)
return
}
toast.error(resp.message || "添加 Skill 失败")
})
toast.success("Skill 已添加")
handleOpenChange(false)
}
return (
@@ -506,16 +574,20 @@ function EditSkillDialog({
return
}
onUpdate({
...skill,
void apiRequest("v1TeamsSkillsUpdate", {
name: name.trim(),
description: description.trim(),
tags: normalizeSkillTags(tagsText),
groups: resolveSelectedGroups(groups, selectedGroupIds),
updatedAt: Math.floor(Date.now() / 1000),
group_ids: selectedGroupIds,
}, [skill.id], (resp) => {
if (resp.code === 0 && resp.data) {
onUpdate(toManagedSkill(resp.data))
toast.success("Skill 已修改")
onOpenChange(false)
return
}
toast.error(resp.message || "修改 Skill 失败")
})
toast.success("Skill 已修改")
onOpenChange(false)
}
return (
@@ -810,14 +882,24 @@ function fetchGroups(setGroups: (groups: DomainTeamGroup[]) => void) {
})
}
function resolveSelectedGroups(groups: DomainTeamGroup[], selectedGroupIds: string[]): DomainTeamGroup[] {
const selected = new Set(selectedGroupIds)
return groups.filter((group) => group.id && selected.has(group.id))
function toManagedSkill(skill: DomainTeamSkill): ManagedSkill {
return {
id: skill.id || "",
name: skill.name || "",
description: skill.description || "",
tags: skill.tags || [],
groups: skill.groups || [],
sourceType: toSkillSourceType(skill.source_type),
sourceLabel: skill.source_label || "SKILL.md",
skillMdPath: skill.skill_md_path,
createdAt: skill.created_at || 0,
updatedAt: skill.updated_at || 0,
}
}
function createLocalSkillID() {
if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
return crypto.randomUUID()
function toSkillSourceType(value: unknown): SkillSourceType {
if (value === "zip" || value === "markdown" || value === "text") {
return value
}
return `skill-${Date.now()}`
return "markdown"
}