// Code generated by ent, DO NOT EDIT. package ent import ( "fmt" "strings" "time" "code.icod.de/dalu/ka/ent/category" "code.icod.de/dalu/ka/ent/post" "code.icod.de/dalu/ka/ent/profile" "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" ) // Post is the model entity for the Post schema. type Post 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"` // Expires holds the value of the "expires" field. Expires bool `json:"expires,omitempty"` // ExpireTime holds the value of the "expire_time" field. ExpireTime *time.Time `json:"expire_time,omitempty"` // Title holds the value of the "title" field. Title string `json:"title,omitempty"` // Body holds the value of the "body" field. Body string `json:"body,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 *uuid.UUID profile_posts *uuid.UUID selectValues sql.SelectValues } // PostEdges holds the relations/edges for other nodes in the graph. type PostEdges struct { // Category holds the value of the category edge. Category *Category `json:"category,omitempty"` // Profile holds the value of the profile edge. Profile *Profile `json:"profile,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [2]bool // totalCount holds the count of the edges above. totalCount [2]map[string]int } // 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[0] { return nil, &NotFoundError{label: category.Label} } return nil, &NotLoadedError{edge: "category"} } // ProfileOrErr returns the Profile value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e PostEdges) ProfileOrErr() (*Profile, error) { if e.Profile != nil { return e.Profile, nil } else if e.loadedTypes[1] { return nil, &NotFoundError{label: profile.Label} } return nil, &NotLoadedError{edge: "profile"} } // 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.FieldExpires: values[i] = new(sql.NullBool) case post.FieldTitle, post.FieldBody: values[i] = new(sql.NullString) case post.FieldCreatedAt, post.FieldUpdatedAt, post.FieldExpireTime: values[i] = new(sql.NullTime) case post.FieldID: values[i] = new(uuid.UUID) case post.ForeignKeys[0]: // category_posts values[i] = &sql.NullScanner{S: new(uuid.UUID)} case post.ForeignKeys[1]: // profile_posts values[i] = &sql.NullScanner{S: 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 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: if value, ok := values[i].(*uuid.UUID); !ok { return fmt.Errorf("unexpected type %T for field id", values[i]) } else if value != nil { po.ID = *value } 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.FieldExpires: if value, ok := values[i].(*sql.NullBool); !ok { return fmt.Errorf("unexpected type %T for field expires", values[i]) } else if value.Valid { po.Expires = value.Bool } case post.FieldExpireTime: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field expire_time", values[i]) } else if value.Valid { po.ExpireTime = new(time.Time) *po.ExpireTime = value.Time } case post.FieldTitle: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field title", values[i]) } else if value.Valid { po.Title = value.String } case post.FieldBody: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field body", values[i]) } else if value.Valid { po.Body = value.String } case post.ForeignKeys[0]: if value, ok := values[i].(*sql.NullScanner); !ok { return fmt.Errorf("unexpected type %T for field category_posts", values[i]) } else if value.Valid { po.category_posts = new(uuid.UUID) *po.category_posts = *value.S.(*uuid.UUID) } case post.ForeignKeys[1]: if value, ok := values[i].(*sql.NullScanner); !ok { return fmt.Errorf("unexpected type %T for field profile_posts", values[i]) } else if value.Valid { po.profile_posts = new(uuid.UUID) *po.profile_posts = *value.S.(*uuid.UUID) } 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) } // QueryCategory queries the "category" edge of the Post entity. func (po *Post) QueryCategory() *CategoryQuery { return NewPostClient(po.config).QueryCategory(po) } // QueryProfile queries the "profile" edge of the Post entity. func (po *Post) QueryProfile() *ProfileQuery { return NewPostClient(po.config).QueryProfile(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("created_at=") builder.WriteString(po.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("updated_at=") builder.WriteString(po.UpdatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("expires=") builder.WriteString(fmt.Sprintf("%v", po.Expires)) builder.WriteString(", ") if v := po.ExpireTime; v != nil { builder.WriteString("expire_time=") builder.WriteString(v.Format(time.ANSIC)) } builder.WriteString(", ") builder.WriteString("title=") builder.WriteString(po.Title) builder.WriteString(", ") builder.WriteString("body=") builder.WriteString(po.Body) builder.WriteByte(')') return builder.String() } // Posts is a parsable slice of Post. type Posts []*Post