mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-29 16:18:40 +08:00
209 lines
8.1 KiB
Go
209 lines
8.1 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/virtualmachinerecyclerecord"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// VirtualMachineRecycleRecord is the model entity for the VirtualMachineRecycleRecord schema.
|
|
type VirtualMachineRecycleRecord struct {
|
|
config `json:"-"`
|
|
// ID of the ent.
|
|
ID uuid.UUID `json:"id,omitempty"`
|
|
// VirtualmachineID holds the value of the "virtualmachine_id" field.
|
|
VirtualmachineID string `json:"virtualmachine_id,omitempty"`
|
|
// EnvironmentID holds the value of the "environment_id" field.
|
|
EnvironmentID string `json:"environment_id,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"`
|
|
// TaskIds holds the value of the "task_ids" field.
|
|
TaskIds []uuid.UUID `json:"task_ids,omitempty"`
|
|
// Method holds the value of the "method" field.
|
|
Method consts.VMRecycleMethod `json:"method,omitempty"`
|
|
// RemoteDeleted holds the value of the "remote_deleted" field.
|
|
RemoteDeleted bool `json:"remote_deleted,omitempty"`
|
|
// RecycledAt holds the value of the "recycled_at" field.
|
|
RecycledAt time.Time `json:"recycled_at,omitempty"`
|
|
// CreatedAt holds the value of the "created_at" field.
|
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
|
selectValues sql.SelectValues
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*VirtualMachineRecycleRecord) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case virtualmachinerecyclerecord.FieldUserID:
|
|
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
|
case virtualmachinerecyclerecord.FieldTaskIds:
|
|
values[i] = new([]byte)
|
|
case virtualmachinerecyclerecord.FieldRemoteDeleted:
|
|
values[i] = new(sql.NullBool)
|
|
case virtualmachinerecyclerecord.FieldVirtualmachineID, virtualmachinerecyclerecord.FieldEnvironmentID, virtualmachinerecyclerecord.FieldHostID, virtualmachinerecyclerecord.FieldMethod:
|
|
values[i] = new(sql.NullString)
|
|
case virtualmachinerecyclerecord.FieldRecycledAt, virtualmachinerecyclerecord.FieldCreatedAt:
|
|
values[i] = new(sql.NullTime)
|
|
case virtualmachinerecyclerecord.FieldID:
|
|
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 VirtualMachineRecycleRecord fields.
|
|
func (_m *VirtualMachineRecycleRecord) 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 virtualmachinerecyclerecord.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 virtualmachinerecyclerecord.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 virtualmachinerecyclerecord.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 virtualmachinerecyclerecord.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 virtualmachinerecyclerecord.FieldUserID:
|
|
if value, ok := values[i].(*sql.NullScanner); !ok {
|
|
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
|
} else if value.Valid {
|
|
_m.UserID = new(uuid.UUID)
|
|
*_m.UserID = *value.S.(*uuid.UUID)
|
|
}
|
|
case virtualmachinerecyclerecord.FieldTaskIds:
|
|
if value, ok := values[i].(*[]byte); !ok {
|
|
return fmt.Errorf("unexpected type %T for field task_ids", values[i])
|
|
} else if value != nil && len(*value) > 0 {
|
|
if err := json.Unmarshal(*value, &_m.TaskIds); err != nil {
|
|
return fmt.Errorf("unmarshal field task_ids: %w", err)
|
|
}
|
|
}
|
|
case virtualmachinerecyclerecord.FieldMethod:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field method", values[i])
|
|
} else if value.Valid {
|
|
_m.Method = consts.VMRecycleMethod(value.String)
|
|
}
|
|
case virtualmachinerecyclerecord.FieldRemoteDeleted:
|
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
|
return fmt.Errorf("unexpected type %T for field remote_deleted", values[i])
|
|
} else if value.Valid {
|
|
_m.RemoteDeleted = value.Bool
|
|
}
|
|
case virtualmachinerecyclerecord.FieldRecycledAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field recycled_at", values[i])
|
|
} else if value.Valid {
|
|
_m.RecycledAt = value.Time
|
|
}
|
|
case virtualmachinerecyclerecord.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 VirtualMachineRecycleRecord.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (_m *VirtualMachineRecycleRecord) Value(name string) (ent.Value, error) {
|
|
return _m.selectValues.Get(name)
|
|
}
|
|
|
|
// Update returns a builder for updating this VirtualMachineRecycleRecord.
|
|
// Note that you need to call VirtualMachineRecycleRecord.Unwrap() before calling this method if this VirtualMachineRecycleRecord
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (_m *VirtualMachineRecycleRecord) Update() *VirtualMachineRecycleRecordUpdateOne {
|
|
return NewVirtualMachineRecycleRecordClient(_m.config).UpdateOne(_m)
|
|
}
|
|
|
|
// Unwrap unwraps the VirtualMachineRecycleRecord 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 *VirtualMachineRecycleRecord) Unwrap() *VirtualMachineRecycleRecord {
|
|
_tx, ok := _m.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("db: VirtualMachineRecycleRecord is not a transactional entity")
|
|
}
|
|
_m.config.driver = _tx.drv
|
|
return _m
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (_m *VirtualMachineRecycleRecord) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("VirtualMachineRecycleRecord(")
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
|
builder.WriteString("virtualmachine_id=")
|
|
builder.WriteString(_m.VirtualmachineID)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("environment_id=")
|
|
builder.WriteString(_m.EnvironmentID)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("host_id=")
|
|
builder.WriteString(_m.HostID)
|
|
builder.WriteString(", ")
|
|
if v := _m.UserID; v != nil {
|
|
builder.WriteString("user_id=")
|
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
|
}
|
|
builder.WriteString(", ")
|
|
builder.WriteString("task_ids=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.TaskIds))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("method=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Method))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("remote_deleted=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.RemoteDeleted))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("recycled_at=")
|
|
builder.WriteString(_m.RecycledAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("created_at=")
|
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// VirtualMachineRecycleRecords is a parsable slice of VirtualMachineRecycleRecord.
|
|
type VirtualMachineRecycleRecords []*VirtualMachineRecycleRecord
|