// 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/task" "github.com/chaitin/MonkeyCode/backend/db/taskvirtualmachine" "github.com/chaitin/MonkeyCode/backend/db/virtualmachine" "github.com/google/uuid" ) // TaskVirtualMachine is the model entity for the TaskVirtualMachine schema. type TaskVirtualMachine struct { config `json:"-"` // ID of the ent. ID uuid.UUID `json:"id,omitempty"` // TaskID holds the value of the "task_id" field. TaskID uuid.UUID `json:"task_id,omitempty"` // VirtualmachineID holds the value of the "virtualmachine_id" field. VirtualmachineID string `json:"virtualmachine_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 TaskVirtualMachineQuery when eager-loading is set. Edges TaskVirtualMachineEdges `json:"edges"` selectValues sql.SelectValues } // TaskVirtualMachineEdges holds the relations/edges for other nodes in the graph. type TaskVirtualMachineEdges struct { // Task holds the value of the task edge. Task *Task `json:"task,omitempty"` // Virtualmachine holds the value of the virtualmachine edge. Virtualmachine *VirtualMachine `json:"virtualmachine,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [2]bool } // TaskOrErr returns the Task value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TaskVirtualMachineEdges) TaskOrErr() (*Task, error) { if e.Task != nil { return e.Task, nil } else if e.loadedTypes[0] { return nil, &NotFoundError{label: task.Label} } return nil, &NotLoadedError{edge: "task"} } // VirtualmachineOrErr returns the Virtualmachine value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TaskVirtualMachineEdges) VirtualmachineOrErr() (*VirtualMachine, error) { if e.Virtualmachine != nil { return e.Virtualmachine, nil } else if e.loadedTypes[1] { return nil, &NotFoundError{label: virtualmachine.Label} } return nil, &NotLoadedError{edge: "virtualmachine"} } // scanValues returns the types for scanning values from sql.Rows. func (*TaskVirtualMachine) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case taskvirtualmachine.FieldVirtualmachineID: values[i] = new(sql.NullString) case taskvirtualmachine.FieldCreatedAt: values[i] = new(sql.NullTime) case taskvirtualmachine.FieldID, taskvirtualmachine.FieldTaskID: 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 TaskVirtualMachine fields. func (_m *TaskVirtualMachine) 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 taskvirtualmachine.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 taskvirtualmachine.FieldTaskID: if value, ok := values[i].(*uuid.UUID); !ok { return fmt.Errorf("unexpected type %T for field task_id", values[i]) } else if value != nil { _m.TaskID = *value } case taskvirtualmachine.FieldVirtualmachineID: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field virtualmachine_id", values[i]) } else if value.Valid { _m.VirtualmachineID = value.String } case taskvirtualmachine.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 TaskVirtualMachine. // This includes values selected through modifiers, order, etc. func (_m *TaskVirtualMachine) Value(name string) (ent.Value, error) { return _m.selectValues.Get(name) } // QueryTask queries the "task" edge of the TaskVirtualMachine entity. func (_m *TaskVirtualMachine) QueryTask() *TaskQuery { return NewTaskVirtualMachineClient(_m.config).QueryTask(_m) } // QueryVirtualmachine queries the "virtualmachine" edge of the TaskVirtualMachine entity. func (_m *TaskVirtualMachine) QueryVirtualmachine() *VirtualMachineQuery { return NewTaskVirtualMachineClient(_m.config).QueryVirtualmachine(_m) } // Update returns a builder for updating this TaskVirtualMachine. // Note that you need to call TaskVirtualMachine.Unwrap() before calling this method if this TaskVirtualMachine // was returned from a transaction, and the transaction was committed or rolled back. func (_m *TaskVirtualMachine) Update() *TaskVirtualMachineUpdateOne { return NewTaskVirtualMachineClient(_m.config).UpdateOne(_m) } // Unwrap unwraps the TaskVirtualMachine 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 *TaskVirtualMachine) Unwrap() *TaskVirtualMachine { _tx, ok := _m.config.driver.(*txDriver) if !ok { panic("db: TaskVirtualMachine is not a transactional entity") } _m.config.driver = _tx.drv return _m } // String implements the fmt.Stringer. func (_m *TaskVirtualMachine) String() string { var builder strings.Builder builder.WriteString("TaskVirtualMachine(") builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString("task_id=") builder.WriteString(fmt.Sprintf("%v", _m.TaskID)) builder.WriteString(", ") builder.WriteString("virtualmachine_id=") builder.WriteString(_m.VirtualmachineID) builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) builder.WriteByte(')') return builder.String() } // TaskVirtualMachines is a parsable slice of TaskVirtualMachine. type TaskVirtualMachines []*TaskVirtualMachine