accountfollow.go•6.27 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/accountfollow"
"github.com/rs/xid"
)
// AccountFollow is the model entity for the AccountFollow schema.
type AccountFollow 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"`
// FollowerAccountID holds the value of the "follower_account_id" field.
FollowerAccountID xid.ID `json:"follower_account_id,omitempty"`
// FollowingAccountID holds the value of the "following_account_id" field.
FollowingAccountID xid.ID `json:"following_account_id,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the AccountFollowQuery when eager-loading is set.
Edges AccountFollowEdges `json:"edges"`
selectValues sql.SelectValues
}
// AccountFollowEdges holds the relations/edges for other nodes in the graph.
type AccountFollowEdges struct {
// Follower holds the value of the follower edge.
Follower *Account `json:"follower,omitempty"`
// Following holds the value of the following edge.
Following *Account `json:"following,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// FollowerOrErr returns the Follower value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e AccountFollowEdges) FollowerOrErr() (*Account, error) {
if e.Follower != nil {
return e.Follower, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: account.Label}
}
return nil, &NotLoadedError{edge: "follower"}
}
// FollowingOrErr returns the Following value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e AccountFollowEdges) FollowingOrErr() (*Account, error) {
if e.Following != nil {
return e.Following, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: account.Label}
}
return nil, &NotLoadedError{edge: "following"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*AccountFollow) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case accountfollow.FieldCreatedAt:
values[i] = new(sql.NullTime)
case accountfollow.FieldID, accountfollow.FieldFollowerAccountID, accountfollow.FieldFollowingAccountID:
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 AccountFollow fields.
func (_m *AccountFollow) 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 accountfollow.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 accountfollow.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 accountfollow.FieldFollowerAccountID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field follower_account_id", values[i])
} else if value != nil {
_m.FollowerAccountID = *value
}
case accountfollow.FieldFollowingAccountID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field following_account_id", values[i])
} else if value != nil {
_m.FollowingAccountID = *value
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the AccountFollow.
// This includes values selected through modifiers, order, etc.
func (_m *AccountFollow) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryFollower queries the "follower" edge of the AccountFollow entity.
func (_m *AccountFollow) QueryFollower() *AccountQuery {
return NewAccountFollowClient(_m.config).QueryFollower(_m)
}
// QueryFollowing queries the "following" edge of the AccountFollow entity.
func (_m *AccountFollow) QueryFollowing() *AccountQuery {
return NewAccountFollowClient(_m.config).QueryFollowing(_m)
}
// Update returns a builder for updating this AccountFollow.
// Note that you need to call AccountFollow.Unwrap() before calling this method if this AccountFollow
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *AccountFollow) Update() *AccountFollowUpdateOne {
return NewAccountFollowClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the AccountFollow 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 *AccountFollow) Unwrap() *AccountFollow {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: AccountFollow is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *AccountFollow) String() string {
var builder strings.Builder
builder.WriteString("AccountFollow(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("follower_account_id=")
builder.WriteString(fmt.Sprintf("%v", _m.FollowerAccountID))
builder.WriteString(", ")
builder.WriteString("following_account_id=")
builder.WriteString(fmt.Sprintf("%v", _m.FollowingAccountID))
builder.WriteByte(')')
return builder.String()
}
// AccountFollows is a parsable slice of AccountFollow.
type AccountFollows []*AccountFollow