notification.go•9 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/notification"
"github.com/rs/xid"
)
// Notification is the model entity for the Notification schema.
type Notification 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"`
// DeletedAt holds the value of the "deleted_at" field.
DeletedAt *time.Time `json:"deleted_at,omitempty"`
// EventType holds the value of the "event_type" field.
EventType string `json:"event_type,omitempty"`
// DatagraphKind holds the value of the "datagraph_kind" field.
DatagraphKind *string `json:"datagraph_kind,omitempty"`
// The ID of the resource that this notification relates to. This is not a foreign key as notifications can refer to a variety of sources, discriminated by the 'datagraph_kind' field.
DatagraphID *xid.ID `json:"datagraph_id,omitempty"`
// Read holds the value of the "read" field.
Read bool `json:"read,omitempty"`
// OwnerAccountID holds the value of the "owner_account_id" field.
OwnerAccountID xid.ID `json:"owner_account_id,omitempty"`
// SourceAccountID holds the value of the "source_account_id" field.
SourceAccountID *xid.ID `json:"source_account_id,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the NotificationQuery when eager-loading is set.
Edges NotificationEdges `json:"edges"`
selectValues sql.SelectValues
}
// NotificationEdges holds the relations/edges for other nodes in the graph.
type NotificationEdges struct {
// Owner holds the value of the owner edge.
Owner *Account `json:"owner,omitempty"`
// Source holds the value of the source edge.
Source *Account `json:"source,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// OwnerOrErr returns the Owner value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e NotificationEdges) OwnerOrErr() (*Account, error) {
if e.Owner != nil {
return e.Owner, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: account.Label}
}
return nil, &NotLoadedError{edge: "owner"}
}
// SourceOrErr returns the Source value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e NotificationEdges) SourceOrErr() (*Account, error) {
if e.Source != nil {
return e.Source, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: account.Label}
}
return nil, &NotLoadedError{edge: "source"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Notification) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case notification.FieldDatagraphID, notification.FieldSourceAccountID:
values[i] = &sql.NullScanner{S: new(xid.ID)}
case notification.FieldRead:
values[i] = new(sql.NullBool)
case notification.FieldEventType, notification.FieldDatagraphKind:
values[i] = new(sql.NullString)
case notification.FieldCreatedAt, notification.FieldDeletedAt:
values[i] = new(sql.NullTime)
case notification.FieldID, notification.FieldOwnerAccountID:
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 Notification fields.
func (_m *Notification) 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 notification.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 notification.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 notification.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 notification.FieldEventType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field event_type", values[i])
} else if value.Valid {
_m.EventType = value.String
}
case notification.FieldDatagraphKind:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field datagraph_kind", values[i])
} else if value.Valid {
_m.DatagraphKind = new(string)
*_m.DatagraphKind = value.String
}
case notification.FieldDatagraphID:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field datagraph_id", values[i])
} else if value.Valid {
_m.DatagraphID = new(xid.ID)
*_m.DatagraphID = *value.S.(*xid.ID)
}
case notification.FieldRead:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field read", values[i])
} else if value.Valid {
_m.Read = value.Bool
}
case notification.FieldOwnerAccountID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field owner_account_id", values[i])
} else if value != nil {
_m.OwnerAccountID = *value
}
case notification.FieldSourceAccountID:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field source_account_id", values[i])
} else if value.Valid {
_m.SourceAccountID = new(xid.ID)
*_m.SourceAccountID = *value.S.(*xid.ID)
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Notification.
// This includes values selected through modifiers, order, etc.
func (_m *Notification) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryOwner queries the "owner" edge of the Notification entity.
func (_m *Notification) QueryOwner() *AccountQuery {
return NewNotificationClient(_m.config).QueryOwner(_m)
}
// QuerySource queries the "source" edge of the Notification entity.
func (_m *Notification) QuerySource() *AccountQuery {
return NewNotificationClient(_m.config).QuerySource(_m)
}
// Update returns a builder for updating this Notification.
// Note that you need to call Notification.Unwrap() before calling this method if this Notification
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Notification) Update() *NotificationUpdateOne {
return NewNotificationClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Notification 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 *Notification) Unwrap() *Notification {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Notification is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Notification) String() string {
var builder strings.Builder
builder.WriteString("Notification(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.DeletedAt; v != nil {
builder.WriteString("deleted_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("event_type=")
builder.WriteString(_m.EventType)
builder.WriteString(", ")
if v := _m.DatagraphKind; v != nil {
builder.WriteString("datagraph_kind=")
builder.WriteString(*v)
}
builder.WriteString(", ")
if v := _m.DatagraphID; v != nil {
builder.WriteString("datagraph_id=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
builder.WriteString("read=")
builder.WriteString(fmt.Sprintf("%v", _m.Read))
builder.WriteString(", ")
builder.WriteString("owner_account_id=")
builder.WriteString(fmt.Sprintf("%v", _m.OwnerAccountID))
builder.WriteString(", ")
if v := _m.SourceAccountID; v != nil {
builder.WriteString("source_account_id=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteByte(')')
return builder.String()
}
// Notifications is a parsable slice of Notification.
type Notifications []*Notification