eventparticipant.go•7.08 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/event"
"github.com/Southclaws/storyden/internal/ent/eventparticipant"
"github.com/rs/xid"
)
// EventParticipant is the model entity for the EventParticipant schema.
type EventParticipant 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"`
// Role holds the value of the "role" field.
Role string `json:"role,omitempty"`
// Status holds the value of the "status" field.
Status string `json:"status,omitempty"`
// AccountID holds the value of the "account_id" field.
AccountID xid.ID `json:"account_id,omitempty"`
// EventID holds the value of the "event_id" field.
EventID xid.ID `json:"event_id,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the EventParticipantQuery when eager-loading is set.
Edges EventParticipantEdges `json:"edges"`
selectValues sql.SelectValues
}
// EventParticipantEdges holds the relations/edges for other nodes in the graph.
type EventParticipantEdges struct {
// Account holds the value of the account edge.
Account *Account `json:"account,omitempty"`
// Event holds the value of the event edge.
Event *Event `json:"event,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// AccountOrErr returns the Account value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e EventParticipantEdges) AccountOrErr() (*Account, error) {
if e.Account != nil {
return e.Account, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: account.Label}
}
return nil, &NotLoadedError{edge: "account"}
}
// EventOrErr returns the Event value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e EventParticipantEdges) EventOrErr() (*Event, error) {
if e.Event != nil {
return e.Event, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: event.Label}
}
return nil, &NotLoadedError{edge: "event"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*EventParticipant) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case eventparticipant.FieldRole, eventparticipant.FieldStatus:
values[i] = new(sql.NullString)
case eventparticipant.FieldCreatedAt:
values[i] = new(sql.NullTime)
case eventparticipant.FieldID, eventparticipant.FieldAccountID, eventparticipant.FieldEventID:
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 EventParticipant fields.
func (_m *EventParticipant) 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 eventparticipant.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 eventparticipant.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 eventparticipant.FieldRole:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field role", values[i])
} else if value.Valid {
_m.Role = value.String
}
case eventparticipant.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
_m.Status = value.String
}
case eventparticipant.FieldAccountID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field account_id", values[i])
} else if value != nil {
_m.AccountID = *value
}
case eventparticipant.FieldEventID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field event_id", values[i])
} else if value != nil {
_m.EventID = *value
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the EventParticipant.
// This includes values selected through modifiers, order, etc.
func (_m *EventParticipant) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryAccount queries the "account" edge of the EventParticipant entity.
func (_m *EventParticipant) QueryAccount() *AccountQuery {
return NewEventParticipantClient(_m.config).QueryAccount(_m)
}
// QueryEvent queries the "event" edge of the EventParticipant entity.
func (_m *EventParticipant) QueryEvent() *EventQuery {
return NewEventParticipantClient(_m.config).QueryEvent(_m)
}
// Update returns a builder for updating this EventParticipant.
// Note that you need to call EventParticipant.Unwrap() before calling this method if this EventParticipant
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *EventParticipant) Update() *EventParticipantUpdateOne {
return NewEventParticipantClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the EventParticipant 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 *EventParticipant) Unwrap() *EventParticipant {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: EventParticipant is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *EventParticipant) String() string {
var builder strings.Builder
builder.WriteString("EventParticipant(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("role=")
builder.WriteString(_m.Role)
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(_m.Status)
builder.WriteString(", ")
builder.WriteString("account_id=")
builder.WriteString(fmt.Sprintf("%v", _m.AccountID))
builder.WriteString(", ")
builder.WriteString("event_id=")
builder.WriteString(fmt.Sprintf("%v", _m.EventID))
builder.WriteByte(')')
return builder.String()
}
// EventParticipants is a parsable slice of EventParticipant.
type EventParticipants []*EventParticipant