diff --git a/backend/app/api/handlers/v1/assets/QRIcon.png b/backend/app/api/handlers/v1/assets/QRIcon.png new file mode 100644 index 0000000..016ceaf Binary files /dev/null and b/backend/app/api/handlers/v1/assets/QRIcon.png differ diff --git a/backend/app/api/handlers/v1/v1_ctrl_qrcode.go b/backend/app/api/handlers/v1/v1_ctrl_qrcode.go new file mode 100644 index 0000000..5055274 --- /dev/null +++ b/backend/app/api/handlers/v1/v1_ctrl_qrcode.go @@ -0,0 +1,67 @@ +package v1 + +import ( + "bytes" + "image/png" + "io" + "net/http" + + "github.com/hay-kot/homebox/backend/internal/sys/validate" + "github.com/hay-kot/homebox/backend/pkgs/server" + "github.com/yeqown/go-qrcode/v2" + "github.com/yeqown/go-qrcode/writer/standard" + + _ "embed" +) + +//go:embed assets/QRIcon.png +var qrcodeLogo []byte + +// HandleGenerateQRCode godoc +// +// @Summary Encode data into QRCode +// @Tags Items +// @Produce json +// @Param data query string false "data to be encoded into qrcode" +// @Success 200 {string} string "image/jpeg" +// @Router /v1/qrcode [GET] +// @Security Bearer +func (ctrl *V1Controller) HandleGenerateQRCode() server.HandlerFunc { + const MaxLength = 4_296 // assume alphanumeric characters only + + return func(w http.ResponseWriter, r *http.Request) error { + data := r.URL.Query().Get("data") + + image, err := png.Decode(bytes.NewReader(qrcodeLogo)) + if err != nil { + panic(err) + } + + if len(data) > MaxLength { + return validate.NewFieldErrors(validate.FieldError{ + Field: "data", + Error: "max length is 4,296 characters exceeded", + }) + } + + qrc, err := qrcode.New(data) + if err != nil { + return err + } + + toWriteCloser := struct { + io.Writer + io.Closer + }{ + Writer: w, + Closer: io.NopCloser(nil), + } + + qrwriter := standard.NewWithWriter(toWriteCloser, standard.WithLogoImage(image)) + + // Return the QR code as a jpeg image + w.Header().Set("Content-Type", "image/jpeg") + w.Header().Set("Content-Disposition", "attachment; filename=qrcode.jpg") + return qrc.Save(qrwriter) + } +} diff --git a/backend/app/api/routes.go b/backend/app/api/routes.go index 9c71d0f..b5ae495 100644 --- a/backend/app/api/routes.go +++ b/backend/app/api/routes.go @@ -119,6 +119,12 @@ func (a *app) mountRoutes(repos *repo.AllRepos) { a.server.Get(v1Base("/asset/{id}"), v1Ctrl.HandleAssetGet(), userMW...) + // Asset-Like endpoints + a.server.Get( + v1Base("/qrcode"), + v1Ctrl.HandleGenerateQRCode(), + a.mwAuthToken, a.mwRoles(RoleModeOr, authroles.RoleUser.String(), authroles.RoleAttachments.String()), + ) a.server.Get( v1Base("/items/{id}/attachments/{attachment_id}"), v1Ctrl.HandleItemAttachmentGet(), diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index 466f3f5..4aa7410 100644 --- a/backend/app/api/static/docs/docs.go +++ b/backend/app/api/static/docs/docs.go @@ -1146,6 +1146,38 @@ const docTemplate = `{ } } }, + "/v1/qrcode": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Encode data into QRCode", + "parameters": [ + { + "type": "string", + "description": "data to be encoded into qrcode", + "name": "data", + "in": "query" + } + ], + "responses": { + "200": { + "description": "image/jpeg", + "schema": { + "type": "string" + } + } + } + } + }, "/v1/status": { "get": { "produces": [ diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index 2693a8b..6e2c0cf 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -1138,6 +1138,38 @@ } } }, + "/v1/qrcode": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Encode data into QRCode", + "parameters": [ + { + "type": "string", + "description": "data to be encoded into qrcode", + "name": "data", + "in": "query" + } + ], + "responses": { + "200": { + "description": "image/jpeg", + "schema": { + "type": "string" + } + } + } + } + }, "/v1/status": { "get": { "produces": [ diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index 7be39e2..a6ef340 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -1301,6 +1301,25 @@ paths: summary: updates a location tags: - Locations + /v1/qrcode: + get: + parameters: + - description: data to be encoded into qrcode + in: query + name: data + type: string + produces: + - application/json + responses: + "200": + description: image/jpeg + schema: + type: string + security: + - Bearer: [] + summary: Encode data into QRCode + tags: + - Items /v1/status: get: produces: diff --git a/backend/go.mod b/backend/go.mod index 648f326..4030e48 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -14,6 +14,8 @@ require ( github.com/stretchr/testify v1.8.1 github.com/swaggo/http-swagger v1.3.3 github.com/swaggo/swag v1.8.9 + github.com/yeqown/go-qrcode/v2 v2.2.1 + github.com/yeqown/go-qrcode/writer/standard v1.2.1 golang.org/x/crypto v0.5.0 ) @@ -22,6 +24,7 @@ require ( github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fogleman/gg v1.3.0 // indirect github.com/go-openapi/inflect v0.19.0 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect @@ -29,6 +32,7 @@ require ( github.com/go-openapi/swag v0.22.3 // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/hashicorp/hcl/v2 v2.15.0 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -37,9 +41,12 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/swaggo/files v1.0.0 // indirect + github.com/yeqown/reedsolomon v1.0.0 // indirect github.com/zclconf/go-cty v1.12.1 // indirect + golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 // indirect golang.org/x/mod v0.7.0 // indirect golang.org/x/net v0.5.0 // indirect golang.org/x/sys v0.4.0 // indirect diff --git a/backend/go.sum b/backend/go.sum index a797887..c3313f6 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,11 +1,5 @@ -ariga.io/atlas v0.8.3 h1:nddOywkhr/62Cwa+UsGgO35lAhUYh52XGVsbFwGzWZM= -ariga.io/atlas v0.8.3/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU= -ariga.io/atlas v0.8.4-0.20221212165942-e53dd27a603d h1:eAmX+el+OOTP5Y3ep9kmdj7Db6+0aHbT0LIYyPtcboU= -ariga.io/atlas v0.8.4-0.20221212165942-e53dd27a603d/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU= ariga.io/atlas v0.9.0 h1:q0JMtqyA3X1YWtPcn+E/kVPwLDslb+jAC8Ejl/vW6d0= ariga.io/atlas v0.9.0/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU= -entgo.io/ent v0.11.4 h1:grwVY0fp31BZ6oEo3YrXenAuv8VJmEw7F/Bi6WqeH3Q= -entgo.io/ent v0.11.4/go.mod h1:fnQIXL36RYnCk/9nvG4aE7YHBFZhCycfh7wMjY5p7SE= entgo.io/ent v0.11.5 h1:V2qhG91C4PMQTa82Q4StoESMQ4dzkMNeStCzszxi0jQ= entgo.io/ent v0.11.5/go.mod h1:u7eKwNWAo/VlHIKxgwbmsFy3J7cKDxwi3jyF5TW/okY= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= @@ -22,6 +16,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= +github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= @@ -47,6 +43,8 @@ github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJ github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -79,12 +77,15 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -95,6 +96,8 @@ 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/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -111,6 +114,12 @@ github.com/swaggo/http-swagger v1.3.3 h1:Hu5Z0L9ssyBLofaama21iYaF2VbWyA8jdohaaCG 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/yeqown/go-qrcode/v2 v2.2.1 h1:Jc1Q916fwC05R8C7mpWDbrT9tyLPaLLKDABoC5XBCe8= +github.com/yeqown/go-qrcode/v2 v2.2.1/go.mod h1:2Qsk2APUCPne0TsRo40DIkI5MYnbzYKCnKGEFWrxd24= +github.com/yeqown/go-qrcode/writer/standard v1.2.1 h1:FMRZiur5yApUIe4fqtqmcdl/XQTZAZWt2DhkPx4VIW0= +github.com/yeqown/go-qrcode/writer/standard v1.2.1/go.mod h1:ZelyDFiVymrauRjUn454iF7bjsabmB1vixkDA5kq2bw= +github.com/yeqown/reedsolomon v1.0.0 h1:x1h/Ej/uJnNu8jaX7GLHBWmZKCAWjEJTetkqaabr4B0= +github.com/yeqown/reedsolomon v1.0.0/go.mod h1:P76zpcn2TCuL0ul1Fso373qHRc69LKwAw/Iy6g1WiiM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.12.1 h1:PcupnljUm9EIvbgSHQnHhUr3fO6oFmkOrvs2BAFNXXY= github.com/zclconf/go-cty v1.12.1/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA= @@ -119,6 +128,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= +golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM= +golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= diff --git a/backend/internal/data/ent/attachment/where.go b/backend/internal/data/ent/attachment/where.go index e2adb4f..dd1981f 100644 --- a/backend/internal/data/ent/attachment/where.go +++ b/backend/internal/data/ent/attachment/where.go @@ -13,251 +13,157 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Attachment(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Attachment(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Attachment(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.Attachment(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.Attachment(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Attachment(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Attachment(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Attachment(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Attachment(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Attachment(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Attachment(sql.FieldEQ(FieldUpdatedAt, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Attachment(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Attachment(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.Attachment { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.Attachment(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.Attachment { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.Attachment(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.Attachment(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Attachment(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.Attachment(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Attachment(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Attachment(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Attachment(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.Attachment { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Attachment(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.Attachment { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Attachment(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Attachment(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Attachment(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Attachment(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Attachment(sql.FieldLTE(FieldUpdatedAt, v)) } // TypeEQ applies the EQ predicate on the "type" field. func TypeEQ(v Type) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldType), v)) - }) + return predicate.Attachment(sql.FieldEQ(FieldType, v)) } // TypeNEQ applies the NEQ predicate on the "type" field. func TypeNEQ(v Type) predicate.Attachment { - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldType), v)) - }) + return predicate.Attachment(sql.FieldNEQ(FieldType, v)) } // TypeIn applies the In predicate on the "type" field. func TypeIn(vs ...Type) predicate.Attachment { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldType), v...)) - }) + return predicate.Attachment(sql.FieldIn(FieldType, vs...)) } // TypeNotIn applies the NotIn predicate on the "type" field. func TypeNotIn(vs ...Type) predicate.Attachment { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Attachment(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldType), v...)) - }) + return predicate.Attachment(sql.FieldNotIn(FieldType, vs...)) } // HasItem applies the HasEdge predicate on the "item" edge. @@ -265,7 +171,6 @@ func HasItem() predicate.Attachment { return predicate.Attachment(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ItemTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, ItemTable, ItemColumn), ) sqlgraph.HasNeighbors(s, step) @@ -293,7 +198,6 @@ func HasDocument() predicate.Attachment { return predicate.Attachment(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(DocumentTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, DocumentTable, DocumentColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/attachment_create.go b/backend/internal/data/ent/attachment_create.go index c5121c5..2be195e 100644 --- a/backend/internal/data/ent/attachment_create.go +++ b/backend/internal/data/ent/attachment_create.go @@ -108,50 +108,8 @@ func (ac *AttachmentCreate) Mutation() *AttachmentMutation { // Save creates the Attachment in the database. func (ac *AttachmentCreate) Save(ctx context.Context) (*Attachment, error) { - var ( - err error - node *Attachment - ) ac.defaults() - if len(ac.hooks) == 0 { - if err = ac.check(); err != nil { - return nil, err - } - node, err = ac.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AttachmentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = ac.check(); err != nil { - return nil, err - } - ac.mutation = mutation - if node, err = ac.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(ac.hooks) - 1; i >= 0; i-- { - if ac.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ac.hooks[i](mut) - } - v, err := mut.Mutate(ctx, ac.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Attachment) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from AttachmentMutation", v) - } - node = nv - } - return node, err + return withHooks[*Attachment, AttachmentMutation](ctx, ac.sqlSave, ac.mutation, ac.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -222,6 +180,9 @@ func (ac *AttachmentCreate) check() error { } func (ac *AttachmentCreate) sqlSave(ctx context.Context) (*Attachment, error) { + if err := ac.check(); err != nil { + return nil, err + } _node, _spec := ac.createSpec() if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -236,6 +197,8 @@ func (ac *AttachmentCreate) sqlSave(ctx context.Context) (*Attachment, error) { return nil, err } } + ac.mutation.id = &_node.ID + ac.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/attachment_delete.go b/backend/internal/data/ent/attachment_delete.go index eeeca20..a018a8e 100644 --- a/backend/internal/data/ent/attachment_delete.go +++ b/backend/internal/data/ent/attachment_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (ad *AttachmentDelete) Where(ps ...predicate.Attachment) *AttachmentDelete // Exec executes the deletion query and returns how many vertices were deleted. func (ad *AttachmentDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ad.hooks) == 0 { - affected, err = ad.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AttachmentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ad.mutation = mutation - affected, err = ad.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ad.hooks) - 1; i >= 0; i-- { - if ad.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ad.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ad.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, AttachmentMutation](ctx, ad.sqlExec, ad.mutation, ad.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (ad *AttachmentDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + ad.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/attachment_query.go b/backend/internal/data/ent/attachment_query.go index ab64646..2e250c2 100644 --- a/backend/internal/data/ent/attachment_query.go +++ b/backend/internal/data/ent/attachment_query.go @@ -25,6 +25,7 @@ type AttachmentQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.Attachment withItem *ItemQuery withDocument *DocumentQuery @@ -40,13 +41,13 @@ func (aq *AttachmentQuery) Where(ps ...predicate.Attachment) *AttachmentQuery { return aq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (aq *AttachmentQuery) Limit(limit int) *AttachmentQuery { aq.limit = &limit return aq } -// Offset adds an offset step to the query. +// Offset to start from. func (aq *AttachmentQuery) Offset(offset int) *AttachmentQuery { aq.offset = &offset return aq @@ -59,7 +60,7 @@ func (aq *AttachmentQuery) Unique(unique bool) *AttachmentQuery { return aq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (aq *AttachmentQuery) Order(o ...OrderFunc) *AttachmentQuery { aq.order = append(aq.order, o...) return aq @@ -67,7 +68,7 @@ func (aq *AttachmentQuery) Order(o ...OrderFunc) *AttachmentQuery { // QueryItem chains the current query on the "item" edge. func (aq *AttachmentQuery) QueryItem() *ItemQuery { - query := &ItemQuery{config: aq.config} + query := (&ItemClient{config: aq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := aq.prepareQuery(ctx); err != nil { return nil, err @@ -89,7 +90,7 @@ func (aq *AttachmentQuery) QueryItem() *ItemQuery { // QueryDocument chains the current query on the "document" edge. func (aq *AttachmentQuery) QueryDocument() *DocumentQuery { - query := &DocumentQuery{config: aq.config} + query := (&DocumentClient{config: aq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := aq.prepareQuery(ctx); err != nil { return nil, err @@ -112,7 +113,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(ctx) + nodes, err := aq.Limit(1).All(newQueryContext(ctx, TypeAttachment, "First")) if err != nil { return nil, err } @@ -135,7 +136,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(ctx); err != nil { + if ids, err = aq.Limit(1).IDs(newQueryContext(ctx, TypeAttachment, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -158,7 +159,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(ctx) + nodes, err := aq.Limit(2).All(newQueryContext(ctx, TypeAttachment, "Only")) if err != nil { return nil, err } @@ -186,7 +187,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(ctx); err != nil { + if ids, err = aq.Limit(2).IDs(newQueryContext(ctx, TypeAttachment, "OnlyID")); err != nil { return } switch len(ids) { @@ -211,10 +212,12 @@ 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") if err := aq.prepareQuery(ctx); err != nil { return nil, err } - return aq.sqlAll(ctx) + qr := querierAll[[]*Attachment, *AttachmentQuery]() + return withInterceptors[[]*Attachment](ctx, aq, qr, aq.inters) } // AllX is like All, but panics if an error occurs. @@ -229,6 +232,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") if err := aq.Select(attachment.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -246,10 +250,11 @@ 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") if err := aq.prepareQuery(ctx); err != nil { return 0, err } - return aq.sqlCount(ctx) + return withInterceptors[int](ctx, aq, querierCount[*AttachmentQuery](), aq.inters) } // CountX is like Count, but panics if an error occurs. @@ -263,10 +268,15 @@ 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) { - if err := aq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeAttachment, "Exist") + switch _, err := aq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return aq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -289,6 +299,7 @@ func (aq *AttachmentQuery) Clone() *AttachmentQuery { limit: aq.limit, offset: aq.offset, order: append([]OrderFunc{}, aq.order...), + inters: append([]Interceptor{}, aq.inters...), predicates: append([]predicate.Attachment{}, aq.predicates...), withItem: aq.withItem.Clone(), withDocument: aq.withDocument.Clone(), @@ -302,7 +313,7 @@ func (aq *AttachmentQuery) Clone() *AttachmentQuery { // WithItem tells the query-builder to eager-load the nodes that are connected to // the "item" edge. The optional arguments are used to configure the query builder of the edge. func (aq *AttachmentQuery) WithItem(opts ...func(*ItemQuery)) *AttachmentQuery { - query := &ItemQuery{config: aq.config} + query := (&ItemClient{config: aq.config}).Query() for _, opt := range opts { opt(query) } @@ -313,7 +324,7 @@ func (aq *AttachmentQuery) WithItem(opts ...func(*ItemQuery)) *AttachmentQuery { // WithDocument tells the query-builder to eager-load the nodes that are connected to // the "document" edge. The optional arguments are used to configure the query builder of the edge. func (aq *AttachmentQuery) WithDocument(opts ...func(*DocumentQuery)) *AttachmentQuery { - query := &DocumentQuery{config: aq.config} + query := (&DocumentClient{config: aq.config}).Query() for _, opt := range opts { opt(query) } @@ -336,16 +347,11 @@ func (aq *AttachmentQuery) WithDocument(opts ...func(*DocumentQuery)) *Attachmen // Aggregate(ent.Count()). // Scan(ctx, &v) func (aq *AttachmentQuery) GroupBy(field string, fields ...string) *AttachmentGroupBy { - grbuild := &AttachmentGroupBy{config: aq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := aq.prepareQuery(ctx); err != nil { - return nil, err - } - return aq.sqlQuery(ctx), nil - } + aq.fields = append([]string{field}, fields...) + grbuild := &AttachmentGroupBy{build: aq} + grbuild.flds = &aq.fields grbuild.label = attachment.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -363,10 +369,10 @@ func (aq *AttachmentQuery) GroupBy(field string, fields ...string) *AttachmentGr // Scan(ctx, &v) func (aq *AttachmentQuery) Select(fields ...string) *AttachmentSelect { aq.fields = append(aq.fields, fields...) - selbuild := &AttachmentSelect{AttachmentQuery: aq} - selbuild.label = attachment.Label - selbuild.flds, selbuild.scan = &aq.fields, selbuild.Scan - return selbuild + sbuild := &AttachmentSelect{AttachmentQuery: aq} + sbuild.label = attachment.Label + sbuild.flds, sbuild.scan = &aq.fields, sbuild.Scan + return sbuild } // Aggregate returns a AttachmentSelect configured with the given aggregations. @@ -375,6 +381,16 @@ func (aq *AttachmentQuery) Aggregate(fns ...AggregateFunc) *AttachmentSelect { } func (aq *AttachmentQuery) prepareQuery(ctx context.Context) error { + for _, inter := range aq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, aq); err != nil { + return err + } + } + } for _, f := range aq.fields { if !attachment.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -507,17 +523,6 @@ func (aq *AttachmentQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, aq.driver, _spec) } -func (aq *AttachmentQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := aq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (aq *AttachmentQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -600,13 +605,8 @@ func (aq *AttachmentQuery) sqlQuery(ctx context.Context) *sql.Selector { // AttachmentGroupBy is the group-by builder for Attachment entities. type AttachmentGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *AttachmentQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -615,58 +615,46 @@ func (agb *AttachmentGroupBy) Aggregate(fns ...AggregateFunc) *AttachmentGroupBy return agb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (agb *AttachmentGroupBy) Scan(ctx context.Context, v any) error { - query, err := agb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeAttachment, "GroupBy") + if err := agb.build.prepareQuery(ctx); err != nil { return err } - agb.sql = query - return agb.sqlScan(ctx, v) + return scanWithInterceptors[*AttachmentQuery, *AttachmentGroupBy](ctx, agb.build, agb, agb.build.inters, v) } -func (agb *AttachmentGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range agb.fields { - if !attachment.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (agb *AttachmentGroupBy) sqlScan(ctx context.Context, root *AttachmentQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(agb.fns)) + for _, fn := range agb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := agb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*agb.flds)+len(agb.fns)) + for _, f := range *agb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*agb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := agb.driver.Query(ctx, query, args, rows); err != nil { + if err := agb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (agb *AttachmentGroupBy) sqlQuery() *sql.Selector { - selector := agb.sql.Select() - aggregation := make([]string, 0, len(agb.fns)) - for _, fn := range agb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(agb.fields)+len(agb.fns)) - for _, f := range agb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(agb.fields...)...) -} - // AttachmentSelect is the builder for selecting fields of Attachment entities. type AttachmentSelect struct { *AttachmentQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -677,26 +665,27 @@ 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") if err := as.prepareQuery(ctx); err != nil { return err } - as.sql = as.AttachmentQuery.sqlQuery(ctx) - return as.sqlScan(ctx, v) + return scanWithInterceptors[*AttachmentQuery, *AttachmentSelect](ctx, as.AttachmentQuery, as, as.inters, v) } -func (as *AttachmentSelect) sqlScan(ctx context.Context, v any) error { +func (as *AttachmentSelect) sqlScan(ctx context.Context, root *AttachmentQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(as.fns)) for _, fn := range as.fns { - aggregation = append(aggregation, fn(as.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*as.selector.flds); { case n == 0 && len(aggregation) > 0: - as.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - as.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := as.sql.Query() + query, args := selector.Query() if err := as.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/attachment_update.go b/backend/internal/data/ent/attachment_update.go index 31d5176..a54ad5a 100644 --- a/backend/internal/data/ent/attachment_update.go +++ b/backend/internal/data/ent/attachment_update.go @@ -92,41 +92,8 @@ func (au *AttachmentUpdate) ClearDocument() *AttachmentUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (au *AttachmentUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) au.defaults() - if len(au.hooks) == 0 { - if err = au.check(); err != nil { - return 0, err - } - affected, err = au.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AttachmentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = au.check(); err != nil { - return 0, err - } - au.mutation = mutation - affected, err = au.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(au.hooks) - 1; i >= 0; i-- { - if au.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = au.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, au.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, AttachmentMutation](ctx, au.sqlSave, au.mutation, au.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -176,6 +143,9 @@ func (au *AttachmentUpdate) check() error { } func (au *AttachmentUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := au.check(); err != nil { + return n, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: attachment.Table, @@ -277,6 +247,7 @@ func (au *AttachmentUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + au.mutation.done = true return n, nil } @@ -356,47 +327,8 @@ func (auo *AttachmentUpdateOne) Select(field string, fields ...string) *Attachme // Save executes the query and returns the updated Attachment entity. func (auo *AttachmentUpdateOne) Save(ctx context.Context) (*Attachment, error) { - var ( - err error - node *Attachment - ) auo.defaults() - if len(auo.hooks) == 0 { - if err = auo.check(); err != nil { - return nil, err - } - node, err = auo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AttachmentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = auo.check(); err != nil { - return nil, err - } - auo.mutation = mutation - node, err = auo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(auo.hooks) - 1; i >= 0; i-- { - if auo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = auo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, auo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Attachment) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from AttachmentMutation", v) - } - node = nv - } - return node, err + return withHooks[*Attachment, AttachmentMutation](ctx, auo.sqlSave, auo.mutation, auo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -446,6 +378,9 @@ func (auo *AttachmentUpdateOne) check() error { } func (auo *AttachmentUpdateOne) sqlSave(ctx context.Context) (_node *Attachment, err error) { + if err := auo.check(); err != nil { + return _node, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: attachment.Table, @@ -567,5 +502,6 @@ func (auo *AttachmentUpdateOne) sqlSave(ctx context.Context) (_node *Attachment, } return nil, err } + auo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/authroles/where.go b/backend/internal/data/ent/authroles/where.go index b3344ec..53978b0 100644 --- a/backend/internal/data/ent/authroles/where.go +++ b/backend/internal/data/ent/authroles/where.go @@ -10,109 +10,67 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.AuthRoles(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.AuthRoles(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.AuthRoles(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.AuthRoles(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.AuthRoles(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.AuthRoles(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.AuthRoles(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.AuthRoles(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.AuthRoles(sql.FieldLTE(FieldID, id)) } // RoleEQ applies the EQ predicate on the "role" field. func RoleEQ(v Role) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRole), v)) - }) + return predicate.AuthRoles(sql.FieldEQ(FieldRole, v)) } // RoleNEQ applies the NEQ predicate on the "role" field. func RoleNEQ(v Role) predicate.AuthRoles { - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldRole), v)) - }) + return predicate.AuthRoles(sql.FieldNEQ(FieldRole, v)) } // RoleIn applies the In predicate on the "role" field. func RoleIn(vs ...Role) predicate.AuthRoles { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldRole), v...)) - }) + return predicate.AuthRoles(sql.FieldIn(FieldRole, vs...)) } // RoleNotIn applies the NotIn predicate on the "role" field. func RoleNotIn(vs ...Role) predicate.AuthRoles { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRoles(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldRole), v...)) - }) + return predicate.AuthRoles(sql.FieldNotIn(FieldRole, vs...)) } // HasToken applies the HasEdge predicate on the "token" edge. @@ -120,7 +78,6 @@ func HasToken() predicate.AuthRoles { return predicate.AuthRoles(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(TokenTable, FieldID), sqlgraph.Edge(sqlgraph.O2O, true, TokenTable, TokenColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/authroles_create.go b/backend/internal/data/ent/authroles_create.go index 3f66cd0..383b8c3 100644 --- a/backend/internal/data/ent/authroles_create.go +++ b/backend/internal/data/ent/authroles_create.go @@ -61,50 +61,8 @@ func (arc *AuthRolesCreate) Mutation() *AuthRolesMutation { // Save creates the AuthRoles in the database. func (arc *AuthRolesCreate) Save(ctx context.Context) (*AuthRoles, error) { - var ( - err error - node *AuthRoles - ) arc.defaults() - if len(arc.hooks) == 0 { - if err = arc.check(); err != nil { - return nil, err - } - node, err = arc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthRolesMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = arc.check(); err != nil { - return nil, err - } - arc.mutation = mutation - if node, err = arc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(arc.hooks) - 1; i >= 0; i-- { - if arc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = arc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, arc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*AuthRoles) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from AuthRolesMutation", v) - } - node = nv - } - return node, err + return withHooks[*AuthRoles, AuthRolesMutation](ctx, arc.sqlSave, arc.mutation, arc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -151,6 +109,9 @@ func (arc *AuthRolesCreate) check() error { } func (arc *AuthRolesCreate) sqlSave(ctx context.Context) (*AuthRoles, error) { + if err := arc.check(); err != nil { + return nil, err + } _node, _spec := arc.createSpec() if err := sqlgraph.CreateNode(ctx, arc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -160,6 +121,8 @@ func (arc *AuthRolesCreate) sqlSave(ctx context.Context) (*AuthRoles, error) { } id := _spec.ID.Value.(int64) _node.ID = int(id) + arc.mutation.id = &_node.ID + arc.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/authroles_delete.go b/backend/internal/data/ent/authroles_delete.go index 10b7c00..4bafec2 100644 --- a/backend/internal/data/ent/authroles_delete.go +++ b/backend/internal/data/ent/authroles_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (ard *AuthRolesDelete) Where(ps ...predicate.AuthRoles) *AuthRolesDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ard *AuthRolesDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ard.hooks) == 0 { - affected, err = ard.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthRolesMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ard.mutation = mutation - affected, err = ard.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ard.hooks) - 1; i >= 0; i-- { - if ard.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ard.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ard.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, AuthRolesMutation](ctx, ard.sqlExec, ard.mutation, ard.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (ard *AuthRolesDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + ard.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/authroles_query.go b/backend/internal/data/ent/authroles_query.go index cc3e56c..fa3e290 100644 --- a/backend/internal/data/ent/authroles_query.go +++ b/backend/internal/data/ent/authroles_query.go @@ -24,6 +24,7 @@ type AuthRolesQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.AuthRoles withToken *AuthTokensQuery withFKs bool @@ -38,13 +39,13 @@ func (arq *AuthRolesQuery) Where(ps ...predicate.AuthRoles) *AuthRolesQuery { return arq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (arq *AuthRolesQuery) Limit(limit int) *AuthRolesQuery { arq.limit = &limit return arq } -// Offset adds an offset step to the query. +// Offset to start from. func (arq *AuthRolesQuery) Offset(offset int) *AuthRolesQuery { arq.offset = &offset return arq @@ -57,7 +58,7 @@ func (arq *AuthRolesQuery) Unique(unique bool) *AuthRolesQuery { return arq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (arq *AuthRolesQuery) Order(o ...OrderFunc) *AuthRolesQuery { arq.order = append(arq.order, o...) return arq @@ -65,7 +66,7 @@ func (arq *AuthRolesQuery) Order(o ...OrderFunc) *AuthRolesQuery { // QueryToken chains the current query on the "token" edge. func (arq *AuthRolesQuery) QueryToken() *AuthTokensQuery { - query := &AuthTokensQuery{config: arq.config} + query := (&AuthTokensClient{config: arq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := arq.prepareQuery(ctx); err != nil { return nil, err @@ -88,7 +89,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(ctx) + nodes, err := arq.Limit(1).All(newQueryContext(ctx, TypeAuthRoles, "First")) if err != nil { return nil, err } @@ -111,7 +112,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(ctx); err != nil { + if ids, err = arq.Limit(1).IDs(newQueryContext(ctx, TypeAuthRoles, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -134,7 +135,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(ctx) + nodes, err := arq.Limit(2).All(newQueryContext(ctx, TypeAuthRoles, "Only")) if err != nil { return nil, err } @@ -162,7 +163,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(ctx); err != nil { + if ids, err = arq.Limit(2).IDs(newQueryContext(ctx, TypeAuthRoles, "OnlyID")); err != nil { return } switch len(ids) { @@ -187,10 +188,12 @@ 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") if err := arq.prepareQuery(ctx); err != nil { return nil, err } - return arq.sqlAll(ctx) + qr := querierAll[[]*AuthRoles, *AuthRolesQuery]() + return withInterceptors[[]*AuthRoles](ctx, arq, qr, arq.inters) } // AllX is like All, but panics if an error occurs. @@ -205,6 +208,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") if err := arq.Select(authroles.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -222,10 +226,11 @@ 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") if err := arq.prepareQuery(ctx); err != nil { return 0, err } - return arq.sqlCount(ctx) + return withInterceptors[int](ctx, arq, querierCount[*AuthRolesQuery](), arq.inters) } // CountX is like Count, but panics if an error occurs. @@ -239,10 +244,15 @@ 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) { - if err := arq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeAuthRoles, "Exist") + switch _, err := arq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return arq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -265,6 +275,7 @@ func (arq *AuthRolesQuery) Clone() *AuthRolesQuery { limit: arq.limit, offset: arq.offset, order: append([]OrderFunc{}, arq.order...), + inters: append([]Interceptor{}, arq.inters...), predicates: append([]predicate.AuthRoles{}, arq.predicates...), withToken: arq.withToken.Clone(), // clone intermediate query. @@ -277,7 +288,7 @@ func (arq *AuthRolesQuery) Clone() *AuthRolesQuery { // WithToken tells the query-builder to eager-load the nodes that are connected to // the "token" edge. The optional arguments are used to configure the query builder of the edge. func (arq *AuthRolesQuery) WithToken(opts ...func(*AuthTokensQuery)) *AuthRolesQuery { - query := &AuthTokensQuery{config: arq.config} + query := (&AuthTokensClient{config: arq.config}).Query() for _, opt := range opts { opt(query) } @@ -300,16 +311,11 @@ func (arq *AuthRolesQuery) WithToken(opts ...func(*AuthTokensQuery)) *AuthRolesQ // Aggregate(ent.Count()). // Scan(ctx, &v) func (arq *AuthRolesQuery) GroupBy(field string, fields ...string) *AuthRolesGroupBy { - grbuild := &AuthRolesGroupBy{config: arq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := arq.prepareQuery(ctx); err != nil { - return nil, err - } - return arq.sqlQuery(ctx), nil - } + arq.fields = append([]string{field}, fields...) + grbuild := &AuthRolesGroupBy{build: arq} + grbuild.flds = &arq.fields grbuild.label = authroles.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -327,10 +333,10 @@ func (arq *AuthRolesQuery) GroupBy(field string, fields ...string) *AuthRolesGro // Scan(ctx, &v) func (arq *AuthRolesQuery) Select(fields ...string) *AuthRolesSelect { arq.fields = append(arq.fields, fields...) - selbuild := &AuthRolesSelect{AuthRolesQuery: arq} - selbuild.label = authroles.Label - selbuild.flds, selbuild.scan = &arq.fields, selbuild.Scan - return selbuild + sbuild := &AuthRolesSelect{AuthRolesQuery: arq} + sbuild.label = authroles.Label + sbuild.flds, sbuild.scan = &arq.fields, sbuild.Scan + return sbuild } // Aggregate returns a AuthRolesSelect configured with the given aggregations. @@ -339,6 +345,16 @@ func (arq *AuthRolesQuery) Aggregate(fns ...AggregateFunc) *AuthRolesSelect { } func (arq *AuthRolesQuery) prepareQuery(ctx context.Context) error { + for _, inter := range arq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, arq); err != nil { + return err + } + } + } for _, f := range arq.fields { if !authroles.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -435,17 +451,6 @@ func (arq *AuthRolesQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, arq.driver, _spec) } -func (arq *AuthRolesQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := arq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (arq *AuthRolesQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -528,13 +533,8 @@ func (arq *AuthRolesQuery) sqlQuery(ctx context.Context) *sql.Selector { // AuthRolesGroupBy is the group-by builder for AuthRoles entities. type AuthRolesGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *AuthRolesQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -543,58 +543,46 @@ func (argb *AuthRolesGroupBy) Aggregate(fns ...AggregateFunc) *AuthRolesGroupBy return argb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (argb *AuthRolesGroupBy) Scan(ctx context.Context, v any) error { - query, err := argb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeAuthRoles, "GroupBy") + if err := argb.build.prepareQuery(ctx); err != nil { return err } - argb.sql = query - return argb.sqlScan(ctx, v) + return scanWithInterceptors[*AuthRolesQuery, *AuthRolesGroupBy](ctx, argb.build, argb, argb.build.inters, v) } -func (argb *AuthRolesGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range argb.fields { - if !authroles.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (argb *AuthRolesGroupBy) sqlScan(ctx context.Context, root *AuthRolesQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(argb.fns)) + for _, fn := range argb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := argb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*argb.flds)+len(argb.fns)) + for _, f := range *argb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*argb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := argb.driver.Query(ctx, query, args, rows); err != nil { + if err := argb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (argb *AuthRolesGroupBy) sqlQuery() *sql.Selector { - selector := argb.sql.Select() - aggregation := make([]string, 0, len(argb.fns)) - for _, fn := range argb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(argb.fields)+len(argb.fns)) - for _, f := range argb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(argb.fields...)...) -} - // AuthRolesSelect is the builder for selecting fields of AuthRoles entities. type AuthRolesSelect struct { *AuthRolesQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -605,26 +593,27 @@ 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") if err := ars.prepareQuery(ctx); err != nil { return err } - ars.sql = ars.AuthRolesQuery.sqlQuery(ctx) - return ars.sqlScan(ctx, v) + return scanWithInterceptors[*AuthRolesQuery, *AuthRolesSelect](ctx, ars.AuthRolesQuery, ars, ars.inters, v) } -func (ars *AuthRolesSelect) sqlScan(ctx context.Context, v any) error { +func (ars *AuthRolesSelect) sqlScan(ctx context.Context, root *AuthRolesQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(ars.fns)) for _, fn := range ars.fns { - aggregation = append(aggregation, fn(ars.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*ars.selector.flds); { case n == 0 && len(aggregation) > 0: - ars.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - ars.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := ars.sql.Query() + query, args := selector.Query() if err := ars.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/authroles_update.go b/backend/internal/data/ent/authroles_update.go index 6aa9b87..dea7b76 100644 --- a/backend/internal/data/ent/authroles_update.go +++ b/backend/internal/data/ent/authroles_update.go @@ -75,40 +75,7 @@ func (aru *AuthRolesUpdate) ClearToken() *AuthRolesUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (aru *AuthRolesUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(aru.hooks) == 0 { - if err = aru.check(); err != nil { - return 0, err - } - affected, err = aru.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthRolesMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = aru.check(); err != nil { - return 0, err - } - aru.mutation = mutation - affected, err = aru.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(aru.hooks) - 1; i >= 0; i-- { - if aru.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = aru.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, aru.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, AuthRolesMutation](ctx, aru.sqlSave, aru.mutation, aru.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -144,6 +111,9 @@ func (aru *AuthRolesUpdate) check() error { } func (aru *AuthRolesUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := aru.check(); err != nil { + return n, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: authroles.Table, @@ -207,6 +177,7 @@ func (aru *AuthRolesUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + aru.mutation.done = true return n, nil } @@ -271,46 +242,7 @@ func (aruo *AuthRolesUpdateOne) Select(field string, fields ...string) *AuthRole // Save executes the query and returns the updated AuthRoles entity. func (aruo *AuthRolesUpdateOne) Save(ctx context.Context) (*AuthRoles, error) { - var ( - err error - node *AuthRoles - ) - if len(aruo.hooks) == 0 { - if err = aruo.check(); err != nil { - return nil, err - } - node, err = aruo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthRolesMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = aruo.check(); err != nil { - return nil, err - } - aruo.mutation = mutation - node, err = aruo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(aruo.hooks) - 1; i >= 0; i-- { - if aruo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = aruo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, aruo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*AuthRoles) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from AuthRolesMutation", v) - } - node = nv - } - return node, err + return withHooks[*AuthRoles, AuthRolesMutation](ctx, aruo.sqlSave, aruo.mutation, aruo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -346,6 +278,9 @@ func (aruo *AuthRolesUpdateOne) check() error { } func (aruo *AuthRolesUpdateOne) sqlSave(ctx context.Context) (_node *AuthRoles, err error) { + if err := aruo.check(); err != nil { + return _node, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: authroles.Table, @@ -429,5 +364,6 @@ func (aruo *AuthRolesUpdateOne) sqlSave(ctx context.Context) (_node *AuthRoles, } return nil, err } + aruo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/authtokens/where.go b/backend/internal/data/ent/authtokens/where.go index 68bcc5f..fc2983f 100644 --- a/backend/internal/data/ent/authtokens/where.go +++ b/backend/internal/data/ent/authtokens/where.go @@ -13,357 +13,227 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.AuthTokens(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.AuthTokens(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.AuthTokens(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.AuthTokens(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.AuthTokens(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.AuthTokens(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.AuthTokens(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.AuthTokens(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.AuthTokens(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldEQ(FieldUpdatedAt, v)) } // Token applies equality check predicate on the "token" field. It's identical to TokenEQ. func Token(v []byte) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldToken), v)) - }) + return predicate.AuthTokens(sql.FieldEQ(FieldToken, v)) } // ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ. func ExpiresAt(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiresAt), v)) - }) + return predicate.AuthTokens(sql.FieldEQ(FieldExpiresAt, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.AuthTokens { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.AuthTokens(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.AuthTokens { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.AuthTokens(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.AuthTokens { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.AuthTokens(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.AuthTokens { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.AuthTokens(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.AuthTokens(sql.FieldLTE(FieldUpdatedAt, v)) } // TokenEQ applies the EQ predicate on the "token" field. func TokenEQ(v []byte) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldToken), v)) - }) + return predicate.AuthTokens(sql.FieldEQ(FieldToken, v)) } // TokenNEQ applies the NEQ predicate on the "token" field. func TokenNEQ(v []byte) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldToken), v)) - }) + return predicate.AuthTokens(sql.FieldNEQ(FieldToken, v)) } // TokenIn applies the In predicate on the "token" field. func TokenIn(vs ...[]byte) predicate.AuthTokens { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldToken), v...)) - }) + return predicate.AuthTokens(sql.FieldIn(FieldToken, vs...)) } // TokenNotIn applies the NotIn predicate on the "token" field. func TokenNotIn(vs ...[]byte) predicate.AuthTokens { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldToken), v...)) - }) + return predicate.AuthTokens(sql.FieldNotIn(FieldToken, vs...)) } // TokenGT applies the GT predicate on the "token" field. func TokenGT(v []byte) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldToken), v)) - }) + return predicate.AuthTokens(sql.FieldGT(FieldToken, v)) } // TokenGTE applies the GTE predicate on the "token" field. func TokenGTE(v []byte) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldToken), v)) - }) + return predicate.AuthTokens(sql.FieldGTE(FieldToken, v)) } // TokenLT applies the LT predicate on the "token" field. func TokenLT(v []byte) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldToken), v)) - }) + return predicate.AuthTokens(sql.FieldLT(FieldToken, v)) } // TokenLTE applies the LTE predicate on the "token" field. func TokenLTE(v []byte) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldToken), v)) - }) + return predicate.AuthTokens(sql.FieldLTE(FieldToken, v)) } // ExpiresAtEQ applies the EQ predicate on the "expires_at" field. func ExpiresAtEQ(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiresAt), v)) - }) + return predicate.AuthTokens(sql.FieldEQ(FieldExpiresAt, v)) } // ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field. func ExpiresAtNEQ(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldExpiresAt), v)) - }) + return predicate.AuthTokens(sql.FieldNEQ(FieldExpiresAt, v)) } // ExpiresAtIn applies the In predicate on the "expires_at" field. func ExpiresAtIn(vs ...time.Time) predicate.AuthTokens { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldExpiresAt), v...)) - }) + return predicate.AuthTokens(sql.FieldIn(FieldExpiresAt, vs...)) } // ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field. func ExpiresAtNotIn(vs ...time.Time) predicate.AuthTokens { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldExpiresAt), v...)) - }) + return predicate.AuthTokens(sql.FieldNotIn(FieldExpiresAt, vs...)) } // ExpiresAtGT applies the GT predicate on the "expires_at" field. func ExpiresAtGT(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldExpiresAt), v)) - }) + return predicate.AuthTokens(sql.FieldGT(FieldExpiresAt, v)) } // ExpiresAtGTE applies the GTE predicate on the "expires_at" field. func ExpiresAtGTE(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldExpiresAt), v)) - }) + return predicate.AuthTokens(sql.FieldGTE(FieldExpiresAt, v)) } // ExpiresAtLT applies the LT predicate on the "expires_at" field. func ExpiresAtLT(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldExpiresAt), v)) - }) + return predicate.AuthTokens(sql.FieldLT(FieldExpiresAt, v)) } // ExpiresAtLTE applies the LTE predicate on the "expires_at" field. func ExpiresAtLTE(v time.Time) predicate.AuthTokens { - return predicate.AuthTokens(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldExpiresAt), v)) - }) + return predicate.AuthTokens(sql.FieldLTE(FieldExpiresAt, v)) } // HasUser applies the HasEdge predicate on the "user" edge. @@ -371,7 +241,6 @@ func HasUser() predicate.AuthTokens { return predicate.AuthTokens(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(UserTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn), ) sqlgraph.HasNeighbors(s, step) @@ -399,7 +268,6 @@ func HasRoles() predicate.AuthTokens { return predicate.AuthTokens(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(RolesTable, FieldID), sqlgraph.Edge(sqlgraph.O2O, false, RolesTable, RolesColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/authtokens_create.go b/backend/internal/data/ent/authtokens_create.go index 9100ed5..d6632bb 100644 --- a/backend/internal/data/ent/authtokens_create.go +++ b/backend/internal/data/ent/authtokens_create.go @@ -130,50 +130,8 @@ func (atc *AuthTokensCreate) Mutation() *AuthTokensMutation { // Save creates the AuthTokens in the database. func (atc *AuthTokensCreate) Save(ctx context.Context) (*AuthTokens, error) { - var ( - err error - node *AuthTokens - ) atc.defaults() - if len(atc.hooks) == 0 { - if err = atc.check(); err != nil { - return nil, err - } - node, err = atc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthTokensMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = atc.check(); err != nil { - return nil, err - } - atc.mutation = mutation - if node, err = atc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(atc.hooks) - 1; i >= 0; i-- { - if atc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = atc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, atc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*AuthTokens) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from AuthTokensMutation", v) - } - node = nv - } - return node, err + return withHooks[*AuthTokens, AuthTokensMutation](ctx, atc.sqlSave, atc.mutation, atc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -236,6 +194,9 @@ func (atc *AuthTokensCreate) check() error { } func (atc *AuthTokensCreate) sqlSave(ctx context.Context) (*AuthTokens, error) { + if err := atc.check(); err != nil { + return nil, err + } _node, _spec := atc.createSpec() if err := sqlgraph.CreateNode(ctx, atc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -250,6 +211,8 @@ func (atc *AuthTokensCreate) sqlSave(ctx context.Context) (*AuthTokens, error) { return nil, err } } + atc.mutation.id = &_node.ID + atc.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/authtokens_delete.go b/backend/internal/data/ent/authtokens_delete.go index 5041362..680d83c 100644 --- a/backend/internal/data/ent/authtokens_delete.go +++ b/backend/internal/data/ent/authtokens_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (atd *AuthTokensDelete) Where(ps ...predicate.AuthTokens) *AuthTokensDelete // Exec executes the deletion query and returns how many vertices were deleted. func (atd *AuthTokensDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(atd.hooks) == 0 { - affected, err = atd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthTokensMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - atd.mutation = mutation - affected, err = atd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(atd.hooks) - 1; i >= 0; i-- { - if atd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = atd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, atd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, AuthTokensMutation](ctx, atd.sqlExec, atd.mutation, atd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (atd *AuthTokensDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + atd.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/authtokens_query.go b/backend/internal/data/ent/authtokens_query.go index 7020edb..6a62190 100644 --- a/backend/internal/data/ent/authtokens_query.go +++ b/backend/internal/data/ent/authtokens_query.go @@ -26,6 +26,7 @@ type AuthTokensQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.AuthTokens withUser *UserQuery withRoles *AuthRolesQuery @@ -41,13 +42,13 @@ func (atq *AuthTokensQuery) Where(ps ...predicate.AuthTokens) *AuthTokensQuery { return atq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (atq *AuthTokensQuery) Limit(limit int) *AuthTokensQuery { atq.limit = &limit return atq } -// Offset adds an offset step to the query. +// Offset to start from. func (atq *AuthTokensQuery) Offset(offset int) *AuthTokensQuery { atq.offset = &offset return atq @@ -60,7 +61,7 @@ func (atq *AuthTokensQuery) Unique(unique bool) *AuthTokensQuery { return atq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (atq *AuthTokensQuery) Order(o ...OrderFunc) *AuthTokensQuery { atq.order = append(atq.order, o...) return atq @@ -68,7 +69,7 @@ func (atq *AuthTokensQuery) Order(o ...OrderFunc) *AuthTokensQuery { // QueryUser chains the current query on the "user" edge. func (atq *AuthTokensQuery) QueryUser() *UserQuery { - query := &UserQuery{config: atq.config} + query := (&UserClient{config: atq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := atq.prepareQuery(ctx); err != nil { return nil, err @@ -90,7 +91,7 @@ func (atq *AuthTokensQuery) QueryUser() *UserQuery { // QueryRoles chains the current query on the "roles" edge. func (atq *AuthTokensQuery) QueryRoles() *AuthRolesQuery { - query := &AuthRolesQuery{config: atq.config} + query := (&AuthRolesClient{config: atq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := atq.prepareQuery(ctx); err != nil { return nil, err @@ -113,7 +114,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(ctx) + nodes, err := atq.Limit(1).All(newQueryContext(ctx, TypeAuthTokens, "First")) if err != nil { return nil, err } @@ -136,7 +137,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(ctx); err != nil { + if ids, err = atq.Limit(1).IDs(newQueryContext(ctx, TypeAuthTokens, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -159,7 +160,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(ctx) + nodes, err := atq.Limit(2).All(newQueryContext(ctx, TypeAuthTokens, "Only")) if err != nil { return nil, err } @@ -187,7 +188,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(ctx); err != nil { + if ids, err = atq.Limit(2).IDs(newQueryContext(ctx, TypeAuthTokens, "OnlyID")); err != nil { return } switch len(ids) { @@ -212,10 +213,12 @@ 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") if err := atq.prepareQuery(ctx); err != nil { return nil, err } - return atq.sqlAll(ctx) + qr := querierAll[[]*AuthTokens, *AuthTokensQuery]() + return withInterceptors[[]*AuthTokens](ctx, atq, qr, atq.inters) } // AllX is like All, but panics if an error occurs. @@ -230,6 +233,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") if err := atq.Select(authtokens.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -247,10 +251,11 @@ 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") if err := atq.prepareQuery(ctx); err != nil { return 0, err } - return atq.sqlCount(ctx) + return withInterceptors[int](ctx, atq, querierCount[*AuthTokensQuery](), atq.inters) } // CountX is like Count, but panics if an error occurs. @@ -264,10 +269,15 @@ 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) { - if err := atq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeAuthTokens, "Exist") + switch _, err := atq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return atq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -290,6 +300,7 @@ func (atq *AuthTokensQuery) Clone() *AuthTokensQuery { limit: atq.limit, offset: atq.offset, order: append([]OrderFunc{}, atq.order...), + inters: append([]Interceptor{}, atq.inters...), predicates: append([]predicate.AuthTokens{}, atq.predicates...), withUser: atq.withUser.Clone(), withRoles: atq.withRoles.Clone(), @@ -303,7 +314,7 @@ func (atq *AuthTokensQuery) Clone() *AuthTokensQuery { // WithUser tells the query-builder to eager-load the nodes that are connected to // the "user" edge. The optional arguments are used to configure the query builder of the edge. func (atq *AuthTokensQuery) WithUser(opts ...func(*UserQuery)) *AuthTokensQuery { - query := &UserQuery{config: atq.config} + query := (&UserClient{config: atq.config}).Query() for _, opt := range opts { opt(query) } @@ -314,7 +325,7 @@ func (atq *AuthTokensQuery) WithUser(opts ...func(*UserQuery)) *AuthTokensQuery // WithRoles tells the query-builder to eager-load the nodes that are connected to // the "roles" edge. The optional arguments are used to configure the query builder of the edge. func (atq *AuthTokensQuery) WithRoles(opts ...func(*AuthRolesQuery)) *AuthTokensQuery { - query := &AuthRolesQuery{config: atq.config} + query := (&AuthRolesClient{config: atq.config}).Query() for _, opt := range opts { opt(query) } @@ -337,16 +348,11 @@ func (atq *AuthTokensQuery) WithRoles(opts ...func(*AuthRolesQuery)) *AuthTokens // Aggregate(ent.Count()). // Scan(ctx, &v) func (atq *AuthTokensQuery) GroupBy(field string, fields ...string) *AuthTokensGroupBy { - grbuild := &AuthTokensGroupBy{config: atq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := atq.prepareQuery(ctx); err != nil { - return nil, err - } - return atq.sqlQuery(ctx), nil - } + atq.fields = append([]string{field}, fields...) + grbuild := &AuthTokensGroupBy{build: atq} + grbuild.flds = &atq.fields grbuild.label = authtokens.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -364,10 +370,10 @@ func (atq *AuthTokensQuery) GroupBy(field string, fields ...string) *AuthTokensG // Scan(ctx, &v) func (atq *AuthTokensQuery) Select(fields ...string) *AuthTokensSelect { atq.fields = append(atq.fields, fields...) - selbuild := &AuthTokensSelect{AuthTokensQuery: atq} - selbuild.label = authtokens.Label - selbuild.flds, selbuild.scan = &atq.fields, selbuild.Scan - return selbuild + sbuild := &AuthTokensSelect{AuthTokensQuery: atq} + sbuild.label = authtokens.Label + sbuild.flds, sbuild.scan = &atq.fields, sbuild.Scan + return sbuild } // Aggregate returns a AuthTokensSelect configured with the given aggregations. @@ -376,6 +382,16 @@ func (atq *AuthTokensQuery) Aggregate(fns ...AggregateFunc) *AuthTokensSelect { } func (atq *AuthTokensQuery) prepareQuery(ctx context.Context) error { + for _, inter := range atq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, atq); err != nil { + return err + } + } + } for _, f := range atq.fields { if !authtokens.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -507,17 +523,6 @@ func (atq *AuthTokensQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, atq.driver, _spec) } -func (atq *AuthTokensQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := atq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (atq *AuthTokensQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -600,13 +605,8 @@ func (atq *AuthTokensQuery) sqlQuery(ctx context.Context) *sql.Selector { // AuthTokensGroupBy is the group-by builder for AuthTokens entities. type AuthTokensGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *AuthTokensQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -615,58 +615,46 @@ func (atgb *AuthTokensGroupBy) Aggregate(fns ...AggregateFunc) *AuthTokensGroupB return atgb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (atgb *AuthTokensGroupBy) Scan(ctx context.Context, v any) error { - query, err := atgb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeAuthTokens, "GroupBy") + if err := atgb.build.prepareQuery(ctx); err != nil { return err } - atgb.sql = query - return atgb.sqlScan(ctx, v) + return scanWithInterceptors[*AuthTokensQuery, *AuthTokensGroupBy](ctx, atgb.build, atgb, atgb.build.inters, v) } -func (atgb *AuthTokensGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range atgb.fields { - if !authtokens.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (atgb *AuthTokensGroupBy) sqlScan(ctx context.Context, root *AuthTokensQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(atgb.fns)) + for _, fn := range atgb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := atgb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*atgb.flds)+len(atgb.fns)) + for _, f := range *atgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*atgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := atgb.driver.Query(ctx, query, args, rows); err != nil { + if err := atgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (atgb *AuthTokensGroupBy) sqlQuery() *sql.Selector { - selector := atgb.sql.Select() - aggregation := make([]string, 0, len(atgb.fns)) - for _, fn := range atgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(atgb.fields)+len(atgb.fns)) - for _, f := range atgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(atgb.fields...)...) -} - // AuthTokensSelect is the builder for selecting fields of AuthTokens entities. type AuthTokensSelect struct { *AuthTokensQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -677,26 +665,27 @@ 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") if err := ats.prepareQuery(ctx); err != nil { return err } - ats.sql = ats.AuthTokensQuery.sqlQuery(ctx) - return ats.sqlScan(ctx, v) + return scanWithInterceptors[*AuthTokensQuery, *AuthTokensSelect](ctx, ats.AuthTokensQuery, ats, ats.inters, v) } -func (ats *AuthTokensSelect) sqlScan(ctx context.Context, v any) error { +func (ats *AuthTokensSelect) sqlScan(ctx context.Context, root *AuthTokensQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(ats.fns)) for _, fn := range ats.fns { - aggregation = append(aggregation, fn(ats.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*ats.selector.flds); { case n == 0 && len(aggregation) > 0: - ats.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - ats.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := ats.sql.Query() + query, args := selector.Query() if err := ats.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/authtokens_update.go b/backend/internal/data/ent/authtokens_update.go index b218d4c..c058ee3 100644 --- a/backend/internal/data/ent/authtokens_update.go +++ b/backend/internal/data/ent/authtokens_update.go @@ -114,35 +114,8 @@ func (atu *AuthTokensUpdate) ClearRoles() *AuthTokensUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (atu *AuthTokensUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) atu.defaults() - if len(atu.hooks) == 0 { - affected, err = atu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthTokensMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - atu.mutation = mutation - affected, err = atu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(atu.hooks) - 1; i >= 0; i-- { - if atu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = atu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, atu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, AuthTokensMutation](ctx, atu.sqlSave, atu.mutation, atu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -280,6 +253,7 @@ func (atu *AuthTokensUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + atu.mutation.done = true return n, nil } @@ -381,41 +355,8 @@ func (atuo *AuthTokensUpdateOne) Select(field string, fields ...string) *AuthTok // Save executes the query and returns the updated AuthTokens entity. func (atuo *AuthTokensUpdateOne) Save(ctx context.Context) (*AuthTokens, error) { - var ( - err error - node *AuthTokens - ) atuo.defaults() - if len(atuo.hooks) == 0 { - node, err = atuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthTokensMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - atuo.mutation = mutation - node, err = atuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(atuo.hooks) - 1; i >= 0; i-- { - if atuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = atuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, atuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*AuthTokens) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from AuthTokensMutation", v) - } - node = nv - } - return node, err + return withHooks[*AuthTokens, AuthTokensMutation](ctx, atuo.sqlSave, atuo.mutation, atuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -573,5 +514,6 @@ func (atuo *AuthTokensUpdateOne) sqlSave(ctx context.Context) (_node *AuthTokens } return nil, err } + atuo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/client.go b/backend/internal/data/ent/client.go index eb66c20..bcbd962 100644 --- a/backend/internal/data/ent/client.go +++ b/backend/internal/data/ent/client.go @@ -62,7 +62,7 @@ type Client struct { // NewClient creates a new client configured with the given options. func NewClient(opts ...Option) *Client { - cfg := config{log: log.Println, hooks: &hooks{}} + cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} cfg.options(opts...) client := &Client{config: cfg} client.init() @@ -201,6 +201,55 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Intercept adds the query interceptors to all the entity clients. +// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. +func (c *Client) Intercept(interceptors ...Interceptor) { + c.Attachment.Intercept(interceptors...) + c.AuthRoles.Intercept(interceptors...) + c.AuthTokens.Intercept(interceptors...) + c.Document.Intercept(interceptors...) + c.Group.Intercept(interceptors...) + c.GroupInvitationToken.Intercept(interceptors...) + c.Item.Intercept(interceptors...) + c.ItemField.Intercept(interceptors...) + c.Label.Intercept(interceptors...) + c.Location.Intercept(interceptors...) + c.MaintenanceEntry.Intercept(interceptors...) + c.User.Intercept(interceptors...) +} + +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *AttachmentMutation: + return c.Attachment.mutate(ctx, m) + case *AuthRolesMutation: + return c.AuthRoles.mutate(ctx, m) + case *AuthTokensMutation: + return c.AuthTokens.mutate(ctx, m) + case *DocumentMutation: + return c.Document.mutate(ctx, m) + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *GroupInvitationTokenMutation: + return c.GroupInvitationToken.mutate(ctx, m) + case *ItemMutation: + return c.Item.mutate(ctx, m) + case *ItemFieldMutation: + return c.ItemField.mutate(ctx, m) + case *LabelMutation: + return c.Label.mutate(ctx, m) + case *LocationMutation: + return c.Location.mutate(ctx, m) + case *MaintenanceEntryMutation: + return c.MaintenanceEntry.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // AttachmentClient is a client for the Attachment schema. type AttachmentClient struct { config @@ -217,6 +266,12 @@ func (c *AttachmentClient) Use(hooks ...Hook) { c.hooks.Attachment = append(c.hooks.Attachment, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `attachment.Intercept(f(g(h())))`. +func (c *AttachmentClient) Intercept(interceptors ...Interceptor) { + c.inters.Attachment = append(c.inters.Attachment, interceptors...) +} + // Create returns a builder for creating a Attachment entity. func (c *AttachmentClient) Create() *AttachmentCreate { mutation := newAttachmentMutation(c.config, OpCreate) @@ -269,6 +324,7 @@ func (c *AttachmentClient) DeleteOneID(id uuid.UUID) *AttachmentDeleteOne { func (c *AttachmentClient) Query() *AttachmentQuery { return &AttachmentQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -288,7 +344,7 @@ func (c *AttachmentClient) GetX(ctx context.Context, id uuid.UUID) *Attachment { // QueryItem queries the item edge of a Attachment. func (c *AttachmentClient) QueryItem(a *Attachment) *ItemQuery { - query := &ItemQuery{config: c.config} + query := (&ItemClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := a.ID step := sqlgraph.NewStep( @@ -304,7 +360,7 @@ func (c *AttachmentClient) QueryItem(a *Attachment) *ItemQuery { // QueryDocument queries the document edge of a Attachment. func (c *AttachmentClient) QueryDocument(a *Attachment) *DocumentQuery { - query := &DocumentQuery{config: c.config} + query := (&DocumentClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := a.ID step := sqlgraph.NewStep( @@ -323,6 +379,26 @@ func (c *AttachmentClient) Hooks() []Hook { return c.hooks.Attachment } +// Interceptors returns the client interceptors. +func (c *AttachmentClient) Interceptors() []Interceptor { + return c.inters.Attachment +} + +func (c *AttachmentClient) mutate(ctx context.Context, m *AttachmentMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AttachmentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AttachmentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AttachmentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AttachmentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Attachment mutation op: %q", m.Op()) + } +} + // AuthRolesClient is a client for the AuthRoles schema. type AuthRolesClient struct { config @@ -339,6 +415,12 @@ func (c *AuthRolesClient) Use(hooks ...Hook) { c.hooks.AuthRoles = append(c.hooks.AuthRoles, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `authroles.Intercept(f(g(h())))`. +func (c *AuthRolesClient) Intercept(interceptors ...Interceptor) { + c.inters.AuthRoles = append(c.inters.AuthRoles, interceptors...) +} + // Create returns a builder for creating a AuthRoles entity. func (c *AuthRolesClient) Create() *AuthRolesCreate { mutation := newAuthRolesMutation(c.config, OpCreate) @@ -391,6 +473,7 @@ func (c *AuthRolesClient) DeleteOneID(id int) *AuthRolesDeleteOne { func (c *AuthRolesClient) Query() *AuthRolesQuery { return &AuthRolesQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -410,7 +493,7 @@ func (c *AuthRolesClient) GetX(ctx context.Context, id int) *AuthRoles { // QueryToken queries the token edge of a AuthRoles. func (c *AuthRolesClient) QueryToken(ar *AuthRoles) *AuthTokensQuery { - query := &AuthTokensQuery{config: c.config} + query := (&AuthTokensClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := ar.ID step := sqlgraph.NewStep( @@ -429,6 +512,26 @@ func (c *AuthRolesClient) Hooks() []Hook { return c.hooks.AuthRoles } +// Interceptors returns the client interceptors. +func (c *AuthRolesClient) Interceptors() []Interceptor { + return c.inters.AuthRoles +} + +func (c *AuthRolesClient) mutate(ctx context.Context, m *AuthRolesMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AuthRolesCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AuthRolesUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AuthRolesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AuthRolesDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown AuthRoles mutation op: %q", m.Op()) + } +} + // AuthTokensClient is a client for the AuthTokens schema. type AuthTokensClient struct { config @@ -445,6 +548,12 @@ func (c *AuthTokensClient) Use(hooks ...Hook) { c.hooks.AuthTokens = append(c.hooks.AuthTokens, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `authtokens.Intercept(f(g(h())))`. +func (c *AuthTokensClient) Intercept(interceptors ...Interceptor) { + c.inters.AuthTokens = append(c.inters.AuthTokens, interceptors...) +} + // Create returns a builder for creating a AuthTokens entity. func (c *AuthTokensClient) Create() *AuthTokensCreate { mutation := newAuthTokensMutation(c.config, OpCreate) @@ -497,6 +606,7 @@ func (c *AuthTokensClient) DeleteOneID(id uuid.UUID) *AuthTokensDeleteOne { func (c *AuthTokensClient) Query() *AuthTokensQuery { return &AuthTokensQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -516,7 +626,7 @@ func (c *AuthTokensClient) GetX(ctx context.Context, id uuid.UUID) *AuthTokens { // QueryUser queries the user edge of a AuthTokens. func (c *AuthTokensClient) QueryUser(at *AuthTokens) *UserQuery { - query := &UserQuery{config: c.config} + query := (&UserClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := at.ID step := sqlgraph.NewStep( @@ -532,7 +642,7 @@ func (c *AuthTokensClient) QueryUser(at *AuthTokens) *UserQuery { // QueryRoles queries the roles edge of a AuthTokens. func (c *AuthTokensClient) QueryRoles(at *AuthTokens) *AuthRolesQuery { - query := &AuthRolesQuery{config: c.config} + query := (&AuthRolesClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := at.ID step := sqlgraph.NewStep( @@ -551,6 +661,26 @@ func (c *AuthTokensClient) Hooks() []Hook { return c.hooks.AuthTokens } +// Interceptors returns the client interceptors. +func (c *AuthTokensClient) Interceptors() []Interceptor { + return c.inters.AuthTokens +} + +func (c *AuthTokensClient) mutate(ctx context.Context, m *AuthTokensMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AuthTokensCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AuthTokensUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AuthTokensUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AuthTokensDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown AuthTokens mutation op: %q", m.Op()) + } +} + // DocumentClient is a client for the Document schema. type DocumentClient struct { config @@ -567,6 +697,12 @@ func (c *DocumentClient) Use(hooks ...Hook) { c.hooks.Document = append(c.hooks.Document, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `document.Intercept(f(g(h())))`. +func (c *DocumentClient) Intercept(interceptors ...Interceptor) { + c.inters.Document = append(c.inters.Document, interceptors...) +} + // Create returns a builder for creating a Document entity. func (c *DocumentClient) Create() *DocumentCreate { mutation := newDocumentMutation(c.config, OpCreate) @@ -619,6 +755,7 @@ func (c *DocumentClient) DeleteOneID(id uuid.UUID) *DocumentDeleteOne { func (c *DocumentClient) Query() *DocumentQuery { return &DocumentQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -638,7 +775,7 @@ func (c *DocumentClient) GetX(ctx context.Context, id uuid.UUID) *Document { // QueryGroup queries the group edge of a Document. func (c *DocumentClient) QueryGroup(d *Document) *GroupQuery { - query := &GroupQuery{config: c.config} + query := (&GroupClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := d.ID step := sqlgraph.NewStep( @@ -654,7 +791,7 @@ func (c *DocumentClient) QueryGroup(d *Document) *GroupQuery { // QueryAttachments queries the attachments edge of a Document. func (c *DocumentClient) QueryAttachments(d *Document) *AttachmentQuery { - query := &AttachmentQuery{config: c.config} + query := (&AttachmentClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := d.ID step := sqlgraph.NewStep( @@ -673,6 +810,26 @@ func (c *DocumentClient) Hooks() []Hook { return c.hooks.Document } +// Interceptors returns the client interceptors. +func (c *DocumentClient) Interceptors() []Interceptor { + return c.inters.Document +} + +func (c *DocumentClient) mutate(ctx context.Context, m *DocumentMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&DocumentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&DocumentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&DocumentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&DocumentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Document mutation op: %q", m.Op()) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -689,6 +846,12 @@ func (c *GroupClient) Use(hooks ...Hook) { c.hooks.Group = append(c.hooks.Group, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `group.Intercept(f(g(h())))`. +func (c *GroupClient) Intercept(interceptors ...Interceptor) { + c.inters.Group = append(c.inters.Group, interceptors...) +} + // Create returns a builder for creating a Group entity. func (c *GroupClient) Create() *GroupCreate { mutation := newGroupMutation(c.config, OpCreate) @@ -741,6 +904,7 @@ func (c *GroupClient) DeleteOneID(id uuid.UUID) *GroupDeleteOne { func (c *GroupClient) Query() *GroupQuery { return &GroupQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -760,7 +924,7 @@ func (c *GroupClient) GetX(ctx context.Context, id uuid.UUID) *Group { // QueryUsers queries the users edge of a Group. func (c *GroupClient) QueryUsers(gr *Group) *UserQuery { - query := &UserQuery{config: c.config} + query := (&UserClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := gr.ID step := sqlgraph.NewStep( @@ -776,7 +940,7 @@ func (c *GroupClient) QueryUsers(gr *Group) *UserQuery { // QueryLocations queries the locations edge of a Group. func (c *GroupClient) QueryLocations(gr *Group) *LocationQuery { - query := &LocationQuery{config: c.config} + query := (&LocationClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := gr.ID step := sqlgraph.NewStep( @@ -792,7 +956,7 @@ func (c *GroupClient) QueryLocations(gr *Group) *LocationQuery { // QueryItems queries the items edge of a Group. func (c *GroupClient) QueryItems(gr *Group) *ItemQuery { - query := &ItemQuery{config: c.config} + query := (&ItemClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := gr.ID step := sqlgraph.NewStep( @@ -808,7 +972,7 @@ func (c *GroupClient) QueryItems(gr *Group) *ItemQuery { // QueryLabels queries the labels edge of a Group. func (c *GroupClient) QueryLabels(gr *Group) *LabelQuery { - query := &LabelQuery{config: c.config} + query := (&LabelClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := gr.ID step := sqlgraph.NewStep( @@ -824,7 +988,7 @@ func (c *GroupClient) QueryLabels(gr *Group) *LabelQuery { // QueryDocuments queries the documents edge of a Group. func (c *GroupClient) QueryDocuments(gr *Group) *DocumentQuery { - query := &DocumentQuery{config: c.config} + query := (&DocumentClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := gr.ID step := sqlgraph.NewStep( @@ -840,7 +1004,7 @@ func (c *GroupClient) QueryDocuments(gr *Group) *DocumentQuery { // QueryInvitationTokens queries the invitation_tokens edge of a Group. func (c *GroupClient) QueryInvitationTokens(gr *Group) *GroupInvitationTokenQuery { - query := &GroupInvitationTokenQuery{config: c.config} + query := (&GroupInvitationTokenClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := gr.ID step := sqlgraph.NewStep( @@ -859,6 +1023,26 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +// Interceptors returns the client interceptors. +func (c *GroupClient) Interceptors() []Interceptor { + return c.inters.Group +} + +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // GroupInvitationTokenClient is a client for the GroupInvitationToken schema. type GroupInvitationTokenClient struct { config @@ -875,6 +1059,12 @@ func (c *GroupInvitationTokenClient) Use(hooks ...Hook) { c.hooks.GroupInvitationToken = append(c.hooks.GroupInvitationToken, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `groupinvitationtoken.Intercept(f(g(h())))`. +func (c *GroupInvitationTokenClient) Intercept(interceptors ...Interceptor) { + c.inters.GroupInvitationToken = append(c.inters.GroupInvitationToken, interceptors...) +} + // Create returns a builder for creating a GroupInvitationToken entity. func (c *GroupInvitationTokenClient) Create() *GroupInvitationTokenCreate { mutation := newGroupInvitationTokenMutation(c.config, OpCreate) @@ -927,6 +1117,7 @@ func (c *GroupInvitationTokenClient) DeleteOneID(id uuid.UUID) *GroupInvitationT func (c *GroupInvitationTokenClient) Query() *GroupInvitationTokenQuery { return &GroupInvitationTokenQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -946,7 +1137,7 @@ func (c *GroupInvitationTokenClient) GetX(ctx context.Context, id uuid.UUID) *Gr // QueryGroup queries the group edge of a GroupInvitationToken. func (c *GroupInvitationTokenClient) QueryGroup(git *GroupInvitationToken) *GroupQuery { - query := &GroupQuery{config: c.config} + query := (&GroupClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := git.ID step := sqlgraph.NewStep( @@ -965,6 +1156,26 @@ func (c *GroupInvitationTokenClient) Hooks() []Hook { return c.hooks.GroupInvitationToken } +// Interceptors returns the client interceptors. +func (c *GroupInvitationTokenClient) Interceptors() []Interceptor { + return c.inters.GroupInvitationToken +} + +func (c *GroupInvitationTokenClient) mutate(ctx context.Context, m *GroupInvitationTokenMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupInvitationTokenCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupInvitationTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupInvitationTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupInvitationTokenDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown GroupInvitationToken mutation op: %q", m.Op()) + } +} + // ItemClient is a client for the Item schema. type ItemClient struct { config @@ -981,6 +1192,12 @@ func (c *ItemClient) Use(hooks ...Hook) { c.hooks.Item = append(c.hooks.Item, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `item.Intercept(f(g(h())))`. +func (c *ItemClient) Intercept(interceptors ...Interceptor) { + c.inters.Item = append(c.inters.Item, interceptors...) +} + // Create returns a builder for creating a Item entity. func (c *ItemClient) Create() *ItemCreate { mutation := newItemMutation(c.config, OpCreate) @@ -1033,6 +1250,7 @@ func (c *ItemClient) DeleteOneID(id uuid.UUID) *ItemDeleteOne { func (c *ItemClient) Query() *ItemQuery { return &ItemQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -1052,7 +1270,7 @@ func (c *ItemClient) GetX(ctx context.Context, id uuid.UUID) *Item { // QueryParent queries the parent edge of a Item. func (c *ItemClient) QueryParent(i *Item) *ItemQuery { - query := &ItemQuery{config: c.config} + query := (&ItemClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := i.ID step := sqlgraph.NewStep( @@ -1068,7 +1286,7 @@ func (c *ItemClient) QueryParent(i *Item) *ItemQuery { // QueryChildren queries the children edge of a Item. func (c *ItemClient) QueryChildren(i *Item) *ItemQuery { - query := &ItemQuery{config: c.config} + query := (&ItemClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := i.ID step := sqlgraph.NewStep( @@ -1084,7 +1302,7 @@ func (c *ItemClient) QueryChildren(i *Item) *ItemQuery { // QueryGroup queries the group edge of a Item. func (c *ItemClient) QueryGroup(i *Item) *GroupQuery { - query := &GroupQuery{config: c.config} + query := (&GroupClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := i.ID step := sqlgraph.NewStep( @@ -1100,7 +1318,7 @@ func (c *ItemClient) QueryGroup(i *Item) *GroupQuery { // QueryLabel queries the label edge of a Item. func (c *ItemClient) QueryLabel(i *Item) *LabelQuery { - query := &LabelQuery{config: c.config} + query := (&LabelClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := i.ID step := sqlgraph.NewStep( @@ -1116,7 +1334,7 @@ func (c *ItemClient) QueryLabel(i *Item) *LabelQuery { // QueryLocation queries the location edge of a Item. func (c *ItemClient) QueryLocation(i *Item) *LocationQuery { - query := &LocationQuery{config: c.config} + query := (&LocationClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := i.ID step := sqlgraph.NewStep( @@ -1132,7 +1350,7 @@ func (c *ItemClient) QueryLocation(i *Item) *LocationQuery { // QueryFields queries the fields edge of a Item. func (c *ItemClient) QueryFields(i *Item) *ItemFieldQuery { - query := &ItemFieldQuery{config: c.config} + query := (&ItemFieldClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := i.ID step := sqlgraph.NewStep( @@ -1148,7 +1366,7 @@ func (c *ItemClient) QueryFields(i *Item) *ItemFieldQuery { // QueryMaintenanceEntries queries the maintenance_entries edge of a Item. func (c *ItemClient) QueryMaintenanceEntries(i *Item) *MaintenanceEntryQuery { - query := &MaintenanceEntryQuery{config: c.config} + query := (&MaintenanceEntryClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := i.ID step := sqlgraph.NewStep( @@ -1164,7 +1382,7 @@ func (c *ItemClient) QueryMaintenanceEntries(i *Item) *MaintenanceEntryQuery { // QueryAttachments queries the attachments edge of a Item. func (c *ItemClient) QueryAttachments(i *Item) *AttachmentQuery { - query := &AttachmentQuery{config: c.config} + query := (&AttachmentClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := i.ID step := sqlgraph.NewStep( @@ -1183,6 +1401,26 @@ func (c *ItemClient) Hooks() []Hook { return c.hooks.Item } +// Interceptors returns the client interceptors. +func (c *ItemClient) Interceptors() []Interceptor { + return c.inters.Item +} + +func (c *ItemClient) mutate(ctx context.Context, m *ItemMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ItemCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ItemUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ItemDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Item mutation op: %q", m.Op()) + } +} + // ItemFieldClient is a client for the ItemField schema. type ItemFieldClient struct { config @@ -1199,6 +1437,12 @@ func (c *ItemFieldClient) Use(hooks ...Hook) { c.hooks.ItemField = append(c.hooks.ItemField, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `itemfield.Intercept(f(g(h())))`. +func (c *ItemFieldClient) Intercept(interceptors ...Interceptor) { + c.inters.ItemField = append(c.inters.ItemField, interceptors...) +} + // Create returns a builder for creating a ItemField entity. func (c *ItemFieldClient) Create() *ItemFieldCreate { mutation := newItemFieldMutation(c.config, OpCreate) @@ -1251,6 +1495,7 @@ func (c *ItemFieldClient) DeleteOneID(id uuid.UUID) *ItemFieldDeleteOne { func (c *ItemFieldClient) Query() *ItemFieldQuery { return &ItemFieldQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -1270,7 +1515,7 @@ func (c *ItemFieldClient) GetX(ctx context.Context, id uuid.UUID) *ItemField { // QueryItem queries the item edge of a ItemField. func (c *ItemFieldClient) QueryItem(_if *ItemField) *ItemQuery { - query := &ItemQuery{config: c.config} + query := (&ItemClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := _if.ID step := sqlgraph.NewStep( @@ -1289,6 +1534,26 @@ func (c *ItemFieldClient) Hooks() []Hook { return c.hooks.ItemField } +// Interceptors returns the client interceptors. +func (c *ItemFieldClient) Interceptors() []Interceptor { + return c.inters.ItemField +} + +func (c *ItemFieldClient) mutate(ctx context.Context, m *ItemFieldMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ItemFieldCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ItemFieldUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ItemFieldUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ItemFieldDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown ItemField mutation op: %q", m.Op()) + } +} + // LabelClient is a client for the Label schema. type LabelClient struct { config @@ -1305,6 +1570,12 @@ func (c *LabelClient) Use(hooks ...Hook) { c.hooks.Label = append(c.hooks.Label, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `label.Intercept(f(g(h())))`. +func (c *LabelClient) Intercept(interceptors ...Interceptor) { + c.inters.Label = append(c.inters.Label, interceptors...) +} + // Create returns a builder for creating a Label entity. func (c *LabelClient) Create() *LabelCreate { mutation := newLabelMutation(c.config, OpCreate) @@ -1357,6 +1628,7 @@ func (c *LabelClient) DeleteOneID(id uuid.UUID) *LabelDeleteOne { func (c *LabelClient) Query() *LabelQuery { return &LabelQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -1376,7 +1648,7 @@ func (c *LabelClient) GetX(ctx context.Context, id uuid.UUID) *Label { // QueryGroup queries the group edge of a Label. func (c *LabelClient) QueryGroup(l *Label) *GroupQuery { - query := &GroupQuery{config: c.config} + query := (&GroupClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := l.ID step := sqlgraph.NewStep( @@ -1392,7 +1664,7 @@ func (c *LabelClient) QueryGroup(l *Label) *GroupQuery { // QueryItems queries the items edge of a Label. func (c *LabelClient) QueryItems(l *Label) *ItemQuery { - query := &ItemQuery{config: c.config} + query := (&ItemClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := l.ID step := sqlgraph.NewStep( @@ -1411,6 +1683,26 @@ func (c *LabelClient) Hooks() []Hook { return c.hooks.Label } +// Interceptors returns the client interceptors. +func (c *LabelClient) Interceptors() []Interceptor { + return c.inters.Label +} + +func (c *LabelClient) mutate(ctx context.Context, m *LabelMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&LabelCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&LabelDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Label mutation op: %q", m.Op()) + } +} + // LocationClient is a client for the Location schema. type LocationClient struct { config @@ -1427,6 +1719,12 @@ func (c *LocationClient) Use(hooks ...Hook) { c.hooks.Location = append(c.hooks.Location, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `location.Intercept(f(g(h())))`. +func (c *LocationClient) Intercept(interceptors ...Interceptor) { + c.inters.Location = append(c.inters.Location, interceptors...) +} + // Create returns a builder for creating a Location entity. func (c *LocationClient) Create() *LocationCreate { mutation := newLocationMutation(c.config, OpCreate) @@ -1479,6 +1777,7 @@ func (c *LocationClient) DeleteOneID(id uuid.UUID) *LocationDeleteOne { func (c *LocationClient) Query() *LocationQuery { return &LocationQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -1498,7 +1797,7 @@ func (c *LocationClient) GetX(ctx context.Context, id uuid.UUID) *Location { // QueryParent queries the parent edge of a Location. func (c *LocationClient) QueryParent(l *Location) *LocationQuery { - query := &LocationQuery{config: c.config} + query := (&LocationClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := l.ID step := sqlgraph.NewStep( @@ -1514,7 +1813,7 @@ func (c *LocationClient) QueryParent(l *Location) *LocationQuery { // QueryChildren queries the children edge of a Location. func (c *LocationClient) QueryChildren(l *Location) *LocationQuery { - query := &LocationQuery{config: c.config} + query := (&LocationClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := l.ID step := sqlgraph.NewStep( @@ -1530,7 +1829,7 @@ func (c *LocationClient) QueryChildren(l *Location) *LocationQuery { // QueryGroup queries the group edge of a Location. func (c *LocationClient) QueryGroup(l *Location) *GroupQuery { - query := &GroupQuery{config: c.config} + query := (&GroupClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := l.ID step := sqlgraph.NewStep( @@ -1546,7 +1845,7 @@ func (c *LocationClient) QueryGroup(l *Location) *GroupQuery { // QueryItems queries the items edge of a Location. func (c *LocationClient) QueryItems(l *Location) *ItemQuery { - query := &ItemQuery{config: c.config} + query := (&ItemClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := l.ID step := sqlgraph.NewStep( @@ -1565,6 +1864,26 @@ func (c *LocationClient) Hooks() []Hook { return c.hooks.Location } +// Interceptors returns the client interceptors. +func (c *LocationClient) Interceptors() []Interceptor { + return c.inters.Location +} + +func (c *LocationClient) mutate(ctx context.Context, m *LocationMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&LocationCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&LocationUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&LocationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&LocationDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Location mutation op: %q", m.Op()) + } +} + // MaintenanceEntryClient is a client for the MaintenanceEntry schema. type MaintenanceEntryClient struct { config @@ -1581,6 +1900,12 @@ func (c *MaintenanceEntryClient) Use(hooks ...Hook) { c.hooks.MaintenanceEntry = append(c.hooks.MaintenanceEntry, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `maintenanceentry.Intercept(f(g(h())))`. +func (c *MaintenanceEntryClient) Intercept(interceptors ...Interceptor) { + c.inters.MaintenanceEntry = append(c.inters.MaintenanceEntry, interceptors...) +} + // Create returns a builder for creating a MaintenanceEntry entity. func (c *MaintenanceEntryClient) Create() *MaintenanceEntryCreate { mutation := newMaintenanceEntryMutation(c.config, OpCreate) @@ -1633,6 +1958,7 @@ func (c *MaintenanceEntryClient) DeleteOneID(id uuid.UUID) *MaintenanceEntryDele func (c *MaintenanceEntryClient) Query() *MaintenanceEntryQuery { return &MaintenanceEntryQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -1652,7 +1978,7 @@ func (c *MaintenanceEntryClient) GetX(ctx context.Context, id uuid.UUID) *Mainte // QueryItem queries the item edge of a MaintenanceEntry. func (c *MaintenanceEntryClient) QueryItem(me *MaintenanceEntry) *ItemQuery { - query := &ItemQuery{config: c.config} + query := (&ItemClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := me.ID step := sqlgraph.NewStep( @@ -1671,6 +1997,26 @@ func (c *MaintenanceEntryClient) Hooks() []Hook { return c.hooks.MaintenanceEntry } +// Interceptors returns the client interceptors. +func (c *MaintenanceEntryClient) Interceptors() []Interceptor { + return c.inters.MaintenanceEntry +} + +func (c *MaintenanceEntryClient) mutate(ctx context.Context, m *MaintenanceEntryMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&MaintenanceEntryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&MaintenanceEntryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&MaintenanceEntryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&MaintenanceEntryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown MaintenanceEntry mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -1687,6 +2033,12 @@ func (c *UserClient) Use(hooks ...Hook) { c.hooks.User = append(c.hooks.User, hooks...) } +// Use adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`. +func (c *UserClient) Intercept(interceptors ...Interceptor) { + c.inters.User = append(c.inters.User, interceptors...) +} + // Create returns a builder for creating a User entity. func (c *UserClient) Create() *UserCreate { mutation := newUserMutation(c.config, OpCreate) @@ -1739,6 +2091,7 @@ func (c *UserClient) DeleteOneID(id uuid.UUID) *UserDeleteOne { func (c *UserClient) Query() *UserQuery { return &UserQuery{ config: c.config, + inters: c.Interceptors(), } } @@ -1758,7 +2111,7 @@ func (c *UserClient) GetX(ctx context.Context, id uuid.UUID) *User { // QueryGroup queries the group edge of a User. func (c *UserClient) QueryGroup(u *User) *GroupQuery { - query := &GroupQuery{config: c.config} + query := (&GroupClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( @@ -1774,7 +2127,7 @@ func (c *UserClient) QueryGroup(u *User) *GroupQuery { // QueryAuthTokens queries the auth_tokens edge of a User. func (c *UserClient) QueryAuthTokens(u *User) *AuthTokensQuery { - query := &AuthTokensQuery{config: c.config} + query := (&AuthTokensClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( @@ -1792,3 +2145,23 @@ func (c *UserClient) QueryAuthTokens(u *User) *AuthTokensQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +// Interceptors returns the client interceptors. +func (c *UserClient) Interceptors() []Interceptor { + return c.inters.User +} + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/backend/internal/data/ent/config.go b/backend/internal/data/ent/config.go index 9cba253..c4dc769 100644 --- a/backend/internal/data/ent/config.go +++ b/backend/internal/data/ent/config.go @@ -20,23 +20,41 @@ type config struct { log func(...any) // hooks to execute on mutations. hooks *hooks + // interceptors to execute on queries. + inters *inters } -// hooks per client, for fast access. -type hooks struct { - Attachment []ent.Hook - AuthRoles []ent.Hook - AuthTokens []ent.Hook - Document []ent.Hook - Group []ent.Hook - GroupInvitationToken []ent.Hook - Item []ent.Hook - ItemField []ent.Hook - Label []ent.Hook - Location []ent.Hook - MaintenanceEntry []ent.Hook - User []ent.Hook -} +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Attachment []ent.Hook + AuthRoles []ent.Hook + AuthTokens []ent.Hook + Document []ent.Hook + Group []ent.Hook + GroupInvitationToken []ent.Hook + Item []ent.Hook + ItemField []ent.Hook + Label []ent.Hook + Location []ent.Hook + MaintenanceEntry []ent.Hook + User []ent.Hook + } + inters struct { + Attachment []ent.Interceptor + AuthRoles []ent.Interceptor + AuthTokens []ent.Interceptor + Document []ent.Interceptor + Group []ent.Interceptor + GroupInvitationToken []ent.Interceptor + Item []ent.Interceptor + ItemField []ent.Interceptor + Label []ent.Interceptor + Location []ent.Interceptor + MaintenanceEntry []ent.Interceptor + User []ent.Interceptor + } +) // Options applies the options on the config object. func (c *config) options(opts ...Option) { diff --git a/backend/internal/data/ent/document/where.go b/backend/internal/data/ent/document/where.go index 6f1bd69..614cf4e 100644 --- a/backend/internal/data/ent/document/where.go +++ b/backend/internal/data/ent/document/where.go @@ -13,427 +13,277 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Document(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Document(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Document(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.Document(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.Document(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Document(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Document(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Document(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Document(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Document(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Document(sql.FieldEQ(FieldUpdatedAt, v)) } // Title applies equality check predicate on the "title" field. It's identical to TitleEQ. func Title(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldEQ(FieldTitle, v)) } // Path applies equality check predicate on the "path" field. It's identical to PathEQ. func Path(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldEQ(FieldPath, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Document(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Document(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.Document { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.Document(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.Document { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.Document(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.Document(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Document(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.Document(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Document(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Document(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Document(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.Document { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Document(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.Document { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Document(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Document(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Document(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Document(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Document(sql.FieldLTE(FieldUpdatedAt, v)) } // TitleEQ applies the EQ predicate on the "title" field. func TitleEQ(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldEQ(FieldTitle, v)) } // TitleNEQ applies the NEQ predicate on the "title" field. func TitleNEQ(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldNEQ(FieldTitle, v)) } // TitleIn applies the In predicate on the "title" field. func TitleIn(vs ...string) predicate.Document { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldTitle), v...)) - }) + return predicate.Document(sql.FieldIn(FieldTitle, vs...)) } // TitleNotIn applies the NotIn predicate on the "title" field. func TitleNotIn(vs ...string) predicate.Document { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldTitle), v...)) - }) + return predicate.Document(sql.FieldNotIn(FieldTitle, vs...)) } // TitleGT applies the GT predicate on the "title" field. func TitleGT(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldGT(FieldTitle, v)) } // TitleGTE applies the GTE predicate on the "title" field. func TitleGTE(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldGTE(FieldTitle, v)) } // TitleLT applies the LT predicate on the "title" field. func TitleLT(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldLT(FieldTitle, v)) } // TitleLTE applies the LTE predicate on the "title" field. func TitleLTE(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldLTE(FieldTitle, v)) } // TitleContains applies the Contains predicate on the "title" field. func TitleContains(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldContains(FieldTitle, v)) } // TitleHasPrefix applies the HasPrefix predicate on the "title" field. func TitleHasPrefix(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldHasPrefix(FieldTitle, v)) } // TitleHasSuffix applies the HasSuffix predicate on the "title" field. func TitleHasSuffix(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldHasSuffix(FieldTitle, v)) } // TitleEqualFold applies the EqualFold predicate on the "title" field. func TitleEqualFold(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldEqualFold(FieldTitle, v)) } // TitleContainsFold applies the ContainsFold predicate on the "title" field. func TitleContainsFold(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldTitle), v)) - }) + return predicate.Document(sql.FieldContainsFold(FieldTitle, v)) } // PathEQ applies the EQ predicate on the "path" field. func PathEQ(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldEQ(FieldPath, v)) } // PathNEQ applies the NEQ predicate on the "path" field. func PathNEQ(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldNEQ(FieldPath, v)) } // PathIn applies the In predicate on the "path" field. func PathIn(vs ...string) predicate.Document { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldPath), v...)) - }) + return predicate.Document(sql.FieldIn(FieldPath, vs...)) } // PathNotIn applies the NotIn predicate on the "path" field. func PathNotIn(vs ...string) predicate.Document { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldPath), v...)) - }) + return predicate.Document(sql.FieldNotIn(FieldPath, vs...)) } // PathGT applies the GT predicate on the "path" field. func PathGT(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldGT(FieldPath, v)) } // PathGTE applies the GTE predicate on the "path" field. func PathGTE(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldGTE(FieldPath, v)) } // PathLT applies the LT predicate on the "path" field. func PathLT(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldLT(FieldPath, v)) } // PathLTE applies the LTE predicate on the "path" field. func PathLTE(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldLTE(FieldPath, v)) } // PathContains applies the Contains predicate on the "path" field. func PathContains(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldContains(FieldPath, v)) } // PathHasPrefix applies the HasPrefix predicate on the "path" field. func PathHasPrefix(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldHasPrefix(FieldPath, v)) } // PathHasSuffix applies the HasSuffix predicate on the "path" field. func PathHasSuffix(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldHasSuffix(FieldPath, v)) } // PathEqualFold applies the EqualFold predicate on the "path" field. func PathEqualFold(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldEqualFold(FieldPath, v)) } // PathContainsFold applies the ContainsFold predicate on the "path" field. func PathContainsFold(v string) predicate.Document { - return predicate.Document(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldPath), v)) - }) + return predicate.Document(sql.FieldContainsFold(FieldPath, v)) } // HasGroup applies the HasEdge predicate on the "group" edge. @@ -441,7 +291,6 @@ func HasGroup() predicate.Document { return predicate.Document(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), ) sqlgraph.HasNeighbors(s, step) @@ -469,7 +318,6 @@ func HasAttachments() predicate.Document { return predicate.Document(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(AttachmentsTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, AttachmentsTable, AttachmentsColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/document_create.go b/backend/internal/data/ent/document_create.go index 67b5baa..81f5e8c 100644 --- a/backend/internal/data/ent/document_create.go +++ b/backend/internal/data/ent/document_create.go @@ -110,50 +110,8 @@ func (dc *DocumentCreate) Mutation() *DocumentMutation { // Save creates the Document in the database. func (dc *DocumentCreate) Save(ctx context.Context) (*Document, error) { - var ( - err error - node *Document - ) dc.defaults() - if len(dc.hooks) == 0 { - if err = dc.check(); err != nil { - return nil, err - } - node, err = dc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DocumentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = dc.check(); err != nil { - return nil, err - } - dc.mutation = mutation - if node, err = dc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(dc.hooks) - 1; i >= 0; i-- { - if dc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = dc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, dc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Document) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from DocumentMutation", v) - } - node = nv - } - return node, err + return withHooks[*Document, DocumentMutation](ctx, dc.sqlSave, dc.mutation, dc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -225,6 +183,9 @@ func (dc *DocumentCreate) check() error { } func (dc *DocumentCreate) sqlSave(ctx context.Context) (*Document, error) { + if err := dc.check(); err != nil { + return nil, err + } _node, _spec := dc.createSpec() if err := sqlgraph.CreateNode(ctx, dc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -239,6 +200,8 @@ func (dc *DocumentCreate) sqlSave(ctx context.Context) (*Document, error) { return nil, err } } + dc.mutation.id = &_node.ID + dc.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/document_delete.go b/backend/internal/data/ent/document_delete.go index 6e21bef..000ab1c 100644 --- a/backend/internal/data/ent/document_delete.go +++ b/backend/internal/data/ent/document_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (dd *DocumentDelete) Where(ps ...predicate.Document) *DocumentDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (dd *DocumentDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(dd.hooks) == 0 { - affected, err = dd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DocumentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - dd.mutation = mutation - affected, err = dd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(dd.hooks) - 1; i >= 0; i-- { - if dd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = dd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, dd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, DocumentMutation](ctx, dd.sqlExec, dd.mutation, dd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (dd *DocumentDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + dd.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/document_query.go b/backend/internal/data/ent/document_query.go index 5ef4f67..51b407c 100644 --- a/backend/internal/data/ent/document_query.go +++ b/backend/internal/data/ent/document_query.go @@ -26,6 +26,7 @@ type DocumentQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.Document withGroup *GroupQuery withAttachments *AttachmentQuery @@ -41,13 +42,13 @@ func (dq *DocumentQuery) Where(ps ...predicate.Document) *DocumentQuery { return dq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (dq *DocumentQuery) Limit(limit int) *DocumentQuery { dq.limit = &limit return dq } -// Offset adds an offset step to the query. +// Offset to start from. func (dq *DocumentQuery) Offset(offset int) *DocumentQuery { dq.offset = &offset return dq @@ -60,7 +61,7 @@ func (dq *DocumentQuery) Unique(unique bool) *DocumentQuery { return dq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (dq *DocumentQuery) Order(o ...OrderFunc) *DocumentQuery { dq.order = append(dq.order, o...) return dq @@ -68,7 +69,7 @@ func (dq *DocumentQuery) Order(o ...OrderFunc) *DocumentQuery { // QueryGroup chains the current query on the "group" edge. func (dq *DocumentQuery) QueryGroup() *GroupQuery { - query := &GroupQuery{config: dq.config} + query := (&GroupClient{config: dq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := dq.prepareQuery(ctx); err != nil { return nil, err @@ -90,7 +91,7 @@ func (dq *DocumentQuery) QueryGroup() *GroupQuery { // QueryAttachments chains the current query on the "attachments" edge. func (dq *DocumentQuery) QueryAttachments() *AttachmentQuery { - query := &AttachmentQuery{config: dq.config} + query := (&AttachmentClient{config: dq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := dq.prepareQuery(ctx); err != nil { return nil, err @@ -113,7 +114,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(ctx) + nodes, err := dq.Limit(1).All(newQueryContext(ctx, TypeDocument, "First")) if err != nil { return nil, err } @@ -136,7 +137,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(ctx); err != nil { + if ids, err = dq.Limit(1).IDs(newQueryContext(ctx, TypeDocument, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -159,7 +160,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(ctx) + nodes, err := dq.Limit(2).All(newQueryContext(ctx, TypeDocument, "Only")) if err != nil { return nil, err } @@ -187,7 +188,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(ctx); err != nil { + if ids, err = dq.Limit(2).IDs(newQueryContext(ctx, TypeDocument, "OnlyID")); err != nil { return } switch len(ids) { @@ -212,10 +213,12 @@ 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") if err := dq.prepareQuery(ctx); err != nil { return nil, err } - return dq.sqlAll(ctx) + qr := querierAll[[]*Document, *DocumentQuery]() + return withInterceptors[[]*Document](ctx, dq, qr, dq.inters) } // AllX is like All, but panics if an error occurs. @@ -230,6 +233,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") if err := dq.Select(document.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -247,10 +251,11 @@ 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") if err := dq.prepareQuery(ctx); err != nil { return 0, err } - return dq.sqlCount(ctx) + return withInterceptors[int](ctx, dq, querierCount[*DocumentQuery](), dq.inters) } // CountX is like Count, but panics if an error occurs. @@ -264,10 +269,15 @@ 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) { - if err := dq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeDocument, "Exist") + switch _, err := dq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return dq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -290,6 +300,7 @@ func (dq *DocumentQuery) Clone() *DocumentQuery { limit: dq.limit, offset: dq.offset, order: append([]OrderFunc{}, dq.order...), + inters: append([]Interceptor{}, dq.inters...), predicates: append([]predicate.Document{}, dq.predicates...), withGroup: dq.withGroup.Clone(), withAttachments: dq.withAttachments.Clone(), @@ -303,7 +314,7 @@ func (dq *DocumentQuery) Clone() *DocumentQuery { // WithGroup tells the query-builder to eager-load the nodes that are connected to // the "group" edge. The optional arguments are used to configure the query builder of the edge. func (dq *DocumentQuery) WithGroup(opts ...func(*GroupQuery)) *DocumentQuery { - query := &GroupQuery{config: dq.config} + query := (&GroupClient{config: dq.config}).Query() for _, opt := range opts { opt(query) } @@ -314,7 +325,7 @@ func (dq *DocumentQuery) WithGroup(opts ...func(*GroupQuery)) *DocumentQuery { // WithAttachments tells the query-builder to eager-load the nodes that are connected to // the "attachments" edge. The optional arguments are used to configure the query builder of the edge. func (dq *DocumentQuery) WithAttachments(opts ...func(*AttachmentQuery)) *DocumentQuery { - query := &AttachmentQuery{config: dq.config} + query := (&AttachmentClient{config: dq.config}).Query() for _, opt := range opts { opt(query) } @@ -337,16 +348,11 @@ func (dq *DocumentQuery) WithAttachments(opts ...func(*AttachmentQuery)) *Docume // Aggregate(ent.Count()). // Scan(ctx, &v) func (dq *DocumentQuery) GroupBy(field string, fields ...string) *DocumentGroupBy { - grbuild := &DocumentGroupBy{config: dq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := dq.prepareQuery(ctx); err != nil { - return nil, err - } - return dq.sqlQuery(ctx), nil - } + dq.fields = append([]string{field}, fields...) + grbuild := &DocumentGroupBy{build: dq} + grbuild.flds = &dq.fields grbuild.label = document.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -364,10 +370,10 @@ func (dq *DocumentQuery) GroupBy(field string, fields ...string) *DocumentGroupB // Scan(ctx, &v) func (dq *DocumentQuery) Select(fields ...string) *DocumentSelect { dq.fields = append(dq.fields, fields...) - selbuild := &DocumentSelect{DocumentQuery: dq} - selbuild.label = document.Label - selbuild.flds, selbuild.scan = &dq.fields, selbuild.Scan - return selbuild + sbuild := &DocumentSelect{DocumentQuery: dq} + sbuild.label = document.Label + sbuild.flds, sbuild.scan = &dq.fields, sbuild.Scan + return sbuild } // Aggregate returns a DocumentSelect configured with the given aggregations. @@ -376,6 +382,16 @@ func (dq *DocumentQuery) Aggregate(fns ...AggregateFunc) *DocumentSelect { } func (dq *DocumentQuery) prepareQuery(ctx context.Context) error { + for _, inter := range dq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, dq); err != nil { + return err + } + } + } for _, f := range dq.fields { if !document.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -511,17 +527,6 @@ func (dq *DocumentQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, dq.driver, _spec) } -func (dq *DocumentQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := dq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (dq *DocumentQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -604,13 +609,8 @@ func (dq *DocumentQuery) sqlQuery(ctx context.Context) *sql.Selector { // DocumentGroupBy is the group-by builder for Document entities. type DocumentGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *DocumentQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -619,58 +619,46 @@ func (dgb *DocumentGroupBy) Aggregate(fns ...AggregateFunc) *DocumentGroupBy { return dgb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (dgb *DocumentGroupBy) Scan(ctx context.Context, v any) error { - query, err := dgb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeDocument, "GroupBy") + if err := dgb.build.prepareQuery(ctx); err != nil { return err } - dgb.sql = query - return dgb.sqlScan(ctx, v) + return scanWithInterceptors[*DocumentQuery, *DocumentGroupBy](ctx, dgb.build, dgb, dgb.build.inters, v) } -func (dgb *DocumentGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range dgb.fields { - if !document.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (dgb *DocumentGroupBy) sqlScan(ctx context.Context, root *DocumentQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(dgb.fns)) + for _, fn := range dgb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := dgb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*dgb.flds)+len(dgb.fns)) + for _, f := range *dgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*dgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := dgb.driver.Query(ctx, query, args, rows); err != nil { + if err := dgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (dgb *DocumentGroupBy) sqlQuery() *sql.Selector { - selector := dgb.sql.Select() - aggregation := make([]string, 0, len(dgb.fns)) - for _, fn := range dgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(dgb.fields)+len(dgb.fns)) - for _, f := range dgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(dgb.fields...)...) -} - // DocumentSelect is the builder for selecting fields of Document entities. type DocumentSelect struct { *DocumentQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -681,26 +669,27 @@ 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") if err := ds.prepareQuery(ctx); err != nil { return err } - ds.sql = ds.DocumentQuery.sqlQuery(ctx) - return ds.sqlScan(ctx, v) + return scanWithInterceptors[*DocumentQuery, *DocumentSelect](ctx, ds.DocumentQuery, ds, ds.inters, v) } -func (ds *DocumentSelect) sqlScan(ctx context.Context, v any) error { +func (ds *DocumentSelect) sqlScan(ctx context.Context, root *DocumentQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(ds.fns)) for _, fn := range ds.fns { - aggregation = append(aggregation, fn(ds.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*ds.selector.flds); { case n == 0 && len(aggregation) > 0: - ds.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - ds.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := ds.sql.Query() + query, args := selector.Query() if err := ds.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/document_update.go b/backend/internal/data/ent/document_update.go index 4a7ae7e..e685bda 100644 --- a/backend/internal/data/ent/document_update.go +++ b/backend/internal/data/ent/document_update.go @@ -109,41 +109,8 @@ func (du *DocumentUpdate) RemoveAttachments(a ...*Attachment) *DocumentUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (du *DocumentUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) du.defaults() - if len(du.hooks) == 0 { - if err = du.check(); err != nil { - return 0, err - } - affected, err = du.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DocumentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = du.check(); err != nil { - return 0, err - } - du.mutation = mutation - affected, err = du.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(du.hooks) - 1; i >= 0; i-- { - if du.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = du.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, du.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, DocumentMutation](ctx, du.sqlSave, du.mutation, du.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -195,6 +162,9 @@ func (du *DocumentUpdate) check() error { } func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := du.check(); err != nil { + return n, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: document.Table, @@ -318,6 +288,7 @@ func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + du.mutation.done = true return n, nil } @@ -414,47 +385,8 @@ func (duo *DocumentUpdateOne) Select(field string, fields ...string) *DocumentUp // Save executes the query and returns the updated Document entity. func (duo *DocumentUpdateOne) Save(ctx context.Context) (*Document, error) { - var ( - err error - node *Document - ) duo.defaults() - if len(duo.hooks) == 0 { - if err = duo.check(); err != nil { - return nil, err - } - node, err = duo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DocumentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = duo.check(); err != nil { - return nil, err - } - duo.mutation = mutation - node, err = duo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(duo.hooks) - 1; i >= 0; i-- { - if duo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = duo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, duo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Document) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from DocumentMutation", v) - } - node = nv - } - return node, err + return withHooks[*Document, DocumentMutation](ctx, duo.sqlSave, duo.mutation, duo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -506,6 +438,9 @@ func (duo *DocumentUpdateOne) check() error { } func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err error) { + if err := duo.check(); err != nil { + return _node, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: document.Table, @@ -649,5 +584,6 @@ func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err } return nil, err } + duo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/ent.go b/backend/internal/data/ent/ent.go index adf8df3..d9a0cae 100644 --- a/backend/internal/data/ent/ent.go +++ b/backend/internal/data/ent/ent.go @@ -6,6 +6,7 @@ import ( "context" "errors" "fmt" + "reflect" "entgo.io/ent" "entgo.io/ent/dialect/sql" @@ -26,14 +27,20 @@ import ( // ent aliases to avoid import conflicts in user's code. type ( - Op = ent.Op - Hook = ent.Hook - Value = ent.Value - Query = ent.Query - Policy = ent.Policy - Mutator = ent.Mutator - Mutation = ent.Mutation - MutateFunc = ent.MutateFunc + Op = ent.Op + Hook = ent.Hook + Value = ent.Value + Query = ent.Query + Querier = ent.Querier + QuerierFunc = ent.QuerierFunc + Interceptor = ent.Interceptor + InterceptFunc = ent.InterceptFunc + Traverser = ent.Traverser + TraverseFunc = ent.TraverseFunc + Policy = ent.Policy + Mutator = ent.Mutator + Mutation = ent.Mutation + MutateFunc = ent.MutateFunc ) // OrderFunc applies an ordering on the sql selector. @@ -484,5 +491,120 @@ func (s *selector) BoolX(ctx context.Context) bool { return v } +// withHooks invokes the builder operation with the given hooks, if any. +func withHooks[V Value, M any, PM interface { + *M + Mutation +}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) { + if len(hooks) == 0 { + return exec(ctx) + } + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutationT, ok := m.(PM) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + // Set the mutation to the builder. + *mutation = *mutationT + return exec(ctx) + }) + for i := len(hooks) - 1; i >= 0; i-- { + if hooks[i] == nil { + return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = hooks[i](mut) + } + v, err := mut.Mutate(ctx, mutation) + if err != nil { + return value, err + } + nv, ok := v.(V) + if !ok { + return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation) + } + 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 { + if ent.QueryFromContext(ctx) == nil { + ctx = ent.NewQueryContext(ctx, &ent.QueryContext{Type: typ, Op: op}) + } + return ctx +} + +func querierAll[V Value, Q interface { + sqlAll(context.Context, ...queryHook) (V, error) +}]() Querier { + return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + return query.sqlAll(ctx) + }) +} + +func querierCount[Q interface { + sqlCount(context.Context) (int, error) +}]() Querier { + return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + return query.sqlCount(ctx) + }) +} + +func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) { + for i := len(inters) - 1; i >= 0; i-- { + qr = inters[i].Intercept(qr) + } + rv, err := qr.Query(ctx, q) + if err != nil { + return v, err + } + vt, ok := rv.(V) + if !ok { + return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v) + } + return vt, nil +} + +func scanWithInterceptors[Q1 ent.Query, Q2 interface { + sqlScan(context.Context, Q1, any) error +}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error { + rv := reflect.ValueOf(v) + var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q1) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + if err := selectOrGroup.sqlScan(ctx, query, v); err != nil { + return nil, err + } + if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() { + return rv.Elem().Interface(), nil + } + return v, nil + }) + for i := len(inters) - 1; i >= 0; i-- { + qr = inters[i].Intercept(qr) + } + vv, err := qr.Query(ctx, rootQuery) + if err != nil { + return err + } + switch rv2 := reflect.ValueOf(vv); { + case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer: + case rv.Type() == rv2.Type(): + rv.Elem().Set(rv2.Elem()) + case rv.Elem().Type() == rv2.Type(): + rv.Elem().Set(rv2) + } + return nil +} + // queryHook describes an internal hook for the different sqlAll methods. type queryHook func(context.Context, *sqlgraph.QuerySpec) diff --git a/backend/internal/data/ent/group/where.go b/backend/internal/data/ent/group/where.go index 62106cc..e6d434b 100644 --- a/backend/internal/data/ent/group/where.go +++ b/backend/internal/data/ent/group/where.go @@ -13,357 +13,227 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Group(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Group(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Group(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.Group(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.Group(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Group(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Group(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Group(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Group(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Group(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Group(sql.FieldEQ(FieldUpdatedAt, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldEQ(FieldName, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Group(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Group(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.Group { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.Group(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.Group { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.Group(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.Group(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Group(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.Group(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Group(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Group(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Group(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.Group { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Group(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.Group { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Group(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Group(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Group(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Group(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Group(sql.FieldLTE(FieldUpdatedAt, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.Group { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.Group(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.Group { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.Group(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.Group(sql.FieldContainsFold(FieldName, v)) } // CurrencyEQ applies the EQ predicate on the "currency" field. func CurrencyEQ(v Currency) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCurrency), v)) - }) + return predicate.Group(sql.FieldEQ(FieldCurrency, v)) } // CurrencyNEQ applies the NEQ predicate on the "currency" field. func CurrencyNEQ(v Currency) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCurrency), v)) - }) + return predicate.Group(sql.FieldNEQ(FieldCurrency, v)) } // CurrencyIn applies the In predicate on the "currency" field. func CurrencyIn(vs ...Currency) predicate.Group { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCurrency), v...)) - }) + return predicate.Group(sql.FieldIn(FieldCurrency, vs...)) } // CurrencyNotIn applies the NotIn predicate on the "currency" field. func CurrencyNotIn(vs ...Currency) predicate.Group { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Group(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCurrency), v...)) - }) + return predicate.Group(sql.FieldNotIn(FieldCurrency, vs...)) } // HasUsers applies the HasEdge predicate on the "users" edge. @@ -371,7 +241,6 @@ func HasUsers() predicate.Group { return predicate.Group(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(UsersTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, UsersTable, UsersColumn), ) sqlgraph.HasNeighbors(s, step) @@ -399,7 +268,6 @@ func HasLocations() predicate.Group { return predicate.Group(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(LocationsTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, LocationsTable, LocationsColumn), ) sqlgraph.HasNeighbors(s, step) @@ -427,7 +295,6 @@ func HasItems() predicate.Group { return predicate.Group(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ItemsTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, ItemsTable, ItemsColumn), ) sqlgraph.HasNeighbors(s, step) @@ -455,7 +322,6 @@ func HasLabels() predicate.Group { return predicate.Group(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(LabelsTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, LabelsTable, LabelsColumn), ) sqlgraph.HasNeighbors(s, step) @@ -483,7 +349,6 @@ func HasDocuments() predicate.Group { return predicate.Group(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(DocumentsTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, DocumentsTable, DocumentsColumn), ) sqlgraph.HasNeighbors(s, step) @@ -511,7 +376,6 @@ func HasInvitationTokens() predicate.Group { return predicate.Group(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(InvitationTokensTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, InvitationTokensTable, InvitationTokensColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/group_create.go b/backend/internal/data/ent/group_create.go index 6839bd0..b13c358 100644 --- a/backend/internal/data/ent/group_create.go +++ b/backend/internal/data/ent/group_create.go @@ -186,50 +186,8 @@ func (gc *GroupCreate) Mutation() *GroupMutation { // Save creates the Group in the database. func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) { - var ( - err error - node *Group - ) gc.defaults() - if len(gc.hooks) == 0 { - if err = gc.check(); err != nil { - return nil, err - } - node, err = gc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GroupMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = gc.check(); err != nil { - return nil, err - } - gc.mutation = mutation - if node, err = gc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(gc.hooks) - 1; i >= 0; i-- { - if gc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = gc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, gc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Group) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from GroupMutation", v) - } - node = nv - } - return node, err + return withHooks[*Group, GroupMutation](ctx, gc.sqlSave, gc.mutation, gc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -302,6 +260,9 @@ func (gc *GroupCreate) check() error { } func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) { + if err := gc.check(); err != nil { + return nil, err + } _node, _spec := gc.createSpec() if err := sqlgraph.CreateNode(ctx, gc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -316,6 +277,8 @@ func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) { return nil, err } } + gc.mutation.id = &_node.ID + gc.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/group_delete.go b/backend/internal/data/ent/group_delete.go index 4bcefc8..5ecc7d1 100644 --- a/backend/internal/data/ent/group_delete.go +++ b/backend/internal/data/ent/group_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (gd *GroupDelete) Where(ps ...predicate.Group) *GroupDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (gd *GroupDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(gd.hooks) == 0 { - affected, err = gd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GroupMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - gd.mutation = mutation - affected, err = gd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(gd.hooks) - 1; i >= 0; i-- { - if gd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = gd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, gd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, GroupMutation](ctx, gd.sqlExec, gd.mutation, gd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (gd *GroupDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + gd.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/group_query.go b/backend/internal/data/ent/group_query.go index 7d17713..701ee01 100644 --- a/backend/internal/data/ent/group_query.go +++ b/backend/internal/data/ent/group_query.go @@ -30,6 +30,7 @@ type GroupQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.Group withUsers *UserQuery withLocations *LocationQuery @@ -48,13 +49,13 @@ func (gq *GroupQuery) Where(ps ...predicate.Group) *GroupQuery { return gq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (gq *GroupQuery) Limit(limit int) *GroupQuery { gq.limit = &limit return gq } -// Offset adds an offset step to the query. +// Offset to start from. func (gq *GroupQuery) Offset(offset int) *GroupQuery { gq.offset = &offset return gq @@ -67,7 +68,7 @@ func (gq *GroupQuery) Unique(unique bool) *GroupQuery { return gq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (gq *GroupQuery) Order(o ...OrderFunc) *GroupQuery { gq.order = append(gq.order, o...) return gq @@ -75,7 +76,7 @@ func (gq *GroupQuery) Order(o ...OrderFunc) *GroupQuery { // QueryUsers chains the current query on the "users" edge. func (gq *GroupQuery) QueryUsers() *UserQuery { - query := &UserQuery{config: gq.config} + query := (&UserClient{config: gq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := gq.prepareQuery(ctx); err != nil { return nil, err @@ -97,7 +98,7 @@ func (gq *GroupQuery) QueryUsers() *UserQuery { // QueryLocations chains the current query on the "locations" edge. func (gq *GroupQuery) QueryLocations() *LocationQuery { - query := &LocationQuery{config: gq.config} + query := (&LocationClient{config: gq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := gq.prepareQuery(ctx); err != nil { return nil, err @@ -119,7 +120,7 @@ func (gq *GroupQuery) QueryLocations() *LocationQuery { // QueryItems chains the current query on the "items" edge. func (gq *GroupQuery) QueryItems() *ItemQuery { - query := &ItemQuery{config: gq.config} + query := (&ItemClient{config: gq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := gq.prepareQuery(ctx); err != nil { return nil, err @@ -141,7 +142,7 @@ func (gq *GroupQuery) QueryItems() *ItemQuery { // QueryLabels chains the current query on the "labels" edge. func (gq *GroupQuery) QueryLabels() *LabelQuery { - query := &LabelQuery{config: gq.config} + query := (&LabelClient{config: gq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := gq.prepareQuery(ctx); err != nil { return nil, err @@ -163,7 +164,7 @@ func (gq *GroupQuery) QueryLabels() *LabelQuery { // QueryDocuments chains the current query on the "documents" edge. func (gq *GroupQuery) QueryDocuments() *DocumentQuery { - query := &DocumentQuery{config: gq.config} + query := (&DocumentClient{config: gq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := gq.prepareQuery(ctx); err != nil { return nil, err @@ -185,7 +186,7 @@ func (gq *GroupQuery) QueryDocuments() *DocumentQuery { // QueryInvitationTokens chains the current query on the "invitation_tokens" edge. func (gq *GroupQuery) QueryInvitationTokens() *GroupInvitationTokenQuery { - query := &GroupInvitationTokenQuery{config: gq.config} + query := (&GroupInvitationTokenClient{config: gq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := gq.prepareQuery(ctx); err != nil { return nil, err @@ -208,7 +209,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(ctx) + nodes, err := gq.Limit(1).All(newQueryContext(ctx, TypeGroup, "First")) if err != nil { return nil, err } @@ -231,7 +232,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(ctx); err != nil { + if ids, err = gq.Limit(1).IDs(newQueryContext(ctx, TypeGroup, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -254,7 +255,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(ctx) + nodes, err := gq.Limit(2).All(newQueryContext(ctx, TypeGroup, "Only")) if err != nil { return nil, err } @@ -282,7 +283,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(ctx); err != nil { + if ids, err = gq.Limit(2).IDs(newQueryContext(ctx, TypeGroup, "OnlyID")); err != nil { return } switch len(ids) { @@ -307,10 +308,12 @@ 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") if err := gq.prepareQuery(ctx); err != nil { return nil, err } - return gq.sqlAll(ctx) + qr := querierAll[[]*Group, *GroupQuery]() + return withInterceptors[[]*Group](ctx, gq, qr, gq.inters) } // AllX is like All, but panics if an error occurs. @@ -325,6 +328,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") if err := gq.Select(group.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -342,10 +346,11 @@ 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") if err := gq.prepareQuery(ctx); err != nil { return 0, err } - return gq.sqlCount(ctx) + return withInterceptors[int](ctx, gq, querierCount[*GroupQuery](), gq.inters) } // CountX is like Count, but panics if an error occurs. @@ -359,10 +364,15 @@ 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) { - if err := gq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeGroup, "Exist") + switch _, err := gq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return gq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -385,6 +395,7 @@ func (gq *GroupQuery) Clone() *GroupQuery { limit: gq.limit, offset: gq.offset, order: append([]OrderFunc{}, gq.order...), + inters: append([]Interceptor{}, gq.inters...), predicates: append([]predicate.Group{}, gq.predicates...), withUsers: gq.withUsers.Clone(), withLocations: gq.withLocations.Clone(), @@ -402,7 +413,7 @@ func (gq *GroupQuery) Clone() *GroupQuery { // WithUsers tells the query-builder to eager-load the nodes that are connected to // the "users" edge. The optional arguments are used to configure the query builder of the edge. func (gq *GroupQuery) WithUsers(opts ...func(*UserQuery)) *GroupQuery { - query := &UserQuery{config: gq.config} + query := (&UserClient{config: gq.config}).Query() for _, opt := range opts { opt(query) } @@ -413,7 +424,7 @@ func (gq *GroupQuery) WithUsers(opts ...func(*UserQuery)) *GroupQuery { // WithLocations tells the query-builder to eager-load the nodes that are connected to // the "locations" edge. The optional arguments are used to configure the query builder of the edge. func (gq *GroupQuery) WithLocations(opts ...func(*LocationQuery)) *GroupQuery { - query := &LocationQuery{config: gq.config} + query := (&LocationClient{config: gq.config}).Query() for _, opt := range opts { opt(query) } @@ -424,7 +435,7 @@ func (gq *GroupQuery) WithLocations(opts ...func(*LocationQuery)) *GroupQuery { // WithItems tells the query-builder to eager-load the nodes that are connected to // the "items" edge. The optional arguments are used to configure the query builder of the edge. func (gq *GroupQuery) WithItems(opts ...func(*ItemQuery)) *GroupQuery { - query := &ItemQuery{config: gq.config} + query := (&ItemClient{config: gq.config}).Query() for _, opt := range opts { opt(query) } @@ -435,7 +446,7 @@ func (gq *GroupQuery) WithItems(opts ...func(*ItemQuery)) *GroupQuery { // WithLabels tells the query-builder to eager-load the nodes that are connected to // the "labels" edge. The optional arguments are used to configure the query builder of the edge. func (gq *GroupQuery) WithLabels(opts ...func(*LabelQuery)) *GroupQuery { - query := &LabelQuery{config: gq.config} + query := (&LabelClient{config: gq.config}).Query() for _, opt := range opts { opt(query) } @@ -446,7 +457,7 @@ func (gq *GroupQuery) WithLabels(opts ...func(*LabelQuery)) *GroupQuery { // WithDocuments tells the query-builder to eager-load the nodes that are connected to // the "documents" edge. The optional arguments are used to configure the query builder of the edge. func (gq *GroupQuery) WithDocuments(opts ...func(*DocumentQuery)) *GroupQuery { - query := &DocumentQuery{config: gq.config} + query := (&DocumentClient{config: gq.config}).Query() for _, opt := range opts { opt(query) } @@ -457,7 +468,7 @@ func (gq *GroupQuery) WithDocuments(opts ...func(*DocumentQuery)) *GroupQuery { // WithInvitationTokens tells the query-builder to eager-load the nodes that are connected to // the "invitation_tokens" edge. The optional arguments are used to configure the query builder of the edge. func (gq *GroupQuery) WithInvitationTokens(opts ...func(*GroupInvitationTokenQuery)) *GroupQuery { - query := &GroupInvitationTokenQuery{config: gq.config} + query := (&GroupInvitationTokenClient{config: gq.config}).Query() for _, opt := range opts { opt(query) } @@ -480,16 +491,11 @@ func (gq *GroupQuery) WithInvitationTokens(opts ...func(*GroupInvitationTokenQue // Aggregate(ent.Count()). // Scan(ctx, &v) func (gq *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy { - grbuild := &GroupGroupBy{config: gq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := gq.prepareQuery(ctx); err != nil { - return nil, err - } - return gq.sqlQuery(ctx), nil - } + gq.fields = append([]string{field}, fields...) + grbuild := &GroupGroupBy{build: gq} + grbuild.flds = &gq.fields grbuild.label = group.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -507,10 +513,10 @@ func (gq *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy { // Scan(ctx, &v) func (gq *GroupQuery) Select(fields ...string) *GroupSelect { gq.fields = append(gq.fields, fields...) - selbuild := &GroupSelect{GroupQuery: gq} - selbuild.label = group.Label - selbuild.flds, selbuild.scan = &gq.fields, selbuild.Scan - return selbuild + sbuild := &GroupSelect{GroupQuery: gq} + sbuild.label = group.Label + sbuild.flds, sbuild.scan = &gq.fields, sbuild.Scan + return sbuild } // Aggregate returns a GroupSelect configured with the given aggregations. @@ -519,6 +525,16 @@ func (gq *GroupQuery) Aggregate(fns ...AggregateFunc) *GroupSelect { } func (gq *GroupQuery) prepareQuery(ctx context.Context) error { + for _, inter := range gq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, gq); err != nil { + return err + } + } + } for _, f := range gq.fields { if !group.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -808,17 +824,6 @@ func (gq *GroupQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, gq.driver, _spec) } -func (gq *GroupQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := gq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (gq *GroupQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -901,13 +906,8 @@ func (gq *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector { // GroupGroupBy is the group-by builder for Group entities. type GroupGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *GroupQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -916,58 +916,46 @@ func (ggb *GroupGroupBy) Aggregate(fns ...AggregateFunc) *GroupGroupBy { return ggb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (ggb *GroupGroupBy) Scan(ctx context.Context, v any) error { - query, err := ggb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeGroup, "GroupBy") + if err := ggb.build.prepareQuery(ctx); err != nil { return err } - ggb.sql = query - return ggb.sqlScan(ctx, v) + return scanWithInterceptors[*GroupQuery, *GroupGroupBy](ctx, ggb.build, ggb, ggb.build.inters, v) } -func (ggb *GroupGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range ggb.fields { - if !group.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (ggb *GroupGroupBy) sqlScan(ctx context.Context, root *GroupQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(ggb.fns)) + for _, fn := range ggb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := ggb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*ggb.flds)+len(ggb.fns)) + for _, f := range *ggb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*ggb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := ggb.driver.Query(ctx, query, args, rows); err != nil { + if err := ggb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (ggb *GroupGroupBy) sqlQuery() *sql.Selector { - selector := ggb.sql.Select() - aggregation := make([]string, 0, len(ggb.fns)) - for _, fn := range ggb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(ggb.fields)+len(ggb.fns)) - for _, f := range ggb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(ggb.fields...)...) -} - // GroupSelect is the builder for selecting fields of Group entities. type GroupSelect struct { *GroupQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -978,26 +966,27 @@ 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") if err := gs.prepareQuery(ctx); err != nil { return err } - gs.sql = gs.GroupQuery.sqlQuery(ctx) - return gs.sqlScan(ctx, v) + return scanWithInterceptors[*GroupQuery, *GroupSelect](ctx, gs.GroupQuery, gs, gs.inters, v) } -func (gs *GroupSelect) sqlScan(ctx context.Context, v any) error { +func (gs *GroupSelect) sqlScan(ctx context.Context, root *GroupQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(gs.fns)) for _, fn := range gs.fns { - aggregation = append(aggregation, fn(gs.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*gs.selector.flds); { case n == 0 && len(aggregation) > 0: - gs.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - gs.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := gs.sql.Query() + query, args := selector.Query() if err := gs.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/group_update.go b/backend/internal/data/ent/group_update.go index 7a9c10c..e4263bf 100644 --- a/backend/internal/data/ent/group_update.go +++ b/backend/internal/data/ent/group_update.go @@ -284,41 +284,8 @@ func (gu *GroupUpdate) RemoveInvitationTokens(g ...*GroupInvitationToken) *Group // Save executes the query and returns the number of nodes affected by the update operation. func (gu *GroupUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) gu.defaults() - if len(gu.hooks) == 0 { - if err = gu.check(); err != nil { - return 0, err - } - affected, err = gu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GroupMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = gu.check(); err != nil { - return 0, err - } - gu.mutation = mutation - affected, err = gu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(gu.hooks) - 1; i >= 0; i-- { - if gu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = gu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, gu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, GroupMutation](ctx, gu.sqlSave, gu.mutation, gu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -367,6 +334,9 @@ func (gu *GroupUpdate) check() error { } func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := gu.check(); err != nil { + return n, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: group.Table, @@ -725,6 +695,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + gu.mutation.done = true return n, nil } @@ -992,47 +963,8 @@ func (guo *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOn // Save executes the query and returns the updated Group entity. func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) { - var ( - err error - node *Group - ) guo.defaults() - if len(guo.hooks) == 0 { - if err = guo.check(); err != nil { - return nil, err - } - node, err = guo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GroupMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = guo.check(); err != nil { - return nil, err - } - guo.mutation = mutation - node, err = guo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(guo.hooks) - 1; i >= 0; i-- { - if guo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = guo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, guo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Group) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from GroupMutation", v) - } - node = nv - } - return node, err + return withHooks[*Group, GroupMutation](ctx, guo.sqlSave, guo.mutation, guo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -1081,6 +1013,9 @@ func (guo *GroupUpdateOne) check() error { } func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) { + if err := guo.check(); err != nil { + return _node, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: group.Table, @@ -1459,5 +1394,6 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error } return nil, err } + guo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/groupinvitationtoken/where.go b/backend/internal/data/ent/groupinvitationtoken/where.go index bf4ccaa..2d81adc 100644 --- a/backend/internal/data/ent/groupinvitationtoken/where.go +++ b/backend/internal/data/ent/groupinvitationtoken/where.go @@ -13,428 +13,272 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.GroupInvitationToken(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.GroupInvitationToken(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.GroupInvitationToken(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.GroupInvitationToken(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.GroupInvitationToken(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldUpdatedAt, v)) } // Token applies equality check predicate on the "token" field. It's identical to TokenEQ. func Token(v []byte) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldToken), v)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldToken, v)) } // ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ. func ExpiresAt(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiresAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldExpiresAt, v)) } // Uses applies equality check predicate on the "uses" field. It's identical to UsesEQ. func Uses(v int) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUses), v)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldUses, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.GroupInvitationToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.GroupInvitationToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.GroupInvitationToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.GroupInvitationToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldLTE(FieldUpdatedAt, v)) } // TokenEQ applies the EQ predicate on the "token" field. func TokenEQ(v []byte) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldToken), v)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldToken, v)) } // TokenNEQ applies the NEQ predicate on the "token" field. func TokenNEQ(v []byte) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldToken), v)) - }) + return predicate.GroupInvitationToken(sql.FieldNEQ(FieldToken, v)) } // TokenIn applies the In predicate on the "token" field. func TokenIn(vs ...[]byte) predicate.GroupInvitationToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldToken), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldIn(FieldToken, vs...)) } // TokenNotIn applies the NotIn predicate on the "token" field. func TokenNotIn(vs ...[]byte) predicate.GroupInvitationToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldToken), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldNotIn(FieldToken, vs...)) } // TokenGT applies the GT predicate on the "token" field. func TokenGT(v []byte) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldToken), v)) - }) + return predicate.GroupInvitationToken(sql.FieldGT(FieldToken, v)) } // TokenGTE applies the GTE predicate on the "token" field. func TokenGTE(v []byte) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldToken), v)) - }) + return predicate.GroupInvitationToken(sql.FieldGTE(FieldToken, v)) } // TokenLT applies the LT predicate on the "token" field. func TokenLT(v []byte) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldToken), v)) - }) + return predicate.GroupInvitationToken(sql.FieldLT(FieldToken, v)) } // TokenLTE applies the LTE predicate on the "token" field. func TokenLTE(v []byte) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldToken), v)) - }) + return predicate.GroupInvitationToken(sql.FieldLTE(FieldToken, v)) } // ExpiresAtEQ applies the EQ predicate on the "expires_at" field. func ExpiresAtEQ(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiresAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldExpiresAt, v)) } // ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field. func ExpiresAtNEQ(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldExpiresAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldNEQ(FieldExpiresAt, v)) } // ExpiresAtIn applies the In predicate on the "expires_at" field. func ExpiresAtIn(vs ...time.Time) predicate.GroupInvitationToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldExpiresAt), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldIn(FieldExpiresAt, vs...)) } // ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field. func ExpiresAtNotIn(vs ...time.Time) predicate.GroupInvitationToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldExpiresAt), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldNotIn(FieldExpiresAt, vs...)) } // ExpiresAtGT applies the GT predicate on the "expires_at" field. func ExpiresAtGT(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldExpiresAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldGT(FieldExpiresAt, v)) } // ExpiresAtGTE applies the GTE predicate on the "expires_at" field. func ExpiresAtGTE(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldExpiresAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldGTE(FieldExpiresAt, v)) } // ExpiresAtLT applies the LT predicate on the "expires_at" field. func ExpiresAtLT(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldExpiresAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldLT(FieldExpiresAt, v)) } // ExpiresAtLTE applies the LTE predicate on the "expires_at" field. func ExpiresAtLTE(v time.Time) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldExpiresAt), v)) - }) + return predicate.GroupInvitationToken(sql.FieldLTE(FieldExpiresAt, v)) } // UsesEQ applies the EQ predicate on the "uses" field. func UsesEQ(v int) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUses), v)) - }) + return predicate.GroupInvitationToken(sql.FieldEQ(FieldUses, v)) } // UsesNEQ applies the NEQ predicate on the "uses" field. func UsesNEQ(v int) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUses), v)) - }) + return predicate.GroupInvitationToken(sql.FieldNEQ(FieldUses, v)) } // UsesIn applies the In predicate on the "uses" field. func UsesIn(vs ...int) predicate.GroupInvitationToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUses), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldIn(FieldUses, vs...)) } // UsesNotIn applies the NotIn predicate on the "uses" field. func UsesNotIn(vs ...int) predicate.GroupInvitationToken { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUses), v...)) - }) + return predicate.GroupInvitationToken(sql.FieldNotIn(FieldUses, vs...)) } // UsesGT applies the GT predicate on the "uses" field. func UsesGT(v int) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUses), v)) - }) + return predicate.GroupInvitationToken(sql.FieldGT(FieldUses, v)) } // UsesGTE applies the GTE predicate on the "uses" field. func UsesGTE(v int) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUses), v)) - }) + return predicate.GroupInvitationToken(sql.FieldGTE(FieldUses, v)) } // UsesLT applies the LT predicate on the "uses" field. func UsesLT(v int) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUses), v)) - }) + return predicate.GroupInvitationToken(sql.FieldLT(FieldUses, v)) } // UsesLTE applies the LTE predicate on the "uses" field. func UsesLTE(v int) predicate.GroupInvitationToken { - return predicate.GroupInvitationToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUses), v)) - }) + return predicate.GroupInvitationToken(sql.FieldLTE(FieldUses, v)) } // HasGroup applies the HasEdge predicate on the "group" edge. @@ -442,7 +286,6 @@ func HasGroup() predicate.GroupInvitationToken { return predicate.GroupInvitationToken(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/groupinvitationtoken_create.go b/backend/internal/data/ent/groupinvitationtoken_create.go index 05f669e..01cd1c8 100644 --- a/backend/internal/data/ent/groupinvitationtoken_create.go +++ b/backend/internal/data/ent/groupinvitationtoken_create.go @@ -124,50 +124,8 @@ func (gitc *GroupInvitationTokenCreate) Mutation() *GroupInvitationTokenMutation // Save creates the GroupInvitationToken in the database. func (gitc *GroupInvitationTokenCreate) Save(ctx context.Context) (*GroupInvitationToken, error) { - var ( - err error - node *GroupInvitationToken - ) gitc.defaults() - if len(gitc.hooks) == 0 { - if err = gitc.check(); err != nil { - return nil, err - } - node, err = gitc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GroupInvitationTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = gitc.check(); err != nil { - return nil, err - } - gitc.mutation = mutation - if node, err = gitc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(gitc.hooks) - 1; i >= 0; i-- { - if gitc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = gitc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, gitc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*GroupInvitationToken) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from GroupInvitationTokenMutation", v) - } - node = nv - } - return node, err + return withHooks[*GroupInvitationToken, GroupInvitationTokenMutation](ctx, gitc.sqlSave, gitc.mutation, gitc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -237,6 +195,9 @@ func (gitc *GroupInvitationTokenCreate) check() error { } func (gitc *GroupInvitationTokenCreate) sqlSave(ctx context.Context) (*GroupInvitationToken, error) { + if err := gitc.check(); err != nil { + return nil, err + } _node, _spec := gitc.createSpec() if err := sqlgraph.CreateNode(ctx, gitc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -251,6 +212,8 @@ func (gitc *GroupInvitationTokenCreate) sqlSave(ctx context.Context) (*GroupInvi return nil, err } } + gitc.mutation.id = &_node.ID + gitc.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/groupinvitationtoken_delete.go b/backend/internal/data/ent/groupinvitationtoken_delete.go index 4fa2ceb..1da616e 100644 --- a/backend/internal/data/ent/groupinvitationtoken_delete.go +++ b/backend/internal/data/ent/groupinvitationtoken_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (gitd *GroupInvitationTokenDelete) Where(ps ...predicate.GroupInvitationTok // Exec executes the deletion query and returns how many vertices were deleted. func (gitd *GroupInvitationTokenDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(gitd.hooks) == 0 { - affected, err = gitd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GroupInvitationTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - gitd.mutation = mutation - affected, err = gitd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(gitd.hooks) - 1; i >= 0; i-- { - if gitd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = gitd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, gitd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, GroupInvitationTokenMutation](ctx, gitd.sqlExec, gitd.mutation, gitd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (gitd *GroupInvitationTokenDelete) sqlExec(ctx context.Context) (int, error if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + gitd.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/groupinvitationtoken_query.go b/backend/internal/data/ent/groupinvitationtoken_query.go index 37f8a25..8c84dca 100644 --- a/backend/internal/data/ent/groupinvitationtoken_query.go +++ b/backend/internal/data/ent/groupinvitationtoken_query.go @@ -24,6 +24,7 @@ type GroupInvitationTokenQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.GroupInvitationToken withGroup *GroupQuery withFKs bool @@ -38,13 +39,13 @@ func (gitq *GroupInvitationTokenQuery) Where(ps ...predicate.GroupInvitationToke return gitq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (gitq *GroupInvitationTokenQuery) Limit(limit int) *GroupInvitationTokenQuery { gitq.limit = &limit return gitq } -// Offset adds an offset step to the query. +// Offset to start from. func (gitq *GroupInvitationTokenQuery) Offset(offset int) *GroupInvitationTokenQuery { gitq.offset = &offset return gitq @@ -57,7 +58,7 @@ func (gitq *GroupInvitationTokenQuery) Unique(unique bool) *GroupInvitationToken return gitq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (gitq *GroupInvitationTokenQuery) Order(o ...OrderFunc) *GroupInvitationTokenQuery { gitq.order = append(gitq.order, o...) return gitq @@ -65,7 +66,7 @@ func (gitq *GroupInvitationTokenQuery) Order(o ...OrderFunc) *GroupInvitationTok // QueryGroup chains the current query on the "group" edge. func (gitq *GroupInvitationTokenQuery) QueryGroup() *GroupQuery { - query := &GroupQuery{config: gitq.config} + query := (&GroupClient{config: gitq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := gitq.prepareQuery(ctx); err != nil { return nil, err @@ -88,7 +89,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(ctx) + nodes, err := gitq.Limit(1).All(newQueryContext(ctx, TypeGroupInvitationToken, "First")) if err != nil { return nil, err } @@ -111,7 +112,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(ctx); err != nil { + if ids, err = gitq.Limit(1).IDs(newQueryContext(ctx, TypeGroupInvitationToken, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -134,7 +135,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(ctx) + nodes, err := gitq.Limit(2).All(newQueryContext(ctx, TypeGroupInvitationToken, "Only")) if err != nil { return nil, err } @@ -162,7 +163,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(ctx); err != nil { + if ids, err = gitq.Limit(2).IDs(newQueryContext(ctx, TypeGroupInvitationToken, "OnlyID")); err != nil { return } switch len(ids) { @@ -187,10 +188,12 @@ 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") if err := gitq.prepareQuery(ctx); err != nil { return nil, err } - return gitq.sqlAll(ctx) + qr := querierAll[[]*GroupInvitationToken, *GroupInvitationTokenQuery]() + return withInterceptors[[]*GroupInvitationToken](ctx, gitq, qr, gitq.inters) } // AllX is like All, but panics if an error occurs. @@ -205,6 +208,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") if err := gitq.Select(groupinvitationtoken.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -222,10 +226,11 @@ 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") if err := gitq.prepareQuery(ctx); err != nil { return 0, err } - return gitq.sqlCount(ctx) + return withInterceptors[int](ctx, gitq, querierCount[*GroupInvitationTokenQuery](), gitq.inters) } // CountX is like Count, but panics if an error occurs. @@ -239,10 +244,15 @@ 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) { - if err := gitq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeGroupInvitationToken, "Exist") + switch _, err := gitq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return gitq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -265,6 +275,7 @@ func (gitq *GroupInvitationTokenQuery) Clone() *GroupInvitationTokenQuery { limit: gitq.limit, offset: gitq.offset, order: append([]OrderFunc{}, gitq.order...), + inters: append([]Interceptor{}, gitq.inters...), predicates: append([]predicate.GroupInvitationToken{}, gitq.predicates...), withGroup: gitq.withGroup.Clone(), // clone intermediate query. @@ -277,7 +288,7 @@ func (gitq *GroupInvitationTokenQuery) Clone() *GroupInvitationTokenQuery { // WithGroup tells the query-builder to eager-load the nodes that are connected to // the "group" edge. The optional arguments are used to configure the query builder of the edge. func (gitq *GroupInvitationTokenQuery) WithGroup(opts ...func(*GroupQuery)) *GroupInvitationTokenQuery { - query := &GroupQuery{config: gitq.config} + query := (&GroupClient{config: gitq.config}).Query() for _, opt := range opts { opt(query) } @@ -300,16 +311,11 @@ func (gitq *GroupInvitationTokenQuery) WithGroup(opts ...func(*GroupQuery)) *Gro // Aggregate(ent.Count()). // Scan(ctx, &v) func (gitq *GroupInvitationTokenQuery) GroupBy(field string, fields ...string) *GroupInvitationTokenGroupBy { - grbuild := &GroupInvitationTokenGroupBy{config: gitq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := gitq.prepareQuery(ctx); err != nil { - return nil, err - } - return gitq.sqlQuery(ctx), nil - } + gitq.fields = append([]string{field}, fields...) + grbuild := &GroupInvitationTokenGroupBy{build: gitq} + grbuild.flds = &gitq.fields grbuild.label = groupinvitationtoken.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -327,10 +333,10 @@ func (gitq *GroupInvitationTokenQuery) GroupBy(field string, fields ...string) * // Scan(ctx, &v) func (gitq *GroupInvitationTokenQuery) Select(fields ...string) *GroupInvitationTokenSelect { gitq.fields = append(gitq.fields, fields...) - selbuild := &GroupInvitationTokenSelect{GroupInvitationTokenQuery: gitq} - selbuild.label = groupinvitationtoken.Label - selbuild.flds, selbuild.scan = &gitq.fields, selbuild.Scan - return selbuild + sbuild := &GroupInvitationTokenSelect{GroupInvitationTokenQuery: gitq} + sbuild.label = groupinvitationtoken.Label + sbuild.flds, sbuild.scan = &gitq.fields, sbuild.Scan + return sbuild } // Aggregate returns a GroupInvitationTokenSelect configured with the given aggregations. @@ -339,6 +345,16 @@ func (gitq *GroupInvitationTokenQuery) Aggregate(fns ...AggregateFunc) *GroupInv } func (gitq *GroupInvitationTokenQuery) prepareQuery(ctx context.Context) error { + for _, inter := range gitq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, gitq); err != nil { + return err + } + } + } for _, f := range gitq.fields { if !groupinvitationtoken.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -435,17 +451,6 @@ func (gitq *GroupInvitationTokenQuery) sqlCount(ctx context.Context) (int, error return sqlgraph.CountNodes(ctx, gitq.driver, _spec) } -func (gitq *GroupInvitationTokenQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := gitq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (gitq *GroupInvitationTokenQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -528,13 +533,8 @@ func (gitq *GroupInvitationTokenQuery) sqlQuery(ctx context.Context) *sql.Select // GroupInvitationTokenGroupBy is the group-by builder for GroupInvitationToken entities. type GroupInvitationTokenGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *GroupInvitationTokenQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -543,58 +543,46 @@ func (gitgb *GroupInvitationTokenGroupBy) Aggregate(fns ...AggregateFunc) *Group return gitgb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (gitgb *GroupInvitationTokenGroupBy) Scan(ctx context.Context, v any) error { - query, err := gitgb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeGroupInvitationToken, "GroupBy") + if err := gitgb.build.prepareQuery(ctx); err != nil { return err } - gitgb.sql = query - return gitgb.sqlScan(ctx, v) + return scanWithInterceptors[*GroupInvitationTokenQuery, *GroupInvitationTokenGroupBy](ctx, gitgb.build, gitgb, gitgb.build.inters, v) } -func (gitgb *GroupInvitationTokenGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range gitgb.fields { - if !groupinvitationtoken.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (gitgb *GroupInvitationTokenGroupBy) sqlScan(ctx context.Context, root *GroupInvitationTokenQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(gitgb.fns)) + for _, fn := range gitgb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := gitgb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*gitgb.flds)+len(gitgb.fns)) + for _, f := range *gitgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*gitgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := gitgb.driver.Query(ctx, query, args, rows); err != nil { + if err := gitgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (gitgb *GroupInvitationTokenGroupBy) sqlQuery() *sql.Selector { - selector := gitgb.sql.Select() - aggregation := make([]string, 0, len(gitgb.fns)) - for _, fn := range gitgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(gitgb.fields)+len(gitgb.fns)) - for _, f := range gitgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(gitgb.fields...)...) -} - // GroupInvitationTokenSelect is the builder for selecting fields of GroupInvitationToken entities. type GroupInvitationTokenSelect struct { *GroupInvitationTokenQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -605,26 +593,27 @@ 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") if err := gits.prepareQuery(ctx); err != nil { return err } - gits.sql = gits.GroupInvitationTokenQuery.sqlQuery(ctx) - return gits.sqlScan(ctx, v) + return scanWithInterceptors[*GroupInvitationTokenQuery, *GroupInvitationTokenSelect](ctx, gits.GroupInvitationTokenQuery, gits, gits.inters, v) } -func (gits *GroupInvitationTokenSelect) sqlScan(ctx context.Context, v any) error { +func (gits *GroupInvitationTokenSelect) sqlScan(ctx context.Context, root *GroupInvitationTokenQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(gits.fns)) for _, fn := range gits.fns { - aggregation = append(aggregation, fn(gits.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*gits.selector.flds); { case n == 0 && len(aggregation) > 0: - gits.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - gits.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := gits.sql.Query() + query, args := selector.Query() if err := gits.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/groupinvitationtoken_update.go b/backend/internal/data/ent/groupinvitationtoken_update.go index 6d26aaa..ac7cfd2 100644 --- a/backend/internal/data/ent/groupinvitationtoken_update.go +++ b/backend/internal/data/ent/groupinvitationtoken_update.go @@ -109,35 +109,8 @@ func (gitu *GroupInvitationTokenUpdate) ClearGroup() *GroupInvitationTokenUpdate // Save executes the query and returns the number of nodes affected by the update operation. func (gitu *GroupInvitationTokenUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) gitu.defaults() - if len(gitu.hooks) == 0 { - affected, err = gitu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GroupInvitationTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - gitu.mutation = mutation - affected, err = gitu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(gitu.hooks) - 1; i >= 0; i-- { - if gitu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = gitu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, gitu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, GroupInvitationTokenMutation](ctx, gitu.sqlSave, gitu.mutation, gitu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -246,6 +219,7 @@ func (gitu *GroupInvitationTokenUpdate) sqlSave(ctx context.Context) (n int, err } return 0, err } + gitu.mutation.done = true return n, nil } @@ -343,41 +317,8 @@ func (gituo *GroupInvitationTokenUpdateOne) Select(field string, fields ...strin // Save executes the query and returns the updated GroupInvitationToken entity. func (gituo *GroupInvitationTokenUpdateOne) Save(ctx context.Context) (*GroupInvitationToken, error) { - var ( - err error - node *GroupInvitationToken - ) gituo.defaults() - if len(gituo.hooks) == 0 { - node, err = gituo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GroupInvitationTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - gituo.mutation = mutation - node, err = gituo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(gituo.hooks) - 1; i >= 0; i-- { - if gituo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = gituo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, gituo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*GroupInvitationToken) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from GroupInvitationTokenMutation", v) - } - node = nv - } - return node, err + return withHooks[*GroupInvitationToken, GroupInvitationTokenMutation](ctx, gituo.sqlSave, gituo.mutation, gituo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -506,5 +447,6 @@ func (gituo *GroupInvitationTokenUpdateOne) sqlSave(ctx context.Context) (_node } return nil, err } + gituo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/hook/hook.go b/backend/internal/data/ent/hook/hook.go index 08c9401..f4fb2ca 100644 --- a/backend/internal/data/ent/hook/hook.go +++ b/backend/internal/data/ent/hook/hook.go @@ -15,11 +15,10 @@ type AttachmentFunc func(context.Context, *ent.AttachmentMutation) (ent.Value, e // Mutate calls f(ctx, m). func (f AttachmentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.AttachmentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AttachmentMutation", m) + if mv, ok := m.(*ent.AttachmentMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AttachmentMutation", m) } // The AuthRolesFunc type is an adapter to allow the use of ordinary @@ -28,11 +27,10 @@ type AuthRolesFunc func(context.Context, *ent.AuthRolesMutation) (ent.Value, err // Mutate calls f(ctx, m). func (f AuthRolesFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.AuthRolesMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AuthRolesMutation", m) + if mv, ok := m.(*ent.AuthRolesMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AuthRolesMutation", m) } // The AuthTokensFunc type is an adapter to allow the use of ordinary @@ -41,11 +39,10 @@ type AuthTokensFunc func(context.Context, *ent.AuthTokensMutation) (ent.Value, e // Mutate calls f(ctx, m). func (f AuthTokensFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.AuthTokensMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AuthTokensMutation", m) + if mv, ok := m.(*ent.AuthTokensMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AuthTokensMutation", m) } // The DocumentFunc type is an adapter to allow the use of ordinary @@ -54,11 +51,10 @@ type DocumentFunc func(context.Context, *ent.DocumentMutation) (ent.Value, error // Mutate calls f(ctx, m). func (f DocumentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.DocumentMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DocumentMutation", m) + if mv, ok := m.(*ent.DocumentMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DocumentMutation", m) } // The GroupFunc type is an adapter to allow the use of ordinary @@ -67,11 +63,10 @@ type GroupFunc func(context.Context, *ent.GroupMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f GroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.GroupMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GroupMutation", m) + if mv, ok := m.(*ent.GroupMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GroupMutation", m) } // The GroupInvitationTokenFunc type is an adapter to allow the use of ordinary @@ -80,11 +75,10 @@ type GroupInvitationTokenFunc func(context.Context, *ent.GroupInvitationTokenMut // Mutate calls f(ctx, m). func (f GroupInvitationTokenFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.GroupInvitationTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GroupInvitationTokenMutation", m) + if mv, ok := m.(*ent.GroupInvitationTokenMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GroupInvitationTokenMutation", m) } // The ItemFunc type is an adapter to allow the use of ordinary @@ -93,11 +87,10 @@ type ItemFunc func(context.Context, *ent.ItemMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f ItemFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.ItemMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ItemMutation", m) + if mv, ok := m.(*ent.ItemMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ItemMutation", m) } // The ItemFieldFunc type is an adapter to allow the use of ordinary @@ -106,11 +99,10 @@ type ItemFieldFunc func(context.Context, *ent.ItemFieldMutation) (ent.Value, err // Mutate calls f(ctx, m). func (f ItemFieldFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.ItemFieldMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ItemFieldMutation", m) + if mv, ok := m.(*ent.ItemFieldMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ItemFieldMutation", m) } // The LabelFunc type is an adapter to allow the use of ordinary @@ -119,11 +111,10 @@ type LabelFunc func(context.Context, *ent.LabelMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f LabelFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.LabelMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LabelMutation", m) + if mv, ok := m.(*ent.LabelMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LabelMutation", m) } // The LocationFunc type is an adapter to allow the use of ordinary @@ -132,11 +123,10 @@ type LocationFunc func(context.Context, *ent.LocationMutation) (ent.Value, error // Mutate calls f(ctx, m). func (f LocationFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.LocationMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LocationMutation", m) + if mv, ok := m.(*ent.LocationMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LocationMutation", m) } // The MaintenanceEntryFunc type is an adapter to allow the use of ordinary @@ -145,11 +135,10 @@ type MaintenanceEntryFunc func(context.Context, *ent.MaintenanceEntryMutation) ( // Mutate calls f(ctx, m). func (f MaintenanceEntryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.MaintenanceEntryMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MaintenanceEntryMutation", m) + if mv, ok := m.(*ent.MaintenanceEntryMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MaintenanceEntryMutation", m) } // The UserFunc type is an adapter to allow the use of ordinary @@ -158,11 +147,10 @@ type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m) + if mv, ok := m.(*ent.UserMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m) } // Condition is a hook condition function. diff --git a/backend/internal/data/ent/item/where.go b/backend/internal/data/ent/item/where.go index cef11f4..e57536e 100644 --- a/backend/internal/data/ent/item/where.go +++ b/backend/internal/data/ent/item/where.go @@ -13,2123 +13,1397 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Item(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Item(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Item(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.Item(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Item(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Item(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Item(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Item(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Item(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Item(sql.FieldEQ(FieldUpdatedAt, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldEQ(FieldName, v)) } // Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. func Description(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldEQ(FieldDescription, v)) } // ImportRef applies equality check predicate on the "import_ref" field. It's identical to ImportRefEQ. func ImportRef(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldEQ(FieldImportRef, v)) } // Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ. func Notes(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldEQ(FieldNotes, v)) } // Quantity applies equality check predicate on the "quantity" field. It's identical to QuantityEQ. func Quantity(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldQuantity), v)) - }) + return predicate.Item(sql.FieldEQ(FieldQuantity, v)) } // Insured applies equality check predicate on the "insured" field. It's identical to InsuredEQ. func Insured(v bool) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldInsured), v)) - }) + return predicate.Item(sql.FieldEQ(FieldInsured, v)) } // Archived applies equality check predicate on the "archived" field. It's identical to ArchivedEQ. func Archived(v bool) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldArchived), v)) - }) + return predicate.Item(sql.FieldEQ(FieldArchived, v)) } // AssetID applies equality check predicate on the "asset_id" field. It's identical to AssetIDEQ. func AssetID(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldAssetID), v)) - }) + return predicate.Item(sql.FieldEQ(FieldAssetID, v)) } // SerialNumber applies equality check predicate on the "serial_number" field. It's identical to SerialNumberEQ. func SerialNumber(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldEQ(FieldSerialNumber, v)) } // ModelNumber applies equality check predicate on the "model_number" field. It's identical to ModelNumberEQ. func ModelNumber(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldEQ(FieldModelNumber, v)) } // Manufacturer applies equality check predicate on the "manufacturer" field. It's identical to ManufacturerEQ. func Manufacturer(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldEQ(FieldManufacturer, v)) } // LifetimeWarranty applies equality check predicate on the "lifetime_warranty" field. It's identical to LifetimeWarrantyEQ. func LifetimeWarranty(v bool) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLifetimeWarranty), v)) - }) + return predicate.Item(sql.FieldEQ(FieldLifetimeWarranty, v)) } // WarrantyExpires applies equality check predicate on the "warranty_expires" field. It's identical to WarrantyExpiresEQ. func WarrantyExpires(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldWarrantyExpires), v)) - }) + return predicate.Item(sql.FieldEQ(FieldWarrantyExpires, v)) } // WarrantyDetails applies equality check predicate on the "warranty_details" field. It's identical to WarrantyDetailsEQ. func WarrantyDetails(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldEQ(FieldWarrantyDetails, v)) } // PurchaseTime applies equality check predicate on the "purchase_time" field. It's identical to PurchaseTimeEQ. func PurchaseTime(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPurchaseTime), v)) - }) + return predicate.Item(sql.FieldEQ(FieldPurchaseTime, v)) } // PurchaseFrom applies equality check predicate on the "purchase_from" field. It's identical to PurchaseFromEQ. func PurchaseFrom(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldEQ(FieldPurchaseFrom, v)) } // PurchasePrice applies equality check predicate on the "purchase_price" field. It's identical to PurchasePriceEQ. func PurchasePrice(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPurchasePrice), v)) - }) + return predicate.Item(sql.FieldEQ(FieldPurchasePrice, v)) } // SoldTime applies equality check predicate on the "sold_time" field. It's identical to SoldTimeEQ. func SoldTime(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSoldTime), v)) - }) + return predicate.Item(sql.FieldEQ(FieldSoldTime, v)) } // SoldTo applies equality check predicate on the "sold_to" field. It's identical to SoldToEQ. func SoldTo(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldEQ(FieldSoldTo, v)) } // SoldPrice applies equality check predicate on the "sold_price" field. It's identical to SoldPriceEQ. func SoldPrice(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSoldPrice), v)) - }) + return predicate.Item(sql.FieldEQ(FieldSoldPrice, v)) } // SoldNotes applies equality check predicate on the "sold_notes" field. It's identical to SoldNotesEQ. func SoldNotes(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldEQ(FieldSoldNotes, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Item(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.Item(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.Item(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Item(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.Item(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Item(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Item(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Item(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Item(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Item(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Item(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Item(sql.FieldLTE(FieldUpdatedAt, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.Item(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldName, v)) } // DescriptionEQ applies the EQ predicate on the "description" field. func DescriptionEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldEQ(FieldDescription, v)) } // DescriptionNEQ applies the NEQ predicate on the "description" field. func DescriptionNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldDescription, v)) } // DescriptionIn applies the In predicate on the "description" field. func DescriptionIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldDescription), v...)) - }) + return predicate.Item(sql.FieldIn(FieldDescription, vs...)) } // DescriptionNotIn applies the NotIn predicate on the "description" field. func DescriptionNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldDescription), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldDescription, vs...)) } // DescriptionGT applies the GT predicate on the "description" field. func DescriptionGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldGT(FieldDescription, v)) } // DescriptionGTE applies the GTE predicate on the "description" field. func DescriptionGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldGTE(FieldDescription, v)) } // DescriptionLT applies the LT predicate on the "description" field. func DescriptionLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldLT(FieldDescription, v)) } // DescriptionLTE applies the LTE predicate on the "description" field. func DescriptionLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldLTE(FieldDescription, v)) } // DescriptionContains applies the Contains predicate on the "description" field. func DescriptionContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldContains(FieldDescription, v)) } // DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. func DescriptionHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldDescription, v)) } // DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. func DescriptionHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldDescription, v)) } // DescriptionIsNil applies the IsNil predicate on the "description" field. func DescriptionIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldDescription))) - }) + return predicate.Item(sql.FieldIsNull(FieldDescription)) } // DescriptionNotNil applies the NotNil predicate on the "description" field. func DescriptionNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldDescription))) - }) + return predicate.Item(sql.FieldNotNull(FieldDescription)) } // DescriptionEqualFold applies the EqualFold predicate on the "description" field. func DescriptionEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldDescription, v)) } // DescriptionContainsFold applies the ContainsFold predicate on the "description" field. func DescriptionContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldDescription), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldDescription, v)) } // ImportRefEQ applies the EQ predicate on the "import_ref" field. func ImportRefEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldEQ(FieldImportRef, v)) } // ImportRefNEQ applies the NEQ predicate on the "import_ref" field. func ImportRefNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldImportRef, v)) } // ImportRefIn applies the In predicate on the "import_ref" field. func ImportRefIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldImportRef), v...)) - }) + return predicate.Item(sql.FieldIn(FieldImportRef, vs...)) } // ImportRefNotIn applies the NotIn predicate on the "import_ref" field. func ImportRefNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldImportRef), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldImportRef, vs...)) } // ImportRefGT applies the GT predicate on the "import_ref" field. func ImportRefGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldGT(FieldImportRef, v)) } // ImportRefGTE applies the GTE predicate on the "import_ref" field. func ImportRefGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldGTE(FieldImportRef, v)) } // ImportRefLT applies the LT predicate on the "import_ref" field. func ImportRefLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldLT(FieldImportRef, v)) } // ImportRefLTE applies the LTE predicate on the "import_ref" field. func ImportRefLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldLTE(FieldImportRef, v)) } // ImportRefContains applies the Contains predicate on the "import_ref" field. func ImportRefContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldContains(FieldImportRef, v)) } // ImportRefHasPrefix applies the HasPrefix predicate on the "import_ref" field. func ImportRefHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldImportRef, v)) } // ImportRefHasSuffix applies the HasSuffix predicate on the "import_ref" field. func ImportRefHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldImportRef, v)) } // ImportRefIsNil applies the IsNil predicate on the "import_ref" field. func ImportRefIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldImportRef))) - }) + return predicate.Item(sql.FieldIsNull(FieldImportRef)) } // ImportRefNotNil applies the NotNil predicate on the "import_ref" field. func ImportRefNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldImportRef))) - }) + return predicate.Item(sql.FieldNotNull(FieldImportRef)) } // ImportRefEqualFold applies the EqualFold predicate on the "import_ref" field. func ImportRefEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldImportRef, v)) } // ImportRefContainsFold applies the ContainsFold predicate on the "import_ref" field. func ImportRefContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldImportRef), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldImportRef, v)) } // NotesEQ applies the EQ predicate on the "notes" field. func NotesEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldEQ(FieldNotes, v)) } // NotesNEQ applies the NEQ predicate on the "notes" field. func NotesNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldNotes, v)) } // NotesIn applies the In predicate on the "notes" field. func NotesIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldNotes), v...)) - }) + return predicate.Item(sql.FieldIn(FieldNotes, vs...)) } // NotesNotIn applies the NotIn predicate on the "notes" field. func NotesNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldNotes), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldNotes, vs...)) } // NotesGT applies the GT predicate on the "notes" field. func NotesGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldGT(FieldNotes, v)) } // NotesGTE applies the GTE predicate on the "notes" field. func NotesGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldGTE(FieldNotes, v)) } // NotesLT applies the LT predicate on the "notes" field. func NotesLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldLT(FieldNotes, v)) } // NotesLTE applies the LTE predicate on the "notes" field. func NotesLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldLTE(FieldNotes, v)) } // NotesContains applies the Contains predicate on the "notes" field. func NotesContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldContains(FieldNotes, v)) } // NotesHasPrefix applies the HasPrefix predicate on the "notes" field. func NotesHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldNotes, v)) } // NotesHasSuffix applies the HasSuffix predicate on the "notes" field. func NotesHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldNotes, v)) } // NotesIsNil applies the IsNil predicate on the "notes" field. func NotesIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldNotes))) - }) + return predicate.Item(sql.FieldIsNull(FieldNotes)) } // NotesNotNil applies the NotNil predicate on the "notes" field. func NotesNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldNotes))) - }) + return predicate.Item(sql.FieldNotNull(FieldNotes)) } // NotesEqualFold applies the EqualFold predicate on the "notes" field. func NotesEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldNotes, v)) } // NotesContainsFold applies the ContainsFold predicate on the "notes" field. func NotesContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldNotes), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldNotes, v)) } // QuantityEQ applies the EQ predicate on the "quantity" field. func QuantityEQ(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldQuantity), v)) - }) + return predicate.Item(sql.FieldEQ(FieldQuantity, v)) } // QuantityNEQ applies the NEQ predicate on the "quantity" field. func QuantityNEQ(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldQuantity), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldQuantity, v)) } // QuantityIn applies the In predicate on the "quantity" field. func QuantityIn(vs ...int) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldQuantity), v...)) - }) + return predicate.Item(sql.FieldIn(FieldQuantity, vs...)) } // QuantityNotIn applies the NotIn predicate on the "quantity" field. func QuantityNotIn(vs ...int) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldQuantity), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldQuantity, vs...)) } // QuantityGT applies the GT predicate on the "quantity" field. func QuantityGT(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldQuantity), v)) - }) + return predicate.Item(sql.FieldGT(FieldQuantity, v)) } // QuantityGTE applies the GTE predicate on the "quantity" field. func QuantityGTE(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldQuantity), v)) - }) + return predicate.Item(sql.FieldGTE(FieldQuantity, v)) } // QuantityLT applies the LT predicate on the "quantity" field. func QuantityLT(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldQuantity), v)) - }) + return predicate.Item(sql.FieldLT(FieldQuantity, v)) } // QuantityLTE applies the LTE predicate on the "quantity" field. func QuantityLTE(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldQuantity), v)) - }) + return predicate.Item(sql.FieldLTE(FieldQuantity, v)) } // InsuredEQ applies the EQ predicate on the "insured" field. func InsuredEQ(v bool) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldInsured), v)) - }) + return predicate.Item(sql.FieldEQ(FieldInsured, v)) } // InsuredNEQ applies the NEQ predicate on the "insured" field. func InsuredNEQ(v bool) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldInsured), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldInsured, v)) } // ArchivedEQ applies the EQ predicate on the "archived" field. func ArchivedEQ(v bool) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldArchived), v)) - }) + return predicate.Item(sql.FieldEQ(FieldArchived, v)) } // ArchivedNEQ applies the NEQ predicate on the "archived" field. func ArchivedNEQ(v bool) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldArchived), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldArchived, v)) } // AssetIDEQ applies the EQ predicate on the "asset_id" field. func AssetIDEQ(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldAssetID), v)) - }) + return predicate.Item(sql.FieldEQ(FieldAssetID, v)) } // AssetIDNEQ applies the NEQ predicate on the "asset_id" field. func AssetIDNEQ(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldAssetID), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldAssetID, v)) } // AssetIDIn applies the In predicate on the "asset_id" field. func AssetIDIn(vs ...int) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldAssetID), v...)) - }) + return predicate.Item(sql.FieldIn(FieldAssetID, vs...)) } // AssetIDNotIn applies the NotIn predicate on the "asset_id" field. func AssetIDNotIn(vs ...int) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldAssetID), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldAssetID, vs...)) } // AssetIDGT applies the GT predicate on the "asset_id" field. func AssetIDGT(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldAssetID), v)) - }) + return predicate.Item(sql.FieldGT(FieldAssetID, v)) } // AssetIDGTE applies the GTE predicate on the "asset_id" field. func AssetIDGTE(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldAssetID), v)) - }) + return predicate.Item(sql.FieldGTE(FieldAssetID, v)) } // AssetIDLT applies the LT predicate on the "asset_id" field. func AssetIDLT(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldAssetID), v)) - }) + return predicate.Item(sql.FieldLT(FieldAssetID, v)) } // AssetIDLTE applies the LTE predicate on the "asset_id" field. func AssetIDLTE(v int) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldAssetID), v)) - }) + return predicate.Item(sql.FieldLTE(FieldAssetID, v)) } // SerialNumberEQ applies the EQ predicate on the "serial_number" field. func SerialNumberEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldEQ(FieldSerialNumber, v)) } // SerialNumberNEQ applies the NEQ predicate on the "serial_number" field. func SerialNumberNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldSerialNumber, v)) } // SerialNumberIn applies the In predicate on the "serial_number" field. func SerialNumberIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldSerialNumber), v...)) - }) + return predicate.Item(sql.FieldIn(FieldSerialNumber, vs...)) } // SerialNumberNotIn applies the NotIn predicate on the "serial_number" field. func SerialNumberNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldSerialNumber), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldSerialNumber, vs...)) } // SerialNumberGT applies the GT predicate on the "serial_number" field. func SerialNumberGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldGT(FieldSerialNumber, v)) } // SerialNumberGTE applies the GTE predicate on the "serial_number" field. func SerialNumberGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldGTE(FieldSerialNumber, v)) } // SerialNumberLT applies the LT predicate on the "serial_number" field. func SerialNumberLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldLT(FieldSerialNumber, v)) } // SerialNumberLTE applies the LTE predicate on the "serial_number" field. func SerialNumberLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldLTE(FieldSerialNumber, v)) } // SerialNumberContains applies the Contains predicate on the "serial_number" field. func SerialNumberContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldContains(FieldSerialNumber, v)) } // SerialNumberHasPrefix applies the HasPrefix predicate on the "serial_number" field. func SerialNumberHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldSerialNumber, v)) } // SerialNumberHasSuffix applies the HasSuffix predicate on the "serial_number" field. func SerialNumberHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldSerialNumber, v)) } // SerialNumberIsNil applies the IsNil predicate on the "serial_number" field. func SerialNumberIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldSerialNumber))) - }) + return predicate.Item(sql.FieldIsNull(FieldSerialNumber)) } // SerialNumberNotNil applies the NotNil predicate on the "serial_number" field. func SerialNumberNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldSerialNumber))) - }) + return predicate.Item(sql.FieldNotNull(FieldSerialNumber)) } // SerialNumberEqualFold applies the EqualFold predicate on the "serial_number" field. func SerialNumberEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldSerialNumber, v)) } // SerialNumberContainsFold applies the ContainsFold predicate on the "serial_number" field. func SerialNumberContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldSerialNumber), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldSerialNumber, v)) } // ModelNumberEQ applies the EQ predicate on the "model_number" field. func ModelNumberEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldEQ(FieldModelNumber, v)) } // ModelNumberNEQ applies the NEQ predicate on the "model_number" field. func ModelNumberNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldModelNumber, v)) } // ModelNumberIn applies the In predicate on the "model_number" field. func ModelNumberIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldModelNumber), v...)) - }) + return predicate.Item(sql.FieldIn(FieldModelNumber, vs...)) } // ModelNumberNotIn applies the NotIn predicate on the "model_number" field. func ModelNumberNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldModelNumber), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldModelNumber, vs...)) } // ModelNumberGT applies the GT predicate on the "model_number" field. func ModelNumberGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldGT(FieldModelNumber, v)) } // ModelNumberGTE applies the GTE predicate on the "model_number" field. func ModelNumberGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldGTE(FieldModelNumber, v)) } // ModelNumberLT applies the LT predicate on the "model_number" field. func ModelNumberLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldLT(FieldModelNumber, v)) } // ModelNumberLTE applies the LTE predicate on the "model_number" field. func ModelNumberLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldLTE(FieldModelNumber, v)) } // ModelNumberContains applies the Contains predicate on the "model_number" field. func ModelNumberContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldContains(FieldModelNumber, v)) } // ModelNumberHasPrefix applies the HasPrefix predicate on the "model_number" field. func ModelNumberHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldModelNumber, v)) } // ModelNumberHasSuffix applies the HasSuffix predicate on the "model_number" field. func ModelNumberHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldModelNumber, v)) } // ModelNumberIsNil applies the IsNil predicate on the "model_number" field. func ModelNumberIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldModelNumber))) - }) + return predicate.Item(sql.FieldIsNull(FieldModelNumber)) } // ModelNumberNotNil applies the NotNil predicate on the "model_number" field. func ModelNumberNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldModelNumber))) - }) + return predicate.Item(sql.FieldNotNull(FieldModelNumber)) } // ModelNumberEqualFold applies the EqualFold predicate on the "model_number" field. func ModelNumberEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldModelNumber, v)) } // ModelNumberContainsFold applies the ContainsFold predicate on the "model_number" field. func ModelNumberContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldModelNumber), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldModelNumber, v)) } // ManufacturerEQ applies the EQ predicate on the "manufacturer" field. func ManufacturerEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldEQ(FieldManufacturer, v)) } // ManufacturerNEQ applies the NEQ predicate on the "manufacturer" field. func ManufacturerNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldManufacturer, v)) } // ManufacturerIn applies the In predicate on the "manufacturer" field. func ManufacturerIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldManufacturer), v...)) - }) + return predicate.Item(sql.FieldIn(FieldManufacturer, vs...)) } // ManufacturerNotIn applies the NotIn predicate on the "manufacturer" field. func ManufacturerNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldManufacturer), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldManufacturer, vs...)) } // ManufacturerGT applies the GT predicate on the "manufacturer" field. func ManufacturerGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldGT(FieldManufacturer, v)) } // ManufacturerGTE applies the GTE predicate on the "manufacturer" field. func ManufacturerGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldGTE(FieldManufacturer, v)) } // ManufacturerLT applies the LT predicate on the "manufacturer" field. func ManufacturerLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldLT(FieldManufacturer, v)) } // ManufacturerLTE applies the LTE predicate on the "manufacturer" field. func ManufacturerLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldLTE(FieldManufacturer, v)) } // ManufacturerContains applies the Contains predicate on the "manufacturer" field. func ManufacturerContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldContains(FieldManufacturer, v)) } // ManufacturerHasPrefix applies the HasPrefix predicate on the "manufacturer" field. func ManufacturerHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldManufacturer, v)) } // ManufacturerHasSuffix applies the HasSuffix predicate on the "manufacturer" field. func ManufacturerHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldManufacturer, v)) } // ManufacturerIsNil applies the IsNil predicate on the "manufacturer" field. func ManufacturerIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldManufacturer))) - }) + return predicate.Item(sql.FieldIsNull(FieldManufacturer)) } // ManufacturerNotNil applies the NotNil predicate on the "manufacturer" field. func ManufacturerNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldManufacturer))) - }) + return predicate.Item(sql.FieldNotNull(FieldManufacturer)) } // ManufacturerEqualFold applies the EqualFold predicate on the "manufacturer" field. func ManufacturerEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldManufacturer, v)) } // ManufacturerContainsFold applies the ContainsFold predicate on the "manufacturer" field. func ManufacturerContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldManufacturer), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldManufacturer, v)) } // LifetimeWarrantyEQ applies the EQ predicate on the "lifetime_warranty" field. func LifetimeWarrantyEQ(v bool) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLifetimeWarranty), v)) - }) + return predicate.Item(sql.FieldEQ(FieldLifetimeWarranty, v)) } // LifetimeWarrantyNEQ applies the NEQ predicate on the "lifetime_warranty" field. func LifetimeWarrantyNEQ(v bool) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldLifetimeWarranty), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldLifetimeWarranty, v)) } // WarrantyExpiresEQ applies the EQ predicate on the "warranty_expires" field. func WarrantyExpiresEQ(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldWarrantyExpires), v)) - }) + return predicate.Item(sql.FieldEQ(FieldWarrantyExpires, v)) } // WarrantyExpiresNEQ applies the NEQ predicate on the "warranty_expires" field. func WarrantyExpiresNEQ(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldWarrantyExpires), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldWarrantyExpires, v)) } // WarrantyExpiresIn applies the In predicate on the "warranty_expires" field. func WarrantyExpiresIn(vs ...time.Time) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldWarrantyExpires), v...)) - }) + return predicate.Item(sql.FieldIn(FieldWarrantyExpires, vs...)) } // WarrantyExpiresNotIn applies the NotIn predicate on the "warranty_expires" field. func WarrantyExpiresNotIn(vs ...time.Time) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldWarrantyExpires), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldWarrantyExpires, vs...)) } // WarrantyExpiresGT applies the GT predicate on the "warranty_expires" field. func WarrantyExpiresGT(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldWarrantyExpires), v)) - }) + return predicate.Item(sql.FieldGT(FieldWarrantyExpires, v)) } // WarrantyExpiresGTE applies the GTE predicate on the "warranty_expires" field. func WarrantyExpiresGTE(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldWarrantyExpires), v)) - }) + return predicate.Item(sql.FieldGTE(FieldWarrantyExpires, v)) } // WarrantyExpiresLT applies the LT predicate on the "warranty_expires" field. func WarrantyExpiresLT(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldWarrantyExpires), v)) - }) + return predicate.Item(sql.FieldLT(FieldWarrantyExpires, v)) } // WarrantyExpiresLTE applies the LTE predicate on the "warranty_expires" field. func WarrantyExpiresLTE(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldWarrantyExpires), v)) - }) + return predicate.Item(sql.FieldLTE(FieldWarrantyExpires, v)) } // WarrantyExpiresIsNil applies the IsNil predicate on the "warranty_expires" field. func WarrantyExpiresIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldWarrantyExpires))) - }) + return predicate.Item(sql.FieldIsNull(FieldWarrantyExpires)) } // WarrantyExpiresNotNil applies the NotNil predicate on the "warranty_expires" field. func WarrantyExpiresNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldWarrantyExpires))) - }) + return predicate.Item(sql.FieldNotNull(FieldWarrantyExpires)) } // WarrantyDetailsEQ applies the EQ predicate on the "warranty_details" field. func WarrantyDetailsEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldEQ(FieldWarrantyDetails, v)) } // WarrantyDetailsNEQ applies the NEQ predicate on the "warranty_details" field. func WarrantyDetailsNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldWarrantyDetails, v)) } // WarrantyDetailsIn applies the In predicate on the "warranty_details" field. func WarrantyDetailsIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldWarrantyDetails), v...)) - }) + return predicate.Item(sql.FieldIn(FieldWarrantyDetails, vs...)) } // WarrantyDetailsNotIn applies the NotIn predicate on the "warranty_details" field. func WarrantyDetailsNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldWarrantyDetails), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldWarrantyDetails, vs...)) } // WarrantyDetailsGT applies the GT predicate on the "warranty_details" field. func WarrantyDetailsGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldGT(FieldWarrantyDetails, v)) } // WarrantyDetailsGTE applies the GTE predicate on the "warranty_details" field. func WarrantyDetailsGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldGTE(FieldWarrantyDetails, v)) } // WarrantyDetailsLT applies the LT predicate on the "warranty_details" field. func WarrantyDetailsLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldLT(FieldWarrantyDetails, v)) } // WarrantyDetailsLTE applies the LTE predicate on the "warranty_details" field. func WarrantyDetailsLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldLTE(FieldWarrantyDetails, v)) } // WarrantyDetailsContains applies the Contains predicate on the "warranty_details" field. func WarrantyDetailsContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldContains(FieldWarrantyDetails, v)) } // WarrantyDetailsHasPrefix applies the HasPrefix predicate on the "warranty_details" field. func WarrantyDetailsHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldWarrantyDetails, v)) } // WarrantyDetailsHasSuffix applies the HasSuffix predicate on the "warranty_details" field. func WarrantyDetailsHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldWarrantyDetails, v)) } // WarrantyDetailsIsNil applies the IsNil predicate on the "warranty_details" field. func WarrantyDetailsIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldWarrantyDetails))) - }) + return predicate.Item(sql.FieldIsNull(FieldWarrantyDetails)) } // WarrantyDetailsNotNil applies the NotNil predicate on the "warranty_details" field. func WarrantyDetailsNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldWarrantyDetails))) - }) + return predicate.Item(sql.FieldNotNull(FieldWarrantyDetails)) } // WarrantyDetailsEqualFold applies the EqualFold predicate on the "warranty_details" field. func WarrantyDetailsEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldWarrantyDetails, v)) } // WarrantyDetailsContainsFold applies the ContainsFold predicate on the "warranty_details" field. func WarrantyDetailsContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldWarrantyDetails), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldWarrantyDetails, v)) } // PurchaseTimeEQ applies the EQ predicate on the "purchase_time" field. func PurchaseTimeEQ(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPurchaseTime), v)) - }) + return predicate.Item(sql.FieldEQ(FieldPurchaseTime, v)) } // PurchaseTimeNEQ applies the NEQ predicate on the "purchase_time" field. func PurchaseTimeNEQ(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldPurchaseTime), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldPurchaseTime, v)) } // PurchaseTimeIn applies the In predicate on the "purchase_time" field. func PurchaseTimeIn(vs ...time.Time) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldPurchaseTime), v...)) - }) + return predicate.Item(sql.FieldIn(FieldPurchaseTime, vs...)) } // PurchaseTimeNotIn applies the NotIn predicate on the "purchase_time" field. func PurchaseTimeNotIn(vs ...time.Time) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldPurchaseTime), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldPurchaseTime, vs...)) } // PurchaseTimeGT applies the GT predicate on the "purchase_time" field. func PurchaseTimeGT(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldPurchaseTime), v)) - }) + return predicate.Item(sql.FieldGT(FieldPurchaseTime, v)) } // PurchaseTimeGTE applies the GTE predicate on the "purchase_time" field. func PurchaseTimeGTE(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldPurchaseTime), v)) - }) + return predicate.Item(sql.FieldGTE(FieldPurchaseTime, v)) } // PurchaseTimeLT applies the LT predicate on the "purchase_time" field. func PurchaseTimeLT(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldPurchaseTime), v)) - }) + return predicate.Item(sql.FieldLT(FieldPurchaseTime, v)) } // PurchaseTimeLTE applies the LTE predicate on the "purchase_time" field. func PurchaseTimeLTE(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldPurchaseTime), v)) - }) + return predicate.Item(sql.FieldLTE(FieldPurchaseTime, v)) } // PurchaseTimeIsNil applies the IsNil predicate on the "purchase_time" field. func PurchaseTimeIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldPurchaseTime))) - }) + return predicate.Item(sql.FieldIsNull(FieldPurchaseTime)) } // PurchaseTimeNotNil applies the NotNil predicate on the "purchase_time" field. func PurchaseTimeNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldPurchaseTime))) - }) + return predicate.Item(sql.FieldNotNull(FieldPurchaseTime)) } // PurchaseFromEQ applies the EQ predicate on the "purchase_from" field. func PurchaseFromEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldEQ(FieldPurchaseFrom, v)) } // PurchaseFromNEQ applies the NEQ predicate on the "purchase_from" field. func PurchaseFromNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldPurchaseFrom, v)) } // PurchaseFromIn applies the In predicate on the "purchase_from" field. func PurchaseFromIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldPurchaseFrom), v...)) - }) + return predicate.Item(sql.FieldIn(FieldPurchaseFrom, vs...)) } // PurchaseFromNotIn applies the NotIn predicate on the "purchase_from" field. func PurchaseFromNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldPurchaseFrom), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldPurchaseFrom, vs...)) } // PurchaseFromGT applies the GT predicate on the "purchase_from" field. func PurchaseFromGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldGT(FieldPurchaseFrom, v)) } // PurchaseFromGTE applies the GTE predicate on the "purchase_from" field. func PurchaseFromGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldGTE(FieldPurchaseFrom, v)) } // PurchaseFromLT applies the LT predicate on the "purchase_from" field. func PurchaseFromLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldLT(FieldPurchaseFrom, v)) } // PurchaseFromLTE applies the LTE predicate on the "purchase_from" field. func PurchaseFromLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldLTE(FieldPurchaseFrom, v)) } // PurchaseFromContains applies the Contains predicate on the "purchase_from" field. func PurchaseFromContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldContains(FieldPurchaseFrom, v)) } // PurchaseFromHasPrefix applies the HasPrefix predicate on the "purchase_from" field. func PurchaseFromHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldPurchaseFrom, v)) } // PurchaseFromHasSuffix applies the HasSuffix predicate on the "purchase_from" field. func PurchaseFromHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldPurchaseFrom, v)) } // PurchaseFromIsNil applies the IsNil predicate on the "purchase_from" field. func PurchaseFromIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldPurchaseFrom))) - }) + return predicate.Item(sql.FieldIsNull(FieldPurchaseFrom)) } // PurchaseFromNotNil applies the NotNil predicate on the "purchase_from" field. func PurchaseFromNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldPurchaseFrom))) - }) + return predicate.Item(sql.FieldNotNull(FieldPurchaseFrom)) } // PurchaseFromEqualFold applies the EqualFold predicate on the "purchase_from" field. func PurchaseFromEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldPurchaseFrom, v)) } // PurchaseFromContainsFold applies the ContainsFold predicate on the "purchase_from" field. func PurchaseFromContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldPurchaseFrom), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldPurchaseFrom, v)) } // PurchasePriceEQ applies the EQ predicate on the "purchase_price" field. func PurchasePriceEQ(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPurchasePrice), v)) - }) + return predicate.Item(sql.FieldEQ(FieldPurchasePrice, v)) } // PurchasePriceNEQ applies the NEQ predicate on the "purchase_price" field. func PurchasePriceNEQ(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldPurchasePrice), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldPurchasePrice, v)) } // PurchasePriceIn applies the In predicate on the "purchase_price" field. func PurchasePriceIn(vs ...float64) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldPurchasePrice), v...)) - }) + return predicate.Item(sql.FieldIn(FieldPurchasePrice, vs...)) } // PurchasePriceNotIn applies the NotIn predicate on the "purchase_price" field. func PurchasePriceNotIn(vs ...float64) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldPurchasePrice), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldPurchasePrice, vs...)) } // PurchasePriceGT applies the GT predicate on the "purchase_price" field. func PurchasePriceGT(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldPurchasePrice), v)) - }) + return predicate.Item(sql.FieldGT(FieldPurchasePrice, v)) } // PurchasePriceGTE applies the GTE predicate on the "purchase_price" field. func PurchasePriceGTE(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldPurchasePrice), v)) - }) + return predicate.Item(sql.FieldGTE(FieldPurchasePrice, v)) } // PurchasePriceLT applies the LT predicate on the "purchase_price" field. func PurchasePriceLT(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldPurchasePrice), v)) - }) + return predicate.Item(sql.FieldLT(FieldPurchasePrice, v)) } // PurchasePriceLTE applies the LTE predicate on the "purchase_price" field. func PurchasePriceLTE(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldPurchasePrice), v)) - }) + return predicate.Item(sql.FieldLTE(FieldPurchasePrice, v)) } // SoldTimeEQ applies the EQ predicate on the "sold_time" field. func SoldTimeEQ(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSoldTime), v)) - }) + return predicate.Item(sql.FieldEQ(FieldSoldTime, v)) } // SoldTimeNEQ applies the NEQ predicate on the "sold_time" field. func SoldTimeNEQ(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSoldTime), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldSoldTime, v)) } // SoldTimeIn applies the In predicate on the "sold_time" field. func SoldTimeIn(vs ...time.Time) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldSoldTime), v...)) - }) + return predicate.Item(sql.FieldIn(FieldSoldTime, vs...)) } // SoldTimeNotIn applies the NotIn predicate on the "sold_time" field. func SoldTimeNotIn(vs ...time.Time) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldSoldTime), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldSoldTime, vs...)) } // SoldTimeGT applies the GT predicate on the "sold_time" field. func SoldTimeGT(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldSoldTime), v)) - }) + return predicate.Item(sql.FieldGT(FieldSoldTime, v)) } // SoldTimeGTE applies the GTE predicate on the "sold_time" field. func SoldTimeGTE(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldSoldTime), v)) - }) + return predicate.Item(sql.FieldGTE(FieldSoldTime, v)) } // SoldTimeLT applies the LT predicate on the "sold_time" field. func SoldTimeLT(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldSoldTime), v)) - }) + return predicate.Item(sql.FieldLT(FieldSoldTime, v)) } // SoldTimeLTE applies the LTE predicate on the "sold_time" field. func SoldTimeLTE(v time.Time) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldSoldTime), v)) - }) + return predicate.Item(sql.FieldLTE(FieldSoldTime, v)) } // SoldTimeIsNil applies the IsNil predicate on the "sold_time" field. func SoldTimeIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldSoldTime))) - }) + return predicate.Item(sql.FieldIsNull(FieldSoldTime)) } // SoldTimeNotNil applies the NotNil predicate on the "sold_time" field. func SoldTimeNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldSoldTime))) - }) + return predicate.Item(sql.FieldNotNull(FieldSoldTime)) } // SoldToEQ applies the EQ predicate on the "sold_to" field. func SoldToEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldEQ(FieldSoldTo, v)) } // SoldToNEQ applies the NEQ predicate on the "sold_to" field. func SoldToNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldSoldTo, v)) } // SoldToIn applies the In predicate on the "sold_to" field. func SoldToIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldSoldTo), v...)) - }) + return predicate.Item(sql.FieldIn(FieldSoldTo, vs...)) } // SoldToNotIn applies the NotIn predicate on the "sold_to" field. func SoldToNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldSoldTo), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldSoldTo, vs...)) } // SoldToGT applies the GT predicate on the "sold_to" field. func SoldToGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldGT(FieldSoldTo, v)) } // SoldToGTE applies the GTE predicate on the "sold_to" field. func SoldToGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldGTE(FieldSoldTo, v)) } // SoldToLT applies the LT predicate on the "sold_to" field. func SoldToLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldLT(FieldSoldTo, v)) } // SoldToLTE applies the LTE predicate on the "sold_to" field. func SoldToLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldLTE(FieldSoldTo, v)) } // SoldToContains applies the Contains predicate on the "sold_to" field. func SoldToContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldContains(FieldSoldTo, v)) } // SoldToHasPrefix applies the HasPrefix predicate on the "sold_to" field. func SoldToHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldSoldTo, v)) } // SoldToHasSuffix applies the HasSuffix predicate on the "sold_to" field. func SoldToHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldSoldTo, v)) } // SoldToIsNil applies the IsNil predicate on the "sold_to" field. func SoldToIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldSoldTo))) - }) + return predicate.Item(sql.FieldIsNull(FieldSoldTo)) } // SoldToNotNil applies the NotNil predicate on the "sold_to" field. func SoldToNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldSoldTo))) - }) + return predicate.Item(sql.FieldNotNull(FieldSoldTo)) } // SoldToEqualFold applies the EqualFold predicate on the "sold_to" field. func SoldToEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldSoldTo, v)) } // SoldToContainsFold applies the ContainsFold predicate on the "sold_to" field. func SoldToContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldSoldTo), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldSoldTo, v)) } // SoldPriceEQ applies the EQ predicate on the "sold_price" field. func SoldPriceEQ(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSoldPrice), v)) - }) + return predicate.Item(sql.FieldEQ(FieldSoldPrice, v)) } // SoldPriceNEQ applies the NEQ predicate on the "sold_price" field. func SoldPriceNEQ(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSoldPrice), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldSoldPrice, v)) } // SoldPriceIn applies the In predicate on the "sold_price" field. func SoldPriceIn(vs ...float64) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldSoldPrice), v...)) - }) + return predicate.Item(sql.FieldIn(FieldSoldPrice, vs...)) } // SoldPriceNotIn applies the NotIn predicate on the "sold_price" field. func SoldPriceNotIn(vs ...float64) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldSoldPrice), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldSoldPrice, vs...)) } // SoldPriceGT applies the GT predicate on the "sold_price" field. func SoldPriceGT(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldSoldPrice), v)) - }) + return predicate.Item(sql.FieldGT(FieldSoldPrice, v)) } // SoldPriceGTE applies the GTE predicate on the "sold_price" field. func SoldPriceGTE(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldSoldPrice), v)) - }) + return predicate.Item(sql.FieldGTE(FieldSoldPrice, v)) } // SoldPriceLT applies the LT predicate on the "sold_price" field. func SoldPriceLT(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldSoldPrice), v)) - }) + return predicate.Item(sql.FieldLT(FieldSoldPrice, v)) } // SoldPriceLTE applies the LTE predicate on the "sold_price" field. func SoldPriceLTE(v float64) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldSoldPrice), v)) - }) + return predicate.Item(sql.FieldLTE(FieldSoldPrice, v)) } // SoldNotesEQ applies the EQ predicate on the "sold_notes" field. func SoldNotesEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldEQ(FieldSoldNotes, v)) } // SoldNotesNEQ applies the NEQ predicate on the "sold_notes" field. func SoldNotesNEQ(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldNEQ(FieldSoldNotes, v)) } // SoldNotesIn applies the In predicate on the "sold_notes" field. func SoldNotesIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldSoldNotes), v...)) - }) + return predicate.Item(sql.FieldIn(FieldSoldNotes, vs...)) } // SoldNotesNotIn applies the NotIn predicate on the "sold_notes" field. func SoldNotesNotIn(vs ...string) predicate.Item { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldSoldNotes), v...)) - }) + return predicate.Item(sql.FieldNotIn(FieldSoldNotes, vs...)) } // SoldNotesGT applies the GT predicate on the "sold_notes" field. func SoldNotesGT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldGT(FieldSoldNotes, v)) } // SoldNotesGTE applies the GTE predicate on the "sold_notes" field. func SoldNotesGTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldGTE(FieldSoldNotes, v)) } // SoldNotesLT applies the LT predicate on the "sold_notes" field. func SoldNotesLT(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldLT(FieldSoldNotes, v)) } // SoldNotesLTE applies the LTE predicate on the "sold_notes" field. func SoldNotesLTE(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldLTE(FieldSoldNotes, v)) } // SoldNotesContains applies the Contains predicate on the "sold_notes" field. func SoldNotesContains(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldContains(FieldSoldNotes, v)) } // SoldNotesHasPrefix applies the HasPrefix predicate on the "sold_notes" field. func SoldNotesHasPrefix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldHasPrefix(FieldSoldNotes, v)) } // SoldNotesHasSuffix applies the HasSuffix predicate on the "sold_notes" field. func SoldNotesHasSuffix(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldHasSuffix(FieldSoldNotes, v)) } // SoldNotesIsNil applies the IsNil predicate on the "sold_notes" field. func SoldNotesIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldSoldNotes))) - }) + return predicate.Item(sql.FieldIsNull(FieldSoldNotes)) } // SoldNotesNotNil applies the NotNil predicate on the "sold_notes" field. func SoldNotesNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldSoldNotes))) - }) + return predicate.Item(sql.FieldNotNull(FieldSoldNotes)) } // SoldNotesEqualFold applies the EqualFold predicate on the "sold_notes" field. func SoldNotesEqualFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldEqualFold(FieldSoldNotes, v)) } // SoldNotesContainsFold applies the ContainsFold predicate on the "sold_notes" field. func SoldNotesContainsFold(v string) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldSoldNotes), v)) - }) + return predicate.Item(sql.FieldContainsFold(FieldSoldNotes, v)) } // HasParent applies the HasEdge predicate on the "parent" edge. @@ -2137,7 +1411,6 @@ func HasParent() predicate.Item { return predicate.Item(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ParentTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, ParentTable, ParentColumn), ) sqlgraph.HasNeighbors(s, step) @@ -2165,7 +1438,6 @@ func HasChildren() predicate.Item { return predicate.Item(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ChildrenTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, ChildrenTable, ChildrenColumn), ) sqlgraph.HasNeighbors(s, step) @@ -2193,7 +1465,6 @@ func HasGroup() predicate.Item { return predicate.Item(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), ) sqlgraph.HasNeighbors(s, step) @@ -2221,7 +1492,6 @@ func HasLabel() predicate.Item { return predicate.Item(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(LabelTable, FieldID), sqlgraph.Edge(sqlgraph.M2M, true, LabelTable, LabelPrimaryKey...), ) sqlgraph.HasNeighbors(s, step) @@ -2249,7 +1519,6 @@ func HasLocation() predicate.Item { return predicate.Item(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(LocationTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, LocationTable, LocationColumn), ) sqlgraph.HasNeighbors(s, step) @@ -2277,7 +1546,6 @@ func HasFields() predicate.Item { return predicate.Item(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(FieldsTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, FieldsTable, FieldsColumn), ) sqlgraph.HasNeighbors(s, step) @@ -2305,7 +1573,6 @@ func HasMaintenanceEntries() predicate.Item { return predicate.Item(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(MaintenanceEntriesTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, MaintenanceEntriesTable, MaintenanceEntriesColumn), ) sqlgraph.HasNeighbors(s, step) @@ -2333,7 +1600,6 @@ func HasAttachments() predicate.Item { return predicate.Item(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(AttachmentsTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, AttachmentsTable, AttachmentsColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/item_create.go b/backend/internal/data/ent/item_create.go index 4a7c5aa..da36e66 100644 --- a/backend/internal/data/ent/item_create.go +++ b/backend/internal/data/ent/item_create.go @@ -486,50 +486,8 @@ func (ic *ItemCreate) Mutation() *ItemMutation { // Save creates the Item in the database. func (ic *ItemCreate) Save(ctx context.Context) (*Item, error) { - var ( - err error - node *Item - ) ic.defaults() - if len(ic.hooks) == 0 { - if err = ic.check(); err != nil { - return nil, err - } - node, err = ic.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ItemMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = ic.check(); err != nil { - return nil, err - } - ic.mutation = mutation - if node, err = ic.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(ic.hooks) - 1; i >= 0; i-- { - if ic.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ic.hooks[i](mut) - } - v, err := mut.Mutate(ctx, ic.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Item) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from ItemMutation", v) - } - node = nv - } - return node, err + return withHooks[*Item, ItemMutation](ctx, ic.sqlSave, ic.mutation, ic.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -682,6 +640,9 @@ func (ic *ItemCreate) check() error { } func (ic *ItemCreate) sqlSave(ctx context.Context) (*Item, error) { + if err := ic.check(); err != nil { + return nil, err + } _node, _spec := ic.createSpec() if err := sqlgraph.CreateNode(ctx, ic.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -696,6 +657,8 @@ func (ic *ItemCreate) sqlSave(ctx context.Context) (*Item, error) { return nil, err } } + ic.mutation.id = &_node.ID + ic.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/item_delete.go b/backend/internal/data/ent/item_delete.go index 56b7e03..4ebd167 100644 --- a/backend/internal/data/ent/item_delete.go +++ b/backend/internal/data/ent/item_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (id *ItemDelete) Where(ps ...predicate.Item) *ItemDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (id *ItemDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(id.hooks) == 0 { - affected, err = id.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ItemMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - id.mutation = mutation - affected, err = id.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(id.hooks) - 1; i >= 0; i-- { - if id.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = id.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, id.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, ItemMutation](ctx, id.sqlExec, id.mutation, id.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (id *ItemDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + id.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/item_query.go b/backend/internal/data/ent/item_query.go index 8891469..cde5b44 100644 --- a/backend/internal/data/ent/item_query.go +++ b/backend/internal/data/ent/item_query.go @@ -30,6 +30,7 @@ type ItemQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.Item withParent *ItemQuery withChildren *ItemQuery @@ -51,13 +52,13 @@ func (iq *ItemQuery) Where(ps ...predicate.Item) *ItemQuery { return iq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (iq *ItemQuery) Limit(limit int) *ItemQuery { iq.limit = &limit return iq } -// Offset adds an offset step to the query. +// Offset to start from. func (iq *ItemQuery) Offset(offset int) *ItemQuery { iq.offset = &offset return iq @@ -70,7 +71,7 @@ func (iq *ItemQuery) Unique(unique bool) *ItemQuery { return iq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (iq *ItemQuery) Order(o ...OrderFunc) *ItemQuery { iq.order = append(iq.order, o...) return iq @@ -78,7 +79,7 @@ func (iq *ItemQuery) Order(o ...OrderFunc) *ItemQuery { // QueryParent chains the current query on the "parent" edge. func (iq *ItemQuery) QueryParent() *ItemQuery { - query := &ItemQuery{config: iq.config} + query := (&ItemClient{config: iq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := iq.prepareQuery(ctx); err != nil { return nil, err @@ -100,7 +101,7 @@ func (iq *ItemQuery) QueryParent() *ItemQuery { // QueryChildren chains the current query on the "children" edge. func (iq *ItemQuery) QueryChildren() *ItemQuery { - query := &ItemQuery{config: iq.config} + query := (&ItemClient{config: iq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := iq.prepareQuery(ctx); err != nil { return nil, err @@ -122,7 +123,7 @@ func (iq *ItemQuery) QueryChildren() *ItemQuery { // QueryGroup chains the current query on the "group" edge. func (iq *ItemQuery) QueryGroup() *GroupQuery { - query := &GroupQuery{config: iq.config} + query := (&GroupClient{config: iq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := iq.prepareQuery(ctx); err != nil { return nil, err @@ -144,7 +145,7 @@ func (iq *ItemQuery) QueryGroup() *GroupQuery { // QueryLabel chains the current query on the "label" edge. func (iq *ItemQuery) QueryLabel() *LabelQuery { - query := &LabelQuery{config: iq.config} + query := (&LabelClient{config: iq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := iq.prepareQuery(ctx); err != nil { return nil, err @@ -166,7 +167,7 @@ func (iq *ItemQuery) QueryLabel() *LabelQuery { // QueryLocation chains the current query on the "location" edge. func (iq *ItemQuery) QueryLocation() *LocationQuery { - query := &LocationQuery{config: iq.config} + query := (&LocationClient{config: iq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := iq.prepareQuery(ctx); err != nil { return nil, err @@ -188,7 +189,7 @@ func (iq *ItemQuery) QueryLocation() *LocationQuery { // QueryFields chains the current query on the "fields" edge. func (iq *ItemQuery) QueryFields() *ItemFieldQuery { - query := &ItemFieldQuery{config: iq.config} + query := (&ItemFieldClient{config: iq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := iq.prepareQuery(ctx); err != nil { return nil, err @@ -210,7 +211,7 @@ func (iq *ItemQuery) QueryFields() *ItemFieldQuery { // QueryMaintenanceEntries chains the current query on the "maintenance_entries" edge. func (iq *ItemQuery) QueryMaintenanceEntries() *MaintenanceEntryQuery { - query := &MaintenanceEntryQuery{config: iq.config} + query := (&MaintenanceEntryClient{config: iq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := iq.prepareQuery(ctx); err != nil { return nil, err @@ -232,7 +233,7 @@ func (iq *ItemQuery) QueryMaintenanceEntries() *MaintenanceEntryQuery { // QueryAttachments chains the current query on the "attachments" edge. func (iq *ItemQuery) QueryAttachments() *AttachmentQuery { - query := &AttachmentQuery{config: iq.config} + query := (&AttachmentClient{config: iq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := iq.prepareQuery(ctx); err != nil { return nil, err @@ -255,7 +256,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(ctx) + nodes, err := iq.Limit(1).All(newQueryContext(ctx, TypeItem, "First")) if err != nil { return nil, err } @@ -278,7 +279,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(ctx); err != nil { + if ids, err = iq.Limit(1).IDs(newQueryContext(ctx, TypeItem, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -301,7 +302,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(ctx) + nodes, err := iq.Limit(2).All(newQueryContext(ctx, TypeItem, "Only")) if err != nil { return nil, err } @@ -329,7 +330,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(ctx); err != nil { + if ids, err = iq.Limit(2).IDs(newQueryContext(ctx, TypeItem, "OnlyID")); err != nil { return } switch len(ids) { @@ -354,10 +355,12 @@ 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") if err := iq.prepareQuery(ctx); err != nil { return nil, err } - return iq.sqlAll(ctx) + qr := querierAll[[]*Item, *ItemQuery]() + return withInterceptors[[]*Item](ctx, iq, qr, iq.inters) } // AllX is like All, but panics if an error occurs. @@ -372,6 +375,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") if err := iq.Select(item.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -389,10 +393,11 @@ 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") if err := iq.prepareQuery(ctx); err != nil { return 0, err } - return iq.sqlCount(ctx) + return withInterceptors[int](ctx, iq, querierCount[*ItemQuery](), iq.inters) } // CountX is like Count, but panics if an error occurs. @@ -406,10 +411,15 @@ 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) { - if err := iq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeItem, "Exist") + switch _, err := iq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return iq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -432,6 +442,7 @@ func (iq *ItemQuery) Clone() *ItemQuery { limit: iq.limit, offset: iq.offset, order: append([]OrderFunc{}, iq.order...), + inters: append([]Interceptor{}, iq.inters...), predicates: append([]predicate.Item{}, iq.predicates...), withParent: iq.withParent.Clone(), withChildren: iq.withChildren.Clone(), @@ -451,7 +462,7 @@ func (iq *ItemQuery) Clone() *ItemQuery { // WithParent tells the query-builder to eager-load the nodes that are connected to // the "parent" edge. The optional arguments are used to configure the query builder of the edge. func (iq *ItemQuery) WithParent(opts ...func(*ItemQuery)) *ItemQuery { - query := &ItemQuery{config: iq.config} + query := (&ItemClient{config: iq.config}).Query() for _, opt := range opts { opt(query) } @@ -462,7 +473,7 @@ func (iq *ItemQuery) WithParent(opts ...func(*ItemQuery)) *ItemQuery { // WithChildren tells the query-builder to eager-load the nodes that are connected to // the "children" edge. The optional arguments are used to configure the query builder of the edge. func (iq *ItemQuery) WithChildren(opts ...func(*ItemQuery)) *ItemQuery { - query := &ItemQuery{config: iq.config} + query := (&ItemClient{config: iq.config}).Query() for _, opt := range opts { opt(query) } @@ -473,7 +484,7 @@ func (iq *ItemQuery) WithChildren(opts ...func(*ItemQuery)) *ItemQuery { // WithGroup tells the query-builder to eager-load the nodes that are connected to // the "group" edge. The optional arguments are used to configure the query builder of the edge. func (iq *ItemQuery) WithGroup(opts ...func(*GroupQuery)) *ItemQuery { - query := &GroupQuery{config: iq.config} + query := (&GroupClient{config: iq.config}).Query() for _, opt := range opts { opt(query) } @@ -484,7 +495,7 @@ func (iq *ItemQuery) WithGroup(opts ...func(*GroupQuery)) *ItemQuery { // WithLabel tells the query-builder to eager-load the nodes that are connected to // the "label" edge. The optional arguments are used to configure the query builder of the edge. func (iq *ItemQuery) WithLabel(opts ...func(*LabelQuery)) *ItemQuery { - query := &LabelQuery{config: iq.config} + query := (&LabelClient{config: iq.config}).Query() for _, opt := range opts { opt(query) } @@ -495,7 +506,7 @@ func (iq *ItemQuery) WithLabel(opts ...func(*LabelQuery)) *ItemQuery { // WithLocation tells the query-builder to eager-load the nodes that are connected to // the "location" edge. The optional arguments are used to configure the query builder of the edge. func (iq *ItemQuery) WithLocation(opts ...func(*LocationQuery)) *ItemQuery { - query := &LocationQuery{config: iq.config} + query := (&LocationClient{config: iq.config}).Query() for _, opt := range opts { opt(query) } @@ -506,7 +517,7 @@ func (iq *ItemQuery) WithLocation(opts ...func(*LocationQuery)) *ItemQuery { // WithFields tells the query-builder to eager-load the nodes that are connected to // the "fields" edge. The optional arguments are used to configure the query builder of the edge. func (iq *ItemQuery) WithFields(opts ...func(*ItemFieldQuery)) *ItemQuery { - query := &ItemFieldQuery{config: iq.config} + query := (&ItemFieldClient{config: iq.config}).Query() for _, opt := range opts { opt(query) } @@ -517,7 +528,7 @@ func (iq *ItemQuery) WithFields(opts ...func(*ItemFieldQuery)) *ItemQuery { // WithMaintenanceEntries tells the query-builder to eager-load the nodes that are connected to // the "maintenance_entries" edge. The optional arguments are used to configure the query builder of the edge. func (iq *ItemQuery) WithMaintenanceEntries(opts ...func(*MaintenanceEntryQuery)) *ItemQuery { - query := &MaintenanceEntryQuery{config: iq.config} + query := (&MaintenanceEntryClient{config: iq.config}).Query() for _, opt := range opts { opt(query) } @@ -528,7 +539,7 @@ func (iq *ItemQuery) WithMaintenanceEntries(opts ...func(*MaintenanceEntryQuery) // WithAttachments tells the query-builder to eager-load the nodes that are connected to // the "attachments" edge. The optional arguments are used to configure the query builder of the edge. func (iq *ItemQuery) WithAttachments(opts ...func(*AttachmentQuery)) *ItemQuery { - query := &AttachmentQuery{config: iq.config} + query := (&AttachmentClient{config: iq.config}).Query() for _, opt := range opts { opt(query) } @@ -551,16 +562,11 @@ func (iq *ItemQuery) WithAttachments(opts ...func(*AttachmentQuery)) *ItemQuery // Aggregate(ent.Count()). // Scan(ctx, &v) func (iq *ItemQuery) GroupBy(field string, fields ...string) *ItemGroupBy { - grbuild := &ItemGroupBy{config: iq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := iq.prepareQuery(ctx); err != nil { - return nil, err - } - return iq.sqlQuery(ctx), nil - } + iq.fields = append([]string{field}, fields...) + grbuild := &ItemGroupBy{build: iq} + grbuild.flds = &iq.fields grbuild.label = item.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -578,10 +584,10 @@ func (iq *ItemQuery) GroupBy(field string, fields ...string) *ItemGroupBy { // Scan(ctx, &v) func (iq *ItemQuery) Select(fields ...string) *ItemSelect { iq.fields = append(iq.fields, fields...) - selbuild := &ItemSelect{ItemQuery: iq} - selbuild.label = item.Label - selbuild.flds, selbuild.scan = &iq.fields, selbuild.Scan - return selbuild + sbuild := &ItemSelect{ItemQuery: iq} + sbuild.label = item.Label + sbuild.flds, sbuild.scan = &iq.fields, sbuild.Scan + return sbuild } // Aggregate returns a ItemSelect configured with the given aggregations. @@ -590,6 +596,16 @@ func (iq *ItemQuery) Aggregate(fns ...AggregateFunc) *ItemSelect { } func (iq *ItemQuery) prepareQuery(ctx context.Context) error { + for _, inter := range iq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, iq); err != nil { + return err + } + } + } for _, f := range iq.fields { if !item.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -976,17 +992,6 @@ func (iq *ItemQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, iq.driver, _spec) } -func (iq *ItemQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := iq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (iq *ItemQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -1069,13 +1074,8 @@ func (iq *ItemQuery) sqlQuery(ctx context.Context) *sql.Selector { // ItemGroupBy is the group-by builder for Item entities. type ItemGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *ItemQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -1084,58 +1084,46 @@ func (igb *ItemGroupBy) Aggregate(fns ...AggregateFunc) *ItemGroupBy { return igb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (igb *ItemGroupBy) Scan(ctx context.Context, v any) error { - query, err := igb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeItem, "GroupBy") + if err := igb.build.prepareQuery(ctx); err != nil { return err } - igb.sql = query - return igb.sqlScan(ctx, v) + return scanWithInterceptors[*ItemQuery, *ItemGroupBy](ctx, igb.build, igb, igb.build.inters, v) } -func (igb *ItemGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range igb.fields { - if !item.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (igb *ItemGroupBy) sqlScan(ctx context.Context, root *ItemQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(igb.fns)) + for _, fn := range igb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := igb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*igb.flds)+len(igb.fns)) + for _, f := range *igb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*igb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := igb.driver.Query(ctx, query, args, rows); err != nil { + if err := igb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (igb *ItemGroupBy) sqlQuery() *sql.Selector { - selector := igb.sql.Select() - aggregation := make([]string, 0, len(igb.fns)) - for _, fn := range igb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(igb.fields)+len(igb.fns)) - for _, f := range igb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(igb.fields...)...) -} - // ItemSelect is the builder for selecting fields of Item entities. type ItemSelect struct { *ItemQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -1146,26 +1134,27 @@ 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") if err := is.prepareQuery(ctx); err != nil { return err } - is.sql = is.ItemQuery.sqlQuery(ctx) - return is.sqlScan(ctx, v) + return scanWithInterceptors[*ItemQuery, *ItemSelect](ctx, is.ItemQuery, is, is.inters, v) } -func (is *ItemSelect) sqlScan(ctx context.Context, v any) error { +func (is *ItemSelect) sqlScan(ctx context.Context, root *ItemQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(is.fns)) for _, fn := range is.fns { - aggregation = append(aggregation, fn(is.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*is.selector.flds); { case n == 0 && len(aggregation) > 0: - is.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - is.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := is.sql.Query() + query, args := selector.Query() if err := is.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/item_update.go b/backend/internal/data/ent/item_update.go index b7a9b79..1d5ec90 100644 --- a/backend/internal/data/ent/item_update.go +++ b/backend/internal/data/ent/item_update.go @@ -667,41 +667,8 @@ func (iu *ItemUpdate) RemoveAttachments(a ...*Attachment) *ItemUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (iu *ItemUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) iu.defaults() - if len(iu.hooks) == 0 { - if err = iu.check(); err != nil { - return 0, err - } - affected, err = iu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ItemMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = iu.check(); err != nil { - return 0, err - } - iu.mutation = mutation - affected, err = iu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(iu.hooks) - 1; i >= 0; i-- { - if iu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = iu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, iu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, ItemMutation](ctx, iu.sqlSave, iu.mutation, iu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -783,6 +750,9 @@ func (iu *ItemUpdate) check() error { } func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := iu.check(); err != nil { + return n, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: item.Table, @@ -1297,6 +1267,7 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + iu.mutation.done = true return n, nil } @@ -1947,47 +1918,8 @@ func (iuo *ItemUpdateOne) Select(field string, fields ...string) *ItemUpdateOne // Save executes the query and returns the updated Item entity. func (iuo *ItemUpdateOne) Save(ctx context.Context) (*Item, error) { - var ( - err error - node *Item - ) iuo.defaults() - if len(iuo.hooks) == 0 { - if err = iuo.check(); err != nil { - return nil, err - } - node, err = iuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ItemMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = iuo.check(); err != nil { - return nil, err - } - iuo.mutation = mutation - node, err = iuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(iuo.hooks) - 1; i >= 0; i-- { - if iuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = iuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, iuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Item) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from ItemMutation", v) - } - node = nv - } - return node, err + return withHooks[*Item, ItemMutation](ctx, iuo.sqlSave, iuo.mutation, iuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -2069,6 +2001,9 @@ func (iuo *ItemUpdateOne) check() error { } func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error) { + if err := iuo.check(); err != nil { + return _node, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: item.Table, @@ -2603,5 +2538,6 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error) } return nil, err } + iuo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/itemfield/where.go b/backend/internal/data/ent/itemfield/where.go index 2af2d7a..94805ea 100644 --- a/backend/internal/data/ent/itemfield/where.go +++ b/backend/internal/data/ent/itemfield/where.go @@ -13,774 +13,502 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.ItemField(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.ItemField(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.ItemField(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.ItemField(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.ItemField(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.ItemField(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.ItemField(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.ItemField(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.ItemField(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldUpdatedAt, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldName, v)) } // Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. func Description(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldDescription, v)) } // TextValue applies equality check predicate on the "text_value" field. It's identical to TextValueEQ. func TextValue(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldTextValue, v)) } // NumberValue applies equality check predicate on the "number_value" field. It's identical to NumberValueEQ. func NumberValue(v int) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNumberValue), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldNumberValue, v)) } // BooleanValue applies equality check predicate on the "boolean_value" field. It's identical to BooleanValueEQ. func BooleanValue(v bool) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldBooleanValue), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldBooleanValue, v)) } // TimeValue applies equality check predicate on the "time_value" field. It's identical to TimeValueEQ. func TimeValue(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldTimeValue), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldTimeValue, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.ItemField(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.ItemField(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.ItemField(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.ItemField(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.ItemField(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.ItemField(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.ItemField(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.ItemField(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.ItemField(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.ItemField(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.ItemField(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.ItemField(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.ItemField(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.ItemField(sql.FieldLTE(FieldUpdatedAt, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.ItemField(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.ItemField(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.ItemField(sql.FieldContainsFold(FieldName, v)) } // DescriptionEQ applies the EQ predicate on the "description" field. func DescriptionEQ(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldDescription, v)) } // DescriptionNEQ applies the NEQ predicate on the "description" field. func DescriptionNEQ(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldNEQ(FieldDescription, v)) } // DescriptionIn applies the In predicate on the "description" field. func DescriptionIn(vs ...string) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldDescription), v...)) - }) + return predicate.ItemField(sql.FieldIn(FieldDescription, vs...)) } // DescriptionNotIn applies the NotIn predicate on the "description" field. func DescriptionNotIn(vs ...string) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldDescription), v...)) - }) + return predicate.ItemField(sql.FieldNotIn(FieldDescription, vs...)) } // DescriptionGT applies the GT predicate on the "description" field. func DescriptionGT(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldGT(FieldDescription, v)) } // DescriptionGTE applies the GTE predicate on the "description" field. func DescriptionGTE(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldGTE(FieldDescription, v)) } // DescriptionLT applies the LT predicate on the "description" field. func DescriptionLT(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldLT(FieldDescription, v)) } // DescriptionLTE applies the LTE predicate on the "description" field. func DescriptionLTE(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldLTE(FieldDescription, v)) } // DescriptionContains applies the Contains predicate on the "description" field. func DescriptionContains(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldContains(FieldDescription, v)) } // DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. func DescriptionHasPrefix(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldHasPrefix(FieldDescription, v)) } // DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. func DescriptionHasSuffix(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldHasSuffix(FieldDescription, v)) } // DescriptionIsNil applies the IsNil predicate on the "description" field. func DescriptionIsNil() predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldDescription))) - }) + return predicate.ItemField(sql.FieldIsNull(FieldDescription)) } // DescriptionNotNil applies the NotNil predicate on the "description" field. func DescriptionNotNil() predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldDescription))) - }) + return predicate.ItemField(sql.FieldNotNull(FieldDescription)) } // DescriptionEqualFold applies the EqualFold predicate on the "description" field. func DescriptionEqualFold(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldEqualFold(FieldDescription, v)) } // DescriptionContainsFold applies the ContainsFold predicate on the "description" field. func DescriptionContainsFold(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldDescription), v)) - }) + return predicate.ItemField(sql.FieldContainsFold(FieldDescription, v)) } // TypeEQ applies the EQ predicate on the "type" field. func TypeEQ(v Type) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldType), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldType, v)) } // TypeNEQ applies the NEQ predicate on the "type" field. func TypeNEQ(v Type) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldType), v)) - }) + return predicate.ItemField(sql.FieldNEQ(FieldType, v)) } // TypeIn applies the In predicate on the "type" field. func TypeIn(vs ...Type) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldType), v...)) - }) + return predicate.ItemField(sql.FieldIn(FieldType, vs...)) } // TypeNotIn applies the NotIn predicate on the "type" field. func TypeNotIn(vs ...Type) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldType), v...)) - }) + return predicate.ItemField(sql.FieldNotIn(FieldType, vs...)) } // TextValueEQ applies the EQ predicate on the "text_value" field. func TextValueEQ(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldTextValue, v)) } // TextValueNEQ applies the NEQ predicate on the "text_value" field. func TextValueNEQ(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldNEQ(FieldTextValue, v)) } // TextValueIn applies the In predicate on the "text_value" field. func TextValueIn(vs ...string) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldTextValue), v...)) - }) + return predicate.ItemField(sql.FieldIn(FieldTextValue, vs...)) } // TextValueNotIn applies the NotIn predicate on the "text_value" field. func TextValueNotIn(vs ...string) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldTextValue), v...)) - }) + return predicate.ItemField(sql.FieldNotIn(FieldTextValue, vs...)) } // TextValueGT applies the GT predicate on the "text_value" field. func TextValueGT(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldGT(FieldTextValue, v)) } // TextValueGTE applies the GTE predicate on the "text_value" field. func TextValueGTE(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldGTE(FieldTextValue, v)) } // TextValueLT applies the LT predicate on the "text_value" field. func TextValueLT(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldLT(FieldTextValue, v)) } // TextValueLTE applies the LTE predicate on the "text_value" field. func TextValueLTE(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldLTE(FieldTextValue, v)) } // TextValueContains applies the Contains predicate on the "text_value" field. func TextValueContains(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldContains(FieldTextValue, v)) } // TextValueHasPrefix applies the HasPrefix predicate on the "text_value" field. func TextValueHasPrefix(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldHasPrefix(FieldTextValue, v)) } // TextValueHasSuffix applies the HasSuffix predicate on the "text_value" field. func TextValueHasSuffix(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldHasSuffix(FieldTextValue, v)) } // TextValueIsNil applies the IsNil predicate on the "text_value" field. func TextValueIsNil() predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldTextValue))) - }) + return predicate.ItemField(sql.FieldIsNull(FieldTextValue)) } // TextValueNotNil applies the NotNil predicate on the "text_value" field. func TextValueNotNil() predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldTextValue))) - }) + return predicate.ItemField(sql.FieldNotNull(FieldTextValue)) } // TextValueEqualFold applies the EqualFold predicate on the "text_value" field. func TextValueEqualFold(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldEqualFold(FieldTextValue, v)) } // TextValueContainsFold applies the ContainsFold predicate on the "text_value" field. func TextValueContainsFold(v string) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldTextValue), v)) - }) + return predicate.ItemField(sql.FieldContainsFold(FieldTextValue, v)) } // NumberValueEQ applies the EQ predicate on the "number_value" field. func NumberValueEQ(v int) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNumberValue), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldNumberValue, v)) } // NumberValueNEQ applies the NEQ predicate on the "number_value" field. func NumberValueNEQ(v int) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldNumberValue), v)) - }) + return predicate.ItemField(sql.FieldNEQ(FieldNumberValue, v)) } // NumberValueIn applies the In predicate on the "number_value" field. func NumberValueIn(vs ...int) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldNumberValue), v...)) - }) + return predicate.ItemField(sql.FieldIn(FieldNumberValue, vs...)) } // NumberValueNotIn applies the NotIn predicate on the "number_value" field. func NumberValueNotIn(vs ...int) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldNumberValue), v...)) - }) + return predicate.ItemField(sql.FieldNotIn(FieldNumberValue, vs...)) } // NumberValueGT applies the GT predicate on the "number_value" field. func NumberValueGT(v int) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldNumberValue), v)) - }) + return predicate.ItemField(sql.FieldGT(FieldNumberValue, v)) } // NumberValueGTE applies the GTE predicate on the "number_value" field. func NumberValueGTE(v int) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldNumberValue), v)) - }) + return predicate.ItemField(sql.FieldGTE(FieldNumberValue, v)) } // NumberValueLT applies the LT predicate on the "number_value" field. func NumberValueLT(v int) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldNumberValue), v)) - }) + return predicate.ItemField(sql.FieldLT(FieldNumberValue, v)) } // NumberValueLTE applies the LTE predicate on the "number_value" field. func NumberValueLTE(v int) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldNumberValue), v)) - }) + return predicate.ItemField(sql.FieldLTE(FieldNumberValue, v)) } // NumberValueIsNil applies the IsNil predicate on the "number_value" field. func NumberValueIsNil() predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldNumberValue))) - }) + return predicate.ItemField(sql.FieldIsNull(FieldNumberValue)) } // NumberValueNotNil applies the NotNil predicate on the "number_value" field. func NumberValueNotNil() predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldNumberValue))) - }) + return predicate.ItemField(sql.FieldNotNull(FieldNumberValue)) } // BooleanValueEQ applies the EQ predicate on the "boolean_value" field. func BooleanValueEQ(v bool) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldBooleanValue), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldBooleanValue, v)) } // BooleanValueNEQ applies the NEQ predicate on the "boolean_value" field. func BooleanValueNEQ(v bool) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldBooleanValue), v)) - }) + return predicate.ItemField(sql.FieldNEQ(FieldBooleanValue, v)) } // TimeValueEQ applies the EQ predicate on the "time_value" field. func TimeValueEQ(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldTimeValue), v)) - }) + return predicate.ItemField(sql.FieldEQ(FieldTimeValue, v)) } // TimeValueNEQ applies the NEQ predicate on the "time_value" field. func TimeValueNEQ(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldTimeValue), v)) - }) + return predicate.ItemField(sql.FieldNEQ(FieldTimeValue, v)) } // TimeValueIn applies the In predicate on the "time_value" field. func TimeValueIn(vs ...time.Time) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldTimeValue), v...)) - }) + return predicate.ItemField(sql.FieldIn(FieldTimeValue, vs...)) } // TimeValueNotIn applies the NotIn predicate on the "time_value" field. func TimeValueNotIn(vs ...time.Time) predicate.ItemField { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldTimeValue), v...)) - }) + return predicate.ItemField(sql.FieldNotIn(FieldTimeValue, vs...)) } // TimeValueGT applies the GT predicate on the "time_value" field. func TimeValueGT(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldTimeValue), v)) - }) + return predicate.ItemField(sql.FieldGT(FieldTimeValue, v)) } // TimeValueGTE applies the GTE predicate on the "time_value" field. func TimeValueGTE(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldTimeValue), v)) - }) + return predicate.ItemField(sql.FieldGTE(FieldTimeValue, v)) } // TimeValueLT applies the LT predicate on the "time_value" field. func TimeValueLT(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldTimeValue), v)) - }) + return predicate.ItemField(sql.FieldLT(FieldTimeValue, v)) } // TimeValueLTE applies the LTE predicate on the "time_value" field. func TimeValueLTE(v time.Time) predicate.ItemField { - return predicate.ItemField(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldTimeValue), v)) - }) + return predicate.ItemField(sql.FieldLTE(FieldTimeValue, v)) } // HasItem applies the HasEdge predicate on the "item" edge. @@ -788,7 +516,6 @@ func HasItem() predicate.ItemField { return predicate.ItemField(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ItemTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, ItemTable, ItemColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/itemfield_create.go b/backend/internal/data/ent/itemfield_create.go index c06d225..32c5578 100644 --- a/backend/internal/data/ent/itemfield_create.go +++ b/backend/internal/data/ent/itemfield_create.go @@ -172,50 +172,8 @@ func (ifc *ItemFieldCreate) Mutation() *ItemFieldMutation { // Save creates the ItemField in the database. func (ifc *ItemFieldCreate) Save(ctx context.Context) (*ItemField, error) { - var ( - err error - node *ItemField - ) ifc.defaults() - if len(ifc.hooks) == 0 { - if err = ifc.check(); err != nil { - return nil, err - } - node, err = ifc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ItemFieldMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = ifc.check(); err != nil { - return nil, err - } - ifc.mutation = mutation - if node, err = ifc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(ifc.hooks) - 1; i >= 0; i-- { - if ifc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ifc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, ifc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*ItemField) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from ItemFieldMutation", v) - } - node = nv - } - return node, err + return withHooks[*ItemField, ItemFieldMutation](ctx, ifc.sqlSave, ifc.mutation, ifc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -308,6 +266,9 @@ func (ifc *ItemFieldCreate) check() error { } func (ifc *ItemFieldCreate) sqlSave(ctx context.Context) (*ItemField, error) { + if err := ifc.check(); err != nil { + return nil, err + } _node, _spec := ifc.createSpec() if err := sqlgraph.CreateNode(ctx, ifc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -322,6 +283,8 @@ func (ifc *ItemFieldCreate) sqlSave(ctx context.Context) (*ItemField, error) { return nil, err } } + ifc.mutation.id = &_node.ID + ifc.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/itemfield_delete.go b/backend/internal/data/ent/itemfield_delete.go index e1933d6..aaca25a 100644 --- a/backend/internal/data/ent/itemfield_delete.go +++ b/backend/internal/data/ent/itemfield_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (ifd *ItemFieldDelete) Where(ps ...predicate.ItemField) *ItemFieldDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ifd *ItemFieldDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ifd.hooks) == 0 { - affected, err = ifd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ItemFieldMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ifd.mutation = mutation - affected, err = ifd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ifd.hooks) - 1; i >= 0; i-- { - if ifd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ifd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ifd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, ItemFieldMutation](ctx, ifd.sqlExec, ifd.mutation, ifd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (ifd *ItemFieldDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + ifd.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/itemfield_query.go b/backend/internal/data/ent/itemfield_query.go index f213cb5..4629dd2 100644 --- a/backend/internal/data/ent/itemfield_query.go +++ b/backend/internal/data/ent/itemfield_query.go @@ -24,6 +24,7 @@ type ItemFieldQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.ItemField withItem *ItemQuery withFKs bool @@ -38,13 +39,13 @@ func (ifq *ItemFieldQuery) Where(ps ...predicate.ItemField) *ItemFieldQuery { return ifq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (ifq *ItemFieldQuery) Limit(limit int) *ItemFieldQuery { ifq.limit = &limit return ifq } -// Offset adds an offset step to the query. +// Offset to start from. func (ifq *ItemFieldQuery) Offset(offset int) *ItemFieldQuery { ifq.offset = &offset return ifq @@ -57,7 +58,7 @@ func (ifq *ItemFieldQuery) Unique(unique bool) *ItemFieldQuery { return ifq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (ifq *ItemFieldQuery) Order(o ...OrderFunc) *ItemFieldQuery { ifq.order = append(ifq.order, o...) return ifq @@ -65,7 +66,7 @@ func (ifq *ItemFieldQuery) Order(o ...OrderFunc) *ItemFieldQuery { // QueryItem chains the current query on the "item" edge. func (ifq *ItemFieldQuery) QueryItem() *ItemQuery { - query := &ItemQuery{config: ifq.config} + query := (&ItemClient{config: ifq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := ifq.prepareQuery(ctx); err != nil { return nil, err @@ -88,7 +89,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(ctx) + nodes, err := ifq.Limit(1).All(newQueryContext(ctx, TypeItemField, "First")) if err != nil { return nil, err } @@ -111,7 +112,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(ctx); err != nil { + if ids, err = ifq.Limit(1).IDs(newQueryContext(ctx, TypeItemField, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -134,7 +135,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(ctx) + nodes, err := ifq.Limit(2).All(newQueryContext(ctx, TypeItemField, "Only")) if err != nil { return nil, err } @@ -162,7 +163,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(ctx); err != nil { + if ids, err = ifq.Limit(2).IDs(newQueryContext(ctx, TypeItemField, "OnlyID")); err != nil { return } switch len(ids) { @@ -187,10 +188,12 @@ 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") if err := ifq.prepareQuery(ctx); err != nil { return nil, err } - return ifq.sqlAll(ctx) + qr := querierAll[[]*ItemField, *ItemFieldQuery]() + return withInterceptors[[]*ItemField](ctx, ifq, qr, ifq.inters) } // AllX is like All, but panics if an error occurs. @@ -205,6 +208,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") if err := ifq.Select(itemfield.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -222,10 +226,11 @@ 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") if err := ifq.prepareQuery(ctx); err != nil { return 0, err } - return ifq.sqlCount(ctx) + return withInterceptors[int](ctx, ifq, querierCount[*ItemFieldQuery](), ifq.inters) } // CountX is like Count, but panics if an error occurs. @@ -239,10 +244,15 @@ 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) { - if err := ifq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeItemField, "Exist") + switch _, err := ifq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return ifq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -265,6 +275,7 @@ func (ifq *ItemFieldQuery) Clone() *ItemFieldQuery { limit: ifq.limit, offset: ifq.offset, order: append([]OrderFunc{}, ifq.order...), + inters: append([]Interceptor{}, ifq.inters...), predicates: append([]predicate.ItemField{}, ifq.predicates...), withItem: ifq.withItem.Clone(), // clone intermediate query. @@ -277,7 +288,7 @@ func (ifq *ItemFieldQuery) Clone() *ItemFieldQuery { // WithItem tells the query-builder to eager-load the nodes that are connected to // the "item" edge. The optional arguments are used to configure the query builder of the edge. func (ifq *ItemFieldQuery) WithItem(opts ...func(*ItemQuery)) *ItemFieldQuery { - query := &ItemQuery{config: ifq.config} + query := (&ItemClient{config: ifq.config}).Query() for _, opt := range opts { opt(query) } @@ -300,16 +311,11 @@ func (ifq *ItemFieldQuery) WithItem(opts ...func(*ItemQuery)) *ItemFieldQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (ifq *ItemFieldQuery) GroupBy(field string, fields ...string) *ItemFieldGroupBy { - grbuild := &ItemFieldGroupBy{config: ifq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := ifq.prepareQuery(ctx); err != nil { - return nil, err - } - return ifq.sqlQuery(ctx), nil - } + ifq.fields = append([]string{field}, fields...) + grbuild := &ItemFieldGroupBy{build: ifq} + grbuild.flds = &ifq.fields grbuild.label = itemfield.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -327,10 +333,10 @@ func (ifq *ItemFieldQuery) GroupBy(field string, fields ...string) *ItemFieldGro // Scan(ctx, &v) func (ifq *ItemFieldQuery) Select(fields ...string) *ItemFieldSelect { ifq.fields = append(ifq.fields, fields...) - selbuild := &ItemFieldSelect{ItemFieldQuery: ifq} - selbuild.label = itemfield.Label - selbuild.flds, selbuild.scan = &ifq.fields, selbuild.Scan - return selbuild + sbuild := &ItemFieldSelect{ItemFieldQuery: ifq} + sbuild.label = itemfield.Label + sbuild.flds, sbuild.scan = &ifq.fields, sbuild.Scan + return sbuild } // Aggregate returns a ItemFieldSelect configured with the given aggregations. @@ -339,6 +345,16 @@ func (ifq *ItemFieldQuery) Aggregate(fns ...AggregateFunc) *ItemFieldSelect { } func (ifq *ItemFieldQuery) prepareQuery(ctx context.Context) error { + for _, inter := range ifq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, ifq); err != nil { + return err + } + } + } for _, f := range ifq.fields { if !itemfield.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -435,17 +451,6 @@ func (ifq *ItemFieldQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, ifq.driver, _spec) } -func (ifq *ItemFieldQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := ifq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (ifq *ItemFieldQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -528,13 +533,8 @@ func (ifq *ItemFieldQuery) sqlQuery(ctx context.Context) *sql.Selector { // ItemFieldGroupBy is the group-by builder for ItemField entities. type ItemFieldGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *ItemFieldQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -543,58 +543,46 @@ func (ifgb *ItemFieldGroupBy) Aggregate(fns ...AggregateFunc) *ItemFieldGroupBy return ifgb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (ifgb *ItemFieldGroupBy) Scan(ctx context.Context, v any) error { - query, err := ifgb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeItemField, "GroupBy") + if err := ifgb.build.prepareQuery(ctx); err != nil { return err } - ifgb.sql = query - return ifgb.sqlScan(ctx, v) + return scanWithInterceptors[*ItemFieldQuery, *ItemFieldGroupBy](ctx, ifgb.build, ifgb, ifgb.build.inters, v) } -func (ifgb *ItemFieldGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range ifgb.fields { - if !itemfield.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (ifgb *ItemFieldGroupBy) sqlScan(ctx context.Context, root *ItemFieldQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(ifgb.fns)) + for _, fn := range ifgb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := ifgb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*ifgb.flds)+len(ifgb.fns)) + for _, f := range *ifgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*ifgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := ifgb.driver.Query(ctx, query, args, rows); err != nil { + if err := ifgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (ifgb *ItemFieldGroupBy) sqlQuery() *sql.Selector { - selector := ifgb.sql.Select() - aggregation := make([]string, 0, len(ifgb.fns)) - for _, fn := range ifgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(ifgb.fields)+len(ifgb.fns)) - for _, f := range ifgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(ifgb.fields...)...) -} - // ItemFieldSelect is the builder for selecting fields of ItemField entities. type ItemFieldSelect struct { *ItemFieldQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -605,26 +593,27 @@ 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") if err := ifs.prepareQuery(ctx); err != nil { return err } - ifs.sql = ifs.ItemFieldQuery.sqlQuery(ctx) - return ifs.sqlScan(ctx, v) + return scanWithInterceptors[*ItemFieldQuery, *ItemFieldSelect](ctx, ifs.ItemFieldQuery, ifs, ifs.inters, v) } -func (ifs *ItemFieldSelect) sqlScan(ctx context.Context, v any) error { +func (ifs *ItemFieldSelect) sqlScan(ctx context.Context, root *ItemFieldQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(ifs.fns)) for _, fn := range ifs.fns { - aggregation = append(aggregation, fn(ifs.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*ifs.selector.flds); { case n == 0 && len(aggregation) > 0: - ifs.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - ifs.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := ifs.sql.Query() + query, args := selector.Query() if err := ifs.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/itemfield_update.go b/backend/internal/data/ent/itemfield_update.go index a0bb9a2..ec93a55 100644 --- a/backend/internal/data/ent/itemfield_update.go +++ b/backend/internal/data/ent/itemfield_update.go @@ -175,41 +175,8 @@ func (ifu *ItemFieldUpdate) ClearItem() *ItemFieldUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (ifu *ItemFieldUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) ifu.defaults() - if len(ifu.hooks) == 0 { - if err = ifu.check(); err != nil { - return 0, err - } - affected, err = ifu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ItemFieldMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = ifu.check(); err != nil { - return 0, err - } - ifu.mutation = mutation - affected, err = ifu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(ifu.hooks) - 1; i >= 0; i-- { - if ifu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ifu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ifu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, ItemFieldMutation](ctx, ifu.sqlSave, ifu.mutation, ifu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -268,6 +235,9 @@ func (ifu *ItemFieldUpdate) check() error { } func (ifu *ItemFieldUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := ifu.check(); err != nil { + return n, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: itemfield.Table, @@ -364,6 +334,7 @@ func (ifu *ItemFieldUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + ifu.mutation.done = true return n, nil } @@ -527,47 +498,8 @@ func (ifuo *ItemFieldUpdateOne) Select(field string, fields ...string) *ItemFiel // Save executes the query and returns the updated ItemField entity. func (ifuo *ItemFieldUpdateOne) Save(ctx context.Context) (*ItemField, error) { - var ( - err error - node *ItemField - ) ifuo.defaults() - if len(ifuo.hooks) == 0 { - if err = ifuo.check(); err != nil { - return nil, err - } - node, err = ifuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ItemFieldMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = ifuo.check(); err != nil { - return nil, err - } - ifuo.mutation = mutation - node, err = ifuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(ifuo.hooks) - 1; i >= 0; i-- { - if ifuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ifuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, ifuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*ItemField) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from ItemFieldMutation", v) - } - node = nv - } - return node, err + return withHooks[*ItemField, ItemFieldMutation](ctx, ifuo.sqlSave, ifuo.mutation, ifuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -626,6 +558,9 @@ func (ifuo *ItemFieldUpdateOne) check() error { } func (ifuo *ItemFieldUpdateOne) sqlSave(ctx context.Context) (_node *ItemField, err error) { + if err := ifuo.check(); err != nil { + return _node, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: itemfield.Table, @@ -742,5 +677,6 @@ func (ifuo *ItemFieldUpdateOne) sqlSave(ctx context.Context) (_node *ItemField, } return nil, err } + ifuo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/label/where.go b/backend/internal/data/ent/label/where.go index 9279ee7..fd321e1 100644 --- a/backend/internal/data/ent/label/where.go +++ b/backend/internal/data/ent/label/where.go @@ -13,561 +13,367 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Label(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Label(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Label(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.Label(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.Label(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Label(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Label(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Label(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Label(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Label(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Label(sql.FieldEQ(FieldUpdatedAt, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldEQ(FieldName, v)) } // Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. func Description(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldEQ(FieldDescription, v)) } // Color applies equality check predicate on the "color" field. It's identical to ColorEQ. func Color(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldEQ(FieldColor, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Label(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Label(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.Label { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.Label(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.Label { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.Label(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.Label(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Label(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.Label(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Label(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Label(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Label(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.Label { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Label(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.Label { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Label(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Label(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Label(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Label(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Label(sql.FieldLTE(FieldUpdatedAt, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.Label { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.Label(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.Label { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.Label(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.Label(sql.FieldContainsFold(FieldName, v)) } // DescriptionEQ applies the EQ predicate on the "description" field. func DescriptionEQ(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldEQ(FieldDescription, v)) } // DescriptionNEQ applies the NEQ predicate on the "description" field. func DescriptionNEQ(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldNEQ(FieldDescription, v)) } // DescriptionIn applies the In predicate on the "description" field. func DescriptionIn(vs ...string) predicate.Label { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldDescription), v...)) - }) + return predicate.Label(sql.FieldIn(FieldDescription, vs...)) } // DescriptionNotIn applies the NotIn predicate on the "description" field. func DescriptionNotIn(vs ...string) predicate.Label { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldDescription), v...)) - }) + return predicate.Label(sql.FieldNotIn(FieldDescription, vs...)) } // DescriptionGT applies the GT predicate on the "description" field. func DescriptionGT(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldGT(FieldDescription, v)) } // DescriptionGTE applies the GTE predicate on the "description" field. func DescriptionGTE(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldGTE(FieldDescription, v)) } // DescriptionLT applies the LT predicate on the "description" field. func DescriptionLT(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldLT(FieldDescription, v)) } // DescriptionLTE applies the LTE predicate on the "description" field. func DescriptionLTE(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldLTE(FieldDescription, v)) } // DescriptionContains applies the Contains predicate on the "description" field. func DescriptionContains(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldContains(FieldDescription, v)) } // DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. func DescriptionHasPrefix(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldHasPrefix(FieldDescription, v)) } // DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. func DescriptionHasSuffix(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldHasSuffix(FieldDescription, v)) } // DescriptionIsNil applies the IsNil predicate on the "description" field. func DescriptionIsNil() predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldDescription))) - }) + return predicate.Label(sql.FieldIsNull(FieldDescription)) } // DescriptionNotNil applies the NotNil predicate on the "description" field. func DescriptionNotNil() predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldDescription))) - }) + return predicate.Label(sql.FieldNotNull(FieldDescription)) } // DescriptionEqualFold applies the EqualFold predicate on the "description" field. func DescriptionEqualFold(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldEqualFold(FieldDescription, v)) } // DescriptionContainsFold applies the ContainsFold predicate on the "description" field. func DescriptionContainsFold(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldDescription), v)) - }) + return predicate.Label(sql.FieldContainsFold(FieldDescription, v)) } // ColorEQ applies the EQ predicate on the "color" field. func ColorEQ(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldEQ(FieldColor, v)) } // ColorNEQ applies the NEQ predicate on the "color" field. func ColorNEQ(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldNEQ(FieldColor, v)) } // ColorIn applies the In predicate on the "color" field. func ColorIn(vs ...string) predicate.Label { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldColor), v...)) - }) + return predicate.Label(sql.FieldIn(FieldColor, vs...)) } // ColorNotIn applies the NotIn predicate on the "color" field. func ColorNotIn(vs ...string) predicate.Label { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldColor), v...)) - }) + return predicate.Label(sql.FieldNotIn(FieldColor, vs...)) } // ColorGT applies the GT predicate on the "color" field. func ColorGT(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldGT(FieldColor, v)) } // ColorGTE applies the GTE predicate on the "color" field. func ColorGTE(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldGTE(FieldColor, v)) } // ColorLT applies the LT predicate on the "color" field. func ColorLT(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldLT(FieldColor, v)) } // ColorLTE applies the LTE predicate on the "color" field. func ColorLTE(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldLTE(FieldColor, v)) } // ColorContains applies the Contains predicate on the "color" field. func ColorContains(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldContains(FieldColor, v)) } // ColorHasPrefix applies the HasPrefix predicate on the "color" field. func ColorHasPrefix(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldHasPrefix(FieldColor, v)) } // ColorHasSuffix applies the HasSuffix predicate on the "color" field. func ColorHasSuffix(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldHasSuffix(FieldColor, v)) } // ColorIsNil applies the IsNil predicate on the "color" field. func ColorIsNil() predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldColor))) - }) + return predicate.Label(sql.FieldIsNull(FieldColor)) } // ColorNotNil applies the NotNil predicate on the "color" field. func ColorNotNil() predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldColor))) - }) + return predicate.Label(sql.FieldNotNull(FieldColor)) } // ColorEqualFold applies the EqualFold predicate on the "color" field. func ColorEqualFold(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldEqualFold(FieldColor, v)) } // ColorContainsFold applies the ContainsFold predicate on the "color" field. func ColorContainsFold(v string) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldColor), v)) - }) + return predicate.Label(sql.FieldContainsFold(FieldColor, v)) } // HasGroup applies the HasEdge predicate on the "group" edge. @@ -575,7 +381,6 @@ func HasGroup() predicate.Label { return predicate.Label(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), ) sqlgraph.HasNeighbors(s, step) @@ -603,7 +408,6 @@ func HasItems() predicate.Label { return predicate.Label(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ItemsTable, FieldID), sqlgraph.Edge(sqlgraph.M2M, false, ItemsTable, ItemsPrimaryKey...), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/label_create.go b/backend/internal/data/ent/label_create.go index 040669b..a9d8649 100644 --- a/backend/internal/data/ent/label_create.go +++ b/backend/internal/data/ent/label_create.go @@ -132,50 +132,8 @@ func (lc *LabelCreate) Mutation() *LabelMutation { // Save creates the Label in the database. func (lc *LabelCreate) Save(ctx context.Context) (*Label, error) { - var ( - err error - node *Label - ) lc.defaults() - if len(lc.hooks) == 0 { - if err = lc.check(); err != nil { - return nil, err - } - node, err = lc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*LabelMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = lc.check(); err != nil { - return nil, err - } - lc.mutation = mutation - if node, err = lc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(lc.hooks) - 1; i >= 0; i-- { - if lc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = lc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, lc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Label) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from LabelMutation", v) - } - node = nv - } - return node, err + return withHooks[*Label, LabelMutation](ctx, lc.sqlSave, lc.mutation, lc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -249,6 +207,9 @@ func (lc *LabelCreate) check() error { } func (lc *LabelCreate) sqlSave(ctx context.Context) (*Label, error) { + if err := lc.check(); err != nil { + return nil, err + } _node, _spec := lc.createSpec() if err := sqlgraph.CreateNode(ctx, lc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -263,6 +224,8 @@ func (lc *LabelCreate) sqlSave(ctx context.Context) (*Label, error) { return nil, err } } + lc.mutation.id = &_node.ID + lc.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/label_delete.go b/backend/internal/data/ent/label_delete.go index 28e103c..1c520df 100644 --- a/backend/internal/data/ent/label_delete.go +++ b/backend/internal/data/ent/label_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (ld *LabelDelete) Where(ps ...predicate.Label) *LabelDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ld *LabelDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ld.hooks) == 0 { - affected, err = ld.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*LabelMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ld.mutation = mutation - affected, err = ld.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ld.hooks) - 1; i >= 0; i-- { - if ld.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ld.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ld.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, LabelMutation](ctx, ld.sqlExec, ld.mutation, ld.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (ld *LabelDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + ld.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/label_query.go b/backend/internal/data/ent/label_query.go index 193579f..16de809 100644 --- a/backend/internal/data/ent/label_query.go +++ b/backend/internal/data/ent/label_query.go @@ -26,6 +26,7 @@ type LabelQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.Label withGroup *GroupQuery withItems *ItemQuery @@ -41,13 +42,13 @@ func (lq *LabelQuery) Where(ps ...predicate.Label) *LabelQuery { return lq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (lq *LabelQuery) Limit(limit int) *LabelQuery { lq.limit = &limit return lq } -// Offset adds an offset step to the query. +// Offset to start from. func (lq *LabelQuery) Offset(offset int) *LabelQuery { lq.offset = &offset return lq @@ -60,7 +61,7 @@ func (lq *LabelQuery) Unique(unique bool) *LabelQuery { return lq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (lq *LabelQuery) Order(o ...OrderFunc) *LabelQuery { lq.order = append(lq.order, o...) return lq @@ -68,7 +69,7 @@ func (lq *LabelQuery) Order(o ...OrderFunc) *LabelQuery { // QueryGroup chains the current query on the "group" edge. func (lq *LabelQuery) QueryGroup() *GroupQuery { - query := &GroupQuery{config: lq.config} + query := (&GroupClient{config: lq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := lq.prepareQuery(ctx); err != nil { return nil, err @@ -90,7 +91,7 @@ func (lq *LabelQuery) QueryGroup() *GroupQuery { // QueryItems chains the current query on the "items" edge. func (lq *LabelQuery) QueryItems() *ItemQuery { - query := &ItemQuery{config: lq.config} + query := (&ItemClient{config: lq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := lq.prepareQuery(ctx); err != nil { return nil, err @@ -113,7 +114,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(ctx) + nodes, err := lq.Limit(1).All(newQueryContext(ctx, TypeLabel, "First")) if err != nil { return nil, err } @@ -136,7 +137,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(ctx); err != nil { + if ids, err = lq.Limit(1).IDs(newQueryContext(ctx, TypeLabel, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -159,7 +160,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(ctx) + nodes, err := lq.Limit(2).All(newQueryContext(ctx, TypeLabel, "Only")) if err != nil { return nil, err } @@ -187,7 +188,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(ctx); err != nil { + if ids, err = lq.Limit(2).IDs(newQueryContext(ctx, TypeLabel, "OnlyID")); err != nil { return } switch len(ids) { @@ -212,10 +213,12 @@ 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") if err := lq.prepareQuery(ctx); err != nil { return nil, err } - return lq.sqlAll(ctx) + qr := querierAll[[]*Label, *LabelQuery]() + return withInterceptors[[]*Label](ctx, lq, qr, lq.inters) } // AllX is like All, but panics if an error occurs. @@ -230,6 +233,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") if err := lq.Select(label.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -247,10 +251,11 @@ 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") if err := lq.prepareQuery(ctx); err != nil { return 0, err } - return lq.sqlCount(ctx) + return withInterceptors[int](ctx, lq, querierCount[*LabelQuery](), lq.inters) } // CountX is like Count, but panics if an error occurs. @@ -264,10 +269,15 @@ 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) { - if err := lq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeLabel, "Exist") + switch _, err := lq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return lq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -290,6 +300,7 @@ func (lq *LabelQuery) Clone() *LabelQuery { limit: lq.limit, offset: lq.offset, order: append([]OrderFunc{}, lq.order...), + inters: append([]Interceptor{}, lq.inters...), predicates: append([]predicate.Label{}, lq.predicates...), withGroup: lq.withGroup.Clone(), withItems: lq.withItems.Clone(), @@ -303,7 +314,7 @@ func (lq *LabelQuery) Clone() *LabelQuery { // WithGroup tells the query-builder to eager-load the nodes that are connected to // the "group" edge. The optional arguments are used to configure the query builder of the edge. func (lq *LabelQuery) WithGroup(opts ...func(*GroupQuery)) *LabelQuery { - query := &GroupQuery{config: lq.config} + query := (&GroupClient{config: lq.config}).Query() for _, opt := range opts { opt(query) } @@ -314,7 +325,7 @@ func (lq *LabelQuery) WithGroup(opts ...func(*GroupQuery)) *LabelQuery { // WithItems tells the query-builder to eager-load the nodes that are connected to // the "items" edge. The optional arguments are used to configure the query builder of the edge. func (lq *LabelQuery) WithItems(opts ...func(*ItemQuery)) *LabelQuery { - query := &ItemQuery{config: lq.config} + query := (&ItemClient{config: lq.config}).Query() for _, opt := range opts { opt(query) } @@ -337,16 +348,11 @@ func (lq *LabelQuery) WithItems(opts ...func(*ItemQuery)) *LabelQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (lq *LabelQuery) GroupBy(field string, fields ...string) *LabelGroupBy { - grbuild := &LabelGroupBy{config: lq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := lq.prepareQuery(ctx); err != nil { - return nil, err - } - return lq.sqlQuery(ctx), nil - } + lq.fields = append([]string{field}, fields...) + grbuild := &LabelGroupBy{build: lq} + grbuild.flds = &lq.fields grbuild.label = label.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -364,10 +370,10 @@ func (lq *LabelQuery) GroupBy(field string, fields ...string) *LabelGroupBy { // Scan(ctx, &v) func (lq *LabelQuery) Select(fields ...string) *LabelSelect { lq.fields = append(lq.fields, fields...) - selbuild := &LabelSelect{LabelQuery: lq} - selbuild.label = label.Label - selbuild.flds, selbuild.scan = &lq.fields, selbuild.Scan - return selbuild + sbuild := &LabelSelect{LabelQuery: lq} + sbuild.label = label.Label + sbuild.flds, sbuild.scan = &lq.fields, sbuild.Scan + return sbuild } // Aggregate returns a LabelSelect configured with the given aggregations. @@ -376,6 +382,16 @@ func (lq *LabelQuery) Aggregate(fns ...AggregateFunc) *LabelSelect { } func (lq *LabelQuery) prepareQuery(ctx context.Context) error { + for _, inter := range lq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, lq); err != nil { + return err + } + } + } for _, f := range lq.fields { if !label.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -538,17 +554,6 @@ func (lq *LabelQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, lq.driver, _spec) } -func (lq *LabelQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := lq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (lq *LabelQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -631,13 +636,8 @@ func (lq *LabelQuery) sqlQuery(ctx context.Context) *sql.Selector { // LabelGroupBy is the group-by builder for Label entities. type LabelGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *LabelQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -646,58 +646,46 @@ func (lgb *LabelGroupBy) Aggregate(fns ...AggregateFunc) *LabelGroupBy { return lgb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (lgb *LabelGroupBy) Scan(ctx context.Context, v any) error { - query, err := lgb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeLabel, "GroupBy") + if err := lgb.build.prepareQuery(ctx); err != nil { return err } - lgb.sql = query - return lgb.sqlScan(ctx, v) + return scanWithInterceptors[*LabelQuery, *LabelGroupBy](ctx, lgb.build, lgb, lgb.build.inters, v) } -func (lgb *LabelGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range lgb.fields { - if !label.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (lgb *LabelGroupBy) sqlScan(ctx context.Context, root *LabelQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(lgb.fns)) + for _, fn := range lgb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := lgb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*lgb.flds)+len(lgb.fns)) + for _, f := range *lgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*lgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := lgb.driver.Query(ctx, query, args, rows); err != nil { + if err := lgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (lgb *LabelGroupBy) sqlQuery() *sql.Selector { - selector := lgb.sql.Select() - aggregation := make([]string, 0, len(lgb.fns)) - for _, fn := range lgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(lgb.fields)+len(lgb.fns)) - for _, f := range lgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(lgb.fields...)...) -} - // LabelSelect is the builder for selecting fields of Label entities. type LabelSelect struct { *LabelQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -708,26 +696,27 @@ 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") if err := ls.prepareQuery(ctx); err != nil { return err } - ls.sql = ls.LabelQuery.sqlQuery(ctx) - return ls.sqlScan(ctx, v) + return scanWithInterceptors[*LabelQuery, *LabelSelect](ctx, ls.LabelQuery, ls, ls.inters, v) } -func (ls *LabelSelect) sqlScan(ctx context.Context, v any) error { +func (ls *LabelSelect) sqlScan(ctx context.Context, root *LabelQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(ls.fns)) for _, fn := range ls.fns { - aggregation = append(aggregation, fn(ls.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*ls.selector.flds); { case n == 0 && len(aggregation) > 0: - ls.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - ls.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := ls.sql.Query() + query, args := selector.Query() if err := ls.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/label_update.go b/backend/internal/data/ent/label_update.go index 64877d1..5b40eb2 100644 --- a/backend/internal/data/ent/label_update.go +++ b/backend/internal/data/ent/label_update.go @@ -143,41 +143,8 @@ func (lu *LabelUpdate) RemoveItems(i ...*Item) *LabelUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (lu *LabelUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) lu.defaults() - if len(lu.hooks) == 0 { - if err = lu.check(); err != nil { - return 0, err - } - affected, err = lu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*LabelMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = lu.check(); err != nil { - return 0, err - } - lu.mutation = mutation - affected, err = lu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(lu.hooks) - 1; i >= 0; i-- { - if lu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = lu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, lu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, LabelMutation](ctx, lu.sqlSave, lu.mutation, lu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -234,6 +201,9 @@ func (lu *LabelUpdate) check() error { } func (lu *LabelUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := lu.check(); err != nil { + return n, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: label.Table, @@ -366,6 +336,7 @@ func (lu *LabelUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + lu.mutation.done = true return n, nil } @@ -496,47 +467,8 @@ func (luo *LabelUpdateOne) Select(field string, fields ...string) *LabelUpdateOn // Save executes the query and returns the updated Label entity. func (luo *LabelUpdateOne) Save(ctx context.Context) (*Label, error) { - var ( - err error - node *Label - ) luo.defaults() - if len(luo.hooks) == 0 { - if err = luo.check(); err != nil { - return nil, err - } - node, err = luo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*LabelMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = luo.check(); err != nil { - return nil, err - } - luo.mutation = mutation - node, err = luo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(luo.hooks) - 1; i >= 0; i-- { - if luo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = luo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, luo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Label) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from LabelMutation", v) - } - node = nv - } - return node, err + return withHooks[*Label, LabelMutation](ctx, luo.sqlSave, luo.mutation, luo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -593,6 +525,9 @@ func (luo *LabelUpdateOne) check() error { } func (luo *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) { + if err := luo.check(); err != nil { + return _node, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: label.Table, @@ -745,5 +680,6 @@ func (luo *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error } return nil, err } + luo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/location/where.go b/backend/internal/data/ent/location/where.go index 73f28bd..cd9a20e 100644 --- a/backend/internal/data/ent/location/where.go +++ b/backend/internal/data/ent/location/where.go @@ -13,441 +13,287 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Location(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Location(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Location(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.Location(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.Location(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Location(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Location(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Location(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Location(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Location(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Location(sql.FieldEQ(FieldUpdatedAt, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldEQ(FieldName, v)) } // Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. func Description(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldEQ(FieldDescription, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Location(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Location(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.Location { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.Location(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.Location { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.Location(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.Location(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Location(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.Location(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Location(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Location(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.Location(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.Location { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Location(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.Location { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.Location(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Location(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Location(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.Location(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.Location(sql.FieldLTE(FieldUpdatedAt, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.Location { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.Location(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.Location { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.Location(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.Location(sql.FieldContainsFold(FieldName, v)) } // DescriptionEQ applies the EQ predicate on the "description" field. func DescriptionEQ(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldEQ(FieldDescription, v)) } // DescriptionNEQ applies the NEQ predicate on the "description" field. func DescriptionNEQ(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldNEQ(FieldDescription, v)) } // DescriptionIn applies the In predicate on the "description" field. func DescriptionIn(vs ...string) predicate.Location { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldDescription), v...)) - }) + return predicate.Location(sql.FieldIn(FieldDescription, vs...)) } // DescriptionNotIn applies the NotIn predicate on the "description" field. func DescriptionNotIn(vs ...string) predicate.Location { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldDescription), v...)) - }) + return predicate.Location(sql.FieldNotIn(FieldDescription, vs...)) } // DescriptionGT applies the GT predicate on the "description" field. func DescriptionGT(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldGT(FieldDescription, v)) } // DescriptionGTE applies the GTE predicate on the "description" field. func DescriptionGTE(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldGTE(FieldDescription, v)) } // DescriptionLT applies the LT predicate on the "description" field. func DescriptionLT(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldLT(FieldDescription, v)) } // DescriptionLTE applies the LTE predicate on the "description" field. func DescriptionLTE(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldLTE(FieldDescription, v)) } // DescriptionContains applies the Contains predicate on the "description" field. func DescriptionContains(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldContains(FieldDescription, v)) } // DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. func DescriptionHasPrefix(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldHasPrefix(FieldDescription, v)) } // DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. func DescriptionHasSuffix(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldHasSuffix(FieldDescription, v)) } // DescriptionIsNil applies the IsNil predicate on the "description" field. func DescriptionIsNil() predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldDescription))) - }) + return predicate.Location(sql.FieldIsNull(FieldDescription)) } // DescriptionNotNil applies the NotNil predicate on the "description" field. func DescriptionNotNil() predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldDescription))) - }) + return predicate.Location(sql.FieldNotNull(FieldDescription)) } // DescriptionEqualFold applies the EqualFold predicate on the "description" field. func DescriptionEqualFold(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldEqualFold(FieldDescription, v)) } // DescriptionContainsFold applies the ContainsFold predicate on the "description" field. func DescriptionContainsFold(v string) predicate.Location { - return predicate.Location(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldDescription), v)) - }) + return predicate.Location(sql.FieldContainsFold(FieldDescription, v)) } // HasParent applies the HasEdge predicate on the "parent" edge. @@ -455,7 +301,6 @@ func HasParent() predicate.Location { return predicate.Location(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ParentTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, ParentTable, ParentColumn), ) sqlgraph.HasNeighbors(s, step) @@ -483,7 +328,6 @@ func HasChildren() predicate.Location { return predicate.Location(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ChildrenTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, ChildrenTable, ChildrenColumn), ) sqlgraph.HasNeighbors(s, step) @@ -511,7 +355,6 @@ func HasGroup() predicate.Location { return predicate.Location(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), ) sqlgraph.HasNeighbors(s, step) @@ -539,7 +382,6 @@ func HasItems() predicate.Location { return predicate.Location(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ItemsTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, ItemsTable, ItemsColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/location_create.go b/backend/internal/data/ent/location_create.go index 55d9661..72618cf 100644 --- a/backend/internal/data/ent/location_create.go +++ b/backend/internal/data/ent/location_create.go @@ -152,50 +152,8 @@ func (lc *LocationCreate) Mutation() *LocationMutation { // Save creates the Location in the database. func (lc *LocationCreate) Save(ctx context.Context) (*Location, error) { - var ( - err error - node *Location - ) lc.defaults() - if len(lc.hooks) == 0 { - if err = lc.check(); err != nil { - return nil, err - } - node, err = lc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*LocationMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = lc.check(); err != nil { - return nil, err - } - lc.mutation = mutation - if node, err = lc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(lc.hooks) - 1; i >= 0; i-- { - if lc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = lc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, lc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Location) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from LocationMutation", v) - } - node = nv - } - return node, err + return withHooks[*Location, LocationMutation](ctx, lc.sqlSave, lc.mutation, lc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -264,6 +222,9 @@ func (lc *LocationCreate) check() error { } func (lc *LocationCreate) sqlSave(ctx context.Context) (*Location, error) { + if err := lc.check(); err != nil { + return nil, err + } _node, _spec := lc.createSpec() if err := sqlgraph.CreateNode(ctx, lc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -278,6 +239,8 @@ func (lc *LocationCreate) sqlSave(ctx context.Context) (*Location, error) { return nil, err } } + lc.mutation.id = &_node.ID + lc.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/location_delete.go b/backend/internal/data/ent/location_delete.go index 7fd8e84..22403fe 100644 --- a/backend/internal/data/ent/location_delete.go +++ b/backend/internal/data/ent/location_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (ld *LocationDelete) Where(ps ...predicate.Location) *LocationDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ld *LocationDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ld.hooks) == 0 { - affected, err = ld.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*LocationMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ld.mutation = mutation - affected, err = ld.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ld.hooks) - 1; i >= 0; i-- { - if ld.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ld.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ld.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, LocationMutation](ctx, ld.sqlExec, ld.mutation, ld.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (ld *LocationDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + ld.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/location_query.go b/backend/internal/data/ent/location_query.go index eb6c492..992644d 100644 --- a/backend/internal/data/ent/location_query.go +++ b/backend/internal/data/ent/location_query.go @@ -26,6 +26,7 @@ type LocationQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.Location withParent *LocationQuery withChildren *LocationQuery @@ -43,13 +44,13 @@ func (lq *LocationQuery) Where(ps ...predicate.Location) *LocationQuery { return lq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (lq *LocationQuery) Limit(limit int) *LocationQuery { lq.limit = &limit return lq } -// Offset adds an offset step to the query. +// Offset to start from. func (lq *LocationQuery) Offset(offset int) *LocationQuery { lq.offset = &offset return lq @@ -62,7 +63,7 @@ func (lq *LocationQuery) Unique(unique bool) *LocationQuery { return lq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (lq *LocationQuery) Order(o ...OrderFunc) *LocationQuery { lq.order = append(lq.order, o...) return lq @@ -70,7 +71,7 @@ func (lq *LocationQuery) Order(o ...OrderFunc) *LocationQuery { // QueryParent chains the current query on the "parent" edge. func (lq *LocationQuery) QueryParent() *LocationQuery { - query := &LocationQuery{config: lq.config} + query := (&LocationClient{config: lq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := lq.prepareQuery(ctx); err != nil { return nil, err @@ -92,7 +93,7 @@ func (lq *LocationQuery) QueryParent() *LocationQuery { // QueryChildren chains the current query on the "children" edge. func (lq *LocationQuery) QueryChildren() *LocationQuery { - query := &LocationQuery{config: lq.config} + query := (&LocationClient{config: lq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := lq.prepareQuery(ctx); err != nil { return nil, err @@ -114,7 +115,7 @@ func (lq *LocationQuery) QueryChildren() *LocationQuery { // QueryGroup chains the current query on the "group" edge. func (lq *LocationQuery) QueryGroup() *GroupQuery { - query := &GroupQuery{config: lq.config} + query := (&GroupClient{config: lq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := lq.prepareQuery(ctx); err != nil { return nil, err @@ -136,7 +137,7 @@ func (lq *LocationQuery) QueryGroup() *GroupQuery { // QueryItems chains the current query on the "items" edge. func (lq *LocationQuery) QueryItems() *ItemQuery { - query := &ItemQuery{config: lq.config} + query := (&ItemClient{config: lq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := lq.prepareQuery(ctx); err != nil { return nil, err @@ -159,7 +160,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(ctx) + nodes, err := lq.Limit(1).All(newQueryContext(ctx, TypeLocation, "First")) if err != nil { return nil, err } @@ -182,7 +183,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(ctx); err != nil { + if ids, err = lq.Limit(1).IDs(newQueryContext(ctx, TypeLocation, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -205,7 +206,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(ctx) + nodes, err := lq.Limit(2).All(newQueryContext(ctx, TypeLocation, "Only")) if err != nil { return nil, err } @@ -233,7 +234,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(ctx); err != nil { + if ids, err = lq.Limit(2).IDs(newQueryContext(ctx, TypeLocation, "OnlyID")); err != nil { return } switch len(ids) { @@ -258,10 +259,12 @@ 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") if err := lq.prepareQuery(ctx); err != nil { return nil, err } - return lq.sqlAll(ctx) + qr := querierAll[[]*Location, *LocationQuery]() + return withInterceptors[[]*Location](ctx, lq, qr, lq.inters) } // AllX is like All, but panics if an error occurs. @@ -276,6 +279,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") if err := lq.Select(location.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -293,10 +297,11 @@ 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") if err := lq.prepareQuery(ctx); err != nil { return 0, err } - return lq.sqlCount(ctx) + return withInterceptors[int](ctx, lq, querierCount[*LocationQuery](), lq.inters) } // CountX is like Count, but panics if an error occurs. @@ -310,10 +315,15 @@ 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) { - if err := lq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeLocation, "Exist") + switch _, err := lq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return lq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -336,6 +346,7 @@ func (lq *LocationQuery) Clone() *LocationQuery { limit: lq.limit, offset: lq.offset, order: append([]OrderFunc{}, lq.order...), + inters: append([]Interceptor{}, lq.inters...), predicates: append([]predicate.Location{}, lq.predicates...), withParent: lq.withParent.Clone(), withChildren: lq.withChildren.Clone(), @@ -351,7 +362,7 @@ func (lq *LocationQuery) Clone() *LocationQuery { // WithParent tells the query-builder to eager-load the nodes that are connected to // the "parent" edge. The optional arguments are used to configure the query builder of the edge. func (lq *LocationQuery) WithParent(opts ...func(*LocationQuery)) *LocationQuery { - query := &LocationQuery{config: lq.config} + query := (&LocationClient{config: lq.config}).Query() for _, opt := range opts { opt(query) } @@ -362,7 +373,7 @@ func (lq *LocationQuery) WithParent(opts ...func(*LocationQuery)) *LocationQuery // WithChildren tells the query-builder to eager-load the nodes that are connected to // the "children" edge. The optional arguments are used to configure the query builder of the edge. func (lq *LocationQuery) WithChildren(opts ...func(*LocationQuery)) *LocationQuery { - query := &LocationQuery{config: lq.config} + query := (&LocationClient{config: lq.config}).Query() for _, opt := range opts { opt(query) } @@ -373,7 +384,7 @@ func (lq *LocationQuery) WithChildren(opts ...func(*LocationQuery)) *LocationQue // WithGroup tells the query-builder to eager-load the nodes that are connected to // the "group" edge. The optional arguments are used to configure the query builder of the edge. func (lq *LocationQuery) WithGroup(opts ...func(*GroupQuery)) *LocationQuery { - query := &GroupQuery{config: lq.config} + query := (&GroupClient{config: lq.config}).Query() for _, opt := range opts { opt(query) } @@ -384,7 +395,7 @@ func (lq *LocationQuery) WithGroup(opts ...func(*GroupQuery)) *LocationQuery { // WithItems tells the query-builder to eager-load the nodes that are connected to // the "items" edge. The optional arguments are used to configure the query builder of the edge. func (lq *LocationQuery) WithItems(opts ...func(*ItemQuery)) *LocationQuery { - query := &ItemQuery{config: lq.config} + query := (&ItemClient{config: lq.config}).Query() for _, opt := range opts { opt(query) } @@ -407,16 +418,11 @@ func (lq *LocationQuery) WithItems(opts ...func(*ItemQuery)) *LocationQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (lq *LocationQuery) GroupBy(field string, fields ...string) *LocationGroupBy { - grbuild := &LocationGroupBy{config: lq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := lq.prepareQuery(ctx); err != nil { - return nil, err - } - return lq.sqlQuery(ctx), nil - } + lq.fields = append([]string{field}, fields...) + grbuild := &LocationGroupBy{build: lq} + grbuild.flds = &lq.fields grbuild.label = location.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -434,10 +440,10 @@ func (lq *LocationQuery) GroupBy(field string, fields ...string) *LocationGroupB // Scan(ctx, &v) func (lq *LocationQuery) Select(fields ...string) *LocationSelect { lq.fields = append(lq.fields, fields...) - selbuild := &LocationSelect{LocationQuery: lq} - selbuild.label = location.Label - selbuild.flds, selbuild.scan = &lq.fields, selbuild.Scan - return selbuild + sbuild := &LocationSelect{LocationQuery: lq} + sbuild.label = location.Label + sbuild.flds, sbuild.scan = &lq.fields, sbuild.Scan + return sbuild } // Aggregate returns a LocationSelect configured with the given aggregations. @@ -446,6 +452,16 @@ func (lq *LocationQuery) Aggregate(fns ...AggregateFunc) *LocationSelect { } func (lq *LocationQuery) prepareQuery(ctx context.Context) error { + for _, inter := range lq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, lq); err != nil { + return err + } + } + } for _, f := range lq.fields { if !location.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -656,17 +672,6 @@ func (lq *LocationQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, lq.driver, _spec) } -func (lq *LocationQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := lq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (lq *LocationQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -749,13 +754,8 @@ func (lq *LocationQuery) sqlQuery(ctx context.Context) *sql.Selector { // LocationGroupBy is the group-by builder for Location entities. type LocationGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *LocationQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -764,58 +764,46 @@ func (lgb *LocationGroupBy) Aggregate(fns ...AggregateFunc) *LocationGroupBy { return lgb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (lgb *LocationGroupBy) Scan(ctx context.Context, v any) error { - query, err := lgb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeLocation, "GroupBy") + if err := lgb.build.prepareQuery(ctx); err != nil { return err } - lgb.sql = query - return lgb.sqlScan(ctx, v) + return scanWithInterceptors[*LocationQuery, *LocationGroupBy](ctx, lgb.build, lgb, lgb.build.inters, v) } -func (lgb *LocationGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range lgb.fields { - if !location.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (lgb *LocationGroupBy) sqlScan(ctx context.Context, root *LocationQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(lgb.fns)) + for _, fn := range lgb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := lgb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*lgb.flds)+len(lgb.fns)) + for _, f := range *lgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*lgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := lgb.driver.Query(ctx, query, args, rows); err != nil { + if err := lgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (lgb *LocationGroupBy) sqlQuery() *sql.Selector { - selector := lgb.sql.Select() - aggregation := make([]string, 0, len(lgb.fns)) - for _, fn := range lgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(lgb.fields)+len(lgb.fns)) - for _, f := range lgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(lgb.fields...)...) -} - // LocationSelect is the builder for selecting fields of Location entities. type LocationSelect struct { *LocationQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -826,26 +814,27 @@ 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") if err := ls.prepareQuery(ctx); err != nil { return err } - ls.sql = ls.LocationQuery.sqlQuery(ctx) - return ls.sqlScan(ctx, v) + return scanWithInterceptors[*LocationQuery, *LocationSelect](ctx, ls.LocationQuery, ls, ls.inters, v) } -func (ls *LocationSelect) sqlScan(ctx context.Context, v any) error { +func (ls *LocationSelect) sqlScan(ctx context.Context, root *LocationQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(ls.fns)) for _, fn := range ls.fns { - aggregation = append(aggregation, fn(ls.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*ls.selector.flds); { case n == 0 && len(aggregation) > 0: - ls.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - ls.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := ls.sql.Query() + query, args := selector.Query() if err := ls.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/location_update.go b/backend/internal/data/ent/location_update.go index f4c88fe..6833208 100644 --- a/backend/internal/data/ent/location_update.go +++ b/backend/internal/data/ent/location_update.go @@ -184,41 +184,8 @@ func (lu *LocationUpdate) RemoveItems(i ...*Item) *LocationUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (lu *LocationUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) lu.defaults() - if len(lu.hooks) == 0 { - if err = lu.check(); err != nil { - return 0, err - } - affected, err = lu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*LocationMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = lu.check(); err != nil { - return 0, err - } - lu.mutation = mutation - affected, err = lu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(lu.hooks) - 1; i >= 0; i-- { - if lu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = lu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, lu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, LocationMutation](ctx, lu.sqlSave, lu.mutation, lu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -270,6 +237,9 @@ func (lu *LocationUpdate) check() error { } func (lu *LocationUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := lu.check(); err != nil { + return n, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: location.Table, @@ -485,6 +455,7 @@ func (lu *LocationUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + lu.mutation.done = true return n, nil } @@ -656,47 +627,8 @@ func (luo *LocationUpdateOne) Select(field string, fields ...string) *LocationUp // Save executes the query and returns the updated Location entity. func (luo *LocationUpdateOne) Save(ctx context.Context) (*Location, error) { - var ( - err error - node *Location - ) luo.defaults() - if len(luo.hooks) == 0 { - if err = luo.check(); err != nil { - return nil, err - } - node, err = luo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*LocationMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = luo.check(); err != nil { - return nil, err - } - luo.mutation = mutation - node, err = luo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(luo.hooks) - 1; i >= 0; i-- { - if luo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = luo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, luo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Location) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from LocationMutation", v) - } - node = nv - } - return node, err + return withHooks[*Location, LocationMutation](ctx, luo.sqlSave, luo.mutation, luo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -748,6 +680,9 @@ func (luo *LocationUpdateOne) check() error { } func (luo *LocationUpdateOne) sqlSave(ctx context.Context) (_node *Location, err error) { + if err := luo.check(); err != nil { + return _node, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: location.Table, @@ -983,5 +918,6 @@ func (luo *LocationUpdateOne) sqlSave(ctx context.Context) (_node *Location, err } return nil, err } + luo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/maintenanceentry/where.go b/backend/internal/data/ent/maintenanceentry/where.go index 02d9633..6a88550 100644 --- a/backend/internal/data/ent/maintenanceentry/where.go +++ b/backend/internal/data/ent/maintenanceentry/where.go @@ -13,626 +13,402 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.MaintenanceEntry(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.MaintenanceEntry(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.MaintenanceEntry(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.MaintenanceEntry(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.MaintenanceEntry(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldUpdatedAt, v)) } // ItemID applies equality check predicate on the "item_id" field. It's identical to ItemIDEQ. func ItemID(v uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldItemID), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldItemID, v)) } // Date applies equality check predicate on the "date" field. It's identical to DateEQ. func Date(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDate), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldDate, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldName, v)) } // Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. func Description(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldDescription, v)) } // Cost applies equality check predicate on the "cost" field. It's identical to CostEQ. func Cost(v float64) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCost), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldCost, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLTE(FieldUpdatedAt, v)) } // ItemIDEQ applies the EQ predicate on the "item_id" field. func ItemIDEQ(v uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldItemID), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldItemID, v)) } // ItemIDNEQ applies the NEQ predicate on the "item_id" field. func ItemIDNEQ(v uuid.UUID) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldItemID), v)) - }) + return predicate.MaintenanceEntry(sql.FieldNEQ(FieldItemID, v)) } // ItemIDIn applies the In predicate on the "item_id" field. func ItemIDIn(vs ...uuid.UUID) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldItemID), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldIn(FieldItemID, vs...)) } // ItemIDNotIn applies the NotIn predicate on the "item_id" field. func ItemIDNotIn(vs ...uuid.UUID) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldItemID), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldNotIn(FieldItemID, vs...)) } // DateEQ applies the EQ predicate on the "date" field. func DateEQ(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDate), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldDate, v)) } // DateNEQ applies the NEQ predicate on the "date" field. func DateNEQ(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldDate), v)) - }) + return predicate.MaintenanceEntry(sql.FieldNEQ(FieldDate, v)) } // DateIn applies the In predicate on the "date" field. func DateIn(vs ...time.Time) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldDate), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldIn(FieldDate, vs...)) } // DateNotIn applies the NotIn predicate on the "date" field. func DateNotIn(vs ...time.Time) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldDate), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldNotIn(FieldDate, vs...)) } // DateGT applies the GT predicate on the "date" field. func DateGT(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldDate), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGT(FieldDate, v)) } // DateGTE applies the GTE predicate on the "date" field. func DateGTE(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldDate), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGTE(FieldDate, v)) } // DateLT applies the LT predicate on the "date" field. func DateLT(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldDate), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLT(FieldDate, v)) } // DateLTE applies the LTE predicate on the "date" field. func DateLTE(v time.Time) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldDate), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLTE(FieldDate, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.MaintenanceEntry(sql.FieldContainsFold(FieldName, v)) } // DescriptionEQ applies the EQ predicate on the "description" field. func DescriptionEQ(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldDescription, v)) } // DescriptionNEQ applies the NEQ predicate on the "description" field. func DescriptionNEQ(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldNEQ(FieldDescription, v)) } // DescriptionIn applies the In predicate on the "description" field. func DescriptionIn(vs ...string) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldDescription), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldIn(FieldDescription, vs...)) } // DescriptionNotIn applies the NotIn predicate on the "description" field. func DescriptionNotIn(vs ...string) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldDescription), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldNotIn(FieldDescription, vs...)) } // DescriptionGT applies the GT predicate on the "description" field. func DescriptionGT(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGT(FieldDescription, v)) } // DescriptionGTE applies the GTE predicate on the "description" field. func DescriptionGTE(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGTE(FieldDescription, v)) } // DescriptionLT applies the LT predicate on the "description" field. func DescriptionLT(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLT(FieldDescription, v)) } // DescriptionLTE applies the LTE predicate on the "description" field. func DescriptionLTE(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLTE(FieldDescription, v)) } // DescriptionContains applies the Contains predicate on the "description" field. func DescriptionContains(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldContains(FieldDescription, v)) } // DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. func DescriptionHasPrefix(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldHasPrefix(FieldDescription, v)) } // DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. func DescriptionHasSuffix(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldHasSuffix(FieldDescription, v)) } // DescriptionIsNil applies the IsNil predicate on the "description" field. func DescriptionIsNil() predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldDescription))) - }) + return predicate.MaintenanceEntry(sql.FieldIsNull(FieldDescription)) } // DescriptionNotNil applies the NotNil predicate on the "description" field. func DescriptionNotNil() predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldDescription))) - }) + return predicate.MaintenanceEntry(sql.FieldNotNull(FieldDescription)) } // DescriptionEqualFold applies the EqualFold predicate on the "description" field. func DescriptionEqualFold(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEqualFold(FieldDescription, v)) } // DescriptionContainsFold applies the ContainsFold predicate on the "description" field. func DescriptionContainsFold(v string) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldDescription), v)) - }) + return predicate.MaintenanceEntry(sql.FieldContainsFold(FieldDescription, v)) } // CostEQ applies the EQ predicate on the "cost" field. func CostEQ(v float64) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCost), v)) - }) + return predicate.MaintenanceEntry(sql.FieldEQ(FieldCost, v)) } // CostNEQ applies the NEQ predicate on the "cost" field. func CostNEQ(v float64) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCost), v)) - }) + return predicate.MaintenanceEntry(sql.FieldNEQ(FieldCost, v)) } // CostIn applies the In predicate on the "cost" field. func CostIn(vs ...float64) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCost), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldIn(FieldCost, vs...)) } // CostNotIn applies the NotIn predicate on the "cost" field. func CostNotIn(vs ...float64) predicate.MaintenanceEntry { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCost), v...)) - }) + return predicate.MaintenanceEntry(sql.FieldNotIn(FieldCost, vs...)) } // CostGT applies the GT predicate on the "cost" field. func CostGT(v float64) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCost), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGT(FieldCost, v)) } // CostGTE applies the GTE predicate on the "cost" field. func CostGTE(v float64) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCost), v)) - }) + return predicate.MaintenanceEntry(sql.FieldGTE(FieldCost, v)) } // CostLT applies the LT predicate on the "cost" field. func CostLT(v float64) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCost), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLT(FieldCost, v)) } // CostLTE applies the LTE predicate on the "cost" field. func CostLTE(v float64) predicate.MaintenanceEntry { - return predicate.MaintenanceEntry(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCost), v)) - }) + return predicate.MaintenanceEntry(sql.FieldLTE(FieldCost, v)) } // HasItem applies the HasEdge predicate on the "item" edge. @@ -640,7 +416,6 @@ func HasItem() predicate.MaintenanceEntry { return predicate.MaintenanceEntry(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ItemTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, ItemTable, ItemColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/maintenanceentry_create.go b/backend/internal/data/ent/maintenanceentry_create.go index 3abaa84..a7a6a94 100644 --- a/backend/internal/data/ent/maintenanceentry_create.go +++ b/backend/internal/data/ent/maintenanceentry_create.go @@ -130,50 +130,8 @@ func (mec *MaintenanceEntryCreate) Mutation() *MaintenanceEntryMutation { // Save creates the MaintenanceEntry in the database. func (mec *MaintenanceEntryCreate) Save(ctx context.Context) (*MaintenanceEntry, error) { - var ( - err error - node *MaintenanceEntry - ) mec.defaults() - if len(mec.hooks) == 0 { - if err = mec.check(); err != nil { - return nil, err - } - node, err = mec.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*MaintenanceEntryMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = mec.check(); err != nil { - return nil, err - } - mec.mutation = mutation - if node, err = mec.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(mec.hooks) - 1; i >= 0; i-- { - if mec.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = mec.hooks[i](mut) - } - v, err := mut.Mutate(ctx, mec.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*MaintenanceEntry) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from MaintenanceEntryMutation", v) - } - node = nv - } - return node, err + return withHooks[*MaintenanceEntry, MaintenanceEntryMutation](ctx, mec.sqlSave, mec.mutation, mec.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -259,6 +217,9 @@ func (mec *MaintenanceEntryCreate) check() error { } func (mec *MaintenanceEntryCreate) sqlSave(ctx context.Context) (*MaintenanceEntry, error) { + if err := mec.check(); err != nil { + return nil, err + } _node, _spec := mec.createSpec() if err := sqlgraph.CreateNode(ctx, mec.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -273,6 +234,8 @@ func (mec *MaintenanceEntryCreate) sqlSave(ctx context.Context) (*MaintenanceEnt return nil, err } } + mec.mutation.id = &_node.ID + mec.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/maintenanceentry_delete.go b/backend/internal/data/ent/maintenanceentry_delete.go index ea0ed2a..7ee2c67 100644 --- a/backend/internal/data/ent/maintenanceentry_delete.go +++ b/backend/internal/data/ent/maintenanceentry_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (med *MaintenanceEntryDelete) Where(ps ...predicate.MaintenanceEntry) *Main // Exec executes the deletion query and returns how many vertices were deleted. func (med *MaintenanceEntryDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(med.hooks) == 0 { - affected, err = med.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*MaintenanceEntryMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - med.mutation = mutation - affected, err = med.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(med.hooks) - 1; i >= 0; i-- { - if med.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = med.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, med.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, MaintenanceEntryMutation](ctx, med.sqlExec, med.mutation, med.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (med *MaintenanceEntryDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + med.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/maintenanceentry_query.go b/backend/internal/data/ent/maintenanceentry_query.go index bcc95b5..b394869 100644 --- a/backend/internal/data/ent/maintenanceentry_query.go +++ b/backend/internal/data/ent/maintenanceentry_query.go @@ -24,6 +24,7 @@ type MaintenanceEntryQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.MaintenanceEntry withItem *ItemQuery // intermediate query (i.e. traversal path). @@ -37,13 +38,13 @@ func (meq *MaintenanceEntryQuery) Where(ps ...predicate.MaintenanceEntry) *Maint return meq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (meq *MaintenanceEntryQuery) Limit(limit int) *MaintenanceEntryQuery { meq.limit = &limit return meq } -// Offset adds an offset step to the query. +// Offset to start from. func (meq *MaintenanceEntryQuery) Offset(offset int) *MaintenanceEntryQuery { meq.offset = &offset return meq @@ -56,7 +57,7 @@ func (meq *MaintenanceEntryQuery) Unique(unique bool) *MaintenanceEntryQuery { return meq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (meq *MaintenanceEntryQuery) Order(o ...OrderFunc) *MaintenanceEntryQuery { meq.order = append(meq.order, o...) return meq @@ -64,7 +65,7 @@ func (meq *MaintenanceEntryQuery) Order(o ...OrderFunc) *MaintenanceEntryQuery { // QueryItem chains the current query on the "item" edge. func (meq *MaintenanceEntryQuery) QueryItem() *ItemQuery { - query := &ItemQuery{config: meq.config} + query := (&ItemClient{config: meq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := meq.prepareQuery(ctx); err != nil { return nil, err @@ -87,7 +88,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(ctx) + nodes, err := meq.Limit(1).All(newQueryContext(ctx, TypeMaintenanceEntry, "First")) if err != nil { return nil, err } @@ -110,7 +111,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(ctx); err != nil { + if ids, err = meq.Limit(1).IDs(newQueryContext(ctx, TypeMaintenanceEntry, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -133,7 +134,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(ctx) + nodes, err := meq.Limit(2).All(newQueryContext(ctx, TypeMaintenanceEntry, "Only")) if err != nil { return nil, err } @@ -161,7 +162,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(ctx); err != nil { + if ids, err = meq.Limit(2).IDs(newQueryContext(ctx, TypeMaintenanceEntry, "OnlyID")); err != nil { return } switch len(ids) { @@ -186,10 +187,12 @@ 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") if err := meq.prepareQuery(ctx); err != nil { return nil, err } - return meq.sqlAll(ctx) + qr := querierAll[[]*MaintenanceEntry, *MaintenanceEntryQuery]() + return withInterceptors[[]*MaintenanceEntry](ctx, meq, qr, meq.inters) } // AllX is like All, but panics if an error occurs. @@ -204,6 +207,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") if err := meq.Select(maintenanceentry.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -221,10 +225,11 @@ 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") if err := meq.prepareQuery(ctx); err != nil { return 0, err } - return meq.sqlCount(ctx) + return withInterceptors[int](ctx, meq, querierCount[*MaintenanceEntryQuery](), meq.inters) } // CountX is like Count, but panics if an error occurs. @@ -238,10 +243,15 @@ 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) { - if err := meq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeMaintenanceEntry, "Exist") + switch _, err := meq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return meq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -264,6 +274,7 @@ func (meq *MaintenanceEntryQuery) Clone() *MaintenanceEntryQuery { limit: meq.limit, offset: meq.offset, order: append([]OrderFunc{}, meq.order...), + inters: append([]Interceptor{}, meq.inters...), predicates: append([]predicate.MaintenanceEntry{}, meq.predicates...), withItem: meq.withItem.Clone(), // clone intermediate query. @@ -276,7 +287,7 @@ func (meq *MaintenanceEntryQuery) Clone() *MaintenanceEntryQuery { // WithItem tells the query-builder to eager-load the nodes that are connected to // the "item" edge. The optional arguments are used to configure the query builder of the edge. func (meq *MaintenanceEntryQuery) WithItem(opts ...func(*ItemQuery)) *MaintenanceEntryQuery { - query := &ItemQuery{config: meq.config} + query := (&ItemClient{config: meq.config}).Query() for _, opt := range opts { opt(query) } @@ -299,16 +310,11 @@ func (meq *MaintenanceEntryQuery) WithItem(opts ...func(*ItemQuery)) *Maintenanc // Aggregate(ent.Count()). // Scan(ctx, &v) func (meq *MaintenanceEntryQuery) GroupBy(field string, fields ...string) *MaintenanceEntryGroupBy { - grbuild := &MaintenanceEntryGroupBy{config: meq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := meq.prepareQuery(ctx); err != nil { - return nil, err - } - return meq.sqlQuery(ctx), nil - } + meq.fields = append([]string{field}, fields...) + grbuild := &MaintenanceEntryGroupBy{build: meq} + grbuild.flds = &meq.fields grbuild.label = maintenanceentry.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -326,10 +332,10 @@ func (meq *MaintenanceEntryQuery) GroupBy(field string, fields ...string) *Maint // Scan(ctx, &v) func (meq *MaintenanceEntryQuery) Select(fields ...string) *MaintenanceEntrySelect { meq.fields = append(meq.fields, fields...) - selbuild := &MaintenanceEntrySelect{MaintenanceEntryQuery: meq} - selbuild.label = maintenanceentry.Label - selbuild.flds, selbuild.scan = &meq.fields, selbuild.Scan - return selbuild + sbuild := &MaintenanceEntrySelect{MaintenanceEntryQuery: meq} + sbuild.label = maintenanceentry.Label + sbuild.flds, sbuild.scan = &meq.fields, sbuild.Scan + return sbuild } // Aggregate returns a MaintenanceEntrySelect configured with the given aggregations. @@ -338,6 +344,16 @@ func (meq *MaintenanceEntryQuery) Aggregate(fns ...AggregateFunc) *MaintenanceEn } func (meq *MaintenanceEntryQuery) prepareQuery(ctx context.Context) error { + for _, inter := range meq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, meq); err != nil { + return err + } + } + } for _, f := range meq.fields { if !maintenanceentry.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -424,17 +440,6 @@ func (meq *MaintenanceEntryQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, meq.driver, _spec) } -func (meq *MaintenanceEntryQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := meq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (meq *MaintenanceEntryQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -517,13 +522,8 @@ func (meq *MaintenanceEntryQuery) sqlQuery(ctx context.Context) *sql.Selector { // MaintenanceEntryGroupBy is the group-by builder for MaintenanceEntry entities. type MaintenanceEntryGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *MaintenanceEntryQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -532,58 +532,46 @@ func (megb *MaintenanceEntryGroupBy) Aggregate(fns ...AggregateFunc) *Maintenanc return megb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (megb *MaintenanceEntryGroupBy) Scan(ctx context.Context, v any) error { - query, err := megb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeMaintenanceEntry, "GroupBy") + if err := megb.build.prepareQuery(ctx); err != nil { return err } - megb.sql = query - return megb.sqlScan(ctx, v) + return scanWithInterceptors[*MaintenanceEntryQuery, *MaintenanceEntryGroupBy](ctx, megb.build, megb, megb.build.inters, v) } -func (megb *MaintenanceEntryGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range megb.fields { - if !maintenanceentry.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (megb *MaintenanceEntryGroupBy) sqlScan(ctx context.Context, root *MaintenanceEntryQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(megb.fns)) + for _, fn := range megb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := megb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*megb.flds)+len(megb.fns)) + for _, f := range *megb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*megb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := megb.driver.Query(ctx, query, args, rows); err != nil { + if err := megb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (megb *MaintenanceEntryGroupBy) sqlQuery() *sql.Selector { - selector := megb.sql.Select() - aggregation := make([]string, 0, len(megb.fns)) - for _, fn := range megb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(megb.fields)+len(megb.fns)) - for _, f := range megb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(megb.fields...)...) -} - // MaintenanceEntrySelect is the builder for selecting fields of MaintenanceEntry entities. type MaintenanceEntrySelect struct { *MaintenanceEntryQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -594,26 +582,27 @@ 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") if err := mes.prepareQuery(ctx); err != nil { return err } - mes.sql = mes.MaintenanceEntryQuery.sqlQuery(ctx) - return mes.sqlScan(ctx, v) + return scanWithInterceptors[*MaintenanceEntryQuery, *MaintenanceEntrySelect](ctx, mes.MaintenanceEntryQuery, mes, mes.inters, v) } -func (mes *MaintenanceEntrySelect) sqlScan(ctx context.Context, v any) error { +func (mes *MaintenanceEntrySelect) sqlScan(ctx context.Context, root *MaintenanceEntryQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(mes.fns)) for _, fn := range mes.fns { - aggregation = append(aggregation, fn(mes.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*mes.selector.flds); { case n == 0 && len(aggregation) > 0: - mes.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - mes.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := mes.sql.Query() + query, args := selector.Query() if err := mes.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/maintenanceentry_update.go b/backend/internal/data/ent/maintenanceentry_update.go index af0aafd..d4c3ee3 100644 --- a/backend/internal/data/ent/maintenanceentry_update.go +++ b/backend/internal/data/ent/maintenanceentry_update.go @@ -121,41 +121,8 @@ func (meu *MaintenanceEntryUpdate) ClearItem() *MaintenanceEntryUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (meu *MaintenanceEntryUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) meu.defaults() - if len(meu.hooks) == 0 { - if err = meu.check(); err != nil { - return 0, err - } - affected, err = meu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*MaintenanceEntryMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = meu.check(); err != nil { - return 0, err - } - meu.mutation = mutation - affected, err = meu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(meu.hooks) - 1; i >= 0; i-- { - if meu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = meu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, meu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, MaintenanceEntryMutation](ctx, meu.sqlSave, meu.mutation, meu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -207,6 +174,9 @@ func (meu *MaintenanceEntryUpdate) check() error { } func (meu *MaintenanceEntryUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := meu.check(); err != nil { + return n, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: maintenanceentry.Table, @@ -288,6 +258,7 @@ func (meu *MaintenanceEntryUpdate) sqlSave(ctx context.Context) (n int, err erro } return 0, err } + meu.mutation.done = true return n, nil } @@ -397,47 +368,8 @@ func (meuo *MaintenanceEntryUpdateOne) Select(field string, fields ...string) *M // Save executes the query and returns the updated MaintenanceEntry entity. func (meuo *MaintenanceEntryUpdateOne) Save(ctx context.Context) (*MaintenanceEntry, error) { - var ( - err error - node *MaintenanceEntry - ) meuo.defaults() - if len(meuo.hooks) == 0 { - if err = meuo.check(); err != nil { - return nil, err - } - node, err = meuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*MaintenanceEntryMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = meuo.check(); err != nil { - return nil, err - } - meuo.mutation = mutation - node, err = meuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(meuo.hooks) - 1; i >= 0; i-- { - if meuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = meuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, meuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*MaintenanceEntry) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from MaintenanceEntryMutation", v) - } - node = nv - } - return node, err + return withHooks[*MaintenanceEntry, MaintenanceEntryMutation](ctx, meuo.sqlSave, meuo.mutation, meuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -489,6 +421,9 @@ func (meuo *MaintenanceEntryUpdateOne) check() error { } func (meuo *MaintenanceEntryUpdateOne) sqlSave(ctx context.Context) (_node *MaintenanceEntry, err error) { + if err := meuo.check(); err != nil { + return _node, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: maintenanceentry.Table, @@ -590,5 +525,6 @@ func (meuo *MaintenanceEntryUpdateOne) sqlSave(ctx context.Context) (_node *Main } return nil, err } + meuo.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/mutation.go b/backend/internal/data/ent/mutation.go index da57310..164071e 100644 --- a/backend/internal/data/ent/mutation.go +++ b/backend/internal/data/ent/mutation.go @@ -25,6 +25,7 @@ import ( "github.com/hay-kot/homebox/backend/internal/data/ent/user" "entgo.io/ent" + "entgo.io/ent/dialect/sql" ) const ( @@ -364,11 +365,26 @@ func (m *AttachmentMutation) Where(ps ...predicate.Attachment) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the AttachmentMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AttachmentMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Attachment, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *AttachmentMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *AttachmentMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Attachment). func (m *AttachmentMutation) Type() string { return m.typ @@ -794,11 +810,26 @@ func (m *AuthRolesMutation) Where(ps ...predicate.AuthRoles) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the AuthRolesMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AuthRolesMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.AuthRoles, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *AuthRolesMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *AuthRolesMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (AuthRoles). func (m *AuthRolesMutation) Type() string { return m.typ @@ -1330,11 +1361,26 @@ func (m *AuthTokensMutation) Where(ps ...predicate.AuthTokens) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the AuthTokensMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AuthTokensMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.AuthTokens, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *AuthTokensMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *AuthTokensMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (AuthTokens). func (m *AuthTokensMutation) Type() string { return m.typ @@ -1951,11 +1997,26 @@ func (m *DocumentMutation) Where(ps ...predicate.Document) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the DocumentMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *DocumentMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Document, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *DocumentMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *DocumentMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Document). func (m *DocumentMutation) Type() string { return m.typ @@ -2826,11 +2887,26 @@ func (m *GroupMutation) Where(ps ...predicate.Group) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the GroupMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *GroupMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Group, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -3570,11 +3646,26 @@ func (m *GroupInvitationTokenMutation) Where(ps ...predicate.GroupInvitationToke m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the GroupInvitationTokenMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *GroupInvitationTokenMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.GroupInvitationToken, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *GroupInvitationTokenMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupInvitationTokenMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (GroupInvitationToken). func (m *GroupInvitationTokenMutation) Type() string { return m.typ @@ -5471,11 +5562,26 @@ func (m *ItemMutation) Where(ps ...predicate.Item) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the ItemMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ItemMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Item, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *ItemMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *ItemMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Item). func (m *ItemMutation) Type() string { return m.typ @@ -6886,11 +6992,26 @@ func (m *ItemFieldMutation) Where(ps ...predicate.ItemField) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the ItemFieldMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ItemFieldMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ItemField, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *ItemFieldMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *ItemFieldMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (ItemField). func (m *ItemFieldMutation) Type() string { return m.typ @@ -7673,11 +7794,26 @@ func (m *LabelMutation) Where(ps ...predicate.Label) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the LabelMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *LabelMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Label, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *LabelMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *LabelMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Label). func (m *LabelMutation) Type() string { return m.typ @@ -8447,11 +8583,26 @@ func (m *LocationMutation) Where(ps ...predicate.Location) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the LocationMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *LocationMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Location, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *LocationMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *LocationMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Location). func (m *LocationMutation) Type() string { return m.typ @@ -9205,11 +9356,26 @@ func (m *MaintenanceEntryMutation) Where(ps ...predicate.MaintenanceEntry) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the MaintenanceEntryMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *MaintenanceEntryMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.MaintenanceEntry, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *MaintenanceEntryMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *MaintenanceEntryMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (MaintenanceEntry). func (m *MaintenanceEntryMutation) Type() string { return m.typ @@ -10081,11 +10247,26 @@ func (m *UserMutation) Where(ps ...predicate.User) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the UserMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.User, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/backend/internal/data/ent/runtime/runtime.go b/backend/internal/data/ent/runtime/runtime.go index 2ade0c7..82fdada 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.4" // Version of ent codegen. - Sum = "h1:grwVY0fp31BZ6oEo3YrXenAuv8VJmEw7F/Bi6WqeH3Q=" // Sum of ent codegen. + Version = "v0.11.5" // Version of ent codegen. + Sum = "h1:V2qhG91C4PMQTa82Q4StoESMQ4dzkMNeStCzszxi0jQ=" // Sum of ent codegen. ) diff --git a/backend/internal/data/ent/user/where.go b/backend/internal/data/ent/user/where.go index 567187e..78335a7 100644 --- a/backend/internal/data/ent/user/where.go +++ b/backend/internal/data/ent/user/where.go @@ -13,696 +13,452 @@ import ( // ID filters vertices based on their ID field. func ID(id uuid.UUID) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id uuid.UUID) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id uuid.UUID) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...uuid.UUID) predicate.User { - return predicate.User(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.User(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...uuid.UUID) predicate.User { - return predicate.User(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id uuid.UUID) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id uuid.UUID) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id uuid.UUID) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id uuid.UUID) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldLTE(FieldID, id)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.User(sql.FieldEQ(FieldCreatedAt, v)) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. func UpdatedAt(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.User(sql.FieldEQ(FieldUpdatedAt, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldEQ(FieldName, v)) } // Email applies equality check predicate on the "email" field. It's identical to EmailEQ. func Email(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldEQ(FieldEmail, v)) } // Password applies equality check predicate on the "password" field. It's identical to PasswordEQ. func Password(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldEQ(FieldPassword, v)) } // IsSuperuser applies equality check predicate on the "is_superuser" field. It's identical to IsSuperuserEQ. func IsSuperuser(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldIsSuperuser), v)) - }) + return predicate.User(sql.FieldEQ(FieldIsSuperuser, v)) } // Superuser applies equality check predicate on the "superuser" field. It's identical to SuperuserEQ. func Superuser(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSuperuser), v)) - }) + return predicate.User(sql.FieldEQ(FieldSuperuser, v)) } // ActivatedOn applies equality check predicate on the "activated_on" field. It's identical to ActivatedOnEQ. func ActivatedOn(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldActivatedOn), v)) - }) + return predicate.User(sql.FieldEQ(FieldActivatedOn, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.User(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.User(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.User(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.User(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.User(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.User(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.User(sql.FieldLTE(FieldCreatedAt, v)) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. func UpdatedAtEQ(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.User(sql.FieldEQ(FieldUpdatedAt, v)) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. func UpdatedAtNEQ(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) + return predicate.User(sql.FieldNEQ(FieldUpdatedAt, v)) } // UpdatedAtIn applies the In predicate on the "updated_at" field. func UpdatedAtIn(vs ...time.Time) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) + return predicate.User(sql.FieldIn(FieldUpdatedAt, vs...)) } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. func UpdatedAtNotIn(vs ...time.Time) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldUpdatedAt, vs...)) } // UpdatedAtGT applies the GT predicate on the "updated_at" field. func UpdatedAtGT(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) + return predicate.User(sql.FieldGT(FieldUpdatedAt, v)) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. func UpdatedAtGTE(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.User(sql.FieldGTE(FieldUpdatedAt, v)) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. func UpdatedAtLT(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) + return predicate.User(sql.FieldLT(FieldUpdatedAt, v)) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. func UpdatedAtLTE(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) + return predicate.User(sql.FieldLTE(FieldUpdatedAt, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.User(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldContainsFold(FieldName, v)) } // EmailEQ applies the EQ predicate on the "email" field. func EmailEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldEQ(FieldEmail, v)) } // EmailNEQ applies the NEQ predicate on the "email" field. func EmailNEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldNEQ(FieldEmail, v)) } // EmailIn applies the In predicate on the "email" field. func EmailIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldEmail), v...)) - }) + return predicate.User(sql.FieldIn(FieldEmail, vs...)) } // EmailNotIn applies the NotIn predicate on the "email" field. func EmailNotIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldEmail), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldEmail, vs...)) } // EmailGT applies the GT predicate on the "email" field. func EmailGT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldGT(FieldEmail, v)) } // EmailGTE applies the GTE predicate on the "email" field. func EmailGTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldGTE(FieldEmail, v)) } // EmailLT applies the LT predicate on the "email" field. func EmailLT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldLT(FieldEmail, v)) } // EmailLTE applies the LTE predicate on the "email" field. func EmailLTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldLTE(FieldEmail, v)) } // EmailContains applies the Contains predicate on the "email" field. func EmailContains(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldContains(FieldEmail, v)) } // EmailHasPrefix applies the HasPrefix predicate on the "email" field. func EmailHasPrefix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldHasPrefix(FieldEmail, v)) } // EmailHasSuffix applies the HasSuffix predicate on the "email" field. func EmailHasSuffix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldHasSuffix(FieldEmail, v)) } // EmailEqualFold applies the EqualFold predicate on the "email" field. func EmailEqualFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldEqualFold(FieldEmail, v)) } // EmailContainsFold applies the ContainsFold predicate on the "email" field. func EmailContainsFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldEmail), v)) - }) + return predicate.User(sql.FieldContainsFold(FieldEmail, v)) } // PasswordEQ applies the EQ predicate on the "password" field. func PasswordEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldEQ(FieldPassword, v)) } // PasswordNEQ applies the NEQ predicate on the "password" field. func PasswordNEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldNEQ(FieldPassword, v)) } // PasswordIn applies the In predicate on the "password" field. func PasswordIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldPassword), v...)) - }) + return predicate.User(sql.FieldIn(FieldPassword, vs...)) } // PasswordNotIn applies the NotIn predicate on the "password" field. func PasswordNotIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldPassword), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldPassword, vs...)) } // PasswordGT applies the GT predicate on the "password" field. func PasswordGT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldGT(FieldPassword, v)) } // PasswordGTE applies the GTE predicate on the "password" field. func PasswordGTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldGTE(FieldPassword, v)) } // PasswordLT applies the LT predicate on the "password" field. func PasswordLT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldLT(FieldPassword, v)) } // PasswordLTE applies the LTE predicate on the "password" field. func PasswordLTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldLTE(FieldPassword, v)) } // PasswordContains applies the Contains predicate on the "password" field. func PasswordContains(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldContains(FieldPassword, v)) } // PasswordHasPrefix applies the HasPrefix predicate on the "password" field. func PasswordHasPrefix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldHasPrefix(FieldPassword, v)) } // PasswordHasSuffix applies the HasSuffix predicate on the "password" field. func PasswordHasSuffix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldHasSuffix(FieldPassword, v)) } // PasswordEqualFold applies the EqualFold predicate on the "password" field. func PasswordEqualFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldEqualFold(FieldPassword, v)) } // PasswordContainsFold applies the ContainsFold predicate on the "password" field. func PasswordContainsFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldPassword), v)) - }) + return predicate.User(sql.FieldContainsFold(FieldPassword, v)) } // IsSuperuserEQ applies the EQ predicate on the "is_superuser" field. func IsSuperuserEQ(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldIsSuperuser), v)) - }) + return predicate.User(sql.FieldEQ(FieldIsSuperuser, v)) } // IsSuperuserNEQ applies the NEQ predicate on the "is_superuser" field. func IsSuperuserNEQ(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldIsSuperuser), v)) - }) + return predicate.User(sql.FieldNEQ(FieldIsSuperuser, v)) } // RoleEQ applies the EQ predicate on the "role" field. func RoleEQ(v Role) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRole), v)) - }) + return predicate.User(sql.FieldEQ(FieldRole, v)) } // RoleNEQ applies the NEQ predicate on the "role" field. func RoleNEQ(v Role) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldRole), v)) - }) + return predicate.User(sql.FieldNEQ(FieldRole, v)) } // RoleIn applies the In predicate on the "role" field. func RoleIn(vs ...Role) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldRole), v...)) - }) + return predicate.User(sql.FieldIn(FieldRole, vs...)) } // RoleNotIn applies the NotIn predicate on the "role" field. func RoleNotIn(vs ...Role) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldRole), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldRole, vs...)) } // SuperuserEQ applies the EQ predicate on the "superuser" field. func SuperuserEQ(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSuperuser), v)) - }) + return predicate.User(sql.FieldEQ(FieldSuperuser, v)) } // SuperuserNEQ applies the NEQ predicate on the "superuser" field. func SuperuserNEQ(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSuperuser), v)) - }) + return predicate.User(sql.FieldNEQ(FieldSuperuser, v)) } // ActivatedOnEQ applies the EQ predicate on the "activated_on" field. func ActivatedOnEQ(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldActivatedOn), v)) - }) + return predicate.User(sql.FieldEQ(FieldActivatedOn, v)) } // ActivatedOnNEQ applies the NEQ predicate on the "activated_on" field. func ActivatedOnNEQ(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldActivatedOn), v)) - }) + return predicate.User(sql.FieldNEQ(FieldActivatedOn, v)) } // ActivatedOnIn applies the In predicate on the "activated_on" field. func ActivatedOnIn(vs ...time.Time) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldActivatedOn), v...)) - }) + return predicate.User(sql.FieldIn(FieldActivatedOn, vs...)) } // ActivatedOnNotIn applies the NotIn predicate on the "activated_on" field. func ActivatedOnNotIn(vs ...time.Time) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldActivatedOn), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldActivatedOn, vs...)) } // ActivatedOnGT applies the GT predicate on the "activated_on" field. func ActivatedOnGT(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldActivatedOn), v)) - }) + return predicate.User(sql.FieldGT(FieldActivatedOn, v)) } // ActivatedOnGTE applies the GTE predicate on the "activated_on" field. func ActivatedOnGTE(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldActivatedOn), v)) - }) + return predicate.User(sql.FieldGTE(FieldActivatedOn, v)) } // ActivatedOnLT applies the LT predicate on the "activated_on" field. func ActivatedOnLT(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldActivatedOn), v)) - }) + return predicate.User(sql.FieldLT(FieldActivatedOn, v)) } // ActivatedOnLTE applies the LTE predicate on the "activated_on" field. func ActivatedOnLTE(v time.Time) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldActivatedOn), v)) - }) + return predicate.User(sql.FieldLTE(FieldActivatedOn, v)) } // ActivatedOnIsNil applies the IsNil predicate on the "activated_on" field. func ActivatedOnIsNil() predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldActivatedOn))) - }) + return predicate.User(sql.FieldIsNull(FieldActivatedOn)) } // ActivatedOnNotNil applies the NotNil predicate on the "activated_on" field. func ActivatedOnNotNil() predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldActivatedOn))) - }) + return predicate.User(sql.FieldNotNull(FieldActivatedOn)) } // HasGroup applies the HasEdge predicate on the "group" edge. @@ -710,7 +466,6 @@ func HasGroup() predicate.User { return predicate.User(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), ) sqlgraph.HasNeighbors(s, step) @@ -738,7 +493,6 @@ func HasAuthTokens() predicate.User { return predicate.User(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(AuthTokensTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, AuthTokensTable, AuthTokensColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/backend/internal/data/ent/user_create.go b/backend/internal/data/ent/user_create.go index 028339a..367ff07 100644 --- a/backend/internal/data/ent/user_create.go +++ b/backend/internal/data/ent/user_create.go @@ -172,50 +172,8 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - var ( - err error - node *User - ) uc.defaults() - if len(uc.hooks) == 0 { - if err = uc.check(); err != nil { - return nil, err - } - node, err = uc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = uc.check(); err != nil { - return nil, err - } - uc.mutation = mutation - if node, err = uc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(uc.hooks) - 1; i >= 0; i-- { - if uc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = uc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, uc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*User) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from UserMutation", v) - } - node = nv - } - return node, err + return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -321,6 +279,9 @@ func (uc *UserCreate) check() error { } func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { + if err := uc.check(); err != nil { + return nil, err + } _node, _spec := uc.createSpec() if err := sqlgraph.CreateNode(ctx, uc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -335,6 +296,8 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { return nil, err } } + uc.mutation.id = &_node.ID + uc.mutation.done = true return _node, nil } diff --git a/backend/internal/data/ent/user_delete.go b/backend/internal/data/ent/user_delete.go index 9013f6f..e54e3de 100644 --- a/backend/internal/data/ent/user_delete.go +++ b/backend/internal/data/ent/user_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ud.hooks) == 0 { - affected, err = ud.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ud.mutation = mutation - affected, err = ud.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ud.hooks) - 1; i >= 0; i-- { - if ud.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ud.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ud.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -88,6 +60,7 @@ func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + ud.mutation.done = true return affected, err } diff --git a/backend/internal/data/ent/user_query.go b/backend/internal/data/ent/user_query.go index cb480e2..75b8ad4 100644 --- a/backend/internal/data/ent/user_query.go +++ b/backend/internal/data/ent/user_query.go @@ -26,6 +26,7 @@ type UserQuery struct { unique *bool order []OrderFunc fields []string + inters []Interceptor predicates []predicate.User withGroup *GroupQuery withAuthTokens *AuthTokensQuery @@ -41,13 +42,13 @@ func (uq *UserQuery) Where(ps ...predicate.User) *UserQuery { return uq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (uq *UserQuery) Limit(limit int) *UserQuery { uq.limit = &limit return uq } -// Offset adds an offset step to the query. +// Offset to start from. func (uq *UserQuery) Offset(offset int) *UserQuery { uq.offset = &offset return uq @@ -60,7 +61,7 @@ func (uq *UserQuery) Unique(unique bool) *UserQuery { return uq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery { uq.order = append(uq.order, o...) return uq @@ -68,7 +69,7 @@ func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery { // QueryGroup chains the current query on the "group" edge. func (uq *UserQuery) QueryGroup() *GroupQuery { - query := &GroupQuery{config: uq.config} + query := (&GroupClient{config: uq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := uq.prepareQuery(ctx); err != nil { return nil, err @@ -90,7 +91,7 @@ func (uq *UserQuery) QueryGroup() *GroupQuery { // QueryAuthTokens chains the current query on the "auth_tokens" edge. func (uq *UserQuery) QueryAuthTokens() *AuthTokensQuery { - query := &AuthTokensQuery{config: uq.config} + query := (&AuthTokensClient{config: uq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := uq.prepareQuery(ctx); err != nil { return nil, err @@ -113,7 +114,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(ctx) + nodes, err := uq.Limit(1).All(newQueryContext(ctx, TypeUser, "First")) if err != nil { return nil, err } @@ -136,7 +137,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(ctx); err != nil { + if ids, err = uq.Limit(1).IDs(newQueryContext(ctx, TypeUser, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -159,7 +160,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(ctx) + nodes, err := uq.Limit(2).All(newQueryContext(ctx, TypeUser, "Only")) if err != nil { return nil, err } @@ -187,7 +188,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(ctx); err != nil { + if ids, err = uq.Limit(2).IDs(newQueryContext(ctx, TypeUser, "OnlyID")); err != nil { return } switch len(ids) { @@ -212,10 +213,12 @@ 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") if err := uq.prepareQuery(ctx); err != nil { return nil, err } - return uq.sqlAll(ctx) + qr := querierAll[[]*User, *UserQuery]() + return withInterceptors[[]*User](ctx, uq, qr, uq.inters) } // AllX is like All, but panics if an error occurs. @@ -230,6 +233,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") if err := uq.Select(user.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -247,10 +251,11 @@ 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") if err := uq.prepareQuery(ctx); err != nil { return 0, err } - return uq.sqlCount(ctx) + return withInterceptors[int](ctx, uq, querierCount[*UserQuery](), uq.inters) } // CountX is like Count, but panics if an error occurs. @@ -264,10 +269,15 @@ 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) { - if err := uq.prepareQuery(ctx); err != nil { - return false, err + ctx = newQueryContext(ctx, TypeUser, "Exist") + switch _, err := uq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return uq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -290,6 +300,7 @@ func (uq *UserQuery) Clone() *UserQuery { limit: uq.limit, offset: uq.offset, order: append([]OrderFunc{}, uq.order...), + inters: append([]Interceptor{}, uq.inters...), predicates: append([]predicate.User{}, uq.predicates...), withGroup: uq.withGroup.Clone(), withAuthTokens: uq.withAuthTokens.Clone(), @@ -303,7 +314,7 @@ func (uq *UserQuery) Clone() *UserQuery { // WithGroup tells the query-builder to eager-load the nodes that are connected to // the "group" edge. The optional arguments are used to configure the query builder of the edge. func (uq *UserQuery) WithGroup(opts ...func(*GroupQuery)) *UserQuery { - query := &GroupQuery{config: uq.config} + query := (&GroupClient{config: uq.config}).Query() for _, opt := range opts { opt(query) } @@ -314,7 +325,7 @@ func (uq *UserQuery) WithGroup(opts ...func(*GroupQuery)) *UserQuery { // WithAuthTokens tells the query-builder to eager-load the nodes that are connected to // the "auth_tokens" edge. The optional arguments are used to configure the query builder of the edge. func (uq *UserQuery) WithAuthTokens(opts ...func(*AuthTokensQuery)) *UserQuery { - query := &AuthTokensQuery{config: uq.config} + query := (&AuthTokensClient{config: uq.config}).Query() for _, opt := range opts { opt(query) } @@ -337,16 +348,11 @@ func (uq *UserQuery) WithAuthTokens(opts ...func(*AuthTokensQuery)) *UserQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { - grbuild := &UserGroupBy{config: uq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := uq.prepareQuery(ctx); err != nil { - return nil, err - } - return uq.sqlQuery(ctx), nil - } + uq.fields = append([]string{field}, fields...) + grbuild := &UserGroupBy{build: uq} + grbuild.flds = &uq.fields grbuild.label = user.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -364,10 +370,10 @@ func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { // Scan(ctx, &v) func (uq *UserQuery) Select(fields ...string) *UserSelect { uq.fields = append(uq.fields, fields...) - selbuild := &UserSelect{UserQuery: uq} - selbuild.label = user.Label - selbuild.flds, selbuild.scan = &uq.fields, selbuild.Scan - return selbuild + sbuild := &UserSelect{UserQuery: uq} + sbuild.label = user.Label + sbuild.flds, sbuild.scan = &uq.fields, sbuild.Scan + return sbuild } // Aggregate returns a UserSelect configured with the given aggregations. @@ -376,6 +382,16 @@ func (uq *UserQuery) Aggregate(fns ...AggregateFunc) *UserSelect { } func (uq *UserQuery) prepareQuery(ctx context.Context) error { + for _, inter := range uq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, uq); err != nil { + return err + } + } + } for _, f := range uq.fields { if !user.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} @@ -511,17 +527,6 @@ func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, uq.driver, _spec) } -func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := uq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ @@ -604,13 +609,8 @@ func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { // UserGroupBy is the group-by builder for User entities. type UserGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *UserQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -619,58 +619,46 @@ func (ugb *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy { return ugb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (ugb *UserGroupBy) Scan(ctx context.Context, v any) error { - query, err := ugb.path(ctx) - if err != nil { + ctx = newQueryContext(ctx, TypeUser, "GroupBy") + if err := ugb.build.prepareQuery(ctx); err != nil { return err } - ugb.sql = query - return ugb.sqlScan(ctx, v) + return scanWithInterceptors[*UserQuery, *UserGroupBy](ctx, ugb.build, ugb, ugb.build.inters, v) } -func (ugb *UserGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range ugb.fields { - if !user.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } +func (ugb *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(ugb.fns)) + for _, fn := range ugb.fns { + aggregation = append(aggregation, fn(selector)) } - selector := ugb.sqlQuery() + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*ugb.flds)+len(ugb.fns)) + for _, f := range *ugb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*ugb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := ugb.driver.Query(ctx, query, args, rows); err != nil { + if err := ugb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (ugb *UserGroupBy) sqlQuery() *sql.Selector { - selector := ugb.sql.Select() - aggregation := make([]string, 0, len(ugb.fns)) - for _, fn := range ugb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(ugb.fields)+len(ugb.fns)) - for _, f := range ugb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(ugb.fields...)...) -} - // UserSelect is the builder for selecting fields of User entities. type UserSelect struct { *UserQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -681,26 +669,27 @@ 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") if err := us.prepareQuery(ctx); err != nil { return err } - us.sql = us.UserQuery.sqlQuery(ctx) - return us.sqlScan(ctx, v) + return scanWithInterceptors[*UserQuery, *UserSelect](ctx, us.UserQuery, us, us.inters, v) } -func (us *UserSelect) sqlScan(ctx context.Context, v any) error { +func (us *UserSelect) sqlScan(ctx context.Context, root *UserQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(us.fns)) for _, fn := range us.fns { - aggregation = append(aggregation, fn(us.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*us.selector.flds); { case n == 0 && len(aggregation) > 0: - us.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - us.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := us.sql.Query() + query, args := selector.Query() if err := us.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/backend/internal/data/ent/user_update.go b/backend/internal/data/ent/user_update.go index 96865b7..f453d37 100644 --- a/backend/internal/data/ent/user_update.go +++ b/backend/internal/data/ent/user_update.go @@ -177,41 +177,8 @@ func (uu *UserUpdate) RemoveAuthTokens(a ...*AuthTokens) *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) uu.defaults() - if len(uu.hooks) == 0 { - if err = uu.check(); err != nil { - return 0, err - } - affected, err = uu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = uu.check(); err != nil { - return 0, err - } - uu.mutation = mutation - affected, err = uu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(uu.hooks) - 1; i >= 0; i-- { - if uu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = uu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, uu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -273,6 +240,9 @@ func (uu *UserUpdate) check() error { } func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := uu.check(); err != nil { + return n, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: user.Table, @@ -414,6 +384,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + uu.mutation.done = true return n, nil } @@ -578,47 +549,8 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - var ( - err error - node *User - ) uuo.defaults() - if len(uuo.hooks) == 0 { - if err = uuo.check(); err != nil { - return nil, err - } - node, err = uuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = uuo.check(); err != nil { - return nil, err - } - uuo.mutation = mutation - node, err = uuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(uuo.hooks) - 1; i >= 0; i-- { - if uuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = uuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, uuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*User) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from UserMutation", v) - } - node = nv - } - return node, err + return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -680,6 +612,9 @@ func (uuo *UserUpdateOne) check() error { } func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) { + if err := uuo.check(); err != nil { + return _node, err + } _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: user.Table, @@ -841,5 +776,6 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) } return nil, err } + uuo.mutation.done = true return _node, nil } diff --git a/docs/docs/tips-tricks.md b/docs/docs/tips-tricks.md index 75501be..03b3626 100644 --- a/docs/docs/tips-tricks.md +++ b/docs/docs/tips-tricks.md @@ -32,3 +32,12 @@ In some cases you may want to skip some items such as consumables, or items that !!! tip If you're migrating from an older version there is a action on the users profile page to assign IDs to all items. This will assign the next available ID to all items in the order of creation. You should _only_ do this once during the migration process. You should be especially cautious of this action if you're using the reset feature described in option number 2 + +## QR Codes + +:octicons-tag-24: 0.7.0 + +Homebox has a built-in QR code generator that can be used to generate QR codes for your items. This is useful for tracking items with a mobile device. You can generate a QR code for any item by clicking the QR code icon in the top right of the item details page. The same can be done for the Labels and Locations page. Currently support is limited to generating one off QR Codes. + +However, the API endpoint is available for generating QR codes on the fly for any item (or any other data) if you provide a valid API key in the query parameters. An example url would look like `/api/v1/qrcode?data=https://homebox.fly.dev/item/{uuid}&access_token={api_key}`. Currently the easiest way to get an API token is to use one from an existing URL of the QR Code in the API key, but this will be improved in the future. + diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 6d0924e..1b7dda5 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -27,6 +27,9 @@ theme: favicon: assets/img/favicon.svg logo: assets/img/favicon.svg +plugins: + - tags + extra_css: - assets/stylesheets/extras.css diff --git a/docs/poetry.lock b/docs/poetry.lock index 3fa9fc7..abf75a8 100644 --- a/docs/poetry.lock +++ b/docs/poetry.lock @@ -415,13 +415,6 @@ files = [ {file = "PyYAML-6.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:f84fbc98b019fef2ee9a1cb3ce93e3187a6df0b2538a651bfb890254ba9f90b5"}, {file = "PyYAML-6.0-cp310-cp310-win32.whl", hash = "sha256:2cd5df3de48857ed0544b34e2d40e9fac445930039f3cfe4bcc592a1f836d513"}, {file = "PyYAML-6.0-cp310-cp310-win_amd64.whl", hash = "sha256:daf496c58a8c52083df09b80c860005194014c3698698d1a57cbcfa182142a3a"}, - {file = "PyYAML-6.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:d4b0ba9512519522b118090257be113b9468d804b19d63c71dbcf4a48fa32358"}, - {file = "PyYAML-6.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:81957921f441d50af23654aa6c5e5eaf9b06aba7f0a19c18a538dc7ef291c5a1"}, - {file = "PyYAML-6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:afa17f5bc4d1b10afd4466fd3a44dc0e245382deca5b3c353d8b757f9e3ecb8d"}, - {file = "PyYAML-6.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:dbad0e9d368bb989f4515da330b88a057617d16b6a8245084f1b05400f24609f"}, - {file = "PyYAML-6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:432557aa2c09802be39460360ddffd48156e30721f5e8d917f01d31694216782"}, - {file = "PyYAML-6.0-cp311-cp311-win32.whl", hash = "sha256:bfaef573a63ba8923503d27530362590ff4f576c626d86a9fed95822a8255fd7"}, - {file = "PyYAML-6.0-cp311-cp311-win_amd64.whl", hash = "sha256:01b45c0191e6d66c470b6cf1b9531a771a83c1c4208272ead47a3ae4f2f603bf"}, {file = "PyYAML-6.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:897b80890765f037df3403d22bab41627ca8811ae55e9a722fd0392850ec4d86"}, {file = "PyYAML-6.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:50602afada6d6cbfad699b0c7bb50d5ccffa7e46a3d738092afddc1f9758427f"}, {file = "PyYAML-6.0-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:48c346915c114f5fdb3ead70312bd042a953a8ce5c7106d5bfb1a5254e47da92"}, @@ -655,4 +648,4 @@ watchmedo = ["PyYAML (>=3.10)"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "5adaef802dc13c36e468c8a2a7d4e33e6a79df1e0156169364c26304df474983" +content-hash = "a0df662c99e9a84d2274616cea45eb315004b70884a296b6db240d790943f1b5" diff --git a/docs/pyproject.toml b/docs/pyproject.toml index df4e363..f46a1b8 100644 --- a/docs/pyproject.toml +++ b/docs/pyproject.toml @@ -7,7 +7,7 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.10" -mkdocs-material = "^9.0.0" +mkdocs-material = "^9.0.5" [build-system] diff --git a/frontend/components/App/Toast.vue b/frontend/components/App/Toast.vue index 34b77b9..06c3944 100644 --- a/frontend/components/App/Toast.vue +++ b/frontend/components/App/Toast.vue @@ -4,7 +4,7 @@
Quantity {{ item.quantity }}
+ Edit