2024-08-11 03:51:22 +02:00
|
|
|
// 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/google/uuid"
|
|
|
|
|
"github.com/lysand-org/versia-go/ent/note"
|
|
|
|
|
"github.com/lysand-org/versia-go/ent/user"
|
2024-08-22 23:03:38 +02:00
|
|
|
"github.com/lysand-org/versia-go/pkg/versia"
|
2024-08-11 03:51:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Note is the model entity for the Note schema.
|
|
|
|
|
type Note struct {
|
|
|
|
|
config `json:"-"`
|
|
|
|
|
// ID of the ent.
|
|
|
|
|
ID uuid.UUID `json:"id,omitempty"`
|
|
|
|
|
// IsRemote holds the value of the "isRemote" field.
|
|
|
|
|
IsRemote bool `json:"isRemote,omitempty"`
|
|
|
|
|
// URI holds the value of the "uri" field.
|
|
|
|
|
URI string `json:"uri,omitempty"`
|
|
|
|
|
// Extensions holds the value of the "extensions" field.
|
2024-08-22 23:03:38 +02:00
|
|
|
Extensions versia.Extensions `json:"extensions,omitempty"`
|
2024-08-11 03:51:22 +02:00
|
|
|
// 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"`
|
|
|
|
|
// Subject holds the value of the "subject" field.
|
|
|
|
|
Subject *string `json:"subject,omitempty"`
|
|
|
|
|
// Content holds the value of the "content" field.
|
|
|
|
|
Content string `json:"content,omitempty"`
|
|
|
|
|
// IsSensitive holds the value of the "isSensitive" field.
|
|
|
|
|
IsSensitive bool `json:"isSensitive,omitempty"`
|
|
|
|
|
// Visibility holds the value of the "visibility" field.
|
|
|
|
|
Visibility note.Visibility `json:"visibility,omitempty"`
|
|
|
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
|
|
|
// The values are being populated by the NoteQuery when eager-loading is set.
|
|
|
|
|
Edges NoteEdges `json:"edges"`
|
|
|
|
|
note_author *uuid.UUID
|
|
|
|
|
selectValues sql.SelectValues
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NoteEdges holds the relations/edges for other nodes in the graph.
|
|
|
|
|
type NoteEdges struct {
|
|
|
|
|
// Author holds the value of the author edge.
|
|
|
|
|
Author *User `json:"author,omitempty"`
|
|
|
|
|
// Mentions holds the value of the mentions edge.
|
|
|
|
|
Mentions []*User `json:"mentions,omitempty"`
|
|
|
|
|
// Attachments holds the value of the attachments edge.
|
|
|
|
|
Attachments []*Attachment `json:"attachments,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 NoteEdges) AuthorOrErr() (*User, error) {
|
|
|
|
|
if e.Author != nil {
|
|
|
|
|
return e.Author, nil
|
|
|
|
|
} else if e.loadedTypes[0] {
|
|
|
|
|
return nil, &NotFoundError{label: user.Label}
|
|
|
|
|
}
|
|
|
|
|
return nil, &NotLoadedError{edge: "author"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MentionsOrErr returns the Mentions value or an error if the edge
|
|
|
|
|
// was not loaded in eager-loading.
|
|
|
|
|
func (e NoteEdges) MentionsOrErr() ([]*User, error) {
|
|
|
|
|
if e.loadedTypes[1] {
|
|
|
|
|
return e.Mentions, nil
|
|
|
|
|
}
|
|
|
|
|
return nil, &NotLoadedError{edge: "mentions"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AttachmentsOrErr returns the Attachments value or an error if the edge
|
|
|
|
|
// was not loaded in eager-loading.
|
|
|
|
|
func (e NoteEdges) AttachmentsOrErr() ([]*Attachment, error) {
|
|
|
|
|
if e.loadedTypes[2] {
|
|
|
|
|
return e.Attachments, nil
|
|
|
|
|
}
|
|
|
|
|
return nil, &NotLoadedError{edge: "attachments"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
|
|
|
func (*Note) scanValues(columns []string) ([]any, error) {
|
|
|
|
|
values := make([]any, len(columns))
|
|
|
|
|
for i := range columns {
|
|
|
|
|
switch columns[i] {
|
|
|
|
|
case note.FieldExtensions:
|
|
|
|
|
values[i] = new([]byte)
|
|
|
|
|
case note.FieldIsRemote, note.FieldIsSensitive:
|
|
|
|
|
values[i] = new(sql.NullBool)
|
|
|
|
|
case note.FieldURI, note.FieldSubject, note.FieldContent, note.FieldVisibility:
|
|
|
|
|
values[i] = new(sql.NullString)
|
|
|
|
|
case note.FieldCreatedAt, note.FieldUpdatedAt:
|
|
|
|
|
values[i] = new(sql.NullTime)
|
|
|
|
|
case note.FieldID:
|
|
|
|
|
values[i] = new(uuid.UUID)
|
|
|
|
|
case note.ForeignKeys[0]: // note_author
|
|
|
|
|
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
|
|
|
|
default:
|
|
|
|
|
values[i] = new(sql.UnknownType)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return values, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
|
|
|
// to the Note fields.
|
|
|
|
|
func (n *Note) 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 note.FieldID:
|
|
|
|
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
|
|
|
|
return fmt.Errorf("unexpected type %T for field id", values[i])
|
|
|
|
|
} else if value != nil {
|
|
|
|
|
n.ID = *value
|
|
|
|
|
}
|
|
|
|
|
case note.FieldIsRemote:
|
|
|
|
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
|
|
|
|
return fmt.Errorf("unexpected type %T for field isRemote", values[i])
|
|
|
|
|
} else if value.Valid {
|
|
|
|
|
n.IsRemote = value.Bool
|
|
|
|
|
}
|
|
|
|
|
case note.FieldURI:
|
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
|
return fmt.Errorf("unexpected type %T for field uri", values[i])
|
|
|
|
|
} else if value.Valid {
|
|
|
|
|
n.URI = value.String
|
|
|
|
|
}
|
|
|
|
|
case note.FieldExtensions:
|
|
|
|
|
if value, ok := values[i].(*[]byte); !ok {
|
|
|
|
|
return fmt.Errorf("unexpected type %T for field extensions", values[i])
|
|
|
|
|
} else if value != nil && len(*value) > 0 {
|
|
|
|
|
if err := json.Unmarshal(*value, &n.Extensions); err != nil {
|
|
|
|
|
return fmt.Errorf("unmarshal field extensions: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case note.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 {
|
|
|
|
|
n.CreatedAt = value.Time
|
|
|
|
|
}
|
|
|
|
|
case note.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 {
|
|
|
|
|
n.UpdatedAt = value.Time
|
|
|
|
|
}
|
|
|
|
|
case note.FieldSubject:
|
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
|
return fmt.Errorf("unexpected type %T for field subject", values[i])
|
|
|
|
|
} else if value.Valid {
|
|
|
|
|
n.Subject = new(string)
|
|
|
|
|
*n.Subject = value.String
|
|
|
|
|
}
|
|
|
|
|
case note.FieldContent:
|
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
|
return fmt.Errorf("unexpected type %T for field content", values[i])
|
|
|
|
|
} else if value.Valid {
|
|
|
|
|
n.Content = value.String
|
|
|
|
|
}
|
|
|
|
|
case note.FieldIsSensitive:
|
|
|
|
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
|
|
|
|
return fmt.Errorf("unexpected type %T for field isSensitive", values[i])
|
|
|
|
|
} else if value.Valid {
|
|
|
|
|
n.IsSensitive = value.Bool
|
|
|
|
|
}
|
|
|
|
|
case note.FieldVisibility:
|
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
|
return fmt.Errorf("unexpected type %T for field visibility", values[i])
|
|
|
|
|
} else if value.Valid {
|
|
|
|
|
n.Visibility = note.Visibility(value.String)
|
|
|
|
|
}
|
|
|
|
|
case note.ForeignKeys[0]:
|
|
|
|
|
if value, ok := values[i].(*sql.NullScanner); !ok {
|
|
|
|
|
return fmt.Errorf("unexpected type %T for field note_author", values[i])
|
|
|
|
|
} else if value.Valid {
|
|
|
|
|
n.note_author = new(uuid.UUID)
|
|
|
|
|
*n.note_author = *value.S.(*uuid.UUID)
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
n.selectValues.Set(columns[i], values[i])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the Note.
|
|
|
|
|
// This includes values selected through modifiers, order, etc.
|
|
|
|
|
func (n *Note) Value(name string) (ent.Value, error) {
|
|
|
|
|
return n.selectValues.Get(name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryAuthor queries the "author" edge of the Note entity.
|
|
|
|
|
func (n *Note) QueryAuthor() *UserQuery {
|
|
|
|
|
return NewNoteClient(n.config).QueryAuthor(n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryMentions queries the "mentions" edge of the Note entity.
|
|
|
|
|
func (n *Note) QueryMentions() *UserQuery {
|
|
|
|
|
return NewNoteClient(n.config).QueryMentions(n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryAttachments queries the "attachments" edge of the Note entity.
|
|
|
|
|
func (n *Note) QueryAttachments() *AttachmentQuery {
|
|
|
|
|
return NewNoteClient(n.config).QueryAttachments(n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update returns a builder for updating this Note.
|
|
|
|
|
// Note that you need to call Note.Unwrap() before calling this method if this Note
|
|
|
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
|
|
|
func (n *Note) Update() *NoteUpdateOne {
|
|
|
|
|
return NewNoteClient(n.config).UpdateOne(n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Unwrap unwraps the Note 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 (n *Note) Unwrap() *Note {
|
|
|
|
|
_tx, ok := n.config.driver.(*txDriver)
|
|
|
|
|
if !ok {
|
|
|
|
|
panic("ent: Note is not a transactional entity")
|
|
|
|
|
}
|
|
|
|
|
n.config.driver = _tx.drv
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// String implements the fmt.Stringer.
|
|
|
|
|
func (n *Note) String() string {
|
|
|
|
|
var builder strings.Builder
|
|
|
|
|
builder.WriteString("Note(")
|
|
|
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", n.ID))
|
|
|
|
|
builder.WriteString("isRemote=")
|
|
|
|
|
builder.WriteString(fmt.Sprintf("%v", n.IsRemote))
|
|
|
|
|
builder.WriteString(", ")
|
|
|
|
|
builder.WriteString("uri=")
|
|
|
|
|
builder.WriteString(n.URI)
|
|
|
|
|
builder.WriteString(", ")
|
|
|
|
|
builder.WriteString("extensions=")
|
|
|
|
|
builder.WriteString(fmt.Sprintf("%v", n.Extensions))
|
|
|
|
|
builder.WriteString(", ")
|
|
|
|
|
builder.WriteString("created_at=")
|
|
|
|
|
builder.WriteString(n.CreatedAt.Format(time.ANSIC))
|
|
|
|
|
builder.WriteString(", ")
|
|
|
|
|
builder.WriteString("updated_at=")
|
|
|
|
|
builder.WriteString(n.UpdatedAt.Format(time.ANSIC))
|
|
|
|
|
builder.WriteString(", ")
|
|
|
|
|
if v := n.Subject; v != nil {
|
|
|
|
|
builder.WriteString("subject=")
|
|
|
|
|
builder.WriteString(*v)
|
|
|
|
|
}
|
|
|
|
|
builder.WriteString(", ")
|
|
|
|
|
builder.WriteString("content=")
|
|
|
|
|
builder.WriteString(n.Content)
|
|
|
|
|
builder.WriteString(", ")
|
|
|
|
|
builder.WriteString("isSensitive=")
|
|
|
|
|
builder.WriteString(fmt.Sprintf("%v", n.IsSensitive))
|
|
|
|
|
builder.WriteString(", ")
|
|
|
|
|
builder.WriteString("visibility=")
|
|
|
|
|
builder.WriteString(fmt.Sprintf("%v", n.Visibility))
|
|
|
|
|
builder.WriteByte(')')
|
|
|
|
|
return builder.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Notes is a parsable slice of Note.
|
|
|
|
|
type Notes []*Note
|