manager/ent/alias.go

185 lines
5.8 KiB
Go
Raw Normal View History

2025-02-06 09:31:49 +01:00
// Code generated by ent, DO NOT EDIT.
2022-04-08 21:26:25 +02:00
package ent
import (
"fmt"
"strings"
"time"
"code.icod.de/postfix/manager/ent/alias"
"code.icod.de/postfix/manager/ent/domain"
2025-02-06 09:31:49 +01:00
"entgo.io/ent"
2022-04-08 21:26:25 +02:00
"entgo.io/ent/dialect/sql"
)
// Alias is the model entity for the Alias schema.
type Alias struct {
config `json:"-"`
// ID of the ent.
ID int64 `json:"id,omitempty"`
// Created holds the value of the "created" field.
Created time.Time `json:"created,omitempty"`
// Modified holds the value of the "modified" field.
Modified *time.Time `json:"modified,omitempty"`
// DomainID holds the value of the "domain_id" field.
DomainID int64 `json:"domain_id,omitempty"`
// Goto holds the value of the "goto" field.
Goto string `json:"goto,omitempty"`
// Active holds the value of the "active" field.
Active bool `json:"active,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the AliasQuery when eager-loading is set.
2025-02-06 09:31:49 +01:00
Edges AliasEdges `json:"edges"`
selectValues sql.SelectValues
2022-04-08 21:26:25 +02:00
}
// AliasEdges holds the relations/edges for other nodes in the graph.
type AliasEdges struct {
// Domain holds the value of the domain edge.
Domain *Domain `json:"domain,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// DomainOrErr returns the Domain value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e AliasEdges) DomainOrErr() (*Domain, error) {
2025-02-06 09:31:49 +01:00
if e.Domain != nil {
2022-04-08 21:26:25 +02:00
return e.Domain, nil
2025-02-06 09:31:49 +01:00
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: domain.Label}
2022-04-08 21:26:25 +02:00
}
return nil, &NotLoadedError{edge: "domain"}
}
// scanValues returns the types for scanning values from sql.Rows.
2025-02-06 09:31:49 +01:00
func (*Alias) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
2022-04-08 21:26:25 +02:00
for i := range columns {
switch columns[i] {
case alias.FieldActive:
values[i] = new(sql.NullBool)
case alias.FieldID, alias.FieldDomainID:
values[i] = new(sql.NullInt64)
case alias.FieldGoto:
values[i] = new(sql.NullString)
case alias.FieldCreated, alias.FieldModified:
values[i] = new(sql.NullTime)
default:
2025-02-06 09:31:49 +01:00
values[i] = new(sql.UnknownType)
2022-04-08 21:26:25 +02:00
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Alias fields.
2025-02-06 09:31:49 +01:00
func (a *Alias) assignValues(columns []string, values []any) error {
2022-04-08 21:26:25 +02:00
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 alias.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
a.ID = int64(value.Int64)
case alias.FieldCreated:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created", values[i])
} else if value.Valid {
a.Created = value.Time
}
case alias.FieldModified:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field modified", values[i])
} else if value.Valid {
a.Modified = new(time.Time)
*a.Modified = value.Time
}
case alias.FieldDomainID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field domain_id", values[i])
} else if value.Valid {
a.DomainID = value.Int64
}
case alias.FieldGoto:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field goto", values[i])
} else if value.Valid {
a.Goto = value.String
}
case alias.FieldActive:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field active", values[i])
} else if value.Valid {
a.Active = value.Bool
}
2025-02-06 09:31:49 +01:00
default:
a.selectValues.Set(columns[i], values[i])
2022-04-08 21:26:25 +02:00
}
}
return nil
}
2025-02-06 09:31:49 +01:00
// Value returns the ent.Value that was dynamically selected and assigned to the Alias.
// This includes values selected through modifiers, order, etc.
func (a *Alias) Value(name string) (ent.Value, error) {
return a.selectValues.Get(name)
}
2022-04-08 21:26:25 +02:00
// QueryDomain queries the "domain" edge of the Alias entity.
func (a *Alias) QueryDomain() *DomainQuery {
2025-02-06 09:31:49 +01:00
return NewAliasClient(a.config).QueryDomain(a)
2022-04-08 21:26:25 +02:00
}
// Update returns a builder for updating this Alias.
// Note that you need to call Alias.Unwrap() before calling this method if this Alias
// was returned from a transaction, and the transaction was committed or rolled back.
func (a *Alias) Update() *AliasUpdateOne {
2025-02-06 09:31:49 +01:00
return NewAliasClient(a.config).UpdateOne(a)
2022-04-08 21:26:25 +02:00
}
// Unwrap unwraps the Alias 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 (a *Alias) Unwrap() *Alias {
2025-02-06 09:31:49 +01:00
_tx, ok := a.config.driver.(*txDriver)
2022-04-08 21:26:25 +02:00
if !ok {
panic("ent: Alias is not a transactional entity")
}
2025-02-06 09:31:49 +01:00
a.config.driver = _tx.drv
2022-04-08 21:26:25 +02:00
return a
}
// String implements the fmt.Stringer.
func (a *Alias) String() string {
var builder strings.Builder
builder.WriteString("Alias(")
2025-02-06 09:31:49 +01:00
builder.WriteString(fmt.Sprintf("id=%v, ", a.ID))
builder.WriteString("created=")
2022-04-08 21:26:25 +02:00
builder.WriteString(a.Created.Format(time.ANSIC))
2025-02-06 09:31:49 +01:00
builder.WriteString(", ")
2022-04-08 21:26:25 +02:00
if v := a.Modified; v != nil {
2025-02-06 09:31:49 +01:00
builder.WriteString("modified=")
2022-04-08 21:26:25 +02:00
builder.WriteString(v.Format(time.ANSIC))
}
2025-02-06 09:31:49 +01:00
builder.WriteString(", ")
builder.WriteString("domain_id=")
2022-04-08 21:26:25 +02:00
builder.WriteString(fmt.Sprintf("%v", a.DomainID))
2025-02-06 09:31:49 +01:00
builder.WriteString(", ")
builder.WriteString("goto=")
2022-04-08 21:26:25 +02:00
builder.WriteString(a.Goto)
2025-02-06 09:31:49 +01:00
builder.WriteString(", ")
builder.WriteString("active=")
2022-04-08 21:26:25 +02:00
builder.WriteString(fmt.Sprintf("%v", a.Active))
builder.WriteByte(')')
return builder.String()
}
// AliasSlice is a parsable slice of Alias.
type AliasSlice []*Alias