event.go•15.7 kB
// Code generated by ent, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Southclaws/storyden/internal/ent/asset"
"github.com/Southclaws/storyden/internal/ent/event"
"github.com/Southclaws/storyden/internal/ent/post"
"github.com/rs/xid"
)
// Event is the model entity for the Event schema.
type Event 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"`
// IndexedAt holds the value of the "indexed_at" field.
IndexedAt *time.Time `json:"indexed_at,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Slug holds the value of the "slug" field.
Slug string `json:"slug,omitempty"`
// Description holds the value of the "description" field.
Description *string `json:"description,omitempty"`
// StartTime holds the value of the "start_time" field.
StartTime time.Time `json:"start_time,omitempty"`
// EndTime holds the value of the "end_time" field.
EndTime time.Time `json:"end_time,omitempty"`
// ParticipationPolicy holds the value of the "participation_policy" field.
ParticipationPolicy string `json:"participation_policy,omitempty"`
// Visibility holds the value of the "visibility" field.
Visibility event.Visibility `json:"visibility,omitempty"`
// LocationType holds the value of the "location_type" field.
LocationType *string `json:"location_type,omitempty"`
// LocationName holds the value of the "location_name" field.
LocationName *string `json:"location_name,omitempty"`
// LocationAddress holds the value of the "location_address" field.
LocationAddress *string `json:"location_address,omitempty"`
// LocationLatitude holds the value of the "location_latitude" field.
LocationLatitude *float64 `json:"location_latitude,omitempty"`
// LocationLongitude holds the value of the "location_longitude" field.
LocationLongitude *float64 `json:"location_longitude,omitempty"`
// LocationURL holds the value of the "location_url" field.
LocationURL *string `json:"location_url,omitempty"`
// Capacity holds the value of the "capacity" field.
Capacity *int `json:"capacity,omitempty"`
// Metadata holds the value of the "metadata" field.
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the EventQuery when eager-loading is set.
Edges EventEdges `json:"edges"`
asset_event *xid.ID
post_event *xid.ID
selectValues sql.SelectValues
}
// EventEdges holds the relations/edges for other nodes in the graph.
type EventEdges struct {
// Participants holds the value of the participants edge.
Participants []*EventParticipant `json:"participants,omitempty"`
// Thread holds the value of the thread edge.
Thread *Post `json:"thread,omitempty"`
// PrimaryImage holds the value of the primary_image edge.
PrimaryImage *Asset `json:"primary_image,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [3]bool
}
// ParticipantsOrErr returns the Participants value or an error if the edge
// was not loaded in eager-loading.
func (e EventEdges) ParticipantsOrErr() ([]*EventParticipant, error) {
if e.loadedTypes[0] {
return e.Participants, nil
}
return nil, &NotLoadedError{edge: "participants"}
}
// ThreadOrErr returns the Thread value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e EventEdges) ThreadOrErr() (*Post, error) {
if e.Thread != nil {
return e.Thread, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: post.Label}
}
return nil, &NotLoadedError{edge: "thread"}
}
// PrimaryImageOrErr returns the PrimaryImage value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e EventEdges) PrimaryImageOrErr() (*Asset, error) {
if e.PrimaryImage != nil {
return e.PrimaryImage, nil
} else if e.loadedTypes[2] {
return nil, &NotFoundError{label: asset.Label}
}
return nil, &NotLoadedError{edge: "primary_image"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Event) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case event.FieldMetadata:
values[i] = new([]byte)
case event.FieldLocationLatitude, event.FieldLocationLongitude:
values[i] = new(sql.NullFloat64)
case event.FieldCapacity:
values[i] = new(sql.NullInt64)
case event.FieldName, event.FieldSlug, event.FieldDescription, event.FieldParticipationPolicy, event.FieldVisibility, event.FieldLocationType, event.FieldLocationName, event.FieldLocationAddress, event.FieldLocationURL:
values[i] = new(sql.NullString)
case event.FieldCreatedAt, event.FieldUpdatedAt, event.FieldDeletedAt, event.FieldIndexedAt, event.FieldStartTime, event.FieldEndTime:
values[i] = new(sql.NullTime)
case event.FieldID:
values[i] = new(xid.ID)
case event.ForeignKeys[0]: // asset_event
values[i] = &sql.NullScanner{S: new(xid.ID)}
case event.ForeignKeys[1]: // post_event
values[i] = &sql.NullScanner{S: 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 Event fields.
func (_m *Event) 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 event.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 event.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 event.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 event.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 event.FieldIndexedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field indexed_at", values[i])
} else if value.Valid {
_m.IndexedAt = new(time.Time)
*_m.IndexedAt = value.Time
}
case event.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case event.FieldSlug:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field slug", values[i])
} else if value.Valid {
_m.Slug = value.String
}
case event.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
_m.Description = new(string)
*_m.Description = value.String
}
case event.FieldStartTime:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field start_time", values[i])
} else if value.Valid {
_m.StartTime = value.Time
}
case event.FieldEndTime:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field end_time", values[i])
} else if value.Valid {
_m.EndTime = value.Time
}
case event.FieldParticipationPolicy:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field participation_policy", values[i])
} else if value.Valid {
_m.ParticipationPolicy = value.String
}
case event.FieldVisibility:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field visibility", values[i])
} else if value.Valid {
_m.Visibility = event.Visibility(value.String)
}
case event.FieldLocationType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field location_type", values[i])
} else if value.Valid {
_m.LocationType = new(string)
*_m.LocationType = value.String
}
case event.FieldLocationName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field location_name", values[i])
} else if value.Valid {
_m.LocationName = new(string)
*_m.LocationName = value.String
}
case event.FieldLocationAddress:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field location_address", values[i])
} else if value.Valid {
_m.LocationAddress = new(string)
*_m.LocationAddress = value.String
}
case event.FieldLocationLatitude:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field location_latitude", values[i])
} else if value.Valid {
_m.LocationLatitude = new(float64)
*_m.LocationLatitude = value.Float64
}
case event.FieldLocationLongitude:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field location_longitude", values[i])
} else if value.Valid {
_m.LocationLongitude = new(float64)
*_m.LocationLongitude = value.Float64
}
case event.FieldLocationURL:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field location_url", values[i])
} else if value.Valid {
_m.LocationURL = new(string)
*_m.LocationURL = value.String
}
case event.FieldCapacity:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field capacity", values[i])
} else if value.Valid {
_m.Capacity = new(int)
*_m.Capacity = int(value.Int64)
}
case event.FieldMetadata:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field metadata", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &_m.Metadata); err != nil {
return fmt.Errorf("unmarshal field metadata: %w", err)
}
}
case event.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field asset_event", values[i])
} else if value.Valid {
_m.asset_event = new(xid.ID)
*_m.asset_event = *value.S.(*xid.ID)
}
case event.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field post_event", values[i])
} else if value.Valid {
_m.post_event = new(xid.ID)
*_m.post_event = *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 Event.
// This includes values selected through modifiers, order, etc.
func (_m *Event) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryParticipants queries the "participants" edge of the Event entity.
func (_m *Event) QueryParticipants() *EventParticipantQuery {
return NewEventClient(_m.config).QueryParticipants(_m)
}
// QueryThread queries the "thread" edge of the Event entity.
func (_m *Event) QueryThread() *PostQuery {
return NewEventClient(_m.config).QueryThread(_m)
}
// QueryPrimaryImage queries the "primary_image" edge of the Event entity.
func (_m *Event) QueryPrimaryImage() *AssetQuery {
return NewEventClient(_m.config).QueryPrimaryImage(_m)
}
// Update returns a builder for updating this Event.
// Note that you need to call Event.Unwrap() before calling this method if this Event
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Event) Update() *EventUpdateOne {
return NewEventClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Event 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 *Event) Unwrap() *Event {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Event is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Event) String() string {
var builder strings.Builder
builder.WriteString("Event(")
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.IndexedAt; v != nil {
builder.WriteString("indexed_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("slug=")
builder.WriteString(_m.Slug)
builder.WriteString(", ")
if v := _m.Description; v != nil {
builder.WriteString("description=")
builder.WriteString(*v)
}
builder.WriteString(", ")
builder.WriteString("start_time=")
builder.WriteString(_m.StartTime.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("end_time=")
builder.WriteString(_m.EndTime.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("participation_policy=")
builder.WriteString(_m.ParticipationPolicy)
builder.WriteString(", ")
builder.WriteString("visibility=")
builder.WriteString(fmt.Sprintf("%v", _m.Visibility))
builder.WriteString(", ")
if v := _m.LocationType; v != nil {
builder.WriteString("location_type=")
builder.WriteString(*v)
}
builder.WriteString(", ")
if v := _m.LocationName; v != nil {
builder.WriteString("location_name=")
builder.WriteString(*v)
}
builder.WriteString(", ")
if v := _m.LocationAddress; v != nil {
builder.WriteString("location_address=")
builder.WriteString(*v)
}
builder.WriteString(", ")
if v := _m.LocationLatitude; v != nil {
builder.WriteString("location_latitude=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
if v := _m.LocationLongitude; v != nil {
builder.WriteString("location_longitude=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
if v := _m.LocationURL; v != nil {
builder.WriteString("location_url=")
builder.WriteString(*v)
}
builder.WriteString(", ")
if v := _m.Capacity; v != nil {
builder.WriteString("capacity=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
builder.WriteString("metadata=")
builder.WriteString(fmt.Sprintf("%v", _m.Metadata))
builder.WriteByte(')')
return builder.String()
}
// Events is a parsable slice of Event.
type Events []*Event