invitation.go•6.97 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/invitation"
"github.com/rs/xid"
)
// Invitation is the model entity for the Invitation schema.
type Invitation 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"`
// DeletedAt holds the value of the "deleted_at" field.
DeletedAt *time.Time `json:"deleted_at,omitempty"`
// Message holds the value of the "message" field.
Message *string `json:"message,omitempty"`
// CreatorAccountID holds the value of the "creator_account_id" field.
CreatorAccountID xid.ID `json:"creator_account_id,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the InvitationQuery when eager-loading is set.
Edges InvitationEdges `json:"edges"`
selectValues sql.SelectValues
}
// InvitationEdges holds the relations/edges for other nodes in the graph.
type InvitationEdges struct {
// Creator holds the value of the creator edge.
Creator *Account `json:"creator,omitempty"`
// Invited holds the value of the invited edge.
Invited []*Account `json:"invited,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// CreatorOrErr returns the Creator value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e InvitationEdges) CreatorOrErr() (*Account, error) {
if e.Creator != nil {
return e.Creator, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: account.Label}
}
return nil, &NotLoadedError{edge: "creator"}
}
// InvitedOrErr returns the Invited value or an error if the edge
// was not loaded in eager-loading.
func (e InvitationEdges) InvitedOrErr() ([]*Account, error) {
if e.loadedTypes[1] {
return e.Invited, nil
}
return nil, &NotLoadedError{edge: "invited"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Invitation) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case invitation.FieldMessage:
values[i] = new(sql.NullString)
case invitation.FieldCreatedAt, invitation.FieldUpdatedAt, invitation.FieldDeletedAt:
values[i] = new(sql.NullTime)
case invitation.FieldID, invitation.FieldCreatorAccountID:
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 Invitation fields.
func (_m *Invitation) 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 invitation.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 invitation.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 invitation.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 invitation.FieldDeletedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
} else if value.Valid {
_m.DeletedAt = new(time.Time)
*_m.DeletedAt = value.Time
}
case invitation.FieldMessage:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field message", values[i])
} else if value.Valid {
_m.Message = new(string)
*_m.Message = value.String
}
case invitation.FieldCreatorAccountID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field creator_account_id", values[i])
} else if value != nil {
_m.CreatorAccountID = *value
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Invitation.
// This includes values selected through modifiers, order, etc.
func (_m *Invitation) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryCreator queries the "creator" edge of the Invitation entity.
func (_m *Invitation) QueryCreator() *AccountQuery {
return NewInvitationClient(_m.config).QueryCreator(_m)
}
// QueryInvited queries the "invited" edge of the Invitation entity.
func (_m *Invitation) QueryInvited() *AccountQuery {
return NewInvitationClient(_m.config).QueryInvited(_m)
}
// Update returns a builder for updating this Invitation.
// Note that you need to call Invitation.Unwrap() before calling this method if this Invitation
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Invitation) Update() *InvitationUpdateOne {
return NewInvitationClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Invitation 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 *Invitation) Unwrap() *Invitation {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Invitation is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Invitation) String() string {
var builder strings.Builder
builder.WriteString("Invitation(")
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.DeletedAt; v != nil {
builder.WriteString("deleted_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
if v := _m.Message; v != nil {
builder.WriteString("message=")
builder.WriteString(*v)
}
builder.WriteString(", ")
builder.WriteString("creator_account_id=")
builder.WriteString(fmt.Sprintf("%v", _m.CreatorAccountID))
builder.WriteByte(')')
return builder.String()
}
// Invitations is a parsable slice of Invitation.
type Invitations []*Invitation