collectionpost.go•6.38 kB
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Southclaws/storyden/internal/ent/collection"
"github.com/Southclaws/storyden/internal/ent/collectionpost"
"github.com/Southclaws/storyden/internal/ent/post"
"github.com/rs/xid"
)
// CollectionPost is the model entity for the CollectionPost schema.
type CollectionPost struct {
config `json:"-"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// CollectionID holds the value of the "collection_id" field.
CollectionID xid.ID `json:"collection_id,omitempty"`
// PostID holds the value of the "post_id" field.
PostID xid.ID `json:"post_id,omitempty"`
// MembershipType holds the value of the "membership_type" field.
MembershipType string `json:"membership_type,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the CollectionPostQuery when eager-loading is set.
Edges CollectionPostEdges `json:"edges"`
selectValues sql.SelectValues
}
// CollectionPostEdges holds the relations/edges for other nodes in the graph.
type CollectionPostEdges struct {
// Collection holds the value of the collection edge.
Collection *Collection `json:"collection,omitempty"`
// Post holds the value of the post edge.
Post *Post `json:"post,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// CollectionOrErr returns the Collection value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CollectionPostEdges) CollectionOrErr() (*Collection, error) {
if e.Collection != nil {
return e.Collection, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: collection.Label}
}
return nil, &NotLoadedError{edge: "collection"}
}
// PostOrErr returns the Post value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CollectionPostEdges) PostOrErr() (*Post, error) {
if e.Post != nil {
return e.Post, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: post.Label}
}
return nil, &NotLoadedError{edge: "post"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*CollectionPost) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case collectionpost.FieldMembershipType:
values[i] = new(sql.NullString)
case collectionpost.FieldCreatedAt:
values[i] = new(sql.NullTime)
case collectionpost.FieldCollectionID, collectionpost.FieldPostID:
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 CollectionPost fields.
func (_m *CollectionPost) 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 collectionpost.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 collectionpost.FieldCollectionID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field collection_id", values[i])
} else if value != nil {
_m.CollectionID = *value
}
case collectionpost.FieldPostID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field post_id", values[i])
} else if value != nil {
_m.PostID = *value
}
case collectionpost.FieldMembershipType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field membership_type", values[i])
} else if value.Valid {
_m.MembershipType = value.String
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the CollectionPost.
// This includes values selected through modifiers, order, etc.
func (_m *CollectionPost) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryCollection queries the "collection" edge of the CollectionPost entity.
func (_m *CollectionPost) QueryCollection() *CollectionQuery {
return NewCollectionPostClient(_m.config).QueryCollection(_m)
}
// QueryPost queries the "post" edge of the CollectionPost entity.
func (_m *CollectionPost) QueryPost() *PostQuery {
return NewCollectionPostClient(_m.config).QueryPost(_m)
}
// Update returns a builder for updating this CollectionPost.
// Note that you need to call CollectionPost.Unwrap() before calling this method if this CollectionPost
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *CollectionPost) Update() *CollectionPostUpdateOne {
return NewCollectionPostClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the CollectionPost 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 *CollectionPost) Unwrap() *CollectionPost {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: CollectionPost is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *CollectionPost) String() string {
var builder strings.Builder
builder.WriteString("CollectionPost(")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("collection_id=")
builder.WriteString(fmt.Sprintf("%v", _m.CollectionID))
builder.WriteString(", ")
builder.WriteString("post_id=")
builder.WriteString(fmt.Sprintf("%v", _m.PostID))
builder.WriteString(", ")
builder.WriteString("membership_type=")
builder.WriteString(_m.MembershipType)
builder.WriteByte(')')
return builder.String()
}
// CollectionPosts is a parsable slice of CollectionPost.
type CollectionPosts []*CollectionPost