email.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/account"
"github.com/Southclaws/storyden/internal/ent/email"
"github.com/rs/xid"
)
// Email is the model entity for the Email schema.
type Email 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"`
// If set, this email is associated with an account, otherwise can be used for newsletter subscriptions etc.
AccountID *xid.ID `json:"account_id,omitempty"`
// EmailAddress holds the value of the "email_address" field.
EmailAddress string `json:"email_address,omitempty"`
// A six digit code that is sent to the email address to verify ownership
VerificationCode string `json:"verification_code,omitempty"`
// Whether this email has been verified to be owned by the account via a token send+verify process
Verified bool `json:"verified,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the EmailQuery when eager-loading is set.
Edges EmailEdges `json:"edges"`
selectValues sql.SelectValues
}
// EmailEdges holds the relations/edges for other nodes in the graph.
type EmailEdges struct {
// Account holds the value of the account edge.
Account *Account `json:"account,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]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 EmailEdges) 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"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Email) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case email.FieldAccountID:
values[i] = &sql.NullScanner{S: new(xid.ID)}
case email.FieldVerified:
values[i] = new(sql.NullBool)
case email.FieldEmailAddress, email.FieldVerificationCode:
values[i] = new(sql.NullString)
case email.FieldCreatedAt:
values[i] = new(sql.NullTime)
case email.FieldID:
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 Email fields.
func (_m *Email) 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 email.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 email.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 email.FieldAccountID:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field account_id", values[i])
} else if value.Valid {
_m.AccountID = new(xid.ID)
*_m.AccountID = *value.S.(*xid.ID)
}
case email.FieldEmailAddress:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field email_address", values[i])
} else if value.Valid {
_m.EmailAddress = value.String
}
case email.FieldVerificationCode:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field verification_code", values[i])
} else if value.Valid {
_m.VerificationCode = value.String
}
case email.FieldVerified:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field verified", values[i])
} else if value.Valid {
_m.Verified = value.Bool
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Email.
// This includes values selected through modifiers, order, etc.
func (_m *Email) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryAccount queries the "account" edge of the Email entity.
func (_m *Email) QueryAccount() *AccountQuery {
return NewEmailClient(_m.config).QueryAccount(_m)
}
// Update returns a builder for updating this Email.
// Note that you need to call Email.Unwrap() before calling this method if this Email
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Email) Update() *EmailUpdateOne {
return NewEmailClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Email 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 *Email) Unwrap() *Email {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Email is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Email) String() string {
var builder strings.Builder
builder.WriteString("Email(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.AccountID; v != nil {
builder.WriteString("account_id=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
builder.WriteString("email_address=")
builder.WriteString(_m.EmailAddress)
builder.WriteString(", ")
builder.WriteString("verification_code=")
builder.WriteString(_m.VerificationCode)
builder.WriteString(", ")
builder.WriteString("verified=")
builder.WriteString(fmt.Sprintf("%v", _m.Verified))
builder.WriteByte(')')
return builder.String()
}
// Emails is a parsable slice of Email.
type Emails []*Email