Files
muninn-aio/ent/link.go

142 lines
4.2 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"code.gurenya.net/carlsmei/muninn-aio/ent/link"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/google/uuid"
)
// Link is the model entity for the Link schema.
type Link struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// Key holds the value of the "key" field.
Key string `json:"key,omitempty"`
// OriginalURL holds the value of the "original_url" field.
OriginalURL string `json:"original_url,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the LinkQuery when eager-loading is set.
Edges LinkEdges `json:"edges"`
selectValues sql.SelectValues
}
// LinkEdges holds the relations/edges for other nodes in the graph.
type LinkEdges struct {
// Owner holds the value of the owner edge.
Owner []*User `json:"owner,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// OwnerOrErr returns the Owner value or an error if the edge
// was not loaded in eager-loading.
func (e LinkEdges) OwnerOrErr() ([]*User, error) {
if e.loadedTypes[0] {
return e.Owner, nil
}
return nil, &NotLoadedError{edge: "owner"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Link) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case link.FieldKey, link.FieldOriginalURL:
values[i] = new(sql.NullString)
case link.FieldID:
values[i] = 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 Link fields.
func (l *Link) 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 link.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
l.ID = *value
}
case link.FieldKey:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field key", values[i])
} else if value.Valid {
l.Key = value.String
}
case link.FieldOriginalURL:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field original_url", values[i])
} else if value.Valid {
l.OriginalURL = value.String
}
default:
l.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Link.
// This includes values selected through modifiers, order, etc.
func (l *Link) Value(name string) (ent.Value, error) {
return l.selectValues.Get(name)
}
// QueryOwner queries the "owner" edge of the Link entity.
func (l *Link) QueryOwner() *UserQuery {
return NewLinkClient(l.config).QueryOwner(l)
}
// Update returns a builder for updating this Link.
// Note that you need to call Link.Unwrap() before calling this method if this Link
// was returned from a transaction, and the transaction was committed or rolled back.
func (l *Link) Update() *LinkUpdateOne {
return NewLinkClient(l.config).UpdateOne(l)
}
// Unwrap unwraps the Link 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 (l *Link) Unwrap() *Link {
_tx, ok := l.config.driver.(*txDriver)
if !ok {
panic("ent: Link is not a transactional entity")
}
l.config.driver = _tx.drv
return l
}
// String implements the fmt.Stringer.
func (l *Link) String() string {
var builder strings.Builder
builder.WriteString("Link(")
builder.WriteString(fmt.Sprintf("id=%v, ", l.ID))
builder.WriteString("key=")
builder.WriteString(l.Key)
builder.WriteString(", ")
builder.WriteString("original_url=")
builder.WriteString(l.OriginalURL)
builder.WriteByte(')')
return builder.String()
}
// Links is a parsable slice of Link.
type Links []*Link