Compare commits

..

40 Commits

Author SHA1 Message Date
Hayden
44f13f751a docs: update label generator docs 2023-02-13 10:50:49 -09:00
Hayden
986d2c586e refactor: editor page (#276) 2023-02-13 10:43:09 -09:00
Hayden
9361997a42 feat(reporting): bill of materials (#275)
* new reporting service

* API route

* code gen

* get tsv export from tools page

* fix naming
2023-02-13 10:00:29 -09:00
Hayden
2e96d8c4c2 fix favicon error 2023-02-12 15:14:11 -09:00
Hayden
ff75daf6b3 feat: mvp for label generation/printing (#274)
* initial label generator for QR codes

* use dynamic URL parameter
2023-02-12 15:09:31 -09:00
renovate[bot]
c0953bbd26 fix(deps): update module github.com/go-playground/validator/v10 to v10.11.2 (#253)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-02-10 19:41:39 -09:00
renovate[bot]
1f7e917c70 fix(deps): update module golang.org/x/crypto to v0.6.0 (#267)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-02-10 19:41:29 -09:00
Hayden
6ff2d64996 feat: init tools page (#271) 2023-02-10 19:38:50 -09:00
Hayden
ab22ea6a25 feat: rebuild search UI w/ new filters (#269) 2023-02-09 17:47:41 -09:00
Hayden
ce2fc7712a fix: add custom action for fixing broken date/times (#268) 2023-02-08 17:59:04 -09:00
Hayden
bd933af874 feat: implement selectable view + sortable table (#264) 2023-02-05 14:00:33 -09:00
Hayden
f36f17b57d feat: toggle view of password field (#263) 2023-02-05 12:56:47 -09:00
Hayden
504569bed0 fix: prevents re-creating locations and labels when someone joins group (#262)
* closes #258

* remove debug statement
2023-02-05 12:25:30 -09:00
Hayden
bd06fdafaf feat: enhanced search functions (#260)
* make login case insensitive

* expand query to support by Field and By AID search

* type generation

* new API callers

* rework search to support field queries

* improve unnecessary data fetches

* clear stores on logout

* change verbage

* add labels
2023-02-05 12:12:54 -09:00
Hayden
7b28973c60 fix: tree fixes (#252)
* use case insensitive sort

* support new location selector in create item

* fix incorrect date-time parsing logic
2023-01-29 13:20:18 -09:00
Hayden
cbac17c059 feat: use native date picker + align date formats (#251)
* use native date picker

* use YYYY-MM-DD for date formats
2023-01-28 13:32:39 -09:00
Hayden
6ed1f3695a chore: upgrade deps + code-gen (#249) 2023-01-28 12:03:51 -09:00
Hayden
3d295b5132 feat: locations tree viewer (#248)
* location tree API

* test fixes

* initial tree location elements

* locations tree page

* update meta-data

* code-gen

* store item display preferences

* introduce basic table/card view elements

* codegen

* set parent location during location creation

* add item support for tree query

* refactor tree view

* wip: location selector improvements

* type gen

* rename items -> search

* remove various log statements

* fix markdown rendering for description

* update location selectors

* fix tests

* fix currency tests

* formatting
2023-01-28 11:53:00 -09:00
renovate[bot]
4d220cdd9c chore(deps): update dependency vitest to ^0.28.0 (#244)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-26 10:05:09 -09:00
Serios
ad20e4e39b Adding new currency (#243)
Adding Bulgarian lev to list of currencies
2023-01-26 08:59:07 -09:00
renovate[bot]
3e2f6a96bf chore(deps): update dependency nuxt to v3.1.1 (#245)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-26 08:58:21 -09:00
renovate[bot]
2ece97c42a fix(deps): update module github.com/swaggo/swag to v1.8.10 (#246)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-26 08:57:54 -09:00
renovate[bot]
a8ee4d421b fix(deps): update module github.com/rs/zerolog to v1.29.0 (#247)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-26 08:57:45 -09:00
Hayden
91d0c588d9 refactor: refactor item page UI (#235)
* fix generated types

* fix tailwind auto-complete

* force lowercase buttons

* add title and change style for items page

* add copy button support for item details

* empty state for log

* fix duplicate padding

* add option for create without closing the current dialog.

* hide purchase price is not set

* invert toggle for edit mode

* update styles on item cards

* add edit support for maintenance logs
2023-01-21 21:15:23 -09:00
Hayden
c19fe94c08 feat: QR Codes (#226)
* code gen updates

* qrcode support

* remove opacity on toast

* update item view to use tab-like pages

* adjust view for cards

* fix old API calls for ioutils

* move embed

* extract QR code

* add docs for QR codes

* add QR code
2023-01-18 20:44:06 -09:00
renovate[bot]
f532b39c46 chore(deps): update docker/setup-qemu-action action to v2 (#219)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-15 13:56:03 -09:00
renovate[bot]
243742a75c chore(deps): update docker/setup-buildx-action action to v2 (#218)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-15 13:55:56 -09:00
renovate[bot]
2b7c1fa429 chore(deps): update dependency @nuxtjs/eslint-config-typescript to v12 (#217)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-15 13:55:48 -09:00
renovate[bot]
125b8f5ecd chore(deps): update actions/setup-go action to v3 (#216)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-15 13:55:40 -09:00
renovate[bot]
580de45cec chore(deps): update actions/checkout action to v3 (#215)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-15 13:55:32 -09:00
renovate[bot]
da52b4ec64 chore(deps): update dependency vitest to ^0.27.0 (#214)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-15 13:55:23 -09:00
renovate[bot]
5b0dba854d fix(deps): update dependency mkdocs-material to v9 (#222)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-15 13:54:33 -09:00
renovate[bot]
984c1a08ac fix(deps): update module ariga.io/atlas to v0.9.0 (#213)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-14 09:51:47 -09:00
renovate[bot]
8419a17109 fix(deps): update module entgo.io/ent to v0.11.5 (#211)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-14 09:40:20 -09:00
renovate[bot]
f3406eec19 chore(deps): update pnpm/action-setup action to v2.2.4 (#210)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-14 09:40:14 -09:00
renovate[bot]
3ed07a909f Add renovate.json (#209)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-14 09:28:52 -09:00
Hayden
07441eec8e feat: add lookup by asset ID (#208)
* add asset id redirecting

* dev env changes

* suggested changes from PR

* remove unnecessary proxy from nuxt config

* fix formatting

* change directory reference

* fix API key storage

* use /a/{id} as redirect

* run generators

* remove dependabot

Co-authored-by: Bradley Nelson <bradley@nel.family>
Co-authored-by: Bradley Nelson <BCNelson@users.noreply.github.com>
2023-01-14 09:24:11 -09:00
dependabot[bot]
c78f10ba5d fix(deps): bump golang.org/x/crypto from 0.4.0 to 0.5.0 in /backend (#199)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.4.0 to 0.5.0.
- [Release notes](https://github.com/golang/crypto/releases)
- [Commits](https://github.com/golang/crypto/compare/v0.4.0...v0.5.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-08 10:02:14 -09:00
Hayden
490a0ece86 chore: rewrite python script in go (#201) 2023-01-06 22:15:59 -09:00
Hayden
891d41b75f feat: new-card-design (#196)
* card option 1

* UI updates for item card

* fix test error

* fix pagination issues on backend

* add integer support

* remove date from cards

* implement pagination for search page

* resolve search state problems

* other fixes

* fix broken datetime

* attempt to fix scroll behavior
2023-01-01 12:50:48 -09:00
184 changed files with 9413 additions and 8603 deletions

View File

@@ -1,31 +0,0 @@
version: 2
updates:
# Fetch and update latest `npm` packages
- package-ecosystem: npm
directory: "/frontend"
schedule:
interval: daily
time: "00:00"
open-pull-requests-limit: 10
reviewers:
- hay-kot
assignees:
- hay-kot
commit-message:
prefix: fix
prefix-development: chore
include: scope
- package-ecosystem: gomod
directory: backend
schedule:
interval: daily
time: "00:00"
open-pull-requests-limit: 10
reviewers:
- hay-kot
assignees:
- hay-kot
commit-message:
prefix: fix
prefix-development: chore
include: scope

View File

@@ -7,10 +7,10 @@ jobs:
Go:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.19

View File

@@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
@@ -18,7 +18,7 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.19
@@ -26,7 +26,7 @@ jobs:
with:
node-version: 18
- uses: pnpm/action-setup@v2.2.2
- uses: pnpm/action-setup@v2.2.4
with:
version: 6.0.2

View File

@@ -20,22 +20,22 @@ jobs:
name: "Publish Homebox"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2
with:
image: tonistiigi/binfmt:latest
platforms: all
- name: install buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
with:
install: true

View File

@@ -27,7 +27,7 @@ jobs:
- backend-tests
- frontend-tests
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
@@ -63,7 +63,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Deploy docs
uses: mhausenblas/mkdocs-deploy-gh-pages@master

4
.gitignore vendored
View File

@@ -45,3 +45,7 @@ node_modules
.output
.env
dist
.pnpm-store
backend/app/api/app
backend/app/api/__debug_bin

47
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,47 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"compounds": [
{
"name": "Full Stack",
"configurations": ["Launch Backend", "Launch Frontend"],
"stopAll": true
}
],
"configurations": [
{
"name": "Launch Backend",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}/backend/app/api/",
"args": [],
"env": {
"HBOX_DEMO": "true",
"HBOX_LOG_LEVEL": "debug",
"HBOX_DEBUG_ENABLED": "true",
"HBOX_STORAGE_DATA": "${workspaceRoot}/backend/.data",
"HBOX_STORAGE_SQLITE_URL": "${workspaceRoot}/backend/.data/homebox.db?_fk=1"
},
},
{
"name": "Launch Frontend",
"type": "node",
"request": "launch",
"runtimeExecutable": "pnpm",
"runtimeArgs": [
"run",
"dev"
],
"cwd": "${workspaceFolder}/frontend",
"serverReadyAction": {
"action": "debugWithChrome",
"pattern": "Local: http://localhost:([0-9]+)",
"uriFormat": "http://localhost:%s",
"webRoot": "${workspaceFolder}/frontend"
}
}
]
}

11
.vscode/settings.json vendored
View File

@@ -12,7 +12,7 @@
"debughandlers"
],
// use ESLint to format code on save
"editor.formatOnSave": true,
"editor.formatOnSave": false,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
@@ -21,4 +21,13 @@
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"eslint.format.enable": true,
"css.validate": false,
"tailwindCSS.includeLanguages": {
"vue": "html",
"vue-html": "html"
},
"editor.quickSuggestions": {
"strings": true
},
"tailwindCSS.experimental.configFile": "./frontend/tailwind.config.js"
}

View File

@@ -26,7 +26,7 @@ tasks:
--modular \
--path ./backend/app/api/static/docs/swagger.json \
--output ./frontend/lib/api/types
- python3 ./scripts/process-types.py ./frontend/lib/api/types/data-contracts.ts
- go run ./scripts/process-types/*.go ./frontend/lib/api/types/data-contracts.ts
sources:
- "./backend/app/api/**/*"
- "./backend/internal/data/**"

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -9,15 +9,15 @@ import (
"github.com/rs/zerolog/log"
)
type EnsureAssetIDResult struct {
type ActionAmountResult struct {
Completed int `json:"completed"`
}
// HandleGroupInvitationsCreate godoc
// @Summary Get the current user
// @Summary Ensures all items in the database have an asset id
// @Tags Group
// @Produce json
// @Success 200 {object} EnsureAssetIDResult
// @Success 200 {object} ActionAmountResult
// @Router /v1/actions/ensure-asset-ids [Post]
// @Security Bearer
func (ctrl *V1Controller) HandleEnsureAssetID() server.HandlerFunc {
@@ -30,6 +30,27 @@ func (ctrl *V1Controller) HandleEnsureAssetID() server.HandlerFunc {
return validate.NewRequestError(err, http.StatusInternalServerError)
}
return server.Respond(w, http.StatusOK, EnsureAssetIDResult{Completed: totalCompleted})
return server.Respond(w, http.StatusOK, ActionAmountResult{Completed: totalCompleted})
}
}
// HandleItemDateZeroOut godoc
// @Summary Resets all item date fields to the beginning of the day
// @Tags Group
// @Produce json
// @Success 200 {object} ActionAmountResult
// @Router /v1/actions/zero-item-time-fields [Post]
// @Security Bearer
func (ctrl *V1Controller) HandleItemDateZeroOut() server.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
ctx := services.NewContext(r.Context())
totalCompleted, err := ctrl.repo.Items.ZeroOutTimeFields(ctx, ctx.GID)
if err != nil {
log.Err(err).Msg("failed to ensure asset id")
return validate.NewRequestError(err, http.StatusInternalServerError)
}
return server.Respond(w, http.StatusOK, ActionAmountResult{Completed: totalCompleted})
}
}

View File

@@ -0,0 +1,61 @@
package v1
import (
"net/http"
"strconv"
"strings"
"github.com/go-chi/chi/v5"
"github.com/hay-kot/homebox/backend/internal/core/services"
"github.com/hay-kot/homebox/backend/internal/data/repo"
"github.com/hay-kot/homebox/backend/internal/sys/validate"
"github.com/hay-kot/homebox/backend/pkgs/server"
"github.com/rs/zerolog/log"
)
// HandleItemGet godocs
// @Summary Gets an item by Asset ID
// @Tags Assets
// @Produce json
// @Param id path string true "Asset ID"
// @Success 200 {object} repo.PaginationResult[repo.ItemSummary]{}
// @Router /v1/assets/{id} [GET]
// @Security Bearer
func (ctrl *V1Controller) HandleAssetGet() server.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
ctx := services.NewContext(r.Context())
assetIdParam := chi.URLParam(r, "id")
assetIdParam = strings.ReplaceAll(assetIdParam, "-", "") // Remove dashes
// Convert the asset ID to an int64
assetId, err := strconv.ParseInt(assetIdParam, 10, 64)
if err != nil {
return err
}
pageParam := r.URL.Query().Get("page")
var page int64 = -1
if pageParam != "" {
page, err = strconv.ParseInt(pageParam, 10, 64)
if err != nil {
return server.Respond(w, http.StatusBadRequest, "Invalid page number")
}
}
pageSizeParam := r.URL.Query().Get("pageSize")
var pageSize int64 = -1
if pageSizeParam != "" {
pageSize, err = strconv.ParseInt(pageSizeParam, 10, 64)
if err != nil {
return server.Respond(w, http.StatusBadRequest, "Invalid page size")
}
}
items, err := ctrl.repo.Items.QueryByAssetID(r.Context(), ctx.GID, repo.AssetID(assetId), int(page), int(pageSize))
if err != nil {
log.Err(err).Msg("failed to get item")
return validate.NewRequestError(err, http.StatusInternalServerError)
}
return server.Respond(w, http.StatusOK, items)
}
}

View File

@@ -3,6 +3,7 @@ package v1
import (
"errors"
"net/http"
"strings"
"time"
"github.com/hay-kot/homebox/backend/internal/core/services"
@@ -70,7 +71,7 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc {
)
}
newToken, err := ctrl.svc.User.Login(r.Context(), loginForm.Username, loginForm.Password)
newToken, err := ctrl.svc.User.Login(r.Context(), strings.ToLower(loginForm.Username), loginForm.Password)
if err != nil {
return validate.NewRequestError(errors.New("authentication failed"), http.StatusInternalServerError)

View File

@@ -4,6 +4,7 @@ import (
"database/sql"
"errors"
"net/http"
"strings"
"github.com/hay-kot/homebox/backend/internal/core/services"
"github.com/hay-kot/homebox/backend/internal/data/repo"
@@ -29,18 +30,48 @@ func (ctrl *V1Controller) HandleItemsGetAll() server.HandlerFunc {
extractQuery := func(r *http.Request) repo.ItemQuery {
params := r.URL.Query()
return repo.ItemQuery{
filterFieldItems := func(raw []string) []repo.FieldQuery {
var items []repo.FieldQuery
for _, v := range raw {
parts := strings.SplitN(v, "=", 2)
if len(parts) == 2 {
items = append(items, repo.FieldQuery{
Name: parts[0],
Value: parts[1],
})
}
}
return items
}
v := repo.ItemQuery{
Page: queryIntOrNegativeOne(params.Get("page")),
PageSize: queryIntOrNegativeOne(params.Get("pageSize")),
Search: params.Get("q"),
LocationIDs: queryUUIDList(params, "locations"),
LabelIDs: queryUUIDList(params, "labels"),
IncludeArchived: queryBool(params.Get("includeArchived")),
Fields: filterFieldItems(params["fields"]),
}
if strings.HasPrefix(v.Search, "#") {
aidStr := strings.TrimPrefix(v.Search, "#")
aid, ok := repo.ParseAssetID(aidStr)
if ok {
v.Search = ""
v.AssetID = aid
}
}
return v
}
return func(w http.ResponseWriter, r *http.Request) error {
ctx := services.NewContext(r.Context())
items, err := ctrl.repo.Items.QueryByGroup(ctx, ctx.GID, extractQuery(r))
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
@@ -161,6 +192,48 @@ func (ctrl *V1Controller) handleItemsGeneral() server.HandlerFunc {
}
}
// HandleGetAllCustomFieldNames godocs
// @Summary imports items into the database
// @Tags Items
// @Produce json
// @Success 200
// @Router /v1/items/fields [GET]
// @Success 200 {object} []string
// @Security Bearer
func (ctrl *V1Controller) HandleGetAllCustomFieldNames() server.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
ctx := services.NewContext(r.Context())
v, err := ctrl.repo.Items.GetAllCustomFieldNames(r.Context(), ctx.GID)
if err != nil {
return err
}
return server.Respond(w, http.StatusOK, v)
}
}
// HandleGetAllCustomFieldValues godocs
// @Summary imports items into the database
// @Tags Items
// @Produce json
// @Success 200
// @Router /v1/items/fields/values [GET]
// @Success 200 {object} []string
// @Security Bearer
func (ctrl *V1Controller) HandleGetAllCustomFieldValues() server.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
ctx := services.NewContext(r.Context())
v, err := ctrl.repo.Items.GetAllCustomFieldValues(r.Context(), ctx.GID, r.URL.Query().Get("field"))
if err != nil {
return err
}
return server.Respond(w, http.StatusOK, v)
}
}
// HandleItemsImport godocs
// @Summary imports items into the database
// @Tags Items

View File

@@ -11,6 +11,39 @@ import (
"github.com/rs/zerolog/log"
)
// HandleLocationTreeQuery godoc
// @Summary Get All Locations
// @Tags Locations
// @Produce json
// @Param withItems query bool false "include items in response tree"
// @Success 200 {object} server.Results{items=[]repo.TreeItem}
// @Router /v1/locations/tree [GET]
// @Security Bearer
func (ctrl *V1Controller) HandleLocationTreeQuery() server.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
user := services.UseUserCtx(r.Context())
q := r.URL.Query()
withItems := queryBool(q.Get("withItems"))
locTree, err := ctrl.repo.Locations.Tree(
r.Context(),
user.GroupID,
repo.TreeQuery{
WithItems: withItems,
},
)
if err != nil {
log.Err(err).Msg("failed to get locations tree")
return validate.NewRequestError(err, http.StatusInternalServerError)
}
return server.Respond(w, http.StatusOK, server.Results{Items: locTree})
}
}
// HandleLocationGetAll godoc
// @Summary Get All Locations
// @Tags Locations

View File

@@ -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)
}
}

View File

@@ -0,0 +1,32 @@
package v1
import (
"net/http"
"github.com/hay-kot/homebox/backend/internal/core/services"
"github.com/hay-kot/homebox/backend/pkgs/server"
)
// HandleBillOfMaterialsExport godoc
//
// @Summary Generates a Bill of Materials CSV
// @Tags Reporting
// @Produce json
// @Success 200 {string} string "text/csv"
// @Router /v1/reporting/bill-of-materials [GET]
// @Security Bearer
func (ctrl *V1Controller) HandleBillOfMaterialsExport() server.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
actor := services.UseUserCtx(r.Context())
csv, err := ctrl.svc.Reporting.BillOfMaterialsTSV(r.Context(), actor.GroupID)
if err != nil {
return err
}
w.Header().Set("Content-Type", "text/csv")
w.Header().Set("Content-Disposition", "attachment; filename=bom.csv")
_, err = w.Write(csv)
return err
}
}

View File

@@ -88,9 +88,11 @@ func (a *app) mountRoutes(repos *repo.AllRepos) {
a.server.Put(v1Base("/groups"), v1Ctrl.HandleGroupUpdate(), userMW...)
a.server.Post(v1Base("/actions/ensure-asset-ids"), v1Ctrl.HandleEnsureAssetID(), userMW...)
a.server.Post(v1Base("/actions/zero-item-time-fields"), v1Ctrl.HandleItemDateZeroOut(), userMW...)
a.server.Get(v1Base("/locations"), v1Ctrl.HandleLocationGetAll(), userMW...)
a.server.Post(v1Base("/locations"), v1Ctrl.HandleLocationCreate(), userMW...)
a.server.Get(v1Base("/locations/tree"), v1Ctrl.HandleLocationTreeQuery(), userMW...)
a.server.Get(v1Base("/locations/{id}"), v1Ctrl.HandleLocationGet(), userMW...)
a.server.Put(v1Base("/locations/{id}"), v1Ctrl.HandleLocationUpdate(), userMW...)
a.server.Delete(v1Base("/locations/{id}"), v1Ctrl.HandleLocationDelete(), userMW...)
@@ -102,8 +104,11 @@ func (a *app) mountRoutes(repos *repo.AllRepos) {
a.server.Delete(v1Base("/labels/{id}"), v1Ctrl.HandleLabelDelete(), userMW...)
a.server.Get(v1Base("/items"), v1Ctrl.HandleItemsGetAll(), userMW...)
a.server.Post(v1Base("/items/import"), v1Ctrl.HandleItemsImport(), userMW...)
a.server.Post(v1Base("/items"), v1Ctrl.HandleItemsCreate(), userMW...)
a.server.Post(v1Base("/items/import"), v1Ctrl.HandleItemsImport(), userMW...)
a.server.Get(v1Base("/items/fields"), v1Ctrl.HandleGetAllCustomFieldNames(), userMW...)
a.server.Get(v1Base("/items/fields/values"), v1Ctrl.HandleGetAllCustomFieldValues(), userMW...)
a.server.Get(v1Base("/items/{id}"), v1Ctrl.HandleItemGet(), userMW...)
a.server.Put(v1Base("/items/{id}"), v1Ctrl.HandleItemUpdate(), userMW...)
a.server.Delete(v1Base("/items/{id}"), v1Ctrl.HandleItemDelete(), userMW...)
@@ -117,12 +122,23 @@ func (a *app) mountRoutes(repos *repo.AllRepos) {
a.server.Put(v1Base("/items/{id}/maintenance/{entry_id}"), v1Ctrl.HandleMaintenanceEntryUpdate(), userMW...)
a.server.Delete(v1Base("/items/{id}/maintenance/{entry_id}"), v1Ctrl.HandleMaintenanceEntryDelete(), userMW...)
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(),
a.mwAuthToken, a.mwRoles(RoleModeOr, authroles.RoleUser.String(), authroles.RoleAttachments.String()),
)
// Reporting Services
a.server.Get(v1Base("/reporting/bill-of-materials"), v1Ctrl.HandleBillOfMaterialsExport(), userMW...)
a.server.NotFound(notFoundHandler())
}

View File

@@ -34,12 +34,69 @@ const docTemplate = `{
"tags": [
"Group"
],
"summary": "Get the current user",
"summary": "Ensures all items in the database have an asset id",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.EnsureAssetIDResult"
"$ref": "#/definitions/v1.ActionAmountResult"
}
}
}
}
},
"/v1/actions/zero-item-time-fields": {
"post": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Group"
],
"summary": "Resets all item date fields to the beginning of the day",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.ActionAmountResult"
}
}
}
}
},
"/v1/assets/{id}": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Assets"
],
"summary": "Gets an item by Asset ID",
"parameters": [
{
"type": "string",
"description": "Asset ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/repo.PaginationResult-repo_ItemSummary"
}
}
}
@@ -350,6 +407,60 @@ const docTemplate = `{
}
}
},
"/v1/items/fields": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Items"
],
"summary": "imports items into the database",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"/v1/items/fields/values": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Items"
],
"summary": "imports items into the database",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"/v1/items/import": {
"post": {
"security": [
@@ -1012,6 +1123,53 @@ const docTemplate = `{
}
}
},
"/v1/locations/tree": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Locations"
],
"summary": "Get All Locations",
"parameters": [
{
"type": "boolean",
"description": "include items in response tree",
"name": "withItems",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/server.Results"
},
{
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/repo.TreeItem"
}
}
}
}
]
}
}
}
}
},
"/v1/locations/{id}": {
"get": {
"security": [
@@ -1113,6 +1271,62 @@ 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/reporting/bill-of-materials": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Reporting"
],
"summary": "Generates a Bill of Materials CSV",
"responses": {
"200": {
"description": "text/csv",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/status": {
"get": {
"produces": [
@@ -1841,6 +2055,10 @@ const docTemplate = `{
},
"name": {
"type": "string"
},
"parentId": {
"type": "string",
"x-nullable": true
}
}
},
@@ -2051,6 +2269,26 @@ const docTemplate = `{
}
}
},
"repo.TreeItem": {
"type": "object",
"properties": {
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/repo.TreeItem"
}
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"repo.UserOut": {
"type": "object",
"properties": {
@@ -2175,6 +2413,14 @@ const docTemplate = `{
}
}
},
"v1.ActionAmountResult": {
"type": "object",
"properties": {
"completed": {
"type": "integer"
}
}
},
"v1.ApiSummary": {
"type": "object",
"properties": {
@@ -2226,14 +2472,6 @@ const docTemplate = `{
}
}
},
"v1.EnsureAssetIDResult": {
"type": "object",
"properties": {
"completed": {
"type": "integer"
}
}
},
"v1.GroupInvitation": {
"type": "object",
"properties": {

View File

@@ -26,12 +26,69 @@
"tags": [
"Group"
],
"summary": "Get the current user",
"summary": "Ensures all items in the database have an asset id",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.EnsureAssetIDResult"
"$ref": "#/definitions/v1.ActionAmountResult"
}
}
}
}
},
"/v1/actions/zero-item-time-fields": {
"post": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Group"
],
"summary": "Resets all item date fields to the beginning of the day",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.ActionAmountResult"
}
}
}
}
},
"/v1/assets/{id}": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Assets"
],
"summary": "Gets an item by Asset ID",
"parameters": [
{
"type": "string",
"description": "Asset ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/repo.PaginationResult-repo_ItemSummary"
}
}
}
@@ -342,6 +399,60 @@
}
}
},
"/v1/items/fields": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Items"
],
"summary": "imports items into the database",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"/v1/items/fields/values": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Items"
],
"summary": "imports items into the database",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"/v1/items/import": {
"post": {
"security": [
@@ -1004,6 +1115,53 @@
}
}
},
"/v1/locations/tree": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Locations"
],
"summary": "Get All Locations",
"parameters": [
{
"type": "boolean",
"description": "include items in response tree",
"name": "withItems",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/server.Results"
},
{
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/repo.TreeItem"
}
}
}
}
]
}
}
}
}
},
"/v1/locations/{id}": {
"get": {
"security": [
@@ -1105,6 +1263,62 @@
}
}
},
"/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/reporting/bill-of-materials": {
"get": {
"security": [
{
"Bearer": []
}
],
"produces": [
"application/json"
],
"tags": [
"Reporting"
],
"summary": "Generates a Bill of Materials CSV",
"responses": {
"200": {
"description": "text/csv",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/status": {
"get": {
"produces": [
@@ -1833,6 +2047,10 @@
},
"name": {
"type": "string"
},
"parentId": {
"type": "string",
"x-nullable": true
}
}
},
@@ -2043,6 +2261,26 @@
}
}
},
"repo.TreeItem": {
"type": "object",
"properties": {
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/repo.TreeItem"
}
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"repo.UserOut": {
"type": "object",
"properties": {
@@ -2167,6 +2405,14 @@
}
}
},
"v1.ActionAmountResult": {
"type": "object",
"properties": {
"completed": {
"type": "integer"
}
}
},
"v1.ApiSummary": {
"type": "object",
"properties": {
@@ -2218,14 +2464,6 @@
}
}
},
"v1.EnsureAssetIDResult": {
"type": "object",
"properties": {
"completed": {
"type": "integer"
}
}
},
"v1.GroupInvitation": {
"type": "object",
"properties": {

View File

@@ -322,6 +322,9 @@ definitions:
type: string
name:
type: string
parentId:
type: string
x-nullable: true
type: object
repo.LocationOut:
properties:
@@ -459,6 +462,19 @@ definitions:
total:
type: number
type: object
repo.TreeItem:
properties:
children:
items:
$ref: '#/definitions/repo.TreeItem'
type: array
id:
type: string
name:
type: string
type:
type: string
type: object
repo.UserOut:
properties:
email:
@@ -540,6 +556,11 @@ definitions:
token:
type: string
type: object
v1.ActionAmountResult:
properties:
completed:
type: integer
type: object
v1.ApiSummary:
properties:
build:
@@ -573,11 +594,6 @@ definitions:
new:
type: string
type: object
v1.EnsureAssetIDResult:
properties:
completed:
type: integer
type: object
v1.GroupInvitation:
properties:
expiresAt:
@@ -627,12 +643,46 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/v1.EnsureAssetIDResult'
$ref: '#/definitions/v1.ActionAmountResult'
security:
- Bearer: []
summary: Get the current user
summary: Ensures all items in the database have an asset id
tags:
- Group
/v1/actions/zero-item-time-fields:
post:
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/v1.ActionAmountResult'
security:
- Bearer: []
summary: Resets all item date fields to the beginning of the day
tags:
- Group
/v1/assets/{id}:
get:
parameters:
- description: Asset ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/repo.PaginationResult-repo_ItemSummary'
security:
- Bearer: []
summary: Gets an item by Asset ID
tags:
- Assets
/v1/groups:
get:
produces:
@@ -1058,6 +1108,38 @@ paths:
summary: Update Maintenance Entry
tags:
- Maintenance
/v1/items/fields:
get:
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
type: string
type: array
security:
- Bearer: []
summary: imports items into the database
tags:
- Items
/v1/items/fields/values:
get:
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
type: string
type: array
security:
- Bearer: []
summary: imports items into the database
tags:
- Items
/v1/items/import:
post:
parameters:
@@ -1281,6 +1363,65 @@ paths:
summary: updates a location
tags:
- Locations
/v1/locations/tree:
get:
parameters:
- description: include items in response tree
in: query
name: withItems
type: boolean
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/server.Results'
- properties:
items:
items:
$ref: '#/definitions/repo.TreeItem'
type: array
type: object
security:
- Bearer: []
summary: Get All Locations
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/reporting/bill-of-materials:
get:
produces:
- application/json
responses:
"200":
description: text/csv
schema:
type: string
security:
- Bearer: []
summary: Generates a Bill of Materials CSV
tags:
- Reporting
/v1/status:
get:
produces:

View File

@@ -3,18 +3,21 @@ module github.com/hay-kot/homebox/backend
go 1.19
require (
ariga.io/atlas v0.8.3
entgo.io/ent v0.11.4
github.com/ardanlabs/conf/v2 v2.2.0
ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb
entgo.io/ent v0.11.7
github.com/ardanlabs/conf/v3 v3.1.3
github.com/go-chi/chi/v5 v5.0.8
github.com/go-playground/validator/v10 v10.11.1
github.com/go-playground/validator/v10 v10.11.2
github.com/gocarina/gocsv v0.0.0-20230123225133-763e25b40669
github.com/google/uuid v1.3.0
github.com/mattn/go-sqlite3 v1.14.16
github.com/rs/zerolog v1.28.0
github.com/rs/zerolog v1.29.0
github.com/stretchr/testify v1.8.1
github.com/swaggo/http-swagger v1.3.3
github.com/swaggo/swag v1.8.9
golang.org/x/crypto v0.4.0
github.com/swaggo/swag v1.8.10
github.com/yeqown/go-qrcode/v2 v2.2.1
github.com/yeqown/go-qrcode/writer/standard v1.2.1
golang.org/x/crypto v0.6.0
)
require (
@@ -22,13 +25,15 @@ 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
github.com/go-openapi/spec v0.20.7 // indirect
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/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // 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,13 +42,16 @@ 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.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/tools v0.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@@ -1,7 +1,7 @@
ariga.io/atlas v0.8.3 h1:nddOywkhr/62Cwa+UsGgO35lAhUYh52XGVsbFwGzWZM=
ariga.io/atlas v0.8.3/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=
ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb h1:mbsFtavDqGdYwdDpP50LGOOZ2hgyGoJcZeOpbgKMyu4=
ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU=
entgo.io/ent v0.11.7 h1:V+wKFh0jhAbY/FoU+PPbdMOf2Ma5vh07R/IdF+N/nFg=
entgo.io/ent v0.11.7/go.mod h1:ericBi6Q8l3wBH1wEIDfKxw7rcQEuRPyBfbIzjtxJ18=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
@@ -9,13 +9,15 @@ github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7l
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/ardanlabs/conf/v2 v2.2.0 h1:ar1+TYIYAh2Tdeg2DQroh7ruR56/vJR8BDfzDIrXgtk=
github.com/ardanlabs/conf/v2 v2.2.0/go.mod h1:m37ZKdW9jwMUEhGX36jRNt8VzSQ/HVmSziLZH2p33nY=
github.com/ardanlabs/conf/v3 v3.1.3 h1:16+Nzfc4PBd/ERtYERUFL/75eVKNyW15Y+vn3W1XZzQ=
github.com/ardanlabs/conf/v3 v3.1.3/go.mod h1:bIacyuGeZjkTdtszdbvOcuq49VhHpV3+IPZ2ewOAK4I=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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=
@@ -31,16 +33,19 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/gocarina/gocsv v0.0.0-20230123225133-763e25b40669 h1:MvZzCA/mduVWoBSVKJeMdv+AqXQmZZ8i6p8889ejt/Y=
github.com/gocarina/gocsv v0.0.0-20230123225133-763e25b40669/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI=
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=
@@ -51,9 +56,7 @@ github.com/hashicorp/hcl/v2 v2.15.0/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6Ko
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -80,16 +83,14 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ
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=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w=
github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
@@ -98,7 +99,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
@@ -107,51 +107,54 @@ github.com/swaggo/files v1.0.0 h1:1gGXVIeUFCS/dta17rnP0iOpr6CXFwKD7EO5ID233e4=
github.com/swaggo/files v1.0.0/go.mod h1:N59U6URJLyU1PQgFqPM7wXLMhJx7QAolnvfQkqO13kc=
github.com/swaggo/http-swagger v1.3.3 h1:Hu5Z0L9ssyBLofaama21iYaF2VbWyA8jdohaaCGpHsc=
github.com/swaggo/http-swagger v1.3.3/go.mod h1:sE+4PjD89IxMPm77FnkDz0sdO+p5lbXzrVWT6OTVVGo=
github.com/swaggo/swag v1.8.9 h1:kHtaBe/Ob9AZzAANfcn5c6RyCke9gG9QpH0jky0I/sA=
github.com/swaggo/swag v1.8.9/go.mod h1:ezQVUUhly8dludpVk+/PuwJWvLLanB13ygV5Pr9enSk=
github.com/swaggo/swag v1.8.10 h1:eExW4bFa52WOjqRzRD58bgWsWfdFJso50lpbeTcmTfo=
github.com/swaggo/swag v1.8.10/go.mod h1:ezQVUUhly8dludpVk+/PuwJWvLLanB13ygV5Pr9enSk=
github.com/yeqown/go-qrcode/v2 v2.2.1 h1:Jc1Q916fwC05R8C7mpWDbrT9tyLPaLLKDABoC5XBCe8=
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=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8=
golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
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=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
@@ -162,13 +165,10 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -1,11 +1,16 @@
package services
import "github.com/hay-kot/homebox/backend/internal/data/repo"
import (
"github.com/hay-kot/homebox/backend/internal/core/services/reporting"
"github.com/hay-kot/homebox/backend/internal/data/repo"
"github.com/rs/zerolog/log"
)
type AllServices struct {
User *UserService
Group *GroupService
Items *ItemService
User *UserService
Group *GroupService
Items *ItemService
Reporting *reporting.ReportingService
}
type OptionsFunc func(*options)
@@ -40,5 +45,7 @@ func New(repos *repo.AllRepos, opts ...OptionsFunc) *AllServices {
repo: repos,
autoIncrementAssetID: options.autoIncrementAssetID,
},
// TODO: don't use global logger
Reporting: reporting.NewReportingService(repos, &log.Logger),
}
}

View File

@@ -0,0 +1,85 @@
package reporting
import (
"context"
"encoding/csv"
"io"
"time"
"github.com/gocarina/gocsv"
"github.com/google/uuid"
"github.com/hay-kot/homebox/backend/internal/data/repo"
"github.com/rs/zerolog"
)
type ReportingService struct {
repos *repo.AllRepos
l *zerolog.Logger
}
func NewReportingService(repos *repo.AllRepos, l *zerolog.Logger) *ReportingService {
gocsv.SetCSVWriter(func(out io.Writer) *gocsv.SafeCSVWriter {
writer := csv.NewWriter(out)
writer.Comma = '\t'
return gocsv.NewSafeCSVWriter(writer)
})
return &ReportingService{
repos: repos,
l: l,
}
}
// =================================================================================================
// NullableTime is a custom type that implements the MarshalCSV interface
// to allow for nullable time.Time fields in the CSV output to be empty
// and not "0001-01-01". It also overrides the default CSV output format
type NullableTime time.Time
func (t NullableTime) MarshalCSV() (string, error) {
if time.Time(t).IsZero() {
return "", nil
}
// YYYY-MM-DD
return time.Time(t).Format("2006-01-02"), nil
}
type BillOfMaterialsEntry struct {
PurchaseDate NullableTime `csv:"Purchase Date"`
Name string `csv:"Name"`
Description string `csv:"Description"`
Manufacturer string `csv:"Manufacturer"`
SerialNumber string `csv:"Serial Number"`
ModelNumber string `csv:"Model Number"`
Quantity int `csv:"Quantity"`
Price float64 `csv:"Price"`
TotalPrice float64 `csv:"Total Price"`
}
// BillOfMaterialsTSV returns a byte slice of the Bill of Materials for a given GID in TSV format
// See BillOfMaterialsEntry for the format of the output
func (rs *ReportingService) BillOfMaterialsTSV(ctx context.Context, GID uuid.UUID) ([]byte, error) {
entities, err := rs.repos.Items.GetAll(ctx, GID)
if err != nil {
rs.l.Debug().Err(err).Msg("failed to get all items for BOM Csv Reporting")
return nil, err
}
bomEntries := make([]BillOfMaterialsEntry, len(entities))
for i, entity := range entities {
bomEntries[i] = BillOfMaterialsEntry{
PurchaseDate: NullableTime(entity.PurchaseTime),
Name: entity.Name,
Description: entity.Description,
Manufacturer: entity.Manufacturer,
SerialNumber: entity.SerialNumber,
ModelNumber: entity.ModelNumber,
Quantity: entity.Quantity,
Price: entity.PurchasePrice,
TotalPrice: entity.PurchasePrice * float64(entity.Quantity),
}
}
return gocsv.MarshalBytes(&bomEntries)
}

View File

@@ -12,10 +12,10 @@ import (
"github.com/stretchr/testify/assert"
)
//go:embed testdata/import.csv
//go:embed .testdata/import.csv
var CSVData_Comma []byte
//go:embed testdata/import.tsv
//go:embed .testdata/import.tsv
var CSVData_Tab []byte
func loadcsv() [][]string {

View File

@@ -51,15 +51,17 @@ func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration)
Msg("Registering new user")
var (
err error
group repo.Group
token repo.GroupInvitation
isOwner = false
err error
group repo.Group
token repo.GroupInvitation
// creatingGroup is true if the user is creating a new group.
creatingGroup = false
)
switch data.GroupToken {
case "":
isOwner = true
creatingGroup = true
group, err = svc.repos.Groups.GroupCreate(ctx, "Home")
if err != nil {
log.Err(err).Msg("Failed to create group")
@@ -81,7 +83,7 @@ func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration)
Password: hashed,
IsSuperuser: false,
GroupID: group.ID,
IsOwner: isOwner,
IsOwner: creatingGroup,
}
usr, err := svc.repos.Users.Create(ctx, usrCreate)
@@ -89,21 +91,24 @@ func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration)
return repo.UserOut{}, err
}
for _, label := range defaultLabels() {
_, err := svc.repos.Labels.Create(ctx, group.ID, label)
if err != nil {
return repo.UserOut{}, err
// Create the default labels and locations for the group.
if creatingGroup {
for _, label := range defaultLabels() {
_, err := svc.repos.Labels.Create(ctx, group.ID, label)
if err != nil {
return repo.UserOut{}, err
}
}
for _, location := range defaultLocations() {
_, err := svc.repos.Locations.Create(ctx, group.ID, location)
if err != nil {
return repo.UserOut{}, err
}
}
}
for _, location := range defaultLocations() {
_, err := svc.repos.Locations.Create(ctx, group.ID, location)
if err != nil {
return repo.UserOut{}, err
}
}
// Decrement the invitation token if it was used
// Decrement the invitation token if it was used.
if token.ID != uuid.Nil {
err = svc.repos.Groups.InvitationUpdate(ctx, token.ID, token.Uses-1)
if err != nil {

View File

@@ -144,19 +144,19 @@ func (a *Attachment) assignValues(columns []string, values []any) error {
// QueryItem queries the "item" edge of the Attachment entity.
func (a *Attachment) QueryItem() *ItemQuery {
return (&AttachmentClient{config: a.config}).QueryItem(a)
return NewAttachmentClient(a.config).QueryItem(a)
}
// QueryDocument queries the "document" edge of the Attachment entity.
func (a *Attachment) QueryDocument() *DocumentQuery {
return (&AttachmentClient{config: a.config}).QueryDocument(a)
return NewAttachmentClient(a.config).QueryDocument(a)
}
// Update returns a builder for updating this Attachment.
// Note that you need to call Attachment.Unwrap() before calling this method if this Attachment
// was returned from a transaction, and the transaction was committed or rolled back.
func (a *Attachment) Update() *AttachmentUpdateOne {
return (&AttachmentClient{config: a.config}).UpdateOne(a)
return NewAttachmentClient(a.config).UpdateOne(a)
}
// Unwrap unwraps the Attachment entity that was returned from a transaction after it was closed,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type AttachmentDeleteOne struct {
ad *AttachmentDelete
}
// Where appends a list predicates to the AttachmentDelete builder.
func (ado *AttachmentDeleteOne) Where(ps ...predicate.Attachment) *AttachmentDeleteOne {
ado.ad.mutation.Where(ps...)
return ado
}
// Exec executes the deletion query.
func (ado *AttachmentDeleteOne) Exec(ctx context.Context) error {
n, err := ado.ad.Exec(ctx)
@@ -111,5 +90,7 @@ func (ado *AttachmentDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (ado *AttachmentDeleteOne) ExecX(ctx context.Context) {
ado.ad.ExecX(ctx)
if err := ado.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -20,11 +20,9 @@ import (
// AttachmentQuery is the builder for querying Attachment entities.
type AttachmentQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.Attachment
withItem *ItemQuery
withDocument *DocumentQuery
@@ -40,26 +38,26 @@ 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
aq.ctx.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
aq.ctx.Offset = &offset
return aq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (aq *AttachmentQuery) Unique(unique bool) *AttachmentQuery {
aq.unique = &unique
aq.ctx.Unique = &unique
return aq
}
// 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 +65,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 +87,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 +110,7 @@ func (aq *AttachmentQuery) QueryDocument() *DocumentQuery {
// First returns the first Attachment entity from the query.
// Returns a *NotFoundError when no Attachment was found.
func (aq *AttachmentQuery) First(ctx context.Context) (*Attachment, error) {
nodes, err := aq.Limit(1).All(ctx)
nodes, err := aq.Limit(1).All(setContextOp(ctx, aq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -135,7 +133,7 @@ func (aq *AttachmentQuery) FirstX(ctx context.Context) *Attachment {
// Returns a *NotFoundError when no Attachment ID was found.
func (aq *AttachmentQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = aq.Limit(1).IDs(ctx); err != nil {
if ids, err = aq.Limit(1).IDs(setContextOp(ctx, aq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -158,7 +156,7 @@ func (aq *AttachmentQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one Attachment entity is found.
// Returns a *NotFoundError when no Attachment entities are found.
func (aq *AttachmentQuery) Only(ctx context.Context) (*Attachment, error) {
nodes, err := aq.Limit(2).All(ctx)
nodes, err := aq.Limit(2).All(setContextOp(ctx, aq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -186,7 +184,7 @@ func (aq *AttachmentQuery) OnlyX(ctx context.Context) *Attachment {
// Returns a *NotFoundError when no entities are found.
func (aq *AttachmentQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = aq.Limit(2).IDs(ctx); err != nil {
if ids, err = aq.Limit(2).IDs(setContextOp(ctx, aq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -211,10 +209,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 = setContextOp(ctx, aq.ctx, "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 +229,7 @@ func (aq *AttachmentQuery) AllX(ctx context.Context) []*Attachment {
// IDs executes the query and returns a list of Attachment IDs.
func (aq *AttachmentQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = setContextOp(ctx, aq.ctx, "IDs")
if err := aq.Select(attachment.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -246,10 +247,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 = setContextOp(ctx, aq.ctx, "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 +265,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 = setContextOp(ctx, aq.ctx, "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.
@@ -286,23 +293,22 @@ func (aq *AttachmentQuery) Clone() *AttachmentQuery {
}
return &AttachmentQuery{
config: aq.config,
limit: aq.limit,
offset: aq.offset,
ctx: aq.ctx.Clone(),
order: append([]OrderFunc{}, aq.order...),
inters: append([]Interceptor{}, aq.inters...),
predicates: append([]predicate.Attachment{}, aq.predicates...),
withItem: aq.withItem.Clone(),
withDocument: aq.withDocument.Clone(),
// clone intermediate query.
sql: aq.sql.Clone(),
path: aq.path,
unique: aq.unique,
sql: aq.sql.Clone(),
path: aq.path,
}
}
// 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 +319,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 +342,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &AttachmentGroupBy{build: aq}
grbuild.flds = &aq.ctx.Fields
grbuild.label = attachment.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -362,11 +363,11 @@ func (aq *AttachmentQuery) GroupBy(field string, fields ...string) *AttachmentGr
// Select(attachment.FieldCreatedAt).
// Scan(ctx, &v)
func (aq *AttachmentQuery) Select(fields ...string) *AttachmentSelect {
aq.fields = append(aq.fields, fields...)
selbuild := &AttachmentSelect{AttachmentQuery: aq}
selbuild.label = attachment.Label
selbuild.flds, selbuild.scan = &aq.fields, selbuild.Scan
return selbuild
aq.ctx.Fields = append(aq.ctx.Fields, fields...)
sbuild := &AttachmentSelect{AttachmentQuery: aq}
sbuild.label = attachment.Label
sbuild.flds, sbuild.scan = &aq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a AttachmentSelect configured with the given aggregations.
@@ -375,7 +376,17 @@ func (aq *AttachmentQuery) Aggregate(fns ...AggregateFunc) *AttachmentSelect {
}
func (aq *AttachmentQuery) prepareQuery(ctx context.Context) error {
for _, f := range aq.fields {
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.ctx.Fields {
if !attachment.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -452,6 +463,9 @@ func (aq *AttachmentQuery) loadItem(ctx context.Context, query *ItemQuery, nodes
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(item.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -481,6 +495,9 @@ func (aq *AttachmentQuery) loadDocument(ctx context.Context, query *DocumentQuer
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(document.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -500,24 +517,13 @@ func (aq *AttachmentQuery) loadDocument(ctx context.Context, query *DocumentQuer
func (aq *AttachmentQuery) sqlCount(ctx context.Context) (int, error) {
_spec := aq.querySpec()
_spec.Node.Columns = aq.fields
if len(aq.fields) > 0 {
_spec.Unique = aq.unique != nil && *aq.unique
_spec.Node.Columns = aq.ctx.Fields
if len(aq.ctx.Fields) > 0 {
_spec.Unique = aq.ctx.Unique != nil && *aq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, aq.driver, _spec)
}
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{
@@ -531,10 +537,10 @@ func (aq *AttachmentQuery) querySpec() *sqlgraph.QuerySpec {
From: aq.sql,
Unique: true,
}
if unique := aq.unique; unique != nil {
if unique := aq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := aq.fields; len(fields) > 0 {
if fields := aq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, attachment.FieldID)
for i := range fields {
@@ -550,10 +556,10 @@ func (aq *AttachmentQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := aq.limit; limit != nil {
if limit := aq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := aq.offset; offset != nil {
if offset := aq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := aq.order; len(ps) > 0 {
@@ -569,7 +575,7 @@ func (aq *AttachmentQuery) querySpec() *sqlgraph.QuerySpec {
func (aq *AttachmentQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(aq.driver.Dialect())
t1 := builder.Table(attachment.Table)
columns := aq.fields
columns := aq.ctx.Fields
if len(columns) == 0 {
columns = attachment.Columns
}
@@ -578,7 +584,7 @@ func (aq *AttachmentQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = aq.sql
selector.Select(selector.Columns(columns...)...)
}
if aq.unique != nil && *aq.unique {
if aq.ctx.Unique != nil && *aq.ctx.Unique {
selector.Distinct()
}
for _, p := range aq.predicates {
@@ -587,12 +593,12 @@ func (aq *AttachmentQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range aq.order {
p(selector)
}
if offset := aq.offset; offset != nil {
if offset := aq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := aq.limit; limit != nil {
if limit := aq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -600,13 +606,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 +616,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 = setContextOp(ctx, agb.build.ctx, "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 +666,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 = setContextOp(ctx, as.ctx, "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
}

View File

@@ -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
}

View File

@@ -99,14 +99,14 @@ func (ar *AuthRoles) assignValues(columns []string, values []any) error {
// QueryToken queries the "token" edge of the AuthRoles entity.
func (ar *AuthRoles) QueryToken() *AuthTokensQuery {
return (&AuthRolesClient{config: ar.config}).QueryToken(ar)
return NewAuthRolesClient(ar.config).QueryToken(ar)
}
// Update returns a builder for updating this AuthRoles.
// Note that you need to call AuthRoles.Unwrap() before calling this method if this AuthRoles
// was returned from a transaction, and the transaction was committed or rolled back.
func (ar *AuthRoles) Update() *AuthRolesUpdateOne {
return (&AuthRolesClient{config: ar.config}).UpdateOne(ar)
return NewAuthRolesClient(ar.config).UpdateOne(ar)
}
// Unwrap unwraps the AuthRoles entity that was returned from a transaction after it was closed,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type AuthRolesDeleteOne struct {
ard *AuthRolesDelete
}
// Where appends a list predicates to the AuthRolesDelete builder.
func (ardo *AuthRolesDeleteOne) Where(ps ...predicate.AuthRoles) *AuthRolesDeleteOne {
ardo.ard.mutation.Where(ps...)
return ardo
}
// Exec executes the deletion query.
func (ardo *AuthRolesDeleteOne) Exec(ctx context.Context) error {
n, err := ardo.ard.Exec(ctx)
@@ -111,5 +90,7 @@ func (ardo *AuthRolesDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (ardo *AuthRolesDeleteOne) ExecX(ctx context.Context) {
ardo.ard.ExecX(ctx)
if err := ardo.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -19,11 +19,9 @@ import (
// AuthRolesQuery is the builder for querying AuthRoles entities.
type AuthRolesQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.AuthRoles
withToken *AuthTokensQuery
withFKs bool
@@ -38,26 +36,26 @@ 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
arq.ctx.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
arq.ctx.Offset = &offset
return arq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (arq *AuthRolesQuery) Unique(unique bool) *AuthRolesQuery {
arq.unique = &unique
arq.ctx.Unique = &unique
return arq
}
// 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 +63,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 +86,7 @@ func (arq *AuthRolesQuery) QueryToken() *AuthTokensQuery {
// First returns the first AuthRoles entity from the query.
// Returns a *NotFoundError when no AuthRoles was found.
func (arq *AuthRolesQuery) First(ctx context.Context) (*AuthRoles, error) {
nodes, err := arq.Limit(1).All(ctx)
nodes, err := arq.Limit(1).All(setContextOp(ctx, arq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -111,7 +109,7 @@ func (arq *AuthRolesQuery) FirstX(ctx context.Context) *AuthRoles {
// Returns a *NotFoundError when no AuthRoles ID was found.
func (arq *AuthRolesQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = arq.Limit(1).IDs(ctx); err != nil {
if ids, err = arq.Limit(1).IDs(setContextOp(ctx, arq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -134,7 +132,7 @@ func (arq *AuthRolesQuery) FirstIDX(ctx context.Context) int {
// Returns a *NotSingularError when more than one AuthRoles entity is found.
// Returns a *NotFoundError when no AuthRoles entities are found.
func (arq *AuthRolesQuery) Only(ctx context.Context) (*AuthRoles, error) {
nodes, err := arq.Limit(2).All(ctx)
nodes, err := arq.Limit(2).All(setContextOp(ctx, arq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -162,7 +160,7 @@ func (arq *AuthRolesQuery) OnlyX(ctx context.Context) *AuthRoles {
// Returns a *NotFoundError when no entities are found.
func (arq *AuthRolesQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = arq.Limit(2).IDs(ctx); err != nil {
if ids, err = arq.Limit(2).IDs(setContextOp(ctx, arq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -187,10 +185,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 = setContextOp(ctx, arq.ctx, "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 +205,7 @@ func (arq *AuthRolesQuery) AllX(ctx context.Context) []*AuthRoles {
// IDs executes the query and returns a list of AuthRoles IDs.
func (arq *AuthRolesQuery) IDs(ctx context.Context) ([]int, error) {
var ids []int
ctx = setContextOp(ctx, arq.ctx, "IDs")
if err := arq.Select(authroles.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -222,10 +223,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 = setContextOp(ctx, arq.ctx, "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 +241,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 = setContextOp(ctx, arq.ctx, "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.
@@ -262,22 +269,21 @@ func (arq *AuthRolesQuery) Clone() *AuthRolesQuery {
}
return &AuthRolesQuery{
config: arq.config,
limit: arq.limit,
offset: arq.offset,
ctx: arq.ctx.Clone(),
order: append([]OrderFunc{}, arq.order...),
inters: append([]Interceptor{}, arq.inters...),
predicates: append([]predicate.AuthRoles{}, arq.predicates...),
withToken: arq.withToken.Clone(),
// clone intermediate query.
sql: arq.sql.Clone(),
path: arq.path,
unique: arq.unique,
sql: arq.sql.Clone(),
path: arq.path,
}
}
// 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 +306,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &AuthRolesGroupBy{build: arq}
grbuild.flds = &arq.ctx.Fields
grbuild.label = authroles.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -326,11 +327,11 @@ func (arq *AuthRolesQuery) GroupBy(field string, fields ...string) *AuthRolesGro
// Select(authroles.FieldRole).
// Scan(ctx, &v)
func (arq *AuthRolesQuery) Select(fields ...string) *AuthRolesSelect {
arq.fields = append(arq.fields, fields...)
selbuild := &AuthRolesSelect{AuthRolesQuery: arq}
selbuild.label = authroles.Label
selbuild.flds, selbuild.scan = &arq.fields, selbuild.Scan
return selbuild
arq.ctx.Fields = append(arq.ctx.Fields, fields...)
sbuild := &AuthRolesSelect{AuthRolesQuery: arq}
sbuild.label = authroles.Label
sbuild.flds, sbuild.scan = &arq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a AuthRolesSelect configured with the given aggregations.
@@ -339,7 +340,17 @@ func (arq *AuthRolesQuery) Aggregate(fns ...AggregateFunc) *AuthRolesSelect {
}
func (arq *AuthRolesQuery) prepareQuery(ctx context.Context) error {
for _, f := range arq.fields {
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.ctx.Fields {
if !authroles.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -409,6 +420,9 @@ func (arq *AuthRolesQuery) loadToken(ctx context.Context, query *AuthTokensQuery
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(authtokens.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -428,24 +442,13 @@ func (arq *AuthRolesQuery) loadToken(ctx context.Context, query *AuthTokensQuery
func (arq *AuthRolesQuery) sqlCount(ctx context.Context) (int, error) {
_spec := arq.querySpec()
_spec.Node.Columns = arq.fields
if len(arq.fields) > 0 {
_spec.Unique = arq.unique != nil && *arq.unique
_spec.Node.Columns = arq.ctx.Fields
if len(arq.ctx.Fields) > 0 {
_spec.Unique = arq.ctx.Unique != nil && *arq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, arq.driver, _spec)
}
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{
@@ -459,10 +462,10 @@ func (arq *AuthRolesQuery) querySpec() *sqlgraph.QuerySpec {
From: arq.sql,
Unique: true,
}
if unique := arq.unique; unique != nil {
if unique := arq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := arq.fields; len(fields) > 0 {
if fields := arq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, authroles.FieldID)
for i := range fields {
@@ -478,10 +481,10 @@ func (arq *AuthRolesQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := arq.limit; limit != nil {
if limit := arq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := arq.offset; offset != nil {
if offset := arq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := arq.order; len(ps) > 0 {
@@ -497,7 +500,7 @@ func (arq *AuthRolesQuery) querySpec() *sqlgraph.QuerySpec {
func (arq *AuthRolesQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(arq.driver.Dialect())
t1 := builder.Table(authroles.Table)
columns := arq.fields
columns := arq.ctx.Fields
if len(columns) == 0 {
columns = authroles.Columns
}
@@ -506,7 +509,7 @@ func (arq *AuthRolesQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = arq.sql
selector.Select(selector.Columns(columns...)...)
}
if arq.unique != nil && *arq.unique {
if arq.ctx.Unique != nil && *arq.ctx.Unique {
selector.Distinct()
}
for _, p := range arq.predicates {
@@ -515,12 +518,12 @@ func (arq *AuthRolesQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range arq.order {
p(selector)
}
if offset := arq.offset; offset != nil {
if offset := arq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := arq.limit; limit != nil {
if limit := arq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -528,13 +531,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 +541,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 = setContextOp(ctx, argb.build.ctx, "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 +591,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 = setContextOp(ctx, ars.ctx, "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
}

View File

@@ -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
}

View File

@@ -142,19 +142,19 @@ func (at *AuthTokens) assignValues(columns []string, values []any) error {
// QueryUser queries the "user" edge of the AuthTokens entity.
func (at *AuthTokens) QueryUser() *UserQuery {
return (&AuthTokensClient{config: at.config}).QueryUser(at)
return NewAuthTokensClient(at.config).QueryUser(at)
}
// QueryRoles queries the "roles" edge of the AuthTokens entity.
func (at *AuthTokens) QueryRoles() *AuthRolesQuery {
return (&AuthTokensClient{config: at.config}).QueryRoles(at)
return NewAuthTokensClient(at.config).QueryRoles(at)
}
// Update returns a builder for updating this AuthTokens.
// Note that you need to call AuthTokens.Unwrap() before calling this method if this AuthTokens
// was returned from a transaction, and the transaction was committed or rolled back.
func (at *AuthTokens) Update() *AuthTokensUpdateOne {
return (&AuthTokensClient{config: at.config}).UpdateOne(at)
return NewAuthTokensClient(at.config).UpdateOne(at)
}
// Unwrap unwraps the AuthTokens entity that was returned from a transaction after it was closed,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type AuthTokensDeleteOne struct {
atd *AuthTokensDelete
}
// Where appends a list predicates to the AuthTokensDelete builder.
func (atdo *AuthTokensDeleteOne) Where(ps ...predicate.AuthTokens) *AuthTokensDeleteOne {
atdo.atd.mutation.Where(ps...)
return atdo
}
// Exec executes the deletion query.
func (atdo *AuthTokensDeleteOne) Exec(ctx context.Context) error {
n, err := atdo.atd.Exec(ctx)
@@ -111,5 +90,7 @@ func (atdo *AuthTokensDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (atdo *AuthTokensDeleteOne) ExecX(ctx context.Context) {
atdo.atd.ExecX(ctx)
if err := atdo.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -21,11 +21,9 @@ import (
// AuthTokensQuery is the builder for querying AuthTokens entities.
type AuthTokensQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.AuthTokens
withUser *UserQuery
withRoles *AuthRolesQuery
@@ -41,26 +39,26 @@ 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
atq.ctx.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
atq.ctx.Offset = &offset
return atq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (atq *AuthTokensQuery) Unique(unique bool) *AuthTokensQuery {
atq.unique = &unique
atq.ctx.Unique = &unique
return atq
}
// 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 +66,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 +88,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 +111,7 @@ func (atq *AuthTokensQuery) QueryRoles() *AuthRolesQuery {
// First returns the first AuthTokens entity from the query.
// Returns a *NotFoundError when no AuthTokens was found.
func (atq *AuthTokensQuery) First(ctx context.Context) (*AuthTokens, error) {
nodes, err := atq.Limit(1).All(ctx)
nodes, err := atq.Limit(1).All(setContextOp(ctx, atq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -136,7 +134,7 @@ func (atq *AuthTokensQuery) FirstX(ctx context.Context) *AuthTokens {
// Returns a *NotFoundError when no AuthTokens ID was found.
func (atq *AuthTokensQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = atq.Limit(1).IDs(ctx); err != nil {
if ids, err = atq.Limit(1).IDs(setContextOp(ctx, atq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -159,7 +157,7 @@ func (atq *AuthTokensQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one AuthTokens entity is found.
// Returns a *NotFoundError when no AuthTokens entities are found.
func (atq *AuthTokensQuery) Only(ctx context.Context) (*AuthTokens, error) {
nodes, err := atq.Limit(2).All(ctx)
nodes, err := atq.Limit(2).All(setContextOp(ctx, atq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -187,7 +185,7 @@ func (atq *AuthTokensQuery) OnlyX(ctx context.Context) *AuthTokens {
// Returns a *NotFoundError when no entities are found.
func (atq *AuthTokensQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = atq.Limit(2).IDs(ctx); err != nil {
if ids, err = atq.Limit(2).IDs(setContextOp(ctx, atq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -212,10 +210,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 = setContextOp(ctx, atq.ctx, "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 +230,7 @@ func (atq *AuthTokensQuery) AllX(ctx context.Context) []*AuthTokens {
// IDs executes the query and returns a list of AuthTokens IDs.
func (atq *AuthTokensQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = setContextOp(ctx, atq.ctx, "IDs")
if err := atq.Select(authtokens.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -247,10 +248,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 = setContextOp(ctx, atq.ctx, "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 +266,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 = setContextOp(ctx, atq.ctx, "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.
@@ -287,23 +294,22 @@ func (atq *AuthTokensQuery) Clone() *AuthTokensQuery {
}
return &AuthTokensQuery{
config: atq.config,
limit: atq.limit,
offset: atq.offset,
ctx: atq.ctx.Clone(),
order: append([]OrderFunc{}, atq.order...),
inters: append([]Interceptor{}, atq.inters...),
predicates: append([]predicate.AuthTokens{}, atq.predicates...),
withUser: atq.withUser.Clone(),
withRoles: atq.withRoles.Clone(),
// clone intermediate query.
sql: atq.sql.Clone(),
path: atq.path,
unique: atq.unique,
sql: atq.sql.Clone(),
path: atq.path,
}
}
// 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 +320,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 +343,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &AuthTokensGroupBy{build: atq}
grbuild.flds = &atq.ctx.Fields
grbuild.label = authtokens.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -363,11 +364,11 @@ func (atq *AuthTokensQuery) GroupBy(field string, fields ...string) *AuthTokensG
// Select(authtokens.FieldCreatedAt).
// Scan(ctx, &v)
func (atq *AuthTokensQuery) Select(fields ...string) *AuthTokensSelect {
atq.fields = append(atq.fields, fields...)
selbuild := &AuthTokensSelect{AuthTokensQuery: atq}
selbuild.label = authtokens.Label
selbuild.flds, selbuild.scan = &atq.fields, selbuild.Scan
return selbuild
atq.ctx.Fields = append(atq.ctx.Fields, fields...)
sbuild := &AuthTokensSelect{AuthTokensQuery: atq}
sbuild.label = authtokens.Label
sbuild.flds, sbuild.scan = &atq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a AuthTokensSelect configured with the given aggregations.
@@ -376,7 +377,17 @@ func (atq *AuthTokensQuery) Aggregate(fns ...AggregateFunc) *AuthTokensSelect {
}
func (atq *AuthTokensQuery) prepareQuery(ctx context.Context) error {
for _, f := range atq.fields {
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.ctx.Fields {
if !authtokens.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -453,6 +464,9 @@ func (atq *AuthTokensQuery) loadUser(ctx context.Context, query *UserQuery, node
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(user.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -500,24 +514,13 @@ func (atq *AuthTokensQuery) loadRoles(ctx context.Context, query *AuthRolesQuery
func (atq *AuthTokensQuery) sqlCount(ctx context.Context) (int, error) {
_spec := atq.querySpec()
_spec.Node.Columns = atq.fields
if len(atq.fields) > 0 {
_spec.Unique = atq.unique != nil && *atq.unique
_spec.Node.Columns = atq.ctx.Fields
if len(atq.ctx.Fields) > 0 {
_spec.Unique = atq.ctx.Unique != nil && *atq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, atq.driver, _spec)
}
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{
@@ -531,10 +534,10 @@ func (atq *AuthTokensQuery) querySpec() *sqlgraph.QuerySpec {
From: atq.sql,
Unique: true,
}
if unique := atq.unique; unique != nil {
if unique := atq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := atq.fields; len(fields) > 0 {
if fields := atq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, authtokens.FieldID)
for i := range fields {
@@ -550,10 +553,10 @@ func (atq *AuthTokensQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := atq.limit; limit != nil {
if limit := atq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := atq.offset; offset != nil {
if offset := atq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := atq.order; len(ps) > 0 {
@@ -569,7 +572,7 @@ func (atq *AuthTokensQuery) querySpec() *sqlgraph.QuerySpec {
func (atq *AuthTokensQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(atq.driver.Dialect())
t1 := builder.Table(authtokens.Table)
columns := atq.fields
columns := atq.ctx.Fields
if len(columns) == 0 {
columns = authtokens.Columns
}
@@ -578,7 +581,7 @@ func (atq *AuthTokensQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = atq.sql
selector.Select(selector.Columns(columns...)...)
}
if atq.unique != nil && *atq.unique {
if atq.ctx.Unique != nil && *atq.ctx.Unique {
selector.Distinct()
}
for _, p := range atq.predicates {
@@ -587,12 +590,12 @@ func (atq *AuthTokensQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range atq.order {
p(selector)
}
if offset := atq.offset; offset != nil {
if offset := atq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := atq.limit; limit != nil {
if limit := atq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -600,13 +603,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 +613,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 = setContextOp(ctx, atgb.build.ctx, "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 +663,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 = setContextOp(ctx, ats.ctx, "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
}

View File

@@ -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
}

View File

@@ -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,8 @@ func (c *AttachmentClient) DeleteOneID(id uuid.UUID) *AttachmentDeleteOne {
func (c *AttachmentClient) Query() *AttachmentQuery {
return &AttachmentQuery{
config: c.config,
ctx: &QueryContext{Type: TypeAttachment},
inters: c.Interceptors(),
}
}
@@ -288,7 +345,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 +361,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 +380,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 +416,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 +474,8 @@ func (c *AuthRolesClient) DeleteOneID(id int) *AuthRolesDeleteOne {
func (c *AuthRolesClient) Query() *AuthRolesQuery {
return &AuthRolesQuery{
config: c.config,
ctx: &QueryContext{Type: TypeAuthRoles},
inters: c.Interceptors(),
}
}
@@ -410,7 +495,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 +514,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 +550,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 +608,8 @@ func (c *AuthTokensClient) DeleteOneID(id uuid.UUID) *AuthTokensDeleteOne {
func (c *AuthTokensClient) Query() *AuthTokensQuery {
return &AuthTokensQuery{
config: c.config,
ctx: &QueryContext{Type: TypeAuthTokens},
inters: c.Interceptors(),
}
}
@@ -516,7 +629,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 +645,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 +664,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 +700,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 +758,8 @@ func (c *DocumentClient) DeleteOneID(id uuid.UUID) *DocumentDeleteOne {
func (c *DocumentClient) Query() *DocumentQuery {
return &DocumentQuery{
config: c.config,
ctx: &QueryContext{Type: TypeDocument},
inters: c.Interceptors(),
}
}
@@ -638,7 +779,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 +795,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 +814,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 +850,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 +908,8 @@ func (c *GroupClient) DeleteOneID(id uuid.UUID) *GroupDeleteOne {
func (c *GroupClient) Query() *GroupQuery {
return &GroupQuery{
config: c.config,
ctx: &QueryContext{Type: TypeGroup},
inters: c.Interceptors(),
}
}
@@ -760,7 +929,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 +945,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 +961,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 +977,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 +993,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 +1009,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 +1028,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 +1064,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 +1122,8 @@ func (c *GroupInvitationTokenClient) DeleteOneID(id uuid.UUID) *GroupInvitationT
func (c *GroupInvitationTokenClient) Query() *GroupInvitationTokenQuery {
return &GroupInvitationTokenQuery{
config: c.config,
ctx: &QueryContext{Type: TypeGroupInvitationToken},
inters: c.Interceptors(),
}
}
@@ -946,7 +1143,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 +1162,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 +1198,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 +1256,8 @@ func (c *ItemClient) DeleteOneID(id uuid.UUID) *ItemDeleteOne {
func (c *ItemClient) Query() *ItemQuery {
return &ItemQuery{
config: c.config,
ctx: &QueryContext{Type: TypeItem},
inters: c.Interceptors(),
}
}
@@ -1052,7 +1277,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 +1293,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 +1309,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 +1325,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 +1341,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 +1357,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 +1373,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 +1389,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 +1408,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 +1444,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 +1502,8 @@ func (c *ItemFieldClient) DeleteOneID(id uuid.UUID) *ItemFieldDeleteOne {
func (c *ItemFieldClient) Query() *ItemFieldQuery {
return &ItemFieldQuery{
config: c.config,
ctx: &QueryContext{Type: TypeItemField},
inters: c.Interceptors(),
}
}
@@ -1270,7 +1523,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 +1542,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 +1578,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 +1636,8 @@ func (c *LabelClient) DeleteOneID(id uuid.UUID) *LabelDeleteOne {
func (c *LabelClient) Query() *LabelQuery {
return &LabelQuery{
config: c.config,
ctx: &QueryContext{Type: TypeLabel},
inters: c.Interceptors(),
}
}
@@ -1376,7 +1657,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 +1673,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 +1692,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 +1728,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 +1786,8 @@ func (c *LocationClient) DeleteOneID(id uuid.UUID) *LocationDeleteOne {
func (c *LocationClient) Query() *LocationQuery {
return &LocationQuery{
config: c.config,
ctx: &QueryContext{Type: TypeLocation},
inters: c.Interceptors(),
}
}
@@ -1498,7 +1807,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 +1823,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 +1839,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 +1855,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 +1874,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 +1910,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 +1968,8 @@ func (c *MaintenanceEntryClient) DeleteOneID(id uuid.UUID) *MaintenanceEntryDele
func (c *MaintenanceEntryClient) Query() *MaintenanceEntryQuery {
return &MaintenanceEntryQuery{
config: c.config,
ctx: &QueryContext{Type: TypeMaintenanceEntry},
inters: c.Interceptors(),
}
}
@@ -1652,7 +1989,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 +2008,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 +2044,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 +2102,8 @@ func (c *UserClient) DeleteOneID(id uuid.UUID) *UserDeleteOne {
func (c *UserClient) Query() *UserQuery {
return &UserQuery{
config: c.config,
ctx: &QueryContext{Type: TypeUser},
inters: c.Interceptors(),
}
}
@@ -1758,7 +2123,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 +2139,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 +2157,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())
}
}

View File

@@ -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) {

View File

@@ -137,19 +137,19 @@ func (d *Document) assignValues(columns []string, values []any) error {
// QueryGroup queries the "group" edge of the Document entity.
func (d *Document) QueryGroup() *GroupQuery {
return (&DocumentClient{config: d.config}).QueryGroup(d)
return NewDocumentClient(d.config).QueryGroup(d)
}
// QueryAttachments queries the "attachments" edge of the Document entity.
func (d *Document) QueryAttachments() *AttachmentQuery {
return (&DocumentClient{config: d.config}).QueryAttachments(d)
return NewDocumentClient(d.config).QueryAttachments(d)
}
// Update returns a builder for updating this Document.
// Note that you need to call Document.Unwrap() before calling this method if this Document
// was returned from a transaction, and the transaction was committed or rolled back.
func (d *Document) Update() *DocumentUpdateOne {
return (&DocumentClient{config: d.config}).UpdateOne(d)
return NewDocumentClient(d.config).UpdateOne(d)
}
// Unwrap unwraps the Document entity that was returned from a transaction after it was closed,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type DocumentDeleteOne struct {
dd *DocumentDelete
}
// Where appends a list predicates to the DocumentDelete builder.
func (ddo *DocumentDeleteOne) Where(ps ...predicate.Document) *DocumentDeleteOne {
ddo.dd.mutation.Where(ps...)
return ddo
}
// Exec executes the deletion query.
func (ddo *DocumentDeleteOne) Exec(ctx context.Context) error {
n, err := ddo.dd.Exec(ctx)
@@ -111,5 +90,7 @@ func (ddo *DocumentDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (ddo *DocumentDeleteOne) ExecX(ctx context.Context) {
ddo.dd.ExecX(ctx)
if err := ddo.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -21,11 +21,9 @@ import (
// DocumentQuery is the builder for querying Document entities.
type DocumentQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.Document
withGroup *GroupQuery
withAttachments *AttachmentQuery
@@ -41,26 +39,26 @@ 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
dq.ctx.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
dq.ctx.Offset = &offset
return dq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (dq *DocumentQuery) Unique(unique bool) *DocumentQuery {
dq.unique = &unique
dq.ctx.Unique = &unique
return dq
}
// 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 +66,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 +88,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 +111,7 @@ func (dq *DocumentQuery) QueryAttachments() *AttachmentQuery {
// First returns the first Document entity from the query.
// Returns a *NotFoundError when no Document was found.
func (dq *DocumentQuery) First(ctx context.Context) (*Document, error) {
nodes, err := dq.Limit(1).All(ctx)
nodes, err := dq.Limit(1).All(setContextOp(ctx, dq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -136,7 +134,7 @@ func (dq *DocumentQuery) FirstX(ctx context.Context) *Document {
// Returns a *NotFoundError when no Document ID was found.
func (dq *DocumentQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = dq.Limit(1).IDs(ctx); err != nil {
if ids, err = dq.Limit(1).IDs(setContextOp(ctx, dq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -159,7 +157,7 @@ func (dq *DocumentQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one Document entity is found.
// Returns a *NotFoundError when no Document entities are found.
func (dq *DocumentQuery) Only(ctx context.Context) (*Document, error) {
nodes, err := dq.Limit(2).All(ctx)
nodes, err := dq.Limit(2).All(setContextOp(ctx, dq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -187,7 +185,7 @@ func (dq *DocumentQuery) OnlyX(ctx context.Context) *Document {
// Returns a *NotFoundError when no entities are found.
func (dq *DocumentQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = dq.Limit(2).IDs(ctx); err != nil {
if ids, err = dq.Limit(2).IDs(setContextOp(ctx, dq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -212,10 +210,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 = setContextOp(ctx, dq.ctx, "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 +230,7 @@ func (dq *DocumentQuery) AllX(ctx context.Context) []*Document {
// IDs executes the query and returns a list of Document IDs.
func (dq *DocumentQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = setContextOp(ctx, dq.ctx, "IDs")
if err := dq.Select(document.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -247,10 +248,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 = setContextOp(ctx, dq.ctx, "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 +266,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 = setContextOp(ctx, dq.ctx, "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.
@@ -287,23 +294,22 @@ func (dq *DocumentQuery) Clone() *DocumentQuery {
}
return &DocumentQuery{
config: dq.config,
limit: dq.limit,
offset: dq.offset,
ctx: dq.ctx.Clone(),
order: append([]OrderFunc{}, dq.order...),
inters: append([]Interceptor{}, dq.inters...),
predicates: append([]predicate.Document{}, dq.predicates...),
withGroup: dq.withGroup.Clone(),
withAttachments: dq.withAttachments.Clone(),
// clone intermediate query.
sql: dq.sql.Clone(),
path: dq.path,
unique: dq.unique,
sql: dq.sql.Clone(),
path: dq.path,
}
}
// 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 +320,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 +343,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &DocumentGroupBy{build: dq}
grbuild.flds = &dq.ctx.Fields
grbuild.label = document.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -363,11 +364,11 @@ func (dq *DocumentQuery) GroupBy(field string, fields ...string) *DocumentGroupB
// Select(document.FieldCreatedAt).
// Scan(ctx, &v)
func (dq *DocumentQuery) Select(fields ...string) *DocumentSelect {
dq.fields = append(dq.fields, fields...)
selbuild := &DocumentSelect{DocumentQuery: dq}
selbuild.label = document.Label
selbuild.flds, selbuild.scan = &dq.fields, selbuild.Scan
return selbuild
dq.ctx.Fields = append(dq.ctx.Fields, fields...)
sbuild := &DocumentSelect{DocumentQuery: dq}
sbuild.label = document.Label
sbuild.flds, sbuild.scan = &dq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a DocumentSelect configured with the given aggregations.
@@ -376,7 +377,17 @@ func (dq *DocumentQuery) Aggregate(fns ...AggregateFunc) *DocumentSelect {
}
func (dq *DocumentQuery) prepareQuery(ctx context.Context) error {
for _, f := range dq.fields {
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.ctx.Fields {
if !document.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -454,6 +465,9 @@ func (dq *DocumentQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(group.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -504,24 +518,13 @@ func (dq *DocumentQuery) loadAttachments(ctx context.Context, query *AttachmentQ
func (dq *DocumentQuery) sqlCount(ctx context.Context) (int, error) {
_spec := dq.querySpec()
_spec.Node.Columns = dq.fields
if len(dq.fields) > 0 {
_spec.Unique = dq.unique != nil && *dq.unique
_spec.Node.Columns = dq.ctx.Fields
if len(dq.ctx.Fields) > 0 {
_spec.Unique = dq.ctx.Unique != nil && *dq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, dq.driver, _spec)
}
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{
@@ -535,10 +538,10 @@ func (dq *DocumentQuery) querySpec() *sqlgraph.QuerySpec {
From: dq.sql,
Unique: true,
}
if unique := dq.unique; unique != nil {
if unique := dq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := dq.fields; len(fields) > 0 {
if fields := dq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, document.FieldID)
for i := range fields {
@@ -554,10 +557,10 @@ func (dq *DocumentQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := dq.limit; limit != nil {
if limit := dq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := dq.offset; offset != nil {
if offset := dq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := dq.order; len(ps) > 0 {
@@ -573,7 +576,7 @@ func (dq *DocumentQuery) querySpec() *sqlgraph.QuerySpec {
func (dq *DocumentQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(dq.driver.Dialect())
t1 := builder.Table(document.Table)
columns := dq.fields
columns := dq.ctx.Fields
if len(columns) == 0 {
columns = document.Columns
}
@@ -582,7 +585,7 @@ func (dq *DocumentQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = dq.sql
selector.Select(selector.Columns(columns...)...)
}
if dq.unique != nil && *dq.unique {
if dq.ctx.Unique != nil && *dq.ctx.Unique {
selector.Distinct()
}
for _, p := range dq.predicates {
@@ -591,12 +594,12 @@ func (dq *DocumentQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range dq.order {
p(selector)
}
if offset := dq.offset; offset != nil {
if offset := dq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := dq.limit; limit != nil {
if limit := dq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -604,13 +607,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 +617,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 = setContextOp(ctx, dgb.build.ctx, "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 +667,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 = setContextOp(ctx, ds.ctx, "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
}

View File

@@ -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
}

View File

@@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"reflect"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
@@ -26,14 +27,21 @@ 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
QueryContext = ent.QueryContext
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 +492,121 @@ 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
}
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
if ent.QueryFromContext(ctx) == nil {
qc.Op = op
ctx = ent.NewQueryContext(ctx, qc)
}
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)

View File

@@ -166,39 +166,39 @@ func (gr *Group) assignValues(columns []string, values []any) error {
// QueryUsers queries the "users" edge of the Group entity.
func (gr *Group) QueryUsers() *UserQuery {
return (&GroupClient{config: gr.config}).QueryUsers(gr)
return NewGroupClient(gr.config).QueryUsers(gr)
}
// QueryLocations queries the "locations" edge of the Group entity.
func (gr *Group) QueryLocations() *LocationQuery {
return (&GroupClient{config: gr.config}).QueryLocations(gr)
return NewGroupClient(gr.config).QueryLocations(gr)
}
// QueryItems queries the "items" edge of the Group entity.
func (gr *Group) QueryItems() *ItemQuery {
return (&GroupClient{config: gr.config}).QueryItems(gr)
return NewGroupClient(gr.config).QueryItems(gr)
}
// QueryLabels queries the "labels" edge of the Group entity.
func (gr *Group) QueryLabels() *LabelQuery {
return (&GroupClient{config: gr.config}).QueryLabels(gr)
return NewGroupClient(gr.config).QueryLabels(gr)
}
// QueryDocuments queries the "documents" edge of the Group entity.
func (gr *Group) QueryDocuments() *DocumentQuery {
return (&GroupClient{config: gr.config}).QueryDocuments(gr)
return NewGroupClient(gr.config).QueryDocuments(gr)
}
// QueryInvitationTokens queries the "invitation_tokens" edge of the Group entity.
func (gr *Group) QueryInvitationTokens() *GroupInvitationTokenQuery {
return (&GroupClient{config: gr.config}).QueryInvitationTokens(gr)
return NewGroupClient(gr.config).QueryInvitationTokens(gr)
}
// Update returns a builder for updating this Group.
// Note that you need to call Group.Unwrap() before calling this method if this Group
// was returned from a transaction, and the transaction was committed or rolled back.
func (gr *Group) Update() *GroupUpdateOne {
return (&GroupClient{config: gr.config}).UpdateOne(gr)
return NewGroupClient(gr.config).UpdateOne(gr)
}
// Unwrap unwraps the Group entity that was returned from a transaction after it was closed,

View File

@@ -131,6 +131,7 @@ const (
CurrencyDkk Currency = "dkk"
CurrencyInr Currency = "inr"
CurrencyRmb Currency = "rmb"
CurrencyBgn Currency = "bgn"
)
func (c Currency) String() string {
@@ -140,7 +141,7 @@ func (c Currency) String() string {
// CurrencyValidator is a validator for the "currency" field enum values. It is called by the builders before save.
func CurrencyValidator(c Currency) error {
switch c {
case CurrencyUsd, CurrencyEur, CurrencyGbp, CurrencyJpy, CurrencyZar, CurrencyAud, CurrencyNok, CurrencySek, CurrencyDkk, CurrencyInr, CurrencyRmb:
case CurrencyUsd, CurrencyEur, CurrencyGbp, CurrencyJpy, CurrencyZar, CurrencyAud, CurrencyNok, CurrencySek, CurrencyDkk, CurrencyInr, CurrencyRmb, CurrencyBgn:
return nil
default:
return fmt.Errorf("group: invalid enum value for currency field: %q", c)

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type GroupDeleteOne struct {
gd *GroupDelete
}
// Where appends a list predicates to the GroupDelete builder.
func (gdo *GroupDeleteOne) Where(ps ...predicate.Group) *GroupDeleteOne {
gdo.gd.mutation.Where(ps...)
return gdo
}
// Exec executes the deletion query.
func (gdo *GroupDeleteOne) Exec(ctx context.Context) error {
n, err := gdo.gd.Exec(ctx)
@@ -111,5 +90,7 @@ func (gdo *GroupDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (gdo *GroupDeleteOne) ExecX(ctx context.Context) {
gdo.gd.ExecX(ctx)
if err := gdo.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -25,11 +25,9 @@ import (
// GroupQuery is the builder for querying Group entities.
type GroupQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.Group
withUsers *UserQuery
withLocations *LocationQuery
@@ -48,26 +46,26 @@ 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
gq.ctx.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
gq.ctx.Offset = &offset
return gq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (gq *GroupQuery) Unique(unique bool) *GroupQuery {
gq.unique = &unique
gq.ctx.Unique = &unique
return gq
}
// 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 +73,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 +95,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 +117,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 +139,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 +161,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 +183,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 +206,7 @@ func (gq *GroupQuery) QueryInvitationTokens() *GroupInvitationTokenQuery {
// First returns the first Group entity from the query.
// Returns a *NotFoundError when no Group was found.
func (gq *GroupQuery) First(ctx context.Context) (*Group, error) {
nodes, err := gq.Limit(1).All(ctx)
nodes, err := gq.Limit(1).All(setContextOp(ctx, gq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -231,7 +229,7 @@ func (gq *GroupQuery) FirstX(ctx context.Context) *Group {
// Returns a *NotFoundError when no Group ID was found.
func (gq *GroupQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = gq.Limit(1).IDs(ctx); err != nil {
if ids, err = gq.Limit(1).IDs(setContextOp(ctx, gq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -254,7 +252,7 @@ func (gq *GroupQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one Group entity is found.
// Returns a *NotFoundError when no Group entities are found.
func (gq *GroupQuery) Only(ctx context.Context) (*Group, error) {
nodes, err := gq.Limit(2).All(ctx)
nodes, err := gq.Limit(2).All(setContextOp(ctx, gq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -282,7 +280,7 @@ func (gq *GroupQuery) OnlyX(ctx context.Context) *Group {
// Returns a *NotFoundError when no entities are found.
func (gq *GroupQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = gq.Limit(2).IDs(ctx); err != nil {
if ids, err = gq.Limit(2).IDs(setContextOp(ctx, gq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -307,10 +305,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 = setContextOp(ctx, gq.ctx, "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 +325,7 @@ func (gq *GroupQuery) AllX(ctx context.Context) []*Group {
// IDs executes the query and returns a list of Group IDs.
func (gq *GroupQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = setContextOp(ctx, gq.ctx, "IDs")
if err := gq.Select(group.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -342,10 +343,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 = setContextOp(ctx, gq.ctx, "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 +361,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 = setContextOp(ctx, gq.ctx, "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.
@@ -382,9 +389,9 @@ func (gq *GroupQuery) Clone() *GroupQuery {
}
return &GroupQuery{
config: gq.config,
limit: gq.limit,
offset: gq.offset,
ctx: gq.ctx.Clone(),
order: append([]OrderFunc{}, gq.order...),
inters: append([]Interceptor{}, gq.inters...),
predicates: append([]predicate.Group{}, gq.predicates...),
withUsers: gq.withUsers.Clone(),
withLocations: gq.withLocations.Clone(),
@@ -393,16 +400,15 @@ func (gq *GroupQuery) Clone() *GroupQuery {
withDocuments: gq.withDocuments.Clone(),
withInvitationTokens: gq.withInvitationTokens.Clone(),
// clone intermediate query.
sql: gq.sql.Clone(),
path: gq.path,
unique: gq.unique,
sql: gq.sql.Clone(),
path: gq.path,
}
}
// 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 +419,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 +430,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 +441,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 +452,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 +463,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 +486,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &GroupGroupBy{build: gq}
grbuild.flds = &gq.ctx.Fields
grbuild.label = group.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -506,11 +507,11 @@ func (gq *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy {
// Select(group.FieldCreatedAt).
// Scan(ctx, &v)
func (gq *GroupQuery) Select(fields ...string) *GroupSelect {
gq.fields = append(gq.fields, fields...)
selbuild := &GroupSelect{GroupQuery: gq}
selbuild.label = group.Label
selbuild.flds, selbuild.scan = &gq.fields, selbuild.Scan
return selbuild
gq.ctx.Fields = append(gq.ctx.Fields, fields...)
sbuild := &GroupSelect{GroupQuery: gq}
sbuild.label = group.Label
sbuild.flds, sbuild.scan = &gq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a GroupSelect configured with the given aggregations.
@@ -519,7 +520,17 @@ func (gq *GroupQuery) Aggregate(fns ...AggregateFunc) *GroupSelect {
}
func (gq *GroupQuery) prepareQuery(ctx context.Context) error {
for _, f := range gq.fields {
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.ctx.Fields {
if !group.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -801,24 +812,13 @@ func (gq *GroupQuery) loadInvitationTokens(ctx context.Context, query *GroupInvi
func (gq *GroupQuery) sqlCount(ctx context.Context) (int, error) {
_spec := gq.querySpec()
_spec.Node.Columns = gq.fields
if len(gq.fields) > 0 {
_spec.Unique = gq.unique != nil && *gq.unique
_spec.Node.Columns = gq.ctx.Fields
if len(gq.ctx.Fields) > 0 {
_spec.Unique = gq.ctx.Unique != nil && *gq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, gq.driver, _spec)
}
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{
@@ -832,10 +832,10 @@ func (gq *GroupQuery) querySpec() *sqlgraph.QuerySpec {
From: gq.sql,
Unique: true,
}
if unique := gq.unique; unique != nil {
if unique := gq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := gq.fields; len(fields) > 0 {
if fields := gq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, group.FieldID)
for i := range fields {
@@ -851,10 +851,10 @@ func (gq *GroupQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := gq.limit; limit != nil {
if limit := gq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := gq.offset; offset != nil {
if offset := gq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := gq.order; len(ps) > 0 {
@@ -870,7 +870,7 @@ func (gq *GroupQuery) querySpec() *sqlgraph.QuerySpec {
func (gq *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(gq.driver.Dialect())
t1 := builder.Table(group.Table)
columns := gq.fields
columns := gq.ctx.Fields
if len(columns) == 0 {
columns = group.Columns
}
@@ -879,7 +879,7 @@ func (gq *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = gq.sql
selector.Select(selector.Columns(columns...)...)
}
if gq.unique != nil && *gq.unique {
if gq.ctx.Unique != nil && *gq.ctx.Unique {
selector.Distinct()
}
for _, p := range gq.predicates {
@@ -888,12 +888,12 @@ func (gq *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range gq.order {
p(selector)
}
if offset := gq.offset; offset != nil {
if offset := gq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := gq.limit; limit != nil {
if limit := gq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -901,13 +901,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 +911,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 = setContextOp(ctx, ggb.build.ctx, "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 +961,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 = setContextOp(ctx, gs.ctx, "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
}

View File

@@ -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
}

View File

@@ -136,14 +136,14 @@ func (git *GroupInvitationToken) assignValues(columns []string, values []any) er
// QueryGroup queries the "group" edge of the GroupInvitationToken entity.
func (git *GroupInvitationToken) QueryGroup() *GroupQuery {
return (&GroupInvitationTokenClient{config: git.config}).QueryGroup(git)
return NewGroupInvitationTokenClient(git.config).QueryGroup(git)
}
// Update returns a builder for updating this GroupInvitationToken.
// Note that you need to call GroupInvitationToken.Unwrap() before calling this method if this GroupInvitationToken
// was returned from a transaction, and the transaction was committed or rolled back.
func (git *GroupInvitationToken) Update() *GroupInvitationTokenUpdateOne {
return (&GroupInvitationTokenClient{config: git.config}).UpdateOne(git)
return NewGroupInvitationTokenClient(git.config).UpdateOne(git)
}
// Unwrap unwraps the GroupInvitationToken entity that was returned from a transaction after it was closed,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type GroupInvitationTokenDeleteOne struct {
gitd *GroupInvitationTokenDelete
}
// Where appends a list predicates to the GroupInvitationTokenDelete builder.
func (gitdo *GroupInvitationTokenDeleteOne) Where(ps ...predicate.GroupInvitationToken) *GroupInvitationTokenDeleteOne {
gitdo.gitd.mutation.Where(ps...)
return gitdo
}
// Exec executes the deletion query.
func (gitdo *GroupInvitationTokenDeleteOne) Exec(ctx context.Context) error {
n, err := gitdo.gitd.Exec(ctx)
@@ -111,5 +90,7 @@ func (gitdo *GroupInvitationTokenDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (gitdo *GroupInvitationTokenDeleteOne) ExecX(ctx context.Context) {
gitdo.gitd.ExecX(ctx)
if err := gitdo.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -19,11 +19,9 @@ import (
// GroupInvitationTokenQuery is the builder for querying GroupInvitationToken entities.
type GroupInvitationTokenQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.GroupInvitationToken
withGroup *GroupQuery
withFKs bool
@@ -38,26 +36,26 @@ 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
gitq.ctx.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
gitq.ctx.Offset = &offset
return gitq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (gitq *GroupInvitationTokenQuery) Unique(unique bool) *GroupInvitationTokenQuery {
gitq.unique = &unique
gitq.ctx.Unique = &unique
return gitq
}
// 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 +63,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 +86,7 @@ func (gitq *GroupInvitationTokenQuery) QueryGroup() *GroupQuery {
// First returns the first GroupInvitationToken entity from the query.
// Returns a *NotFoundError when no GroupInvitationToken was found.
func (gitq *GroupInvitationTokenQuery) First(ctx context.Context) (*GroupInvitationToken, error) {
nodes, err := gitq.Limit(1).All(ctx)
nodes, err := gitq.Limit(1).All(setContextOp(ctx, gitq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -111,7 +109,7 @@ func (gitq *GroupInvitationTokenQuery) FirstX(ctx context.Context) *GroupInvitat
// Returns a *NotFoundError when no GroupInvitationToken ID was found.
func (gitq *GroupInvitationTokenQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = gitq.Limit(1).IDs(ctx); err != nil {
if ids, err = gitq.Limit(1).IDs(setContextOp(ctx, gitq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -134,7 +132,7 @@ func (gitq *GroupInvitationTokenQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one GroupInvitationToken entity is found.
// Returns a *NotFoundError when no GroupInvitationToken entities are found.
func (gitq *GroupInvitationTokenQuery) Only(ctx context.Context) (*GroupInvitationToken, error) {
nodes, err := gitq.Limit(2).All(ctx)
nodes, err := gitq.Limit(2).All(setContextOp(ctx, gitq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -162,7 +160,7 @@ func (gitq *GroupInvitationTokenQuery) OnlyX(ctx context.Context) *GroupInvitati
// Returns a *NotFoundError when no entities are found.
func (gitq *GroupInvitationTokenQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = gitq.Limit(2).IDs(ctx); err != nil {
if ids, err = gitq.Limit(2).IDs(setContextOp(ctx, gitq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -187,10 +185,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 = setContextOp(ctx, gitq.ctx, "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 +205,7 @@ func (gitq *GroupInvitationTokenQuery) AllX(ctx context.Context) []*GroupInvitat
// IDs executes the query and returns a list of GroupInvitationToken IDs.
func (gitq *GroupInvitationTokenQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = setContextOp(ctx, gitq.ctx, "IDs")
if err := gitq.Select(groupinvitationtoken.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -222,10 +223,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 = setContextOp(ctx, gitq.ctx, "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 +241,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 = setContextOp(ctx, gitq.ctx, "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.
@@ -262,22 +269,21 @@ func (gitq *GroupInvitationTokenQuery) Clone() *GroupInvitationTokenQuery {
}
return &GroupInvitationTokenQuery{
config: gitq.config,
limit: gitq.limit,
offset: gitq.offset,
ctx: gitq.ctx.Clone(),
order: append([]OrderFunc{}, gitq.order...),
inters: append([]Interceptor{}, gitq.inters...),
predicates: append([]predicate.GroupInvitationToken{}, gitq.predicates...),
withGroup: gitq.withGroup.Clone(),
// clone intermediate query.
sql: gitq.sql.Clone(),
path: gitq.path,
unique: gitq.unique,
sql: gitq.sql.Clone(),
path: gitq.path,
}
}
// 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 +306,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &GroupInvitationTokenGroupBy{build: gitq}
grbuild.flds = &gitq.ctx.Fields
grbuild.label = groupinvitationtoken.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -326,11 +327,11 @@ func (gitq *GroupInvitationTokenQuery) GroupBy(field string, fields ...string) *
// Select(groupinvitationtoken.FieldCreatedAt).
// Scan(ctx, &v)
func (gitq *GroupInvitationTokenQuery) Select(fields ...string) *GroupInvitationTokenSelect {
gitq.fields = append(gitq.fields, fields...)
selbuild := &GroupInvitationTokenSelect{GroupInvitationTokenQuery: gitq}
selbuild.label = groupinvitationtoken.Label
selbuild.flds, selbuild.scan = &gitq.fields, selbuild.Scan
return selbuild
gitq.ctx.Fields = append(gitq.ctx.Fields, fields...)
sbuild := &GroupInvitationTokenSelect{GroupInvitationTokenQuery: gitq}
sbuild.label = groupinvitationtoken.Label
sbuild.flds, sbuild.scan = &gitq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a GroupInvitationTokenSelect configured with the given aggregations.
@@ -339,7 +340,17 @@ func (gitq *GroupInvitationTokenQuery) Aggregate(fns ...AggregateFunc) *GroupInv
}
func (gitq *GroupInvitationTokenQuery) prepareQuery(ctx context.Context) error {
for _, f := range gitq.fields {
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.ctx.Fields {
if !groupinvitationtoken.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -409,6 +420,9 @@ func (gitq *GroupInvitationTokenQuery) loadGroup(ctx context.Context, query *Gro
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(group.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -428,24 +442,13 @@ func (gitq *GroupInvitationTokenQuery) loadGroup(ctx context.Context, query *Gro
func (gitq *GroupInvitationTokenQuery) sqlCount(ctx context.Context) (int, error) {
_spec := gitq.querySpec()
_spec.Node.Columns = gitq.fields
if len(gitq.fields) > 0 {
_spec.Unique = gitq.unique != nil && *gitq.unique
_spec.Node.Columns = gitq.ctx.Fields
if len(gitq.ctx.Fields) > 0 {
_spec.Unique = gitq.ctx.Unique != nil && *gitq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, gitq.driver, _spec)
}
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{
@@ -459,10 +462,10 @@ func (gitq *GroupInvitationTokenQuery) querySpec() *sqlgraph.QuerySpec {
From: gitq.sql,
Unique: true,
}
if unique := gitq.unique; unique != nil {
if unique := gitq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := gitq.fields; len(fields) > 0 {
if fields := gitq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, groupinvitationtoken.FieldID)
for i := range fields {
@@ -478,10 +481,10 @@ func (gitq *GroupInvitationTokenQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := gitq.limit; limit != nil {
if limit := gitq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := gitq.offset; offset != nil {
if offset := gitq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := gitq.order; len(ps) > 0 {
@@ -497,7 +500,7 @@ func (gitq *GroupInvitationTokenQuery) querySpec() *sqlgraph.QuerySpec {
func (gitq *GroupInvitationTokenQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(gitq.driver.Dialect())
t1 := builder.Table(groupinvitationtoken.Table)
columns := gitq.fields
columns := gitq.ctx.Fields
if len(columns) == 0 {
columns = groupinvitationtoken.Columns
}
@@ -506,7 +509,7 @@ func (gitq *GroupInvitationTokenQuery) sqlQuery(ctx context.Context) *sql.Select
selector = gitq.sql
selector.Select(selector.Columns(columns...)...)
}
if gitq.unique != nil && *gitq.unique {
if gitq.ctx.Unique != nil && *gitq.ctx.Unique {
selector.Distinct()
}
for _, p := range gitq.predicates {
@@ -515,12 +518,12 @@ func (gitq *GroupInvitationTokenQuery) sqlQuery(ctx context.Context) *sql.Select
for _, p := range gitq.order {
p(selector)
}
if offset := gitq.offset; offset != nil {
if offset := gitq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := gitq.limit; limit != nil {
if limit := gitq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -528,13 +531,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 +541,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 = setContextOp(ctx, gitgb.build.ctx, "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 +591,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 = setContextOp(ctx, gits.ctx, "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
}

View File

@@ -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
}

View File

@@ -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.

View File

@@ -390,49 +390,49 @@ func (i *Item) assignValues(columns []string, values []any) error {
// QueryParent queries the "parent" edge of the Item entity.
func (i *Item) QueryParent() *ItemQuery {
return (&ItemClient{config: i.config}).QueryParent(i)
return NewItemClient(i.config).QueryParent(i)
}
// QueryChildren queries the "children" edge of the Item entity.
func (i *Item) QueryChildren() *ItemQuery {
return (&ItemClient{config: i.config}).QueryChildren(i)
return NewItemClient(i.config).QueryChildren(i)
}
// QueryGroup queries the "group" edge of the Item entity.
func (i *Item) QueryGroup() *GroupQuery {
return (&ItemClient{config: i.config}).QueryGroup(i)
return NewItemClient(i.config).QueryGroup(i)
}
// QueryLabel queries the "label" edge of the Item entity.
func (i *Item) QueryLabel() *LabelQuery {
return (&ItemClient{config: i.config}).QueryLabel(i)
return NewItemClient(i.config).QueryLabel(i)
}
// QueryLocation queries the "location" edge of the Item entity.
func (i *Item) QueryLocation() *LocationQuery {
return (&ItemClient{config: i.config}).QueryLocation(i)
return NewItemClient(i.config).QueryLocation(i)
}
// QueryFields queries the "fields" edge of the Item entity.
func (i *Item) QueryFields() *ItemFieldQuery {
return (&ItemClient{config: i.config}).QueryFields(i)
return NewItemClient(i.config).QueryFields(i)
}
// QueryMaintenanceEntries queries the "maintenance_entries" edge of the Item entity.
func (i *Item) QueryMaintenanceEntries() *MaintenanceEntryQuery {
return (&ItemClient{config: i.config}).QueryMaintenanceEntries(i)
return NewItemClient(i.config).QueryMaintenanceEntries(i)
}
// QueryAttachments queries the "attachments" edge of the Item entity.
func (i *Item) QueryAttachments() *AttachmentQuery {
return (&ItemClient{config: i.config}).QueryAttachments(i)
return NewItemClient(i.config).QueryAttachments(i)
}
// Update returns a builder for updating this Item.
// Note that you need to call Item.Unwrap() before calling this method if this Item
// was returned from a transaction, and the transaction was committed or rolled back.
func (i *Item) Update() *ItemUpdateOne {
return (&ItemClient{config: i.config}).UpdateOne(i)
return NewItemClient(i.config).UpdateOne(i)
}
// Unwrap unwraps the Item entity that was returned from a transaction after it was closed,

File diff suppressed because it is too large Load Diff

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type ItemDeleteOne struct {
id *ItemDelete
}
// Where appends a list predicates to the ItemDelete builder.
func (ido *ItemDeleteOne) Where(ps ...predicate.Item) *ItemDeleteOne {
ido.id.mutation.Where(ps...)
return ido
}
// Exec executes the deletion query.
func (ido *ItemDeleteOne) Exec(ctx context.Context) error {
n, err := ido.id.Exec(ctx)
@@ -111,5 +90,7 @@ func (ido *ItemDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (ido *ItemDeleteOne) ExecX(ctx context.Context) {
ido.id.ExecX(ctx)
if err := ido.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -25,11 +25,9 @@ import (
// ItemQuery is the builder for querying Item entities.
type ItemQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.Item
withParent *ItemQuery
withChildren *ItemQuery
@@ -51,26 +49,26 @@ 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
iq.ctx.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
iq.ctx.Offset = &offset
return iq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (iq *ItemQuery) Unique(unique bool) *ItemQuery {
iq.unique = &unique
iq.ctx.Unique = &unique
return iq
}
// 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 +76,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 +98,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 +120,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 +142,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 +164,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 +186,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 +208,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 +230,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 +253,7 @@ func (iq *ItemQuery) QueryAttachments() *AttachmentQuery {
// First returns the first Item entity from the query.
// Returns a *NotFoundError when no Item was found.
func (iq *ItemQuery) First(ctx context.Context) (*Item, error) {
nodes, err := iq.Limit(1).All(ctx)
nodes, err := iq.Limit(1).All(setContextOp(ctx, iq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -278,7 +276,7 @@ func (iq *ItemQuery) FirstX(ctx context.Context) *Item {
// Returns a *NotFoundError when no Item ID was found.
func (iq *ItemQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = iq.Limit(1).IDs(ctx); err != nil {
if ids, err = iq.Limit(1).IDs(setContextOp(ctx, iq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -301,7 +299,7 @@ func (iq *ItemQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one Item entity is found.
// Returns a *NotFoundError when no Item entities are found.
func (iq *ItemQuery) Only(ctx context.Context) (*Item, error) {
nodes, err := iq.Limit(2).All(ctx)
nodes, err := iq.Limit(2).All(setContextOp(ctx, iq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -329,7 +327,7 @@ func (iq *ItemQuery) OnlyX(ctx context.Context) *Item {
// Returns a *NotFoundError when no entities are found.
func (iq *ItemQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = iq.Limit(2).IDs(ctx); err != nil {
if ids, err = iq.Limit(2).IDs(setContextOp(ctx, iq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -354,10 +352,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 = setContextOp(ctx, iq.ctx, "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 +372,7 @@ func (iq *ItemQuery) AllX(ctx context.Context) []*Item {
// IDs executes the query and returns a list of Item IDs.
func (iq *ItemQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = setContextOp(ctx, iq.ctx, "IDs")
if err := iq.Select(item.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -389,10 +390,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 = setContextOp(ctx, iq.ctx, "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 +408,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 = setContextOp(ctx, iq.ctx, "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.
@@ -429,9 +436,9 @@ func (iq *ItemQuery) Clone() *ItemQuery {
}
return &ItemQuery{
config: iq.config,
limit: iq.limit,
offset: iq.offset,
ctx: iq.ctx.Clone(),
order: append([]OrderFunc{}, iq.order...),
inters: append([]Interceptor{}, iq.inters...),
predicates: append([]predicate.Item{}, iq.predicates...),
withParent: iq.withParent.Clone(),
withChildren: iq.withChildren.Clone(),
@@ -442,16 +449,15 @@ func (iq *ItemQuery) Clone() *ItemQuery {
withMaintenanceEntries: iq.withMaintenanceEntries.Clone(),
withAttachments: iq.withAttachments.Clone(),
// clone intermediate query.
sql: iq.sql.Clone(),
path: iq.path,
unique: iq.unique,
sql: iq.sql.Clone(),
path: iq.path,
}
}
// 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 +468,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 +479,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 +490,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 +501,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 +512,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 +523,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 +534,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 +557,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &ItemGroupBy{build: iq}
grbuild.flds = &iq.ctx.Fields
grbuild.label = item.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -577,11 +578,11 @@ func (iq *ItemQuery) GroupBy(field string, fields ...string) *ItemGroupBy {
// Select(item.FieldCreatedAt).
// Scan(ctx, &v)
func (iq *ItemQuery) Select(fields ...string) *ItemSelect {
iq.fields = append(iq.fields, fields...)
selbuild := &ItemSelect{ItemQuery: iq}
selbuild.label = item.Label
selbuild.flds, selbuild.scan = &iq.fields, selbuild.Scan
return selbuild
iq.ctx.Fields = append(iq.ctx.Fields, fields...)
sbuild := &ItemSelect{ItemQuery: iq}
sbuild.label = item.Label
sbuild.flds, sbuild.scan = &iq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ItemSelect configured with the given aggregations.
@@ -590,7 +591,17 @@ func (iq *ItemQuery) Aggregate(fns ...AggregateFunc) *ItemSelect {
}
func (iq *ItemQuery) prepareQuery(ctx context.Context) error {
for _, f := range iq.fields {
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.ctx.Fields {
if !item.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -714,6 +725,9 @@ func (iq *ItemQuery) loadParent(ctx context.Context, query *ItemQuery, nodes []*
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(item.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -774,6 +788,9 @@ func (iq *ItemQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(group.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -813,27 +830,30 @@ func (iq *ItemQuery) loadLabel(ctx context.Context, query *LabelQuery, nodes []*
if err := query.prepareQuery(ctx); err != nil {
return err
}
neighbors, err := query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
assign := spec.Assign
values := spec.ScanValues
spec.ScanValues = func(columns []string) ([]any, error) {
values, err := values(columns[1:])
if err != nil {
return nil, err
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
assign := spec.Assign
values := spec.ScanValues
spec.ScanValues = func(columns []string) ([]any, error) {
values, err := values(columns[1:])
if err != nil {
return nil, err
}
return append([]any{new(uuid.UUID)}, values...), nil
}
return append([]any{new(uuid.UUID)}, values...), nil
}
spec.Assign = func(columns []string, values []any) error {
outValue := *values[0].(*uuid.UUID)
inValue := *values[1].(*uuid.UUID)
if nids[inValue] == nil {
nids[inValue] = map[*Item]struct{}{byID[outValue]: {}}
return assign(columns[1:], values[1:])
spec.Assign = func(columns []string, values []any) error {
outValue := *values[0].(*uuid.UUID)
inValue := *values[1].(*uuid.UUID)
if nids[inValue] == nil {
nids[inValue] = map[*Item]struct{}{byID[outValue]: {}}
return assign(columns[1:], values[1:])
}
nids[inValue][byID[outValue]] = struct{}{}
return nil
}
nids[inValue][byID[outValue]] = struct{}{}
return nil
}
})
})
neighbors, err := withInterceptors[[]*Label](ctx, query, qr, query.inters)
if err != nil {
return err
}
@@ -861,6 +881,9 @@ func (iq *ItemQuery) loadLocation(ctx context.Context, query *LocationQuery, nod
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(location.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -969,24 +992,13 @@ func (iq *ItemQuery) loadAttachments(ctx context.Context, query *AttachmentQuery
func (iq *ItemQuery) sqlCount(ctx context.Context) (int, error) {
_spec := iq.querySpec()
_spec.Node.Columns = iq.fields
if len(iq.fields) > 0 {
_spec.Unique = iq.unique != nil && *iq.unique
_spec.Node.Columns = iq.ctx.Fields
if len(iq.ctx.Fields) > 0 {
_spec.Unique = iq.ctx.Unique != nil && *iq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, iq.driver, _spec)
}
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{
@@ -1000,10 +1012,10 @@ func (iq *ItemQuery) querySpec() *sqlgraph.QuerySpec {
From: iq.sql,
Unique: true,
}
if unique := iq.unique; unique != nil {
if unique := iq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := iq.fields; len(fields) > 0 {
if fields := iq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, item.FieldID)
for i := range fields {
@@ -1019,10 +1031,10 @@ func (iq *ItemQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := iq.limit; limit != nil {
if limit := iq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := iq.offset; offset != nil {
if offset := iq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := iq.order; len(ps) > 0 {
@@ -1038,7 +1050,7 @@ func (iq *ItemQuery) querySpec() *sqlgraph.QuerySpec {
func (iq *ItemQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(iq.driver.Dialect())
t1 := builder.Table(item.Table)
columns := iq.fields
columns := iq.ctx.Fields
if len(columns) == 0 {
columns = item.Columns
}
@@ -1047,7 +1059,7 @@ func (iq *ItemQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = iq.sql
selector.Select(selector.Columns(columns...)...)
}
if iq.unique != nil && *iq.unique {
if iq.ctx.Unique != nil && *iq.ctx.Unique {
selector.Distinct()
}
for _, p := range iq.predicates {
@@ -1056,12 +1068,12 @@ func (iq *ItemQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range iq.order {
p(selector)
}
if offset := iq.offset; offset != nil {
if offset := iq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := iq.limit; limit != nil {
if limit := iq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -1069,13 +1081,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 +1091,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 = setContextOp(ctx, igb.build.ctx, "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 +1141,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 = setContextOp(ctx, is.ctx, "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
}

View File

@@ -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
}

View File

@@ -170,14 +170,14 @@ func (_if *ItemField) assignValues(columns []string, values []any) error {
// QueryItem queries the "item" edge of the ItemField entity.
func (_if *ItemField) QueryItem() *ItemQuery {
return (&ItemFieldClient{config: _if.config}).QueryItem(_if)
return NewItemFieldClient(_if.config).QueryItem(_if)
}
// Update returns a builder for updating this ItemField.
// Note that you need to call ItemField.Unwrap() before calling this method if this ItemField
// was returned from a transaction, and the transaction was committed or rolled back.
func (_if *ItemField) Update() *ItemFieldUpdateOne {
return (&ItemFieldClient{config: _if.config}).UpdateOne(_if)
return NewItemFieldClient(_if.config).UpdateOne(_if)
}
// Unwrap unwraps the ItemField entity that was returned from a transaction after it was closed,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type ItemFieldDeleteOne struct {
ifd *ItemFieldDelete
}
// Where appends a list predicates to the ItemFieldDelete builder.
func (ifdo *ItemFieldDeleteOne) Where(ps ...predicate.ItemField) *ItemFieldDeleteOne {
ifdo.ifd.mutation.Where(ps...)
return ifdo
}
// Exec executes the deletion query.
func (ifdo *ItemFieldDeleteOne) Exec(ctx context.Context) error {
n, err := ifdo.ifd.Exec(ctx)
@@ -111,5 +90,7 @@ func (ifdo *ItemFieldDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (ifdo *ItemFieldDeleteOne) ExecX(ctx context.Context) {
ifdo.ifd.ExecX(ctx)
if err := ifdo.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -19,11 +19,9 @@ import (
// ItemFieldQuery is the builder for querying ItemField entities.
type ItemFieldQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.ItemField
withItem *ItemQuery
withFKs bool
@@ -38,26 +36,26 @@ 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
ifq.ctx.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
ifq.ctx.Offset = &offset
return ifq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (ifq *ItemFieldQuery) Unique(unique bool) *ItemFieldQuery {
ifq.unique = &unique
ifq.ctx.Unique = &unique
return ifq
}
// 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 +63,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 +86,7 @@ func (ifq *ItemFieldQuery) QueryItem() *ItemQuery {
// First returns the first ItemField entity from the query.
// Returns a *NotFoundError when no ItemField was found.
func (ifq *ItemFieldQuery) First(ctx context.Context) (*ItemField, error) {
nodes, err := ifq.Limit(1).All(ctx)
nodes, err := ifq.Limit(1).All(setContextOp(ctx, ifq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -111,7 +109,7 @@ func (ifq *ItemFieldQuery) FirstX(ctx context.Context) *ItemField {
// Returns a *NotFoundError when no ItemField ID was found.
func (ifq *ItemFieldQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = ifq.Limit(1).IDs(ctx); err != nil {
if ids, err = ifq.Limit(1).IDs(setContextOp(ctx, ifq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -134,7 +132,7 @@ func (ifq *ItemFieldQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one ItemField entity is found.
// Returns a *NotFoundError when no ItemField entities are found.
func (ifq *ItemFieldQuery) Only(ctx context.Context) (*ItemField, error) {
nodes, err := ifq.Limit(2).All(ctx)
nodes, err := ifq.Limit(2).All(setContextOp(ctx, ifq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -162,7 +160,7 @@ func (ifq *ItemFieldQuery) OnlyX(ctx context.Context) *ItemField {
// Returns a *NotFoundError when no entities are found.
func (ifq *ItemFieldQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = ifq.Limit(2).IDs(ctx); err != nil {
if ids, err = ifq.Limit(2).IDs(setContextOp(ctx, ifq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -187,10 +185,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 = setContextOp(ctx, ifq.ctx, "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 +205,7 @@ func (ifq *ItemFieldQuery) AllX(ctx context.Context) []*ItemField {
// IDs executes the query and returns a list of ItemField IDs.
func (ifq *ItemFieldQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = setContextOp(ctx, ifq.ctx, "IDs")
if err := ifq.Select(itemfield.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -222,10 +223,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 = setContextOp(ctx, ifq.ctx, "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 +241,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 = setContextOp(ctx, ifq.ctx, "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.
@@ -262,22 +269,21 @@ func (ifq *ItemFieldQuery) Clone() *ItemFieldQuery {
}
return &ItemFieldQuery{
config: ifq.config,
limit: ifq.limit,
offset: ifq.offset,
ctx: ifq.ctx.Clone(),
order: append([]OrderFunc{}, ifq.order...),
inters: append([]Interceptor{}, ifq.inters...),
predicates: append([]predicate.ItemField{}, ifq.predicates...),
withItem: ifq.withItem.Clone(),
// clone intermediate query.
sql: ifq.sql.Clone(),
path: ifq.path,
unique: ifq.unique,
sql: ifq.sql.Clone(),
path: ifq.path,
}
}
// 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 +306,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &ItemFieldGroupBy{build: ifq}
grbuild.flds = &ifq.ctx.Fields
grbuild.label = itemfield.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -326,11 +327,11 @@ func (ifq *ItemFieldQuery) GroupBy(field string, fields ...string) *ItemFieldGro
// Select(itemfield.FieldCreatedAt).
// Scan(ctx, &v)
func (ifq *ItemFieldQuery) Select(fields ...string) *ItemFieldSelect {
ifq.fields = append(ifq.fields, fields...)
selbuild := &ItemFieldSelect{ItemFieldQuery: ifq}
selbuild.label = itemfield.Label
selbuild.flds, selbuild.scan = &ifq.fields, selbuild.Scan
return selbuild
ifq.ctx.Fields = append(ifq.ctx.Fields, fields...)
sbuild := &ItemFieldSelect{ItemFieldQuery: ifq}
sbuild.label = itemfield.Label
sbuild.flds, sbuild.scan = &ifq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ItemFieldSelect configured with the given aggregations.
@@ -339,7 +340,17 @@ func (ifq *ItemFieldQuery) Aggregate(fns ...AggregateFunc) *ItemFieldSelect {
}
func (ifq *ItemFieldQuery) prepareQuery(ctx context.Context) error {
for _, f := range ifq.fields {
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.ctx.Fields {
if !itemfield.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -409,6 +420,9 @@ func (ifq *ItemFieldQuery) loadItem(ctx context.Context, query *ItemQuery, nodes
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(item.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -428,24 +442,13 @@ func (ifq *ItemFieldQuery) loadItem(ctx context.Context, query *ItemQuery, nodes
func (ifq *ItemFieldQuery) sqlCount(ctx context.Context) (int, error) {
_spec := ifq.querySpec()
_spec.Node.Columns = ifq.fields
if len(ifq.fields) > 0 {
_spec.Unique = ifq.unique != nil && *ifq.unique
_spec.Node.Columns = ifq.ctx.Fields
if len(ifq.ctx.Fields) > 0 {
_spec.Unique = ifq.ctx.Unique != nil && *ifq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, ifq.driver, _spec)
}
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{
@@ -459,10 +462,10 @@ func (ifq *ItemFieldQuery) querySpec() *sqlgraph.QuerySpec {
From: ifq.sql,
Unique: true,
}
if unique := ifq.unique; unique != nil {
if unique := ifq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := ifq.fields; len(fields) > 0 {
if fields := ifq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, itemfield.FieldID)
for i := range fields {
@@ -478,10 +481,10 @@ func (ifq *ItemFieldQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := ifq.limit; limit != nil {
if limit := ifq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := ifq.offset; offset != nil {
if offset := ifq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := ifq.order; len(ps) > 0 {
@@ -497,7 +500,7 @@ func (ifq *ItemFieldQuery) querySpec() *sqlgraph.QuerySpec {
func (ifq *ItemFieldQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(ifq.driver.Dialect())
t1 := builder.Table(itemfield.Table)
columns := ifq.fields
columns := ifq.ctx.Fields
if len(columns) == 0 {
columns = itemfield.Columns
}
@@ -506,7 +509,7 @@ func (ifq *ItemFieldQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = ifq.sql
selector.Select(selector.Columns(columns...)...)
}
if ifq.unique != nil && *ifq.unique {
if ifq.ctx.Unique != nil && *ifq.ctx.Unique {
selector.Distinct()
}
for _, p := range ifq.predicates {
@@ -515,12 +518,12 @@ func (ifq *ItemFieldQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range ifq.order {
p(selector)
}
if offset := ifq.offset; offset != nil {
if offset := ifq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := ifq.limit; limit != nil {
if limit := ifq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -528,13 +531,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 +541,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 = setContextOp(ctx, ifgb.build.ctx, "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 +591,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 = setContextOp(ctx, ifs.ctx, "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
}

View File

@@ -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
}

View File

@@ -145,19 +145,19 @@ func (l *Label) assignValues(columns []string, values []any) error {
// QueryGroup queries the "group" edge of the Label entity.
func (l *Label) QueryGroup() *GroupQuery {
return (&LabelClient{config: l.config}).QueryGroup(l)
return NewLabelClient(l.config).QueryGroup(l)
}
// QueryItems queries the "items" edge of the Label entity.
func (l *Label) QueryItems() *ItemQuery {
return (&LabelClient{config: l.config}).QueryItems(l)
return NewLabelClient(l.config).QueryItems(l)
}
// Update returns a builder for updating this Label.
// Note that you need to call Label.Unwrap() before calling this method if this Label
// was returned from a transaction, and the transaction was committed or rolled back.
func (l *Label) Update() *LabelUpdateOne {
return (&LabelClient{config: l.config}).UpdateOne(l)
return NewLabelClient(l.config).UpdateOne(l)
}
// Unwrap unwraps the Label entity that was returned from a transaction after it was closed,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type LabelDeleteOne struct {
ld *LabelDelete
}
// Where appends a list predicates to the LabelDelete builder.
func (ldo *LabelDeleteOne) Where(ps ...predicate.Label) *LabelDeleteOne {
ldo.ld.mutation.Where(ps...)
return ldo
}
// Exec executes the deletion query.
func (ldo *LabelDeleteOne) Exec(ctx context.Context) error {
n, err := ldo.ld.Exec(ctx)
@@ -111,5 +90,7 @@ func (ldo *LabelDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (ldo *LabelDeleteOne) ExecX(ctx context.Context) {
ldo.ld.ExecX(ctx)
if err := ldo.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -21,11 +21,9 @@ import (
// LabelQuery is the builder for querying Label entities.
type LabelQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.Label
withGroup *GroupQuery
withItems *ItemQuery
@@ -41,26 +39,26 @@ 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
lq.ctx.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
lq.ctx.Offset = &offset
return lq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (lq *LabelQuery) Unique(unique bool) *LabelQuery {
lq.unique = &unique
lq.ctx.Unique = &unique
return lq
}
// 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 +66,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 +88,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 +111,7 @@ func (lq *LabelQuery) QueryItems() *ItemQuery {
// First returns the first Label entity from the query.
// Returns a *NotFoundError when no Label was found.
func (lq *LabelQuery) First(ctx context.Context) (*Label, error) {
nodes, err := lq.Limit(1).All(ctx)
nodes, err := lq.Limit(1).All(setContextOp(ctx, lq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -136,7 +134,7 @@ func (lq *LabelQuery) FirstX(ctx context.Context) *Label {
// Returns a *NotFoundError when no Label ID was found.
func (lq *LabelQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = lq.Limit(1).IDs(ctx); err != nil {
if ids, err = lq.Limit(1).IDs(setContextOp(ctx, lq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -159,7 +157,7 @@ func (lq *LabelQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one Label entity is found.
// Returns a *NotFoundError when no Label entities are found.
func (lq *LabelQuery) Only(ctx context.Context) (*Label, error) {
nodes, err := lq.Limit(2).All(ctx)
nodes, err := lq.Limit(2).All(setContextOp(ctx, lq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -187,7 +185,7 @@ func (lq *LabelQuery) OnlyX(ctx context.Context) *Label {
// Returns a *NotFoundError when no entities are found.
func (lq *LabelQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = lq.Limit(2).IDs(ctx); err != nil {
if ids, err = lq.Limit(2).IDs(setContextOp(ctx, lq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -212,10 +210,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 = setContextOp(ctx, lq.ctx, "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 +230,7 @@ func (lq *LabelQuery) AllX(ctx context.Context) []*Label {
// IDs executes the query and returns a list of Label IDs.
func (lq *LabelQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = setContextOp(ctx, lq.ctx, "IDs")
if err := lq.Select(label.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -247,10 +248,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 = setContextOp(ctx, lq.ctx, "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 +266,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 = setContextOp(ctx, lq.ctx, "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.
@@ -287,23 +294,22 @@ func (lq *LabelQuery) Clone() *LabelQuery {
}
return &LabelQuery{
config: lq.config,
limit: lq.limit,
offset: lq.offset,
ctx: lq.ctx.Clone(),
order: append([]OrderFunc{}, lq.order...),
inters: append([]Interceptor{}, lq.inters...),
predicates: append([]predicate.Label{}, lq.predicates...),
withGroup: lq.withGroup.Clone(),
withItems: lq.withItems.Clone(),
// clone intermediate query.
sql: lq.sql.Clone(),
path: lq.path,
unique: lq.unique,
sql: lq.sql.Clone(),
path: lq.path,
}
}
// 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 +320,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 +343,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &LabelGroupBy{build: lq}
grbuild.flds = &lq.ctx.Fields
grbuild.label = label.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -363,11 +364,11 @@ func (lq *LabelQuery) GroupBy(field string, fields ...string) *LabelGroupBy {
// Select(label.FieldCreatedAt).
// Scan(ctx, &v)
func (lq *LabelQuery) Select(fields ...string) *LabelSelect {
lq.fields = append(lq.fields, fields...)
selbuild := &LabelSelect{LabelQuery: lq}
selbuild.label = label.Label
selbuild.flds, selbuild.scan = &lq.fields, selbuild.Scan
return selbuild
lq.ctx.Fields = append(lq.ctx.Fields, fields...)
sbuild := &LabelSelect{LabelQuery: lq}
sbuild.label = label.Label
sbuild.flds, sbuild.scan = &lq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a LabelSelect configured with the given aggregations.
@@ -376,7 +377,17 @@ func (lq *LabelQuery) Aggregate(fns ...AggregateFunc) *LabelSelect {
}
func (lq *LabelQuery) prepareQuery(ctx context.Context) error {
for _, f := range lq.fields {
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.ctx.Fields {
if !label.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -454,6 +465,9 @@ func (lq *LabelQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(group.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -493,27 +507,30 @@ func (lq *LabelQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []*
if err := query.prepareQuery(ctx); err != nil {
return err
}
neighbors, err := query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
assign := spec.Assign
values := spec.ScanValues
spec.ScanValues = func(columns []string) ([]any, error) {
values, err := values(columns[1:])
if err != nil {
return nil, err
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
assign := spec.Assign
values := spec.ScanValues
spec.ScanValues = func(columns []string) ([]any, error) {
values, err := values(columns[1:])
if err != nil {
return nil, err
}
return append([]any{new(uuid.UUID)}, values...), nil
}
return append([]any{new(uuid.UUID)}, values...), nil
}
spec.Assign = func(columns []string, values []any) error {
outValue := *values[0].(*uuid.UUID)
inValue := *values[1].(*uuid.UUID)
if nids[inValue] == nil {
nids[inValue] = map[*Label]struct{}{byID[outValue]: {}}
return assign(columns[1:], values[1:])
spec.Assign = func(columns []string, values []any) error {
outValue := *values[0].(*uuid.UUID)
inValue := *values[1].(*uuid.UUID)
if nids[inValue] == nil {
nids[inValue] = map[*Label]struct{}{byID[outValue]: {}}
return assign(columns[1:], values[1:])
}
nids[inValue][byID[outValue]] = struct{}{}
return nil
}
nids[inValue][byID[outValue]] = struct{}{}
return nil
}
})
})
neighbors, err := withInterceptors[[]*Item](ctx, query, qr, query.inters)
if err != nil {
return err
}
@@ -531,24 +548,13 @@ func (lq *LabelQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []*
func (lq *LabelQuery) sqlCount(ctx context.Context) (int, error) {
_spec := lq.querySpec()
_spec.Node.Columns = lq.fields
if len(lq.fields) > 0 {
_spec.Unique = lq.unique != nil && *lq.unique
_spec.Node.Columns = lq.ctx.Fields
if len(lq.ctx.Fields) > 0 {
_spec.Unique = lq.ctx.Unique != nil && *lq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, lq.driver, _spec)
}
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{
@@ -562,10 +568,10 @@ func (lq *LabelQuery) querySpec() *sqlgraph.QuerySpec {
From: lq.sql,
Unique: true,
}
if unique := lq.unique; unique != nil {
if unique := lq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := lq.fields; len(fields) > 0 {
if fields := lq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, label.FieldID)
for i := range fields {
@@ -581,10 +587,10 @@ func (lq *LabelQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := lq.limit; limit != nil {
if limit := lq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := lq.offset; offset != nil {
if offset := lq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := lq.order; len(ps) > 0 {
@@ -600,7 +606,7 @@ func (lq *LabelQuery) querySpec() *sqlgraph.QuerySpec {
func (lq *LabelQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(lq.driver.Dialect())
t1 := builder.Table(label.Table)
columns := lq.fields
columns := lq.ctx.Fields
if len(columns) == 0 {
columns = label.Columns
}
@@ -609,7 +615,7 @@ func (lq *LabelQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = lq.sql
selector.Select(selector.Columns(columns...)...)
}
if lq.unique != nil && *lq.unique {
if lq.ctx.Unique != nil && *lq.ctx.Unique {
selector.Distinct()
}
for _, p := range lq.predicates {
@@ -618,12 +624,12 @@ func (lq *LabelQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range lq.order {
p(selector)
}
if offset := lq.offset; offset != nil {
if offset := lq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := lq.limit; limit != nil {
if limit := lq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -631,13 +637,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 +647,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 = setContextOp(ctx, lgb.build.ctx, "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 +697,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 = setContextOp(ctx, ls.ctx, "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
}

View File

@@ -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
}

View File

@@ -173,29 +173,29 @@ func (l *Location) assignValues(columns []string, values []any) error {
// QueryParent queries the "parent" edge of the Location entity.
func (l *Location) QueryParent() *LocationQuery {
return (&LocationClient{config: l.config}).QueryParent(l)
return NewLocationClient(l.config).QueryParent(l)
}
// QueryChildren queries the "children" edge of the Location entity.
func (l *Location) QueryChildren() *LocationQuery {
return (&LocationClient{config: l.config}).QueryChildren(l)
return NewLocationClient(l.config).QueryChildren(l)
}
// QueryGroup queries the "group" edge of the Location entity.
func (l *Location) QueryGroup() *GroupQuery {
return (&LocationClient{config: l.config}).QueryGroup(l)
return NewLocationClient(l.config).QueryGroup(l)
}
// QueryItems queries the "items" edge of the Location entity.
func (l *Location) QueryItems() *ItemQuery {
return (&LocationClient{config: l.config}).QueryItems(l)
return NewLocationClient(l.config).QueryItems(l)
}
// Update returns a builder for updating this Location.
// Note that you need to call Location.Unwrap() before calling this method if this Location
// was returned from a transaction, and the transaction was committed or rolled back.
func (l *Location) Update() *LocationUpdateOne {
return (&LocationClient{config: l.config}).UpdateOne(l)
return NewLocationClient(l.config).UpdateOne(l)
}
// Unwrap unwraps the Location entity that was returned from a transaction after it was closed,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type LocationDeleteOne struct {
ld *LocationDelete
}
// Where appends a list predicates to the LocationDelete builder.
func (ldo *LocationDeleteOne) Where(ps ...predicate.Location) *LocationDeleteOne {
ldo.ld.mutation.Where(ps...)
return ldo
}
// Exec executes the deletion query.
func (ldo *LocationDeleteOne) Exec(ctx context.Context) error {
n, err := ldo.ld.Exec(ctx)
@@ -111,5 +90,7 @@ func (ldo *LocationDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (ldo *LocationDeleteOne) ExecX(ctx context.Context) {
ldo.ld.ExecX(ctx)
if err := ldo.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -21,11 +21,9 @@ import (
// LocationQuery is the builder for querying Location entities.
type LocationQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.Location
withParent *LocationQuery
withChildren *LocationQuery
@@ -43,26 +41,26 @@ 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
lq.ctx.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
lq.ctx.Offset = &offset
return lq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (lq *LocationQuery) Unique(unique bool) *LocationQuery {
lq.unique = &unique
lq.ctx.Unique = &unique
return lq
}
// 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 +68,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 +90,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 +112,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 +134,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 +157,7 @@ func (lq *LocationQuery) QueryItems() *ItemQuery {
// First returns the first Location entity from the query.
// Returns a *NotFoundError when no Location was found.
func (lq *LocationQuery) First(ctx context.Context) (*Location, error) {
nodes, err := lq.Limit(1).All(ctx)
nodes, err := lq.Limit(1).All(setContextOp(ctx, lq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -182,7 +180,7 @@ func (lq *LocationQuery) FirstX(ctx context.Context) *Location {
// Returns a *NotFoundError when no Location ID was found.
func (lq *LocationQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = lq.Limit(1).IDs(ctx); err != nil {
if ids, err = lq.Limit(1).IDs(setContextOp(ctx, lq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -205,7 +203,7 @@ func (lq *LocationQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one Location entity is found.
// Returns a *NotFoundError when no Location entities are found.
func (lq *LocationQuery) Only(ctx context.Context) (*Location, error) {
nodes, err := lq.Limit(2).All(ctx)
nodes, err := lq.Limit(2).All(setContextOp(ctx, lq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -233,7 +231,7 @@ func (lq *LocationQuery) OnlyX(ctx context.Context) *Location {
// Returns a *NotFoundError when no entities are found.
func (lq *LocationQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = lq.Limit(2).IDs(ctx); err != nil {
if ids, err = lq.Limit(2).IDs(setContextOp(ctx, lq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -258,10 +256,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 = setContextOp(ctx, lq.ctx, "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 +276,7 @@ func (lq *LocationQuery) AllX(ctx context.Context) []*Location {
// IDs executes the query and returns a list of Location IDs.
func (lq *LocationQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = setContextOp(ctx, lq.ctx, "IDs")
if err := lq.Select(location.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -293,10 +294,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 = setContextOp(ctx, lq.ctx, "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 +312,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 = setContextOp(ctx, lq.ctx, "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.
@@ -333,25 +340,24 @@ func (lq *LocationQuery) Clone() *LocationQuery {
}
return &LocationQuery{
config: lq.config,
limit: lq.limit,
offset: lq.offset,
ctx: lq.ctx.Clone(),
order: append([]OrderFunc{}, lq.order...),
inters: append([]Interceptor{}, lq.inters...),
predicates: append([]predicate.Location{}, lq.predicates...),
withParent: lq.withParent.Clone(),
withChildren: lq.withChildren.Clone(),
withGroup: lq.withGroup.Clone(),
withItems: lq.withItems.Clone(),
// clone intermediate query.
sql: lq.sql.Clone(),
path: lq.path,
unique: lq.unique,
sql: lq.sql.Clone(),
path: lq.path,
}
}
// 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 +368,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 +379,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 +390,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 +413,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &LocationGroupBy{build: lq}
grbuild.flds = &lq.ctx.Fields
grbuild.label = location.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -433,11 +434,11 @@ func (lq *LocationQuery) GroupBy(field string, fields ...string) *LocationGroupB
// Select(location.FieldCreatedAt).
// Scan(ctx, &v)
func (lq *LocationQuery) Select(fields ...string) *LocationSelect {
lq.fields = append(lq.fields, fields...)
selbuild := &LocationSelect{LocationQuery: lq}
selbuild.label = location.Label
selbuild.flds, selbuild.scan = &lq.fields, selbuild.Scan
return selbuild
lq.ctx.Fields = append(lq.ctx.Fields, fields...)
sbuild := &LocationSelect{LocationQuery: lq}
sbuild.label = location.Label
sbuild.flds, sbuild.scan = &lq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a LocationSelect configured with the given aggregations.
@@ -446,7 +447,17 @@ func (lq *LocationQuery) Aggregate(fns ...AggregateFunc) *LocationSelect {
}
func (lq *LocationQuery) prepareQuery(ctx context.Context) error {
for _, f := range lq.fields {
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.ctx.Fields {
if !location.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -539,6 +550,9 @@ func (lq *LocationQuery) loadParent(ctx context.Context, query *LocationQuery, n
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(location.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -599,6 +613,9 @@ func (lq *LocationQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(group.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -649,24 +666,13 @@ func (lq *LocationQuery) loadItems(ctx context.Context, query *ItemQuery, nodes
func (lq *LocationQuery) sqlCount(ctx context.Context) (int, error) {
_spec := lq.querySpec()
_spec.Node.Columns = lq.fields
if len(lq.fields) > 0 {
_spec.Unique = lq.unique != nil && *lq.unique
_spec.Node.Columns = lq.ctx.Fields
if len(lq.ctx.Fields) > 0 {
_spec.Unique = lq.ctx.Unique != nil && *lq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, lq.driver, _spec)
}
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{
@@ -680,10 +686,10 @@ func (lq *LocationQuery) querySpec() *sqlgraph.QuerySpec {
From: lq.sql,
Unique: true,
}
if unique := lq.unique; unique != nil {
if unique := lq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := lq.fields; len(fields) > 0 {
if fields := lq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, location.FieldID)
for i := range fields {
@@ -699,10 +705,10 @@ func (lq *LocationQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := lq.limit; limit != nil {
if limit := lq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := lq.offset; offset != nil {
if offset := lq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := lq.order; len(ps) > 0 {
@@ -718,7 +724,7 @@ func (lq *LocationQuery) querySpec() *sqlgraph.QuerySpec {
func (lq *LocationQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(lq.driver.Dialect())
t1 := builder.Table(location.Table)
columns := lq.fields
columns := lq.ctx.Fields
if len(columns) == 0 {
columns = location.Columns
}
@@ -727,7 +733,7 @@ func (lq *LocationQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = lq.sql
selector.Select(selector.Columns(columns...)...)
}
if lq.unique != nil && *lq.unique {
if lq.ctx.Unique != nil && *lq.ctx.Unique {
selector.Distinct()
}
for _, p := range lq.predicates {
@@ -736,12 +742,12 @@ func (lq *LocationQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range lq.order {
p(selector)
}
if offset := lq.offset; offset != nil {
if offset := lq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := lq.limit; limit != nil {
if limit := lq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -749,13 +755,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 +765,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 = setContextOp(ctx, lgb.build.ctx, "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 +815,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 = setContextOp(ctx, ls.ctx, "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
}

View File

@@ -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
}

View File

@@ -142,14 +142,14 @@ func (me *MaintenanceEntry) assignValues(columns []string, values []any) error {
// QueryItem queries the "item" edge of the MaintenanceEntry entity.
func (me *MaintenanceEntry) QueryItem() *ItemQuery {
return (&MaintenanceEntryClient{config: me.config}).QueryItem(me)
return NewMaintenanceEntryClient(me.config).QueryItem(me)
}
// Update returns a builder for updating this MaintenanceEntry.
// Note that you need to call MaintenanceEntry.Unwrap() before calling this method if this MaintenanceEntry
// was returned from a transaction, and the transaction was committed or rolled back.
func (me *MaintenanceEntry) Update() *MaintenanceEntryUpdateOne {
return (&MaintenanceEntryClient{config: me.config}).UpdateOne(me)
return NewMaintenanceEntryClient(me.config).UpdateOne(me)
}
// Unwrap unwraps the MaintenanceEntry entity that was returned from a transaction after it was closed,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}
@@ -96,6 +69,12 @@ type MaintenanceEntryDeleteOne struct {
med *MaintenanceEntryDelete
}
// Where appends a list predicates to the MaintenanceEntryDelete builder.
func (medo *MaintenanceEntryDeleteOne) Where(ps ...predicate.MaintenanceEntry) *MaintenanceEntryDeleteOne {
medo.med.mutation.Where(ps...)
return medo
}
// Exec executes the deletion query.
func (medo *MaintenanceEntryDeleteOne) Exec(ctx context.Context) error {
n, err := medo.med.Exec(ctx)
@@ -111,5 +90,7 @@ func (medo *MaintenanceEntryDeleteOne) Exec(ctx context.Context) error {
// ExecX is like Exec, but panics if an error occurs.
func (medo *MaintenanceEntryDeleteOne) ExecX(ctx context.Context) {
medo.med.ExecX(ctx)
if err := medo.Exec(ctx); err != nil {
panic(err)
}
}

View File

@@ -19,11 +19,9 @@ import (
// MaintenanceEntryQuery is the builder for querying MaintenanceEntry entities.
type MaintenanceEntryQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.MaintenanceEntry
withItem *ItemQuery
// intermediate query (i.e. traversal path).
@@ -37,26 +35,26 @@ 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
meq.ctx.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
meq.ctx.Offset = &offset
return meq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (meq *MaintenanceEntryQuery) Unique(unique bool) *MaintenanceEntryQuery {
meq.unique = &unique
meq.ctx.Unique = &unique
return meq
}
// 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 +62,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 +85,7 @@ func (meq *MaintenanceEntryQuery) QueryItem() *ItemQuery {
// First returns the first MaintenanceEntry entity from the query.
// Returns a *NotFoundError when no MaintenanceEntry was found.
func (meq *MaintenanceEntryQuery) First(ctx context.Context) (*MaintenanceEntry, error) {
nodes, err := meq.Limit(1).All(ctx)
nodes, err := meq.Limit(1).All(setContextOp(ctx, meq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -110,7 +108,7 @@ func (meq *MaintenanceEntryQuery) FirstX(ctx context.Context) *MaintenanceEntry
// Returns a *NotFoundError when no MaintenanceEntry ID was found.
func (meq *MaintenanceEntryQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = meq.Limit(1).IDs(ctx); err != nil {
if ids, err = meq.Limit(1).IDs(setContextOp(ctx, meq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -133,7 +131,7 @@ func (meq *MaintenanceEntryQuery) FirstIDX(ctx context.Context) uuid.UUID {
// Returns a *NotSingularError when more than one MaintenanceEntry entity is found.
// Returns a *NotFoundError when no MaintenanceEntry entities are found.
func (meq *MaintenanceEntryQuery) Only(ctx context.Context) (*MaintenanceEntry, error) {
nodes, err := meq.Limit(2).All(ctx)
nodes, err := meq.Limit(2).All(setContextOp(ctx, meq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -161,7 +159,7 @@ func (meq *MaintenanceEntryQuery) OnlyX(ctx context.Context) *MaintenanceEntry {
// Returns a *NotFoundError when no entities are found.
func (meq *MaintenanceEntryQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = meq.Limit(2).IDs(ctx); err != nil {
if ids, err = meq.Limit(2).IDs(setContextOp(ctx, meq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -186,10 +184,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 = setContextOp(ctx, meq.ctx, "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 +204,7 @@ func (meq *MaintenanceEntryQuery) AllX(ctx context.Context) []*MaintenanceEntry
// IDs executes the query and returns a list of MaintenanceEntry IDs.
func (meq *MaintenanceEntryQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
var ids []uuid.UUID
ctx = setContextOp(ctx, meq.ctx, "IDs")
if err := meq.Select(maintenanceentry.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -221,10 +222,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 = setContextOp(ctx, meq.ctx, "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 +240,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 = setContextOp(ctx, meq.ctx, "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.
@@ -261,22 +268,21 @@ func (meq *MaintenanceEntryQuery) Clone() *MaintenanceEntryQuery {
}
return &MaintenanceEntryQuery{
config: meq.config,
limit: meq.limit,
offset: meq.offset,
ctx: meq.ctx.Clone(),
order: append([]OrderFunc{}, meq.order...),
inters: append([]Interceptor{}, meq.inters...),
predicates: append([]predicate.MaintenanceEntry{}, meq.predicates...),
withItem: meq.withItem.Clone(),
// clone intermediate query.
sql: meq.sql.Clone(),
path: meq.path,
unique: meq.unique,
sql: meq.sql.Clone(),
path: meq.path,
}
}
// 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 +305,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.ctx.Fields = append([]string{field}, fields...)
grbuild := &MaintenanceEntryGroupBy{build: meq}
grbuild.flds = &meq.ctx.Fields
grbuild.label = maintenanceentry.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -325,11 +326,11 @@ func (meq *MaintenanceEntryQuery) GroupBy(field string, fields ...string) *Maint
// Select(maintenanceentry.FieldCreatedAt).
// Scan(ctx, &v)
func (meq *MaintenanceEntryQuery) Select(fields ...string) *MaintenanceEntrySelect {
meq.fields = append(meq.fields, fields...)
selbuild := &MaintenanceEntrySelect{MaintenanceEntryQuery: meq}
selbuild.label = maintenanceentry.Label
selbuild.flds, selbuild.scan = &meq.fields, selbuild.Scan
return selbuild
meq.ctx.Fields = append(meq.ctx.Fields, fields...)
sbuild := &MaintenanceEntrySelect{MaintenanceEntryQuery: meq}
sbuild.label = maintenanceentry.Label
sbuild.flds, sbuild.scan = &meq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a MaintenanceEntrySelect configured with the given aggregations.
@@ -338,7 +339,17 @@ func (meq *MaintenanceEntryQuery) Aggregate(fns ...AggregateFunc) *MaintenanceEn
}
func (meq *MaintenanceEntryQuery) prepareQuery(ctx context.Context) error {
for _, f := range meq.fields {
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.ctx.Fields {
if !maintenanceentry.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -398,6 +409,9 @@ func (meq *MaintenanceEntryQuery) loadItem(ctx context.Context, query *ItemQuery
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(item.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -417,24 +431,13 @@ func (meq *MaintenanceEntryQuery) loadItem(ctx context.Context, query *ItemQuery
func (meq *MaintenanceEntryQuery) sqlCount(ctx context.Context) (int, error) {
_spec := meq.querySpec()
_spec.Node.Columns = meq.fields
if len(meq.fields) > 0 {
_spec.Unique = meq.unique != nil && *meq.unique
_spec.Node.Columns = meq.ctx.Fields
if len(meq.ctx.Fields) > 0 {
_spec.Unique = meq.ctx.Unique != nil && *meq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, meq.driver, _spec)
}
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{
@@ -448,10 +451,10 @@ func (meq *MaintenanceEntryQuery) querySpec() *sqlgraph.QuerySpec {
From: meq.sql,
Unique: true,
}
if unique := meq.unique; unique != nil {
if unique := meq.ctx.Unique; unique != nil {
_spec.Unique = *unique
}
if fields := meq.fields; len(fields) > 0 {
if fields := meq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, maintenanceentry.FieldID)
for i := range fields {
@@ -467,10 +470,10 @@ func (meq *MaintenanceEntryQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := meq.limit; limit != nil {
if limit := meq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := meq.offset; offset != nil {
if offset := meq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := meq.order; len(ps) > 0 {
@@ -486,7 +489,7 @@ func (meq *MaintenanceEntryQuery) querySpec() *sqlgraph.QuerySpec {
func (meq *MaintenanceEntryQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(meq.driver.Dialect())
t1 := builder.Table(maintenanceentry.Table)
columns := meq.fields
columns := meq.ctx.Fields
if len(columns) == 0 {
columns = maintenanceentry.Columns
}
@@ -495,7 +498,7 @@ func (meq *MaintenanceEntryQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = meq.sql
selector.Select(selector.Columns(columns...)...)
}
if meq.unique != nil && *meq.unique {
if meq.ctx.Unique != nil && *meq.ctx.Unique {
selector.Distinct()
}
for _, p := range meq.predicates {
@@ -504,12 +507,12 @@ func (meq *MaintenanceEntryQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range meq.order {
p(selector)
}
if offset := meq.offset; offset != nil {
if offset := meq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := meq.limit; limit != nil {
if limit := meq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -517,13 +520,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 +530,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 = setContextOp(ctx, megb.build.ctx, "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 +580,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 = setContextOp(ctx, mes.ctx, "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
}

View File

@@ -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
}

Some files were not shown because too many files have changed in this diff Show More