From 6ed1f3695acbd0e873b856d62551fa25677e7c34 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 28 Jan 2023 12:03:51 -0900 Subject: [PATCH] chore: upgrade deps + code-gen (#249) --- backend/go.mod | 6 +- backend/go.sum | 12 +- backend/internal/data/ent/attachment.go | 6 +- .../internal/data/ent/attachment_delete.go | 10 +- backend/internal/data/ent/attachment_query.go | 77 ++++++------ backend/internal/data/ent/authroles.go | 4 +- backend/internal/data/ent/authroles_delete.go | 10 +- backend/internal/data/ent/authroles_query.go | 74 ++++++----- backend/internal/data/ent/authtokens.go | 6 +- .../internal/data/ent/authtokens_delete.go | 10 +- backend/internal/data/ent/authtokens_query.go | 74 ++++++----- backend/internal/data/ent/client.go | 12 ++ backend/internal/data/ent/document.go | 6 +- backend/internal/data/ent/document_delete.go | 10 +- backend/internal/data/ent/document_query.go | 74 ++++++----- backend/internal/data/ent/ent.go | 8 +- backend/internal/data/ent/group.go | 14 +-- backend/internal/data/ent/group_delete.go | 10 +- backend/internal/data/ent/group_query.go | 71 +++++------ .../internal/data/ent/groupinvitationtoken.go | 4 +- .../data/ent/groupinvitationtoken_delete.go | 10 +- .../data/ent/groupinvitationtoken_query.go | 74 ++++++----- backend/internal/data/ent/item.go | 18 +-- backend/internal/data/ent/item_delete.go | 10 +- backend/internal/data/ent/item_query.go | 119 +++++++++--------- backend/internal/data/ent/itemfield.go | 4 +- backend/internal/data/ent/itemfield_delete.go | 10 +- backend/internal/data/ent/itemfield_query.go | 74 ++++++----- backend/internal/data/ent/label.go | 6 +- backend/internal/data/ent/label_delete.go | 10 +- backend/internal/data/ent/label_query.go | 113 ++++++++--------- backend/internal/data/ent/location.go | 10 +- backend/internal/data/ent/location_delete.go | 10 +- backend/internal/data/ent/location_query.go | 77 ++++++------ backend/internal/data/ent/maintenanceentry.go | 4 +- .../data/ent/maintenanceentry_delete.go | 10 +- .../data/ent/maintenanceentry_query.go | 74 ++++++----- backend/internal/data/ent/runtime/runtime.go | 4 +- backend/internal/data/ent/user.go | 6 +- backend/internal/data/ent/user_delete.go | 10 +- backend/internal/data/ent/user_query.go | 74 ++++++----- backend/internal/sys/config/conf.go | 2 +- 42 files changed, 664 insertions(+), 563 deletions(-) diff --git a/backend/go.mod b/backend/go.mod index ddbec9c..3262b17 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -3,9 +3,9 @@ module github.com/hay-kot/homebox/backend go 1.19 require ( - ariga.io/atlas v0.9.0 - entgo.io/ent v0.11.5 - github.com/ardanlabs/conf/v2 v2.2.0 + ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb + entgo.io/ent v0.11.7 + github.com/ardanlabs/conf/v3 v3.1.3 github.com/go-chi/chi/v5 v5.0.8 github.com/go-playground/validator/v10 v10.11.1 github.com/google/uuid v1.3.0 diff --git a/backend/go.sum b/backend/go.sum index 4a7f349..516065a 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,7 +1,11 @@ ariga.io/atlas v0.9.0 h1:q0JMtqyA3X1YWtPcn+E/kVPwLDslb+jAC8Ejl/vW6d0= ariga.io/atlas v0.9.0/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU= +ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb h1:mbsFtavDqGdYwdDpP50LGOOZ2hgyGoJcZeOpbgKMyu4= +ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU= entgo.io/ent v0.11.5 h1:V2qhG91C4PMQTa82Q4StoESMQ4dzkMNeStCzszxi0jQ= entgo.io/ent v0.11.5/go.mod h1:u7eKwNWAo/VlHIKxgwbmsFy3J7cKDxwi3jyF5TW/okY= +entgo.io/ent v0.11.7 h1:V+wKFh0jhAbY/FoU+PPbdMOf2Ma5vh07R/IdF+N/nFg= +entgo.io/ent v0.11.7/go.mod h1:ericBi6Q8l3wBH1wEIDfKxw7rcQEuRPyBfbIzjtxJ18= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= @@ -9,8 +13,8 @@ github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7l github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= -github.com/ardanlabs/conf/v2 v2.2.0 h1:ar1+TYIYAh2Tdeg2DQroh7ruR56/vJR8BDfzDIrXgtk= -github.com/ardanlabs/conf/v2 v2.2.0/go.mod h1:m37ZKdW9jwMUEhGX36jRNt8VzSQ/HVmSziLZH2p33nY= +github.com/ardanlabs/conf/v3 v3.1.3 h1:16+Nzfc4PBd/ERtYERUFL/75eVKNyW15Y+vn3W1XZzQ= +github.com/ardanlabs/conf/v3 v3.1.3/go.mod h1:bIacyuGeZjkTdtszdbvOcuq49VhHpV3+IPZ2ewOAK4I= github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -93,8 +97,6 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY= -github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w= github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= @@ -114,8 +116,6 @@ github.com/swaggo/files v1.0.0 h1:1gGXVIeUFCS/dta17rnP0iOpr6CXFwKD7EO5ID233e4= github.com/swaggo/files v1.0.0/go.mod h1:N59U6URJLyU1PQgFqPM7wXLMhJx7QAolnvfQkqO13kc= github.com/swaggo/http-swagger v1.3.3 h1:Hu5Z0L9ssyBLofaama21iYaF2VbWyA8jdohaaCGpHsc= github.com/swaggo/http-swagger v1.3.3/go.mod h1:sE+4PjD89IxMPm77FnkDz0sdO+p5lbXzrVWT6OTVVGo= -github.com/swaggo/swag v1.8.9 h1:kHtaBe/Ob9AZzAANfcn5c6RyCke9gG9QpH0jky0I/sA= -github.com/swaggo/swag v1.8.9/go.mod h1:ezQVUUhly8dludpVk+/PuwJWvLLanB13ygV5Pr9enSk= github.com/swaggo/swag v1.8.10 h1:eExW4bFa52WOjqRzRD58bgWsWfdFJso50lpbeTcmTfo= github.com/swaggo/swag v1.8.10/go.mod h1:ezQVUUhly8dludpVk+/PuwJWvLLanB13ygV5Pr9enSk= github.com/yeqown/go-qrcode/v2 v2.2.1 h1:Jc1Q916fwC05R8C7mpWDbrT9tyLPaLLKDABoC5XBCe8= diff --git a/backend/internal/data/ent/attachment.go b/backend/internal/data/ent/attachment.go index e5f738a..897a0a3 100644 --- a/backend/internal/data/ent/attachment.go +++ b/backend/internal/data/ent/attachment.go @@ -144,19 +144,19 @@ func (a *Attachment) assignValues(columns []string, values []any) error { // QueryItem queries the "item" edge of the Attachment entity. func (a *Attachment) QueryItem() *ItemQuery { - return (&AttachmentClient{config: a.config}).QueryItem(a) + return NewAttachmentClient(a.config).QueryItem(a) } // QueryDocument queries the "document" edge of the Attachment entity. func (a *Attachment) QueryDocument() *DocumentQuery { - return (&AttachmentClient{config: a.config}).QueryDocument(a) + return NewAttachmentClient(a.config).QueryDocument(a) } // Update returns a builder for updating this Attachment. // Note that you need to call Attachment.Unwrap() before calling this method if this Attachment // was returned from a transaction, and the transaction was committed or rolled back. func (a *Attachment) Update() *AttachmentUpdateOne { - return (&AttachmentClient{config: a.config}).UpdateOne(a) + return NewAttachmentClient(a.config).UpdateOne(a) } // Unwrap unwraps the Attachment entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/attachment_delete.go b/backend/internal/data/ent/attachment_delete.go index a018a8e..5b45801 100644 --- a/backend/internal/data/ent/attachment_delete.go +++ b/backend/internal/data/ent/attachment_delete.go @@ -69,6 +69,12 @@ type AttachmentDeleteOne struct { ad *AttachmentDelete } +// Where appends a list predicates to the AttachmentDelete builder. +func (ado *AttachmentDeleteOne) Where(ps ...predicate.Attachment) *AttachmentDeleteOne { + ado.ad.mutation.Where(ps...) + return ado +} + // Exec executes the deletion query. func (ado *AttachmentDeleteOne) Exec(ctx context.Context) error { n, err := ado.ad.Exec(ctx) @@ -84,5 +90,7 @@ func (ado *AttachmentDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (ado *AttachmentDeleteOne) ExecX(ctx context.Context) { - ado.ad.ExecX(ctx) + if err := ado.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/attachment_query.go b/backend/internal/data/ent/attachment_query.go index 2e250c2..d631f7e 100644 --- a/backend/internal/data/ent/attachment_query.go +++ b/backend/internal/data/ent/attachment_query.go @@ -20,11 +20,8 @@ import ( // AttachmentQuery is the builder for querying Attachment entities. type AttachmentQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.Attachment withItem *ItemQuery @@ -43,20 +40,20 @@ func (aq *AttachmentQuery) Where(ps ...predicate.Attachment) *AttachmentQuery { // Limit the number of records to be returned by this query. func (aq *AttachmentQuery) Limit(limit int) *AttachmentQuery { - aq.limit = &limit + aq.ctx.Limit = &limit return aq } // Offset to start from. func (aq *AttachmentQuery) Offset(offset int) *AttachmentQuery { - aq.offset = &offset + aq.ctx.Offset = &offset return aq } // 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 (aq *AttachmentQuery) Unique(unique bool) *AttachmentQuery { - aq.unique = &unique + aq.ctx.Unique = &unique return aq } @@ -113,7 +110,7 @@ func (aq *AttachmentQuery) QueryDocument() *DocumentQuery { // First returns the first Attachment entity from the query. // Returns a *NotFoundError when no Attachment was found. func (aq *AttachmentQuery) First(ctx context.Context) (*Attachment, error) { - nodes, err := aq.Limit(1).All(newQueryContext(ctx, TypeAttachment, "First")) + nodes, err := aq.Limit(1).All(setContextOp(ctx, aq.ctx, "First")) if err != nil { return nil, err } @@ -136,7 +133,7 @@ func (aq *AttachmentQuery) FirstX(ctx context.Context) *Attachment { // Returns a *NotFoundError when no Attachment ID was found. func (aq *AttachmentQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = aq.Limit(1).IDs(newQueryContext(ctx, TypeAttachment, "FirstID")); err != nil { + if ids, err = aq.Limit(1).IDs(setContextOp(ctx, aq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -159,7 +156,7 @@ func (aq *AttachmentQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Attachment entity is found. // Returns a *NotFoundError when no Attachment entities are found. func (aq *AttachmentQuery) Only(ctx context.Context) (*Attachment, error) { - nodes, err := aq.Limit(2).All(newQueryContext(ctx, TypeAttachment, "Only")) + nodes, err := aq.Limit(2).All(setContextOp(ctx, aq.ctx, "Only")) if err != nil { return nil, err } @@ -187,7 +184,7 @@ func (aq *AttachmentQuery) OnlyX(ctx context.Context) *Attachment { // Returns a *NotFoundError when no entities are found. func (aq *AttachmentQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = aq.Limit(2).IDs(newQueryContext(ctx, TypeAttachment, "OnlyID")); err != nil { + if ids, err = aq.Limit(2).IDs(setContextOp(ctx, aq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -212,7 +209,7 @@ func (aq *AttachmentQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Attachments. func (aq *AttachmentQuery) All(ctx context.Context) ([]*Attachment, error) { - ctx = newQueryContext(ctx, TypeAttachment, "All") + ctx = setContextOp(ctx, aq.ctx, "All") if err := aq.prepareQuery(ctx); err != nil { return nil, err } @@ -232,7 +229,7 @@ func (aq *AttachmentQuery) AllX(ctx context.Context) []*Attachment { // IDs executes the query and returns a list of Attachment IDs. func (aq *AttachmentQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { var ids []uuid.UUID - ctx = newQueryContext(ctx, TypeAttachment, "IDs") + ctx = setContextOp(ctx, aq.ctx, "IDs") if err := aq.Select(attachment.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -250,7 +247,7 @@ func (aq *AttachmentQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (aq *AttachmentQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeAttachment, "Count") + ctx = setContextOp(ctx, aq.ctx, "Count") if err := aq.prepareQuery(ctx); err != nil { return 0, err } @@ -268,7 +265,7 @@ func (aq *AttachmentQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (aq *AttachmentQuery) Exist(ctx context.Context) (bool, error) { - ctx = newQueryContext(ctx, TypeAttachment, "Exist") + ctx = setContextOp(ctx, aq.ctx, "Exist") switch _, err := aq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,17 +293,15 @@ func (aq *AttachmentQuery) Clone() *AttachmentQuery { } return &AttachmentQuery{ config: aq.config, - limit: aq.limit, - offset: aq.offset, + ctx: aq.ctx.Clone(), order: append([]OrderFunc{}, aq.order...), inters: append([]Interceptor{}, aq.inters...), predicates: append([]predicate.Attachment{}, aq.predicates...), withItem: aq.withItem.Clone(), withDocument: aq.withDocument.Clone(), // clone intermediate query. - sql: aq.sql.Clone(), - path: aq.path, - unique: aq.unique, + sql: aq.sql.Clone(), + path: aq.path, } } @@ -347,9 +342,9 @@ func (aq *AttachmentQuery) WithDocument(opts ...func(*DocumentQuery)) *Attachmen // Aggregate(ent.Count()). // Scan(ctx, &v) func (aq *AttachmentQuery) GroupBy(field string, fields ...string) *AttachmentGroupBy { - aq.fields = append([]string{field}, fields...) + aq.ctx.Fields = append([]string{field}, fields...) grbuild := &AttachmentGroupBy{build: aq} - grbuild.flds = &aq.fields + grbuild.flds = &aq.ctx.Fields grbuild.label = attachment.Label grbuild.scan = grbuild.Scan return grbuild @@ -368,10 +363,10 @@ func (aq *AttachmentQuery) GroupBy(field string, fields ...string) *AttachmentGr // Select(attachment.FieldCreatedAt). // Scan(ctx, &v) func (aq *AttachmentQuery) Select(fields ...string) *AttachmentSelect { - aq.fields = append(aq.fields, fields...) + aq.ctx.Fields = append(aq.ctx.Fields, fields...) sbuild := &AttachmentSelect{AttachmentQuery: aq} sbuild.label = attachment.Label - sbuild.flds, sbuild.scan = &aq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &aq.ctx.Fields, sbuild.Scan return sbuild } @@ -391,7 +386,7 @@ func (aq *AttachmentQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range aq.fields { + for _, f := range aq.ctx.Fields { if !attachment.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -468,6 +463,9 @@ func (aq *AttachmentQuery) loadItem(ctx context.Context, query *ItemQuery, nodes } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(item.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -497,6 +495,9 @@ func (aq *AttachmentQuery) loadDocument(ctx context.Context, query *DocumentQuer } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(document.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -516,9 +517,9 @@ func (aq *AttachmentQuery) loadDocument(ctx context.Context, query *DocumentQuer func (aq *AttachmentQuery) sqlCount(ctx context.Context) (int, error) { _spec := aq.querySpec() - _spec.Node.Columns = aq.fields - if len(aq.fields) > 0 { - _spec.Unique = aq.unique != nil && *aq.unique + _spec.Node.Columns = aq.ctx.Fields + if len(aq.ctx.Fields) > 0 { + _spec.Unique = aq.ctx.Unique != nil && *aq.ctx.Unique } return sqlgraph.CountNodes(ctx, aq.driver, _spec) } @@ -536,10 +537,10 @@ func (aq *AttachmentQuery) querySpec() *sqlgraph.QuerySpec { From: aq.sql, Unique: true, } - if unique := aq.unique; unique != nil { + if unique := aq.ctx.Unique; unique != nil { _spec.Unique = *unique } - if fields := aq.fields; len(fields) > 0 { + if fields := aq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, attachment.FieldID) for i := range fields { @@ -555,10 +556,10 @@ func (aq *AttachmentQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := aq.limit; limit != nil { + if limit := aq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := aq.offset; offset != nil { + if offset := aq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := aq.order; len(ps) > 0 { @@ -574,7 +575,7 @@ func (aq *AttachmentQuery) querySpec() *sqlgraph.QuerySpec { func (aq *AttachmentQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(aq.driver.Dialect()) t1 := builder.Table(attachment.Table) - columns := aq.fields + columns := aq.ctx.Fields if len(columns) == 0 { columns = attachment.Columns } @@ -583,7 +584,7 @@ func (aq *AttachmentQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = aq.sql selector.Select(selector.Columns(columns...)...) } - if aq.unique != nil && *aq.unique { + if aq.ctx.Unique != nil && *aq.ctx.Unique { selector.Distinct() } for _, p := range aq.predicates { @@ -592,12 +593,12 @@ func (aq *AttachmentQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range aq.order { p(selector) } - if offset := aq.offset; offset != nil { + if offset := aq.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 := aq.limit; limit != nil { + if limit := aq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -617,7 +618,7 @@ func (agb *AttachmentGroupBy) Aggregate(fns ...AggregateFunc) *AttachmentGroupBy // Scan applies the selector query and scans the result into the given value. func (agb *AttachmentGroupBy) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeAttachment, "GroupBy") + ctx = setContextOp(ctx, agb.build.ctx, "GroupBy") if err := agb.build.prepareQuery(ctx); err != nil { return err } @@ -665,7 +666,7 @@ func (as *AttachmentSelect) Aggregate(fns ...AggregateFunc) *AttachmentSelect { // Scan applies the selector query and scans the result into the given value. func (as *AttachmentSelect) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeAttachment, "Select") + ctx = setContextOp(ctx, as.ctx, "Select") if err := as.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/authroles.go b/backend/internal/data/ent/authroles.go index cfd2be4..5e8ed40 100644 --- a/backend/internal/data/ent/authroles.go +++ b/backend/internal/data/ent/authroles.go @@ -99,14 +99,14 @@ func (ar *AuthRoles) assignValues(columns []string, values []any) error { // QueryToken queries the "token" edge of the AuthRoles entity. func (ar *AuthRoles) QueryToken() *AuthTokensQuery { - return (&AuthRolesClient{config: ar.config}).QueryToken(ar) + return NewAuthRolesClient(ar.config).QueryToken(ar) } // Update returns a builder for updating this AuthRoles. // Note that you need to call AuthRoles.Unwrap() before calling this method if this AuthRoles // was returned from a transaction, and the transaction was committed or rolled back. func (ar *AuthRoles) Update() *AuthRolesUpdateOne { - return (&AuthRolesClient{config: ar.config}).UpdateOne(ar) + return NewAuthRolesClient(ar.config).UpdateOne(ar) } // Unwrap unwraps the AuthRoles entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/authroles_delete.go b/backend/internal/data/ent/authroles_delete.go index 4bafec2..3cc1faa 100644 --- a/backend/internal/data/ent/authroles_delete.go +++ b/backend/internal/data/ent/authroles_delete.go @@ -69,6 +69,12 @@ type AuthRolesDeleteOne struct { ard *AuthRolesDelete } +// Where appends a list predicates to the AuthRolesDelete builder. +func (ardo *AuthRolesDeleteOne) Where(ps ...predicate.AuthRoles) *AuthRolesDeleteOne { + ardo.ard.mutation.Where(ps...) + return ardo +} + // Exec executes the deletion query. func (ardo *AuthRolesDeleteOne) Exec(ctx context.Context) error { n, err := ardo.ard.Exec(ctx) @@ -84,5 +90,7 @@ func (ardo *AuthRolesDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (ardo *AuthRolesDeleteOne) ExecX(ctx context.Context) { - ardo.ard.ExecX(ctx) + if err := ardo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/authroles_query.go b/backend/internal/data/ent/authroles_query.go index fa3e290..ed44fa9 100644 --- a/backend/internal/data/ent/authroles_query.go +++ b/backend/internal/data/ent/authroles_query.go @@ -19,11 +19,8 @@ import ( // AuthRolesQuery is the builder for querying AuthRoles entities. type AuthRolesQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.AuthRoles withToken *AuthTokensQuery @@ -41,20 +38,20 @@ func (arq *AuthRolesQuery) Where(ps ...predicate.AuthRoles) *AuthRolesQuery { // Limit the number of records to be returned by this query. func (arq *AuthRolesQuery) Limit(limit int) *AuthRolesQuery { - arq.limit = &limit + arq.ctx.Limit = &limit return arq } // Offset to start from. func (arq *AuthRolesQuery) Offset(offset int) *AuthRolesQuery { - arq.offset = &offset + arq.ctx.Offset = &offset return arq } // 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 (arq *AuthRolesQuery) Unique(unique bool) *AuthRolesQuery { - arq.unique = &unique + arq.ctx.Unique = &unique return arq } @@ -89,7 +86,7 @@ func (arq *AuthRolesQuery) QueryToken() *AuthTokensQuery { // First returns the first AuthRoles entity from the query. // Returns a *NotFoundError when no AuthRoles was found. func (arq *AuthRolesQuery) First(ctx context.Context) (*AuthRoles, error) { - nodes, err := arq.Limit(1).All(newQueryContext(ctx, TypeAuthRoles, "First")) + nodes, err := arq.Limit(1).All(setContextOp(ctx, arq.ctx, "First")) if err != nil { return nil, err } @@ -112,7 +109,7 @@ func (arq *AuthRolesQuery) FirstX(ctx context.Context) *AuthRoles { // Returns a *NotFoundError when no AuthRoles ID was found. func (arq *AuthRolesQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = arq.Limit(1).IDs(newQueryContext(ctx, TypeAuthRoles, "FirstID")); err != nil { + if ids, err = arq.Limit(1).IDs(setContextOp(ctx, arq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -135,7 +132,7 @@ func (arq *AuthRolesQuery) FirstIDX(ctx context.Context) int { // Returns a *NotSingularError when more than one AuthRoles entity is found. // Returns a *NotFoundError when no AuthRoles entities are found. func (arq *AuthRolesQuery) Only(ctx context.Context) (*AuthRoles, error) { - nodes, err := arq.Limit(2).All(newQueryContext(ctx, TypeAuthRoles, "Only")) + nodes, err := arq.Limit(2).All(setContextOp(ctx, arq.ctx, "Only")) if err != nil { return nil, err } @@ -163,7 +160,7 @@ func (arq *AuthRolesQuery) OnlyX(ctx context.Context) *AuthRoles { // Returns a *NotFoundError when no entities are found. func (arq *AuthRolesQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = arq.Limit(2).IDs(newQueryContext(ctx, TypeAuthRoles, "OnlyID")); err != nil { + if ids, err = arq.Limit(2).IDs(setContextOp(ctx, arq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -188,7 +185,7 @@ func (arq *AuthRolesQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of AuthRolesSlice. func (arq *AuthRolesQuery) All(ctx context.Context) ([]*AuthRoles, error) { - ctx = newQueryContext(ctx, TypeAuthRoles, "All") + ctx = setContextOp(ctx, arq.ctx, "All") if err := arq.prepareQuery(ctx); err != nil { return nil, err } @@ -208,7 +205,7 @@ func (arq *AuthRolesQuery) AllX(ctx context.Context) []*AuthRoles { // IDs executes the query and returns a list of AuthRoles IDs. func (arq *AuthRolesQuery) IDs(ctx context.Context) ([]int, error) { var ids []int - ctx = newQueryContext(ctx, TypeAuthRoles, "IDs") + ctx = setContextOp(ctx, arq.ctx, "IDs") if err := arq.Select(authroles.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -226,7 +223,7 @@ func (arq *AuthRolesQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (arq *AuthRolesQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeAuthRoles, "Count") + ctx = setContextOp(ctx, arq.ctx, "Count") if err := arq.prepareQuery(ctx); err != nil { return 0, err } @@ -244,7 +241,7 @@ func (arq *AuthRolesQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (arq *AuthRolesQuery) Exist(ctx context.Context) (bool, error) { - ctx = newQueryContext(ctx, TypeAuthRoles, "Exist") + ctx = setContextOp(ctx, arq.ctx, "Exist") switch _, err := arq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -272,16 +269,14 @@ func (arq *AuthRolesQuery) Clone() *AuthRolesQuery { } return &AuthRolesQuery{ config: arq.config, - limit: arq.limit, - offset: arq.offset, + ctx: arq.ctx.Clone(), order: append([]OrderFunc{}, arq.order...), inters: append([]Interceptor{}, arq.inters...), predicates: append([]predicate.AuthRoles{}, arq.predicates...), withToken: arq.withToken.Clone(), // clone intermediate query. - sql: arq.sql.Clone(), - path: arq.path, - unique: arq.unique, + sql: arq.sql.Clone(), + path: arq.path, } } @@ -311,9 +306,9 @@ func (arq *AuthRolesQuery) WithToken(opts ...func(*AuthTokensQuery)) *AuthRolesQ // Aggregate(ent.Count()). // Scan(ctx, &v) func (arq *AuthRolesQuery) GroupBy(field string, fields ...string) *AuthRolesGroupBy { - arq.fields = append([]string{field}, fields...) + arq.ctx.Fields = append([]string{field}, fields...) grbuild := &AuthRolesGroupBy{build: arq} - grbuild.flds = &arq.fields + grbuild.flds = &arq.ctx.Fields grbuild.label = authroles.Label grbuild.scan = grbuild.Scan return grbuild @@ -332,10 +327,10 @@ func (arq *AuthRolesQuery) GroupBy(field string, fields ...string) *AuthRolesGro // Select(authroles.FieldRole). // Scan(ctx, &v) func (arq *AuthRolesQuery) Select(fields ...string) *AuthRolesSelect { - arq.fields = append(arq.fields, fields...) + arq.ctx.Fields = append(arq.ctx.Fields, fields...) sbuild := &AuthRolesSelect{AuthRolesQuery: arq} sbuild.label = authroles.Label - sbuild.flds, sbuild.scan = &arq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &arq.ctx.Fields, sbuild.Scan return sbuild } @@ -355,7 +350,7 @@ func (arq *AuthRolesQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range arq.fields { + for _, f := range arq.ctx.Fields { if !authroles.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -425,6 +420,9 @@ func (arq *AuthRolesQuery) loadToken(ctx context.Context, query *AuthTokensQuery } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(authtokens.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -444,9 +442,9 @@ func (arq *AuthRolesQuery) loadToken(ctx context.Context, query *AuthTokensQuery func (arq *AuthRolesQuery) sqlCount(ctx context.Context) (int, error) { _spec := arq.querySpec() - _spec.Node.Columns = arq.fields - if len(arq.fields) > 0 { - _spec.Unique = arq.unique != nil && *arq.unique + _spec.Node.Columns = arq.ctx.Fields + if len(arq.ctx.Fields) > 0 { + _spec.Unique = arq.ctx.Unique != nil && *arq.ctx.Unique } return sqlgraph.CountNodes(ctx, arq.driver, _spec) } @@ -464,10 +462,10 @@ func (arq *AuthRolesQuery) querySpec() *sqlgraph.QuerySpec { From: arq.sql, Unique: true, } - if unique := arq.unique; unique != nil { + if unique := arq.ctx.Unique; unique != nil { _spec.Unique = *unique } - if fields := arq.fields; len(fields) > 0 { + if fields := arq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, authroles.FieldID) for i := range fields { @@ -483,10 +481,10 @@ func (arq *AuthRolesQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := arq.limit; limit != nil { + if limit := arq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := arq.offset; offset != nil { + if offset := arq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := arq.order; len(ps) > 0 { @@ -502,7 +500,7 @@ func (arq *AuthRolesQuery) querySpec() *sqlgraph.QuerySpec { func (arq *AuthRolesQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(arq.driver.Dialect()) t1 := builder.Table(authroles.Table) - columns := arq.fields + columns := arq.ctx.Fields if len(columns) == 0 { columns = authroles.Columns } @@ -511,7 +509,7 @@ func (arq *AuthRolesQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = arq.sql selector.Select(selector.Columns(columns...)...) } - if arq.unique != nil && *arq.unique { + if arq.ctx.Unique != nil && *arq.ctx.Unique { selector.Distinct() } for _, p := range arq.predicates { @@ -520,12 +518,12 @@ func (arq *AuthRolesQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range arq.order { p(selector) } - if offset := arq.offset; offset != nil { + if offset := arq.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 := arq.limit; limit != nil { + if limit := arq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -545,7 +543,7 @@ func (argb *AuthRolesGroupBy) Aggregate(fns ...AggregateFunc) *AuthRolesGroupBy // Scan applies the selector query and scans the result into the given value. func (argb *AuthRolesGroupBy) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeAuthRoles, "GroupBy") + ctx = setContextOp(ctx, argb.build.ctx, "GroupBy") if err := argb.build.prepareQuery(ctx); err != nil { return err } @@ -593,7 +591,7 @@ func (ars *AuthRolesSelect) Aggregate(fns ...AggregateFunc) *AuthRolesSelect { // Scan applies the selector query and scans the result into the given value. func (ars *AuthRolesSelect) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeAuthRoles, "Select") + ctx = setContextOp(ctx, ars.ctx, "Select") if err := ars.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/authtokens.go b/backend/internal/data/ent/authtokens.go index 8945152..1418838 100644 --- a/backend/internal/data/ent/authtokens.go +++ b/backend/internal/data/ent/authtokens.go @@ -142,19 +142,19 @@ func (at *AuthTokens) assignValues(columns []string, values []any) error { // QueryUser queries the "user" edge of the AuthTokens entity. func (at *AuthTokens) QueryUser() *UserQuery { - return (&AuthTokensClient{config: at.config}).QueryUser(at) + return NewAuthTokensClient(at.config).QueryUser(at) } // QueryRoles queries the "roles" edge of the AuthTokens entity. func (at *AuthTokens) QueryRoles() *AuthRolesQuery { - return (&AuthTokensClient{config: at.config}).QueryRoles(at) + return NewAuthTokensClient(at.config).QueryRoles(at) } // Update returns a builder for updating this AuthTokens. // Note that you need to call AuthTokens.Unwrap() before calling this method if this AuthTokens // was returned from a transaction, and the transaction was committed or rolled back. func (at *AuthTokens) Update() *AuthTokensUpdateOne { - return (&AuthTokensClient{config: at.config}).UpdateOne(at) + return NewAuthTokensClient(at.config).UpdateOne(at) } // Unwrap unwraps the AuthTokens entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/authtokens_delete.go b/backend/internal/data/ent/authtokens_delete.go index 680d83c..79c1a0c 100644 --- a/backend/internal/data/ent/authtokens_delete.go +++ b/backend/internal/data/ent/authtokens_delete.go @@ -69,6 +69,12 @@ type AuthTokensDeleteOne struct { atd *AuthTokensDelete } +// Where appends a list predicates to the AuthTokensDelete builder. +func (atdo *AuthTokensDeleteOne) Where(ps ...predicate.AuthTokens) *AuthTokensDeleteOne { + atdo.atd.mutation.Where(ps...) + return atdo +} + // Exec executes the deletion query. func (atdo *AuthTokensDeleteOne) Exec(ctx context.Context) error { n, err := atdo.atd.Exec(ctx) @@ -84,5 +90,7 @@ func (atdo *AuthTokensDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (atdo *AuthTokensDeleteOne) ExecX(ctx context.Context) { - atdo.atd.ExecX(ctx) + if err := atdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/authtokens_query.go b/backend/internal/data/ent/authtokens_query.go index 6a62190..5695942 100644 --- a/backend/internal/data/ent/authtokens_query.go +++ b/backend/internal/data/ent/authtokens_query.go @@ -21,11 +21,8 @@ import ( // AuthTokensQuery is the builder for querying AuthTokens entities. type AuthTokensQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.AuthTokens withUser *UserQuery @@ -44,20 +41,20 @@ func (atq *AuthTokensQuery) Where(ps ...predicate.AuthTokens) *AuthTokensQuery { // Limit the number of records to be returned by this query. func (atq *AuthTokensQuery) Limit(limit int) *AuthTokensQuery { - atq.limit = &limit + atq.ctx.Limit = &limit return atq } // Offset to start from. func (atq *AuthTokensQuery) Offset(offset int) *AuthTokensQuery { - atq.offset = &offset + atq.ctx.Offset = &offset return atq } // 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 (atq *AuthTokensQuery) Unique(unique bool) *AuthTokensQuery { - atq.unique = &unique + atq.ctx.Unique = &unique return atq } @@ -114,7 +111,7 @@ func (atq *AuthTokensQuery) QueryRoles() *AuthRolesQuery { // First returns the first AuthTokens entity from the query. // Returns a *NotFoundError when no AuthTokens was found. func (atq *AuthTokensQuery) First(ctx context.Context) (*AuthTokens, error) { - nodes, err := atq.Limit(1).All(newQueryContext(ctx, TypeAuthTokens, "First")) + nodes, err := atq.Limit(1).All(setContextOp(ctx, atq.ctx, "First")) if err != nil { return nil, err } @@ -137,7 +134,7 @@ func (atq *AuthTokensQuery) FirstX(ctx context.Context) *AuthTokens { // Returns a *NotFoundError when no AuthTokens ID was found. func (atq *AuthTokensQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = atq.Limit(1).IDs(newQueryContext(ctx, TypeAuthTokens, "FirstID")); err != nil { + if ids, err = atq.Limit(1).IDs(setContextOp(ctx, atq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -160,7 +157,7 @@ func (atq *AuthTokensQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one AuthTokens entity is found. // Returns a *NotFoundError when no AuthTokens entities are found. func (atq *AuthTokensQuery) Only(ctx context.Context) (*AuthTokens, error) { - nodes, err := atq.Limit(2).All(newQueryContext(ctx, TypeAuthTokens, "Only")) + nodes, err := atq.Limit(2).All(setContextOp(ctx, atq.ctx, "Only")) if err != nil { return nil, err } @@ -188,7 +185,7 @@ func (atq *AuthTokensQuery) OnlyX(ctx context.Context) *AuthTokens { // Returns a *NotFoundError when no entities are found. func (atq *AuthTokensQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = atq.Limit(2).IDs(newQueryContext(ctx, TypeAuthTokens, "OnlyID")); err != nil { + if ids, err = atq.Limit(2).IDs(setContextOp(ctx, atq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -213,7 +210,7 @@ func (atq *AuthTokensQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of AuthTokensSlice. func (atq *AuthTokensQuery) All(ctx context.Context) ([]*AuthTokens, error) { - ctx = newQueryContext(ctx, TypeAuthTokens, "All") + ctx = setContextOp(ctx, atq.ctx, "All") if err := atq.prepareQuery(ctx); err != nil { return nil, err } @@ -233,7 +230,7 @@ func (atq *AuthTokensQuery) AllX(ctx context.Context) []*AuthTokens { // IDs executes the query and returns a list of AuthTokens IDs. func (atq *AuthTokensQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { var ids []uuid.UUID - ctx = newQueryContext(ctx, TypeAuthTokens, "IDs") + ctx = setContextOp(ctx, atq.ctx, "IDs") if err := atq.Select(authtokens.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -251,7 +248,7 @@ func (atq *AuthTokensQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (atq *AuthTokensQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeAuthTokens, "Count") + ctx = setContextOp(ctx, atq.ctx, "Count") if err := atq.prepareQuery(ctx); err != nil { return 0, err } @@ -269,7 +266,7 @@ func (atq *AuthTokensQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (atq *AuthTokensQuery) Exist(ctx context.Context) (bool, error) { - ctx = newQueryContext(ctx, TypeAuthTokens, "Exist") + ctx = setContextOp(ctx, atq.ctx, "Exist") switch _, err := atq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -297,17 +294,15 @@ func (atq *AuthTokensQuery) Clone() *AuthTokensQuery { } return &AuthTokensQuery{ config: atq.config, - limit: atq.limit, - offset: atq.offset, + ctx: atq.ctx.Clone(), order: append([]OrderFunc{}, atq.order...), inters: append([]Interceptor{}, atq.inters...), predicates: append([]predicate.AuthTokens{}, atq.predicates...), withUser: atq.withUser.Clone(), withRoles: atq.withRoles.Clone(), // clone intermediate query. - sql: atq.sql.Clone(), - path: atq.path, - unique: atq.unique, + sql: atq.sql.Clone(), + path: atq.path, } } @@ -348,9 +343,9 @@ func (atq *AuthTokensQuery) WithRoles(opts ...func(*AuthRolesQuery)) *AuthTokens // Aggregate(ent.Count()). // Scan(ctx, &v) func (atq *AuthTokensQuery) GroupBy(field string, fields ...string) *AuthTokensGroupBy { - atq.fields = append([]string{field}, fields...) + atq.ctx.Fields = append([]string{field}, fields...) grbuild := &AuthTokensGroupBy{build: atq} - grbuild.flds = &atq.fields + grbuild.flds = &atq.ctx.Fields grbuild.label = authtokens.Label grbuild.scan = grbuild.Scan return grbuild @@ -369,10 +364,10 @@ func (atq *AuthTokensQuery) GroupBy(field string, fields ...string) *AuthTokensG // Select(authtokens.FieldCreatedAt). // Scan(ctx, &v) func (atq *AuthTokensQuery) Select(fields ...string) *AuthTokensSelect { - atq.fields = append(atq.fields, fields...) + atq.ctx.Fields = append(atq.ctx.Fields, fields...) sbuild := &AuthTokensSelect{AuthTokensQuery: atq} sbuild.label = authtokens.Label - sbuild.flds, sbuild.scan = &atq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &atq.ctx.Fields, sbuild.Scan return sbuild } @@ -392,7 +387,7 @@ func (atq *AuthTokensQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range atq.fields { + for _, f := range atq.ctx.Fields { if !authtokens.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -469,6 +464,9 @@ func (atq *AuthTokensQuery) loadUser(ctx context.Context, query *UserQuery, node } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(user.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -516,9 +514,9 @@ func (atq *AuthTokensQuery) loadRoles(ctx context.Context, query *AuthRolesQuery func (atq *AuthTokensQuery) sqlCount(ctx context.Context) (int, error) { _spec := atq.querySpec() - _spec.Node.Columns = atq.fields - if len(atq.fields) > 0 { - _spec.Unique = atq.unique != nil && *atq.unique + _spec.Node.Columns = atq.ctx.Fields + if len(atq.ctx.Fields) > 0 { + _spec.Unique = atq.ctx.Unique != nil && *atq.ctx.Unique } return sqlgraph.CountNodes(ctx, atq.driver, _spec) } @@ -536,10 +534,10 @@ func (atq *AuthTokensQuery) querySpec() *sqlgraph.QuerySpec { From: atq.sql, Unique: true, } - if unique := atq.unique; unique != nil { + if unique := atq.ctx.Unique; unique != nil { _spec.Unique = *unique } - if fields := atq.fields; len(fields) > 0 { + if fields := atq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, authtokens.FieldID) for i := range fields { @@ -555,10 +553,10 @@ func (atq *AuthTokensQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := atq.limit; limit != nil { + if limit := atq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := atq.offset; offset != nil { + if offset := atq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := atq.order; len(ps) > 0 { @@ -574,7 +572,7 @@ func (atq *AuthTokensQuery) querySpec() *sqlgraph.QuerySpec { func (atq *AuthTokensQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(atq.driver.Dialect()) t1 := builder.Table(authtokens.Table) - columns := atq.fields + columns := atq.ctx.Fields if len(columns) == 0 { columns = authtokens.Columns } @@ -583,7 +581,7 @@ func (atq *AuthTokensQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = atq.sql selector.Select(selector.Columns(columns...)...) } - if atq.unique != nil && *atq.unique { + if atq.ctx.Unique != nil && *atq.ctx.Unique { selector.Distinct() } for _, p := range atq.predicates { @@ -592,12 +590,12 @@ func (atq *AuthTokensQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range atq.order { p(selector) } - if offset := atq.offset; offset != nil { + if offset := atq.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 := atq.limit; limit != nil { + if limit := atq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -617,7 +615,7 @@ func (atgb *AuthTokensGroupBy) Aggregate(fns ...AggregateFunc) *AuthTokensGroupB // Scan applies the selector query and scans the result into the given value. func (atgb *AuthTokensGroupBy) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeAuthTokens, "GroupBy") + ctx = setContextOp(ctx, atgb.build.ctx, "GroupBy") if err := atgb.build.prepareQuery(ctx); err != nil { return err } @@ -665,7 +663,7 @@ func (ats *AuthTokensSelect) Aggregate(fns ...AggregateFunc) *AuthTokensSelect { // Scan applies the selector query and scans the result into the given value. func (ats *AuthTokensSelect) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeAuthTokens, "Select") + ctx = setContextOp(ctx, ats.ctx, "Select") if err := ats.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/client.go b/backend/internal/data/ent/client.go index bcbd962..f021598 100644 --- a/backend/internal/data/ent/client.go +++ b/backend/internal/data/ent/client.go @@ -324,6 +324,7 @@ func (c *AttachmentClient) DeleteOneID(id uuid.UUID) *AttachmentDeleteOne { func (c *AttachmentClient) Query() *AttachmentQuery { return &AttachmentQuery{ config: c.config, + ctx: &QueryContext{Type: TypeAttachment}, inters: c.Interceptors(), } } @@ -473,6 +474,7 @@ func (c *AuthRolesClient) DeleteOneID(id int) *AuthRolesDeleteOne { func (c *AuthRolesClient) Query() *AuthRolesQuery { return &AuthRolesQuery{ config: c.config, + ctx: &QueryContext{Type: TypeAuthRoles}, inters: c.Interceptors(), } } @@ -606,6 +608,7 @@ func (c *AuthTokensClient) DeleteOneID(id uuid.UUID) *AuthTokensDeleteOne { func (c *AuthTokensClient) Query() *AuthTokensQuery { return &AuthTokensQuery{ config: c.config, + ctx: &QueryContext{Type: TypeAuthTokens}, inters: c.Interceptors(), } } @@ -755,6 +758,7 @@ func (c *DocumentClient) DeleteOneID(id uuid.UUID) *DocumentDeleteOne { func (c *DocumentClient) Query() *DocumentQuery { return &DocumentQuery{ config: c.config, + ctx: &QueryContext{Type: TypeDocument}, inters: c.Interceptors(), } } @@ -904,6 +908,7 @@ func (c *GroupClient) DeleteOneID(id uuid.UUID) *GroupDeleteOne { func (c *GroupClient) Query() *GroupQuery { return &GroupQuery{ config: c.config, + ctx: &QueryContext{Type: TypeGroup}, inters: c.Interceptors(), } } @@ -1117,6 +1122,7 @@ func (c *GroupInvitationTokenClient) DeleteOneID(id uuid.UUID) *GroupInvitationT func (c *GroupInvitationTokenClient) Query() *GroupInvitationTokenQuery { return &GroupInvitationTokenQuery{ config: c.config, + ctx: &QueryContext{Type: TypeGroupInvitationToken}, inters: c.Interceptors(), } } @@ -1250,6 +1256,7 @@ func (c *ItemClient) DeleteOneID(id uuid.UUID) *ItemDeleteOne { func (c *ItemClient) Query() *ItemQuery { return &ItemQuery{ config: c.config, + ctx: &QueryContext{Type: TypeItem}, inters: c.Interceptors(), } } @@ -1495,6 +1502,7 @@ func (c *ItemFieldClient) DeleteOneID(id uuid.UUID) *ItemFieldDeleteOne { func (c *ItemFieldClient) Query() *ItemFieldQuery { return &ItemFieldQuery{ config: c.config, + ctx: &QueryContext{Type: TypeItemField}, inters: c.Interceptors(), } } @@ -1628,6 +1636,7 @@ func (c *LabelClient) DeleteOneID(id uuid.UUID) *LabelDeleteOne { func (c *LabelClient) Query() *LabelQuery { return &LabelQuery{ config: c.config, + ctx: &QueryContext{Type: TypeLabel}, inters: c.Interceptors(), } } @@ -1777,6 +1786,7 @@ func (c *LocationClient) DeleteOneID(id uuid.UUID) *LocationDeleteOne { func (c *LocationClient) Query() *LocationQuery { return &LocationQuery{ config: c.config, + ctx: &QueryContext{Type: TypeLocation}, inters: c.Interceptors(), } } @@ -1958,6 +1968,7 @@ func (c *MaintenanceEntryClient) DeleteOneID(id uuid.UUID) *MaintenanceEntryDele func (c *MaintenanceEntryClient) Query() *MaintenanceEntryQuery { return &MaintenanceEntryQuery{ config: c.config, + ctx: &QueryContext{Type: TypeMaintenanceEntry}, inters: c.Interceptors(), } } @@ -2091,6 +2102,7 @@ func (c *UserClient) DeleteOneID(id uuid.UUID) *UserDeleteOne { func (c *UserClient) Query() *UserQuery { return &UserQuery{ config: c.config, + ctx: &QueryContext{Type: TypeUser}, inters: c.Interceptors(), } } diff --git a/backend/internal/data/ent/document.go b/backend/internal/data/ent/document.go index 50c1612..661a37e 100644 --- a/backend/internal/data/ent/document.go +++ b/backend/internal/data/ent/document.go @@ -137,19 +137,19 @@ func (d *Document) assignValues(columns []string, values []any) error { // QueryGroup queries the "group" edge of the Document entity. func (d *Document) QueryGroup() *GroupQuery { - return (&DocumentClient{config: d.config}).QueryGroup(d) + return NewDocumentClient(d.config).QueryGroup(d) } // QueryAttachments queries the "attachments" edge of the Document entity. func (d *Document) QueryAttachments() *AttachmentQuery { - return (&DocumentClient{config: d.config}).QueryAttachments(d) + return NewDocumentClient(d.config).QueryAttachments(d) } // Update returns a builder for updating this Document. // Note that you need to call Document.Unwrap() before calling this method if this Document // was returned from a transaction, and the transaction was committed or rolled back. func (d *Document) Update() *DocumentUpdateOne { - return (&DocumentClient{config: d.config}).UpdateOne(d) + return NewDocumentClient(d.config).UpdateOne(d) } // Unwrap unwraps the Document entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/document_delete.go b/backend/internal/data/ent/document_delete.go index 000ab1c..0096d8e 100644 --- a/backend/internal/data/ent/document_delete.go +++ b/backend/internal/data/ent/document_delete.go @@ -69,6 +69,12 @@ type DocumentDeleteOne struct { dd *DocumentDelete } +// Where appends a list predicates to the DocumentDelete builder. +func (ddo *DocumentDeleteOne) Where(ps ...predicate.Document) *DocumentDeleteOne { + ddo.dd.mutation.Where(ps...) + return ddo +} + // Exec executes the deletion query. func (ddo *DocumentDeleteOne) Exec(ctx context.Context) error { n, err := ddo.dd.Exec(ctx) @@ -84,5 +90,7 @@ func (ddo *DocumentDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (ddo *DocumentDeleteOne) ExecX(ctx context.Context) { - ddo.dd.ExecX(ctx) + if err := ddo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/document_query.go b/backend/internal/data/ent/document_query.go index 51b407c..d2bde65 100644 --- a/backend/internal/data/ent/document_query.go +++ b/backend/internal/data/ent/document_query.go @@ -21,11 +21,8 @@ import ( // DocumentQuery is the builder for querying Document entities. type DocumentQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.Document withGroup *GroupQuery @@ -44,20 +41,20 @@ func (dq *DocumentQuery) Where(ps ...predicate.Document) *DocumentQuery { // Limit the number of records to be returned by this query. func (dq *DocumentQuery) Limit(limit int) *DocumentQuery { - dq.limit = &limit + dq.ctx.Limit = &limit return dq } // Offset to start from. func (dq *DocumentQuery) Offset(offset int) *DocumentQuery { - dq.offset = &offset + dq.ctx.Offset = &offset return dq } // 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 (dq *DocumentQuery) Unique(unique bool) *DocumentQuery { - dq.unique = &unique + dq.ctx.Unique = &unique return dq } @@ -114,7 +111,7 @@ func (dq *DocumentQuery) QueryAttachments() *AttachmentQuery { // First returns the first Document entity from the query. // Returns a *NotFoundError when no Document was found. func (dq *DocumentQuery) First(ctx context.Context) (*Document, error) { - nodes, err := dq.Limit(1).All(newQueryContext(ctx, TypeDocument, "First")) + nodes, err := dq.Limit(1).All(setContextOp(ctx, dq.ctx, "First")) if err != nil { return nil, err } @@ -137,7 +134,7 @@ func (dq *DocumentQuery) FirstX(ctx context.Context) *Document { // Returns a *NotFoundError when no Document ID was found. func (dq *DocumentQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = dq.Limit(1).IDs(newQueryContext(ctx, TypeDocument, "FirstID")); err != nil { + if ids, err = dq.Limit(1).IDs(setContextOp(ctx, dq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -160,7 +157,7 @@ func (dq *DocumentQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Document entity is found. // Returns a *NotFoundError when no Document entities are found. func (dq *DocumentQuery) Only(ctx context.Context) (*Document, error) { - nodes, err := dq.Limit(2).All(newQueryContext(ctx, TypeDocument, "Only")) + nodes, err := dq.Limit(2).All(setContextOp(ctx, dq.ctx, "Only")) if err != nil { return nil, err } @@ -188,7 +185,7 @@ func (dq *DocumentQuery) OnlyX(ctx context.Context) *Document { // Returns a *NotFoundError when no entities are found. func (dq *DocumentQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = dq.Limit(2).IDs(newQueryContext(ctx, TypeDocument, "OnlyID")); err != nil { + if ids, err = dq.Limit(2).IDs(setContextOp(ctx, dq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -213,7 +210,7 @@ func (dq *DocumentQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Documents. func (dq *DocumentQuery) All(ctx context.Context) ([]*Document, error) { - ctx = newQueryContext(ctx, TypeDocument, "All") + ctx = setContextOp(ctx, dq.ctx, "All") if err := dq.prepareQuery(ctx); err != nil { return nil, err } @@ -233,7 +230,7 @@ func (dq *DocumentQuery) AllX(ctx context.Context) []*Document { // IDs executes the query and returns a list of Document IDs. func (dq *DocumentQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { var ids []uuid.UUID - ctx = newQueryContext(ctx, TypeDocument, "IDs") + ctx = setContextOp(ctx, dq.ctx, "IDs") if err := dq.Select(document.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -251,7 +248,7 @@ func (dq *DocumentQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (dq *DocumentQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeDocument, "Count") + ctx = setContextOp(ctx, dq.ctx, "Count") if err := dq.prepareQuery(ctx); err != nil { return 0, err } @@ -269,7 +266,7 @@ func (dq *DocumentQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (dq *DocumentQuery) Exist(ctx context.Context) (bool, error) { - ctx = newQueryContext(ctx, TypeDocument, "Exist") + ctx = setContextOp(ctx, dq.ctx, "Exist") switch _, err := dq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -297,17 +294,15 @@ func (dq *DocumentQuery) Clone() *DocumentQuery { } return &DocumentQuery{ config: dq.config, - limit: dq.limit, - offset: dq.offset, + ctx: dq.ctx.Clone(), order: append([]OrderFunc{}, dq.order...), inters: append([]Interceptor{}, dq.inters...), predicates: append([]predicate.Document{}, dq.predicates...), withGroup: dq.withGroup.Clone(), withAttachments: dq.withAttachments.Clone(), // clone intermediate query. - sql: dq.sql.Clone(), - path: dq.path, - unique: dq.unique, + sql: dq.sql.Clone(), + path: dq.path, } } @@ -348,9 +343,9 @@ func (dq *DocumentQuery) WithAttachments(opts ...func(*AttachmentQuery)) *Docume // Aggregate(ent.Count()). // Scan(ctx, &v) func (dq *DocumentQuery) GroupBy(field string, fields ...string) *DocumentGroupBy { - dq.fields = append([]string{field}, fields...) + dq.ctx.Fields = append([]string{field}, fields...) grbuild := &DocumentGroupBy{build: dq} - grbuild.flds = &dq.fields + grbuild.flds = &dq.ctx.Fields grbuild.label = document.Label grbuild.scan = grbuild.Scan return grbuild @@ -369,10 +364,10 @@ func (dq *DocumentQuery) GroupBy(field string, fields ...string) *DocumentGroupB // Select(document.FieldCreatedAt). // Scan(ctx, &v) func (dq *DocumentQuery) Select(fields ...string) *DocumentSelect { - dq.fields = append(dq.fields, fields...) + dq.ctx.Fields = append(dq.ctx.Fields, fields...) sbuild := &DocumentSelect{DocumentQuery: dq} sbuild.label = document.Label - sbuild.flds, sbuild.scan = &dq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &dq.ctx.Fields, sbuild.Scan return sbuild } @@ -392,7 +387,7 @@ func (dq *DocumentQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range dq.fields { + for _, f := range dq.ctx.Fields { if !document.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -470,6 +465,9 @@ func (dq *DocumentQuery) 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 { @@ -520,9 +518,9 @@ func (dq *DocumentQuery) loadAttachments(ctx context.Context, query *AttachmentQ func (dq *DocumentQuery) sqlCount(ctx context.Context) (int, error) { _spec := dq.querySpec() - _spec.Node.Columns = dq.fields - if len(dq.fields) > 0 { - _spec.Unique = dq.unique != nil && *dq.unique + _spec.Node.Columns = dq.ctx.Fields + if len(dq.ctx.Fields) > 0 { + _spec.Unique = dq.ctx.Unique != nil && *dq.ctx.Unique } return sqlgraph.CountNodes(ctx, dq.driver, _spec) } @@ -540,10 +538,10 @@ func (dq *DocumentQuery) querySpec() *sqlgraph.QuerySpec { From: dq.sql, Unique: true, } - if unique := dq.unique; unique != nil { + if unique := dq.ctx.Unique; unique != nil { _spec.Unique = *unique } - if fields := dq.fields; len(fields) > 0 { + if fields := dq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, document.FieldID) for i := range fields { @@ -559,10 +557,10 @@ func (dq *DocumentQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := dq.limit; limit != nil { + if limit := dq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := dq.offset; offset != nil { + if offset := dq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := dq.order; len(ps) > 0 { @@ -578,7 +576,7 @@ func (dq *DocumentQuery) querySpec() *sqlgraph.QuerySpec { func (dq *DocumentQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(dq.driver.Dialect()) t1 := builder.Table(document.Table) - columns := dq.fields + columns := dq.ctx.Fields if len(columns) == 0 { columns = document.Columns } @@ -587,7 +585,7 @@ func (dq *DocumentQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = dq.sql selector.Select(selector.Columns(columns...)...) } - if dq.unique != nil && *dq.unique { + if dq.ctx.Unique != nil && *dq.ctx.Unique { selector.Distinct() } for _, p := range dq.predicates { @@ -596,12 +594,12 @@ func (dq *DocumentQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range dq.order { p(selector) } - if offset := dq.offset; offset != nil { + if offset := dq.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 := dq.limit; limit != nil { + if limit := dq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -621,7 +619,7 @@ func (dgb *DocumentGroupBy) Aggregate(fns ...AggregateFunc) *DocumentGroupBy { // Scan applies the selector query and scans the result into the given value. func (dgb *DocumentGroupBy) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeDocument, "GroupBy") + ctx = setContextOp(ctx, dgb.build.ctx, "GroupBy") if err := dgb.build.prepareQuery(ctx); err != nil { return err } @@ -669,7 +667,7 @@ func (ds *DocumentSelect) Aggregate(fns ...AggregateFunc) *DocumentSelect { // Scan applies the selector query and scans the result into the given value. func (ds *DocumentSelect) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeDocument, "Select") + ctx = setContextOp(ctx, ds.ctx, "Select") if err := ds.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/ent.go b/backend/internal/data/ent/ent.go index d9a0cae..27d53ca 100644 --- a/backend/internal/data/ent/ent.go +++ b/backend/internal/data/ent/ent.go @@ -31,6 +31,7 @@ type ( Hook = ent.Hook Value = ent.Value Query = ent.Query + QueryContext = ent.QueryContext Querier = ent.Querier QuerierFunc = ent.QuerierFunc Interceptor = ent.Interceptor @@ -525,10 +526,11 @@ func withHooks[V Value, M any, PM interface { return nv, nil } -// newQueryContext returns a new context with the given QueryContext attached in case it does not exist. -func newQueryContext(ctx context.Context, typ, op string) context.Context { +// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist. +func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context { if ent.QueryFromContext(ctx) == nil { - ctx = ent.NewQueryContext(ctx, &ent.QueryContext{Type: typ, Op: op}) + qc.Op = op + ctx = ent.NewQueryContext(ctx, qc) } return ctx } diff --git a/backend/internal/data/ent/group.go b/backend/internal/data/ent/group.go index 8140104..16dc988 100644 --- a/backend/internal/data/ent/group.go +++ b/backend/internal/data/ent/group.go @@ -166,39 +166,39 @@ func (gr *Group) assignValues(columns []string, values []any) error { // QueryUsers queries the "users" edge of the Group entity. func (gr *Group) QueryUsers() *UserQuery { - return (&GroupClient{config: gr.config}).QueryUsers(gr) + return NewGroupClient(gr.config).QueryUsers(gr) } // QueryLocations queries the "locations" edge of the Group entity. func (gr *Group) QueryLocations() *LocationQuery { - return (&GroupClient{config: gr.config}).QueryLocations(gr) + return NewGroupClient(gr.config).QueryLocations(gr) } // QueryItems queries the "items" edge of the Group entity. func (gr *Group) QueryItems() *ItemQuery { - return (&GroupClient{config: gr.config}).QueryItems(gr) + return NewGroupClient(gr.config).QueryItems(gr) } // QueryLabels queries the "labels" edge of the Group entity. func (gr *Group) QueryLabels() *LabelQuery { - return (&GroupClient{config: gr.config}).QueryLabels(gr) + return NewGroupClient(gr.config).QueryLabels(gr) } // QueryDocuments queries the "documents" edge of the Group entity. func (gr *Group) QueryDocuments() *DocumentQuery { - return (&GroupClient{config: gr.config}).QueryDocuments(gr) + return NewGroupClient(gr.config).QueryDocuments(gr) } // QueryInvitationTokens queries the "invitation_tokens" edge of the Group entity. func (gr *Group) QueryInvitationTokens() *GroupInvitationTokenQuery { - return (&GroupClient{config: gr.config}).QueryInvitationTokens(gr) + return NewGroupClient(gr.config).QueryInvitationTokens(gr) } // Update returns a builder for updating this Group. // Note that you need to call Group.Unwrap() before calling this method if this Group // was returned from a transaction, and the transaction was committed or rolled back. func (gr *Group) Update() *GroupUpdateOne { - return (&GroupClient{config: gr.config}).UpdateOne(gr) + return NewGroupClient(gr.config).UpdateOne(gr) } // Unwrap unwraps the Group entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/group_delete.go b/backend/internal/data/ent/group_delete.go index 5ecc7d1..eae02e2 100644 --- a/backend/internal/data/ent/group_delete.go +++ b/backend/internal/data/ent/group_delete.go @@ -69,6 +69,12 @@ type GroupDeleteOne struct { gd *GroupDelete } +// Where appends a list predicates to the GroupDelete builder. +func (gdo *GroupDeleteOne) Where(ps ...predicate.Group) *GroupDeleteOne { + gdo.gd.mutation.Where(ps...) + return gdo +} + // Exec executes the deletion query. func (gdo *GroupDeleteOne) Exec(ctx context.Context) error { n, err := gdo.gd.Exec(ctx) @@ -84,5 +90,7 @@ func (gdo *GroupDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (gdo *GroupDeleteOne) ExecX(ctx context.Context) { - gdo.gd.ExecX(ctx) + if err := gdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/group_query.go b/backend/internal/data/ent/group_query.go index 701ee01..a0f6d61 100644 --- a/backend/internal/data/ent/group_query.go +++ b/backend/internal/data/ent/group_query.go @@ -25,11 +25,8 @@ import ( // GroupQuery is the builder for querying Group entities. type GroupQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.Group withUsers *UserQuery @@ -51,20 +48,20 @@ func (gq *GroupQuery) Where(ps ...predicate.Group) *GroupQuery { // Limit the number of records to be returned by this query. func (gq *GroupQuery) Limit(limit int) *GroupQuery { - gq.limit = &limit + gq.ctx.Limit = &limit return gq } // Offset to start from. func (gq *GroupQuery) Offset(offset int) *GroupQuery { - gq.offset = &offset + gq.ctx.Offset = &offset return gq } // 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 (gq *GroupQuery) Unique(unique bool) *GroupQuery { - gq.unique = &unique + gq.ctx.Unique = &unique return gq } @@ -209,7 +206,7 @@ func (gq *GroupQuery) QueryInvitationTokens() *GroupInvitationTokenQuery { // First returns the first Group entity from the query. // Returns a *NotFoundError when no Group was found. func (gq *GroupQuery) First(ctx context.Context) (*Group, error) { - nodes, err := gq.Limit(1).All(newQueryContext(ctx, TypeGroup, "First")) + nodes, err := gq.Limit(1).All(setContextOp(ctx, gq.ctx, "First")) if err != nil { return nil, err } @@ -232,7 +229,7 @@ func (gq *GroupQuery) FirstX(ctx context.Context) *Group { // Returns a *NotFoundError when no Group ID was found. func (gq *GroupQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gq.Limit(1).IDs(newQueryContext(ctx, TypeGroup, "FirstID")); err != nil { + if ids, err = gq.Limit(1).IDs(setContextOp(ctx, gq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -255,7 +252,7 @@ func (gq *GroupQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Group entity is found. // Returns a *NotFoundError when no Group entities are found. func (gq *GroupQuery) Only(ctx context.Context) (*Group, error) { - nodes, err := gq.Limit(2).All(newQueryContext(ctx, TypeGroup, "Only")) + nodes, err := gq.Limit(2).All(setContextOp(ctx, gq.ctx, "Only")) if err != nil { return nil, err } @@ -283,7 +280,7 @@ func (gq *GroupQuery) OnlyX(ctx context.Context) *Group { // Returns a *NotFoundError when no entities are found. func (gq *GroupQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gq.Limit(2).IDs(newQueryContext(ctx, TypeGroup, "OnlyID")); err != nil { + if ids, err = gq.Limit(2).IDs(setContextOp(ctx, gq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -308,7 +305,7 @@ func (gq *GroupQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Groups. func (gq *GroupQuery) All(ctx context.Context) ([]*Group, error) { - ctx = newQueryContext(ctx, TypeGroup, "All") + ctx = setContextOp(ctx, gq.ctx, "All") if err := gq.prepareQuery(ctx); err != nil { return nil, err } @@ -328,7 +325,7 @@ func (gq *GroupQuery) AllX(ctx context.Context) []*Group { // IDs executes the query and returns a list of Group IDs. func (gq *GroupQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { var ids []uuid.UUID - ctx = newQueryContext(ctx, TypeGroup, "IDs") + ctx = setContextOp(ctx, gq.ctx, "IDs") if err := gq.Select(group.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -346,7 +343,7 @@ func (gq *GroupQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (gq *GroupQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeGroup, "Count") + ctx = setContextOp(ctx, gq.ctx, "Count") if err := gq.prepareQuery(ctx); err != nil { return 0, err } @@ -364,7 +361,7 @@ func (gq *GroupQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (gq *GroupQuery) Exist(ctx context.Context) (bool, error) { - ctx = newQueryContext(ctx, TypeGroup, "Exist") + ctx = setContextOp(ctx, gq.ctx, "Exist") switch _, err := gq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -392,8 +389,7 @@ func (gq *GroupQuery) Clone() *GroupQuery { } return &GroupQuery{ config: gq.config, - limit: gq.limit, - offset: gq.offset, + ctx: gq.ctx.Clone(), order: append([]OrderFunc{}, gq.order...), inters: append([]Interceptor{}, gq.inters...), predicates: append([]predicate.Group{}, gq.predicates...), @@ -404,9 +400,8 @@ func (gq *GroupQuery) Clone() *GroupQuery { withDocuments: gq.withDocuments.Clone(), withInvitationTokens: gq.withInvitationTokens.Clone(), // clone intermediate query. - sql: gq.sql.Clone(), - path: gq.path, - unique: gq.unique, + sql: gq.sql.Clone(), + path: gq.path, } } @@ -491,9 +486,9 @@ func (gq *GroupQuery) WithInvitationTokens(opts ...func(*GroupInvitationTokenQue // Aggregate(ent.Count()). // Scan(ctx, &v) func (gq *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy { - gq.fields = append([]string{field}, fields...) + gq.ctx.Fields = append([]string{field}, fields...) grbuild := &GroupGroupBy{build: gq} - grbuild.flds = &gq.fields + grbuild.flds = &gq.ctx.Fields grbuild.label = group.Label grbuild.scan = grbuild.Scan return grbuild @@ -512,10 +507,10 @@ func (gq *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy { // Select(group.FieldCreatedAt). // Scan(ctx, &v) func (gq *GroupQuery) Select(fields ...string) *GroupSelect { - gq.fields = append(gq.fields, fields...) + gq.ctx.Fields = append(gq.ctx.Fields, fields...) sbuild := &GroupSelect{GroupQuery: gq} sbuild.label = group.Label - sbuild.flds, sbuild.scan = &gq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &gq.ctx.Fields, sbuild.Scan return sbuild } @@ -535,7 +530,7 @@ func (gq *GroupQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range gq.fields { + for _, f := range gq.ctx.Fields { if !group.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -817,9 +812,9 @@ func (gq *GroupQuery) loadInvitationTokens(ctx context.Context, query *GroupInvi func (gq *GroupQuery) sqlCount(ctx context.Context) (int, error) { _spec := gq.querySpec() - _spec.Node.Columns = gq.fields - if len(gq.fields) > 0 { - _spec.Unique = gq.unique != nil && *gq.unique + _spec.Node.Columns = gq.ctx.Fields + if len(gq.ctx.Fields) > 0 { + _spec.Unique = gq.ctx.Unique != nil && *gq.ctx.Unique } return sqlgraph.CountNodes(ctx, gq.driver, _spec) } @@ -837,10 +832,10 @@ func (gq *GroupQuery) querySpec() *sqlgraph.QuerySpec { From: gq.sql, Unique: true, } - if unique := gq.unique; unique != nil { + if unique := gq.ctx.Unique; unique != nil { _spec.Unique = *unique } - if fields := gq.fields; len(fields) > 0 { + if fields := gq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, group.FieldID) for i := range fields { @@ -856,10 +851,10 @@ func (gq *GroupQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := gq.limit; limit != nil { + if limit := gq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := gq.offset; offset != nil { + if offset := gq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := gq.order; len(ps) > 0 { @@ -875,7 +870,7 @@ func (gq *GroupQuery) querySpec() *sqlgraph.QuerySpec { func (gq *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(gq.driver.Dialect()) t1 := builder.Table(group.Table) - columns := gq.fields + columns := gq.ctx.Fields if len(columns) == 0 { columns = group.Columns } @@ -884,7 +879,7 @@ func (gq *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = gq.sql selector.Select(selector.Columns(columns...)...) } - if gq.unique != nil && *gq.unique { + if gq.ctx.Unique != nil && *gq.ctx.Unique { selector.Distinct() } for _, p := range gq.predicates { @@ -893,12 +888,12 @@ func (gq *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range gq.order { p(selector) } - if offset := gq.offset; offset != nil { + if offset := gq.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 := gq.limit; limit != nil { + if limit := gq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -918,7 +913,7 @@ func (ggb *GroupGroupBy) Aggregate(fns ...AggregateFunc) *GroupGroupBy { // Scan applies the selector query and scans the result into the given value. func (ggb *GroupGroupBy) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeGroup, "GroupBy") + ctx = setContextOp(ctx, ggb.build.ctx, "GroupBy") if err := ggb.build.prepareQuery(ctx); err != nil { return err } @@ -966,7 +961,7 @@ func (gs *GroupSelect) Aggregate(fns ...AggregateFunc) *GroupSelect { // Scan applies the selector query and scans the result into the given value. func (gs *GroupSelect) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeGroup, "Select") + ctx = setContextOp(ctx, gs.ctx, "Select") if err := gs.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/groupinvitationtoken.go b/backend/internal/data/ent/groupinvitationtoken.go index 248e40f..8f145d4 100644 --- a/backend/internal/data/ent/groupinvitationtoken.go +++ b/backend/internal/data/ent/groupinvitationtoken.go @@ -136,14 +136,14 @@ func (git *GroupInvitationToken) assignValues(columns []string, values []any) er // QueryGroup queries the "group" edge of the GroupInvitationToken entity. func (git *GroupInvitationToken) QueryGroup() *GroupQuery { - return (&GroupInvitationTokenClient{config: git.config}).QueryGroup(git) + return NewGroupInvitationTokenClient(git.config).QueryGroup(git) } // Update returns a builder for updating this GroupInvitationToken. // Note that you need to call GroupInvitationToken.Unwrap() before calling this method if this GroupInvitationToken // was returned from a transaction, and the transaction was committed or rolled back. func (git *GroupInvitationToken) Update() *GroupInvitationTokenUpdateOne { - return (&GroupInvitationTokenClient{config: git.config}).UpdateOne(git) + return NewGroupInvitationTokenClient(git.config).UpdateOne(git) } // Unwrap unwraps the GroupInvitationToken entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/groupinvitationtoken_delete.go b/backend/internal/data/ent/groupinvitationtoken_delete.go index 1da616e..1896841 100644 --- a/backend/internal/data/ent/groupinvitationtoken_delete.go +++ b/backend/internal/data/ent/groupinvitationtoken_delete.go @@ -69,6 +69,12 @@ type GroupInvitationTokenDeleteOne struct { gitd *GroupInvitationTokenDelete } +// Where appends a list predicates to the GroupInvitationTokenDelete builder. +func (gitdo *GroupInvitationTokenDeleteOne) Where(ps ...predicate.GroupInvitationToken) *GroupInvitationTokenDeleteOne { + gitdo.gitd.mutation.Where(ps...) + return gitdo +} + // Exec executes the deletion query. func (gitdo *GroupInvitationTokenDeleteOne) Exec(ctx context.Context) error { n, err := gitdo.gitd.Exec(ctx) @@ -84,5 +90,7 @@ func (gitdo *GroupInvitationTokenDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (gitdo *GroupInvitationTokenDeleteOne) ExecX(ctx context.Context) { - gitdo.gitd.ExecX(ctx) + if err := gitdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/groupinvitationtoken_query.go b/backend/internal/data/ent/groupinvitationtoken_query.go index 8c84dca..ac1fc92 100644 --- a/backend/internal/data/ent/groupinvitationtoken_query.go +++ b/backend/internal/data/ent/groupinvitationtoken_query.go @@ -19,11 +19,8 @@ import ( // GroupInvitationTokenQuery is the builder for querying GroupInvitationToken entities. type GroupInvitationTokenQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.GroupInvitationToken withGroup *GroupQuery @@ -41,20 +38,20 @@ func (gitq *GroupInvitationTokenQuery) Where(ps ...predicate.GroupInvitationToke // Limit the number of records to be returned by this query. func (gitq *GroupInvitationTokenQuery) Limit(limit int) *GroupInvitationTokenQuery { - gitq.limit = &limit + gitq.ctx.Limit = &limit return gitq } // Offset to start from. func (gitq *GroupInvitationTokenQuery) Offset(offset int) *GroupInvitationTokenQuery { - gitq.offset = &offset + gitq.ctx.Offset = &offset return gitq } // 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 (gitq *GroupInvitationTokenQuery) Unique(unique bool) *GroupInvitationTokenQuery { - gitq.unique = &unique + gitq.ctx.Unique = &unique return gitq } @@ -89,7 +86,7 @@ func (gitq *GroupInvitationTokenQuery) QueryGroup() *GroupQuery { // First returns the first GroupInvitationToken entity from the query. // Returns a *NotFoundError when no GroupInvitationToken was found. func (gitq *GroupInvitationTokenQuery) First(ctx context.Context) (*GroupInvitationToken, error) { - nodes, err := gitq.Limit(1).All(newQueryContext(ctx, TypeGroupInvitationToken, "First")) + nodes, err := gitq.Limit(1).All(setContextOp(ctx, gitq.ctx, "First")) if err != nil { return nil, err } @@ -112,7 +109,7 @@ func (gitq *GroupInvitationTokenQuery) FirstX(ctx context.Context) *GroupInvitat // Returns a *NotFoundError when no GroupInvitationToken ID was found. func (gitq *GroupInvitationTokenQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gitq.Limit(1).IDs(newQueryContext(ctx, TypeGroupInvitationToken, "FirstID")); err != nil { + if ids, err = gitq.Limit(1).IDs(setContextOp(ctx, gitq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -135,7 +132,7 @@ func (gitq *GroupInvitationTokenQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one GroupInvitationToken entity is found. // Returns a *NotFoundError when no GroupInvitationToken entities are found. func (gitq *GroupInvitationTokenQuery) Only(ctx context.Context) (*GroupInvitationToken, error) { - nodes, err := gitq.Limit(2).All(newQueryContext(ctx, TypeGroupInvitationToken, "Only")) + nodes, err := gitq.Limit(2).All(setContextOp(ctx, gitq.ctx, "Only")) if err != nil { return nil, err } @@ -163,7 +160,7 @@ func (gitq *GroupInvitationTokenQuery) OnlyX(ctx context.Context) *GroupInvitati // Returns a *NotFoundError when no entities are found. func (gitq *GroupInvitationTokenQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gitq.Limit(2).IDs(newQueryContext(ctx, TypeGroupInvitationToken, "OnlyID")); err != nil { + if ids, err = gitq.Limit(2).IDs(setContextOp(ctx, gitq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -188,7 +185,7 @@ func (gitq *GroupInvitationTokenQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of GroupInvitationTokens. func (gitq *GroupInvitationTokenQuery) All(ctx context.Context) ([]*GroupInvitationToken, error) { - ctx = newQueryContext(ctx, TypeGroupInvitationToken, "All") + ctx = setContextOp(ctx, gitq.ctx, "All") if err := gitq.prepareQuery(ctx); err != nil { return nil, err } @@ -208,7 +205,7 @@ func (gitq *GroupInvitationTokenQuery) AllX(ctx context.Context) []*GroupInvitat // IDs executes the query and returns a list of GroupInvitationToken IDs. func (gitq *GroupInvitationTokenQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { var ids []uuid.UUID - ctx = newQueryContext(ctx, TypeGroupInvitationToken, "IDs") + ctx = setContextOp(ctx, gitq.ctx, "IDs") if err := gitq.Select(groupinvitationtoken.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -226,7 +223,7 @@ func (gitq *GroupInvitationTokenQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (gitq *GroupInvitationTokenQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeGroupInvitationToken, "Count") + ctx = setContextOp(ctx, gitq.ctx, "Count") if err := gitq.prepareQuery(ctx); err != nil { return 0, err } @@ -244,7 +241,7 @@ func (gitq *GroupInvitationTokenQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (gitq *GroupInvitationTokenQuery) Exist(ctx context.Context) (bool, error) { - ctx = newQueryContext(ctx, TypeGroupInvitationToken, "Exist") + ctx = setContextOp(ctx, gitq.ctx, "Exist") switch _, err := gitq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -272,16 +269,14 @@ func (gitq *GroupInvitationTokenQuery) Clone() *GroupInvitationTokenQuery { } return &GroupInvitationTokenQuery{ config: gitq.config, - limit: gitq.limit, - offset: gitq.offset, + ctx: gitq.ctx.Clone(), order: append([]OrderFunc{}, gitq.order...), inters: append([]Interceptor{}, gitq.inters...), predicates: append([]predicate.GroupInvitationToken{}, gitq.predicates...), withGroup: gitq.withGroup.Clone(), // clone intermediate query. - sql: gitq.sql.Clone(), - path: gitq.path, - unique: gitq.unique, + sql: gitq.sql.Clone(), + path: gitq.path, } } @@ -311,9 +306,9 @@ func (gitq *GroupInvitationTokenQuery) WithGroup(opts ...func(*GroupQuery)) *Gro // Aggregate(ent.Count()). // Scan(ctx, &v) func (gitq *GroupInvitationTokenQuery) GroupBy(field string, fields ...string) *GroupInvitationTokenGroupBy { - gitq.fields = append([]string{field}, fields...) + gitq.ctx.Fields = append([]string{field}, fields...) grbuild := &GroupInvitationTokenGroupBy{build: gitq} - grbuild.flds = &gitq.fields + grbuild.flds = &gitq.ctx.Fields grbuild.label = groupinvitationtoken.Label grbuild.scan = grbuild.Scan return grbuild @@ -332,10 +327,10 @@ func (gitq *GroupInvitationTokenQuery) GroupBy(field string, fields ...string) * // Select(groupinvitationtoken.FieldCreatedAt). // Scan(ctx, &v) func (gitq *GroupInvitationTokenQuery) Select(fields ...string) *GroupInvitationTokenSelect { - gitq.fields = append(gitq.fields, fields...) + gitq.ctx.Fields = append(gitq.ctx.Fields, fields...) sbuild := &GroupInvitationTokenSelect{GroupInvitationTokenQuery: gitq} sbuild.label = groupinvitationtoken.Label - sbuild.flds, sbuild.scan = &gitq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &gitq.ctx.Fields, sbuild.Scan return sbuild } @@ -355,7 +350,7 @@ func (gitq *GroupInvitationTokenQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range gitq.fields { + for _, f := range gitq.ctx.Fields { if !groupinvitationtoken.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -425,6 +420,9 @@ func (gitq *GroupInvitationTokenQuery) loadGroup(ctx context.Context, query *Gro } 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 { @@ -444,9 +442,9 @@ func (gitq *GroupInvitationTokenQuery) loadGroup(ctx context.Context, query *Gro func (gitq *GroupInvitationTokenQuery) sqlCount(ctx context.Context) (int, error) { _spec := gitq.querySpec() - _spec.Node.Columns = gitq.fields - if len(gitq.fields) > 0 { - _spec.Unique = gitq.unique != nil && *gitq.unique + _spec.Node.Columns = gitq.ctx.Fields + if len(gitq.ctx.Fields) > 0 { + _spec.Unique = gitq.ctx.Unique != nil && *gitq.ctx.Unique } return sqlgraph.CountNodes(ctx, gitq.driver, _spec) } @@ -464,10 +462,10 @@ func (gitq *GroupInvitationTokenQuery) querySpec() *sqlgraph.QuerySpec { From: gitq.sql, Unique: true, } - if unique := gitq.unique; unique != nil { + if unique := gitq.ctx.Unique; unique != nil { _spec.Unique = *unique } - if fields := gitq.fields; len(fields) > 0 { + if fields := gitq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, groupinvitationtoken.FieldID) for i := range fields { @@ -483,10 +481,10 @@ func (gitq *GroupInvitationTokenQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := gitq.limit; limit != nil { + if limit := gitq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := gitq.offset; offset != nil { + if offset := gitq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := gitq.order; len(ps) > 0 { @@ -502,7 +500,7 @@ func (gitq *GroupInvitationTokenQuery) querySpec() *sqlgraph.QuerySpec { func (gitq *GroupInvitationTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(gitq.driver.Dialect()) t1 := builder.Table(groupinvitationtoken.Table) - columns := gitq.fields + columns := gitq.ctx.Fields if len(columns) == 0 { columns = groupinvitationtoken.Columns } @@ -511,7 +509,7 @@ func (gitq *GroupInvitationTokenQuery) sqlQuery(ctx context.Context) *sql.Select selector = gitq.sql selector.Select(selector.Columns(columns...)...) } - if gitq.unique != nil && *gitq.unique { + if gitq.ctx.Unique != nil && *gitq.ctx.Unique { selector.Distinct() } for _, p := range gitq.predicates { @@ -520,12 +518,12 @@ func (gitq *GroupInvitationTokenQuery) sqlQuery(ctx context.Context) *sql.Select for _, p := range gitq.order { p(selector) } - if offset := gitq.offset; offset != nil { + if offset := gitq.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 := gitq.limit; limit != nil { + if limit := gitq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -545,7 +543,7 @@ func (gitgb *GroupInvitationTokenGroupBy) Aggregate(fns ...AggregateFunc) *Group // Scan applies the selector query and scans the result into the given value. func (gitgb *GroupInvitationTokenGroupBy) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeGroupInvitationToken, "GroupBy") + ctx = setContextOp(ctx, gitgb.build.ctx, "GroupBy") if err := gitgb.build.prepareQuery(ctx); err != nil { return err } @@ -593,7 +591,7 @@ func (gits *GroupInvitationTokenSelect) Aggregate(fns ...AggregateFunc) *GroupIn // Scan applies the selector query and scans the result into the given value. func (gits *GroupInvitationTokenSelect) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeGroupInvitationToken, "Select") + ctx = setContextOp(ctx, gits.ctx, "Select") if err := gits.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/item.go b/backend/internal/data/ent/item.go index bcca2c7..415b8b9 100644 --- a/backend/internal/data/ent/item.go +++ b/backend/internal/data/ent/item.go @@ -390,49 +390,49 @@ func (i *Item) assignValues(columns []string, values []any) error { // QueryParent queries the "parent" edge of the Item entity. func (i *Item) QueryParent() *ItemQuery { - return (&ItemClient{config: i.config}).QueryParent(i) + return NewItemClient(i.config).QueryParent(i) } // QueryChildren queries the "children" edge of the Item entity. func (i *Item) QueryChildren() *ItemQuery { - return (&ItemClient{config: i.config}).QueryChildren(i) + return NewItemClient(i.config).QueryChildren(i) } // QueryGroup queries the "group" edge of the Item entity. func (i *Item) QueryGroup() *GroupQuery { - return (&ItemClient{config: i.config}).QueryGroup(i) + return NewItemClient(i.config).QueryGroup(i) } // QueryLabel queries the "label" edge of the Item entity. func (i *Item) QueryLabel() *LabelQuery { - return (&ItemClient{config: i.config}).QueryLabel(i) + return NewItemClient(i.config).QueryLabel(i) } // QueryLocation queries the "location" edge of the Item entity. func (i *Item) QueryLocation() *LocationQuery { - return (&ItemClient{config: i.config}).QueryLocation(i) + return NewItemClient(i.config).QueryLocation(i) } // QueryFields queries the "fields" edge of the Item entity. func (i *Item) QueryFields() *ItemFieldQuery { - return (&ItemClient{config: i.config}).QueryFields(i) + return NewItemClient(i.config).QueryFields(i) } // QueryMaintenanceEntries queries the "maintenance_entries" edge of the Item entity. func (i *Item) QueryMaintenanceEntries() *MaintenanceEntryQuery { - return (&ItemClient{config: i.config}).QueryMaintenanceEntries(i) + return NewItemClient(i.config).QueryMaintenanceEntries(i) } // QueryAttachments queries the "attachments" edge of the Item entity. func (i *Item) QueryAttachments() *AttachmentQuery { - return (&ItemClient{config: i.config}).QueryAttachments(i) + return NewItemClient(i.config).QueryAttachments(i) } // Update returns a builder for updating this Item. // Note that you need to call Item.Unwrap() before calling this method if this Item // was returned from a transaction, and the transaction was committed or rolled back. func (i *Item) Update() *ItemUpdateOne { - return (&ItemClient{config: i.config}).UpdateOne(i) + return NewItemClient(i.config).UpdateOne(i) } // Unwrap unwraps the Item entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/item_delete.go b/backend/internal/data/ent/item_delete.go index 4ebd167..b6f0d47 100644 --- a/backend/internal/data/ent/item_delete.go +++ b/backend/internal/data/ent/item_delete.go @@ -69,6 +69,12 @@ type ItemDeleteOne struct { id *ItemDelete } +// Where appends a list predicates to the ItemDelete builder. +func (ido *ItemDeleteOne) Where(ps ...predicate.Item) *ItemDeleteOne { + ido.id.mutation.Where(ps...) + return ido +} + // Exec executes the deletion query. func (ido *ItemDeleteOne) Exec(ctx context.Context) error { n, err := ido.id.Exec(ctx) @@ -84,5 +90,7 @@ func (ido *ItemDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (ido *ItemDeleteOne) ExecX(ctx context.Context) { - ido.id.ExecX(ctx) + if err := ido.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/item_query.go b/backend/internal/data/ent/item_query.go index cde5b44..045c31f 100644 --- a/backend/internal/data/ent/item_query.go +++ b/backend/internal/data/ent/item_query.go @@ -25,11 +25,8 @@ import ( // ItemQuery is the builder for querying Item entities. type ItemQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.Item withParent *ItemQuery @@ -54,20 +51,20 @@ func (iq *ItemQuery) Where(ps ...predicate.Item) *ItemQuery { // Limit the number of records to be returned by this query. func (iq *ItemQuery) Limit(limit int) *ItemQuery { - iq.limit = &limit + iq.ctx.Limit = &limit return iq } // Offset to start from. func (iq *ItemQuery) Offset(offset int) *ItemQuery { - iq.offset = &offset + iq.ctx.Offset = &offset return iq } // 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 (iq *ItemQuery) Unique(unique bool) *ItemQuery { - iq.unique = &unique + iq.ctx.Unique = &unique return iq } @@ -256,7 +253,7 @@ func (iq *ItemQuery) QueryAttachments() *AttachmentQuery { // First returns the first Item entity from the query. // Returns a *NotFoundError when no Item was found. func (iq *ItemQuery) First(ctx context.Context) (*Item, error) { - nodes, err := iq.Limit(1).All(newQueryContext(ctx, TypeItem, "First")) + nodes, err := iq.Limit(1).All(setContextOp(ctx, iq.ctx, "First")) if err != nil { return nil, err } @@ -279,7 +276,7 @@ func (iq *ItemQuery) FirstX(ctx context.Context) *Item { // Returns a *NotFoundError when no Item ID was found. func (iq *ItemQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = iq.Limit(1).IDs(newQueryContext(ctx, TypeItem, "FirstID")); err != nil { + if ids, err = iq.Limit(1).IDs(setContextOp(ctx, iq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -302,7 +299,7 @@ func (iq *ItemQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Item entity is found. // Returns a *NotFoundError when no Item entities are found. func (iq *ItemQuery) Only(ctx context.Context) (*Item, error) { - nodes, err := iq.Limit(2).All(newQueryContext(ctx, TypeItem, "Only")) + nodes, err := iq.Limit(2).All(setContextOp(ctx, iq.ctx, "Only")) if err != nil { return nil, err } @@ -330,7 +327,7 @@ func (iq *ItemQuery) OnlyX(ctx context.Context) *Item { // Returns a *NotFoundError when no entities are found. func (iq *ItemQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = iq.Limit(2).IDs(newQueryContext(ctx, TypeItem, "OnlyID")); err != nil { + if ids, err = iq.Limit(2).IDs(setContextOp(ctx, iq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -355,7 +352,7 @@ func (iq *ItemQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Items. func (iq *ItemQuery) All(ctx context.Context) ([]*Item, error) { - ctx = newQueryContext(ctx, TypeItem, "All") + ctx = setContextOp(ctx, iq.ctx, "All") if err := iq.prepareQuery(ctx); err != nil { return nil, err } @@ -375,7 +372,7 @@ func (iq *ItemQuery) AllX(ctx context.Context) []*Item { // IDs executes the query and returns a list of Item IDs. func (iq *ItemQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { var ids []uuid.UUID - ctx = newQueryContext(ctx, TypeItem, "IDs") + ctx = setContextOp(ctx, iq.ctx, "IDs") if err := iq.Select(item.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -393,7 +390,7 @@ func (iq *ItemQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (iq *ItemQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeItem, "Count") + ctx = setContextOp(ctx, iq.ctx, "Count") if err := iq.prepareQuery(ctx); err != nil { return 0, err } @@ -411,7 +408,7 @@ func (iq *ItemQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (iq *ItemQuery) Exist(ctx context.Context) (bool, error) { - ctx = newQueryContext(ctx, TypeItem, "Exist") + ctx = setContextOp(ctx, iq.ctx, "Exist") switch _, err := iq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -439,8 +436,7 @@ func (iq *ItemQuery) Clone() *ItemQuery { } return &ItemQuery{ config: iq.config, - limit: iq.limit, - offset: iq.offset, + ctx: iq.ctx.Clone(), order: append([]OrderFunc{}, iq.order...), inters: append([]Interceptor{}, iq.inters...), predicates: append([]predicate.Item{}, iq.predicates...), @@ -453,9 +449,8 @@ func (iq *ItemQuery) Clone() *ItemQuery { withMaintenanceEntries: iq.withMaintenanceEntries.Clone(), withAttachments: iq.withAttachments.Clone(), // clone intermediate query. - sql: iq.sql.Clone(), - path: iq.path, - unique: iq.unique, + sql: iq.sql.Clone(), + path: iq.path, } } @@ -562,9 +557,9 @@ func (iq *ItemQuery) WithAttachments(opts ...func(*AttachmentQuery)) *ItemQuery // Aggregate(ent.Count()). // Scan(ctx, &v) func (iq *ItemQuery) GroupBy(field string, fields ...string) *ItemGroupBy { - iq.fields = append([]string{field}, fields...) + iq.ctx.Fields = append([]string{field}, fields...) grbuild := &ItemGroupBy{build: iq} - grbuild.flds = &iq.fields + grbuild.flds = &iq.ctx.Fields grbuild.label = item.Label grbuild.scan = grbuild.Scan return grbuild @@ -583,10 +578,10 @@ func (iq *ItemQuery) GroupBy(field string, fields ...string) *ItemGroupBy { // Select(item.FieldCreatedAt). // Scan(ctx, &v) func (iq *ItemQuery) Select(fields ...string) *ItemSelect { - iq.fields = append(iq.fields, fields...) + iq.ctx.Fields = append(iq.ctx.Fields, fields...) sbuild := &ItemSelect{ItemQuery: iq} sbuild.label = item.Label - sbuild.flds, sbuild.scan = &iq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &iq.ctx.Fields, sbuild.Scan return sbuild } @@ -606,7 +601,7 @@ func (iq *ItemQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range iq.fields { + for _, f := range iq.ctx.Fields { if !item.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -730,6 +725,9 @@ func (iq *ItemQuery) loadParent(ctx context.Context, query *ItemQuery, nodes []* } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(item.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -790,6 +788,9 @@ func (iq *ItemQuery) 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 { @@ -829,27 +830,30 @@ func (iq *ItemQuery) loadLabel(ctx context.Context, query *LabelQuery, nodes []* if err := query.prepareQuery(ctx); err != nil { return err } - neighbors, err := query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { - assign := spec.Assign - values := spec.ScanValues - spec.ScanValues = func(columns []string) ([]any, error) { - values, err := values(columns[1:]) - if err != nil { - return nil, err + qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { + assign := spec.Assign + values := spec.ScanValues + spec.ScanValues = func(columns []string) ([]any, error) { + values, err := values(columns[1:]) + if err != nil { + return nil, err + } + return append([]any{new(uuid.UUID)}, values...), nil } - return append([]any{new(uuid.UUID)}, values...), nil - } - spec.Assign = func(columns []string, values []any) error { - outValue := *values[0].(*uuid.UUID) - inValue := *values[1].(*uuid.UUID) - if nids[inValue] == nil { - nids[inValue] = map[*Item]struct{}{byID[outValue]: {}} - return assign(columns[1:], values[1:]) + spec.Assign = func(columns []string, values []any) error { + outValue := *values[0].(*uuid.UUID) + inValue := *values[1].(*uuid.UUID) + if nids[inValue] == nil { + nids[inValue] = map[*Item]struct{}{byID[outValue]: {}} + return assign(columns[1:], values[1:]) + } + nids[inValue][byID[outValue]] = struct{}{} + return nil } - nids[inValue][byID[outValue]] = struct{}{} - return nil - } + }) }) + neighbors, err := withInterceptors[[]*Label](ctx, query, qr, query.inters) if err != nil { return err } @@ -877,6 +881,9 @@ func (iq *ItemQuery) loadLocation(ctx context.Context, query *LocationQuery, nod } 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 { @@ -985,9 +992,9 @@ func (iq *ItemQuery) loadAttachments(ctx context.Context, query *AttachmentQuery func (iq *ItemQuery) sqlCount(ctx context.Context) (int, error) { _spec := iq.querySpec() - _spec.Node.Columns = iq.fields - if len(iq.fields) > 0 { - _spec.Unique = iq.unique != nil && *iq.unique + _spec.Node.Columns = iq.ctx.Fields + if len(iq.ctx.Fields) > 0 { + _spec.Unique = iq.ctx.Unique != nil && *iq.ctx.Unique } return sqlgraph.CountNodes(ctx, iq.driver, _spec) } @@ -1005,10 +1012,10 @@ func (iq *ItemQuery) querySpec() *sqlgraph.QuerySpec { From: iq.sql, Unique: true, } - if unique := iq.unique; unique != nil { + if unique := iq.ctx.Unique; unique != nil { _spec.Unique = *unique } - if fields := iq.fields; len(fields) > 0 { + if fields := iq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, item.FieldID) for i := range fields { @@ -1024,10 +1031,10 @@ func (iq *ItemQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := iq.limit; limit != nil { + if limit := iq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := iq.offset; offset != nil { + if offset := iq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := iq.order; len(ps) > 0 { @@ -1043,7 +1050,7 @@ func (iq *ItemQuery) querySpec() *sqlgraph.QuerySpec { func (iq *ItemQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(iq.driver.Dialect()) t1 := builder.Table(item.Table) - columns := iq.fields + columns := iq.ctx.Fields if len(columns) == 0 { columns = item.Columns } @@ -1052,7 +1059,7 @@ func (iq *ItemQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = iq.sql selector.Select(selector.Columns(columns...)...) } - if iq.unique != nil && *iq.unique { + if iq.ctx.Unique != nil && *iq.ctx.Unique { selector.Distinct() } for _, p := range iq.predicates { @@ -1061,12 +1068,12 @@ func (iq *ItemQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range iq.order { p(selector) } - if offset := iq.offset; offset != nil { + if offset := iq.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 := iq.limit; limit != nil { + if limit := iq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -1086,7 +1093,7 @@ func (igb *ItemGroupBy) Aggregate(fns ...AggregateFunc) *ItemGroupBy { // Scan applies the selector query and scans the result into the given value. func (igb *ItemGroupBy) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeItem, "GroupBy") + ctx = setContextOp(ctx, igb.build.ctx, "GroupBy") if err := igb.build.prepareQuery(ctx); err != nil { return err } @@ -1134,7 +1141,7 @@ func (is *ItemSelect) Aggregate(fns ...AggregateFunc) *ItemSelect { // Scan applies the selector query and scans the result into the given value. func (is *ItemSelect) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeItem, "Select") + ctx = setContextOp(ctx, is.ctx, "Select") if err := is.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/itemfield.go b/backend/internal/data/ent/itemfield.go index be68023..91b1195 100644 --- a/backend/internal/data/ent/itemfield.go +++ b/backend/internal/data/ent/itemfield.go @@ -170,14 +170,14 @@ func (_if *ItemField) assignValues(columns []string, values []any) error { // QueryItem queries the "item" edge of the ItemField entity. func (_if *ItemField) QueryItem() *ItemQuery { - return (&ItemFieldClient{config: _if.config}).QueryItem(_if) + return NewItemFieldClient(_if.config).QueryItem(_if) } // Update returns a builder for updating this ItemField. // Note that you need to call ItemField.Unwrap() before calling this method if this ItemField // was returned from a transaction, and the transaction was committed or rolled back. func (_if *ItemField) Update() *ItemFieldUpdateOne { - return (&ItemFieldClient{config: _if.config}).UpdateOne(_if) + return NewItemFieldClient(_if.config).UpdateOne(_if) } // Unwrap unwraps the ItemField entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/itemfield_delete.go b/backend/internal/data/ent/itemfield_delete.go index aaca25a..5b9c139 100644 --- a/backend/internal/data/ent/itemfield_delete.go +++ b/backend/internal/data/ent/itemfield_delete.go @@ -69,6 +69,12 @@ type ItemFieldDeleteOne struct { ifd *ItemFieldDelete } +// Where appends a list predicates to the ItemFieldDelete builder. +func (ifdo *ItemFieldDeleteOne) Where(ps ...predicate.ItemField) *ItemFieldDeleteOne { + ifdo.ifd.mutation.Where(ps...) + return ifdo +} + // Exec executes the deletion query. func (ifdo *ItemFieldDeleteOne) Exec(ctx context.Context) error { n, err := ifdo.ifd.Exec(ctx) @@ -84,5 +90,7 @@ func (ifdo *ItemFieldDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (ifdo *ItemFieldDeleteOne) ExecX(ctx context.Context) { - ifdo.ifd.ExecX(ctx) + if err := ifdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/itemfield_query.go b/backend/internal/data/ent/itemfield_query.go index 4629dd2..ef8ca94 100644 --- a/backend/internal/data/ent/itemfield_query.go +++ b/backend/internal/data/ent/itemfield_query.go @@ -19,11 +19,8 @@ import ( // ItemFieldQuery is the builder for querying ItemField entities. type ItemFieldQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.ItemField withItem *ItemQuery @@ -41,20 +38,20 @@ func (ifq *ItemFieldQuery) Where(ps ...predicate.ItemField) *ItemFieldQuery { // Limit the number of records to be returned by this query. func (ifq *ItemFieldQuery) Limit(limit int) *ItemFieldQuery { - ifq.limit = &limit + ifq.ctx.Limit = &limit return ifq } // Offset to start from. func (ifq *ItemFieldQuery) Offset(offset int) *ItemFieldQuery { - ifq.offset = &offset + ifq.ctx.Offset = &offset return ifq } // 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 (ifq *ItemFieldQuery) Unique(unique bool) *ItemFieldQuery { - ifq.unique = &unique + ifq.ctx.Unique = &unique return ifq } @@ -89,7 +86,7 @@ func (ifq *ItemFieldQuery) QueryItem() *ItemQuery { // First returns the first ItemField entity from the query. // Returns a *NotFoundError when no ItemField was found. func (ifq *ItemFieldQuery) First(ctx context.Context) (*ItemField, error) { - nodes, err := ifq.Limit(1).All(newQueryContext(ctx, TypeItemField, "First")) + nodes, err := ifq.Limit(1).All(setContextOp(ctx, ifq.ctx, "First")) if err != nil { return nil, err } @@ -112,7 +109,7 @@ func (ifq *ItemFieldQuery) FirstX(ctx context.Context) *ItemField { // Returns a *NotFoundError when no ItemField ID was found. func (ifq *ItemFieldQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = ifq.Limit(1).IDs(newQueryContext(ctx, TypeItemField, "FirstID")); err != nil { + if ids, err = ifq.Limit(1).IDs(setContextOp(ctx, ifq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -135,7 +132,7 @@ func (ifq *ItemFieldQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one ItemField entity is found. // Returns a *NotFoundError when no ItemField entities are found. func (ifq *ItemFieldQuery) Only(ctx context.Context) (*ItemField, error) { - nodes, err := ifq.Limit(2).All(newQueryContext(ctx, TypeItemField, "Only")) + nodes, err := ifq.Limit(2).All(setContextOp(ctx, ifq.ctx, "Only")) if err != nil { return nil, err } @@ -163,7 +160,7 @@ func (ifq *ItemFieldQuery) OnlyX(ctx context.Context) *ItemField { // Returns a *NotFoundError when no entities are found. func (ifq *ItemFieldQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = ifq.Limit(2).IDs(newQueryContext(ctx, TypeItemField, "OnlyID")); err != nil { + if ids, err = ifq.Limit(2).IDs(setContextOp(ctx, ifq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -188,7 +185,7 @@ func (ifq *ItemFieldQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of ItemFields. func (ifq *ItemFieldQuery) All(ctx context.Context) ([]*ItemField, error) { - ctx = newQueryContext(ctx, TypeItemField, "All") + ctx = setContextOp(ctx, ifq.ctx, "All") if err := ifq.prepareQuery(ctx); err != nil { return nil, err } @@ -208,7 +205,7 @@ func (ifq *ItemFieldQuery) AllX(ctx context.Context) []*ItemField { // IDs executes the query and returns a list of ItemField IDs. func (ifq *ItemFieldQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { var ids []uuid.UUID - ctx = newQueryContext(ctx, TypeItemField, "IDs") + ctx = setContextOp(ctx, ifq.ctx, "IDs") if err := ifq.Select(itemfield.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -226,7 +223,7 @@ func (ifq *ItemFieldQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (ifq *ItemFieldQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeItemField, "Count") + ctx = setContextOp(ctx, ifq.ctx, "Count") if err := ifq.prepareQuery(ctx); err != nil { return 0, err } @@ -244,7 +241,7 @@ func (ifq *ItemFieldQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (ifq *ItemFieldQuery) Exist(ctx context.Context) (bool, error) { - ctx = newQueryContext(ctx, TypeItemField, "Exist") + ctx = setContextOp(ctx, ifq.ctx, "Exist") switch _, err := ifq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -272,16 +269,14 @@ func (ifq *ItemFieldQuery) Clone() *ItemFieldQuery { } return &ItemFieldQuery{ config: ifq.config, - limit: ifq.limit, - offset: ifq.offset, + ctx: ifq.ctx.Clone(), order: append([]OrderFunc{}, ifq.order...), inters: append([]Interceptor{}, ifq.inters...), predicates: append([]predicate.ItemField{}, ifq.predicates...), withItem: ifq.withItem.Clone(), // clone intermediate query. - sql: ifq.sql.Clone(), - path: ifq.path, - unique: ifq.unique, + sql: ifq.sql.Clone(), + path: ifq.path, } } @@ -311,9 +306,9 @@ func (ifq *ItemFieldQuery) WithItem(opts ...func(*ItemQuery)) *ItemFieldQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (ifq *ItemFieldQuery) GroupBy(field string, fields ...string) *ItemFieldGroupBy { - ifq.fields = append([]string{field}, fields...) + ifq.ctx.Fields = append([]string{field}, fields...) grbuild := &ItemFieldGroupBy{build: ifq} - grbuild.flds = &ifq.fields + grbuild.flds = &ifq.ctx.Fields grbuild.label = itemfield.Label grbuild.scan = grbuild.Scan return grbuild @@ -332,10 +327,10 @@ func (ifq *ItemFieldQuery) GroupBy(field string, fields ...string) *ItemFieldGro // Select(itemfield.FieldCreatedAt). // Scan(ctx, &v) func (ifq *ItemFieldQuery) Select(fields ...string) *ItemFieldSelect { - ifq.fields = append(ifq.fields, fields...) + ifq.ctx.Fields = append(ifq.ctx.Fields, fields...) sbuild := &ItemFieldSelect{ItemFieldQuery: ifq} sbuild.label = itemfield.Label - sbuild.flds, sbuild.scan = &ifq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &ifq.ctx.Fields, sbuild.Scan return sbuild } @@ -355,7 +350,7 @@ func (ifq *ItemFieldQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range ifq.fields { + for _, f := range ifq.ctx.Fields { if !itemfield.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -425,6 +420,9 @@ func (ifq *ItemFieldQuery) loadItem(ctx context.Context, query *ItemQuery, nodes } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(item.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -444,9 +442,9 @@ func (ifq *ItemFieldQuery) loadItem(ctx context.Context, query *ItemQuery, nodes func (ifq *ItemFieldQuery) sqlCount(ctx context.Context) (int, error) { _spec := ifq.querySpec() - _spec.Node.Columns = ifq.fields - if len(ifq.fields) > 0 { - _spec.Unique = ifq.unique != nil && *ifq.unique + _spec.Node.Columns = ifq.ctx.Fields + if len(ifq.ctx.Fields) > 0 { + _spec.Unique = ifq.ctx.Unique != nil && *ifq.ctx.Unique } return sqlgraph.CountNodes(ctx, ifq.driver, _spec) } @@ -464,10 +462,10 @@ func (ifq *ItemFieldQuery) querySpec() *sqlgraph.QuerySpec { From: ifq.sql, Unique: true, } - if unique := ifq.unique; unique != nil { + if unique := ifq.ctx.Unique; unique != nil { _spec.Unique = *unique } - if fields := ifq.fields; len(fields) > 0 { + if fields := ifq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, itemfield.FieldID) for i := range fields { @@ -483,10 +481,10 @@ func (ifq *ItemFieldQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := ifq.limit; limit != nil { + if limit := ifq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := ifq.offset; offset != nil { + if offset := ifq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := ifq.order; len(ps) > 0 { @@ -502,7 +500,7 @@ func (ifq *ItemFieldQuery) querySpec() *sqlgraph.QuerySpec { func (ifq *ItemFieldQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(ifq.driver.Dialect()) t1 := builder.Table(itemfield.Table) - columns := ifq.fields + columns := ifq.ctx.Fields if len(columns) == 0 { columns = itemfield.Columns } @@ -511,7 +509,7 @@ func (ifq *ItemFieldQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = ifq.sql selector.Select(selector.Columns(columns...)...) } - if ifq.unique != nil && *ifq.unique { + if ifq.ctx.Unique != nil && *ifq.ctx.Unique { selector.Distinct() } for _, p := range ifq.predicates { @@ -520,12 +518,12 @@ func (ifq *ItemFieldQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range ifq.order { p(selector) } - if offset := ifq.offset; offset != nil { + if offset := ifq.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 := ifq.limit; limit != nil { + if limit := ifq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -545,7 +543,7 @@ func (ifgb *ItemFieldGroupBy) Aggregate(fns ...AggregateFunc) *ItemFieldGroupBy // Scan applies the selector query and scans the result into the given value. func (ifgb *ItemFieldGroupBy) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeItemField, "GroupBy") + ctx = setContextOp(ctx, ifgb.build.ctx, "GroupBy") if err := ifgb.build.prepareQuery(ctx); err != nil { return err } @@ -593,7 +591,7 @@ func (ifs *ItemFieldSelect) Aggregate(fns ...AggregateFunc) *ItemFieldSelect { // Scan applies the selector query and scans the result into the given value. func (ifs *ItemFieldSelect) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeItemField, "Select") + ctx = setContextOp(ctx, ifs.ctx, "Select") if err := ifs.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/label.go b/backend/internal/data/ent/label.go index 9e65bfe..22d5370 100644 --- a/backend/internal/data/ent/label.go +++ b/backend/internal/data/ent/label.go @@ -145,19 +145,19 @@ func (l *Label) assignValues(columns []string, values []any) error { // QueryGroup queries the "group" edge of the Label entity. func (l *Label) QueryGroup() *GroupQuery { - return (&LabelClient{config: l.config}).QueryGroup(l) + return NewLabelClient(l.config).QueryGroup(l) } // QueryItems queries the "items" edge of the Label entity. func (l *Label) QueryItems() *ItemQuery { - return (&LabelClient{config: l.config}).QueryItems(l) + return NewLabelClient(l.config).QueryItems(l) } // Update returns a builder for updating this Label. // Note that you need to call Label.Unwrap() before calling this method if this Label // was returned from a transaction, and the transaction was committed or rolled back. func (l *Label) Update() *LabelUpdateOne { - return (&LabelClient{config: l.config}).UpdateOne(l) + return NewLabelClient(l.config).UpdateOne(l) } // Unwrap unwraps the Label entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/label_delete.go b/backend/internal/data/ent/label_delete.go index 1c520df..bd869cd 100644 --- a/backend/internal/data/ent/label_delete.go +++ b/backend/internal/data/ent/label_delete.go @@ -69,6 +69,12 @@ type LabelDeleteOne struct { ld *LabelDelete } +// Where appends a list predicates to the LabelDelete builder. +func (ldo *LabelDeleteOne) Where(ps ...predicate.Label) *LabelDeleteOne { + ldo.ld.mutation.Where(ps...) + return ldo +} + // Exec executes the deletion query. func (ldo *LabelDeleteOne) Exec(ctx context.Context) error { n, err := ldo.ld.Exec(ctx) @@ -84,5 +90,7 @@ func (ldo *LabelDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (ldo *LabelDeleteOne) ExecX(ctx context.Context) { - ldo.ld.ExecX(ctx) + if err := ldo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/label_query.go b/backend/internal/data/ent/label_query.go index 16de809..ec6165e 100644 --- a/backend/internal/data/ent/label_query.go +++ b/backend/internal/data/ent/label_query.go @@ -21,11 +21,8 @@ import ( // LabelQuery is the builder for querying Label entities. type LabelQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.Label withGroup *GroupQuery @@ -44,20 +41,20 @@ func (lq *LabelQuery) Where(ps ...predicate.Label) *LabelQuery { // Limit the number of records to be returned by this query. func (lq *LabelQuery) Limit(limit int) *LabelQuery { - lq.limit = &limit + lq.ctx.Limit = &limit return lq } // Offset to start from. func (lq *LabelQuery) Offset(offset int) *LabelQuery { - 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 *LabelQuery) Unique(unique bool) *LabelQuery { - lq.unique = &unique + lq.ctx.Unique = &unique return lq } @@ -114,7 +111,7 @@ func (lq *LabelQuery) QueryItems() *ItemQuery { // First returns the first Label entity from the query. // Returns a *NotFoundError when no Label was found. func (lq *LabelQuery) First(ctx context.Context) (*Label, error) { - nodes, err := lq.Limit(1).All(newQueryContext(ctx, TypeLabel, "First")) + nodes, err := lq.Limit(1).All(setContextOp(ctx, lq.ctx, "First")) if err != nil { return nil, err } @@ -137,7 +134,7 @@ func (lq *LabelQuery) FirstX(ctx context.Context) *Label { // Returns a *NotFoundError when no Label ID was found. func (lq *LabelQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = lq.Limit(1).IDs(newQueryContext(ctx, TypeLabel, "FirstID")); err != nil { + if ids, err = lq.Limit(1).IDs(setContextOp(ctx, lq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -160,7 +157,7 @@ func (lq *LabelQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Label entity is found. // Returns a *NotFoundError when no Label entities are found. func (lq *LabelQuery) Only(ctx context.Context) (*Label, error) { - nodes, err := lq.Limit(2).All(newQueryContext(ctx, TypeLabel, "Only")) + nodes, err := lq.Limit(2).All(setContextOp(ctx, lq.ctx, "Only")) if err != nil { return nil, err } @@ -188,7 +185,7 @@ func (lq *LabelQuery) OnlyX(ctx context.Context) *Label { // Returns a *NotFoundError when no entities are found. func (lq *LabelQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = lq.Limit(2).IDs(newQueryContext(ctx, TypeLabel, "OnlyID")); err != nil { + if ids, err = lq.Limit(2).IDs(setContextOp(ctx, lq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -213,7 +210,7 @@ func (lq *LabelQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Labels. func (lq *LabelQuery) All(ctx context.Context) ([]*Label, error) { - ctx = newQueryContext(ctx, TypeLabel, "All") + ctx = setContextOp(ctx, lq.ctx, "All") if err := lq.prepareQuery(ctx); err != nil { return nil, err } @@ -233,7 +230,7 @@ func (lq *LabelQuery) AllX(ctx context.Context) []*Label { // IDs executes the query and returns a list of Label IDs. func (lq *LabelQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { var ids []uuid.UUID - ctx = newQueryContext(ctx, TypeLabel, "IDs") + ctx = setContextOp(ctx, lq.ctx, "IDs") if err := lq.Select(label.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -251,7 +248,7 @@ func (lq *LabelQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (lq *LabelQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeLabel, "Count") + ctx = setContextOp(ctx, lq.ctx, "Count") if err := lq.prepareQuery(ctx); err != nil { return 0, err } @@ -269,7 +266,7 @@ func (lq *LabelQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (lq *LabelQuery) Exist(ctx context.Context) (bool, error) { - ctx = newQueryContext(ctx, TypeLabel, "Exist") + ctx = setContextOp(ctx, lq.ctx, "Exist") switch _, err := lq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -297,17 +294,15 @@ func (lq *LabelQuery) Clone() *LabelQuery { } return &LabelQuery{ 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.Label{}, lq.predicates...), 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, } } @@ -348,9 +343,9 @@ func (lq *LabelQuery) WithItems(opts ...func(*ItemQuery)) *LabelQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (lq *LabelQuery) GroupBy(field string, fields ...string) *LabelGroupBy { - lq.fields = append([]string{field}, fields...) + lq.ctx.Fields = append([]string{field}, fields...) grbuild := &LabelGroupBy{build: lq} - grbuild.flds = &lq.fields + grbuild.flds = &lq.ctx.Fields grbuild.label = label.Label grbuild.scan = grbuild.Scan return grbuild @@ -369,10 +364,10 @@ func (lq *LabelQuery) GroupBy(field string, fields ...string) *LabelGroupBy { // Select(label.FieldCreatedAt). // Scan(ctx, &v) func (lq *LabelQuery) Select(fields ...string) *LabelSelect { - lq.fields = append(lq.fields, fields...) + lq.ctx.Fields = append(lq.ctx.Fields, fields...) sbuild := &LabelSelect{LabelQuery: lq} sbuild.label = label.Label - sbuild.flds, sbuild.scan = &lq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &lq.ctx.Fields, sbuild.Scan return sbuild } @@ -392,7 +387,7 @@ func (lq *LabelQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range lq.fields { + for _, f := range lq.ctx.Fields { if !label.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -470,6 +465,9 @@ func (lq *LabelQuery) 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 { @@ -509,27 +507,30 @@ func (lq *LabelQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []* if err := query.prepareQuery(ctx); err != nil { return err } - neighbors, err := query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { - assign := spec.Assign - values := spec.ScanValues - spec.ScanValues = func(columns []string) ([]any, error) { - values, err := values(columns[1:]) - if err != nil { - return nil, err + qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { + assign := spec.Assign + values := spec.ScanValues + spec.ScanValues = func(columns []string) ([]any, error) { + values, err := values(columns[1:]) + if err != nil { + return nil, err + } + return append([]any{new(uuid.UUID)}, values...), nil } - return append([]any{new(uuid.UUID)}, values...), nil - } - spec.Assign = func(columns []string, values []any) error { - outValue := *values[0].(*uuid.UUID) - inValue := *values[1].(*uuid.UUID) - if nids[inValue] == nil { - nids[inValue] = map[*Label]struct{}{byID[outValue]: {}} - return assign(columns[1:], values[1:]) + spec.Assign = func(columns []string, values []any) error { + outValue := *values[0].(*uuid.UUID) + inValue := *values[1].(*uuid.UUID) + if nids[inValue] == nil { + nids[inValue] = map[*Label]struct{}{byID[outValue]: {}} + return assign(columns[1:], values[1:]) + } + nids[inValue][byID[outValue]] = struct{}{} + return nil } - nids[inValue][byID[outValue]] = struct{}{} - return nil - } + }) }) + neighbors, err := withInterceptors[[]*Item](ctx, query, qr, query.inters) if err != nil { return err } @@ -547,9 +548,9 @@ func (lq *LabelQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []* func (lq *LabelQuery) 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) } @@ -567,10 +568,10 @@ func (lq *LabelQuery) 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, label.FieldID) for i := range fields { @@ -586,10 +587,10 @@ func (lq *LabelQuery) 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 { @@ -605,7 +606,7 @@ func (lq *LabelQuery) querySpec() *sqlgraph.QuerySpec { func (lq *LabelQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(lq.driver.Dialect()) t1 := builder.Table(label.Table) - columns := lq.fields + columns := lq.ctx.Fields if len(columns) == 0 { columns = label.Columns } @@ -614,7 +615,7 @@ func (lq *LabelQuery) 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 { @@ -623,12 +624,12 @@ func (lq *LabelQuery) 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 @@ -648,7 +649,7 @@ func (lgb *LabelGroupBy) Aggregate(fns ...AggregateFunc) *LabelGroupBy { // Scan applies the selector query and scans the result into the given value. func (lgb *LabelGroupBy) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeLabel, "GroupBy") + ctx = setContextOp(ctx, lgb.build.ctx, "GroupBy") if err := lgb.build.prepareQuery(ctx); err != nil { return err } @@ -696,7 +697,7 @@ func (ls *LabelSelect) Aggregate(fns ...AggregateFunc) *LabelSelect { // Scan applies the selector query and scans the result into the given value. func (ls *LabelSelect) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeLabel, "Select") + ctx = setContextOp(ctx, ls.ctx, "Select") if err := ls.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/location.go b/backend/internal/data/ent/location.go index 67abd30..0ac5d00 100644 --- a/backend/internal/data/ent/location.go +++ b/backend/internal/data/ent/location.go @@ -173,29 +173,29 @@ func (l *Location) assignValues(columns []string, values []any) error { // QueryParent queries the "parent" edge of the Location entity. func (l *Location) QueryParent() *LocationQuery { - return (&LocationClient{config: l.config}).QueryParent(l) + return NewLocationClient(l.config).QueryParent(l) } // QueryChildren queries the "children" edge of the Location entity. func (l *Location) QueryChildren() *LocationQuery { - return (&LocationClient{config: l.config}).QueryChildren(l) + return NewLocationClient(l.config).QueryChildren(l) } // QueryGroup queries the "group" edge of the Location entity. func (l *Location) QueryGroup() *GroupQuery { - return (&LocationClient{config: l.config}).QueryGroup(l) + return NewLocationClient(l.config).QueryGroup(l) } // QueryItems queries the "items" edge of the Location entity. func (l *Location) QueryItems() *ItemQuery { - return (&LocationClient{config: l.config}).QueryItems(l) + return NewLocationClient(l.config).QueryItems(l) } // Update returns a builder for updating this Location. // Note that you need to call Location.Unwrap() before calling this method if this Location // was returned from a transaction, and the transaction was committed or rolled back. func (l *Location) Update() *LocationUpdateOne { - return (&LocationClient{config: l.config}).UpdateOne(l) + return NewLocationClient(l.config).UpdateOne(l) } // Unwrap unwraps the Location entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/location_delete.go b/backend/internal/data/ent/location_delete.go index 22403fe..24e0ff5 100644 --- a/backend/internal/data/ent/location_delete.go +++ b/backend/internal/data/ent/location_delete.go @@ -69,6 +69,12 @@ type LocationDeleteOne struct { ld *LocationDelete } +// Where appends a list predicates to the LocationDelete builder. +func (ldo *LocationDeleteOne) Where(ps ...predicate.Location) *LocationDeleteOne { + ldo.ld.mutation.Where(ps...) + return ldo +} + // Exec executes the deletion query. func (ldo *LocationDeleteOne) Exec(ctx context.Context) error { n, err := ldo.ld.Exec(ctx) @@ -84,5 +90,7 @@ func (ldo *LocationDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (ldo *LocationDeleteOne) ExecX(ctx context.Context) { - ldo.ld.ExecX(ctx) + if err := ldo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/location_query.go b/backend/internal/data/ent/location_query.go index 992644d..5b8647d 100644 --- a/backend/internal/data/ent/location_query.go +++ b/backend/internal/data/ent/location_query.go @@ -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 } diff --git a/backend/internal/data/ent/maintenanceentry.go b/backend/internal/data/ent/maintenanceentry.go index 4d0b078..c0f6a4e 100644 --- a/backend/internal/data/ent/maintenanceentry.go +++ b/backend/internal/data/ent/maintenanceentry.go @@ -142,14 +142,14 @@ func (me *MaintenanceEntry) assignValues(columns []string, values []any) error { // QueryItem queries the "item" edge of the MaintenanceEntry entity. func (me *MaintenanceEntry) QueryItem() *ItemQuery { - return (&MaintenanceEntryClient{config: me.config}).QueryItem(me) + return NewMaintenanceEntryClient(me.config).QueryItem(me) } // Update returns a builder for updating this MaintenanceEntry. // Note that you need to call MaintenanceEntry.Unwrap() before calling this method if this MaintenanceEntry // was returned from a transaction, and the transaction was committed or rolled back. func (me *MaintenanceEntry) Update() *MaintenanceEntryUpdateOne { - return (&MaintenanceEntryClient{config: me.config}).UpdateOne(me) + return NewMaintenanceEntryClient(me.config).UpdateOne(me) } // Unwrap unwraps the MaintenanceEntry entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/maintenanceentry_delete.go b/backend/internal/data/ent/maintenanceentry_delete.go index 7ee2c67..cdfe480 100644 --- a/backend/internal/data/ent/maintenanceentry_delete.go +++ b/backend/internal/data/ent/maintenanceentry_delete.go @@ -69,6 +69,12 @@ type MaintenanceEntryDeleteOne struct { med *MaintenanceEntryDelete } +// Where appends a list predicates to the MaintenanceEntryDelete builder. +func (medo *MaintenanceEntryDeleteOne) Where(ps ...predicate.MaintenanceEntry) *MaintenanceEntryDeleteOne { + medo.med.mutation.Where(ps...) + return medo +} + // Exec executes the deletion query. func (medo *MaintenanceEntryDeleteOne) Exec(ctx context.Context) error { n, err := medo.med.Exec(ctx) @@ -84,5 +90,7 @@ func (medo *MaintenanceEntryDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (medo *MaintenanceEntryDeleteOne) ExecX(ctx context.Context) { - medo.med.ExecX(ctx) + if err := medo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/maintenanceentry_query.go b/backend/internal/data/ent/maintenanceentry_query.go index b394869..114f8d9 100644 --- a/backend/internal/data/ent/maintenanceentry_query.go +++ b/backend/internal/data/ent/maintenanceentry_query.go @@ -19,11 +19,8 @@ import ( // MaintenanceEntryQuery is the builder for querying MaintenanceEntry entities. type MaintenanceEntryQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.MaintenanceEntry withItem *ItemQuery @@ -40,20 +37,20 @@ func (meq *MaintenanceEntryQuery) Where(ps ...predicate.MaintenanceEntry) *Maint // Limit the number of records to be returned by this query. func (meq *MaintenanceEntryQuery) Limit(limit int) *MaintenanceEntryQuery { - meq.limit = &limit + meq.ctx.Limit = &limit return meq } // Offset to start from. func (meq *MaintenanceEntryQuery) Offset(offset int) *MaintenanceEntryQuery { - meq.offset = &offset + meq.ctx.Offset = &offset return meq } // 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 (meq *MaintenanceEntryQuery) Unique(unique bool) *MaintenanceEntryQuery { - meq.unique = &unique + meq.ctx.Unique = &unique return meq } @@ -88,7 +85,7 @@ func (meq *MaintenanceEntryQuery) QueryItem() *ItemQuery { // First returns the first MaintenanceEntry entity from the query. // Returns a *NotFoundError when no MaintenanceEntry was found. func (meq *MaintenanceEntryQuery) First(ctx context.Context) (*MaintenanceEntry, error) { - nodes, err := meq.Limit(1).All(newQueryContext(ctx, TypeMaintenanceEntry, "First")) + nodes, err := meq.Limit(1).All(setContextOp(ctx, meq.ctx, "First")) if err != nil { return nil, err } @@ -111,7 +108,7 @@ func (meq *MaintenanceEntryQuery) FirstX(ctx context.Context) *MaintenanceEntry // Returns a *NotFoundError when no MaintenanceEntry ID was found. func (meq *MaintenanceEntryQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = meq.Limit(1).IDs(newQueryContext(ctx, TypeMaintenanceEntry, "FirstID")); err != nil { + if ids, err = meq.Limit(1).IDs(setContextOp(ctx, meq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -134,7 +131,7 @@ func (meq *MaintenanceEntryQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one MaintenanceEntry entity is found. // Returns a *NotFoundError when no MaintenanceEntry entities are found. func (meq *MaintenanceEntryQuery) Only(ctx context.Context) (*MaintenanceEntry, error) { - nodes, err := meq.Limit(2).All(newQueryContext(ctx, TypeMaintenanceEntry, "Only")) + nodes, err := meq.Limit(2).All(setContextOp(ctx, meq.ctx, "Only")) if err != nil { return nil, err } @@ -162,7 +159,7 @@ func (meq *MaintenanceEntryQuery) OnlyX(ctx context.Context) *MaintenanceEntry { // Returns a *NotFoundError when no entities are found. func (meq *MaintenanceEntryQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = meq.Limit(2).IDs(newQueryContext(ctx, TypeMaintenanceEntry, "OnlyID")); err != nil { + if ids, err = meq.Limit(2).IDs(setContextOp(ctx, meq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -187,7 +184,7 @@ func (meq *MaintenanceEntryQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of MaintenanceEntries. func (meq *MaintenanceEntryQuery) All(ctx context.Context) ([]*MaintenanceEntry, error) { - ctx = newQueryContext(ctx, TypeMaintenanceEntry, "All") + ctx = setContextOp(ctx, meq.ctx, "All") if err := meq.prepareQuery(ctx); err != nil { return nil, err } @@ -207,7 +204,7 @@ func (meq *MaintenanceEntryQuery) AllX(ctx context.Context) []*MaintenanceEntry // IDs executes the query and returns a list of MaintenanceEntry IDs. func (meq *MaintenanceEntryQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { var ids []uuid.UUID - ctx = newQueryContext(ctx, TypeMaintenanceEntry, "IDs") + ctx = setContextOp(ctx, meq.ctx, "IDs") if err := meq.Select(maintenanceentry.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -225,7 +222,7 @@ func (meq *MaintenanceEntryQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (meq *MaintenanceEntryQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeMaintenanceEntry, "Count") + ctx = setContextOp(ctx, meq.ctx, "Count") if err := meq.prepareQuery(ctx); err != nil { return 0, err } @@ -243,7 +240,7 @@ func (meq *MaintenanceEntryQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (meq *MaintenanceEntryQuery) Exist(ctx context.Context) (bool, error) { - ctx = newQueryContext(ctx, TypeMaintenanceEntry, "Exist") + ctx = setContextOp(ctx, meq.ctx, "Exist") switch _, err := meq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -271,16 +268,14 @@ func (meq *MaintenanceEntryQuery) Clone() *MaintenanceEntryQuery { } return &MaintenanceEntryQuery{ config: meq.config, - limit: meq.limit, - offset: meq.offset, + ctx: meq.ctx.Clone(), order: append([]OrderFunc{}, meq.order...), inters: append([]Interceptor{}, meq.inters...), predicates: append([]predicate.MaintenanceEntry{}, meq.predicates...), withItem: meq.withItem.Clone(), // clone intermediate query. - sql: meq.sql.Clone(), - path: meq.path, - unique: meq.unique, + sql: meq.sql.Clone(), + path: meq.path, } } @@ -310,9 +305,9 @@ func (meq *MaintenanceEntryQuery) WithItem(opts ...func(*ItemQuery)) *Maintenanc // Aggregate(ent.Count()). // Scan(ctx, &v) func (meq *MaintenanceEntryQuery) GroupBy(field string, fields ...string) *MaintenanceEntryGroupBy { - meq.fields = append([]string{field}, fields...) + meq.ctx.Fields = append([]string{field}, fields...) grbuild := &MaintenanceEntryGroupBy{build: meq} - grbuild.flds = &meq.fields + grbuild.flds = &meq.ctx.Fields grbuild.label = maintenanceentry.Label grbuild.scan = grbuild.Scan return grbuild @@ -331,10 +326,10 @@ func (meq *MaintenanceEntryQuery) GroupBy(field string, fields ...string) *Maint // Select(maintenanceentry.FieldCreatedAt). // Scan(ctx, &v) func (meq *MaintenanceEntryQuery) Select(fields ...string) *MaintenanceEntrySelect { - meq.fields = append(meq.fields, fields...) + meq.ctx.Fields = append(meq.ctx.Fields, fields...) sbuild := &MaintenanceEntrySelect{MaintenanceEntryQuery: meq} sbuild.label = maintenanceentry.Label - sbuild.flds, sbuild.scan = &meq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &meq.ctx.Fields, sbuild.Scan return sbuild } @@ -354,7 +349,7 @@ func (meq *MaintenanceEntryQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range meq.fields { + for _, f := range meq.ctx.Fields { if !maintenanceentry.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -414,6 +409,9 @@ func (meq *MaintenanceEntryQuery) loadItem(ctx context.Context, query *ItemQuery } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(item.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -433,9 +431,9 @@ func (meq *MaintenanceEntryQuery) loadItem(ctx context.Context, query *ItemQuery func (meq *MaintenanceEntryQuery) sqlCount(ctx context.Context) (int, error) { _spec := meq.querySpec() - _spec.Node.Columns = meq.fields - if len(meq.fields) > 0 { - _spec.Unique = meq.unique != nil && *meq.unique + _spec.Node.Columns = meq.ctx.Fields + if len(meq.ctx.Fields) > 0 { + _spec.Unique = meq.ctx.Unique != nil && *meq.ctx.Unique } return sqlgraph.CountNodes(ctx, meq.driver, _spec) } @@ -453,10 +451,10 @@ func (meq *MaintenanceEntryQuery) querySpec() *sqlgraph.QuerySpec { From: meq.sql, Unique: true, } - if unique := meq.unique; unique != nil { + if unique := meq.ctx.Unique; unique != nil { _spec.Unique = *unique } - if fields := meq.fields; len(fields) > 0 { + if fields := meq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, maintenanceentry.FieldID) for i := range fields { @@ -472,10 +470,10 @@ func (meq *MaintenanceEntryQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := meq.limit; limit != nil { + if limit := meq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := meq.offset; offset != nil { + if offset := meq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := meq.order; len(ps) > 0 { @@ -491,7 +489,7 @@ func (meq *MaintenanceEntryQuery) querySpec() *sqlgraph.QuerySpec { func (meq *MaintenanceEntryQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(meq.driver.Dialect()) t1 := builder.Table(maintenanceentry.Table) - columns := meq.fields + columns := meq.ctx.Fields if len(columns) == 0 { columns = maintenanceentry.Columns } @@ -500,7 +498,7 @@ func (meq *MaintenanceEntryQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = meq.sql selector.Select(selector.Columns(columns...)...) } - if meq.unique != nil && *meq.unique { + if meq.ctx.Unique != nil && *meq.ctx.Unique { selector.Distinct() } for _, p := range meq.predicates { @@ -509,12 +507,12 @@ func (meq *MaintenanceEntryQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range meq.order { p(selector) } - if offset := meq.offset; offset != nil { + if offset := meq.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 := meq.limit; limit != nil { + if limit := meq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -534,7 +532,7 @@ func (megb *MaintenanceEntryGroupBy) Aggregate(fns ...AggregateFunc) *Maintenanc // Scan applies the selector query and scans the result into the given value. func (megb *MaintenanceEntryGroupBy) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeMaintenanceEntry, "GroupBy") + ctx = setContextOp(ctx, megb.build.ctx, "GroupBy") if err := megb.build.prepareQuery(ctx); err != nil { return err } @@ -582,7 +580,7 @@ func (mes *MaintenanceEntrySelect) Aggregate(fns ...AggregateFunc) *MaintenanceE // Scan applies the selector query and scans the result into the given value. func (mes *MaintenanceEntrySelect) Scan(ctx context.Context, v any) error { - ctx = newQueryContext(ctx, TypeMaintenanceEntry, "Select") + ctx = setContextOp(ctx, mes.ctx, "Select") if err := mes.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/runtime/runtime.go b/backend/internal/data/ent/runtime/runtime.go index 82fdada..84a815f 100644 --- a/backend/internal/data/ent/runtime/runtime.go +++ b/backend/internal/data/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in github.com/hay-kot/homebox/backend/internal/data/ent/runtime.go const ( - Version = "v0.11.5" // Version of ent codegen. - Sum = "h1:V2qhG91C4PMQTa82Q4StoESMQ4dzkMNeStCzszxi0jQ=" // Sum of ent codegen. + Version = "v0.11.7" // Version of ent codegen. + Sum = "h1:V+wKFh0jhAbY/FoU+PPbdMOf2Ma5vh07R/IdF+N/nFg=" // Sum of ent codegen. ) diff --git a/backend/internal/data/ent/user.go b/backend/internal/data/ent/user.go index 48dbdcb..cd4709b 100644 --- a/backend/internal/data/ent/user.go +++ b/backend/internal/data/ent/user.go @@ -179,19 +179,19 @@ func (u *User) assignValues(columns []string, values []any) error { // QueryGroup queries the "group" edge of the User entity. func (u *User) QueryGroup() *GroupQuery { - return (&UserClient{config: u.config}).QueryGroup(u) + return NewUserClient(u.config).QueryGroup(u) } // QueryAuthTokens queries the "auth_tokens" edge of the User entity. func (u *User) QueryAuthTokens() *AuthTokensQuery { - return (&UserClient{config: u.config}).QueryAuthTokens(u) + return NewUserClient(u.config).QueryAuthTokens(u) } // 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 { - return (&UserClient{config: u.config}).UpdateOne(u) + return NewUserClient(u.config).UpdateOne(u) } // Unwrap unwraps the User entity that was returned from a transaction after it was closed, diff --git a/backend/internal/data/ent/user_delete.go b/backend/internal/data/ent/user_delete.go index e54e3de..0f2d066 100644 --- a/backend/internal/data/ent/user_delete.go +++ b/backend/internal/data/ent/user_delete.go @@ -69,6 +69,12 @@ type UserDeleteOne struct { ud *UserDelete } +// Where appends a list predicates to the UserDelete builder. +func (udo *UserDeleteOne) Where(ps ...predicate.User) *UserDeleteOne { + udo.ud.mutation.Where(ps...) + return udo +} + // Exec executes the deletion query. func (udo *UserDeleteOne) Exec(ctx context.Context) error { n, err := udo.ud.Exec(ctx) @@ -84,5 +90,7 @@ func (udo *UserDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (udo *UserDeleteOne) ExecX(ctx context.Context) { - udo.ud.ExecX(ctx) + if err := udo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/backend/internal/data/ent/user_query.go b/backend/internal/data/ent/user_query.go index 75b8ad4..151b5cb 100644 --- a/backend/internal/data/ent/user_query.go +++ b/backend/internal/data/ent/user_query.go @@ -21,11 +21,8 @@ import ( // UserQuery is the builder for querying User entities. type UserQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string inters []Interceptor predicates []predicate.User withGroup *GroupQuery @@ -44,20 +41,20 @@ func (uq *UserQuery) Where(ps ...predicate.User) *UserQuery { // Limit the number of records to be returned by this query. func (uq *UserQuery) Limit(limit int) *UserQuery { - uq.limit = &limit + uq.ctx.Limit = &limit return uq } // Offset to start from. func (uq *UserQuery) Offset(offset int) *UserQuery { - uq.offset = &offset + uq.ctx.Offset = &offset return uq } // 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 (uq *UserQuery) Unique(unique bool) *UserQuery { - uq.unique = &unique + uq.ctx.Unique = &unique return uq } @@ -114,7 +111,7 @@ func (uq *UserQuery) QueryAuthTokens() *AuthTokensQuery { // 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(newQueryContext(ctx, TypeUser, "First")) + nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, "First")) if err != nil { return nil, err } @@ -137,7 +134,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 uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = uq.Limit(1).IDs(newQueryContext(ctx, TypeUser, "FirstID")); err != nil { + if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -160,7 +157,7 @@ func (uq *UserQuery) FirstIDX(ctx context.Context) uuid.UUID { // 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(newQueryContext(ctx, TypeUser, "Only")) + nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, "Only")) if err != nil { return nil, err } @@ -188,7 +185,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 uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = uq.Limit(2).IDs(newQueryContext(ctx, TypeUser, "OnlyID")); err != nil { + if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -213,7 +210,7 @@ func (uq *UserQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Users. func (uq *UserQuery) All(ctx context.Context) ([]*User, error) { - ctx = newQueryContext(ctx, TypeUser, "All") + ctx = setContextOp(ctx, uq.ctx, "All") if err := uq.prepareQuery(ctx); err != nil { return nil, err } @@ -233,7 +230,7 @@ func (uq *UserQuery) AllX(ctx context.Context) []*User { // IDs executes the query and returns a list of User IDs. func (uq *UserQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { var ids []uuid.UUID - ctx = newQueryContext(ctx, TypeUser, "IDs") + ctx = setContextOp(ctx, uq.ctx, "IDs") if err := uq.Select(user.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -251,7 +248,7 @@ func (uq *UserQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (uq *UserQuery) Count(ctx context.Context) (int, error) { - ctx = newQueryContext(ctx, TypeUser, "Count") + ctx = setContextOp(ctx, uq.ctx, "Count") if err := uq.prepareQuery(ctx); err != nil { return 0, err } @@ -269,7 +266,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 = newQueryContext(ctx, TypeUser, "Exist") + ctx = setContextOp(ctx, uq.ctx, "Exist") switch _, err := uq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -297,17 +294,15 @@ func (uq *UserQuery) Clone() *UserQuery { } return &UserQuery{ config: uq.config, - limit: uq.limit, - offset: uq.offset, + ctx: uq.ctx.Clone(), order: append([]OrderFunc{}, uq.order...), inters: append([]Interceptor{}, uq.inters...), predicates: append([]predicate.User{}, uq.predicates...), withGroup: uq.withGroup.Clone(), withAuthTokens: uq.withAuthTokens.Clone(), // clone intermediate query. - sql: uq.sql.Clone(), - path: uq.path, - unique: uq.unique, + sql: uq.sql.Clone(), + path: uq.path, } } @@ -348,9 +343,9 @@ func (uq *UserQuery) WithAuthTokens(opts ...func(*AuthTokensQuery)) *UserQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { - uq.fields = append([]string{field}, fields...) + uq.ctx.Fields = append([]string{field}, fields...) grbuild := &UserGroupBy{build: uq} - grbuild.flds = &uq.fields + grbuild.flds = &uq.ctx.Fields grbuild.label = user.Label grbuild.scan = grbuild.Scan return grbuild @@ -369,10 +364,10 @@ func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { // Select(user.FieldCreatedAt). // Scan(ctx, &v) func (uq *UserQuery) Select(fields ...string) *UserSelect { - uq.fields = append(uq.fields, fields...) + uq.ctx.Fields = append(uq.ctx.Fields, fields...) sbuild := &UserSelect{UserQuery: uq} sbuild.label = user.Label - sbuild.flds, sbuild.scan = &uq.fields, sbuild.Scan + sbuild.flds, sbuild.scan = &uq.ctx.Fields, sbuild.Scan return sbuild } @@ -392,7 +387,7 @@ func (uq *UserQuery) prepareQuery(ctx context.Context) error { } } } - for _, f := range uq.fields { + for _, f := range uq.ctx.Fields { if !user.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -470,6 +465,9 @@ func (uq *UserQuery) 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 { @@ -520,9 +518,9 @@ func (uq *UserQuery) loadAuthTokens(ctx context.Context, query *AuthTokensQuery, func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) { _spec := uq.querySpec() - _spec.Node.Columns = uq.fields - if len(uq.fields) > 0 { - _spec.Unique = uq.unique != nil && *uq.unique + _spec.Node.Columns = uq.ctx.Fields + if len(uq.ctx.Fields) > 0 { + _spec.Unique = uq.ctx.Unique != nil && *uq.ctx.Unique } return sqlgraph.CountNodes(ctx, uq.driver, _spec) } @@ -540,10 +538,10 @@ func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec { From: uq.sql, Unique: true, } - if unique := uq.unique; unique != nil { + if unique := uq.ctx.Unique; unique != nil { _spec.Unique = *unique } - if fields := uq.fields; len(fields) > 0 { + if fields := uq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, user.FieldID) for i := range fields { @@ -559,10 +557,10 @@ func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := uq.limit; limit != nil { + if limit := uq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := uq.offset; offset != nil { + if offset := uq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := uq.order; len(ps) > 0 { @@ -578,7 +576,7 @@ func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec { func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(uq.driver.Dialect()) t1 := builder.Table(user.Table) - columns := uq.fields + columns := uq.ctx.Fields if len(columns) == 0 { columns = user.Columns } @@ -587,7 +585,7 @@ func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = uq.sql selector.Select(selector.Columns(columns...)...) } - if uq.unique != nil && *uq.unique { + if uq.ctx.Unique != nil && *uq.ctx.Unique { selector.Distinct() } for _, p := range uq.predicates { @@ -596,12 +594,12 @@ func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range uq.order { p(selector) } - if offset := uq.offset; offset != nil { + if offset := uq.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 := uq.limit; limit != nil { + if limit := uq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -621,7 +619,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 = newQueryContext(ctx, TypeUser, "GroupBy") + ctx = setContextOp(ctx, ugb.build.ctx, "GroupBy") if err := ugb.build.prepareQuery(ctx); err != nil { return err } @@ -669,7 +667,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 = newQueryContext(ctx, TypeUser, "Select") + ctx = setContextOp(ctx, us.ctx, "Select") if err := us.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/sys/config/conf.go b/backend/internal/sys/config/conf.go index 5f212eb..a7a17f0 100644 --- a/backend/internal/sys/config/conf.go +++ b/backend/internal/sys/config/conf.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/ardanlabs/conf/v2" + "github.com/ardanlabs/conf/v3" "os" )