Upgraded ent.

This commit is contained in:
mikestefanello 2025-02-18 19:27:00 -05:00
parent 633c60cdf5
commit 5cad4cbd33
9 changed files with 70 additions and 56 deletions

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
}