TinySkin/db/ent/skin.go
2023-09-03 17:00:10 +08:00

167 lines
5.2 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/xmdhs/authlib-skin/db/ent/skin"
"github.com/xmdhs/authlib-skin/db/ent/user"
)
// Skin is the model entity for the Skin schema.
type Skin struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// SkinHash holds the value of the "skin_hash" field.
SkinHash string `json:"skin_hash,omitempty"`
// Type holds the value of the "type" field.
Type uint8 `json:"type,omitempty"`
// Variant holds the value of the "variant" field.
Variant string `json:"variant,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the SkinQuery when eager-loading is set.
Edges SkinEdges `json:"edges"`
skin_created_user *int
selectValues sql.SelectValues
}
// SkinEdges holds the relations/edges for other nodes in the graph.
type SkinEdges struct {
// CreatedUser holds the value of the created_user edge.
CreatedUser *User `json:"created_user,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// CreatedUserOrErr returns the CreatedUser value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e SkinEdges) CreatedUserOrErr() (*User, error) {
if e.loadedTypes[0] {
if e.CreatedUser == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: user.Label}
}
return e.CreatedUser, nil
}
return nil, &NotLoadedError{edge: "created_user"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Skin) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case skin.FieldID, skin.FieldType:
values[i] = new(sql.NullInt64)
case skin.FieldSkinHash, skin.FieldVariant:
values[i] = new(sql.NullString)
case skin.ForeignKeys[0]: // skin_created_user
values[i] = new(sql.NullInt64)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Skin fields.
func (s *Skin) 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 skin.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 skin.FieldSkinHash:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field skin_hash", values[i])
} else if value.Valid {
s.SkinHash = value.String
}
case skin.FieldType:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field type", values[i])
} else if value.Valid {
s.Type = uint8(value.Int64)
}
case skin.FieldVariant:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field variant", values[i])
} else if value.Valid {
s.Variant = value.String
}
case skin.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field skin_created_user", value)
} else if value.Valid {
s.skin_created_user = new(int)
*s.skin_created_user = 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 Skin.
// This includes values selected through modifiers, order, etc.
func (s *Skin) Value(name string) (ent.Value, error) {
return s.selectValues.Get(name)
}
// QueryCreatedUser queries the "created_user" edge of the Skin entity.
func (s *Skin) QueryCreatedUser() *UserQuery {
return NewSkinClient(s.config).QueryCreatedUser(s)
}
// Update returns a builder for updating this Skin.
// Note that you need to call Skin.Unwrap() before calling this method if this Skin
// was returned from a transaction, and the transaction was committed or rolled back.
func (s *Skin) Update() *SkinUpdateOne {
return NewSkinClient(s.config).UpdateOne(s)
}
// Unwrap unwraps the Skin 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 *Skin) Unwrap() *Skin {
_tx, ok := s.config.driver.(*txDriver)
if !ok {
panic("ent: Skin is not a transactional entity")
}
s.config.driver = _tx.drv
return s
}
// String implements the fmt.Stringer.
func (s *Skin) String() string {
var builder strings.Builder
builder.WriteString("Skin(")
builder.WriteString(fmt.Sprintf("id=%v, ", s.ID))
builder.WriteString("skin_hash=")
builder.WriteString(s.SkinHash)
builder.WriteString(", ")
builder.WriteString("type=")
builder.WriteString(fmt.Sprintf("%v", s.Type))
builder.WriteString(", ")
builder.WriteString("variant=")
builder.WriteString(s.Variant)
builder.WriteByte(')')
return builder.String()
}
// Skins is a parsable slice of Skin.
type Skins []*Skin