collection.go•11.4 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/account"
"github.com/Southclaws/storyden/internal/ent/asset"
"github.com/Southclaws/storyden/internal/ent/collection"
"github.com/rs/xid"
)
// Collection is the model entity for the Collection schema.
type Collection 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"`
// IndexedAt holds the value of the "indexed_at" field.
IndexedAt *time.Time `json:"indexed_at,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Slug holds the value of the "slug" field.
Slug string `json:"slug,omitempty"`
// Description holds the value of the "description" field.
Description *string `json:"description,omitempty"`
// CoverAssetID holds the value of the "cover_asset_id" field.
CoverAssetID *xid.ID `json:"cover_asset_id,omitempty"`
// Visibility holds the value of the "visibility" field.
Visibility collection.Visibility `json:"visibility,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the CollectionQuery when eager-loading is set.
Edges CollectionEdges `json:"edges"`
account_collections *xid.ID
selectValues sql.SelectValues
}
// CollectionEdges holds the relations/edges for other nodes in the graph.
type CollectionEdges struct {
// Owner holds the value of the owner edge.
Owner *Account `json:"owner,omitempty"`
// CoverImage holds the value of the cover_image edge.
CoverImage *Asset `json:"cover_image,omitempty"`
// Posts holds the value of the posts edge.
Posts []*Post `json:"posts,omitempty"`
// Nodes holds the value of the nodes edge.
Nodes []*Node `json:"nodes,omitempty"`
// CollectionPosts holds the value of the collection_posts edge.
CollectionPosts []*CollectionPost `json:"collection_posts,omitempty"`
// CollectionNodes holds the value of the collection_nodes edge.
CollectionNodes []*CollectionNode `json:"collection_nodes,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [6]bool
}
// OwnerOrErr returns the Owner value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CollectionEdges) OwnerOrErr() (*Account, error) {
if e.Owner != nil {
return e.Owner, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: account.Label}
}
return nil, &NotLoadedError{edge: "owner"}
}
// CoverImageOrErr returns the CoverImage value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CollectionEdges) CoverImageOrErr() (*Asset, error) {
if e.CoverImage != nil {
return e.CoverImage, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: asset.Label}
}
return nil, &NotLoadedError{edge: "cover_image"}
}
// PostsOrErr returns the Posts value or an error if the edge
// was not loaded in eager-loading.
func (e CollectionEdges) PostsOrErr() ([]*Post, error) {
if e.loadedTypes[2] {
return e.Posts, nil
}
return nil, &NotLoadedError{edge: "posts"}
}
// NodesOrErr returns the Nodes value or an error if the edge
// was not loaded in eager-loading.
func (e CollectionEdges) NodesOrErr() ([]*Node, error) {
if e.loadedTypes[3] {
return e.Nodes, nil
}
return nil, &NotLoadedError{edge: "nodes"}
}
// CollectionPostsOrErr returns the CollectionPosts value or an error if the edge
// was not loaded in eager-loading.
func (e CollectionEdges) CollectionPostsOrErr() ([]*CollectionPost, error) {
if e.loadedTypes[4] {
return e.CollectionPosts, nil
}
return nil, &NotLoadedError{edge: "collection_posts"}
}
// CollectionNodesOrErr returns the CollectionNodes value or an error if the edge
// was not loaded in eager-loading.
func (e CollectionEdges) CollectionNodesOrErr() ([]*CollectionNode, error) {
if e.loadedTypes[5] {
return e.CollectionNodes, nil
}
return nil, &NotLoadedError{edge: "collection_nodes"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Collection) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case collection.FieldCoverAssetID:
values[i] = &sql.NullScanner{S: new(xid.ID)}
case collection.FieldName, collection.FieldSlug, collection.FieldDescription, collection.FieldVisibility:
values[i] = new(sql.NullString)
case collection.FieldCreatedAt, collection.FieldUpdatedAt, collection.FieldIndexedAt:
values[i] = new(sql.NullTime)
case collection.FieldID:
values[i] = new(xid.ID)
case collection.ForeignKeys[0]: // account_collections
values[i] = &sql.NullScanner{S: 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 Collection fields.
func (_m *Collection) 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 collection.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 collection.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 collection.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 collection.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 collection.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case collection.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 collection.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
_m.Description = new(string)
*_m.Description = value.String
}
case collection.FieldCoverAssetID:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field cover_asset_id", values[i])
} else if value.Valid {
_m.CoverAssetID = new(xid.ID)
*_m.CoverAssetID = *value.S.(*xid.ID)
}
case collection.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 = collection.Visibility(value.String)
}
case collection.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field account_collections", values[i])
} else if value.Valid {
_m.account_collections = new(xid.ID)
*_m.account_collections = *value.S.(*xid.ID)
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Collection.
// This includes values selected through modifiers, order, etc.
func (_m *Collection) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryOwner queries the "owner" edge of the Collection entity.
func (_m *Collection) QueryOwner() *AccountQuery {
return NewCollectionClient(_m.config).QueryOwner(_m)
}
// QueryCoverImage queries the "cover_image" edge of the Collection entity.
func (_m *Collection) QueryCoverImage() *AssetQuery {
return NewCollectionClient(_m.config).QueryCoverImage(_m)
}
// QueryPosts queries the "posts" edge of the Collection entity.
func (_m *Collection) QueryPosts() *PostQuery {
return NewCollectionClient(_m.config).QueryPosts(_m)
}
// QueryNodes queries the "nodes" edge of the Collection entity.
func (_m *Collection) QueryNodes() *NodeQuery {
return NewCollectionClient(_m.config).QueryNodes(_m)
}
// QueryCollectionPosts queries the "collection_posts" edge of the Collection entity.
func (_m *Collection) QueryCollectionPosts() *CollectionPostQuery {
return NewCollectionClient(_m.config).QueryCollectionPosts(_m)
}
// QueryCollectionNodes queries the "collection_nodes" edge of the Collection entity.
func (_m *Collection) QueryCollectionNodes() *CollectionNodeQuery {
return NewCollectionClient(_m.config).QueryCollectionNodes(_m)
}
// Update returns a builder for updating this Collection.
// Note that you need to call Collection.Unwrap() before calling this method if this Collection
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Collection) Update() *CollectionUpdateOne {
return NewCollectionClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Collection 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 *Collection) Unwrap() *Collection {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Collection is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Collection) String() string {
var builder strings.Builder
builder.WriteString("Collection(")
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.IndexedAt; v != nil {
builder.WriteString("indexed_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("slug=")
builder.WriteString(_m.Slug)
builder.WriteString(", ")
if v := _m.Description; v != nil {
builder.WriteString("description=")
builder.WriteString(*v)
}
builder.WriteString(", ")
if v := _m.CoverAssetID; v != nil {
builder.WriteString("cover_asset_id=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
builder.WriteString("visibility=")
builder.WriteString(fmt.Sprintf("%v", _m.Visibility))
builder.WriteByte(')')
return builder.String()
}
// Collections is a parsable slice of Collection.
type Collections []*Collection