collectionnode.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/collectionnode"
"github.com/Southclaws/storyden/internal/ent/node"
"github.com/rs/xid"
)
// CollectionNode is the model entity for the CollectionNode schema.
type CollectionNode 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"`
// NodeID holds the value of the "node_id" field.
NodeID xid.ID `json:"node_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 CollectionNodeQuery when eager-loading is set.
Edges CollectionNodeEdges `json:"edges"`
selectValues sql.SelectValues
}
// CollectionNodeEdges holds the relations/edges for other nodes in the graph.
type CollectionNodeEdges struct {
// Collection holds the value of the collection edge.
Collection *Collection `json:"collection,omitempty"`
// Node holds the value of the node edge.
Node *Node `json:"node,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 CollectionNodeEdges) 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"}
}
// NodeOrErr returns the Node value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CollectionNodeEdges) NodeOrErr() (*Node, error) {
if e.Node != nil {
return e.Node, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: node.Label}
}
return nil, &NotLoadedError{edge: "node"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*CollectionNode) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case collectionnode.FieldMembershipType:
values[i] = new(sql.NullString)
case collectionnode.FieldCreatedAt:
values[i] = new(sql.NullTime)
case collectionnode.FieldCollectionID, collectionnode.FieldNodeID:
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 CollectionNode fields.
func (_m *CollectionNode) 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 collectionnode.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 collectionnode.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 collectionnode.FieldNodeID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field node_id", values[i])
} else if value != nil {
_m.NodeID = *value
}
case collectionnode.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 CollectionNode.
// This includes values selected through modifiers, order, etc.
func (_m *CollectionNode) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryCollection queries the "collection" edge of the CollectionNode entity.
func (_m *CollectionNode) QueryCollection() *CollectionQuery {
return NewCollectionNodeClient(_m.config).QueryCollection(_m)
}
// QueryNode queries the "node" edge of the CollectionNode entity.
func (_m *CollectionNode) QueryNode() *NodeQuery {
return NewCollectionNodeClient(_m.config).QueryNode(_m)
}
// Update returns a builder for updating this CollectionNode.
// Note that you need to call CollectionNode.Unwrap() before calling this method if this CollectionNode
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *CollectionNode) Update() *CollectionNodeUpdateOne {
return NewCollectionNodeClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the CollectionNode 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 *CollectionNode) Unwrap() *CollectionNode {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: CollectionNode is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *CollectionNode) String() string {
var builder strings.Builder
builder.WriteString("CollectionNode(")
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("node_id=")
builder.WriteString(fmt.Sprintf("%v", _m.NodeID))
builder.WriteString(", ")
builder.WriteString("membership_type=")
builder.WriteString(_m.MembershipType)
builder.WriteByte(')')
return builder.String()
}
// CollectionNodes is a parsable slice of CollectionNode.
type CollectionNodes []*CollectionNode