tss-rocks/backend/ent/post.go
CDN 05ddc1f783
Some checks failed
Build Backend / Build Docker Image (push) Successful in 3m33s
Test Backend / test (push) Failing after 31s
[feature] migrate to monorepo
2025-02-21 00:49:20 +08:00

210 lines
6.8 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"tss-rocks-be/ent/category"
"tss-rocks-be/ent/post"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// Post is the model entity for the Post schema.
type Post struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Status holds the value of the "status" field.
Status post.Status `json:"status,omitempty"`
// Slug holds the value of the "slug" field.
Slug string `json:"slug,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"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the PostQuery when eager-loading is set.
Edges PostEdges `json:"edges"`
category_posts *int
selectValues sql.SelectValues
}
// PostEdges holds the relations/edges for other nodes in the graph.
type PostEdges struct {
// Contents holds the value of the contents edge.
Contents []*PostContent `json:"contents,omitempty"`
// Contributors holds the value of the contributors edge.
Contributors []*PostContributor `json:"contributors,omitempty"`
// Category holds the value of the category edge.
Category *Category `json:"category,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [3]bool
}
// ContentsOrErr returns the Contents value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) ContentsOrErr() ([]*PostContent, error) {
if e.loadedTypes[0] {
return e.Contents, nil
}
return nil, &NotLoadedError{edge: "contents"}
}
// ContributorsOrErr returns the Contributors value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) ContributorsOrErr() ([]*PostContributor, error) {
if e.loadedTypes[1] {
return e.Contributors, nil
}
return nil, &NotLoadedError{edge: "contributors"}
}
// CategoryOrErr returns the Category value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e PostEdges) CategoryOrErr() (*Category, error) {
if e.Category != nil {
return e.Category, nil
} else if e.loadedTypes[2] {
return nil, &NotFoundError{label: category.Label}
}
return nil, &NotLoadedError{edge: "category"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Post) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case post.FieldID:
values[i] = new(sql.NullInt64)
case post.FieldStatus, post.FieldSlug:
values[i] = new(sql.NullString)
case post.FieldCreatedAt, post.FieldUpdatedAt:
values[i] = new(sql.NullTime)
case post.ForeignKeys[0]: // category_posts
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 Post fields.
func (po *Post) 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 post.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
po.ID = int(value.Int64)
case post.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
po.Status = post.Status(value.String)
}
case post.FieldSlug:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field slug", values[i])
} else if value.Valid {
po.Slug = value.String
}
case post.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 {
po.CreatedAt = value.Time
}
case post.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 {
po.UpdatedAt = value.Time
}
case post.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field category_posts", value)
} else if value.Valid {
po.category_posts = new(int)
*po.category_posts = int(value.Int64)
}
default:
po.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Post.
// This includes values selected through modifiers, order, etc.
func (po *Post) Value(name string) (ent.Value, error) {
return po.selectValues.Get(name)
}
// QueryContents queries the "contents" edge of the Post entity.
func (po *Post) QueryContents() *PostContentQuery {
return NewPostClient(po.config).QueryContents(po)
}
// QueryContributors queries the "contributors" edge of the Post entity.
func (po *Post) QueryContributors() *PostContributorQuery {
return NewPostClient(po.config).QueryContributors(po)
}
// QueryCategory queries the "category" edge of the Post entity.
func (po *Post) QueryCategory() *CategoryQuery {
return NewPostClient(po.config).QueryCategory(po)
}
// Update returns a builder for updating this Post.
// Note that you need to call Post.Unwrap() before calling this method if this Post
// was returned from a transaction, and the transaction was committed or rolled back.
func (po *Post) Update() *PostUpdateOne {
return NewPostClient(po.config).UpdateOne(po)
}
// Unwrap unwraps the Post 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 (po *Post) Unwrap() *Post {
_tx, ok := po.config.driver.(*txDriver)
if !ok {
panic("ent: Post is not a transactional entity")
}
po.config.driver = _tx.drv
return po
}
// String implements the fmt.Stringer.
func (po *Post) String() string {
var builder strings.Builder
builder.WriteString("Post(")
builder.WriteString(fmt.Sprintf("id=%v, ", po.ID))
builder.WriteString("status=")
builder.WriteString(fmt.Sprintf("%v", po.Status))
builder.WriteString(", ")
builder.WriteString("slug=")
builder.WriteString(po.Slug)
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(po.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(po.UpdatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// Posts is a parsable slice of Post.
type Posts []*Post