Upgraded ent.

This commit is contained in:
mikestefanello 2025-02-18 19:27:00 -05:00
parent acbc5e4bf6
commit 0bf9ab7189
9 changed files with 70 additions and 56 deletions

View file

@ -70,7 +70,7 @@ var (
columnCheck sql.ColumnCheck
)
// columnChecker checks if the column exists in the given table.
// checkColumn checks if the column exists in the given table.
func checkColumn(table, column string) error {
initCheck.Do(func() {
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{

View file

@ -41,12 +41,10 @@ type PasswordTokenEdges struct {
// UserOrErr returns the User value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e PasswordTokenEdges) UserOrErr() (*User, error) {
if e.loadedTypes[0] {
if e.User == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: user.Label}
}
if e.User != nil {
return e.User, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: user.Label}
}
return nil, &NotLoadedError{edge: "user"}
}

View file

@ -106,7 +106,7 @@ func (ptc *PasswordTokenCreate) check() error {
if _, ok := ptc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "PasswordToken.created_at"`)}
}
if _, ok := ptc.mutation.UserID(); !ok {
if len(ptc.mutation.UserIDs()) == 0 {
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "PasswordToken.user"`)}
}
return nil

View file

@ -7,6 +7,7 @@ import (
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
@ -85,7 +86,7 @@ func (ptq *PasswordTokenQuery) QueryUser() *UserQuery {
// First returns the first PasswordToken entity from the query.
// Returns a *NotFoundError when no PasswordToken was found.
func (ptq *PasswordTokenQuery) First(ctx context.Context) (*PasswordToken, error) {
nodes, err := ptq.Limit(1).All(setContextOp(ctx, ptq.ctx, "First"))
nodes, err := ptq.Limit(1).All(setContextOp(ctx, ptq.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
@ -108,7 +109,7 @@ func (ptq *PasswordTokenQuery) FirstX(ctx context.Context) *PasswordToken {
// Returns a *NotFoundError when no PasswordToken ID was found.
func (ptq *PasswordTokenQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = ptq.Limit(1).IDs(setContextOp(ctx, ptq.ctx, "FirstID")); err != nil {
if ids, err = ptq.Limit(1).IDs(setContextOp(ctx, ptq.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
@ -131,7 +132,7 @@ func (ptq *PasswordTokenQuery) FirstIDX(ctx context.Context) int {
// Returns a *NotSingularError when more than one PasswordToken entity is found.
// Returns a *NotFoundError when no PasswordToken entities are found.
func (ptq *PasswordTokenQuery) Only(ctx context.Context) (*PasswordToken, error) {
nodes, err := ptq.Limit(2).All(setContextOp(ctx, ptq.ctx, "Only"))
nodes, err := ptq.Limit(2).All(setContextOp(ctx, ptq.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
@ -159,7 +160,7 @@ func (ptq *PasswordTokenQuery) OnlyX(ctx context.Context) *PasswordToken {
// Returns a *NotFoundError when no entities are found.
func (ptq *PasswordTokenQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = ptq.Limit(2).IDs(setContextOp(ctx, ptq.ctx, "OnlyID")); err != nil {
if ids, err = ptq.Limit(2).IDs(setContextOp(ctx, ptq.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
@ -184,7 +185,7 @@ func (ptq *PasswordTokenQuery) OnlyIDX(ctx context.Context) int {
// All executes the query and returns a list of PasswordTokens.
func (ptq *PasswordTokenQuery) All(ctx context.Context) ([]*PasswordToken, error) {
ctx = setContextOp(ctx, ptq.ctx, "All")
ctx = setContextOp(ctx, ptq.ctx, ent.OpQueryAll)
if err := ptq.prepareQuery(ctx); err != nil {
return nil, err
}
@ -206,7 +207,7 @@ func (ptq *PasswordTokenQuery) IDs(ctx context.Context) (ids []int, err error) {
if ptq.ctx.Unique == nil && ptq.path != nil {
ptq.Unique(true)
}
ctx = setContextOp(ctx, ptq.ctx, "IDs")
ctx = setContextOp(ctx, ptq.ctx, ent.OpQueryIDs)
if err = ptq.Select(passwordtoken.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@ -224,7 +225,7 @@ func (ptq *PasswordTokenQuery) IDsX(ctx context.Context) []int {
// Count returns the count of the given query.
func (ptq *PasswordTokenQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, ptq.ctx, "Count")
ctx = setContextOp(ctx, ptq.ctx, ent.OpQueryCount)
if err := ptq.prepareQuery(ctx); err != nil {
return 0, err
}
@ -242,7 +243,7 @@ func (ptq *PasswordTokenQuery) CountX(ctx context.Context) int {
// Exist returns true if the query has elements in the graph.
func (ptq *PasswordTokenQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, ptq.ctx, "Exist")
ctx = setContextOp(ctx, ptq.ctx, ent.OpQueryExist)
switch _, err := ptq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
@ -536,7 +537,7 @@ func (ptgb *PasswordTokenGroupBy) Aggregate(fns ...AggregateFunc) *PasswordToken
// Scan applies the selector query and scans the result into the given value.
func (ptgb *PasswordTokenGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, ptgb.build.ctx, "GroupBy")
ctx = setContextOp(ctx, ptgb.build.ctx, ent.OpQueryGroupBy)
if err := ptgb.build.prepareQuery(ctx); err != nil {
return err
}
@ -584,7 +585,7 @@ func (pts *PasswordTokenSelect) Aggregate(fns ...AggregateFunc) *PasswordTokenSe
// Scan applies the selector query and scans the result into the given value.
func (pts *PasswordTokenSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, pts.ctx, "Select")
ctx = setContextOp(ctx, pts.ctx, ent.OpQuerySelect)
if err := pts.prepareQuery(ctx); err != nil {
return err
}

View file

@ -113,7 +113,7 @@ func (ptu *PasswordTokenUpdate) check() error {
return &ValidationError{Name: "hash", err: fmt.Errorf(`ent: validator failed for field "PasswordToken.hash": %w`, err)}
}
}
if _, ok := ptu.mutation.UserID(); ptu.mutation.UserCleared() && !ok {
if ptu.mutation.UserCleared() && len(ptu.mutation.UserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "PasswordToken.user"`)
}
return nil
@ -283,7 +283,7 @@ func (ptuo *PasswordTokenUpdateOne) check() error {
return &ValidationError{Name: "hash", err: fmt.Errorf(`ent: validator failed for field "PasswordToken.hash": %w`, err)}
}
}
if _, ok := ptuo.mutation.UserID(); ptuo.mutation.UserCleared() && !ok {
if ptuo.mutation.UserCleared() && len(ptuo.mutation.UserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "PasswordToken.user"`)
}
return nil

View file

@ -51,6 +51,6 @@ func init() {
}
const (
Version = "v0.12.5" // Version of ent codegen.
Sum = "h1:KREM5E4CSoej4zeGa88Ou/gfturAnpUv0mzAjch1sj4=" // Sum of ent codegen.
Version = "v0.14.2" // Version of ent codegen.
Sum = "h1:ywld/j2Rx4EmnIKs8eZ29cbFA1zpB+DA9TLL5l3rlq0=" // Sum of ent codegen.
)

View file

@ -8,6 +8,7 @@ import (
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
@ -85,7 +86,7 @@ func (uq *UserQuery) QueryOwner() *PasswordTokenQuery {
// First returns the first User entity from the query.
// Returns a *NotFoundError when no User was found.
func (uq *UserQuery) First(ctx context.Context) (*User, error) {
nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, "First"))
nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
@ -108,7 +109,7 @@ func (uq *UserQuery) FirstX(ctx context.Context) *User {
// Returns a *NotFoundError when no User ID was found.
func (uq *UserQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, "FirstID")); err != nil {
if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
@ -131,7 +132,7 @@ func (uq *UserQuery) FirstIDX(ctx context.Context) int {
// Returns a *NotSingularError when more than one User entity is found.
// Returns a *NotFoundError when no User entities are found.
func (uq *UserQuery) Only(ctx context.Context) (*User, error) {
nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, "Only"))
nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
@ -159,7 +160,7 @@ func (uq *UserQuery) OnlyX(ctx context.Context) *User {
// Returns a *NotFoundError when no entities are found.
func (uq *UserQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, "OnlyID")); err != nil {
if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
@ -184,7 +185,7 @@ func (uq *UserQuery) OnlyIDX(ctx context.Context) int {
// All executes the query and returns a list of Users.
func (uq *UserQuery) All(ctx context.Context) ([]*User, error) {
ctx = setContextOp(ctx, uq.ctx, "All")
ctx = setContextOp(ctx, uq.ctx, ent.OpQueryAll)
if err := uq.prepareQuery(ctx); err != nil {
return nil, err
}
@ -206,7 +207,7 @@ func (uq *UserQuery) IDs(ctx context.Context) (ids []int, err error) {
if uq.ctx.Unique == nil && uq.path != nil {
uq.Unique(true)
}
ctx = setContextOp(ctx, uq.ctx, "IDs")
ctx = setContextOp(ctx, uq.ctx, ent.OpQueryIDs)
if err = uq.Select(user.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@ -224,7 +225,7 @@ func (uq *UserQuery) IDsX(ctx context.Context) []int {
// Count returns the count of the given query.
func (uq *UserQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, uq.ctx, "Count")
ctx = setContextOp(ctx, uq.ctx, ent.OpQueryCount)
if err := uq.prepareQuery(ctx); err != nil {
return 0, err
}
@ -242,7 +243,7 @@ func (uq *UserQuery) CountX(ctx context.Context) int {
// Exist returns true if the query has elements in the graph.
func (uq *UserQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, uq.ctx, "Exist")
ctx = setContextOp(ctx, uq.ctx, ent.OpQueryExist)
switch _, err := uq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
@ -529,7 +530,7 @@ func (ugb *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy {
// Scan applies the selector query and scans the result into the given value.
func (ugb *UserGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, ugb.build.ctx, "GroupBy")
ctx = setContextOp(ctx, ugb.build.ctx, ent.OpQueryGroupBy)
if err := ugb.build.prepareQuery(ctx); err != nil {
return err
}
@ -577,7 +578,7 @@ func (us *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect {
// Scan applies the selector query and scans the result into the given value.
func (us *UserSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, us.ctx, "Select")
ctx = setContextOp(ctx, us.ctx, ent.OpQuerySelect)
if err := us.prepareQuery(ctx); err != nil {
return err
}