question.go•8.95 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/account"
"github.com/Southclaws/storyden/internal/ent/question"
"github.com/rs/xid"
)
// Question is the model entity for the Question schema.
type Question 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"`
// IndexedAt holds the value of the "indexed_at" field.
IndexedAt *time.Time `json:"indexed_at,omitempty"`
// Slug holds the value of the "slug" field.
Slug string `json:"slug,omitempty"`
// Query holds the value of the "query" field.
Query string `json:"query,omitempty"`
// Result holds the value of the "result" field.
Result string `json:"result,omitempty"`
// Metadata holds the value of the "metadata" field.
Metadata map[string]interface{} `json:"metadata,omitempty"`
// AccountID holds the value of the "account_id" field.
AccountID xid.ID `json:"account_id,omitempty"`
// ParentQuestionID holds the value of the "parent_question_id" field.
ParentQuestionID xid.ID `json:"parent_question_id,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the QuestionQuery when eager-loading is set.
Edges QuestionEdges `json:"edges"`
selectValues sql.SelectValues
}
// QuestionEdges holds the relations/edges for other nodes in the graph.
type QuestionEdges struct {
// Author holds the value of the author edge.
Author *Account `json:"author,omitempty"`
// Parent holds the value of the parent edge.
Parent *Question `json:"parent,omitempty"`
// ParentQuestion holds the value of the parent_question edge.
ParentQuestion []*Question `json:"parent_question,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [3]bool
}
// AuthorOrErr returns the Author value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e QuestionEdges) AuthorOrErr() (*Account, error) {
if e.Author != nil {
return e.Author, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: account.Label}
}
return nil, &NotLoadedError{edge: "author"}
}
// ParentOrErr returns the Parent value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e QuestionEdges) ParentOrErr() (*Question, error) {
if e.Parent != nil {
return e.Parent, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: question.Label}
}
return nil, &NotLoadedError{edge: "parent"}
}
// ParentQuestionOrErr returns the ParentQuestion value or an error if the edge
// was not loaded in eager-loading.
func (e QuestionEdges) ParentQuestionOrErr() ([]*Question, error) {
if e.loadedTypes[2] {
return e.ParentQuestion, nil
}
return nil, &NotLoadedError{edge: "parent_question"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Question) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case question.FieldMetadata:
values[i] = new([]byte)
case question.FieldSlug, question.FieldQuery, question.FieldResult:
values[i] = new(sql.NullString)
case question.FieldCreatedAt, question.FieldIndexedAt:
values[i] = new(sql.NullTime)
case question.FieldID, question.FieldAccountID, question.FieldParentQuestionID:
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 Question fields.
func (_m *Question) 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 question.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 question.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 question.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 question.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 question.FieldQuery:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field query", values[i])
} else if value.Valid {
_m.Query = value.String
}
case question.FieldResult:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field result", values[i])
} else if value.Valid {
_m.Result = value.String
}
case question.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 question.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 question.FieldParentQuestionID:
if value, ok := values[i].(*xid.ID); !ok {
return fmt.Errorf("unexpected type %T for field parent_question_id", values[i])
} else if value != nil {
_m.ParentQuestionID = *value
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Question.
// This includes values selected through modifiers, order, etc.
func (_m *Question) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryAuthor queries the "author" edge of the Question entity.
func (_m *Question) QueryAuthor() *AccountQuery {
return NewQuestionClient(_m.config).QueryAuthor(_m)
}
// QueryParent queries the "parent" edge of the Question entity.
func (_m *Question) QueryParent() *QuestionQuery {
return NewQuestionClient(_m.config).QueryParent(_m)
}
// QueryParentQuestion queries the "parent_question" edge of the Question entity.
func (_m *Question) QueryParentQuestion() *QuestionQuery {
return NewQuestionClient(_m.config).QueryParentQuestion(_m)
}
// Update returns a builder for updating this Question.
// Note that you need to call Question.Unwrap() before calling this method if this Question
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Question) Update() *QuestionUpdateOne {
return NewQuestionClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Question 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 *Question) Unwrap() *Question {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Question is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Question) String() string {
var builder strings.Builder
builder.WriteString("Question(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.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("slug=")
builder.WriteString(_m.Slug)
builder.WriteString(", ")
builder.WriteString("query=")
builder.WriteString(_m.Query)
builder.WriteString(", ")
builder.WriteString("result=")
builder.WriteString(_m.Result)
builder.WriteString(", ")
builder.WriteString("metadata=")
builder.WriteString(fmt.Sprintf("%v", _m.Metadata))
builder.WriteString(", ")
builder.WriteString("account_id=")
builder.WriteString(fmt.Sprintf("%v", _m.AccountID))
builder.WriteString(", ")
builder.WriteString("parent_question_id=")
builder.WriteString(fmt.Sprintf("%v", _m.ParentQuestionID))
builder.WriteByte(')')
return builder.String()
}
// Questions is a parsable slice of Question.
type Questions []*Question