// 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/host" "github.com/chaitin/MonkeyCode/backend/db/model" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/chaitin/MonkeyCode/backend/db/virtualmachine" "github.com/chaitin/MonkeyCode/backend/ent/types" "github.com/google/uuid" ) // VirtualMachine is the model entity for the VirtualMachine schema. type VirtualMachine struct { config `json:"-"` // ID of the ent. ID string `json:"id,omitempty"` // DeletedAt holds the value of the "deleted_at" field. DeletedAt time.Time `json:"deleted_at,omitempty"` // HostID holds the value of the "host_id" field. HostID string `json:"host_id,omitempty"` // UserID holds the value of the "user_id" field. UserID uuid.UUID `json:"user_id,omitempty"` // ModelID holds the value of the "model_id" field. ModelID uuid.UUID `json:"model_id,omitempty"` // EnvironmentID holds the value of the "environment_id" field. EnvironmentID string `json:"environment_id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` // Hostname holds the value of the "hostname" field. Hostname string `json:"hostname,omitempty"` // Arch holds the value of the "arch" field. Arch string `json:"arch,omitempty"` // Cores holds the value of the "cores" field. Cores int `json:"cores,omitempty"` // Memory holds the value of the "memory" field. Memory int64 `json:"memory,omitempty"` // Os holds the value of the "os" field. Os string `json:"os,omitempty"` // ExternalIP holds the value of the "external_ip" field. ExternalIP string `json:"external_ip,omitempty"` // InternalIP holds the value of the "internal_ip" field. InternalIP string `json:"internal_ip,omitempty"` // TTLKind holds the value of the "ttl_kind" field. TTLKind consts.VirtualmachineTTLKind `json:"ttl_kind,omitempty"` // TTL holds the value of the "ttl" field. TTL int64 `json:"ttl,omitempty"` // Version holds the value of the "version" field. Version string `json:"version,omitempty"` // MachineID holds the value of the "machine_id" field. MachineID string `json:"machine_id,omitempty"` // RepoURL holds the value of the "repo_url" field. RepoURL string `json:"repo_url,omitempty"` // RepoFilename holds the value of the "repo_filename" field. RepoFilename string `json:"repo_filename,omitempty"` // Branch holds the value of the "branch" field. Branch string `json:"branch,omitempty"` // IsRecycled holds the value of the "is_recycled" field. IsRecycled bool `json:"is_recycled,omitempty"` // Conditions holds the value of the "conditions" field. Conditions *types.VirtualMachineCondition `json:"conditions,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 VirtualMachineQuery when eager-loading is set. Edges VirtualMachineEdges `json:"edges"` selectValues sql.SelectValues } // VirtualMachineEdges holds the relations/edges for other nodes in the graph. type VirtualMachineEdges struct { // Host holds the value of the host edge. Host *Host `json:"host,omitempty"` // Model holds the value of the model edge. Model *Model `json:"model,omitempty"` // User holds the value of the user edge. User *User `json:"user,omitempty"` // Tasks holds the value of the tasks edge. Tasks []*Task `json:"tasks,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 [5]bool } // HostOrErr returns the Host value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e VirtualMachineEdges) HostOrErr() (*Host, error) { if e.Host != nil { return e.Host, nil } else if e.loadedTypes[0] { return nil, &NotFoundError{label: host.Label} } return nil, &NotLoadedError{edge: "host"} } // ModelOrErr returns the Model value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e VirtualMachineEdges) ModelOrErr() (*Model, error) { if e.Model != nil { return e.Model, nil } else if e.loadedTypes[1] { return nil, &NotFoundError{label: model.Label} } return nil, &NotLoadedError{edge: "model"} } // 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 VirtualMachineEdges) 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"} } // TasksOrErr returns the Tasks value or an error if the edge // was not loaded in eager-loading. func (e VirtualMachineEdges) TasksOrErr() ([]*Task, error) { if e.loadedTypes[3] { return e.Tasks, nil } return nil, &NotLoadedError{edge: "tasks"} } // TaskVmsOrErr returns the TaskVms value or an error if the edge // was not loaded in eager-loading. func (e VirtualMachineEdges) TaskVmsOrErr() ([]*TaskVirtualMachine, error) { if e.loadedTypes[4] { return e.TaskVms, nil } return nil, &NotLoadedError{edge: "task_vms"} } // scanValues returns the types for scanning values from sql.Rows. func (*VirtualMachine) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case virtualmachine.FieldConditions: values[i] = new([]byte) case virtualmachine.FieldIsRecycled: values[i] = new(sql.NullBool) case virtualmachine.FieldCores, virtualmachine.FieldMemory, virtualmachine.FieldTTL: values[i] = new(sql.NullInt64) case virtualmachine.FieldID, virtualmachine.FieldHostID, virtualmachine.FieldEnvironmentID, virtualmachine.FieldName, virtualmachine.FieldHostname, virtualmachine.FieldArch, virtualmachine.FieldOs, virtualmachine.FieldExternalIP, virtualmachine.FieldInternalIP, virtualmachine.FieldTTLKind, virtualmachine.FieldVersion, virtualmachine.FieldMachineID, virtualmachine.FieldRepoURL, virtualmachine.FieldRepoFilename, virtualmachine.FieldBranch: values[i] = new(sql.NullString) case virtualmachine.FieldDeletedAt, virtualmachine.FieldCreatedAt, virtualmachine.FieldUpdatedAt: values[i] = new(sql.NullTime) case virtualmachine.FieldUserID, virtualmachine.FieldModelID: 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 VirtualMachine fields. func (_m *VirtualMachine) 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 virtualmachine.FieldID: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field id", values[i]) } else if value.Valid { _m.ID = value.String } case virtualmachine.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 virtualmachine.FieldHostID: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field host_id", values[i]) } else if value.Valid { _m.HostID = value.String } case virtualmachine.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 virtualmachine.FieldModelID: if value, ok := values[i].(*uuid.UUID); !ok { return fmt.Errorf("unexpected type %T for field model_id", values[i]) } else if value != nil { _m.ModelID = *value } case virtualmachine.FieldEnvironmentID: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field environment_id", values[i]) } else if value.Valid { _m.EnvironmentID = value.String } case virtualmachine.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 virtualmachine.FieldHostname: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field hostname", values[i]) } else if value.Valid { _m.Hostname = value.String } case virtualmachine.FieldArch: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field arch", values[i]) } else if value.Valid { _m.Arch = value.String } case virtualmachine.FieldCores: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field cores", values[i]) } else if value.Valid { _m.Cores = int(value.Int64) } case virtualmachine.FieldMemory: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field memory", values[i]) } else if value.Valid { _m.Memory = value.Int64 } case virtualmachine.FieldOs: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field os", values[i]) } else if value.Valid { _m.Os = value.String } case virtualmachine.FieldExternalIP: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field external_ip", values[i]) } else if value.Valid { _m.ExternalIP = value.String } case virtualmachine.FieldInternalIP: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field internal_ip", values[i]) } else if value.Valid { _m.InternalIP = value.String } case virtualmachine.FieldTTLKind: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field ttl_kind", values[i]) } else if value.Valid { _m.TTLKind = consts.VirtualmachineTTLKind(value.String) } case virtualmachine.FieldTTL: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field ttl", values[i]) } else if value.Valid { _m.TTL = value.Int64 } case virtualmachine.FieldVersion: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field version", values[i]) } else if value.Valid { _m.Version = value.String } case virtualmachine.FieldMachineID: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field machine_id", values[i]) } else if value.Valid { _m.MachineID = value.String } case virtualmachine.FieldRepoURL: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field repo_url", values[i]) } else if value.Valid { _m.RepoURL = value.String } case virtualmachine.FieldRepoFilename: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field repo_filename", values[i]) } else if value.Valid { _m.RepoFilename = value.String } case virtualmachine.FieldBranch: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field branch", values[i]) } else if value.Valid { _m.Branch = value.String } case virtualmachine.FieldIsRecycled: if value, ok := values[i].(*sql.NullBool); !ok { return fmt.Errorf("unexpected type %T for field is_recycled", values[i]) } else if value.Valid { _m.IsRecycled = value.Bool } case virtualmachine.FieldConditions: if value, ok := values[i].(*[]byte); !ok { return fmt.Errorf("unexpected type %T for field conditions", values[i]) } else if value != nil && len(*value) > 0 { if err := json.Unmarshal(*value, &_m.Conditions); err != nil { return fmt.Errorf("unmarshal field conditions: %w", err) } } case virtualmachine.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 virtualmachine.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 VirtualMachine. // This includes values selected through modifiers, order, etc. func (_m *VirtualMachine) Value(name string) (ent.Value, error) { return _m.selectValues.Get(name) } // QueryHost queries the "host" edge of the VirtualMachine entity. func (_m *VirtualMachine) QueryHost() *HostQuery { return NewVirtualMachineClient(_m.config).QueryHost(_m) } // QueryModel queries the "model" edge of the VirtualMachine entity. func (_m *VirtualMachine) QueryModel() *ModelQuery { return NewVirtualMachineClient(_m.config).QueryModel(_m) } // QueryUser queries the "user" edge of the VirtualMachine entity. func (_m *VirtualMachine) QueryUser() *UserQuery { return NewVirtualMachineClient(_m.config).QueryUser(_m) } // QueryTasks queries the "tasks" edge of the VirtualMachine entity. func (_m *VirtualMachine) QueryTasks() *TaskQuery { return NewVirtualMachineClient(_m.config).QueryTasks(_m) } // QueryTaskVms queries the "task_vms" edge of the VirtualMachine entity. func (_m *VirtualMachine) QueryTaskVms() *TaskVirtualMachineQuery { return NewVirtualMachineClient(_m.config).QueryTaskVms(_m) } // Update returns a builder for updating this VirtualMachine. // Note that you need to call VirtualMachine.Unwrap() before calling this method if this VirtualMachine // was returned from a transaction, and the transaction was committed or rolled back. func (_m *VirtualMachine) Update() *VirtualMachineUpdateOne { return NewVirtualMachineClient(_m.config).UpdateOne(_m) } // Unwrap unwraps the VirtualMachine 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 *VirtualMachine) Unwrap() *VirtualMachine { _tx, ok := _m.config.driver.(*txDriver) if !ok { panic("db: VirtualMachine is not a transactional entity") } _m.config.driver = _tx.drv return _m } // String implements the fmt.Stringer. func (_m *VirtualMachine) String() string { var builder strings.Builder builder.WriteString("VirtualMachine(") builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString("deleted_at=") builder.WriteString(_m.DeletedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("host_id=") builder.WriteString(_m.HostID) builder.WriteString(", ") builder.WriteString("user_id=") builder.WriteString(fmt.Sprintf("%v", _m.UserID)) builder.WriteString(", ") builder.WriteString("model_id=") builder.WriteString(fmt.Sprintf("%v", _m.ModelID)) builder.WriteString(", ") builder.WriteString("environment_id=") builder.WriteString(_m.EnvironmentID) builder.WriteString(", ") builder.WriteString("name=") builder.WriteString(_m.Name) builder.WriteString(", ") builder.WriteString("hostname=") builder.WriteString(_m.Hostname) builder.WriteString(", ") builder.WriteString("arch=") builder.WriteString(_m.Arch) builder.WriteString(", ") builder.WriteString("cores=") builder.WriteString(fmt.Sprintf("%v", _m.Cores)) builder.WriteString(", ") builder.WriteString("memory=") builder.WriteString(fmt.Sprintf("%v", _m.Memory)) builder.WriteString(", ") builder.WriteString("os=") builder.WriteString(_m.Os) builder.WriteString(", ") builder.WriteString("external_ip=") builder.WriteString(_m.ExternalIP) builder.WriteString(", ") builder.WriteString("internal_ip=") builder.WriteString(_m.InternalIP) builder.WriteString(", ") builder.WriteString("ttl_kind=") builder.WriteString(fmt.Sprintf("%v", _m.TTLKind)) builder.WriteString(", ") builder.WriteString("ttl=") builder.WriteString(fmt.Sprintf("%v", _m.TTL)) builder.WriteString(", ") builder.WriteString("version=") builder.WriteString(_m.Version) builder.WriteString(", ") builder.WriteString("machine_id=") builder.WriteString(_m.MachineID) builder.WriteString(", ") builder.WriteString("repo_url=") builder.WriteString(_m.RepoURL) builder.WriteString(", ") builder.WriteString("repo_filename=") builder.WriteString(_m.RepoFilename) builder.WriteString(", ") builder.WriteString("branch=") builder.WriteString(_m.Branch) builder.WriteString(", ") builder.WriteString("is_recycled=") builder.WriteString(fmt.Sprintf("%v", _m.IsRecycled)) builder.WriteString(", ") builder.WriteString("conditions=") builder.WriteString(fmt.Sprintf("%v", _m.Conditions)) 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() } // VirtualMachines is a parsable slice of VirtualMachine. type VirtualMachines []*VirtualMachine