195 lines
6.1 KiB
Go
195 lines
6.1 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"code.icod.de/dalu/ka/ent/category"
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Category is the model entity for the Category schema.
|
|
type Category struct {
|
|
config `json:"-"`
|
|
// ID of the ent.
|
|
ID uuid.UUID `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"`
|
|
// Title holds the value of the "title" field.
|
|
Title string `json:"title,omitempty"`
|
|
// Description holds the value of the "description" field.
|
|
Description string `json:"description,omitempty"`
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
// The values are being populated by the CategoryQuery when eager-loading is set.
|
|
Edges CategoryEdges `json:"edges"`
|
|
selectValues sql.SelectValues
|
|
}
|
|
|
|
// CategoryEdges holds the relations/edges for other nodes in the graph.
|
|
type CategoryEdges struct {
|
|
// Posts holds the value of the posts edge.
|
|
Posts []*Post `json:"posts,omitempty"`
|
|
// loadedTypes holds the information for reporting if a
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
loadedTypes [1]bool
|
|
// totalCount holds the count of the edges above.
|
|
totalCount [1]map[string]int
|
|
|
|
namedPosts map[string][]*Post
|
|
}
|
|
|
|
// PostsOrErr returns the Posts value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e CategoryEdges) PostsOrErr() ([]*Post, error) {
|
|
if e.loadedTypes[0] {
|
|
return e.Posts, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "posts"}
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*Category) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case category.FieldTitle, category.FieldDescription:
|
|
values[i] = new(sql.NullString)
|
|
case category.FieldCreatedAt, category.FieldUpdatedAt:
|
|
values[i] = new(sql.NullTime)
|
|
case category.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 Category fields.
|
|
func (c *Category) 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 category.FieldID:
|
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
|
return fmt.Errorf("unexpected type %T for field id", values[i])
|
|
} else if value != nil {
|
|
c.ID = *value
|
|
}
|
|
case category.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 {
|
|
c.CreatedAt = value.Time
|
|
}
|
|
case category.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 {
|
|
c.UpdatedAt = value.Time
|
|
}
|
|
case category.FieldTitle:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field title", values[i])
|
|
} else if value.Valid {
|
|
c.Title = value.String
|
|
}
|
|
case category.FieldDescription:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field description", values[i])
|
|
} else if value.Valid {
|
|
c.Description = value.String
|
|
}
|
|
default:
|
|
c.selectValues.Set(columns[i], values[i])
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the Category.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (c *Category) Value(name string) (ent.Value, error) {
|
|
return c.selectValues.Get(name)
|
|
}
|
|
|
|
// QueryPosts queries the "posts" edge of the Category entity.
|
|
func (c *Category) QueryPosts() *PostQuery {
|
|
return NewCategoryClient(c.config).QueryPosts(c)
|
|
}
|
|
|
|
// Update returns a builder for updating this Category.
|
|
// Note that you need to call Category.Unwrap() before calling this method if this Category
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (c *Category) Update() *CategoryUpdateOne {
|
|
return NewCategoryClient(c.config).UpdateOne(c)
|
|
}
|
|
|
|
// Unwrap unwraps the Category 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 (c *Category) Unwrap() *Category {
|
|
_tx, ok := c.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("ent: Category is not a transactional entity")
|
|
}
|
|
c.config.driver = _tx.drv
|
|
return c
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (c *Category) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("Category(")
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", c.ID))
|
|
builder.WriteString("created_at=")
|
|
builder.WriteString(c.CreatedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("updated_at=")
|
|
builder.WriteString(c.UpdatedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("title=")
|
|
builder.WriteString(c.Title)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("description=")
|
|
builder.WriteString(c.Description)
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// NamedPosts returns the Posts named value or an error if the edge was not
|
|
// loaded in eager-loading with this name.
|
|
func (c *Category) NamedPosts(name string) ([]*Post, error) {
|
|
if c.Edges.namedPosts == nil {
|
|
return nil, &NotLoadedError{edge: name}
|
|
}
|
|
nodes, ok := c.Edges.namedPosts[name]
|
|
if !ok {
|
|
return nil, &NotLoadedError{edge: name}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
func (c *Category) appendNamedPosts(name string, edges ...*Post) {
|
|
if c.Edges.namedPosts == nil {
|
|
c.Edges.namedPosts = make(map[string][]*Post)
|
|
}
|
|
if len(edges) == 0 {
|
|
c.Edges.namedPosts[name] = []*Post{}
|
|
} else {
|
|
c.Edges.namedPosts[name] = append(c.Edges.namedPosts[name], edges...)
|
|
}
|
|
}
|
|
|
|
// Categories is a parsable slice of Category.
|
|
type Categories []*Category
|