You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudreve/ent/sku.go

247 lines
8.0 KiB

// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/cloudreve/Cloudreve/v4/ent/sku"
)
// Sku is the model entity for the Sku schema.
type Sku struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,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"`
// DeletedAt holds the value of the "deleted_at" field.
DeletedAt *time.Time `json:"deleted_at,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Type holds the value of the "type" field.
Type sku.Type `json:"type,omitempty"`
// Amount holds the value of the "amount" field.
Amount int64 `json:"amount,omitempty"`
// Duration holds the value of the "duration" field.
Duration int64 `json:"duration,omitempty"`
// Price holds the value of the "price" field.
Price int64 `json:"price,omitempty"`
// Points holds the value of the "points" field.
Points *int64 `json:"points,omitempty"`
// Label holds the value of the "label" field.
Label string `json:"label,omitempty"`
// Des holds the value of the "des" field.
Des string `json:"des,omitempty"`
// Enabled holds the value of the "enabled" field.
Enabled bool `json:"enabled,omitempty"`
// Weight holds the value of the "weight" field.
Weight int `json:"weight,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Sku) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case sku.FieldEnabled:
values[i] = new(sql.NullBool)
case sku.FieldID, sku.FieldAmount, sku.FieldDuration, sku.FieldPrice, sku.FieldPoints, sku.FieldWeight:
values[i] = new(sql.NullInt64)
case sku.FieldName, sku.FieldType, sku.FieldLabel, sku.FieldDes:
values[i] = new(sql.NullString)
case sku.FieldCreatedAt, sku.FieldUpdatedAt, sku.FieldDeletedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Sku fields.
func (s *Sku) 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 sku.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
s.ID = int(value.Int64)
case sku.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 {
s.CreatedAt = value.Time
}
case sku.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 {
s.UpdatedAt = value.Time
}
case sku.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 {
s.DeletedAt = new(time.Time)
*s.DeletedAt = value.Time
}
case sku.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
s.Name = value.String
}
case sku.FieldType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field type", values[i])
} else if value.Valid {
s.Type = sku.Type(value.String)
}
case sku.FieldAmount:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field amount", values[i])
} else if value.Valid {
s.Amount = value.Int64
}
case sku.FieldDuration:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field duration", values[i])
} else if value.Valid {
s.Duration = value.Int64
}
case sku.FieldPrice:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field price", values[i])
} else if value.Valid {
s.Price = value.Int64
}
case sku.FieldPoints:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field points", values[i])
} else if value.Valid {
s.Points = new(int64)
*s.Points = value.Int64
}
case sku.FieldLabel:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field label", values[i])
} else if value.Valid {
s.Label = value.String
}
case sku.FieldDes:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field des", values[i])
} else if value.Valid {
s.Des = value.String
}
case sku.FieldEnabled:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field enabled", values[i])
} else if value.Valid {
s.Enabled = value.Bool
}
case sku.FieldWeight:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field weight", values[i])
} else if value.Valid {
s.Weight = int(value.Int64)
}
default:
s.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Sku.
// This includes values selected through modifiers, order, etc.
func (s *Sku) Value(name string) (ent.Value, error) {
return s.selectValues.Get(name)
}
// Update returns a builder for updating this Sku.
// Note that you need to call Sku.Unwrap() before calling this method if this Sku
// was returned from a transaction, and the transaction was committed or rolled back.
func (s *Sku) Update() *SkuUpdateOne {
return NewSkuClient(s.config).UpdateOne(s)
}
// Unwrap unwraps the Sku 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 (s *Sku) Unwrap() *Sku {
_tx, ok := s.config.driver.(*txDriver)
if !ok {
panic("ent: Sku is not a transactional entity")
}
s.config.driver = _tx.drv
return s
}
// String implements the fmt.Stringer.
func (s *Sku) String() string {
var builder strings.Builder
builder.WriteString("Sku(")
builder.WriteString(fmt.Sprintf("id=%v, ", s.ID))
builder.WriteString("created_at=")
builder.WriteString(s.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(s.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := s.DeletedAt; v != nil {
builder.WriteString("deleted_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(s.Name)
builder.WriteString(", ")
builder.WriteString("type=")
builder.WriteString(fmt.Sprintf("%v", s.Type))
builder.WriteString(", ")
builder.WriteString("amount=")
builder.WriteString(fmt.Sprintf("%v", s.Amount))
builder.WriteString(", ")
builder.WriteString("duration=")
builder.WriteString(fmt.Sprintf("%v", s.Duration))
builder.WriteString(", ")
builder.WriteString("price=")
builder.WriteString(fmt.Sprintf("%v", s.Price))
builder.WriteString(", ")
if v := s.Points; v != nil {
builder.WriteString("points=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
builder.WriteString("label=")
builder.WriteString(s.Label)
builder.WriteString(", ")
builder.WriteString("des=")
builder.WriteString(s.Des)
builder.WriteString(", ")
builder.WriteString("enabled=")
builder.WriteString(fmt.Sprintf("%v", s.Enabled))
builder.WriteString(", ")
builder.WriteString("weight=")
builder.WriteString(fmt.Sprintf("%v", s.Weight))
builder.WriteByte(')')
return builder.String()
}
// Skus is a parsable slice of Sku.
type Skus []*Sku