mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-02 06:43:23 +08:00
143 lines
4.3 KiB
Go
143 lines
4.3 KiB
Go
// 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/consts"
|
|
"github.com/chaitin/MonkeyCode/backend/db/license"
|
|
)
|
|
|
|
// License is the model entity for the License schema.
|
|
type License struct {
|
|
config `json:"-"`
|
|
// ID of the ent.
|
|
ID int `json:"id,omitempty"`
|
|
// Type holds the value of the "type" field.
|
|
Type consts.LicenseType `json:"type,omitempty"`
|
|
// Data holds the value of the "data" field.
|
|
Data []byte `json:"data,omitempty"`
|
|
// Code holds the value of the "code" field.
|
|
Code string `json:"code,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 (*License) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case license.FieldData:
|
|
values[i] = new([]byte)
|
|
case license.FieldID:
|
|
values[i] = new(sql.NullInt64)
|
|
case license.FieldType, license.FieldCode:
|
|
values[i] = new(sql.NullString)
|
|
case license.FieldCreatedAt:
|
|
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 License fields.
|
|
func (l *License) 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 license.FieldID:
|
|
value, ok := values[i].(*sql.NullInt64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field id", value)
|
|
}
|
|
l.ID = int(value.Int64)
|
|
case license.FieldType:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field type", values[i])
|
|
} else if value.Valid {
|
|
l.Type = consts.LicenseType(value.String)
|
|
}
|
|
case license.FieldData:
|
|
if value, ok := values[i].(*[]byte); !ok {
|
|
return fmt.Errorf("unexpected type %T for field data", values[i])
|
|
} else if value != nil {
|
|
l.Data = *value
|
|
}
|
|
case license.FieldCode:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field code", values[i])
|
|
} else if value.Valid {
|
|
l.Code = value.String
|
|
}
|
|
case license.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 {
|
|
l.CreatedAt = value.Time
|
|
}
|
|
default:
|
|
l.selectValues.Set(columns[i], values[i])
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the License.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (l *License) Value(name string) (ent.Value, error) {
|
|
return l.selectValues.Get(name)
|
|
}
|
|
|
|
// Update returns a builder for updating this License.
|
|
// Note that you need to call License.Unwrap() before calling this method if this License
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (l *License) Update() *LicenseUpdateOne {
|
|
return NewLicenseClient(l.config).UpdateOne(l)
|
|
}
|
|
|
|
// Unwrap unwraps the License 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 (l *License) Unwrap() *License {
|
|
_tx, ok := l.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("db: License is not a transactional entity")
|
|
}
|
|
l.config.driver = _tx.drv
|
|
return l
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (l *License) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("License(")
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", l.ID))
|
|
builder.WriteString("type=")
|
|
builder.WriteString(fmt.Sprintf("%v", l.Type))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("data=")
|
|
builder.WriteString(fmt.Sprintf("%v", l.Data))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("code=")
|
|
builder.WriteString(l.Code)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("created_at=")
|
|
builder.WriteString(l.CreatedAt.Format(time.ANSIC))
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// Licenses is a parsable slice of License.
|
|
type Licenses []*License
|