mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 03:18:50 +08:00
401 lines
14 KiB
Go
401 lines
14 KiB
Go
// 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/consts"
|
|
"github.com/chaitin/MonkeyCode/backend/db/gittask"
|
|
"github.com/chaitin/MonkeyCode/backend/db/task"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Task is the model entity for the Task schema.
|
|
type Task 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"`
|
|
// Kind holds the value of the "kind" field.
|
|
Kind consts.TaskType `json:"kind,omitempty"`
|
|
// SubType holds the value of the "sub_type" field.
|
|
SubType consts.TaskSubType `json:"sub_type,omitempty"`
|
|
// Content holds the value of the "content" field.
|
|
Content string `json:"content,omitempty"`
|
|
// Title holds the value of the "title" field.
|
|
Title string `json:"title,omitempty"`
|
|
// Summary holds the value of the "summary" field.
|
|
Summary string `json:"summary,omitempty"`
|
|
// Status holds the value of the "status" field.
|
|
Status consts.TaskStatus `json:"status,omitempty"`
|
|
// LogStore holds the value of the "log_store" field.
|
|
LogStore *consts.LogStore `json:"log_store,omitempty"`
|
|
// CreatedAt holds the value of the "created_at" field.
|
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
|
// LastActiveAt holds the value of the "last_active_at" field.
|
|
LastActiveAt time.Time `json:"last_active_at,omitempty"`
|
|
// UpdatedAt holds the value of the "updated_at" field.
|
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
|
// CompletedAt holds the value of the "completed_at" field.
|
|
CompletedAt time.Time `json:"completed_at,omitempty"`
|
|
// SkillIds holds the value of the "skill_ids" field.
|
|
SkillIds []string `json:"skill_ids,omitempty"`
|
|
// PluginIds holds the value of the "plugin_ids" field.
|
|
PluginIds []string `json:"plugin_ids,omitempty"`
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
// The values are being populated by the TaskQuery when eager-loading is set.
|
|
Edges TaskEdges `json:"edges"`
|
|
selectValues sql.SelectValues
|
|
}
|
|
|
|
// TaskEdges holds the relations/edges for other nodes in the graph.
|
|
type TaskEdges struct {
|
|
// ProjectTasks holds the value of the project_tasks edge.
|
|
ProjectTasks []*ProjectTask `json:"project_tasks,omitempty"`
|
|
// GitTasks holds the value of the git_tasks edge.
|
|
GitTasks *GitTask `json:"git_tasks,omitempty"`
|
|
// User holds the value of the user edge.
|
|
User *User `json:"user,omitempty"`
|
|
// Vms holds the value of the vms edge.
|
|
Vms []*VirtualMachine `json:"vms,omitempty"`
|
|
// GitBotTasks holds the value of the git_bot_tasks edge.
|
|
GitBotTasks []*GitBotTask `json:"git_bot_tasks,omitempty"`
|
|
// ModelSwitches holds the value of the model_switches edge.
|
|
ModelSwitches []*TaskModelSwitch `json:"model_switches,omitempty"`
|
|
// TaskVms holds the value of the task_vms edge.
|
|
TaskVms []*TaskVirtualMachine `json:"task_vms,omitempty"`
|
|
// loadedTypes holds the information for reporting if a
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
loadedTypes [7]bool
|
|
}
|
|
|
|
// ProjectTasksOrErr returns the ProjectTasks value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e TaskEdges) ProjectTasksOrErr() ([]*ProjectTask, error) {
|
|
if e.loadedTypes[0] {
|
|
return e.ProjectTasks, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "project_tasks"}
|
|
}
|
|
|
|
// GitTasksOrErr returns the GitTasks value or an error if the edge
|
|
// was not loaded in eager-loading, or loaded but was not found.
|
|
func (e TaskEdges) GitTasksOrErr() (*GitTask, error) {
|
|
if e.GitTasks != nil {
|
|
return e.GitTasks, nil
|
|
} else if e.loadedTypes[1] {
|
|
return nil, &NotFoundError{label: gittask.Label}
|
|
}
|
|
return nil, &NotLoadedError{edge: "git_tasks"}
|
|
}
|
|
|
|
// 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 TaskEdges) UserOrErr() (*User, error) {
|
|
if e.User != nil {
|
|
return e.User, nil
|
|
} else if e.loadedTypes[2] {
|
|
return nil, &NotFoundError{label: user.Label}
|
|
}
|
|
return nil, &NotLoadedError{edge: "user"}
|
|
}
|
|
|
|
// VmsOrErr returns the Vms value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e TaskEdges) VmsOrErr() ([]*VirtualMachine, error) {
|
|
if e.loadedTypes[3] {
|
|
return e.Vms, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "vms"}
|
|
}
|
|
|
|
// GitBotTasksOrErr returns the GitBotTasks value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e TaskEdges) GitBotTasksOrErr() ([]*GitBotTask, error) {
|
|
if e.loadedTypes[4] {
|
|
return e.GitBotTasks, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "git_bot_tasks"}
|
|
}
|
|
|
|
// ModelSwitchesOrErr returns the ModelSwitches value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e TaskEdges) ModelSwitchesOrErr() ([]*TaskModelSwitch, error) {
|
|
if e.loadedTypes[5] {
|
|
return e.ModelSwitches, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "model_switches"}
|
|
}
|
|
|
|
// TaskVmsOrErr returns the TaskVms value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e TaskEdges) TaskVmsOrErr() ([]*TaskVirtualMachine, error) {
|
|
if e.loadedTypes[6] {
|
|
return e.TaskVms, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "task_vms"}
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*Task) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case task.FieldSkillIds, task.FieldPluginIds:
|
|
values[i] = new([]byte)
|
|
case task.FieldKind, task.FieldSubType, task.FieldContent, task.FieldTitle, task.FieldSummary, task.FieldStatus, task.FieldLogStore:
|
|
values[i] = new(sql.NullString)
|
|
case task.FieldDeletedAt, task.FieldCreatedAt, task.FieldLastActiveAt, task.FieldUpdatedAt, task.FieldCompletedAt:
|
|
values[i] = new(sql.NullTime)
|
|
case task.FieldID, task.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 Task fields.
|
|
func (_m *Task) 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 task.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 task.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 task.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 task.FieldKind:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field kind", values[i])
|
|
} else if value.Valid {
|
|
_m.Kind = consts.TaskType(value.String)
|
|
}
|
|
case task.FieldSubType:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field sub_type", values[i])
|
|
} else if value.Valid {
|
|
_m.SubType = consts.TaskSubType(value.String)
|
|
}
|
|
case task.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 task.FieldTitle:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field title", values[i])
|
|
} else if value.Valid {
|
|
_m.Title = value.String
|
|
}
|
|
case task.FieldSummary:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field summary", values[i])
|
|
} else if value.Valid {
|
|
_m.Summary = value.String
|
|
}
|
|
case task.FieldStatus:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
|
} else if value.Valid {
|
|
_m.Status = consts.TaskStatus(value.String)
|
|
}
|
|
case task.FieldLogStore:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field log_store", values[i])
|
|
} else if value.Valid {
|
|
_m.LogStore = new(consts.LogStore)
|
|
*_m.LogStore = consts.LogStore(value.String)
|
|
}
|
|
case task.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 task.FieldLastActiveAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field last_active_at", values[i])
|
|
} else if value.Valid {
|
|
_m.LastActiveAt = value.Time
|
|
}
|
|
case task.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
|
|
}
|
|
case task.FieldCompletedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field completed_at", values[i])
|
|
} else if value.Valid {
|
|
_m.CompletedAt = value.Time
|
|
}
|
|
case task.FieldSkillIds:
|
|
if value, ok := values[i].(*[]byte); !ok {
|
|
return fmt.Errorf("unexpected type %T for field skill_ids", values[i])
|
|
} else if value != nil && len(*value) > 0 {
|
|
if err := json.Unmarshal(*value, &_m.SkillIds); err != nil {
|
|
return fmt.Errorf("unmarshal field skill_ids: %w", err)
|
|
}
|
|
}
|
|
case task.FieldPluginIds:
|
|
if value, ok := values[i].(*[]byte); !ok {
|
|
return fmt.Errorf("unexpected type %T for field plugin_ids", values[i])
|
|
} else if value != nil && len(*value) > 0 {
|
|
if err := json.Unmarshal(*value, &_m.PluginIds); err != nil {
|
|
return fmt.Errorf("unmarshal field plugin_ids: %w", err)
|
|
}
|
|
}
|
|
default:
|
|
_m.selectValues.Set(columns[i], values[i])
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the Task.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (_m *Task) Value(name string) (ent.Value, error) {
|
|
return _m.selectValues.Get(name)
|
|
}
|
|
|
|
// QueryProjectTasks queries the "project_tasks" edge of the Task entity.
|
|
func (_m *Task) QueryProjectTasks() *ProjectTaskQuery {
|
|
return NewTaskClient(_m.config).QueryProjectTasks(_m)
|
|
}
|
|
|
|
// QueryGitTasks queries the "git_tasks" edge of the Task entity.
|
|
func (_m *Task) QueryGitTasks() *GitTaskQuery {
|
|
return NewTaskClient(_m.config).QueryGitTasks(_m)
|
|
}
|
|
|
|
// QueryUser queries the "user" edge of the Task entity.
|
|
func (_m *Task) QueryUser() *UserQuery {
|
|
return NewTaskClient(_m.config).QueryUser(_m)
|
|
}
|
|
|
|
// QueryVms queries the "vms" edge of the Task entity.
|
|
func (_m *Task) QueryVms() *VirtualMachineQuery {
|
|
return NewTaskClient(_m.config).QueryVms(_m)
|
|
}
|
|
|
|
// QueryGitBotTasks queries the "git_bot_tasks" edge of the Task entity.
|
|
func (_m *Task) QueryGitBotTasks() *GitBotTaskQuery {
|
|
return NewTaskClient(_m.config).QueryGitBotTasks(_m)
|
|
}
|
|
|
|
// QueryModelSwitches queries the "model_switches" edge of the Task entity.
|
|
func (_m *Task) QueryModelSwitches() *TaskModelSwitchQuery {
|
|
return NewTaskClient(_m.config).QueryModelSwitches(_m)
|
|
}
|
|
|
|
// QueryTaskVms queries the "task_vms" edge of the Task entity.
|
|
func (_m *Task) QueryTaskVms() *TaskVirtualMachineQuery {
|
|
return NewTaskClient(_m.config).QueryTaskVms(_m)
|
|
}
|
|
|
|
// Update returns a builder for updating this Task.
|
|
// Note that you need to call Task.Unwrap() before calling this method if this Task
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (_m *Task) Update() *TaskUpdateOne {
|
|
return NewTaskClient(_m.config).UpdateOne(_m)
|
|
}
|
|
|
|
// Unwrap unwraps the Task 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 *Task) Unwrap() *Task {
|
|
_tx, ok := _m.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("db: Task is not a transactional entity")
|
|
}
|
|
_m.config.driver = _tx.drv
|
|
return _m
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (_m *Task) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("Task(")
|
|
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("kind=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Kind))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("sub_type=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.SubType))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("content=")
|
|
builder.WriteString(_m.Content)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("title=")
|
|
builder.WriteString(_m.Title)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("summary=")
|
|
builder.WriteString(_m.Summary)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("status=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Status))
|
|
builder.WriteString(", ")
|
|
if v := _m.LogStore; v != nil {
|
|
builder.WriteString("log_store=")
|
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
|
}
|
|
builder.WriteString(", ")
|
|
builder.WriteString("created_at=")
|
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("last_active_at=")
|
|
builder.WriteString(_m.LastActiveAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("updated_at=")
|
|
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("completed_at=")
|
|
builder.WriteString(_m.CompletedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("skill_ids=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.SkillIds))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("plugin_ids=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.PluginIds))
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// Tasks is a parsable slice of Task.
|
|
type Tasks []*Task
|