homebox/backend/internal/data/ent/user.go

270 lines
9 KiB
Go
Raw Permalink Normal View History

2022-08-30 18:04:50 +00:00
// Code generated by ent, DO NOT EDIT.
2022-08-30 02:30:36 +00:00
package ent
import (
"fmt"
"strings"
2022-08-30 18:04:50 +00:00
"time"
2022-08-30 02:30:36 +00:00
"entgo.io/ent"
2022-08-30 02:30:36 +00:00
"entgo.io/ent/dialect/sql"
"github.com/google/uuid"
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
2022-08-30 02:30:36 +00:00
)
// User is the model entity for the User schema.
type User struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
2022-08-30 18:04:50 +00: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"`
2022-08-30 02:30:36 +00:00
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Email holds the value of the "email" field.
Email string `json:"email,omitempty"`
// Password holds the value of the "password" field.
Password string `json:"-"`
// IsSuperuser holds the value of the "is_superuser" field.
IsSuperuser bool `json:"is_superuser,omitempty"`
// Superuser holds the value of the "superuser" field.
Superuser bool `json:"superuser,omitempty"`
// Role holds the value of the "role" field.
Role user.Role `json:"role,omitempty"`
// ActivatedOn holds the value of the "activated_on" field.
ActivatedOn time.Time `json:"activated_on,omitempty"`
2022-08-30 02:30:36 +00:00
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the UserQuery when eager-loading is set.
Edges UserEdges `json:"edges"`
group_users *uuid.UUID
selectValues sql.SelectValues
2022-08-30 02:30:36 +00:00
}
// UserEdges holds the relations/edges for other nodes in the graph.
type UserEdges struct {
2022-08-30 18:04:50 +00:00
// Group holds the value of the group edge.
Group *Group `json:"group,omitempty"`
2022-08-30 02:30:36 +00:00
// AuthTokens holds the value of the auth_tokens edge.
AuthTokens []*AuthTokens `json:"auth_tokens,omitempty"`
// Notifiers holds the value of the notifiers edge.
Notifiers []*Notifier `json:"notifiers,omitempty"`
2022-08-30 02:30:36 +00:00
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [3]bool
2022-08-30 18:04:50 +00:00
}
// GroupOrErr returns the Group value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e UserEdges) GroupOrErr() (*Group, error) {
if e.loadedTypes[0] {
if e.Group == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: group.Label}
}
return e.Group, nil
}
return nil, &NotLoadedError{edge: "group"}
2022-08-30 02:30:36 +00:00
}
// AuthTokensOrErr returns the AuthTokens value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) AuthTokensOrErr() ([]*AuthTokens, error) {
2022-08-30 18:04:50 +00:00
if e.loadedTypes[1] {
2022-08-30 02:30:36 +00:00
return e.AuthTokens, nil
}
return nil, &NotLoadedError{edge: "auth_tokens"}
}
// NotifiersOrErr returns the Notifiers value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) NotifiersOrErr() ([]*Notifier, error) {
if e.loadedTypes[2] {
return e.Notifiers, nil
}
return nil, &NotLoadedError{edge: "notifiers"}
}
2022-08-30 02:30:36 +00:00
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
2022-08-30 02:30:36 +00:00
for i := range columns {
switch columns[i] {
case user.FieldIsSuperuser, user.FieldSuperuser:
2022-08-30 02:30:36 +00:00
values[i] = new(sql.NullBool)
case user.FieldName, user.FieldEmail, user.FieldPassword, user.FieldRole:
2022-08-30 02:30:36 +00:00
values[i] = new(sql.NullString)
case user.FieldCreatedAt, user.FieldUpdatedAt, user.FieldActivatedOn:
2022-08-30 18:04:50 +00:00
values[i] = new(sql.NullTime)
2022-08-30 02:30:36 +00:00
case user.FieldID:
values[i] = new(uuid.UUID)
2022-08-30 18:04:50 +00:00
case user.ForeignKeys[0]: // group_users
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
2022-08-30 02:30:36 +00:00
default:
values[i] = new(sql.UnknownType)
2022-08-30 02:30:36 +00:00
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the User fields.
func (u *User) assignValues(columns []string, values []any) error {
2022-08-30 02:30:36 +00: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 user.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
u.ID = *value
}
2022-08-30 18:04:50 +00:00
case user.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 {
u.CreatedAt = value.Time
}
case user.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 {
u.UpdatedAt = value.Time
}
2022-08-30 02:30:36 +00:00
case user.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
u.Name = value.String
}
case user.FieldEmail:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field email", values[i])
} else if value.Valid {
u.Email = value.String
}
case user.FieldPassword:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field password", values[i])
} else if value.Valid {
u.Password = value.String
}
case user.FieldIsSuperuser:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_superuser", values[i])
} else if value.Valid {
u.IsSuperuser = value.Bool
}
case user.FieldSuperuser:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field superuser", values[i])
} else if value.Valid {
u.Superuser = value.Bool
}
case user.FieldRole:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field role", values[i])
} else if value.Valid {
u.Role = user.Role(value.String)
}
case user.FieldActivatedOn:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field activated_on", values[i])
} else if value.Valid {
u.ActivatedOn = value.Time
}
2022-08-30 18:04:50 +00:00
case user.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field group_users", values[i])
} else if value.Valid {
u.group_users = new(uuid.UUID)
*u.group_users = *value.S.(*uuid.UUID)
}
default:
u.selectValues.Set(columns[i], values[i])
2022-08-30 02:30:36 +00:00
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the User.
// This includes values selected through modifiers, order, etc.
func (u *User) Value(name string) (ent.Value, error) {
return u.selectValues.Get(name)
}
2022-08-30 18:04:50 +00:00
// QueryGroup queries the "group" edge of the User entity.
func (u *User) QueryGroup() *GroupQuery {
2023-01-28 21:03:51 +00:00
return NewUserClient(u.config).QueryGroup(u)
2022-08-30 18:04:50 +00:00
}
2022-08-30 02:30:36 +00:00
// QueryAuthTokens queries the "auth_tokens" edge of the User entity.
func (u *User) QueryAuthTokens() *AuthTokensQuery {
2023-01-28 21:03:51 +00:00
return NewUserClient(u.config).QueryAuthTokens(u)
2022-08-30 02:30:36 +00:00
}
// QueryNotifiers queries the "notifiers" edge of the User entity.
func (u *User) QueryNotifiers() *NotifierQuery {
return NewUserClient(u.config).QueryNotifiers(u)
}
2022-08-30 02:30:36 +00:00
// Update returns a builder for updating this User.
// Note that you need to call User.Unwrap() before calling this method if this User
// was returned from a transaction, and the transaction was committed or rolled back.
func (u *User) Update() *UserUpdateOne {
2023-01-28 21:03:51 +00:00
return NewUserClient(u.config).UpdateOne(u)
2022-08-30 02:30:36 +00:00
}
// Unwrap unwraps the User 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 (u *User) Unwrap() *User {
2022-08-30 18:04:50 +00:00
_tx, ok := u.config.driver.(*txDriver)
2022-08-30 02:30:36 +00:00
if !ok {
panic("ent: User is not a transactional entity")
}
2022-08-30 18:04:50 +00:00
u.config.driver = _tx.drv
2022-08-30 02:30:36 +00:00
return u
}
// String implements the fmt.Stringer.
func (u *User) String() string {
var builder strings.Builder
builder.WriteString("User(")
2022-08-30 18:04:50 +00:00
builder.WriteString(fmt.Sprintf("id=%v, ", u.ID))
builder.WriteString("created_at=")
builder.WriteString(u.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(u.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("name=")
2022-08-30 02:30:36 +00:00
builder.WriteString(u.Name)
2022-08-30 18:04:50 +00:00
builder.WriteString(", ")
builder.WriteString("email=")
2022-08-30 02:30:36 +00:00
builder.WriteString(u.Email)
2022-08-30 18:04:50 +00:00
builder.WriteString(", ")
builder.WriteString("password=<sensitive>")
builder.WriteString(", ")
builder.WriteString("is_superuser=")
2022-08-30 02:30:36 +00:00
builder.WriteString(fmt.Sprintf("%v", u.IsSuperuser))
builder.WriteString(", ")
builder.WriteString("superuser=")
builder.WriteString(fmt.Sprintf("%v", u.Superuser))
builder.WriteString(", ")
builder.WriteString("role=")
builder.WriteString(fmt.Sprintf("%v", u.Role))
builder.WriteString(", ")
builder.WriteString("activated_on=")
builder.WriteString(u.ActivatedOn.Format(time.ANSIC))
2022-08-30 02:30:36 +00:00
builder.WriteByte(')')
return builder.String()
}
// Users is a parsable slice of User.
type Users []*User