chore: upgrade deps + code-gen (#249)

This commit is contained in:
Hayden 2023-01-28 12:03:51 -09:00 committed by GitHub
parent 3d295b5132
commit 6ed1f3695a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 664 additions and 563 deletions

View file

@ -21,11 +21,8 @@ import (
// LocationQuery is the builder for querying Location entities.
type LocationQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.Location
withParent *LocationQuery
@ -46,20 +43,20 @@ func (lq *LocationQuery) Where(ps ...predicate.Location) *LocationQuery {
// Limit the number of records to be returned by this query.
func (lq *LocationQuery) Limit(limit int) *LocationQuery {
lq.limit = &limit
lq.ctx.Limit = &limit
return lq
}
// Offset to start from.
func (lq *LocationQuery) Offset(offset int) *LocationQuery {
lq.offset = &offset
lq.ctx.Offset = &offset
return lq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (lq *LocationQuery) Unique(unique bool) *LocationQuery {
lq.unique = &unique
lq.ctx.Unique = &unique
return lq
}
@ -160,7 +157,7 @@ func (lq *LocationQuery) QueryItems() *ItemQuery {
// First returns the first Location entity from the query.
// Returns a *NotFoundError when no Location was found.
func (lq *LocationQuery) First(ctx context.Context) (*Location, error) {
nodes, err := lq.Limit(1).All(newQueryContext(ctx, TypeLocation, "First"))
nodes, err := lq.Limit(1).All(setContextOp(ctx, lq.ctx, "First"))
if err != nil {
return nil, err
}
@ -183,7 +180,7 @@ func (lq *LocationQuery) FirstX(ctx context.Context) *Location {
// Returns a *NotFoundError when no Location ID was found.
func (lq *LocationQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = lq.Limit(1).IDs(newQueryContext(ctx, TypeLocation, "FirstID")); err != nil {
if ids, err = lq.Limit(1).IDs(setContextOp(ctx, lq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@ -206,7 +203,7 @@ func (lq *LocationQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one Location entity is found.
// Returns a *NotFoundError when no Location entities are found.
func (lq *LocationQuery) Only(ctx context.Context) (*Location, error) {
nodes, err := lq.Limit(2).All(newQueryContext(ctx, TypeLocation, "Only"))
nodes, err := lq.Limit(2).All(setContextOp(ctx, lq.ctx, "Only"))
if err != nil {
return nil, err
}
@ -234,7 +231,7 @@ func (lq *LocationQuery) OnlyX(ctx context.Context) *Location {
// Returns a *NotFoundError when no entities are found.
func (lq *LocationQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = lq.Limit(2).IDs(newQueryContext(ctx, TypeLocation, "OnlyID")); err != nil {
if ids, err = lq.Limit(2).IDs(setContextOp(ctx, lq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@ -259,7 +256,7 @@ func (lq *LocationQuery) OnlyIDX(ctx context.Context) uuid.UUID {
// All executes the query and returns a list of Locations.
func (lq *LocationQuery) All(ctx context.Context) ([]*Location, error) {
ctx = newQueryContext(ctx, TypeLocation, "All")
ctx = setContextOp(ctx, lq.ctx, "All")
if err := lq.prepareQuery(ctx); err != nil {
return nil, err
}
@ -279,7 +276,7 @@ func (lq *LocationQuery) AllX(ctx context.Context) []*Location {
// IDs executes the query and returns a list of Location IDs.
func (lq *LocationQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = newQueryContext(ctx, TypeLocation, "IDs")
ctx = setContextOp(ctx, lq.ctx, "IDs")
if err := lq.Select(location.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@ -297,7 +294,7 @@ func (lq *LocationQuery) IDsX(ctx context.Context) []uuid.UUID {
// Count returns the count of the given query.
func (lq *LocationQuery) Count(ctx context.Context) (int, error) {
ctx = newQueryContext(ctx, TypeLocation, "Count")
ctx = setContextOp(ctx, lq.ctx, "Count")
if err := lq.prepareQuery(ctx); err != nil {
return 0, err
}
@ -315,7 +312,7 @@ func (lq *LocationQuery) CountX(ctx context.Context) int {
// Exist returns true if the query has elements in the graph.
func (lq *LocationQuery) Exist(ctx context.Context) (bool, error) {
ctx = newQueryContext(ctx, TypeLocation, "Exist")
ctx = setContextOp(ctx, lq.ctx, "Exist")
switch _, err := lq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
@ -343,8 +340,7 @@ func (lq *LocationQuery) Clone() *LocationQuery {
}
return &LocationQuery{
config: lq.config,
limit: lq.limit,
offset: lq.offset,
ctx: lq.ctx.Clone(),
order: append([]OrderFunc{}, lq.order...),
inters: append([]Interceptor{}, lq.inters...),
predicates: append([]predicate.Location{}, lq.predicates...),
@ -353,9 +349,8 @@ func (lq *LocationQuery) Clone() *LocationQuery {
withGroup: lq.withGroup.Clone(),
withItems: lq.withItems.Clone(),
// clone intermediate query.
sql: lq.sql.Clone(),
path: lq.path,
unique: lq.unique,
sql: lq.sql.Clone(),
path: lq.path,
}
}
@ -418,9 +413,9 @@ func (lq *LocationQuery) WithItems(opts ...func(*ItemQuery)) *LocationQuery {
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (lq *LocationQuery) GroupBy(field string, fields ...string) *LocationGroupBy {
lq.fields = append([]string{field}, fields...)
lq.ctx.Fields = append([]string{field}, fields...)
grbuild := &LocationGroupBy{build: lq}
grbuild.flds = &lq.fields
grbuild.flds = &lq.ctx.Fields
grbuild.label = location.Label
grbuild.scan = grbuild.Scan
return grbuild
@ -439,10 +434,10 @@ func (lq *LocationQuery) GroupBy(field string, fields ...string) *LocationGroupB
// Select(location.FieldCreatedAt).
// Scan(ctx, &v)
func (lq *LocationQuery) Select(fields ...string) *LocationSelect {
lq.fields = append(lq.fields, fields...)
lq.ctx.Fields = append(lq.ctx.Fields, fields...)
sbuild := &LocationSelect{LocationQuery: lq}
sbuild.label = location.Label
sbuild.flds, sbuild.scan = &lq.fields, sbuild.Scan
sbuild.flds, sbuild.scan = &lq.ctx.Fields, sbuild.Scan
return sbuild
}
@ -462,7 +457,7 @@ func (lq *LocationQuery) prepareQuery(ctx context.Context) error {
}
}
}
for _, f := range lq.fields {
for _, f := range lq.ctx.Fields {
if !location.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@ -555,6 +550,9 @@ func (lq *LocationQuery) loadParent(ctx context.Context, query *LocationQuery, n
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(location.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@ -615,6 +613,9 @@ func (lq *LocationQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(group.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@ -665,9 +666,9 @@ func (lq *LocationQuery) loadItems(ctx context.Context, query *ItemQuery, nodes
func (lq *LocationQuery) sqlCount(ctx context.Context) (int, error) {
_spec := lq.querySpec()
_spec.Node.Columns = lq.fields
if len(lq.fields) > 0 {
_spec.Unique = lq.unique != nil && *lq.unique
_spec.Node.Columns = lq.ctx.Fields
if len(lq.ctx.Fields) > 0 {
_spec.Unique = lq.ctx.Unique != nil && *lq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, lq.driver, _spec)
}
@ -685,10 +686,10 @@ func (lq *LocationQuery) querySpec() *sqlgraph.QuerySpec {
From: lq.sql,
Unique: true,
}
if unique := lq.unique; unique != nil {
if unique := lq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := lq.fields; len(fields) > 0 {
if fields := lq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, location.FieldID)
for i := range fields {
@ -704,10 +705,10 @@ func (lq *LocationQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := lq.limit; limit != nil {
if limit := lq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := lq.offset; offset != nil {
if offset := lq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := lq.order; len(ps) > 0 {
@ -723,7 +724,7 @@ func (lq *LocationQuery) querySpec() *sqlgraph.QuerySpec {
func (lq *LocationQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(lq.driver.Dialect())
t1 := builder.Table(location.Table)
columns := lq.fields
columns := lq.ctx.Fields
if len(columns) == 0 {
columns = location.Columns
}
@ -732,7 +733,7 @@ func (lq *LocationQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = lq.sql
selector.Select(selector.Columns(columns...)...)
}
if lq.unique != nil && *lq.unique {
if lq.ctx.Unique != nil && *lq.ctx.Unique {
selector.Distinct()
}
for _, p := range lq.predicates {
@ -741,12 +742,12 @@ func (lq *LocationQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range lq.order {
p(selector)
}
if offset := lq.offset; offset != nil {
if offset := lq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := lq.limit; limit != nil {
if limit := lq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@ -766,7 +767,7 @@ func (lgb *LocationGroupBy) Aggregate(fns ...AggregateFunc) *LocationGroupBy {
// Scan applies the selector query and scans the result into the given value.
func (lgb *LocationGroupBy) Scan(ctx context.Context, v any) error {
ctx = newQueryContext(ctx, TypeLocation, "GroupBy")
ctx = setContextOp(ctx, lgb.build.ctx, "GroupBy")
if err := lgb.build.prepareQuery(ctx); err != nil {
return err
}
@ -814,7 +815,7 @@ func (ls *LocationSelect) Aggregate(fns ...AggregateFunc) *LocationSelect {
// Scan applies the selector query and scans the result into the given value.
func (ls *LocationSelect) Scan(ctx context.Context, v any) error {
ctx = newQueryContext(ctx, TypeLocation, "Select")
ctx = setContextOp(ctx, ls.ctx, "Select")
if err := ls.prepareQuery(ctx); err != nil {
return err
}