post.go•20.5 kB
// Code generated by ent, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Southclaws/storyden/internal/ent/account"
"github.com/Southclaws/storyden/internal/ent/category"
"github.com/Southclaws/storyden/internal/ent/link"
"github.com/Southclaws/storyden/internal/ent/post"
"github.com/rs/xid"
)
// Post is the model entity for the Post schema.
type Post struct {
config `json:"-"`
// ID of the ent.
ID xid.ID `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"`
// DeletedAt holds the value of the "deleted_at" field.
DeletedAt *time.Time `json:"deleted_at,omitempty"`
// IndexedAt holds the value of the "indexed_at" field.
IndexedAt *time.Time `json:"indexed_at,omitempty"`
// First holds the value of the "first" field.
First bool `json:"first,omitempty"`
// Title holds the value of the "title" field.
Title string `json:"title,omitempty"`
// Slug holds the value of the "slug" field.
Slug string `json:"slug,omitempty"`
// Pinned holds the value of the "pinned" field.
Pinned bool `json:"pinned,omitempty"`
// LastReplyAt holds the value of the "last_reply_at" field.
LastReplyAt *time.Time `json:"last_reply_at,omitempty"`
// RootPostID holds the value of the "root_post_id" field.
RootPostID xid.ID `json:"root_post_id,omitempty"`
// ReplyToPostID holds the value of the "reply_to_post_id" field.
ReplyToPostID xid.ID `json:"reply_to_post_id,omitempty"`
// Body holds the value of the "body" field.
Body string `json:"body,omitempty"`
// Short holds the value of the "short" field.
Short string `json:"short,omitempty"`
// Arbitrary metadata used by clients to store domain specific information.
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Visibility holds the value of the "visibility" field.
Visibility post.Visibility `json:"visibility,omitempty"`
// AccountPosts holds the value of the "account_posts" field.
AccountPosts xid.ID `json:"account_posts,omitempty"`
// CategoryID holds the value of the "category_id" field.
CategoryID xid.ID `json:"category_id,omitempty"`
// LinkID holds the value of the "link_id" field.
LinkID xid.ID `json:"link_id,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"`
selectValues sql.SelectValues
}
// PostEdges holds the relations/edges for other nodes in the graph.
type PostEdges struct {
// Author holds the value of the author edge.
Author *Account `json:"author,omitempty"`
// Category is only required for root posts. It should never be added to a child post.
Category *Category `json:"category,omitempty"`
// Tags are only required for root posts. It should never be added to a child post.
Tags []*Tag `json:"tags,omitempty"`
// A many-to-many recursive self reference. The root post is the first post in the thread.
Root *Post `json:"root,omitempty"`
// Posts holds the value of the posts edge.
Posts []*Post `json:"posts,omitempty"`
// A many-to-many recursive self reference. The replyTo post is an optional post that this post is in reply to.
ReplyTo *Post `json:"replyTo,omitempty"`
// Replies holds the value of the replies edge.
Replies []*Post `json:"replies,omitempty"`
// Reacts holds the value of the reacts edge.
Reacts []*React `json:"reacts,omitempty"`
// Likes holds the value of the likes edge.
Likes []*LikePost `json:"likes,omitempty"`
// Mentions holds the value of the mentions edge.
Mentions []*MentionProfile `json:"mentions,omitempty"`
// Assets holds the value of the assets edge.
Assets []*Asset `json:"assets,omitempty"`
// Collections holds the value of the collections edge.
Collections []*Collection `json:"collections,omitempty"`
// Link holds the value of the link edge.
Link *Link `json:"link,omitempty"`
// ContentLinks holds the value of the content_links edge.
ContentLinks []*Link `json:"content_links,omitempty"`
// Event holds the value of the event edge.
Event []*Event `json:"event,omitempty"`
// PostReads holds the value of the post_reads edge.
PostReads []*PostRead `json:"post_reads,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [16]bool
}
// AuthorOrErr returns the Author value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e PostEdges) AuthorOrErr() (*Account, error) {
if e.Author != nil {
return e.Author, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: account.Label}
}
return nil, &NotLoadedError{edge: "author"}
}
// 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[1] {
return nil, &NotFoundError{label: category.Label}
}
return nil, &NotLoadedError{edge: "category"}
}
// TagsOrErr returns the Tags value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) TagsOrErr() ([]*Tag, error) {
if e.loadedTypes[2] {
return e.Tags, nil
}
return nil, &NotLoadedError{edge: "tags"}
}
// RootOrErr returns the Root value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e PostEdges) RootOrErr() (*Post, error) {
if e.Root != nil {
return e.Root, nil
} else if e.loadedTypes[3] {
return nil, &NotFoundError{label: post.Label}
}
return nil, &NotLoadedError{edge: "root"}
}
// PostsOrErr returns the Posts value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) PostsOrErr() ([]*Post, error) {
if e.loadedTypes[4] {
return e.Posts, nil
}
return nil, &NotLoadedError{edge: "posts"}
}
// ReplyToOrErr returns the ReplyTo value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e PostEdges) ReplyToOrErr() (*Post, error) {
if e.ReplyTo != nil {
return e.ReplyTo, nil
} else if e.loadedTypes[5] {
return nil, &NotFoundError{label: post.Label}
}
return nil, &NotLoadedError{edge: "replyTo"}
}
// RepliesOrErr returns the Replies value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) RepliesOrErr() ([]*Post, error) {
if e.loadedTypes[6] {
return e.Replies, nil
}
return nil, &NotLoadedError{edge: "replies"}
}
// ReactsOrErr returns the Reacts value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) ReactsOrErr() ([]*React, error) {
if e.loadedTypes[7] {
return e.Reacts, nil
}
return nil, &NotLoadedError{edge: "reacts"}
}
// LikesOrErr returns the Likes value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) LikesOrErr() ([]*LikePost, error) {
if e.loadedTypes[8] {
return e.Likes, nil
}
return nil, &NotLoadedError{edge: "likes"}
}
// MentionsOrErr returns the Mentions value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) MentionsOrErr() ([]*MentionProfile, error) {
if e.loadedTypes[9] {
return e.Mentions, nil
}
return nil, &NotLoadedError{edge: "mentions"}
}
// AssetsOrErr returns the Assets value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) AssetsOrErr() ([]*Asset, error) {
if e.loadedTypes[10] {
return e.Assets, nil
}
return nil, &NotLoadedError{edge: "assets"}
}
// CollectionsOrErr returns the Collections value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) CollectionsOrErr() ([]*Collection, error) {
if e.loadedTypes[11] {
return e.Collections, nil
}
return nil, &NotLoadedError{edge: "collections"}
}
// LinkOrErr returns the Link value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e PostEdges) LinkOrErr() (*Link, error) {
if e.Link != nil {
return e.Link, nil
} else if e.loadedTypes[12] {
return nil, &NotFoundError{label: link.Label}
}
return nil, &NotLoadedError{edge: "link"}
}
// ContentLinksOrErr returns the ContentLinks value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) ContentLinksOrErr() ([]*Link, error) {
if e.loadedTypes[13] {
return e.ContentLinks, nil
}
return nil, &NotLoadedError{edge: "content_links"}
}
// EventOrErr returns the Event value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) EventOrErr() ([]*Event, error) {
if e.loadedTypes[14] {
return e.Event, nil
}
return nil, &NotLoadedError{edge: "event"}
}
// PostReadsOrErr returns the PostReads value or an error if the edge
// was not loaded in eager-loading.
func (e PostEdges) PostReadsOrErr() ([]*PostRead, error) {
if e.loadedTypes[15] {
return e.PostReads, nil
}
return nil, &NotLoadedError{edge: "post_reads"}
}
// 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.FieldMetadata:
values[i] = new([]byte)
case post.FieldFirst, post.FieldPinned:
values[i] = new(sql.NullBool)
case post.FieldTitle, post.FieldSlug, post.FieldBody, post.FieldShort, post.FieldVisibility:
values[i] = new(sql.NullString)
case post.FieldCreatedAt, post.FieldUpdatedAt, post.FieldDeletedAt, post.FieldIndexedAt, post.FieldLastReplyAt:
values[i] = new(sql.NullTime)
case post.FieldID, post.FieldRootPostID, post.FieldReplyToPostID, post.FieldAccountPosts, post.FieldCategoryID, post.FieldLinkID:
values[i] = new(xid.ID)
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 (_m *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].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
_m.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 {
_m.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 {
_m.UpdatedAt = value.Time
}
case post.FieldDeletedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
} else if value.Valid {
_m.DeletedAt = new(time.Time)
*_m.DeletedAt = value.Time
}
case post.FieldIndexedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field indexed_at", values[i])
} else if value.Valid {
_m.IndexedAt = new(time.Time)
*_m.IndexedAt = value.Time
}
case post.FieldFirst:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field first", values[i])
} else if value.Valid {
_m.First = value.Bool
}
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 {
_m.Title = 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 {
_m.Slug = value.String
}
case post.FieldPinned:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field pinned", values[i])
} else if value.Valid {
_m.Pinned = value.Bool
}
case post.FieldLastReplyAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field last_reply_at", values[i])
} else if value.Valid {
_m.LastReplyAt = new(time.Time)
*_m.LastReplyAt = value.Time
}
case post.FieldRootPostID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field root_post_id", values[i])
} else if value != nil {
_m.RootPostID = *value
}
case post.FieldReplyToPostID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field reply_to_post_id", values[i])
} else if value != nil {
_m.ReplyToPostID = *value
}
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 {
_m.Body = value.String
}
case post.FieldShort:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field short", values[i])
} else if value.Valid {
_m.Short = value.String
}
case post.FieldMetadata:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field metadata", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &_m.Metadata); err != nil {
return fmt.Errorf("unmarshal field metadata: %w", err)
}
}
case post.FieldVisibility:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field visibility", values[i])
} else if value.Valid {
_m.Visibility = post.Visibility(value.String)
}
case post.FieldAccountPosts:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field account_posts", values[i])
} else if value != nil {
_m.AccountPosts = *value
}
case post.FieldCategoryID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field category_id", values[i])
} else if value != nil {
_m.CategoryID = *value
}
case post.FieldLinkID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field link_id", values[i])
} else if value != nil {
_m.LinkID = *value
}
default:
_m.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 (_m *Post) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryAuthor queries the "author" edge of the Post entity.
func (_m *Post) QueryAuthor() *AccountQuery {
return NewPostClient(_m.config).QueryAuthor(_m)
}
// QueryCategory queries the "category" edge of the Post entity.
func (_m *Post) QueryCategory() *CategoryQuery {
return NewPostClient(_m.config).QueryCategory(_m)
}
// QueryTags queries the "tags" edge of the Post entity.
func (_m *Post) QueryTags() *TagQuery {
return NewPostClient(_m.config).QueryTags(_m)
}
// QueryRoot queries the "root" edge of the Post entity.
func (_m *Post) QueryRoot() *PostQuery {
return NewPostClient(_m.config).QueryRoot(_m)
}
// QueryPosts queries the "posts" edge of the Post entity.
func (_m *Post) QueryPosts() *PostQuery {
return NewPostClient(_m.config).QueryPosts(_m)
}
// QueryReplyTo queries the "replyTo" edge of the Post entity.
func (_m *Post) QueryReplyTo() *PostQuery {
return NewPostClient(_m.config).QueryReplyTo(_m)
}
// QueryReplies queries the "replies" edge of the Post entity.
func (_m *Post) QueryReplies() *PostQuery {
return NewPostClient(_m.config).QueryReplies(_m)
}
// QueryReacts queries the "reacts" edge of the Post entity.
func (_m *Post) QueryReacts() *ReactQuery {
return NewPostClient(_m.config).QueryReacts(_m)
}
// QueryLikes queries the "likes" edge of the Post entity.
func (_m *Post) QueryLikes() *LikePostQuery {
return NewPostClient(_m.config).QueryLikes(_m)
}
// QueryMentions queries the "mentions" edge of the Post entity.
func (_m *Post) QueryMentions() *MentionProfileQuery {
return NewPostClient(_m.config).QueryMentions(_m)
}
// QueryAssets queries the "assets" edge of the Post entity.
func (_m *Post) QueryAssets() *AssetQuery {
return NewPostClient(_m.config).QueryAssets(_m)
}
// QueryCollections queries the "collections" edge of the Post entity.
func (_m *Post) QueryCollections() *CollectionQuery {
return NewPostClient(_m.config).QueryCollections(_m)
}
// QueryLink queries the "link" edge of the Post entity.
func (_m *Post) QueryLink() *LinkQuery {
return NewPostClient(_m.config).QueryLink(_m)
}
// QueryContentLinks queries the "content_links" edge of the Post entity.
func (_m *Post) QueryContentLinks() *LinkQuery {
return NewPostClient(_m.config).QueryContentLinks(_m)
}
// QueryEvent queries the "event" edge of the Post entity.
func (_m *Post) QueryEvent() *EventQuery {
return NewPostClient(_m.config).QueryEvent(_m)
}
// QueryPostReads queries the "post_reads" edge of the Post entity.
func (_m *Post) QueryPostReads() *PostReadQuery {
return NewPostClient(_m.config).QueryPostReads(_m)
}
// 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 (_m *Post) Update() *PostUpdateOne {
return NewPostClient(_m.config).UpdateOne(_m)
}
// 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 (_m *Post) Unwrap() *Post {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Post is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Post) String() string {
var builder strings.Builder
builder.WriteString("Post(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.DeletedAt; v != nil {
builder.WriteString("deleted_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
if v := _m.IndexedAt; v != nil {
builder.WriteString("indexed_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("first=")
builder.WriteString(fmt.Sprintf("%v", _m.First))
builder.WriteString(", ")
builder.WriteString("title=")
builder.WriteString(_m.Title)
builder.WriteString(", ")
builder.WriteString("slug=")
builder.WriteString(_m.Slug)
builder.WriteString(", ")
builder.WriteString("pinned=")
builder.WriteString(fmt.Sprintf("%v", _m.Pinned))
builder.WriteString(", ")
if v := _m.LastReplyAt; v != nil {
builder.WriteString("last_reply_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("root_post_id=")
builder.WriteString(fmt.Sprintf("%v", _m.RootPostID))
builder.WriteString(", ")
builder.WriteString("reply_to_post_id=")
builder.WriteString(fmt.Sprintf("%v", _m.ReplyToPostID))
builder.WriteString(", ")
builder.WriteString("body=")
builder.WriteString(_m.Body)
builder.WriteString(", ")
builder.WriteString("short=")
builder.WriteString(_m.Short)
builder.WriteString(", ")
builder.WriteString("metadata=")
builder.WriteString(fmt.Sprintf("%v", _m.Metadata))
builder.WriteString(", ")
builder.WriteString("visibility=")
builder.WriteString(fmt.Sprintf("%v", _m.Visibility))
builder.WriteString(", ")
builder.WriteString("account_posts=")
builder.WriteString(fmt.Sprintf("%v", _m.AccountPosts))
builder.WriteString(", ")
builder.WriteString("category_id=")
builder.WriteString(fmt.Sprintf("%v", _m.CategoryID))
builder.WriteString(", ")
builder.WriteString("link_id=")
builder.WriteString(fmt.Sprintf("%v", _m.LinkID))
builder.WriteByte(')')
return builder.String()
}
// Posts is a parsable slice of Post.
type Posts []*Post