diff --git a/docs/_docs/dev-guide/tavern.md b/docs/_docs/dev-guide/tavern.md index 4bec9aa27..f38692a73 100644 --- a/docs/_docs/dev-guide/tavern.md +++ b/docs/_docs/dev-guide/tavern.md @@ -1,18 +1,22 @@ --- title: Tavern -tags: +tags: - Dev Guide description: Want to contribute to Tavern? Start here! permalink: dev-guide/tavern --- -# Overview + +## Overview + Tavern is a teamserver for Realm, providing a UI to control deployments and implants during an engagement. The majority of Tavern's functionality is exposed through a GraphQL API, which is used by both implants and the UI. If you would like to help contribute to Tavern, please take a look at our [open issues](https://github.com/KCarretto/realm/issues?q=is%3Aopen+is%3Aissue+label%3Atavern). -# Configuration -## MySQL -By default, Tavern operates an in-memory SQLite database. To persist data, a MySQL backend is supported. In order to configure Tavern to use MySQL, the `MYSQL_ADDR` environment variable must be set to the `host[:port]` of the database (e.g. `127.0.0.1`, `mydb.com`, or `mydb.com:3306`). You can reference the [mysql.Config](https://pkg.go.dev/github.com/go-sql-driver/mysql#Config) for additional information about Tavern's MySQL configuration. +## Configuration + +### MySQL + +By default, Tavern operates an in-memory SQLite database. To persist data, a MySQL backend is supported. In order to configure Tavern to use MySQL, the `MYSQL_ADDR` environment variable must be set to the `host[:port]` of the database (e.g. `127.0.0.1`, `mydb.com`, or `mydb.com:3306`). You can reference the [mysql.Config](https://pkg.go.dev/github.com/go-sql-driver/mysql#Config) for additional information about Tavern's MySQL configuration. The following environment variables are currently supported for additional MySQL Configuration: @@ -23,20 +27,25 @@ The following environment variables are currently supported for additional MySQL | MYSQL_USER| User to authenticate with | root | No | | MYSQL_PASSWD| Password to authenticate with | no password | No | | MYSQL_DB| Name of the database to use | tavern | No | +| MYSQL_MAX_IDLE_CONNS | Integer value of max idle mysql connections to keep open | 10 | No | +| MYSQL_MAX_OPEN_CONNS | Integer value of max mysql connections to open | 100 | No | +| MYSQL_MAX_CONN_LIFETIME | Integer value of max mysql connection lifetime (in seconds) | 3600 | No | -
Here is an example of running Tavern locally with a MySQL backend: -``` + +```sh MYSQL_USER="admin" MYSQL_ADDR="127.0.0.1:3306" go run ./tavern ``` -
+ When no value is set for `MYSQL_ADDR`, the default SQLite backend is used: -``` + +```sh MYSQL_USER="admin" go run ./tavern/ 2022/03/08 05:46:06 no value found for environment var 'MYSQL_ADDR', starting tavern with SQLite ``` -## OAuth +### OAuth + By default, user authentication is disabled for Tavern. This means that anyone can login and be granted a session. To restrict who is able to access your deployment, Tavern supports OAuth configuration (using [Google OAuth](https://developers.google.com/identity/protocols/oauth2)). To obtain a client_id and a client_secret for Google OAuth, please follow [their instructions](https://developers.google.com/identity/sign-in/web/sign-in#create_authorization_credentials) to create an application. @@ -49,32 +58,32 @@ The following environment variables are required for OAuth Configuration: | OAUTH_CLIENT_SECRET | The [OAuth client_secret](https://www.oauth.com/oauth2-servers/client-registration/client-id-secret/) Tavern will use to authenticate to an identity provider (Google) | OAUTH_DOMAIN | The domain Tavern is being hosted at, that the identity provider (Google) should redirect users to after completing the consent flow | -
Here is an example of running Tavern locally with OAuth configured: -``` + +```sh OAUTH_CLIENT_ID=123 OAUTH_CLIENT_SECRET=456 OAUTH_DOMAIN=127.0.0.1 go run ./tavern 2022/03/09 05:32:58 no value found for environment var 'MYSQL_ADDR', starting tavern with SQLite 2022/03/09 05:32:58 listening on 0.0.0.0:80 ``` -
When no OAuth configuration is provided, authentication is disabled: -``` + +```sh go run ./tavern 2022/03/09 05:24:43 no value found for environment var 'MYSQL_ADDR', starting tavern with SQLite 2022/03/09 05:24:43 WARNING: OAuth is not configured, authentication disabled ``` -
When partial OAuth configuration is provided, Tavern will error. This is to protect against inadvertently starting Tavern with authentication disabled. -``` + +```sh OAUTH_CLIENT_ID=123 go run ./tavern 2022/03/09 05:31:46 no value found for environment var 'MYSQL_ADDR', starting tavern with SQLite 2022/03/09 05:31:46 [FATAL] To configure OAuth, must provide value for environment var 'OAUTH_CLIENT_SECRET' exit status 1 ``` -## Test Data +### Test Data Running Tavern with the `ENABLE_TEST_DATA` environment variable set will populate the database with test data. This is useful for UI development, testing, or just interacting with Tavern and seeing how it works. @@ -89,35 +98,40 @@ ENABLE_TEST_DATA=1 go run ./tavern #### How it Works Tavern hosts two endpoints to support OAuth: + * A login handler (`/oauth/login`) which redirects users to Google's OAuth consent flow - * This endpoint sets a JWT cookie for the user, such that the [OAuth state parameter](https://auth0.com/docs/secure/attack-protection/state-parameters#csrf-attacks) can safely be verified later to prevent against CSRF attacks - * Currently the keys used to sign and verify JWTs are generated at server start, meaning if the server is restarted while a user is in the middle of an OAuth flow, it will fail and the user will need to restart the flow + * This endpoint sets a JWT cookie for the user, such that the [OAuth state parameter](https://auth0.com/docs/secure/attack-protection/state-parameters#csrf-attacks) can safely be verified later to prevent against CSRF attacks + * Currently the keys used to sign and verify JWTs are generated at server start, meaning if the server is restarted while a user is in the middle of an OAuth flow, it will fail and the user will need to restart the flow * An authorization handler (`/oauth/authorize`) which users are redirected to by Google after completing Google's OAuth consent flow - * This handler is responsible for obtaining a user's profile information from Google using an OAuth access token, and creates the user's account if it does not exist yet + * This handler is responsible for obtaining a user's profile information from Google using an OAuth access token, and creates the user's account if it does not exist yet ##### Trust on First Use + Tavern supports a Trust on First Use (TOFU) authentication model, meaning the first user to successfully authenticate will be granted admin permissions. Subsequent users that login will have accounts created, but will require activation before they can interact with any Tavern APIs. Only admin users may activate other users. -# User Interface +## User Interface -# CDN API +## CDN API + +### Uploading Files -## Uploading Files * File uploads require 2 form parameters: `fileName` and `fileContent` * A successful response returns JSON with the following content: `{"data":{"file":{"id":}}}` -## Downloading Files +### Downloading Files + * TODO (CDN is not yet added to Tavern) -# GraphQL API +## GraphQL API + +### Playground -## Playground If you'd like to explore the Graph API and try out some queries, head to the `/graphiql` endpoint of your Tavern deployment. This endpoint exposes an interactive playground for you to experiment with GraphQL queries. ![/assets/img/tavern/graphiql.png](/assets/img/tavern/graphiql.png) +### Creating a New Model -## Creating a New Model 1. Initialize the schema `cd tavern && go run entgo.io/ent/cmd/ent init ` 2. Update the generated file in `tavern/ent/schema/.go` 3. Ensure you include a `func () Annotations() []schema.Annotation` method which returns a `entgql.QueryField()` annotation to tell entgo to generate a GraphQL root query for this model (if you'd like it to be queryable from the root query) @@ -125,17 +139,19 @@ If you'd like to explore the Graph API and try out some queries, head to the `/g 5. **Optionally** update the `models:` section of `tavern/graphql/gqlgen.yml` to bind any GraphQL enum types to their respective `entgo` generated types (e.g. `github.com/kcarretto/realm/tavern/ent/.`) 6. Run `go generate ./tavern/...` from the project root 7. If you added an annotation for a root query field (see above), you will notice auto-generated the `query.resolvers.go` file has been updated with new methods to query your model (e.g. `func (r *queryResolver) s ...`) - * This must be implemented (e.g. `return r.client..Query().All(ctx)` where is the name of your model) + * This must be implemented (e.g. `return r.client..Query().All(ctx)` where NAME is the name of your model) + +### Adding Mutations -## Adding Mutations 1. Update the `mutation.graphql` schema file to include your new mutation and please include it in the section for the model it's mutating if applicable (e.g. createUser should be defined near all the related User mutations) * **Note:** Input types such as `CreateInput` or `UpdateInput` will already be generated if you [added the approproate annotations to your ent schema](https://entgo.io/docs/tutorial-todo-gql#install-and-configure-entgql). If you require custom input mutations (e.g. `ClaimTasksInput`) then add them to the `inputs.graphql` file (Golang code will be generated in tavern/graphql/models e.g. `models.ClaimTasksInput`). 2. Run `go generate ./...` 3. Implement generated the generated mutation resolver method in `tavern/graphql/mutation.resolvers.go` * Depending on the mutation you're trying to implement, a one liner such as `return r.client..Create().SetInput(input).Save(ctx)` might be sufficient -5. Please write a unit test for your new mutation in `_test.go` <3 +4. Please write a unit test for your new mutation in `_test.go` <3 + +### Code Generation Reference -## Code Generation Reference * After making a change, remember to run `go generate ./...` from the project root. * `tavern/ent/schema` is a directory which defines our graph using database models (ents) and the relations between them * `tavern/generate.go` is responsible for generating ents defined by the ent schema as well as updating the GraphQL schema and generating related code @@ -145,16 +161,15 @@ If you'd like to explore the Graph API and try out some queries, head to the `/g * `tavern/graphql/schema/scalars.graphql` defines scalar GraphQL types that can be used to help with Go bindings (See [gqlgen docs](https://gqlgen.com/reference/scalars/) for more info) * `tavern/graphql/schema/inputs.graphql` defines custom GraphQL inputs that can be used with your mutations (e.g. outside of the default auto-generated CRUD inputs) -## Resources +### Resources + * [Relay Documentation](https://relay.dev/graphql/connections.htm) * [entgo.io GraphQL Integration Docs](https://entgo.io/docs/graphql) * [Ent + GraphQL Tutorial](https://entgo.io/docs/tutorial-todo-gql) * [Example Ent + GraphQL project](https://github.com/ent/contrib/tree/master/entgql/internal/todo) * [GQLGen Repo](https://github.com/99designs/gqlgen) -# Agent Development - -## Overview +## Agent Development Tavern provides an HTTP(s) GraphQL API that agents may use directly to claim tasks and submit execution results. This is the standard request flow, and is supported as a core function of realm. To learn more about how to interface with GraphQL APIs, please read [this documentation](https://www.graphql.com/tutorials/#clients) or read on for a simple example. @@ -164,7 +179,7 @@ This however restricts the available transport methods the agent may use to comm ![/assets/img/tavern/custom-usage-arch.png](/assets/img/tavern/custom-usage-arch.png) -## GraphQL Example +### GraphQL Example GraphQL mutations enable clients to _mutate_ or modify backend data. Tavern supports a variety of different mutations for interacting with the graph ([see schema](https://github.com/KCarretto/realm/blob/main/tavern/graphql/schema/mutation.graphql)). The two mutations agents rely on are `claimTasks` and `submitTaskResult` (covered in more detail below). GraphQL requests are submitted as HTTP POST requests to Tavern, with a JSON body including the GraphQL mutation. Below is an example JSON body that may be sent to the Tavern GraphQL API: @@ -186,7 +201,7 @@ GraphQL mutations enable clients to _mutate_ or modify backend data. Tavern supp In the above example, `$input` is used to pass variables from code to the GraphQL mutation while avoiding sketchy string parsing. Fields that should be present in the output are included in the body of the query (e.g. 'id'). -## Claiming Tasks +### Claiming Tasks The first GraphQL mutation an agent should utilize is `claimTasks`. This mutation is used to fetch new tasks from Tavern that should be executed by the agent. In order to fetch execution information, the agent should perform a graph traversal to obtain information about the associated job. For example: diff --git a/go.mod b/go.mod index 2031392b3..9b652cfc8 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,14 @@ module github.com/kcarretto/realm go 1.20 require ( - entgo.io/contrib v0.3.4 - entgo.io/ent v0.11.5-0.20221031135557-521f9b57bc3d - github.com/99designs/gqlgen v0.17.20 - github.com/go-sql-driver/mysql v1.6.0 + entgo.io/contrib v0.3.5 + entgo.io/ent v0.11.9 + github.com/99designs/gqlgen v0.17.26 + github.com/go-sql-driver/mysql v1.7.0 github.com/golang-jwt/jwt v3.2.2+incompatible github.com/hashicorp/go-multierror v1.1.1 github.com/mattn/go-sqlite3 v1.14.16 - github.com/stretchr/testify v1.8.0 + github.com/stretchr/testify v1.8.2 github.com/urfave/cli v1.22.5 github.com/vektah/gqlparser/v2 v2.5.1 github.com/vmihailenco/msgpack/v5 v5.3.5 @@ -21,12 +21,12 @@ require ( ) require ( - ariga.io/atlas v0.8.2 // indirect + ariga.io/atlas v0.9.1 // indirect cloud.google.com/go/compute/metadata v0.2.0 // indirect github.com/agext/levenshtein v1.2.3 // indirect github.com/agnivade/levenshtein v1.1.1 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-openapi/inflect v0.19.0 // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -34,22 +34,19 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/hashicorp/golang-lru v0.5.4 // indirect - github.com/hashicorp/hcl/v2 v2.15.0 // indirect - github.com/logrusorgru/aurora/v3 v3.0.0 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.1 // indirect + github.com/hashicorp/hcl/v2 v2.16.1 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - github.com/zclconf/go-cty v1.12.1 // indirect - golang.org/x/mod v0.7.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.3.0 // indirect + github.com/zclconf/go-cty v1.13.0 // indirect + golang.org/x/mod v0.9.0 // indirect + golang.org/x/net v0.8.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect + golang.org/x/tools v0.7.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.1 // indirect ) diff --git a/go.sum b/go.sum index 193257596..5295fa87f 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,14 @@ -ariga.io/atlas v0.8.2 h1:uXRegk0Zd7nlCYC60tdx12xUvN2NmeGTc2MB5HnnbkA= -ariga.io/atlas v0.8.2/go.mod h1:ft47uSh5hWGDCmQC9DsztZg6Xk+KagM5Ts/mZYKb9JE= +ariga.io/atlas v0.9.1 h1:EpoPMnwsQG0vn9c0sYExpwSYtr7bvuSUXzQclU2pMjc= +ariga.io/atlas v0.9.1/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU= cloud.google.com/go/compute/metadata v0.2.0 h1:nBbNSZyDpkNlo3DepaaLKVuO7ClyifSAmNloSCZrHnQ= cloud.google.com/go/compute/metadata v0.2.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= -entgo.io/contrib v0.3.4 h1:s6dSxMALALQRktvTVeKCSTEVIk9kg/HPOAWtomBU2uE= -entgo.io/contrib v0.3.4/go.mod h1:fUwIOdC0+G7OTDpsXZjrjJK8iTPyvYP22pG08hFhhZ0= -entgo.io/ent v0.11.5-0.20221031135557-521f9b57bc3d h1:slfuvOSWSiV0ldHU+V+O2cfOEgWRpbRloUeE9k7wXnw= -entgo.io/ent v0.11.5-0.20221031135557-521f9b57bc3d/go.mod h1:fnQIXL36RYnCk/9nvG4aE7YHBFZhCycfh7wMjY5p7SE= -github.com/99designs/gqlgen v0.17.20 h1:O7WzccIhKB1dm+7g6dhQcULINftfiLSBg2l/mwbpJMw= -github.com/99designs/gqlgen v0.17.20/go.mod h1:Mja2HI23kWT1VRH09hvWshFgOzKswpO20o4ScpJIES4= +entgo.io/contrib v0.3.5 h1:wY85TgRp3j5ix/SZ9IE6Ob5lObHFmVUYH0ZFw1D5Hzc= +entgo.io/contrib v0.3.5/go.mod h1:R5HiFszVD8OVOZKFGRbqYogRxK7z1ruzWyEEesjQwE0= +entgo.io/ent v0.11.9 h1:dbbCkAiPVTRBIJwoZctiSYjB7zxQIBOzVSU5H9VYIQI= +entgo.io/ent v0.11.9/go.mod h1:KWHOcDZn1xk3mz3ipWdKrQpMvwqa/9B69TUuAPP9W6g= +github.com/99designs/gqlgen v0.17.26 h1:fxgSTbPf1G30uWAWSoHd+9gSNMagmP04k58ThJ1/ikQ= +github.com/99designs/gqlgen v0.17.26/go.mod h1:i4rEatMrzzu6RXaHydq1nmEPZkb3bKQsnxNRHS4DQB4= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= @@ -23,8 +22,8 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkE github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= -github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 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= @@ -32,8 +31,8 @@ github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+ github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= -github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= -github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= +github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= @@ -53,29 +52,20 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= -github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/hcl/v2 v2.15.0 h1:CPDXO6+uORPjKflkWCCwoWc9uRp+zSIPcCQ+BrxV7m8= -github.com/hashicorp/hcl/v2 v2.15.0/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng= -github.com/kevinmbeaulieu/eq-go v1.0.0/go.mod h1:G3S8ajA56gKBZm4UB9AOyoOS37JO3roToPzKNM8dtdM= +github.com/hashicorp/golang-lru/v2 v2.0.1 h1:5pv5N1lT1fjLg2VQ5KWc7kmucp2x/kvFOnxuVTqZ6x4= +github.com/hashicorp/golang-lru/v2 v2.0.1/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/hashicorp/hcl/v2 v2.16.1 h1:BwuxEMD/tsYgbhIW7UuI3crjovf3MzuFWiVgiv57iHg= +github.com/hashicorp/hcl/v2 v2.16.1/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 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= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= -github.com/logrusorgru/aurora/v3 v3.0.0 h1:R6zcoZZbvVcGMvDCKo45A9U/lzYyzl5NfYIvznmDfE4= -github.com/logrusorgru/aurora/v3 v3.0.0/go.mod h1:vsR12bk5grlLvLXAYrBsb5Oc/N+LxAlxggSjiwMnCUc= -github.com/matryer/moq v0.2.7/go.mod h1:kITsx543GOENm48TUAQyJ9+SAvFSr7iGQXPoth/VUBk= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= -github.com/mitchellh/mapstructure v1.3.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -87,83 +77,52 @@ github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/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 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/urfave/cli/v2 v2.8.1/go.mod h1:Z41J9TPoffeoqP0Iza0YbAhGvymRdZAd2uPmZ5JxRdY= github.com/vektah/gqlparser/v2 v2.5.1 h1:ZGu+bquAY23jsxDRcYpWjttRZrUz07LbiY77gUOHcr4= github.com/vektah/gqlparser/v2 v2.5.1/go.mod h1:mPgqFBu/woKTVYWyNk8cO3kh4S/f4aRFZrvOnp3hmCs= github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -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= +github.com/zclconf/go-cty v1.13.0 h1:It5dfKTTZHe9aeppbNOda3mN7Ag7sg6QkBNm6TkyFa0= +github.com/zclconf/go-cty v1.13.0/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= 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-20220517005047-85d78b3ac167 h1:O8uGbHCqlTp2P6QJSLmCojM4mN6UemYv8K+dCnmHmu0= golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= -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/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= +golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -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-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -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/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/oauth2 v0.5.0 h1:HuArIo48skDwlrvM3sEdHXElYslAMsf3KwRkkW4MC4s= golang.org/x/oauth2 v0.5.0/go.mod h1:9/XBHVqLaWO3/BRHs5jbpYCnOZVjj5V0ndyaAM7KB4I= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/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-20211019181941-9d821ace8654/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.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/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -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.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 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.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.3.0 h1:SrNbZl6ECOS1qFzgTdQfWXZM9XBkiA6tkFrH9YSTPHM= -golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -173,7 +132,6 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tavern/app.go b/tavern/app.go index ae08223fb..5114a2c1f 100644 --- a/tavern/app.go +++ b/tavern/app.go @@ -15,7 +15,6 @@ import ( "entgo.io/contrib/entgql" gqlgraphql "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/handler" - "github.com/99designs/gqlgen/graphql/handler/debug" "github.com/99designs/gqlgen/graphql/playground" "github.com/kcarretto/realm/tavern/auth" "github.com/kcarretto/realm/tavern/ent" @@ -109,7 +108,6 @@ func NewServer(ctx context.Context, options ...func(*Config)) (*Server, error) { // Create GraphQL Handler srv := handler.NewDefaultServer(graphql.NewSchema(client)) srv.Use(entgql.Transactioner{TxOpener: client}) - srv.Use(&debug.Tracer{}) // GraphQL Logging gqlLogger := log.New(os.Stderr, "[GraphQL] ", log.Flags()) @@ -165,7 +163,7 @@ func NewServer(ctx context.Context, options ...func(*Config)) (*Server, error) { if cfg.oauth.ClientID != "" { endpoint = auth.Middleware(handlerWithLogging, client) } else { - endpoint = auth.AuthDisabledMiddleware(handlerWithLogging) + endpoint = auth.AuthDisabledMiddleware(handlerWithLogging, client) } // Initialize HTTP Server diff --git a/tavern/auth/authtest/identity.go b/tavern/auth/authtest/identity.go deleted file mode 100644 index ae0c68b7f..000000000 --- a/tavern/auth/authtest/identity.go +++ /dev/null @@ -1,33 +0,0 @@ -package authtest - -// TestIdentity that is designed to be used in tests to control authentication properties. -type TestIdentity struct { - Authenticated bool - Activated bool - Admin bool -} - -// String representation of a TestIdentity will be reported as "test_identity". -func (t TestIdentity) String() string { - return "test_identity" -} - -// IsAuthenticated returns true if the test has configured it to. -func (t TestIdentity) IsAuthenticated() bool { - return t.Authenticated -} - -// IsActivated returns true if the test has configured it to. -func (t TestIdentity) IsActivated() bool { - return t.Activated -} - -// IsAdmin returns true if the test has configured it to. -func (t TestIdentity) IsAdmin() bool { - return t.Admin -} - -// NewAllPowerfulIdentityForTest returns an authenticated, activated, admin identity for tests. -func NewAllPowerfulIdentityForTest() TestIdentity { - return TestIdentity{true, true, true} -} diff --git a/tavern/auth/authtest/middleware.go b/tavern/auth/authtest/middleware.go deleted file mode 100644 index a8b1e5c7a..000000000 --- a/tavern/auth/authtest/middleware.go +++ /dev/null @@ -1,17 +0,0 @@ -package authtest - -import ( - "net/http" - - "github.com/kcarretto/realm/tavern/auth" -) - -// Middleware that associates an all powerful test identity with the request context. -func Middleware(handler http.Handler) http.HandlerFunc { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - r = r.WithContext( - auth.ContextFromIdentity(r.Context(), NewAllPowerfulIdentityForTest()), - ) - handler.ServeHTTP(w, r) - }) -} diff --git a/tavern/auth/context.go b/tavern/auth/context.go index 2e578e062..39eb4f2aa 100644 --- a/tavern/auth/context.go +++ b/tavern/auth/context.go @@ -66,8 +66,8 @@ func (u *userIdentity) IsAdmin() bool { return u.User.IsAdmin } -// ContextFromIdentity returns a copy of parent context with the given Identity associated with it. -func ContextFromIdentity(ctx context.Context, id Identity) context.Context { +// contextFromIdentity returns a copy of parent context with the given Identity associated with it. +func contextFromIdentity(ctx context.Context, id Identity) context.Context { return context.WithValue(ctx, ctxKey{}, id) } @@ -80,7 +80,7 @@ func ContextFromSessionToken(ctx context.Context, graph *ent.Client, token strin return nil, err } - return ContextFromIdentity(ctx, &userIdentity{true, u}), nil + return contextFromIdentity(ctx, &userIdentity{true, u}), nil } // IdentityFromContext returns the identity associated with the provided context, or nil if no identity is associated. @@ -93,6 +93,16 @@ func IdentityFromContext(ctx context.Context) Identity { return id } +// UserFromContext returns the user identity associated with the provided context, or nil if no user identity or a different identity type is associated. +func UserFromContext(ctx context.Context) *ent.User { + val := ctx.Value(ctxKey{}) + u, ok := val.(*userIdentity) + if !ok || u == nil { + return nil + } + return u.User +} + // IsAuthenticatedContext returns true if the context is associated with an authenticated identity, false otherwise. func IsAuthenticatedContext(ctx context.Context) bool { v, ok := ctx.Value(ctxKey{}).(Identity) diff --git a/tavern/auth/middleware.go b/tavern/auth/middleware.go index a5d158e4d..5080efc73 100644 --- a/tavern/auth/middleware.go +++ b/tavern/auth/middleware.go @@ -1,6 +1,7 @@ package auth import ( + "fmt" "log" "net/http" "time" @@ -8,20 +9,31 @@ import ( "github.com/kcarretto/realm/tavern/ent" ) -// authDisabledIdentity is used whenever authentication has been disabled. -type authDisabledIdentity struct{} - -func (id authDisabledIdentity) String() string { return "auth_disabled" } -func (id authDisabledIdentity) IsAuthenticated() bool { return true } -func (id authDisabledIdentity) IsActivated() bool { return true } -func (id authDisabledIdentity) IsAdmin() bool { return true } - // AuthDisabledMiddleware should only be used when authentication has been disabled. -func AuthDisabledMiddleware(handler http.Handler) http.HandlerFunc { +func AuthDisabledMiddleware(handler http.Handler, graph *ent.Client) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - r = r.WithContext( - ContextFromIdentity(r.Context(), authDisabledIdentity{}), - ) + // Authenticate as the first available user, create one if none exist + authUser, err := graph.User.Query().First(r.Context()) + if err != nil || authUser == nil { + if !ent.IsNotFound(err) { + panic(fmt.Errorf("failed to lookup users: %w", err)) + } + + authUser = graph.User.Create(). + SetName("auth-disabled"). + SetOauthID("auth-disabled"). + SetPhotoURL("https://upload.wikimedia.org/wikipedia/commons/a/ac/Default_pfp.jpg"). + SetIsActivated(true). + SetIsAdmin(true). + SaveX(r.Context()) + } + + ctx, err := ContextFromSessionToken(r.Context(), graph, authUser.SessionToken) + if err != nil { + panic(fmt.Errorf("failed to create authenticated session for user: %w", err)) + } + + r = r.WithContext(ctx) handler.ServeHTTP(w, r) }) } diff --git a/tavern/auth/oauth.go b/tavern/auth/oauth.go index 4e7f5eb16..5b5d21612 100644 --- a/tavern/auth/oauth.go +++ b/tavern/auth/oauth.go @@ -140,7 +140,7 @@ func NewOAuthAuthorizationHandler(cfg oauth2.Config, pubKey ed25519.PublicKey, g // Lookup the user usr, err := graph.User.Query(). - Where(user.OAuthID(profile.OAuthID)). + Where(user.OauthID(profile.OAuthID)). Only(req.Context()) if err == nil { http.SetCookie(w, &http.Cookie{ @@ -166,7 +166,7 @@ func NewOAuthAuthorizationHandler(cfg oauth2.Config, pubKey ed25519.PublicKey, g isTOFU := graph.User.Query().CountX(req.Context()) == 0 usr = graph.User.Create(). SetName(profile.Name). - SetOAuthID(profile.OAuthID). + SetOauthID(profile.OAuthID). SetPhotoURL(profile.PhotoURL). SetIsAdmin(isTOFU). SetIsActivated(isTOFU). diff --git a/tavern/auth/oauth_test.go b/tavern/auth/oauth_test.go index 4b87698f6..cc3a5caa7 100644 --- a/tavern/auth/oauth_test.go +++ b/tavern/auth/oauth_test.go @@ -5,7 +5,7 @@ import ( "crypto/ed25519" "crypto/rand" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -94,7 +94,7 @@ func TestNewOAuthAuthorizationHandler(t *testing.T) { // Setup Mock IDP idp := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) require.NoError(t, err) expected := fmt.Sprintf("client_id=%s&client_secret=%s&code=%s&grant_type=authorization_code&redirect_uri=%s", expectedClientID, expectedClientSecret, expectedCode, expectedRedirect) assert.Equal(t, expected, string(body)) @@ -137,7 +137,7 @@ func TestNewOAuthAuthorizationHandler(t *testing.T) { result := resp.Result() require.Equal(t, http.StatusFound, result.StatusCode) usr := graph.User.Query(). - Where(user.OAuthID("goofygoober")). + Where(user.OauthID("goofygoober")). OnlyX(context.Background()) assert.NotEmpty(t, usr.SessionToken) assert.True(t, usr.IsActivated) @@ -172,7 +172,7 @@ func TestNewOAuthAuthorizationHandler(t *testing.T) { // Second User assertions secondUsr := graph.User.Query(). - Where(user.OAuthID("n00b")). + Where(user.OauthID("n00b")). OnlyX(context.Background()) assert.NotEqual(t, usr.ID, secondUsr.ID) assert.NotEqual(t, usr.SessionToken, secondUsr.SessionToken) diff --git a/tavern/config.go b/tavern/config.go index fcd04b346..24f1b9808 100644 --- a/tavern/config.go +++ b/tavern/config.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "net/http" - "os" "strings" "time" @@ -16,11 +15,42 @@ import ( "github.com/go-sql-driver/mysql" ) +var ( + // EnvEnableTestData if set will populate the database with test data. + EnvEnableTestData = EnvString{"ENABLE_TEST_DATA", ""} + + // EnvOAuthClientID set to configure OAuth Client ID. + // EnvOAuthClientSecret set to configure OAuth Client Secret. + // EnvOAuthDomain set to configure OAuth domain for consent flow redirect. + EnvOAuthClientID = EnvString{"OAUTH_CLIENT_ID", ""} + EnvOAuthClientSecret = EnvString{"OAUTH_CLIENT_SECRET", ""} + EnvOAuthDomain = EnvString{"OAUTH_DOMAIN", ""} + + // EnvMySQLAddr defines the MySQL address to connect to, if unset SQLLite is used. + // EnvMySQLNet defines the network used to connect to MySQL (e.g. unix). + // EnvMySQLUser defines the MySQL user to authenticate as. + // EnvMySQLPasswd defines the password for the MySQL user to authenticate with. + // EnvMySQLDB defines the name of the MySQL database to use. + EnvMySQLAddr = EnvString{"MYSQL_ADDR", ""} + EnvMySQLNet = EnvString{"MYSQL_NET", "tcp"} + EnvMySQLUser = EnvString{"MYSQL_USER", "root"} + EnvMySQLPasswd = EnvString{"MYSQL_PASSWD", ""} + EnvMySQLDB = EnvString{"MYSQL_DB", "tavern"} + + // EnvDBMaxIdleConns defines the maximum number of idle db connections to allow. + // EnvDBMaxOpenConns defines the maximum number of open db connections to allow. + // EnvDBMaxConnLifetime defines the maximum lifetime of a db connection. + EnvDBMaxIdleConns = EnvInteger{"DB_MAX_IDLE_CONNS", 10} + EnvDBMaxOpenConns = EnvInteger{"DB_MAX_OPEN_CONNS", 100} + EnvDBMaxConnLifetime = EnvInteger{"DB_MAX_CONN_LIFETIME", 3600} +) + // Config holds information that controls the behaviour of Tavern type Config struct { srv *http.Server - mysql string + mysqlDSN string + client *ent.Client oauth oauth2.Config } @@ -35,8 +65,8 @@ func (cfg *Config) Connect(options ...ent.Option) (*ent.Client, error) { mysqlDSN = "file:ent?mode=memory&cache=shared&_fk=1" driver = "sqlite3" ) - if cfg != nil && cfg.mysql != "" { - mysqlDSN = cfg.mysql + if cfg != nil && cfg.mysqlDSN != "" { + mysqlDSN = cfg.mysqlDSN driver = "mysql" } @@ -44,23 +74,34 @@ func (cfg *Config) Connect(options ...ent.Option) (*ent.Client, error) { if err != nil { return nil, fmt.Errorf("failed to connect to database: %w", err) } + + // Setup DB Pool Config + var ( + maxIdleConns = EnvDBMaxIdleConns.Int() + maxOpenConns = EnvDBMaxOpenConns.Int() + maxConnLifetime = time.Duration(EnvDBMaxConnLifetime.Int()) * time.Second + ) + if maxIdleConns < 0 { + log.Fatalf("[FATAL] %q must be greater than or equal to 0 if set, got: %d", EnvDBMaxIdleConns.Key, maxIdleConns) + } + if maxOpenConns <= 0 { + log.Fatalf("[FATAL] %q must be greater than 0 if set, got: %d", EnvDBMaxOpenConns.Key, maxOpenConns) + } + if maxConnLifetime <= 10*time.Second { + log.Fatalf("[FATAL] %q must be greater than 10 seconds if set, got: %d", EnvDBMaxConnLifetime.Key, maxConnLifetime) + } + // Get the underlying sql.DB object of the driver. db := drv.DB() - db.SetMaxIdleConns(10) // TODO: Move to environment variable - db.SetMaxOpenConns(100) - db.SetConnMaxLifetime(time.Hour) + db.SetMaxIdleConns(maxIdleConns) + db.SetMaxOpenConns(maxOpenConns) + db.SetConnMaxLifetime(maxConnLifetime) return ent.NewClient(append(options, ent.Driver(drv))...), nil - - // return ent.Open( - // driver, - // mysql, - // options..., - // ) } // IsTestDataEnabled returns true if a value for the "ENABLE_TEST_DATA" environment variable is set. func (cfg *Config) IsTestDataEnabled() bool { - return os.Getenv("ENABLE_TEST_DATA") != "" + return EnvEnableTestData.String() != "" } // ConfigureHTTPServer enables the configuration of the Tavern HTTP server. The endpoint field will be @@ -81,9 +122,9 @@ func ConfigureHTTPServer(address string, options ...func(*http.Server)) func(*Co func ConfigureOAuthFromEnv(redirectPath string) func(*Config) { return func(cfg *Config) { var ( - clientID = os.Getenv("OAUTH_CLIENT_ID") - clientSecret = os.Getenv("OAUTH_CLIENT_SECRET") - domain = os.Getenv("OAUTH_DOMAIN") + clientID = EnvOAuthClientID.String() + clientSecret = EnvOAuthClientSecret.String() + domain = EnvOAuthDomain.String() ) // If none are set, default to auth disabled @@ -122,33 +163,21 @@ func ConfigureOAuthFromEnv(redirectPath string) func(*Config) { // ConfigureMySQLFromEnv sets MySQL config values from the environment func ConfigureMySQLFromEnv() func(*Config) { return func(cfg *Config) { - mysqlConfig := mysql.Config{ - Net: "tcp", - User: "root", - DBName: "tavern", - ParseTime: true, - } + mysqlConfig := mysql.NewConfig() - if envAddr := os.Getenv("MYSQL_ADDR"); envAddr != "" { - mysqlConfig.Addr = envAddr - } else { + mysqlConfig.Addr = EnvMySQLAddr.String() + if mysqlConfig.Addr == "" { log.Printf("[WARN] MySQL is not configured, using SQLite") return } - if envNet := os.Getenv("MYSQL_NET"); envNet != "" { - mysqlConfig.Net = envNet - } - if envUser := os.Getenv("MYSQL_USER"); envUser != "" { - mysqlConfig.User = envUser - } - if envPasswd := os.Getenv("MYSQL_PASSWD"); envPasswd != "" { - mysqlConfig.Passwd = envPasswd - } - if envDB := os.Getenv("MYSQL_DB"); envDB != "" { - mysqlConfig.DBName = envDB - } - cfg.mysql = mysqlConfig.FormatDSN() + mysqlConfig.ParseTime = true + mysqlConfig.Net = EnvMySQLNet.String() + mysqlConfig.User = EnvMySQLUser.String() + mysqlConfig.Passwd = EnvMySQLPasswd.String() + mysqlConfig.DBName = EnvMySQLDB.String() + + cfg.mysqlDSN = mysqlConfig.FormatDSN() } } diff --git a/tavern/config_test.go b/tavern/config_test.go index aa5905b94..e6caba060 100644 --- a/tavern/config_test.go +++ b/tavern/config_test.go @@ -1,46 +1,171 @@ package main import ( + "context" + "fmt" "os" "testing" + "github.com/kcarretto/realm/tavern/ent/migrate" + "github.com/kcarretto/realm/tavern/ent/tag" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "golang.org/x/oauth2" + "golang.org/x/oauth2/google" ) +// TestConfigureMySQLFromEnv ensures environment variables set the proper config values. func TestConfigureMySQLFromEnv(t *testing.T) { - // Always cleanup env - defer func() { - require.NoError(t, os.Unsetenv("MYSQL_ADDR")) - require.NoError(t, os.Unsetenv("MYSQL_NET")) - require.NoError(t, os.Unsetenv("MYSQL_USER")) - require.NoError(t, os.Unsetenv("MYSQL_PASSWD")) - require.NoError(t, os.Unsetenv("MYSQL_DB")) - }() - - // No env vars set - cfg := &Config{} - ConfigureMySQLFromEnv()(cfg) - assert.Empty(t, cfg.mysql, "Set MySQL DSN without any env config") - - // Missing Addr - require.NoError(t, os.Setenv("MYSQL_NET", "unix")) - require.NoError(t, os.Setenv("MYSQL_USER", "admin")) - require.NoError(t, os.Setenv("MYSQL_PASSWD", "changeme")) - require.NoError(t, os.Setenv("MYSQL_DB", "testdb")) - ConfigureMySQLFromEnv()(cfg) - assert.Empty(t, cfg.mysql, "Set MySQL DSN without MYSQL_ADDR in env") - - // w/ Addr - require.NoError(t, os.Setenv("MYSQL_ADDR", "127.0.0.1")) - ConfigureMySQLFromEnv()(cfg) - assert.Equal(t, "admin:changeme@unix(127.0.0.1)/testdb?allowNativePasswords=false&checkConnLiveness=false&parseTime=true&maxAllowedPacket=0", cfg.mysql) - - // Defaults w/ Addr - require.NoError(t, os.Unsetenv("MYSQL_NET")) - require.NoError(t, os.Unsetenv("MYSQL_USER")) - require.NoError(t, os.Unsetenv("MYSQL_PASSWD")) - require.NoError(t, os.Unsetenv("MYSQL_DB")) - ConfigureMySQLFromEnv()(cfg) - assert.Equal(t, "root@tcp(127.0.0.1)/tavern?allowNativePasswords=false&checkConnLiveness=false&parseTime=true&maxAllowedPacket=0", cfg.mysql) + cleanup := func() { + require.NoError(t, os.Unsetenv(EnvMySQLAddr.Key)) + require.NoError(t, os.Unsetenv(EnvMySQLNet.Key)) + require.NoError(t, os.Unsetenv(EnvMySQLUser.Key)) + require.NoError(t, os.Unsetenv(EnvMySQLPasswd.Key)) + require.NoError(t, os.Unsetenv(EnvMySQLDB.Key)) + require.NoError(t, os.Unsetenv(EnvDBMaxIdleConns.Key)) + require.NoError(t, os.Unsetenv(EnvDBMaxOpenConns.Key)) + require.NoError(t, os.Unsetenv(EnvDBMaxConnLifetime.Key)) + } + + t.Run("SQLLite", func(t *testing.T) { + defer cleanup() + + cfg := &Config{} + ConfigureMySQLFromEnv()(cfg) + + }) + + t.Run("Defaults", func(t *testing.T) { + defer cleanup() + + cfg := &Config{} + ConfigureMySQLFromEnv()(cfg) + + assert.Empty(t, cfg.mysqlDSN, "Set MySQL DSN without any env config") + }) + + t.Run("MissingAddr", func(t *testing.T) { + defer cleanup() + require.NoError(t, os.Setenv(EnvMySQLNet.Key, "unix")) + require.NoError(t, os.Setenv(EnvMySQLUser.Key, "admin")) + require.NoError(t, os.Setenv(EnvMySQLPasswd.Key, "changeme")) + require.NoError(t, os.Setenv(EnvMySQLDB.Key, "testdb")) + + cfg := &Config{} + ConfigureMySQLFromEnv()(cfg) + assert.Empty(t, cfg.mysqlDSN, "Set MySQL DSN without MYSQL_ADDR in env") + }) + + t.Run("ValuesWithAddr", func(t *testing.T) { + defer cleanup() + require.NoError(t, os.Setenv(EnvMySQLNet.Key, "unix")) + require.NoError(t, os.Setenv(EnvMySQLUser.Key, "admin")) + require.NoError(t, os.Setenv(EnvMySQLPasswd.Key, "changeme")) + require.NoError(t, os.Setenv(EnvMySQLDB.Key, "testdb")) + require.NoError(t, os.Setenv(EnvMySQLAddr.Key, "127.0.0.1")) + + cfg := &Config{} + ConfigureMySQLFromEnv()(cfg) + + assert.Equal(t, "admin:changeme@unix(127.0.0.1)/testdb?parseTime=true", cfg.mysqlDSN) + }) + + t.Run("DefaultsWithAddr", func(t *testing.T) { + defer cleanup() + require.NoError(t, os.Setenv(EnvMySQLAddr.Key, "127.0.0.1")) + + cfg := &Config{} + ConfigureMySQLFromEnv()(cfg) + + assert.Equal(t, "root@tcp(127.0.0.1)/tavern?parseTime=true", cfg.mysqlDSN) + }) + + t.Run("SQLLite", func(t *testing.T) { + defer cleanup() + require.NoError(t, os.Setenv(EnvDBMaxIdleConns.Key, "1337")) + require.NoError(t, os.Setenv(EnvDBMaxOpenConns.Key, "420")) + require.NoError(t, os.Setenv(EnvDBMaxConnLifetime.Key, "20")) + + cfg := &Config{} + ConfigureMySQLFromEnv()(cfg) + + client, err := cfg.Connect() + require.NoError(t, err) + require.NotNil(t, client) + + require.NoError(t, client.Schema.Create( + context.Background(), + migrate.WithGlobalUniqueID(true), + )) + + // Create an ent to assert we're not impacted by a "no such table:" bug, which can happen if DBLimits are not properly applied + _, err = client.Tag.Create().SetName("Test").SetKind(tag.KindGroup).Save(context.Background()) + require.NoError(t, err) + }) +} + +// TestConfigureOAuthFromEnv ensures environment variables set the proper config values. +func TestConfigureOAuthFromEnv(t *testing.T) { + cleanup := func() { + require.NoError(t, os.Unsetenv(EnvOAuthClientID.Key)) + require.NoError(t, os.Unsetenv(EnvOAuthClientSecret.Key)) + require.NoError(t, os.Unsetenv(EnvOAuthDomain.Key)) + } + + t.Run("NoEnvVarsSet", func(t *testing.T) { + defer cleanup() + + cfg := &Config{} + ConfigureOAuthFromEnv("/redirect/here")(cfg) + + assert.Equal(t, oauth2.Config{}, cfg.oauth) + }) + + t.Run("WithoutDomainSchema", func(t *testing.T) { + defer cleanup() + + expectedDomain := "domain.com" + expectedCfg := oauth2.Config{ + ClientID: "ABCDEFG", + ClientSecret: "beep-boop", + RedirectURL: fmt.Sprintf("https://%s/redirect/here", expectedDomain), + Scopes: []string{ + "https://www.googleapis.com/auth/userinfo.profile", + }, + Endpoint: google.Endpoint, + } + + require.NoError(t, os.Setenv(EnvOAuthClientID.Key, expectedCfg.ClientID)) + require.NoError(t, os.Setenv(EnvOAuthClientSecret.Key, expectedCfg.ClientSecret)) + require.NoError(t, os.Setenv(EnvOAuthDomain.Key, expectedDomain)) + + cfg := &Config{} + ConfigureOAuthFromEnv("/redirect/here")(cfg) + + assert.Equal(t, expectedCfg, cfg.oauth) + }) + + t.Run("Enabled", func(t *testing.T) { + defer cleanup() + + expectedDomain := "http://domain.com" + expectedCfg := oauth2.Config{ + ClientID: "ABCDEFG", + ClientSecret: "beep-boop", + RedirectURL: fmt.Sprintf("%s/redirect/here", expectedDomain), + Scopes: []string{ + "https://www.googleapis.com/auth/userinfo.profile", + }, + Endpoint: google.Endpoint, + } + + require.NoError(t, os.Setenv(EnvOAuthClientID.Key, expectedCfg.ClientID)) + require.NoError(t, os.Setenv(EnvOAuthClientSecret.Key, expectedCfg.ClientSecret)) + require.NoError(t, os.Setenv(EnvOAuthDomain.Key, expectedDomain)) + + cfg := &Config{} + ConfigureOAuthFromEnv("/redirect/here")(cfg) + + assert.Equal(t, expectedCfg, cfg.oauth) + }) } diff --git a/tavern/e2e_test.go b/tavern/e2e_test.go index d34c6622f..c25871a2b 100644 --- a/tavern/e2e_test.go +++ b/tavern/e2e_test.go @@ -63,6 +63,7 @@ func TestEndToEnd(t *testing.T) { "input": map[string]any{ "principal": "root", "hostname": "some_hostname", + "hostPlatform": session.HostPlatformUnknown, "sessionIdentifier": identifier, "hostIdentifier": "uniquely_identifies_host.For_example_a_serial_number", "agentIdentifier": "uniquely_identifies_this_agent", diff --git a/tavern/ent/client.go b/tavern/ent/client.go index 22971e53f..3f7673d2e 100644 --- a/tavern/ent/client.go +++ b/tavern/ent/client.go @@ -10,6 +10,10 @@ import ( "github.com/kcarretto/realm/tavern/ent/migrate" + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/kcarretto/realm/tavern/ent/file" "github.com/kcarretto/realm/tavern/ent/job" "github.com/kcarretto/realm/tavern/ent/session" @@ -17,10 +21,6 @@ import ( "github.com/kcarretto/realm/tavern/ent/task" "github.com/kcarretto/realm/tavern/ent/tome" "github.com/kcarretto/realm/tavern/ent/user" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" ) // Client is the client that holds all ent builders. @@ -48,7 +48,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() @@ -66,6 +66,55 @@ func (c *Client) init() { c.User = NewUserClient(c.config) } +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. @@ -158,13 +207,43 @@ func (c *Client) Close() error { // Use adds the mutation hooks to all the entity clients. // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { - c.File.Use(hooks...) - c.Job.Use(hooks...) - c.Session.Use(hooks...) - c.Tag.Use(hooks...) - c.Task.Use(hooks...) - c.Tome.Use(hooks...) - c.User.Use(hooks...) + for _, n := range []interface{ Use(...Hook) }{ + c.File, c.Job, c.Session, c.Tag, c.Task, c.Tome, c.User, + } { + n.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) { + for _, n := range []interface{ Intercept(...Interceptor) }{ + c.File, c.Job, c.Session, c.Tag, c.Task, c.Tome, c.User, + } { + n.Intercept(interceptors...) + } +} + +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *FileMutation: + return c.File.mutate(ctx, m) + case *JobMutation: + return c.Job.mutate(ctx, m) + case *SessionMutation: + return c.Session.mutate(ctx, m) + case *TagMutation: + return c.Tag.mutate(ctx, m) + case *TaskMutation: + return c.Task.mutate(ctx, m) + case *TomeMutation: + return c.Tome.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } } // FileClient is a client for the File schema. @@ -183,6 +262,12 @@ func (c *FileClient) Use(hooks ...Hook) { c.hooks.File = append(c.hooks.File, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `file.Intercept(f(g(h())))`. +func (c *FileClient) Intercept(interceptors ...Interceptor) { + c.inters.File = append(c.inters.File, interceptors...) +} + // Create returns a builder for creating a File entity. func (c *FileClient) Create() *FileCreate { mutation := newFileMutation(c.config, OpCreate) @@ -235,6 +320,8 @@ func (c *FileClient) DeleteOneID(id int) *FileDeleteOne { func (c *FileClient) Query() *FileQuery { return &FileQuery{ config: c.config, + ctx: &QueryContext{Type: TypeFile}, + inters: c.Interceptors(), } } @@ -258,6 +345,26 @@ func (c *FileClient) Hooks() []Hook { return append(hooks[:len(hooks):len(hooks)], file.Hooks[:]...) } +// Interceptors returns the client interceptors. +func (c *FileClient) Interceptors() []Interceptor { + return c.inters.File +} + +func (c *FileClient) mutate(ctx context.Context, m *FileMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FileCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FileUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FileDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown File mutation op: %q", m.Op()) + } +} + // JobClient is a client for the Job schema. type JobClient struct { config @@ -274,6 +381,12 @@ func (c *JobClient) Use(hooks ...Hook) { c.hooks.Job = append(c.hooks.Job, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `job.Intercept(f(g(h())))`. +func (c *JobClient) Intercept(interceptors ...Interceptor) { + c.inters.Job = append(c.inters.Job, interceptors...) +} + // Create returns a builder for creating a Job entity. func (c *JobClient) Create() *JobCreate { mutation := newJobMutation(c.config, OpCreate) @@ -326,6 +439,8 @@ func (c *JobClient) DeleteOneID(id int) *JobDeleteOne { func (c *JobClient) Query() *JobQuery { return &JobQuery{ config: c.config, + ctx: &QueryContext{Type: TypeJob}, + inters: c.Interceptors(), } } @@ -345,7 +460,7 @@ func (c *JobClient) GetX(ctx context.Context, id int) *Job { // QueryTome queries the tome edge of a Job. func (c *JobClient) QueryTome(j *Job) *TomeQuery { - query := &TomeQuery{config: c.config} + query := (&TomeClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := j.ID step := sqlgraph.NewStep( @@ -361,7 +476,7 @@ func (c *JobClient) QueryTome(j *Job) *TomeQuery { // QueryBundle queries the bundle edge of a Job. func (c *JobClient) QueryBundle(j *Job) *FileQuery { - query := &FileQuery{config: c.config} + query := (&FileClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := j.ID step := sqlgraph.NewStep( @@ -377,7 +492,7 @@ func (c *JobClient) QueryBundle(j *Job) *FileQuery { // QueryTasks queries the tasks edge of a Job. func (c *JobClient) QueryTasks(j *Job) *TaskQuery { - query := &TaskQuery{config: c.config} + query := (&TaskClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := j.ID step := sqlgraph.NewStep( @@ -391,11 +506,47 @@ func (c *JobClient) QueryTasks(j *Job) *TaskQuery { return query } +// QueryCreator queries the creator edge of a Job. +func (c *JobClient) QueryCreator(j *Job) *UserQuery { + query := (&UserClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := j.ID + step := sqlgraph.NewStep( + sqlgraph.From(job.Table, job.FieldID, id), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, job.CreatorTable, job.CreatorColumn), + ) + fromV = sqlgraph.Neighbors(j.driver.Dialect(), step) + return fromV, nil + } + return query +} + // Hooks returns the client hooks. func (c *JobClient) Hooks() []Hook { return c.hooks.Job } +// Interceptors returns the client interceptors. +func (c *JobClient) Interceptors() []Interceptor { + return c.inters.Job +} + +func (c *JobClient) mutate(ctx context.Context, m *JobMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&JobCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&JobUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&JobUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&JobDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Job mutation op: %q", m.Op()) + } +} + // SessionClient is a client for the Session schema. type SessionClient struct { config @@ -412,6 +563,12 @@ func (c *SessionClient) Use(hooks ...Hook) { c.hooks.Session = append(c.hooks.Session, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `session.Intercept(f(g(h())))`. +func (c *SessionClient) Intercept(interceptors ...Interceptor) { + c.inters.Session = append(c.inters.Session, interceptors...) +} + // Create returns a builder for creating a Session entity. func (c *SessionClient) Create() *SessionCreate { mutation := newSessionMutation(c.config, OpCreate) @@ -464,6 +621,8 @@ func (c *SessionClient) DeleteOneID(id int) *SessionDeleteOne { func (c *SessionClient) Query() *SessionQuery { return &SessionQuery{ config: c.config, + ctx: &QueryContext{Type: TypeSession}, + inters: c.Interceptors(), } } @@ -483,7 +642,7 @@ func (c *SessionClient) GetX(ctx context.Context, id int) *Session { // QueryTags queries the tags edge of a Session. func (c *SessionClient) QueryTags(s *Session) *TagQuery { - query := &TagQuery{config: c.config} + query := (&TagClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := s.ID step := sqlgraph.NewStep( @@ -499,7 +658,7 @@ func (c *SessionClient) QueryTags(s *Session) *TagQuery { // QueryTasks queries the tasks edge of a Session. func (c *SessionClient) QueryTasks(s *Session) *TaskQuery { - query := &TaskQuery{config: c.config} + query := (&TaskClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := s.ID step := sqlgraph.NewStep( @@ -518,6 +677,26 @@ func (c *SessionClient) Hooks() []Hook { return c.hooks.Session } +// Interceptors returns the client interceptors. +func (c *SessionClient) Interceptors() []Interceptor { + return c.inters.Session +} + +func (c *SessionClient) mutate(ctx context.Context, m *SessionMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SessionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SessionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SessionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Session mutation op: %q", m.Op()) + } +} + // TagClient is a client for the Tag schema. type TagClient struct { config @@ -534,6 +713,12 @@ func (c *TagClient) Use(hooks ...Hook) { c.hooks.Tag = append(c.hooks.Tag, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `tag.Intercept(f(g(h())))`. +func (c *TagClient) Intercept(interceptors ...Interceptor) { + c.inters.Tag = append(c.inters.Tag, interceptors...) +} + // Create returns a builder for creating a Tag entity. func (c *TagClient) Create() *TagCreate { mutation := newTagMutation(c.config, OpCreate) @@ -586,6 +771,8 @@ func (c *TagClient) DeleteOneID(id int) *TagDeleteOne { func (c *TagClient) Query() *TagQuery { return &TagQuery{ config: c.config, + ctx: &QueryContext{Type: TypeTag}, + inters: c.Interceptors(), } } @@ -605,7 +792,7 @@ func (c *TagClient) GetX(ctx context.Context, id int) *Tag { // QuerySessions queries the sessions edge of a Tag. func (c *TagClient) QuerySessions(t *Tag) *SessionQuery { - query := &SessionQuery{config: c.config} + query := (&SessionClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := t.ID step := sqlgraph.NewStep( @@ -624,6 +811,26 @@ func (c *TagClient) Hooks() []Hook { return c.hooks.Tag } +// Interceptors returns the client interceptors. +func (c *TagClient) Interceptors() []Interceptor { + return c.inters.Tag +} + +func (c *TagClient) mutate(ctx context.Context, m *TagMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TagCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TagUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TagDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Tag mutation op: %q", m.Op()) + } +} + // TaskClient is a client for the Task schema. type TaskClient struct { config @@ -640,6 +847,12 @@ func (c *TaskClient) Use(hooks ...Hook) { c.hooks.Task = append(c.hooks.Task, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `task.Intercept(f(g(h())))`. +func (c *TaskClient) Intercept(interceptors ...Interceptor) { + c.inters.Task = append(c.inters.Task, interceptors...) +} + // Create returns a builder for creating a Task entity. func (c *TaskClient) Create() *TaskCreate { mutation := newTaskMutation(c.config, OpCreate) @@ -692,6 +905,8 @@ func (c *TaskClient) DeleteOneID(id int) *TaskDeleteOne { func (c *TaskClient) Query() *TaskQuery { return &TaskQuery{ config: c.config, + ctx: &QueryContext{Type: TypeTask}, + inters: c.Interceptors(), } } @@ -711,7 +926,7 @@ func (c *TaskClient) GetX(ctx context.Context, id int) *Task { // QueryJob queries the job edge of a Task. func (c *TaskClient) QueryJob(t *Task) *JobQuery { - query := &JobQuery{config: c.config} + query := (&JobClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := t.ID step := sqlgraph.NewStep( @@ -727,7 +942,7 @@ func (c *TaskClient) QueryJob(t *Task) *JobQuery { // QuerySession queries the session edge of a Task. func (c *TaskClient) QuerySession(t *Task) *SessionQuery { - query := &SessionQuery{config: c.config} + query := (&SessionClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := t.ID step := sqlgraph.NewStep( @@ -746,6 +961,26 @@ func (c *TaskClient) Hooks() []Hook { return c.hooks.Task } +// Interceptors returns the client interceptors. +func (c *TaskClient) Interceptors() []Interceptor { + return c.inters.Task +} + +func (c *TaskClient) mutate(ctx context.Context, m *TaskMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Task mutation op: %q", m.Op()) + } +} + // TomeClient is a client for the Tome schema. type TomeClient struct { config @@ -762,6 +997,12 @@ func (c *TomeClient) Use(hooks ...Hook) { c.hooks.Tome = append(c.hooks.Tome, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `tome.Intercept(f(g(h())))`. +func (c *TomeClient) Intercept(interceptors ...Interceptor) { + c.inters.Tome = append(c.inters.Tome, interceptors...) +} + // Create returns a builder for creating a Tome entity. func (c *TomeClient) Create() *TomeCreate { mutation := newTomeMutation(c.config, OpCreate) @@ -814,6 +1055,8 @@ func (c *TomeClient) DeleteOneID(id int) *TomeDeleteOne { func (c *TomeClient) Query() *TomeQuery { return &TomeQuery{ config: c.config, + ctx: &QueryContext{Type: TypeTome}, + inters: c.Interceptors(), } } @@ -833,7 +1076,7 @@ func (c *TomeClient) GetX(ctx context.Context, id int) *Tome { // QueryFiles queries the files edge of a Tome. func (c *TomeClient) QueryFiles(t *Tome) *FileQuery { - query := &FileQuery{config: c.config} + query := (&FileClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := t.ID step := sqlgraph.NewStep( @@ -853,6 +1096,26 @@ func (c *TomeClient) Hooks() []Hook { return append(hooks[:len(hooks):len(hooks)], tome.Hooks[:]...) } +// Interceptors returns the client interceptors. +func (c *TomeClient) Interceptors() []Interceptor { + return c.inters.Tome +} + +func (c *TomeClient) mutate(ctx context.Context, m *TomeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TomeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TomeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TomeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TomeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Tome mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -869,6 +1132,12 @@ func (c *UserClient) Use(hooks ...Hook) { c.hooks.User = append(c.hooks.User, hooks...) } +// Intercept 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) @@ -921,6 +1190,8 @@ func (c *UserClient) DeleteOneID(id int) *UserDeleteOne { func (c *UserClient) Query() *UserQuery { return &UserQuery{ config: c.config, + ctx: &QueryContext{Type: TypeUser}, + inters: c.Interceptors(), } } @@ -942,3 +1213,33 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User { 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()) + } +} + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + File, Job, Session, Tag, Task, Tome, User []ent.Hook + } + inters struct { + File, Job, Session, Tag, Task, Tome, User []ent.Interceptor + } +) diff --git a/tavern/ent/config.go b/tavern/ent/config.go deleted file mode 100644 index 751da553f..000000000 --- a/tavern/ent/config.go +++ /dev/null @@ -1,65 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "entgo.io/ent" - "entgo.io/ent/dialect" -) - -// Option function to configure the client. -type Option func(*config) - -// Config is the configuration for the client and its builder. -type config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks -} - -// hooks per client, for fast access. -type hooks struct { - File []ent.Hook - Job []ent.Hook - Session []ent.Hook - Tag []ent.Hook - Task []ent.Hook - Tome []ent.Hook - User []ent.Hook -} - -// Options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} diff --git a/tavern/ent/context.go b/tavern/ent/context.go deleted file mode 100644 index 7811bfa23..000000000 --- a/tavern/ent/context.go +++ /dev/null @@ -1,33 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" -) - -type clientCtxKey struct{} - -// FromContext returns a Client stored inside a context, or nil if there isn't one. -func FromContext(ctx context.Context) *Client { - c, _ := ctx.Value(clientCtxKey{}).(*Client) - return c -} - -// NewContext returns a new context with the given Client attached. -func NewContext(parent context.Context, c *Client) context.Context { - return context.WithValue(parent, clientCtxKey{}, c) -} - -type txCtxKey struct{} - -// TxFromContext returns a Tx stored inside a context, or nil if there isn't one. -func TxFromContext(ctx context.Context) *Tx { - tx, _ := ctx.Value(txCtxKey{}).(*Tx) - return tx -} - -// NewTxContext returns a new context with the given Tx attached. -func NewTxContext(parent context.Context, tx *Tx) context.Context { - return context.WithValue(parent, txCtxKey{}, tx) -} diff --git a/tavern/ent/ent.go b/tavern/ent/ent.go index 835db4e0b..b1c649de4 100644 --- a/tavern/ent/ent.go +++ b/tavern/ent/ent.go @@ -6,6 +6,7 @@ import ( "context" "errors" "fmt" + "reflect" "entgo.io/ent" "entgo.io/ent/dialect/sql" @@ -21,16 +22,49 @@ 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 ) +type clientCtxKey struct{} + +// FromContext returns a Client stored inside a context, or nil if there isn't one. +func FromContext(ctx context.Context) *Client { + c, _ := ctx.Value(clientCtxKey{}).(*Client) + return c +} + +// NewContext returns a new context with the given Client attached. +func NewContext(parent context.Context, c *Client) context.Context { + return context.WithValue(parent, clientCtxKey{}, c) +} + +type txCtxKey struct{} + +// TxFromContext returns a Tx stored inside a context, or nil if there isn't one. +func TxFromContext(ctx context.Context) *Tx { + tx, _ := ctx.Value(txCtxKey{}).(*Tx) + return tx +} + +// NewTxContext returns a new context with the given Tx attached. +func NewTxContext(parent context.Context, tx *Tx) context.Context { + return context.WithValue(parent, txCtxKey{}, tx) +} + // OrderFunc applies an ordering on the sql selector. type OrderFunc func(*sql.Selector) @@ -474,5 +508,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) diff --git a/tavern/ent/file.go b/tavern/ent/file.go index 5e87bcb79..21f0abfeb 100644 --- a/tavern/ent/file.go +++ b/tavern/ent/file.go @@ -17,9 +17,9 @@ type File struct { // ID of the ent. ID int `json:"id,omitempty"` // Timestamp of when this ent was created - CreatedAt time.Time `json:"createdAt,omitempty"` + CreatedAt time.Time `json:"created_at,omitempty"` // Timestamp of when this ent was last updated - LastModifiedAt time.Time `json:"lastModifiedAt,omitempty"` + LastModifiedAt time.Time `json:"last_modified_at,omitempty"` // The name of the file, used to reference it for downloads Name string `json:"name,omitempty"` // The size of the file in bytes @@ -69,13 +69,13 @@ func (f *File) assignValues(columns []string, values []any) error { f.ID = int(value.Int64) case file.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field createdAt", values[i]) + return fmt.Errorf("unexpected type %T for field created_at", values[i]) } else if value.Valid { f.CreatedAt = value.Time } case file.FieldLastModifiedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field lastModifiedAt", values[i]) + return fmt.Errorf("unexpected type %T for field last_modified_at", values[i]) } else if value.Valid { f.LastModifiedAt = value.Time } @@ -119,7 +119,7 @@ func (f *File) assignValues(columns []string, values []any) error { // Note that you need to call File.Unwrap() before calling this method if this File // was returned from a transaction, and the transaction was committed or rolled back. func (f *File) Update() *FileUpdateOne { - return (&FileClient{config: f.config}).UpdateOne(f) + return NewFileClient(f.config).UpdateOne(f) } // Unwrap unwraps the File entity that was returned from a transaction after it was closed, @@ -138,10 +138,10 @@ func (f *File) String() string { var builder strings.Builder builder.WriteString("File(") builder.WriteString(fmt.Sprintf("id=%v, ", f.ID)) - builder.WriteString("createdAt=") + builder.WriteString("created_at=") builder.WriteString(f.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") - builder.WriteString("lastModifiedAt=") + builder.WriteString("last_modified_at=") builder.WriteString(f.LastModifiedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("name=") @@ -161,9 +161,3 @@ func (f *File) String() string { // Files is a parsable slice of File. type Files []*File - -func (f Files) config(cfg config) { - for _i := range f { - f[_i].config = cfg - } -} diff --git a/tavern/ent/file/file.go b/tavern/ent/file/file.go index 3371c49a5..98e1b1ff6 100644 --- a/tavern/ent/file/file.go +++ b/tavern/ent/file/file.go @@ -13,9 +13,9 @@ const ( Label = "file" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldCreatedAt holds the string denoting the createdat field in the database. + // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" - // FieldLastModifiedAt holds the string denoting the lastmodifiedat field in the database. + // FieldLastModifiedAt holds the string denoting the last_modified_at field in the database. FieldLastModifiedAt = "last_modified_at" // FieldName holds the string denoting the name field in the database. FieldName = "name" @@ -68,11 +68,11 @@ func ValidColumn(column string) bool { // import _ "github.com/kcarretto/realm/tavern/ent/runtime" var ( Hooks [1]ent.Hook - // DefaultCreatedAt holds the default value on creation for the "createdAt" field. + // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time - // DefaultLastModifiedAt holds the default value on creation for the "lastModifiedAt" field. + // DefaultLastModifiedAt holds the default value on creation for the "last_modified_at" field. DefaultLastModifiedAt func() time.Time - // UpdateDefaultLastModifiedAt holds the default value on update for the "lastModifiedAt" field. + // UpdateDefaultLastModifiedAt holds the default value on update for the "last_modified_at" field. UpdateDefaultLastModifiedAt func() time.Time // NameValidator is a validator for the "name" field. It is called by the builders before save. NameValidator func(string) error diff --git a/tavern/ent/file/where.go b/tavern/ent/file/where.go index 002c9e35f..daba25069 100644 --- a/tavern/ent/file/where.go +++ b/tavern/ent/file/where.go @@ -11,569 +11,367 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.File(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.File(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.File(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.File { - return predicate.File(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.File(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.File { - return predicate.File(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.File(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.File(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.File(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.File(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.File(sql.FieldLTE(FieldID, id)) } -// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.File(sql.FieldEQ(FieldCreatedAt, v)) } -// LastModifiedAt applies equality check predicate on the "lastModifiedAt" field. It's identical to LastModifiedAtEQ. +// LastModifiedAt applies equality check predicate on the "last_modified_at" field. It's identical to LastModifiedAtEQ. func LastModifiedAt(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.File(sql.FieldEQ(FieldLastModifiedAt, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldEQ(FieldName, v)) } // Size applies equality check predicate on the "size" field. It's identical to SizeEQ. func Size(v int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSize), v)) - }) + return predicate.File(sql.FieldEQ(FieldSize, v)) } // Hash applies equality check predicate on the "hash" field. It's identical to HashEQ. func Hash(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldEQ(FieldHash, v)) } // Content applies equality check predicate on the "content" field. It's identical to ContentEQ. func Content(v []byte) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldContent), v)) - }) + return predicate.File(sql.FieldEQ(FieldContent, v)) } -// CreatedAtEQ applies the EQ predicate on the "createdAt" field. +// CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.File(sql.FieldEQ(FieldCreatedAt, v)) } -// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.File(sql.FieldNEQ(FieldCreatedAt, v)) } -// CreatedAtIn applies the In predicate on the "createdAt" field. +// CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.File(sql.FieldIn(FieldCreatedAt, vs...)) } -// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.File(sql.FieldNotIn(FieldCreatedAt, vs...)) } -// CreatedAtGT applies the GT predicate on the "createdAt" field. +// CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.File(sql.FieldGT(FieldCreatedAt, v)) } -// CreatedAtGTE applies the GTE predicate on the "createdAt" field. +// CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.File(sql.FieldGTE(FieldCreatedAt, v)) } -// CreatedAtLT applies the LT predicate on the "createdAt" field. +// CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.File(sql.FieldLT(FieldCreatedAt, v)) } -// CreatedAtLTE applies the LTE predicate on the "createdAt" field. +// CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.File(sql.FieldLTE(FieldCreatedAt, v)) } -// LastModifiedAtEQ applies the EQ predicate on the "lastModifiedAt" field. +// LastModifiedAtEQ applies the EQ predicate on the "last_modified_at" field. func LastModifiedAtEQ(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.File(sql.FieldEQ(FieldLastModifiedAt, v)) } -// LastModifiedAtNEQ applies the NEQ predicate on the "lastModifiedAt" field. +// LastModifiedAtNEQ applies the NEQ predicate on the "last_modified_at" field. func LastModifiedAtNEQ(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.File(sql.FieldNEQ(FieldLastModifiedAt, v)) } -// LastModifiedAtIn applies the In predicate on the "lastModifiedAt" field. +// LastModifiedAtIn applies the In predicate on the "last_modified_at" field. func LastModifiedAtIn(vs ...time.Time) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldLastModifiedAt), v...)) - }) + return predicate.File(sql.FieldIn(FieldLastModifiedAt, vs...)) } -// LastModifiedAtNotIn applies the NotIn predicate on the "lastModifiedAt" field. +// LastModifiedAtNotIn applies the NotIn predicate on the "last_modified_at" field. func LastModifiedAtNotIn(vs ...time.Time) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldLastModifiedAt), v...)) - }) + return predicate.File(sql.FieldNotIn(FieldLastModifiedAt, vs...)) } -// LastModifiedAtGT applies the GT predicate on the "lastModifiedAt" field. +// LastModifiedAtGT applies the GT predicate on the "last_modified_at" field. func LastModifiedAtGT(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldLastModifiedAt), v)) - }) + return predicate.File(sql.FieldGT(FieldLastModifiedAt, v)) } -// LastModifiedAtGTE applies the GTE predicate on the "lastModifiedAt" field. +// LastModifiedAtGTE applies the GTE predicate on the "last_modified_at" field. func LastModifiedAtGTE(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldLastModifiedAt), v)) - }) + return predicate.File(sql.FieldGTE(FieldLastModifiedAt, v)) } -// LastModifiedAtLT applies the LT predicate on the "lastModifiedAt" field. +// LastModifiedAtLT applies the LT predicate on the "last_modified_at" field. func LastModifiedAtLT(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldLastModifiedAt), v)) - }) + return predicate.File(sql.FieldLT(FieldLastModifiedAt, v)) } -// LastModifiedAtLTE applies the LTE predicate on the "lastModifiedAt" field. +// LastModifiedAtLTE applies the LTE predicate on the "last_modified_at" field. func LastModifiedAtLTE(v time.Time) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldLastModifiedAt), v)) - }) + return predicate.File(sql.FieldLTE(FieldLastModifiedAt, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.File(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.File(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.File(sql.FieldContainsFold(FieldName, v)) } // SizeEQ applies the EQ predicate on the "size" field. func SizeEQ(v int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSize), v)) - }) + return predicate.File(sql.FieldEQ(FieldSize, v)) } // SizeNEQ applies the NEQ predicate on the "size" field. func SizeNEQ(v int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSize), v)) - }) + return predicate.File(sql.FieldNEQ(FieldSize, v)) } // SizeIn applies the In predicate on the "size" field. func SizeIn(vs ...int) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldSize), v...)) - }) + return predicate.File(sql.FieldIn(FieldSize, vs...)) } // SizeNotIn applies the NotIn predicate on the "size" field. func SizeNotIn(vs ...int) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldSize), v...)) - }) + return predicate.File(sql.FieldNotIn(FieldSize, vs...)) } // SizeGT applies the GT predicate on the "size" field. func SizeGT(v int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldSize), v)) - }) + return predicate.File(sql.FieldGT(FieldSize, v)) } // SizeGTE applies the GTE predicate on the "size" field. func SizeGTE(v int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldSize), v)) - }) + return predicate.File(sql.FieldGTE(FieldSize, v)) } // SizeLT applies the LT predicate on the "size" field. func SizeLT(v int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldSize), v)) - }) + return predicate.File(sql.FieldLT(FieldSize, v)) } // SizeLTE applies the LTE predicate on the "size" field. func SizeLTE(v int) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldSize), v)) - }) + return predicate.File(sql.FieldLTE(FieldSize, v)) } // HashEQ applies the EQ predicate on the "hash" field. func HashEQ(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldEQ(FieldHash, v)) } // HashNEQ applies the NEQ predicate on the "hash" field. func HashNEQ(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldNEQ(FieldHash, v)) } // HashIn applies the In predicate on the "hash" field. func HashIn(vs ...string) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldHash), v...)) - }) + return predicate.File(sql.FieldIn(FieldHash, vs...)) } // HashNotIn applies the NotIn predicate on the "hash" field. func HashNotIn(vs ...string) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldHash), v...)) - }) + return predicate.File(sql.FieldNotIn(FieldHash, vs...)) } // HashGT applies the GT predicate on the "hash" field. func HashGT(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldGT(FieldHash, v)) } // HashGTE applies the GTE predicate on the "hash" field. func HashGTE(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldGTE(FieldHash, v)) } // HashLT applies the LT predicate on the "hash" field. func HashLT(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldLT(FieldHash, v)) } // HashLTE applies the LTE predicate on the "hash" field. func HashLTE(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldLTE(FieldHash, v)) } // HashContains applies the Contains predicate on the "hash" field. func HashContains(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldContains(FieldHash, v)) } // HashHasPrefix applies the HasPrefix predicate on the "hash" field. func HashHasPrefix(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldHasPrefix(FieldHash, v)) } // HashHasSuffix applies the HasSuffix predicate on the "hash" field. func HashHasSuffix(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldHasSuffix(FieldHash, v)) } // HashEqualFold applies the EqualFold predicate on the "hash" field. func HashEqualFold(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldEqualFold(FieldHash, v)) } // HashContainsFold applies the ContainsFold predicate on the "hash" field. func HashContainsFold(v string) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldHash), v)) - }) + return predicate.File(sql.FieldContainsFold(FieldHash, v)) } // ContentEQ applies the EQ predicate on the "content" field. func ContentEQ(v []byte) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldContent), v)) - }) + return predicate.File(sql.FieldEQ(FieldContent, v)) } // ContentNEQ applies the NEQ predicate on the "content" field. func ContentNEQ(v []byte) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldContent), v)) - }) + return predicate.File(sql.FieldNEQ(FieldContent, v)) } // ContentIn applies the In predicate on the "content" field. func ContentIn(vs ...[]byte) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldContent), v...)) - }) + return predicate.File(sql.FieldIn(FieldContent, vs...)) } // ContentNotIn applies the NotIn predicate on the "content" field. func ContentNotIn(vs ...[]byte) predicate.File { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.File(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldContent), v...)) - }) + return predicate.File(sql.FieldNotIn(FieldContent, vs...)) } // ContentGT applies the GT predicate on the "content" field. func ContentGT(v []byte) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldContent), v)) - }) + return predicate.File(sql.FieldGT(FieldContent, v)) } // ContentGTE applies the GTE predicate on the "content" field. func ContentGTE(v []byte) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldContent), v)) - }) + return predicate.File(sql.FieldGTE(FieldContent, v)) } // ContentLT applies the LT predicate on the "content" field. func ContentLT(v []byte) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldContent), v)) - }) + return predicate.File(sql.FieldLT(FieldContent, v)) } // ContentLTE applies the LTE predicate on the "content" field. func ContentLTE(v []byte) predicate.File { - return predicate.File(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldContent), v)) - }) + return predicate.File(sql.FieldLTE(FieldContent, v)) } // And groups predicates with the AND operator between them. diff --git a/tavern/ent/file_create.go b/tavern/ent/file_create.go index 9fe6a0943..ef83abd17 100644 --- a/tavern/ent/file_create.go +++ b/tavern/ent/file_create.go @@ -20,13 +20,13 @@ type FileCreate struct { hooks []Hook } -// SetCreatedAt sets the "createdAt" field. +// SetCreatedAt sets the "created_at" field. func (fc *FileCreate) SetCreatedAt(t time.Time) *FileCreate { fc.mutation.SetCreatedAt(t) return fc } -// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (fc *FileCreate) SetNillableCreatedAt(t *time.Time) *FileCreate { if t != nil { fc.SetCreatedAt(*t) @@ -34,13 +34,13 @@ func (fc *FileCreate) SetNillableCreatedAt(t *time.Time) *FileCreate { return fc } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (fc *FileCreate) SetLastModifiedAt(t time.Time) *FileCreate { fc.mutation.SetLastModifiedAt(t) return fc } -// SetNillableLastModifiedAt sets the "lastModifiedAt" field if the given value is not nil. +// SetNillableLastModifiedAt sets the "last_modified_at" field if the given value is not nil. func (fc *FileCreate) SetNillableLastModifiedAt(t *time.Time) *FileCreate { if t != nil { fc.SetLastModifiedAt(*t) @@ -87,52 +87,10 @@ func (fc *FileCreate) Mutation() *FileMutation { // Save creates the File in the database. func (fc *FileCreate) Save(ctx context.Context) (*File, error) { - var ( - err error - node *File - ) if err := fc.defaults(); err != nil { return nil, err } - if len(fc.hooks) == 0 { - if err = fc.check(); err != nil { - return nil, err - } - node, err = fc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*FileMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = fc.check(); err != nil { - return nil, err - } - fc.mutation = mutation - if node, err = fc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(fc.hooks) - 1; i >= 0; i-- { - if fc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = fc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, fc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*File) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from FileMutation", v) - } - node = nv - } - return node, err + return withHooks[*File, FileMutation](ctx, fc.sqlSave, fc.mutation, fc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -183,10 +141,10 @@ func (fc *FileCreate) defaults() error { // check runs all checks and user-defined validators on the builder. func (fc *FileCreate) check() error { if _, ok := fc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "File.createdAt"`)} + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "File.created_at"`)} } if _, ok := fc.mutation.LastModifiedAt(); !ok { - return &ValidationError{Name: "lastModifiedAt", err: errors.New(`ent: missing required field "File.lastModifiedAt"`)} + return &ValidationError{Name: "last_modified_at", err: errors.New(`ent: missing required field "File.last_modified_at"`)} } if _, ok := fc.mutation.Name(); !ok { return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "File.name"`)} @@ -219,6 +177,9 @@ func (fc *FileCreate) check() error { } func (fc *FileCreate) sqlSave(ctx context.Context) (*File, error) { + if err := fc.check(); err != nil { + return nil, err + } _node, _spec := fc.createSpec() if err := sqlgraph.CreateNode(ctx, fc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -228,19 +189,15 @@ func (fc *FileCreate) sqlSave(ctx context.Context) (*File, error) { } id := _spec.ID.Value.(int64) _node.ID = int(id) + fc.mutation.id = &_node.ID + fc.mutation.done = true return _node, nil } func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) { var ( _node = &File{config: fc.config} - _spec = &sqlgraph.CreateSpec{ - Table: file.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: file.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(file.Table, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt)) ) if value, ok := fc.mutation.CreatedAt(); ok { _spec.SetField(file.FieldCreatedAt, field.TypeTime, value) diff --git a/tavern/ent/file_delete.go b/tavern/ent/file_delete.go index 36ec32fa3..7dfcc5ea4 100644 --- a/tavern/ent/file_delete.go +++ b/tavern/ent/file_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (fd *FileDelete) Where(ps ...predicate.File) *FileDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (fd *FileDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(fd.hooks) == 0 { - affected, err = fd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*FileMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - fd.mutation = mutation - affected, err = fd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(fd.hooks) - 1; i >= 0; i-- { - if fd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = fd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, fd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, FileMutation](ctx, fd.sqlExec, fd.mutation, fd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (fd *FileDelete) ExecX(ctx context.Context) int { } func (fd *FileDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: file.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: file.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(file.Table, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt)) if ps := fd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (fd *FileDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + fd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type FileDeleteOne struct { fd *FileDelete } +// Where appends a list predicates to the FileDelete builder. +func (fdo *FileDeleteOne) Where(ps ...predicate.File) *FileDeleteOne { + fdo.fd.mutation.Where(ps...) + return fdo +} + // Exec executes the deletion query. func (fdo *FileDeleteOne) Exec(ctx context.Context) error { n, err := fdo.fd.Exec(ctx) @@ -111,5 +82,7 @@ func (fdo *FileDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (fdo *FileDeleteOne) ExecX(ctx context.Context) { - fdo.fd.ExecX(ctx) + if err := fdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/tavern/ent/file_query.go b/tavern/ent/file_query.go index a48ea9917..6cabf18c7 100644 --- a/tavern/ent/file_query.go +++ b/tavern/ent/file_query.go @@ -17,11 +17,9 @@ import ( // FileQuery is the builder for querying File entities. type FileQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.File withFKs bool modifiers []func(*sql.Selector) @@ -37,26 +35,26 @@ func (fq *FileQuery) Where(ps ...predicate.File) *FileQuery { return fq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (fq *FileQuery) Limit(limit int) *FileQuery { - fq.limit = &limit + fq.ctx.Limit = &limit return fq } -// Offset adds an offset step to the query. +// Offset to start from. func (fq *FileQuery) Offset(offset int) *FileQuery { - fq.offset = &offset + fq.ctx.Offset = &offset return fq } // 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 (fq *FileQuery) Unique(unique bool) *FileQuery { - fq.unique = &unique + fq.ctx.Unique = &unique return fq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (fq *FileQuery) Order(o ...OrderFunc) *FileQuery { fq.order = append(fq.order, o...) return fq @@ -65,7 +63,7 @@ func (fq *FileQuery) Order(o ...OrderFunc) *FileQuery { // First returns the first File entity from the query. // Returns a *NotFoundError when no File was found. func (fq *FileQuery) First(ctx context.Context) (*File, error) { - nodes, err := fq.Limit(1).All(ctx) + nodes, err := fq.Limit(1).All(setContextOp(ctx, fq.ctx, "First")) if err != nil { return nil, err } @@ -88,7 +86,7 @@ func (fq *FileQuery) FirstX(ctx context.Context) *File { // Returns a *NotFoundError when no File ID was found. func (fq *FileQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = fq.Limit(1).IDs(ctx); err != nil { + if ids, err = fq.Limit(1).IDs(setContextOp(ctx, fq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -111,7 +109,7 @@ func (fq *FileQuery) FirstIDX(ctx context.Context) int { // Returns a *NotSingularError when more than one File entity is found. // Returns a *NotFoundError when no File entities are found. func (fq *FileQuery) Only(ctx context.Context) (*File, error) { - nodes, err := fq.Limit(2).All(ctx) + nodes, err := fq.Limit(2).All(setContextOp(ctx, fq.ctx, "Only")) if err != nil { return nil, err } @@ -139,7 +137,7 @@ func (fq *FileQuery) OnlyX(ctx context.Context) *File { // Returns a *NotFoundError when no entities are found. func (fq *FileQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = fq.Limit(2).IDs(ctx); err != nil { + if ids, err = fq.Limit(2).IDs(setContextOp(ctx, fq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -164,10 +162,12 @@ func (fq *FileQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of Files. func (fq *FileQuery) All(ctx context.Context) ([]*File, error) { + ctx = setContextOp(ctx, fq.ctx, "All") if err := fq.prepareQuery(ctx); err != nil { return nil, err } - return fq.sqlAll(ctx) + qr := querierAll[[]*File, *FileQuery]() + return withInterceptors[[]*File](ctx, fq, qr, fq.inters) } // AllX is like All, but panics if an error occurs. @@ -180,9 +180,12 @@ func (fq *FileQuery) AllX(ctx context.Context) []*File { } // IDs executes the query and returns a list of File IDs. -func (fq *FileQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := fq.Select(file.FieldID).Scan(ctx, &ids); err != nil { +func (fq *FileQuery) IDs(ctx context.Context) (ids []int, err error) { + if fq.ctx.Unique == nil && fq.path != nil { + fq.Unique(true) + } + ctx = setContextOp(ctx, fq.ctx, "IDs") + if err = fq.Select(file.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -199,10 +202,11 @@ func (fq *FileQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (fq *FileQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, fq.ctx, "Count") if err := fq.prepareQuery(ctx); err != nil { return 0, err } - return fq.sqlCount(ctx) + return withInterceptors[int](ctx, fq, querierCount[*FileQuery](), fq.inters) } // CountX is like Count, but panics if an error occurs. @@ -216,10 +220,15 @@ func (fq *FileQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (fq *FileQuery) Exist(ctx context.Context) (bool, error) { - if err := fq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, fq.ctx, "Exist") + switch _, err := fq.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 fq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -239,14 +248,13 @@ func (fq *FileQuery) Clone() *FileQuery { } return &FileQuery{ config: fq.config, - limit: fq.limit, - offset: fq.offset, + ctx: fq.ctx.Clone(), order: append([]OrderFunc{}, fq.order...), + inters: append([]Interceptor{}, fq.inters...), predicates: append([]predicate.File{}, fq.predicates...), // clone intermediate query. - sql: fq.sql.Clone(), - path: fq.path, - unique: fq.unique, + sql: fq.sql.Clone(), + path: fq.path, } } @@ -256,7 +264,7 @@ func (fq *FileQuery) Clone() *FileQuery { // Example: // // var v []struct { -// CreatedAt time.Time `json:"createdAt,omitempty"` +// CreatedAt time.Time `json:"created_at,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -265,16 +273,11 @@ func (fq *FileQuery) Clone() *FileQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (fq *FileQuery) GroupBy(field string, fields ...string) *FileGroupBy { - grbuild := &FileGroupBy{config: fq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := fq.prepareQuery(ctx); err != nil { - return nil, err - } - return fq.sqlQuery(ctx), nil - } + fq.ctx.Fields = append([]string{field}, fields...) + grbuild := &FileGroupBy{build: fq} + grbuild.flds = &fq.ctx.Fields grbuild.label = file.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -284,18 +287,18 @@ func (fq *FileQuery) GroupBy(field string, fields ...string) *FileGroupBy { // Example: // // var v []struct { -// CreatedAt time.Time `json:"createdAt,omitempty"` +// CreatedAt time.Time `json:"created_at,omitempty"` // } // // client.File.Query(). // Select(file.FieldCreatedAt). // Scan(ctx, &v) func (fq *FileQuery) Select(fields ...string) *FileSelect { - fq.fields = append(fq.fields, fields...) - selbuild := &FileSelect{FileQuery: fq} - selbuild.label = file.Label - selbuild.flds, selbuild.scan = &fq.fields, selbuild.Scan - return selbuild + fq.ctx.Fields = append(fq.ctx.Fields, fields...) + sbuild := &FileSelect{FileQuery: fq} + sbuild.label = file.Label + sbuild.flds, sbuild.scan = &fq.ctx.Fields, sbuild.Scan + return sbuild } // Aggregate returns a FileSelect configured with the given aggregations. @@ -304,7 +307,17 @@ func (fq *FileQuery) Aggregate(fns ...AggregateFunc) *FileSelect { } func (fq *FileQuery) prepareQuery(ctx context.Context) error { - for _, f := range fq.fields { + for _, inter := range fq.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, fq); err != nil { + return err + } + } + } + for _, f := range fq.ctx.Fields { if !file.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -361,41 +374,22 @@ func (fq *FileQuery) sqlCount(ctx context.Context) (int, error) { if len(fq.modifiers) > 0 { _spec.Modifiers = fq.modifiers } - _spec.Node.Columns = fq.fields - if len(fq.fields) > 0 { - _spec.Unique = fq.unique != nil && *fq.unique + _spec.Node.Columns = fq.ctx.Fields + if len(fq.ctx.Fields) > 0 { + _spec.Unique = fq.ctx.Unique != nil && *fq.ctx.Unique } return sqlgraph.CountNodes(ctx, fq.driver, _spec) } -func (fq *FileQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := fq.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 (fq *FileQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: file.Table, - Columns: file.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: file.FieldID, - }, - }, - From: fq.sql, - Unique: true, - } - if unique := fq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(file.Table, file.Columns, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt)) + _spec.From = fq.sql + if unique := fq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if fq.path != nil { + _spec.Unique = true } - if fields := fq.fields; len(fields) > 0 { + if fields := fq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, file.FieldID) for i := range fields { @@ -411,10 +405,10 @@ func (fq *FileQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := fq.limit; limit != nil { + if limit := fq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := fq.offset; offset != nil { + if offset := fq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := fq.order; len(ps) > 0 { @@ -430,7 +424,7 @@ func (fq *FileQuery) querySpec() *sqlgraph.QuerySpec { func (fq *FileQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(fq.driver.Dialect()) t1 := builder.Table(file.Table) - columns := fq.fields + columns := fq.ctx.Fields if len(columns) == 0 { columns = file.Columns } @@ -439,7 +433,7 @@ func (fq *FileQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = fq.sql selector.Select(selector.Columns(columns...)...) } - if fq.unique != nil && *fq.unique { + if fq.ctx.Unique != nil && *fq.ctx.Unique { selector.Distinct() } for _, p := range fq.predicates { @@ -448,12 +442,12 @@ func (fq *FileQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range fq.order { p(selector) } - if offset := fq.offset; offset != nil { + if offset := fq.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 := fq.limit; limit != nil { + if limit := fq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -461,13 +455,8 @@ func (fq *FileQuery) sqlQuery(ctx context.Context) *sql.Selector { // FileGroupBy is the group-by builder for File entities. type FileGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *FileQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -476,58 +465,46 @@ func (fgb *FileGroupBy) Aggregate(fns ...AggregateFunc) *FileGroupBy { return fgb } -// 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 (fgb *FileGroupBy) Scan(ctx context.Context, v any) error { - query, err := fgb.path(ctx) - if err != nil { + ctx = setContextOp(ctx, fgb.build.ctx, "GroupBy") + if err := fgb.build.prepareQuery(ctx); err != nil { return err } - fgb.sql = query - return fgb.sqlScan(ctx, v) + return scanWithInterceptors[*FileQuery, *FileGroupBy](ctx, fgb.build, fgb, fgb.build.inters, v) } -func (fgb *FileGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range fgb.fields { - if !file.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} +func (fgb *FileGroupBy) sqlScan(ctx context.Context, root *FileQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(fgb.fns)) + for _, fn := range fgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*fgb.flds)+len(fgb.fns)) + for _, f := range *fgb.flds { + columns = append(columns, selector.C(f)) } + columns = append(columns, aggregation...) + selector.Select(columns...) } - selector := fgb.sqlQuery() + selector.GroupBy(selector.Columns(*fgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := fgb.driver.Query(ctx, query, args, rows); err != nil { + if err := fgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (fgb *FileGroupBy) sqlQuery() *sql.Selector { - selector := fgb.sql.Select() - aggregation := make([]string, 0, len(fgb.fns)) - for _, fn := range fgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(fgb.fields)+len(fgb.fns)) - for _, f := range fgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(fgb.fields...)...) -} - // FileSelect is the builder for selecting fields of File entities. type FileSelect struct { *FileQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -538,26 +515,27 @@ func (fs *FileSelect) Aggregate(fns ...AggregateFunc) *FileSelect { // Scan applies the selector query and scans the result into the given value. func (fs *FileSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, fs.ctx, "Select") if err := fs.prepareQuery(ctx); err != nil { return err } - fs.sql = fs.FileQuery.sqlQuery(ctx) - return fs.sqlScan(ctx, v) + return scanWithInterceptors[*FileQuery, *FileSelect](ctx, fs.FileQuery, fs, fs.inters, v) } -func (fs *FileSelect) sqlScan(ctx context.Context, v any) error { +func (fs *FileSelect) sqlScan(ctx context.Context, root *FileQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(fs.fns)) for _, fn := range fs.fns { - aggregation = append(aggregation, fn(fs.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*fs.selector.flds); { case n == 0 && len(aggregation) > 0: - fs.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - fs.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := fs.sql.Query() + query, args := selector.Query() if err := fs.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/tavern/ent/file_update.go b/tavern/ent/file_update.go index 1b12a6d44..e036a080d 100644 --- a/tavern/ent/file_update.go +++ b/tavern/ent/file_update.go @@ -28,7 +28,7 @@ func (fu *FileUpdate) Where(ps ...predicate.File) *FileUpdate { return fu } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (fu *FileUpdate) SetLastModifiedAt(t time.Time) *FileUpdate { fu.mutation.SetLastModifiedAt(t) return fu @@ -80,43 +80,10 @@ func (fu *FileUpdate) Mutation() *FileMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (fu *FileUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) if err := fu.defaults(); err != nil { return 0, err } - if len(fu.hooks) == 0 { - if err = fu.check(); err != nil { - return 0, err - } - affected, err = fu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*FileMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = fu.check(); err != nil { - return 0, err - } - fu.mutation = mutation - affected, err = fu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(fu.hooks) - 1; i >= 0; i-- { - if fu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = fu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, fu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, FileMutation](ctx, fu.sqlSave, fu.mutation, fu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -174,16 +141,10 @@ func (fu *FileUpdate) check() error { } func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: file.Table, - Columns: file.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: file.FieldID, - }, - }, + if err := fu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(file.Table, file.Columns, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt)) if ps := fu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -217,6 +178,7 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + fu.mutation.done = true return n, nil } @@ -228,7 +190,7 @@ type FileUpdateOne struct { mutation *FileMutation } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (fuo *FileUpdateOne) SetLastModifiedAt(t time.Time) *FileUpdateOne { fuo.mutation.SetLastModifiedAt(t) return fuo @@ -278,6 +240,12 @@ func (fuo *FileUpdateOne) Mutation() *FileMutation { return fuo.mutation } +// Where appends a list predicates to the FileUpdate builder. +func (fuo *FileUpdateOne) Where(ps ...predicate.File) *FileUpdateOne { + fuo.mutation.Where(ps...) + return fuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (fuo *FileUpdateOne) Select(field string, fields ...string) *FileUpdateOne { @@ -287,49 +255,10 @@ func (fuo *FileUpdateOne) Select(field string, fields ...string) *FileUpdateOne // Save executes the query and returns the updated File entity. func (fuo *FileUpdateOne) Save(ctx context.Context) (*File, error) { - var ( - err error - node *File - ) if err := fuo.defaults(); err != nil { return nil, err } - if len(fuo.hooks) == 0 { - if err = fuo.check(); err != nil { - return nil, err - } - node, err = fuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*FileMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = fuo.check(); err != nil { - return nil, err - } - fuo.mutation = mutation - node, err = fuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(fuo.hooks) - 1; i >= 0; i-- { - if fuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = fuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, fuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*File) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from FileMutation", v) - } - node = nv - } - return node, err + return withHooks[*File, FileMutation](ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -387,16 +316,10 @@ func (fuo *FileUpdateOne) check() error { } func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: file.Table, - Columns: file.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: file.FieldID, - }, - }, + if err := fuo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(file.Table, file.Columns, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt)) id, ok := fuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "File.id" for update`)} @@ -450,5 +373,6 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) } return nil, err } + fuo.mutation.done = true return _node, nil } diff --git a/tavern/ent/gql_collection.go b/tavern/ent/gql_collection.go index 9d866461a..5baa878eb 100644 --- a/tavern/ent/gql_collection.go +++ b/tavern/ent/gql_collection.go @@ -97,7 +97,7 @@ func (j *JobQuery) collectField(ctx context.Context, op *graphql.OperationContex var ( alias = field.Alias path = append(path, alias) - query = &TomeQuery{config: j.config} + query = (&TomeClient{config: j.config}).Query() ) if err := query.collectField(ctx, op, field, path, satisfies...); err != nil { return err @@ -107,7 +107,7 @@ func (j *JobQuery) collectField(ctx context.Context, op *graphql.OperationContex var ( alias = field.Alias path = append(path, alias) - query = &FileQuery{config: j.config} + query = (&FileClient{config: j.config}).Query() ) if err := query.collectField(ctx, op, field, path, satisfies...); err != nil { return err @@ -117,7 +117,7 @@ func (j *JobQuery) collectField(ctx context.Context, op *graphql.OperationContex var ( alias = field.Alias path = append(path, alias) - query = &TaskQuery{config: j.config} + query = (&TaskClient{config: j.config}).Query() ) if err := query.collectField(ctx, op, field, path, satisfies...); err != nil { return err @@ -125,6 +125,16 @@ func (j *JobQuery) collectField(ctx context.Context, op *graphql.OperationContex j.WithNamedTasks(alias, func(wq *TaskQuery) { *wq = *query }) + case "creator": + var ( + alias = field.Alias + path = append(path, alias) + query = (&UserClient{config: j.config}).Query() + ) + if err := query.collectField(ctx, op, field, path, satisfies...); err != nil { + return err + } + j.withCreator = query } } return nil @@ -201,7 +211,7 @@ func (s *SessionQuery) collectField(ctx context.Context, op *graphql.OperationCo var ( alias = field.Alias path = append(path, alias) - query = &TagQuery{config: s.config} + query = (&TagClient{config: s.config}).Query() ) if err := query.collectField(ctx, op, field, path, satisfies...); err != nil { return err @@ -213,7 +223,7 @@ func (s *SessionQuery) collectField(ctx context.Context, op *graphql.OperationCo var ( alias = field.Alias path = append(path, alias) - query = &TaskQuery{config: s.config} + query = (&TaskClient{config: s.config}).Query() ) if err := query.collectField(ctx, op, field, path, satisfies...); err != nil { return err @@ -297,7 +307,7 @@ func (t *TagQuery) collectField(ctx context.Context, op *graphql.OperationContex var ( alias = field.Alias path = append(path, alias) - query = &SessionQuery{config: t.config} + query = (&SessionClient{config: t.config}).Query() ) if err := query.collectField(ctx, op, field, path, satisfies...); err != nil { return err @@ -381,7 +391,7 @@ func (t *TaskQuery) collectField(ctx context.Context, op *graphql.OperationConte var ( alias = field.Alias path = append(path, alias) - query = &JobQuery{config: t.config} + query = (&JobClient{config: t.config}).Query() ) if err := query.collectField(ctx, op, field, path, satisfies...); err != nil { return err @@ -391,7 +401,7 @@ func (t *TaskQuery) collectField(ctx context.Context, op *graphql.OperationConte var ( alias = field.Alias path = append(path, alias) - query = &SessionQuery{config: t.config} + query = (&SessionClient{config: t.config}).Query() ) if err := query.collectField(ctx, op, field, path, satisfies...); err != nil { return err @@ -473,7 +483,7 @@ func (t *TomeQuery) collectField(ctx context.Context, op *graphql.OperationConte var ( alias = field.Alias path = append(path, alias) - query = &FileQuery{config: t.config} + query = (&FileClient{config: t.config}).Query() ) if err := query.collectField(ctx, op, field, path, satisfies...); err != nil { return err diff --git a/tavern/ent/gql_edge.go b/tavern/ent/gql_edge.go index 89c309c2c..9fd699274 100644 --- a/tavern/ent/gql_edge.go +++ b/tavern/ent/gql_edge.go @@ -36,6 +36,14 @@ func (j *Job) Tasks(ctx context.Context) (result []*Task, err error) { return result, err } +func (j *Job) Creator(ctx context.Context) (*User, error) { + result, err := j.Edges.CreatorOrErr() + if IsNotLoaded(err) { + result, err = j.QueryCreator().Only(ctx) + } + return result, MaskNotFound(err) +} + func (s *Session) Tags(ctx context.Context) (result []*Tag, err error) { if fc := graphql.GetFieldContext(ctx); fc != nil && fc.Field.Alias != "" { result, err = s.NamedTags(graphql.GetFieldContext(ctx).Field.Alias) diff --git a/tavern/ent/gql_mutation_input.go b/tavern/ent/gql_mutation_input.go index 7e9011abb..6836ce567 100644 --- a/tavern/ent/gql_mutation_input.go +++ b/tavern/ent/gql_mutation_input.go @@ -2,7 +2,9 @@ package ent -import "github.com/kcarretto/realm/tavern/ent/tag" +import ( + "github.com/kcarretto/realm/tavern/ent/tag" +) // CreateJobInput represents a mutation input for creating jobs. type CreateJobInput struct { @@ -31,6 +33,7 @@ type UpdateSessionInput struct { Name *string ClearHostname bool Hostname *string + ClearTags bool AddTagIDs []int RemoveTagIDs []int } @@ -46,6 +49,9 @@ func (i *UpdateSessionInput) Mutate(m *SessionMutation) { if v := i.Hostname; v != nil { m.SetHostname(*v) } + if i.ClearTags { + m.ClearTags() + } if v := i.AddTagIDs; len(v) > 0 { m.AddTagIDs(v...) } @@ -92,6 +98,7 @@ func (c *TagCreate) SetInput(i CreateTagInput) *TagCreate { type UpdateTagInput struct { Name *string Kind *tag.Kind + ClearSessions bool AddSessionIDs []int RemoveSessionIDs []int } @@ -104,6 +111,9 @@ func (i *UpdateTagInput) Mutate(m *TagMutation) { if v := i.Kind; v != nil { m.SetKind(*v) } + if i.ClearSessions { + m.ClearSessions() + } if v := i.AddSessionIDs; len(v) > 0 { m.AddSessionIDs(v...) } @@ -128,7 +138,7 @@ func (c *TagUpdateOne) SetInput(i UpdateTagInput) *TagUpdateOne { type CreateTomeInput struct { Name string Description string - Parameters *string + ParamDefs *string Eldritch string FileIDs []int } @@ -137,8 +147,8 @@ type CreateTomeInput struct { func (i *CreateTomeInput) Mutate(m *TomeMutation) { m.SetName(i.Name) m.SetDescription(i.Description) - if v := i.Parameters; v != nil { - m.SetParameters(*v) + if v := i.ParamDefs; v != nil { + m.SetParamDefs(*v) } m.SetEldritch(i.Eldritch) if v := i.FileIDs; len(v) > 0 { diff --git a/tavern/ent/gql_node.go b/tavern/ent/gql_node.go index 1c52cc3b2..8fc4d3cfb 100644 --- a/tavern/ent/gql_node.go +++ b/tavern/ent/gql_node.go @@ -4,7 +4,6 @@ package ent import ( "context" - "encoding/json" "fmt" "sync" "sync/atomic" @@ -27,493 +26,29 @@ import ( // Noder wraps the basic Node method. type Noder interface { - Node(context.Context) (*Node, error) + IsNode() } -// Node in the graph. -type Node struct { - ID int `json:"id,omitempty"` // node id. - Type string `json:"type,omitempty"` // node type. - Fields []*Field `json:"fields,omitempty"` // node fields. - Edges []*Edge `json:"edges,omitempty"` // node edges. -} +// IsNode implements the Node interface check for GQLGen. +func (n *File) IsNode() {} -// Field of a node. -type Field struct { - Type string `json:"type,omitempty"` // field type. - Name string `json:"name,omitempty"` // field name (as in struct). - Value string `json:"value,omitempty"` // stringified value. -} +// IsNode implements the Node interface check for GQLGen. +func (n *Job) IsNode() {} -// Edges between two nodes. -type Edge struct { - Type string `json:"type,omitempty"` // edge type. - Name string `json:"name,omitempty"` // edge name. - IDs []int `json:"ids,omitempty"` // node ids (where this edge point to). -} +// IsNode implements the Node interface check for GQLGen. +func (n *Session) IsNode() {} -func (f *File) Node(ctx context.Context) (node *Node, err error) { - node = &Node{ - ID: f.ID, - Type: "File", - Fields: make([]*Field, 5), - Edges: make([]*Edge, 0), - } - var buf []byte - if buf, err = json.Marshal(f.CreatedAt); err != nil { - return nil, err - } - node.Fields[0] = &Field{ - Type: "time.Time", - Name: "createdAt", - Value: string(buf), - } - if buf, err = json.Marshal(f.LastModifiedAt); err != nil { - return nil, err - } - node.Fields[1] = &Field{ - Type: "time.Time", - Name: "lastModifiedAt", - Value: string(buf), - } - if buf, err = json.Marshal(f.Name); err != nil { - return nil, err - } - node.Fields[2] = &Field{ - Type: "string", - Name: "name", - Value: string(buf), - } - if buf, err = json.Marshal(f.Size); err != nil { - return nil, err - } - node.Fields[3] = &Field{ - Type: "int", - Name: "size", - Value: string(buf), - } - if buf, err = json.Marshal(f.Hash); err != nil { - return nil, err - } - node.Fields[4] = &Field{ - Type: "string", - Name: "hash", - Value: string(buf), - } - return node, nil -} +// IsNode implements the Node interface check for GQLGen. +func (n *Tag) IsNode() {} -func (j *Job) Node(ctx context.Context) (node *Node, err error) { - node = &Node{ - ID: j.ID, - Type: "Job", - Fields: make([]*Field, 4), - Edges: make([]*Edge, 3), - } - var buf []byte - if buf, err = json.Marshal(j.CreatedAt); err != nil { - return nil, err - } - node.Fields[0] = &Field{ - Type: "time.Time", - Name: "createdAt", - Value: string(buf), - } - if buf, err = json.Marshal(j.LastModifiedAt); err != nil { - return nil, err - } - node.Fields[1] = &Field{ - Type: "time.Time", - Name: "lastModifiedAt", - Value: string(buf), - } - if buf, err = json.Marshal(j.Name); err != nil { - return nil, err - } - node.Fields[2] = &Field{ - Type: "string", - Name: "name", - Value: string(buf), - } - if buf, err = json.Marshal(j.Parameters); err != nil { - return nil, err - } - node.Fields[3] = &Field{ - Type: "string", - Name: "parameters", - Value: string(buf), - } - node.Edges[0] = &Edge{ - Type: "Tome", - Name: "tome", - } - err = j.QueryTome(). - Select(tome.FieldID). - Scan(ctx, &node.Edges[0].IDs) - if err != nil { - return nil, err - } - node.Edges[1] = &Edge{ - Type: "File", - Name: "bundle", - } - err = j.QueryBundle(). - Select(file.FieldID). - Scan(ctx, &node.Edges[1].IDs) - if err != nil { - return nil, err - } - node.Edges[2] = &Edge{ - Type: "Task", - Name: "tasks", - } - err = j.QueryTasks(). - Select(task.FieldID). - Scan(ctx, &node.Edges[2].IDs) - if err != nil { - return nil, err - } - return node, nil -} +// IsNode implements the Node interface check for GQLGen. +func (n *Task) IsNode() {} -func (s *Session) Node(ctx context.Context) (node *Node, err error) { - node = &Node{ - ID: s.ID, - Type: "Session", - Fields: make([]*Field, 7), - Edges: make([]*Edge, 2), - } - var buf []byte - if buf, err = json.Marshal(s.Name); err != nil { - return nil, err - } - node.Fields[0] = &Field{ - Type: "string", - Name: "name", - Value: string(buf), - } - if buf, err = json.Marshal(s.Principal); err != nil { - return nil, err - } - node.Fields[1] = &Field{ - Type: "string", - Name: "principal", - Value: string(buf), - } - if buf, err = json.Marshal(s.Hostname); err != nil { - return nil, err - } - node.Fields[2] = &Field{ - Type: "string", - Name: "hostname", - Value: string(buf), - } - if buf, err = json.Marshal(s.Identifier); err != nil { - return nil, err - } - node.Fields[3] = &Field{ - Type: "string", - Name: "identifier", - Value: string(buf), - } - if buf, err = json.Marshal(s.AgentIdentifier); err != nil { - return nil, err - } - node.Fields[4] = &Field{ - Type: "string", - Name: "agentIdentifier", - Value: string(buf), - } - if buf, err = json.Marshal(s.HostIdentifier); err != nil { - return nil, err - } - node.Fields[5] = &Field{ - Type: "string", - Name: "hostIdentifier", - Value: string(buf), - } - if buf, err = json.Marshal(s.LastSeenAt); err != nil { - return nil, err - } - node.Fields[6] = &Field{ - Type: "time.Time", - Name: "lastSeenAt", - Value: string(buf), - } - node.Edges[0] = &Edge{ - Type: "Tag", - Name: "tags", - } - err = s.QueryTags(). - Select(tag.FieldID). - Scan(ctx, &node.Edges[0].IDs) - if err != nil { - return nil, err - } - node.Edges[1] = &Edge{ - Type: "Task", - Name: "tasks", - } - err = s.QueryTasks(). - Select(task.FieldID). - Scan(ctx, &node.Edges[1].IDs) - if err != nil { - return nil, err - } - return node, nil -} +// IsNode implements the Node interface check for GQLGen. +func (n *Tome) IsNode() {} -func (t *Tag) Node(ctx context.Context) (node *Node, err error) { - node = &Node{ - ID: t.ID, - Type: "Tag", - Fields: make([]*Field, 2), - Edges: make([]*Edge, 1), - } - var buf []byte - if buf, err = json.Marshal(t.Name); err != nil { - return nil, err - } - node.Fields[0] = &Field{ - Type: "string", - Name: "name", - Value: string(buf), - } - if buf, err = json.Marshal(t.Kind); err != nil { - return nil, err - } - node.Fields[1] = &Field{ - Type: "tag.Kind", - Name: "kind", - Value: string(buf), - } - node.Edges[0] = &Edge{ - Type: "Session", - Name: "sessions", - } - err = t.QuerySessions(). - Select(session.FieldID). - Scan(ctx, &node.Edges[0].IDs) - if err != nil { - return nil, err - } - return node, nil -} - -func (t *Task) Node(ctx context.Context) (node *Node, err error) { - node = &Node{ - ID: t.ID, - Type: "Task", - Fields: make([]*Field, 7), - Edges: make([]*Edge, 2), - } - var buf []byte - if buf, err = json.Marshal(t.CreatedAt); err != nil { - return nil, err - } - node.Fields[0] = &Field{ - Type: "time.Time", - Name: "createdAt", - Value: string(buf), - } - if buf, err = json.Marshal(t.LastModifiedAt); err != nil { - return nil, err - } - node.Fields[1] = &Field{ - Type: "time.Time", - Name: "lastModifiedAt", - Value: string(buf), - } - if buf, err = json.Marshal(t.ClaimedAt); err != nil { - return nil, err - } - node.Fields[2] = &Field{ - Type: "time.Time", - Name: "claimedAt", - Value: string(buf), - } - if buf, err = json.Marshal(t.ExecStartedAt); err != nil { - return nil, err - } - node.Fields[3] = &Field{ - Type: "time.Time", - Name: "execStartedAt", - Value: string(buf), - } - if buf, err = json.Marshal(t.ExecFinishedAt); err != nil { - return nil, err - } - node.Fields[4] = &Field{ - Type: "time.Time", - Name: "execFinishedAt", - Value: string(buf), - } - if buf, err = json.Marshal(t.Output); err != nil { - return nil, err - } - node.Fields[5] = &Field{ - Type: "string", - Name: "output", - Value: string(buf), - } - if buf, err = json.Marshal(t.Error); err != nil { - return nil, err - } - node.Fields[6] = &Field{ - Type: "string", - Name: "error", - Value: string(buf), - } - node.Edges[0] = &Edge{ - Type: "Job", - Name: "job", - } - err = t.QueryJob(). - Select(job.FieldID). - Scan(ctx, &node.Edges[0].IDs) - if err != nil { - return nil, err - } - node.Edges[1] = &Edge{ - Type: "Session", - Name: "session", - } - err = t.QuerySession(). - Select(session.FieldID). - Scan(ctx, &node.Edges[1].IDs) - if err != nil { - return nil, err - } - return node, nil -} - -func (t *Tome) Node(ctx context.Context) (node *Node, err error) { - node = &Node{ - ID: t.ID, - Type: "Tome", - Fields: make([]*Field, 6), - Edges: make([]*Edge, 1), - } - var buf []byte - if buf, err = json.Marshal(t.CreatedAt); err != nil { - return nil, err - } - node.Fields[0] = &Field{ - Type: "time.Time", - Name: "createdAt", - Value: string(buf), - } - if buf, err = json.Marshal(t.LastModifiedAt); err != nil { - return nil, err - } - node.Fields[1] = &Field{ - Type: "time.Time", - Name: "lastModifiedAt", - Value: string(buf), - } - if buf, err = json.Marshal(t.Name); err != nil { - return nil, err - } - node.Fields[2] = &Field{ - Type: "string", - Name: "name", - Value: string(buf), - } - if buf, err = json.Marshal(t.Description); err != nil { - return nil, err - } - node.Fields[3] = &Field{ - Type: "string", - Name: "description", - Value: string(buf), - } - if buf, err = json.Marshal(t.Parameters); err != nil { - return nil, err - } - node.Fields[4] = &Field{ - Type: "string", - Name: "parameters", - Value: string(buf), - } - if buf, err = json.Marshal(t.Eldritch); err != nil { - return nil, err - } - node.Fields[5] = &Field{ - Type: "string", - Name: "eldritch", - Value: string(buf), - } - node.Edges[0] = &Edge{ - Type: "File", - Name: "files", - } - err = t.QueryFiles(). - Select(file.FieldID). - Scan(ctx, &node.Edges[0].IDs) - if err != nil { - return nil, err - } - return node, nil -} - -func (u *User) Node(ctx context.Context) (node *Node, err error) { - node = &Node{ - ID: u.ID, - Type: "User", - Fields: make([]*Field, 5), - Edges: make([]*Edge, 0), - } - var buf []byte - if buf, err = json.Marshal(u.Name); err != nil { - return nil, err - } - node.Fields[0] = &Field{ - Type: "string", - Name: "Name", - Value: string(buf), - } - if buf, err = json.Marshal(u.OAuthID); err != nil { - return nil, err - } - node.Fields[1] = &Field{ - Type: "string", - Name: "OAuthID", - Value: string(buf), - } - if buf, err = json.Marshal(u.PhotoURL); err != nil { - return nil, err - } - node.Fields[2] = &Field{ - Type: "string", - Name: "PhotoURL", - Value: string(buf), - } - if buf, err = json.Marshal(u.IsActivated); err != nil { - return nil, err - } - node.Fields[3] = &Field{ - Type: "bool", - Name: "IsActivated", - Value: string(buf), - } - if buf, err = json.Marshal(u.IsAdmin); err != nil { - return nil, err - } - node.Fields[4] = &Field{ - Type: "bool", - Name: "IsAdmin", - Value: string(buf), - } - return node, nil -} - -func (c *Client) Node(ctx context.Context, id int) (*Node, error) { - n, err := c.Noder(ctx, id) - if err != nil { - return nil, err - } - return n.Node(ctx) -} +// IsNode implements the Node interface check for GQLGen. +func (n *User) IsNode() {} var errNodeInvalidID = &NotFoundError{"node"} diff --git a/tavern/ent/gql_pagination.go b/tavern/ent/gql_pagination.go index b47c68d41..81751e09d 100644 --- a/tavern/ent/gql_pagination.go +++ b/tavern/ent/gql_pagination.go @@ -445,7 +445,7 @@ func (f *FileQuery) Paginate( } var ( - // FileOrderFieldCreatedAt orders File by createdAt. + // FileOrderFieldCreatedAt orders File by created_at. FileOrderFieldCreatedAt = &FileOrderField{ field: file.FieldCreatedAt, toCursor: func(f *File) Cursor { @@ -455,7 +455,7 @@ var ( } }, } - // FileOrderFieldLastModifiedAt orders File by lastModifiedAt. + // FileOrderFieldLastModifiedAt orders File by last_modified_at. FileOrderFieldLastModifiedAt = &FileOrderField{ field: file.FieldLastModifiedAt, toCursor: func(f *File) Cursor { @@ -761,7 +761,7 @@ func (j *JobQuery) Paginate( } var ( - // JobOrderFieldCreatedAt orders Job by createdAt. + // JobOrderFieldCreatedAt orders Job by created_at. JobOrderFieldCreatedAt = &JobOrderField{ field: job.FieldCreatedAt, toCursor: func(j *Job) Cursor { @@ -771,7 +771,7 @@ var ( } }, } - // JobOrderFieldLastModifiedAt orders Job by lastModifiedAt. + // JobOrderFieldLastModifiedAt orders Job by last_modified_at. JobOrderFieldLastModifiedAt = &JobOrderField{ field: job.FieldLastModifiedAt, toCursor: func(j *Job) Cursor { @@ -1063,7 +1063,7 @@ func (s *SessionQuery) Paginate( } var ( - // SessionOrderFieldLastSeenAt orders Session by lastSeenAt. + // SessionOrderFieldLastSeenAt orders Session by last_seen_at. SessionOrderFieldLastSeenAt = &SessionOrderField{ field: session.FieldLastSeenAt, toCursor: func(s *Session) Cursor { @@ -1611,7 +1611,7 @@ func (t *TaskQuery) Paginate( } var ( - // TaskOrderFieldCreatedAt orders Task by createdAt. + // TaskOrderFieldCreatedAt orders Task by created_at. TaskOrderFieldCreatedAt = &TaskOrderField{ field: task.FieldCreatedAt, toCursor: func(t *Task) Cursor { @@ -1621,7 +1621,7 @@ var ( } }, } - // TaskOrderFieldLastModifiedAt orders Task by lastModifiedAt. + // TaskOrderFieldLastModifiedAt orders Task by last_modified_at. TaskOrderFieldLastModifiedAt = &TaskOrderField{ field: task.FieldLastModifiedAt, toCursor: func(t *Task) Cursor { @@ -1631,7 +1631,7 @@ var ( } }, } - // TaskOrderFieldClaimedAt orders Task by claimedAt. + // TaskOrderFieldClaimedAt orders Task by claimed_at. TaskOrderFieldClaimedAt = &TaskOrderField{ field: task.FieldClaimedAt, toCursor: func(t *Task) Cursor { @@ -1641,7 +1641,7 @@ var ( } }, } - // TaskOrderFieldExecStartedAt orders Task by execStartedAt. + // TaskOrderFieldExecStartedAt orders Task by exec_started_at. TaskOrderFieldExecStartedAt = &TaskOrderField{ field: task.FieldExecStartedAt, toCursor: func(t *Task) Cursor { @@ -1651,7 +1651,7 @@ var ( } }, } - // TaskOrderFieldExecFinishedAt orders Task by execFinishedAt. + // TaskOrderFieldExecFinishedAt orders Task by exec_finished_at. TaskOrderFieldExecFinishedAt = &TaskOrderField{ field: task.FieldExecFinishedAt, toCursor: func(t *Task) Cursor { @@ -1941,7 +1941,7 @@ func (t *TomeQuery) Paginate( } var ( - // TomeOrderFieldCreatedAt orders Tome by createdAt. + // TomeOrderFieldCreatedAt orders Tome by created_at. TomeOrderFieldCreatedAt = &TomeOrderField{ field: tome.FieldCreatedAt, toCursor: func(t *Tome) Cursor { @@ -1951,7 +1951,7 @@ var ( } }, } - // TomeOrderFieldLastModifiedAt orders Tome by lastModifiedAt. + // TomeOrderFieldLastModifiedAt orders Tome by last_modified_at. TomeOrderFieldLastModifiedAt = &TomeOrderField{ field: tome.FieldLastModifiedAt, toCursor: func(t *Tome) Cursor { diff --git a/tavern/ent/gql_where_input.go b/tavern/ent/gql_where_input.go index b9a793cb4..71fa787d9 100644 --- a/tavern/ent/gql_where_input.go +++ b/tavern/ent/gql_where_input.go @@ -34,25 +34,25 @@ type FileWhereInput struct { IDLT *int `json:"idLT,omitempty"` IDLTE *int `json:"idLTE,omitempty"` - // "createdAt" field predicates. - CreatedAt *time.Time `json:"createdat,omitempty"` - CreatedAtNEQ *time.Time `json:"createdatNEQ,omitempty"` - CreatedAtIn []time.Time `json:"createdatIn,omitempty"` - CreatedAtNotIn []time.Time `json:"createdatNotIn,omitempty"` - CreatedAtGT *time.Time `json:"createdatGT,omitempty"` - CreatedAtGTE *time.Time `json:"createdatGTE,omitempty"` - CreatedAtLT *time.Time `json:"createdatLT,omitempty"` - CreatedAtLTE *time.Time `json:"createdatLTE,omitempty"` - - // "lastModifiedAt" field predicates. - LastModifiedAt *time.Time `json:"lastmodifiedat,omitempty"` - LastModifiedAtNEQ *time.Time `json:"lastmodifiedatNEQ,omitempty"` - LastModifiedAtIn []time.Time `json:"lastmodifiedatIn,omitempty"` - LastModifiedAtNotIn []time.Time `json:"lastmodifiedatNotIn,omitempty"` - LastModifiedAtGT *time.Time `json:"lastmodifiedatGT,omitempty"` - LastModifiedAtGTE *time.Time `json:"lastmodifiedatGTE,omitempty"` - LastModifiedAtLT *time.Time `json:"lastmodifiedatLT,omitempty"` - LastModifiedAtLTE *time.Time `json:"lastmodifiedatLTE,omitempty"` + // "created_at" field predicates. + CreatedAt *time.Time `json:"createdAt,omitempty"` + CreatedAtNEQ *time.Time `json:"createdAtNEQ,omitempty"` + CreatedAtIn []time.Time `json:"createdAtIn,omitempty"` + CreatedAtNotIn []time.Time `json:"createdAtNotIn,omitempty"` + CreatedAtGT *time.Time `json:"createdAtGT,omitempty"` + CreatedAtGTE *time.Time `json:"createdAtGTE,omitempty"` + CreatedAtLT *time.Time `json:"createdAtLT,omitempty"` + CreatedAtLTE *time.Time `json:"createdAtLTE,omitempty"` + + // "last_modified_at" field predicates. + LastModifiedAt *time.Time `json:"lastModifiedAt,omitempty"` + LastModifiedAtNEQ *time.Time `json:"lastModifiedAtNEQ,omitempty"` + LastModifiedAtIn []time.Time `json:"lastModifiedAtIn,omitempty"` + LastModifiedAtNotIn []time.Time `json:"lastModifiedAtNotIn,omitempty"` + LastModifiedAtGT *time.Time `json:"lastModifiedAtGT,omitempty"` + LastModifiedAtGTE *time.Time `json:"lastModifiedAtGTE,omitempty"` + LastModifiedAtLT *time.Time `json:"lastModifiedAtLT,omitempty"` + LastModifiedAtLTE *time.Time `json:"lastModifiedAtLTE,omitempty"` // "name" field predicates. Name *string `json:"name,omitempty"` @@ -368,25 +368,25 @@ type JobWhereInput struct { IDLT *int `json:"idLT,omitempty"` IDLTE *int `json:"idLTE,omitempty"` - // "createdAt" field predicates. - CreatedAt *time.Time `json:"createdat,omitempty"` - CreatedAtNEQ *time.Time `json:"createdatNEQ,omitempty"` - CreatedAtIn []time.Time `json:"createdatIn,omitempty"` - CreatedAtNotIn []time.Time `json:"createdatNotIn,omitempty"` - CreatedAtGT *time.Time `json:"createdatGT,omitempty"` - CreatedAtGTE *time.Time `json:"createdatGTE,omitempty"` - CreatedAtLT *time.Time `json:"createdatLT,omitempty"` - CreatedAtLTE *time.Time `json:"createdatLTE,omitempty"` - - // "lastModifiedAt" field predicates. - LastModifiedAt *time.Time `json:"lastmodifiedat,omitempty"` - LastModifiedAtNEQ *time.Time `json:"lastmodifiedatNEQ,omitempty"` - LastModifiedAtIn []time.Time `json:"lastmodifiedatIn,omitempty"` - LastModifiedAtNotIn []time.Time `json:"lastmodifiedatNotIn,omitempty"` - LastModifiedAtGT *time.Time `json:"lastmodifiedatGT,omitempty"` - LastModifiedAtGTE *time.Time `json:"lastmodifiedatGTE,omitempty"` - LastModifiedAtLT *time.Time `json:"lastmodifiedatLT,omitempty"` - LastModifiedAtLTE *time.Time `json:"lastmodifiedatLTE,omitempty"` + // "created_at" field predicates. + CreatedAt *time.Time `json:"createdAt,omitempty"` + CreatedAtNEQ *time.Time `json:"createdAtNEQ,omitempty"` + CreatedAtIn []time.Time `json:"createdAtIn,omitempty"` + CreatedAtNotIn []time.Time `json:"createdAtNotIn,omitempty"` + CreatedAtGT *time.Time `json:"createdAtGT,omitempty"` + CreatedAtGTE *time.Time `json:"createdAtGTE,omitempty"` + CreatedAtLT *time.Time `json:"createdAtLT,omitempty"` + CreatedAtLTE *time.Time `json:"createdAtLTE,omitempty"` + + // "last_modified_at" field predicates. + LastModifiedAt *time.Time `json:"lastModifiedAt,omitempty"` + LastModifiedAtNEQ *time.Time `json:"lastModifiedAtNEQ,omitempty"` + LastModifiedAtIn []time.Time `json:"lastModifiedAtIn,omitempty"` + LastModifiedAtNotIn []time.Time `json:"lastModifiedAtNotIn,omitempty"` + LastModifiedAtGT *time.Time `json:"lastModifiedAtGT,omitempty"` + LastModifiedAtGTE *time.Time `json:"lastModifiedAtGTE,omitempty"` + LastModifiedAtLT *time.Time `json:"lastModifiedAtLT,omitempty"` + LastModifiedAtLTE *time.Time `json:"lastModifiedAtLTE,omitempty"` // "name" field predicates. Name *string `json:"name,omitempty"` @@ -431,6 +431,10 @@ type JobWhereInput struct { // "tasks" edge predicates. HasTasks *bool `json:"hasTasks,omitempty"` HasTasksWith []*TaskWhereInput `json:"hasTasksWith,omitempty"` + + // "creator" edge predicates. + HasCreator *bool `json:"hasCreator,omitempty"` + HasCreatorWith []*UserWhereInput `json:"hasCreatorWith,omitempty"` } // AddPredicates adds custom predicates to the where input to be used during the filtering phase. @@ -715,6 +719,24 @@ func (i *JobWhereInput) P() (predicate.Job, error) { } predicates = append(predicates, job.HasTasksWith(with...)) } + if i.HasCreator != nil { + p := job.HasCreator() + if !*i.HasCreator { + p = job.Not(p) + } + predicates = append(predicates, p) + } + if len(i.HasCreatorWith) > 0 { + with := make([]predicate.User, 0, len(i.HasCreatorWith)) + for _, w := range i.HasCreatorWith { + p, err := w.P() + if err != nil { + return nil, fmt.Errorf("%w: field 'HasCreatorWith'", err) + } + with = append(with, p) + } + predicates = append(predicates, job.HasCreatorWith(with...)) + } switch len(predicates) { case 0: return nil, ErrEmptyJobWhereInput @@ -806,51 +828,74 @@ type SessionWhereInput struct { IdentifierEqualFold *string `json:"identifierEqualFold,omitempty"` IdentifierContainsFold *string `json:"identifierContainsFold,omitempty"` - // "agentIdentifier" field predicates. - AgentIdentifier *string `json:"agentidentifier,omitempty"` - AgentIdentifierNEQ *string `json:"agentidentifierNEQ,omitempty"` - AgentIdentifierIn []string `json:"agentidentifierIn,omitempty"` - AgentIdentifierNotIn []string `json:"agentidentifierNotIn,omitempty"` - AgentIdentifierGT *string `json:"agentidentifierGT,omitempty"` - AgentIdentifierGTE *string `json:"agentidentifierGTE,omitempty"` - AgentIdentifierLT *string `json:"agentidentifierLT,omitempty"` - AgentIdentifierLTE *string `json:"agentidentifierLTE,omitempty"` - AgentIdentifierContains *string `json:"agentidentifierContains,omitempty"` - AgentIdentifierHasPrefix *string `json:"agentidentifierHasPrefix,omitempty"` - AgentIdentifierHasSuffix *string `json:"agentidentifierHasSuffix,omitempty"` - AgentIdentifierIsNil bool `json:"agentidentifierIsNil,omitempty"` - AgentIdentifierNotNil bool `json:"agentidentifierNotNil,omitempty"` - AgentIdentifierEqualFold *string `json:"agentidentifierEqualFold,omitempty"` - AgentIdentifierContainsFold *string `json:"agentidentifierContainsFold,omitempty"` - - // "hostIdentifier" field predicates. - HostIdentifier *string `json:"hostidentifier,omitempty"` - HostIdentifierNEQ *string `json:"hostidentifierNEQ,omitempty"` - HostIdentifierIn []string `json:"hostidentifierIn,omitempty"` - HostIdentifierNotIn []string `json:"hostidentifierNotIn,omitempty"` - HostIdentifierGT *string `json:"hostidentifierGT,omitempty"` - HostIdentifierGTE *string `json:"hostidentifierGTE,omitempty"` - HostIdentifierLT *string `json:"hostidentifierLT,omitempty"` - HostIdentifierLTE *string `json:"hostidentifierLTE,omitempty"` - HostIdentifierContains *string `json:"hostidentifierContains,omitempty"` - HostIdentifierHasPrefix *string `json:"hostidentifierHasPrefix,omitempty"` - HostIdentifierHasSuffix *string `json:"hostidentifierHasSuffix,omitempty"` - HostIdentifierIsNil bool `json:"hostidentifierIsNil,omitempty"` - HostIdentifierNotNil bool `json:"hostidentifierNotNil,omitempty"` - HostIdentifierEqualFold *string `json:"hostidentifierEqualFold,omitempty"` - HostIdentifierContainsFold *string `json:"hostidentifierContainsFold,omitempty"` - - // "lastSeenAt" field predicates. - LastSeenAt *time.Time `json:"lastseenat,omitempty"` - LastSeenAtNEQ *time.Time `json:"lastseenatNEQ,omitempty"` - LastSeenAtIn []time.Time `json:"lastseenatIn,omitempty"` - LastSeenAtNotIn []time.Time `json:"lastseenatNotIn,omitempty"` - LastSeenAtGT *time.Time `json:"lastseenatGT,omitempty"` - LastSeenAtGTE *time.Time `json:"lastseenatGTE,omitempty"` - LastSeenAtLT *time.Time `json:"lastseenatLT,omitempty"` - LastSeenAtLTE *time.Time `json:"lastseenatLTE,omitempty"` - LastSeenAtIsNil bool `json:"lastseenatIsNil,omitempty"` - LastSeenAtNotNil bool `json:"lastseenatNotNil,omitempty"` + // "agent_identifier" field predicates. + AgentIdentifier *string `json:"agentIdentifier,omitempty"` + AgentIdentifierNEQ *string `json:"agentIdentifierNEQ,omitempty"` + AgentIdentifierIn []string `json:"agentIdentifierIn,omitempty"` + AgentIdentifierNotIn []string `json:"agentIdentifierNotIn,omitempty"` + AgentIdentifierGT *string `json:"agentIdentifierGT,omitempty"` + AgentIdentifierGTE *string `json:"agentIdentifierGTE,omitempty"` + AgentIdentifierLT *string `json:"agentIdentifierLT,omitempty"` + AgentIdentifierLTE *string `json:"agentIdentifierLTE,omitempty"` + AgentIdentifierContains *string `json:"agentIdentifierContains,omitempty"` + AgentIdentifierHasPrefix *string `json:"agentIdentifierHasPrefix,omitempty"` + AgentIdentifierHasSuffix *string `json:"agentIdentifierHasSuffix,omitempty"` + AgentIdentifierIsNil bool `json:"agentIdentifierIsNil,omitempty"` + AgentIdentifierNotNil bool `json:"agentIdentifierNotNil,omitempty"` + AgentIdentifierEqualFold *string `json:"agentIdentifierEqualFold,omitempty"` + AgentIdentifierContainsFold *string `json:"agentIdentifierContainsFold,omitempty"` + + // "host_identifier" field predicates. + HostIdentifier *string `json:"hostIdentifier,omitempty"` + HostIdentifierNEQ *string `json:"hostIdentifierNEQ,omitempty"` + HostIdentifierIn []string `json:"hostIdentifierIn,omitempty"` + HostIdentifierNotIn []string `json:"hostIdentifierNotIn,omitempty"` + HostIdentifierGT *string `json:"hostIdentifierGT,omitempty"` + HostIdentifierGTE *string `json:"hostIdentifierGTE,omitempty"` + HostIdentifierLT *string `json:"hostIdentifierLT,omitempty"` + HostIdentifierLTE *string `json:"hostIdentifierLTE,omitempty"` + HostIdentifierContains *string `json:"hostIdentifierContains,omitempty"` + HostIdentifierHasPrefix *string `json:"hostIdentifierHasPrefix,omitempty"` + HostIdentifierHasSuffix *string `json:"hostIdentifierHasSuffix,omitempty"` + HostIdentifierIsNil bool `json:"hostIdentifierIsNil,omitempty"` + HostIdentifierNotNil bool `json:"hostIdentifierNotNil,omitempty"` + HostIdentifierEqualFold *string `json:"hostIdentifierEqualFold,omitempty"` + HostIdentifierContainsFold *string `json:"hostIdentifierContainsFold,omitempty"` + + // "host_primary_ip" field predicates. + HostPrimaryIP *string `json:"hostPrimaryIP,omitempty"` + HostPrimaryIPNEQ *string `json:"hostPrimaryIPNEQ,omitempty"` + HostPrimaryIPIn []string `json:"hostPrimaryIPIn,omitempty"` + HostPrimaryIPNotIn []string `json:"hostPrimaryIPNotIn,omitempty"` + HostPrimaryIPGT *string `json:"hostPrimaryIPGT,omitempty"` + HostPrimaryIPGTE *string `json:"hostPrimaryIPGTE,omitempty"` + HostPrimaryIPLT *string `json:"hostPrimaryIPLT,omitempty"` + HostPrimaryIPLTE *string `json:"hostPrimaryIPLTE,omitempty"` + HostPrimaryIPContains *string `json:"hostPrimaryIPContains,omitempty"` + HostPrimaryIPHasPrefix *string `json:"hostPrimaryIPHasPrefix,omitempty"` + HostPrimaryIPHasSuffix *string `json:"hostPrimaryIPHasSuffix,omitempty"` + HostPrimaryIPIsNil bool `json:"hostPrimaryIPIsNil,omitempty"` + HostPrimaryIPNotNil bool `json:"hostPrimaryIPNotNil,omitempty"` + HostPrimaryIPEqualFold *string `json:"hostPrimaryIPEqualFold,omitempty"` + HostPrimaryIPContainsFold *string `json:"hostPrimaryIPContainsFold,omitempty"` + + // "host_platform" field predicates. + HostPlatform *session.HostPlatform `json:"hostPlatform,omitempty"` + HostPlatformNEQ *session.HostPlatform `json:"hostPlatformNEQ,omitempty"` + HostPlatformIn []session.HostPlatform `json:"hostPlatformIn,omitempty"` + HostPlatformNotIn []session.HostPlatform `json:"hostPlatformNotIn,omitempty"` + + // "last_seen_at" field predicates. + LastSeenAt *time.Time `json:"lastSeenAt,omitempty"` + LastSeenAtNEQ *time.Time `json:"lastSeenAtNEQ,omitempty"` + LastSeenAtIn []time.Time `json:"lastSeenAtIn,omitempty"` + LastSeenAtNotIn []time.Time `json:"lastSeenAtNotIn,omitempty"` + LastSeenAtGT *time.Time `json:"lastSeenAtGT,omitempty"` + LastSeenAtGTE *time.Time `json:"lastSeenAtGTE,omitempty"` + LastSeenAtLT *time.Time `json:"lastSeenAtLT,omitempty"` + LastSeenAtLTE *time.Time `json:"lastSeenAtLTE,omitempty"` + LastSeenAtIsNil bool `json:"lastSeenAtIsNil,omitempty"` + LastSeenAtNotNil bool `json:"lastSeenAtNotNil,omitempty"` // "tags" edge predicates. HasTags *bool `json:"hasTags,omitempty"` @@ -1214,6 +1259,63 @@ func (i *SessionWhereInput) P() (predicate.Session, error) { if i.HostIdentifierContainsFold != nil { predicates = append(predicates, session.HostIdentifierContainsFold(*i.HostIdentifierContainsFold)) } + if i.HostPrimaryIP != nil { + predicates = append(predicates, session.HostPrimaryIPEQ(*i.HostPrimaryIP)) + } + if i.HostPrimaryIPNEQ != nil { + predicates = append(predicates, session.HostPrimaryIPNEQ(*i.HostPrimaryIPNEQ)) + } + if len(i.HostPrimaryIPIn) > 0 { + predicates = append(predicates, session.HostPrimaryIPIn(i.HostPrimaryIPIn...)) + } + if len(i.HostPrimaryIPNotIn) > 0 { + predicates = append(predicates, session.HostPrimaryIPNotIn(i.HostPrimaryIPNotIn...)) + } + if i.HostPrimaryIPGT != nil { + predicates = append(predicates, session.HostPrimaryIPGT(*i.HostPrimaryIPGT)) + } + if i.HostPrimaryIPGTE != nil { + predicates = append(predicates, session.HostPrimaryIPGTE(*i.HostPrimaryIPGTE)) + } + if i.HostPrimaryIPLT != nil { + predicates = append(predicates, session.HostPrimaryIPLT(*i.HostPrimaryIPLT)) + } + if i.HostPrimaryIPLTE != nil { + predicates = append(predicates, session.HostPrimaryIPLTE(*i.HostPrimaryIPLTE)) + } + if i.HostPrimaryIPContains != nil { + predicates = append(predicates, session.HostPrimaryIPContains(*i.HostPrimaryIPContains)) + } + if i.HostPrimaryIPHasPrefix != nil { + predicates = append(predicates, session.HostPrimaryIPHasPrefix(*i.HostPrimaryIPHasPrefix)) + } + if i.HostPrimaryIPHasSuffix != nil { + predicates = append(predicates, session.HostPrimaryIPHasSuffix(*i.HostPrimaryIPHasSuffix)) + } + if i.HostPrimaryIPIsNil { + predicates = append(predicates, session.HostPrimaryIPIsNil()) + } + if i.HostPrimaryIPNotNil { + predicates = append(predicates, session.HostPrimaryIPNotNil()) + } + if i.HostPrimaryIPEqualFold != nil { + predicates = append(predicates, session.HostPrimaryIPEqualFold(*i.HostPrimaryIPEqualFold)) + } + if i.HostPrimaryIPContainsFold != nil { + predicates = append(predicates, session.HostPrimaryIPContainsFold(*i.HostPrimaryIPContainsFold)) + } + if i.HostPlatform != nil { + predicates = append(predicates, session.HostPlatformEQ(*i.HostPlatform)) + } + if i.HostPlatformNEQ != nil { + predicates = append(predicates, session.HostPlatformNEQ(*i.HostPlatformNEQ)) + } + if len(i.HostPlatformIn) > 0 { + predicates = append(predicates, session.HostPlatformIn(i.HostPlatformIn...)) + } + if len(i.HostPlatformNotIn) > 0 { + predicates = append(predicates, session.HostPlatformNotIn(i.HostPlatformNotIn...)) + } if i.LastSeenAt != nil { predicates = append(predicates, session.LastSeenAtEQ(*i.LastSeenAt)) } @@ -1526,61 +1628,61 @@ type TaskWhereInput struct { IDLT *int `json:"idLT,omitempty"` IDLTE *int `json:"idLTE,omitempty"` - // "createdAt" field predicates. - CreatedAt *time.Time `json:"createdat,omitempty"` - CreatedAtNEQ *time.Time `json:"createdatNEQ,omitempty"` - CreatedAtIn []time.Time `json:"createdatIn,omitempty"` - CreatedAtNotIn []time.Time `json:"createdatNotIn,omitempty"` - CreatedAtGT *time.Time `json:"createdatGT,omitempty"` - CreatedAtGTE *time.Time `json:"createdatGTE,omitempty"` - CreatedAtLT *time.Time `json:"createdatLT,omitempty"` - CreatedAtLTE *time.Time `json:"createdatLTE,omitempty"` - - // "lastModifiedAt" field predicates. - LastModifiedAt *time.Time `json:"lastmodifiedat,omitempty"` - LastModifiedAtNEQ *time.Time `json:"lastmodifiedatNEQ,omitempty"` - LastModifiedAtIn []time.Time `json:"lastmodifiedatIn,omitempty"` - LastModifiedAtNotIn []time.Time `json:"lastmodifiedatNotIn,omitempty"` - LastModifiedAtGT *time.Time `json:"lastmodifiedatGT,omitempty"` - LastModifiedAtGTE *time.Time `json:"lastmodifiedatGTE,omitempty"` - LastModifiedAtLT *time.Time `json:"lastmodifiedatLT,omitempty"` - LastModifiedAtLTE *time.Time `json:"lastmodifiedatLTE,omitempty"` - - // "claimedAt" field predicates. - ClaimedAt *time.Time `json:"claimedat,omitempty"` - ClaimedAtNEQ *time.Time `json:"claimedatNEQ,omitempty"` - ClaimedAtIn []time.Time `json:"claimedatIn,omitempty"` - ClaimedAtNotIn []time.Time `json:"claimedatNotIn,omitempty"` - ClaimedAtGT *time.Time `json:"claimedatGT,omitempty"` - ClaimedAtGTE *time.Time `json:"claimedatGTE,omitempty"` - ClaimedAtLT *time.Time `json:"claimedatLT,omitempty"` - ClaimedAtLTE *time.Time `json:"claimedatLTE,omitempty"` - ClaimedAtIsNil bool `json:"claimedatIsNil,omitempty"` - ClaimedAtNotNil bool `json:"claimedatNotNil,omitempty"` - - // "execStartedAt" field predicates. - ExecStartedAt *time.Time `json:"execstartedat,omitempty"` - ExecStartedAtNEQ *time.Time `json:"execstartedatNEQ,omitempty"` - ExecStartedAtIn []time.Time `json:"execstartedatIn,omitempty"` - ExecStartedAtNotIn []time.Time `json:"execstartedatNotIn,omitempty"` - ExecStartedAtGT *time.Time `json:"execstartedatGT,omitempty"` - ExecStartedAtGTE *time.Time `json:"execstartedatGTE,omitempty"` - ExecStartedAtLT *time.Time `json:"execstartedatLT,omitempty"` - ExecStartedAtLTE *time.Time `json:"execstartedatLTE,omitempty"` - ExecStartedAtIsNil bool `json:"execstartedatIsNil,omitempty"` - ExecStartedAtNotNil bool `json:"execstartedatNotNil,omitempty"` - - // "execFinishedAt" field predicates. - ExecFinishedAt *time.Time `json:"execfinishedat,omitempty"` - ExecFinishedAtNEQ *time.Time `json:"execfinishedatNEQ,omitempty"` - ExecFinishedAtIn []time.Time `json:"execfinishedatIn,omitempty"` - ExecFinishedAtNotIn []time.Time `json:"execfinishedatNotIn,omitempty"` - ExecFinishedAtGT *time.Time `json:"execfinishedatGT,omitempty"` - ExecFinishedAtGTE *time.Time `json:"execfinishedatGTE,omitempty"` - ExecFinishedAtLT *time.Time `json:"execfinishedatLT,omitempty"` - ExecFinishedAtLTE *time.Time `json:"execfinishedatLTE,omitempty"` - ExecFinishedAtIsNil bool `json:"execfinishedatIsNil,omitempty"` - ExecFinishedAtNotNil bool `json:"execfinishedatNotNil,omitempty"` + // "created_at" field predicates. + CreatedAt *time.Time `json:"createdAt,omitempty"` + CreatedAtNEQ *time.Time `json:"createdAtNEQ,omitempty"` + CreatedAtIn []time.Time `json:"createdAtIn,omitempty"` + CreatedAtNotIn []time.Time `json:"createdAtNotIn,omitempty"` + CreatedAtGT *time.Time `json:"createdAtGT,omitempty"` + CreatedAtGTE *time.Time `json:"createdAtGTE,omitempty"` + CreatedAtLT *time.Time `json:"createdAtLT,omitempty"` + CreatedAtLTE *time.Time `json:"createdAtLTE,omitempty"` + + // "last_modified_at" field predicates. + LastModifiedAt *time.Time `json:"lastModifiedAt,omitempty"` + LastModifiedAtNEQ *time.Time `json:"lastModifiedAtNEQ,omitempty"` + LastModifiedAtIn []time.Time `json:"lastModifiedAtIn,omitempty"` + LastModifiedAtNotIn []time.Time `json:"lastModifiedAtNotIn,omitempty"` + LastModifiedAtGT *time.Time `json:"lastModifiedAtGT,omitempty"` + LastModifiedAtGTE *time.Time `json:"lastModifiedAtGTE,omitempty"` + LastModifiedAtLT *time.Time `json:"lastModifiedAtLT,omitempty"` + LastModifiedAtLTE *time.Time `json:"lastModifiedAtLTE,omitempty"` + + // "claimed_at" field predicates. + ClaimedAt *time.Time `json:"claimedAt,omitempty"` + ClaimedAtNEQ *time.Time `json:"claimedAtNEQ,omitempty"` + ClaimedAtIn []time.Time `json:"claimedAtIn,omitempty"` + ClaimedAtNotIn []time.Time `json:"claimedAtNotIn,omitempty"` + ClaimedAtGT *time.Time `json:"claimedAtGT,omitempty"` + ClaimedAtGTE *time.Time `json:"claimedAtGTE,omitempty"` + ClaimedAtLT *time.Time `json:"claimedAtLT,omitempty"` + ClaimedAtLTE *time.Time `json:"claimedAtLTE,omitempty"` + ClaimedAtIsNil bool `json:"claimedAtIsNil,omitempty"` + ClaimedAtNotNil bool `json:"claimedAtNotNil,omitempty"` + + // "exec_started_at" field predicates. + ExecStartedAt *time.Time `json:"execStartedAt,omitempty"` + ExecStartedAtNEQ *time.Time `json:"execStartedAtNEQ,omitempty"` + ExecStartedAtIn []time.Time `json:"execStartedAtIn,omitempty"` + ExecStartedAtNotIn []time.Time `json:"execStartedAtNotIn,omitempty"` + ExecStartedAtGT *time.Time `json:"execStartedAtGT,omitempty"` + ExecStartedAtGTE *time.Time `json:"execStartedAtGTE,omitempty"` + ExecStartedAtLT *time.Time `json:"execStartedAtLT,omitempty"` + ExecStartedAtLTE *time.Time `json:"execStartedAtLTE,omitempty"` + ExecStartedAtIsNil bool `json:"execStartedAtIsNil,omitempty"` + ExecStartedAtNotNil bool `json:"execStartedAtNotNil,omitempty"` + + // "exec_finished_at" field predicates. + ExecFinishedAt *time.Time `json:"execFinishedAt,omitempty"` + ExecFinishedAtNEQ *time.Time `json:"execFinishedAtNEQ,omitempty"` + ExecFinishedAtIn []time.Time `json:"execFinishedAtIn,omitempty"` + ExecFinishedAtNotIn []time.Time `json:"execFinishedAtNotIn,omitempty"` + ExecFinishedAtGT *time.Time `json:"execFinishedAtGT,omitempty"` + ExecFinishedAtGTE *time.Time `json:"execFinishedAtGTE,omitempty"` + ExecFinishedAtLT *time.Time `json:"execFinishedAtLT,omitempty"` + ExecFinishedAtLTE *time.Time `json:"execFinishedAtLTE,omitempty"` + ExecFinishedAtIsNil bool `json:"execFinishedAtIsNil,omitempty"` + ExecFinishedAtNotNil bool `json:"execFinishedAtNotNil,omitempty"` // "output" field predicates. Output *string `json:"output,omitempty"` @@ -2012,25 +2114,25 @@ type TomeWhereInput struct { IDLT *int `json:"idLT,omitempty"` IDLTE *int `json:"idLTE,omitempty"` - // "createdAt" field predicates. - CreatedAt *time.Time `json:"createdat,omitempty"` - CreatedAtNEQ *time.Time `json:"createdatNEQ,omitempty"` - CreatedAtIn []time.Time `json:"createdatIn,omitempty"` - CreatedAtNotIn []time.Time `json:"createdatNotIn,omitempty"` - CreatedAtGT *time.Time `json:"createdatGT,omitempty"` - CreatedAtGTE *time.Time `json:"createdatGTE,omitempty"` - CreatedAtLT *time.Time `json:"createdatLT,omitempty"` - CreatedAtLTE *time.Time `json:"createdatLTE,omitempty"` - - // "lastModifiedAt" field predicates. - LastModifiedAt *time.Time `json:"lastmodifiedat,omitempty"` - LastModifiedAtNEQ *time.Time `json:"lastmodifiedatNEQ,omitempty"` - LastModifiedAtIn []time.Time `json:"lastmodifiedatIn,omitempty"` - LastModifiedAtNotIn []time.Time `json:"lastmodifiedatNotIn,omitempty"` - LastModifiedAtGT *time.Time `json:"lastmodifiedatGT,omitempty"` - LastModifiedAtGTE *time.Time `json:"lastmodifiedatGTE,omitempty"` - LastModifiedAtLT *time.Time `json:"lastmodifiedatLT,omitempty"` - LastModifiedAtLTE *time.Time `json:"lastmodifiedatLTE,omitempty"` + // "created_at" field predicates. + CreatedAt *time.Time `json:"createdAt,omitempty"` + CreatedAtNEQ *time.Time `json:"createdAtNEQ,omitempty"` + CreatedAtIn []time.Time `json:"createdAtIn,omitempty"` + CreatedAtNotIn []time.Time `json:"createdAtNotIn,omitempty"` + CreatedAtGT *time.Time `json:"createdAtGT,omitempty"` + CreatedAtGTE *time.Time `json:"createdAtGTE,omitempty"` + CreatedAtLT *time.Time `json:"createdAtLT,omitempty"` + CreatedAtLTE *time.Time `json:"createdAtLTE,omitempty"` + + // "last_modified_at" field predicates. + LastModifiedAt *time.Time `json:"lastModifiedAt,omitempty"` + LastModifiedAtNEQ *time.Time `json:"lastModifiedAtNEQ,omitempty"` + LastModifiedAtIn []time.Time `json:"lastModifiedAtIn,omitempty"` + LastModifiedAtNotIn []time.Time `json:"lastModifiedAtNotIn,omitempty"` + LastModifiedAtGT *time.Time `json:"lastModifiedAtGT,omitempty"` + LastModifiedAtGTE *time.Time `json:"lastModifiedAtGTE,omitempty"` + LastModifiedAtLT *time.Time `json:"lastModifiedAtLT,omitempty"` + LastModifiedAtLTE *time.Time `json:"lastModifiedAtLTE,omitempty"` // "name" field predicates. Name *string `json:"name,omitempty"` @@ -2062,22 +2164,22 @@ type TomeWhereInput struct { DescriptionEqualFold *string `json:"descriptionEqualFold,omitempty"` DescriptionContainsFold *string `json:"descriptionContainsFold,omitempty"` - // "parameters" field predicates. - Parameters *string `json:"parameters,omitempty"` - ParametersNEQ *string `json:"parametersNEQ,omitempty"` - ParametersIn []string `json:"parametersIn,omitempty"` - ParametersNotIn []string `json:"parametersNotIn,omitempty"` - ParametersGT *string `json:"parametersGT,omitempty"` - ParametersGTE *string `json:"parametersGTE,omitempty"` - ParametersLT *string `json:"parametersLT,omitempty"` - ParametersLTE *string `json:"parametersLTE,omitempty"` - ParametersContains *string `json:"parametersContains,omitempty"` - ParametersHasPrefix *string `json:"parametersHasPrefix,omitempty"` - ParametersHasSuffix *string `json:"parametersHasSuffix,omitempty"` - ParametersIsNil bool `json:"parametersIsNil,omitempty"` - ParametersNotNil bool `json:"parametersNotNil,omitempty"` - ParametersEqualFold *string `json:"parametersEqualFold,omitempty"` - ParametersContainsFold *string `json:"parametersContainsFold,omitempty"` + // "param_defs" field predicates. + ParamDefs *string `json:"paramDefs,omitempty"` + ParamDefsNEQ *string `json:"paramDefsNEQ,omitempty"` + ParamDefsIn []string `json:"paramDefsIn,omitempty"` + ParamDefsNotIn []string `json:"paramDefsNotIn,omitempty"` + ParamDefsGT *string `json:"paramDefsGT,omitempty"` + ParamDefsGTE *string `json:"paramDefsGTE,omitempty"` + ParamDefsLT *string `json:"paramDefsLT,omitempty"` + ParamDefsLTE *string `json:"paramDefsLTE,omitempty"` + ParamDefsContains *string `json:"paramDefsContains,omitempty"` + ParamDefsHasPrefix *string `json:"paramDefsHasPrefix,omitempty"` + ParamDefsHasSuffix *string `json:"paramDefsHasSuffix,omitempty"` + ParamDefsIsNil bool `json:"paramDefsIsNil,omitempty"` + ParamDefsNotNil bool `json:"paramDefsNotNil,omitempty"` + ParamDefsEqualFold *string `json:"paramDefsEqualFold,omitempty"` + ParamDefsContainsFold *string `json:"paramDefsContainsFold,omitempty"` // "eldritch" field predicates. Eldritch *string `json:"eldritch,omitempty"` @@ -2320,50 +2422,50 @@ func (i *TomeWhereInput) P() (predicate.Tome, error) { if i.DescriptionContainsFold != nil { predicates = append(predicates, tome.DescriptionContainsFold(*i.DescriptionContainsFold)) } - if i.Parameters != nil { - predicates = append(predicates, tome.ParametersEQ(*i.Parameters)) + if i.ParamDefs != nil { + predicates = append(predicates, tome.ParamDefsEQ(*i.ParamDefs)) } - if i.ParametersNEQ != nil { - predicates = append(predicates, tome.ParametersNEQ(*i.ParametersNEQ)) + if i.ParamDefsNEQ != nil { + predicates = append(predicates, tome.ParamDefsNEQ(*i.ParamDefsNEQ)) } - if len(i.ParametersIn) > 0 { - predicates = append(predicates, tome.ParametersIn(i.ParametersIn...)) + if len(i.ParamDefsIn) > 0 { + predicates = append(predicates, tome.ParamDefsIn(i.ParamDefsIn...)) } - if len(i.ParametersNotIn) > 0 { - predicates = append(predicates, tome.ParametersNotIn(i.ParametersNotIn...)) + if len(i.ParamDefsNotIn) > 0 { + predicates = append(predicates, tome.ParamDefsNotIn(i.ParamDefsNotIn...)) } - if i.ParametersGT != nil { - predicates = append(predicates, tome.ParametersGT(*i.ParametersGT)) + if i.ParamDefsGT != nil { + predicates = append(predicates, tome.ParamDefsGT(*i.ParamDefsGT)) } - if i.ParametersGTE != nil { - predicates = append(predicates, tome.ParametersGTE(*i.ParametersGTE)) + if i.ParamDefsGTE != nil { + predicates = append(predicates, tome.ParamDefsGTE(*i.ParamDefsGTE)) } - if i.ParametersLT != nil { - predicates = append(predicates, tome.ParametersLT(*i.ParametersLT)) + if i.ParamDefsLT != nil { + predicates = append(predicates, tome.ParamDefsLT(*i.ParamDefsLT)) } - if i.ParametersLTE != nil { - predicates = append(predicates, tome.ParametersLTE(*i.ParametersLTE)) + if i.ParamDefsLTE != nil { + predicates = append(predicates, tome.ParamDefsLTE(*i.ParamDefsLTE)) } - if i.ParametersContains != nil { - predicates = append(predicates, tome.ParametersContains(*i.ParametersContains)) + if i.ParamDefsContains != nil { + predicates = append(predicates, tome.ParamDefsContains(*i.ParamDefsContains)) } - if i.ParametersHasPrefix != nil { - predicates = append(predicates, tome.ParametersHasPrefix(*i.ParametersHasPrefix)) + if i.ParamDefsHasPrefix != nil { + predicates = append(predicates, tome.ParamDefsHasPrefix(*i.ParamDefsHasPrefix)) } - if i.ParametersHasSuffix != nil { - predicates = append(predicates, tome.ParametersHasSuffix(*i.ParametersHasSuffix)) + if i.ParamDefsHasSuffix != nil { + predicates = append(predicates, tome.ParamDefsHasSuffix(*i.ParamDefsHasSuffix)) } - if i.ParametersIsNil { - predicates = append(predicates, tome.ParametersIsNil()) + if i.ParamDefsIsNil { + predicates = append(predicates, tome.ParamDefsIsNil()) } - if i.ParametersNotNil { - predicates = append(predicates, tome.ParametersNotNil()) + if i.ParamDefsNotNil { + predicates = append(predicates, tome.ParamDefsNotNil()) } - if i.ParametersEqualFold != nil { - predicates = append(predicates, tome.ParametersEqualFold(*i.ParametersEqualFold)) + if i.ParamDefsEqualFold != nil { + predicates = append(predicates, tome.ParamDefsEqualFold(*i.ParamDefsEqualFold)) } - if i.ParametersContainsFold != nil { - predicates = append(predicates, tome.ParametersContainsFold(*i.ParametersContainsFold)) + if i.ParamDefsContainsFold != nil { + predicates = append(predicates, tome.ParamDefsContainsFold(*i.ParamDefsContainsFold)) } if i.Eldritch != nil { predicates = append(predicates, tome.EldritchEQ(*i.Eldritch)) @@ -2450,7 +2552,7 @@ type UserWhereInput struct { IDLT *int `json:"idLT,omitempty"` IDLTE *int `json:"idLTE,omitempty"` - // "Name" field predicates. + // "name" field predicates. Name *string `json:"name,omitempty"` NameNEQ *string `json:"nameNEQ,omitempty"` NameIn []string `json:"nameIn,omitempty"` @@ -2465,43 +2567,43 @@ type UserWhereInput struct { NameEqualFold *string `json:"nameEqualFold,omitempty"` NameContainsFold *string `json:"nameContainsFold,omitempty"` - // "OAuthID" field predicates. - OAuthID *string `json:"oauthid,omitempty"` - OAuthIDNEQ *string `json:"oauthidNEQ,omitempty"` - OAuthIDIn []string `json:"oauthidIn,omitempty"` - OAuthIDNotIn []string `json:"oauthidNotIn,omitempty"` - OAuthIDGT *string `json:"oauthidGT,omitempty"` - OAuthIDGTE *string `json:"oauthidGTE,omitempty"` - OAuthIDLT *string `json:"oauthidLT,omitempty"` - OAuthIDLTE *string `json:"oauthidLTE,omitempty"` - OAuthIDContains *string `json:"oauthidContains,omitempty"` - OAuthIDHasPrefix *string `json:"oauthidHasPrefix,omitempty"` - OAuthIDHasSuffix *string `json:"oauthidHasSuffix,omitempty"` - OAuthIDEqualFold *string `json:"oauthidEqualFold,omitempty"` - OAuthIDContainsFold *string `json:"oauthidContainsFold,omitempty"` - - // "PhotoURL" field predicates. - PhotoURL *string `json:"photourl,omitempty"` - PhotoURLNEQ *string `json:"photourlNEQ,omitempty"` - PhotoURLIn []string `json:"photourlIn,omitempty"` - PhotoURLNotIn []string `json:"photourlNotIn,omitempty"` - PhotoURLGT *string `json:"photourlGT,omitempty"` - PhotoURLGTE *string `json:"photourlGTE,omitempty"` - PhotoURLLT *string `json:"photourlLT,omitempty"` - PhotoURLLTE *string `json:"photourlLTE,omitempty"` - PhotoURLContains *string `json:"photourlContains,omitempty"` - PhotoURLHasPrefix *string `json:"photourlHasPrefix,omitempty"` - PhotoURLHasSuffix *string `json:"photourlHasSuffix,omitempty"` - PhotoURLEqualFold *string `json:"photourlEqualFold,omitempty"` - PhotoURLContainsFold *string `json:"photourlContainsFold,omitempty"` - - // "IsActivated" field predicates. - IsActivated *bool `json:"isactivated,omitempty"` - IsActivatedNEQ *bool `json:"isactivatedNEQ,omitempty"` - - // "IsAdmin" field predicates. - IsAdmin *bool `json:"isadmin,omitempty"` - IsAdminNEQ *bool `json:"isadminNEQ,omitempty"` + // "oauth_id" field predicates. + OauthID *string `json:"oauthID,omitempty"` + OauthIDNEQ *string `json:"oauthIDNEQ,omitempty"` + OauthIDIn []string `json:"oauthIDIn,omitempty"` + OauthIDNotIn []string `json:"oauthIDNotIn,omitempty"` + OauthIDGT *string `json:"oauthIDGT,omitempty"` + OauthIDGTE *string `json:"oauthIDGTE,omitempty"` + OauthIDLT *string `json:"oauthIDLT,omitempty"` + OauthIDLTE *string `json:"oauthIDLTE,omitempty"` + OauthIDContains *string `json:"oauthIDContains,omitempty"` + OauthIDHasPrefix *string `json:"oauthIDHasPrefix,omitempty"` + OauthIDHasSuffix *string `json:"oauthIDHasSuffix,omitempty"` + OauthIDEqualFold *string `json:"oauthIDEqualFold,omitempty"` + OauthIDContainsFold *string `json:"oauthIDContainsFold,omitempty"` + + // "photo_url" field predicates. + PhotoURL *string `json:"photoURL,omitempty"` + PhotoURLNEQ *string `json:"photoURLNEQ,omitempty"` + PhotoURLIn []string `json:"photoURLIn,omitempty"` + PhotoURLNotIn []string `json:"photoURLNotIn,omitempty"` + PhotoURLGT *string `json:"photoURLGT,omitempty"` + PhotoURLGTE *string `json:"photoURLGTE,omitempty"` + PhotoURLLT *string `json:"photoURLLT,omitempty"` + PhotoURLLTE *string `json:"photoURLLTE,omitempty"` + PhotoURLContains *string `json:"photoURLContains,omitempty"` + PhotoURLHasPrefix *string `json:"photoURLHasPrefix,omitempty"` + PhotoURLHasSuffix *string `json:"photoURLHasSuffix,omitempty"` + PhotoURLEqualFold *string `json:"photoURLEqualFold,omitempty"` + PhotoURLContainsFold *string `json:"photoURLContainsFold,omitempty"` + + // "is_activated" field predicates. + IsActivated *bool `json:"isActivated,omitempty"` + IsActivatedNEQ *bool `json:"isActivatedNEQ,omitempty"` + + // "is_admin" field predicates. + IsAdmin *bool `json:"isAdmin,omitempty"` + IsAdminNEQ *bool `json:"isAdminNEQ,omitempty"` } // AddPredicates adds custom predicates to the where input to be used during the filtering phase. @@ -2638,44 +2740,44 @@ func (i *UserWhereInput) P() (predicate.User, error) { if i.NameContainsFold != nil { predicates = append(predicates, user.NameContainsFold(*i.NameContainsFold)) } - if i.OAuthID != nil { - predicates = append(predicates, user.OAuthIDEQ(*i.OAuthID)) + if i.OauthID != nil { + predicates = append(predicates, user.OauthIDEQ(*i.OauthID)) } - if i.OAuthIDNEQ != nil { - predicates = append(predicates, user.OAuthIDNEQ(*i.OAuthIDNEQ)) + if i.OauthIDNEQ != nil { + predicates = append(predicates, user.OauthIDNEQ(*i.OauthIDNEQ)) } - if len(i.OAuthIDIn) > 0 { - predicates = append(predicates, user.OAuthIDIn(i.OAuthIDIn...)) + if len(i.OauthIDIn) > 0 { + predicates = append(predicates, user.OauthIDIn(i.OauthIDIn...)) } - if len(i.OAuthIDNotIn) > 0 { - predicates = append(predicates, user.OAuthIDNotIn(i.OAuthIDNotIn...)) + if len(i.OauthIDNotIn) > 0 { + predicates = append(predicates, user.OauthIDNotIn(i.OauthIDNotIn...)) } - if i.OAuthIDGT != nil { - predicates = append(predicates, user.OAuthIDGT(*i.OAuthIDGT)) + if i.OauthIDGT != nil { + predicates = append(predicates, user.OauthIDGT(*i.OauthIDGT)) } - if i.OAuthIDGTE != nil { - predicates = append(predicates, user.OAuthIDGTE(*i.OAuthIDGTE)) + if i.OauthIDGTE != nil { + predicates = append(predicates, user.OauthIDGTE(*i.OauthIDGTE)) } - if i.OAuthIDLT != nil { - predicates = append(predicates, user.OAuthIDLT(*i.OAuthIDLT)) + if i.OauthIDLT != nil { + predicates = append(predicates, user.OauthIDLT(*i.OauthIDLT)) } - if i.OAuthIDLTE != nil { - predicates = append(predicates, user.OAuthIDLTE(*i.OAuthIDLTE)) + if i.OauthIDLTE != nil { + predicates = append(predicates, user.OauthIDLTE(*i.OauthIDLTE)) } - if i.OAuthIDContains != nil { - predicates = append(predicates, user.OAuthIDContains(*i.OAuthIDContains)) + if i.OauthIDContains != nil { + predicates = append(predicates, user.OauthIDContains(*i.OauthIDContains)) } - if i.OAuthIDHasPrefix != nil { - predicates = append(predicates, user.OAuthIDHasPrefix(*i.OAuthIDHasPrefix)) + if i.OauthIDHasPrefix != nil { + predicates = append(predicates, user.OauthIDHasPrefix(*i.OauthIDHasPrefix)) } - if i.OAuthIDHasSuffix != nil { - predicates = append(predicates, user.OAuthIDHasSuffix(*i.OAuthIDHasSuffix)) + if i.OauthIDHasSuffix != nil { + predicates = append(predicates, user.OauthIDHasSuffix(*i.OauthIDHasSuffix)) } - if i.OAuthIDEqualFold != nil { - predicates = append(predicates, user.OAuthIDEqualFold(*i.OAuthIDEqualFold)) + if i.OauthIDEqualFold != nil { + predicates = append(predicates, user.OauthIDEqualFold(*i.OauthIDEqualFold)) } - if i.OAuthIDContainsFold != nil { - predicates = append(predicates, user.OAuthIDContainsFold(*i.OAuthIDContainsFold)) + if i.OauthIDContainsFold != nil { + predicates = append(predicates, user.OauthIDContainsFold(*i.OauthIDContainsFold)) } if i.PhotoURL != nil { predicates = append(predicates, user.PhotoURLEQ(*i.PhotoURL)) diff --git a/tavern/ent/hook/hook.go b/tavern/ent/hook/hook.go index 39062a154..0ae8311d4 100644 --- a/tavern/ent/hook/hook.go +++ b/tavern/ent/hook/hook.go @@ -15,11 +15,10 @@ type FileFunc func(context.Context, *ent.FileMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f FileFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.FileMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.FileMutation", m) + if mv, ok := m.(*ent.FileMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.FileMutation", m) } // The JobFunc type is an adapter to allow the use of ordinary @@ -28,11 +27,10 @@ type JobFunc func(context.Context, *ent.JobMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f JobFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.JobMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.JobMutation", m) + if mv, ok := m.(*ent.JobMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.JobMutation", m) } // The SessionFunc type is an adapter to allow the use of ordinary @@ -41,11 +39,10 @@ type SessionFunc func(context.Context, *ent.SessionMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f SessionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.SessionMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SessionMutation", m) + if mv, ok := m.(*ent.SessionMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SessionMutation", m) } // The TagFunc type is an adapter to allow the use of ordinary @@ -54,11 +51,10 @@ type TagFunc func(context.Context, *ent.TagMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f TagFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TagMutation", m) + if mv, ok := m.(*ent.TagMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TagMutation", m) } // The TaskFunc type is an adapter to allow the use of ordinary @@ -67,11 +63,10 @@ type TaskFunc func(context.Context, *ent.TaskMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f TaskFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.TaskMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TaskMutation", m) + if mv, ok := m.(*ent.TaskMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TaskMutation", m) } // The TomeFunc type is an adapter to allow the use of ordinary @@ -80,11 +75,10 @@ type TomeFunc func(context.Context, *ent.TomeMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f TomeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.TomeMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TomeMutation", m) + if mv, ok := m.(*ent.TomeMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TomeMutation", m) } // The UserFunc type is an adapter to allow the use of ordinary @@ -93,11 +87,10 @@ type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error) // Mutate calls f(ctx, m). func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m) + if mv, ok := m.(*ent.UserMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m) } // Condition is a hook condition function. diff --git a/tavern/ent/job.go b/tavern/ent/job.go index 61bda285f..5bd0f9e4f 100644 --- a/tavern/ent/job.go +++ b/tavern/ent/job.go @@ -11,6 +11,7 @@ import ( "github.com/kcarretto/realm/tavern/ent/file" "github.com/kcarretto/realm/tavern/ent/job" "github.com/kcarretto/realm/tavern/ent/tome" + "github.com/kcarretto/realm/tavern/ent/user" ) // Job is the model entity for the Job schema. @@ -19,18 +20,19 @@ type Job struct { // ID of the ent. ID int `json:"id,omitempty"` // Timestamp of when this ent was created - CreatedAt time.Time `json:"createdAt,omitempty"` + CreatedAt time.Time `json:"created_at,omitempty"` // Timestamp of when this ent was last updated - LastModifiedAt time.Time `json:"lastModifiedAt,omitempty"` + LastModifiedAt time.Time `json:"last_modified_at,omitempty"` // Name of the job Name string `json:"name,omitempty"` // Value of parameters that were specified for the job (as a JSON string). Parameters string `json:"parameters,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the JobQuery when eager-loading is set. - Edges JobEdges `json:"edges"` - job_tome *int - job_bundle *int + Edges JobEdges `json:"edges"` + job_tome *int + job_bundle *int + job_creator *int } // JobEdges holds the relations/edges for other nodes in the graph. @@ -41,11 +43,13 @@ type JobEdges struct { Bundle *File `json:"bundle,omitempty"` // Tasks tracking the status and output of individual tome execution on targets Tasks []*Task `json:"tasks,omitempty"` + // User that created the job if available. + Creator *User `json:"creator,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [3]bool + loadedTypes [4]bool // totalCount holds the count of the edges above. - totalCount [3]map[string]int + totalCount [4]map[string]int namedTasks map[string][]*Task } @@ -85,6 +89,19 @@ func (e JobEdges) TasksOrErr() ([]*Task, error) { return nil, &NotLoadedError{edge: "tasks"} } +// CreatorOrErr returns the Creator value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e JobEdges) CreatorOrErr() (*User, error) { + if e.loadedTypes[3] { + if e.Creator == nil { + // Edge was loaded but was not found. + return nil, &NotFoundError{label: user.Label} + } + return e.Creator, nil + } + return nil, &NotLoadedError{edge: "creator"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*Job) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) @@ -100,6 +117,8 @@ func (*Job) scanValues(columns []string) ([]any, error) { values[i] = new(sql.NullInt64) case job.ForeignKeys[1]: // job_bundle values[i] = new(sql.NullInt64) + case job.ForeignKeys[2]: // job_creator + values[i] = new(sql.NullInt64) default: return nil, fmt.Errorf("unexpected column %q for type Job", columns[i]) } @@ -123,13 +142,13 @@ func (j *Job) assignValues(columns []string, values []any) error { j.ID = int(value.Int64) case job.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field createdAt", values[i]) + return fmt.Errorf("unexpected type %T for field created_at", values[i]) } else if value.Valid { j.CreatedAt = value.Time } case job.FieldLastModifiedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field lastModifiedAt", values[i]) + return fmt.Errorf("unexpected type %T for field last_modified_at", values[i]) } else if value.Valid { j.LastModifiedAt = value.Time } @@ -159,6 +178,13 @@ func (j *Job) assignValues(columns []string, values []any) error { j.job_bundle = new(int) *j.job_bundle = int(value.Int64) } + case job.ForeignKeys[2]: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for edge-field job_creator", value) + } else if value.Valid { + j.job_creator = new(int) + *j.job_creator = int(value.Int64) + } } } return nil @@ -166,24 +192,29 @@ func (j *Job) assignValues(columns []string, values []any) error { // QueryTome queries the "tome" edge of the Job entity. func (j *Job) QueryTome() *TomeQuery { - return (&JobClient{config: j.config}).QueryTome(j) + return NewJobClient(j.config).QueryTome(j) } // QueryBundle queries the "bundle" edge of the Job entity. func (j *Job) QueryBundle() *FileQuery { - return (&JobClient{config: j.config}).QueryBundle(j) + return NewJobClient(j.config).QueryBundle(j) } // QueryTasks queries the "tasks" edge of the Job entity. func (j *Job) QueryTasks() *TaskQuery { - return (&JobClient{config: j.config}).QueryTasks(j) + return NewJobClient(j.config).QueryTasks(j) +} + +// QueryCreator queries the "creator" edge of the Job entity. +func (j *Job) QueryCreator() *UserQuery { + return NewJobClient(j.config).QueryCreator(j) } // Update returns a builder for updating this Job. // Note that you need to call Job.Unwrap() before calling this method if this Job // was returned from a transaction, and the transaction was committed or rolled back. func (j *Job) Update() *JobUpdateOne { - return (&JobClient{config: j.config}).UpdateOne(j) + return NewJobClient(j.config).UpdateOne(j) } // Unwrap unwraps the Job entity that was returned from a transaction after it was closed, @@ -202,10 +233,10 @@ func (j *Job) String() string { var builder strings.Builder builder.WriteString("Job(") builder.WriteString(fmt.Sprintf("id=%v, ", j.ID)) - builder.WriteString("createdAt=") + builder.WriteString("created_at=") builder.WriteString(j.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") - builder.WriteString("lastModifiedAt=") + builder.WriteString("last_modified_at=") builder.WriteString(j.LastModifiedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("name=") @@ -243,9 +274,3 @@ func (j *Job) appendNamedTasks(name string, edges ...*Task) { // Jobs is a parsable slice of Job. type Jobs []*Job - -func (j Jobs) config(cfg config) { - for _i := range j { - j[_i].config = cfg - } -} diff --git a/tavern/ent/job/job.go b/tavern/ent/job/job.go index b398c19fd..7958c2041 100644 --- a/tavern/ent/job/job.go +++ b/tavern/ent/job/job.go @@ -11,9 +11,9 @@ const ( Label = "job" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldCreatedAt holds the string denoting the createdat field in the database. + // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" - // FieldLastModifiedAt holds the string denoting the lastmodifiedat field in the database. + // FieldLastModifiedAt holds the string denoting the last_modified_at field in the database. FieldLastModifiedAt = "last_modified_at" // FieldName holds the string denoting the name field in the database. FieldName = "name" @@ -25,6 +25,8 @@ const ( EdgeBundle = "bundle" // EdgeTasks holds the string denoting the tasks edge name in mutations. EdgeTasks = "tasks" + // EdgeCreator holds the string denoting the creator edge name in mutations. + EdgeCreator = "creator" // Table holds the table name of the job in the database. Table = "jobs" // TomeTable is the table that holds the tome relation/edge. @@ -48,6 +50,13 @@ const ( TasksInverseTable = "tasks" // TasksColumn is the table column denoting the tasks relation/edge. TasksColumn = "job_tasks" + // CreatorTable is the table that holds the creator relation/edge. + CreatorTable = "jobs" + // CreatorInverseTable is the table name for the User entity. + // It exists in this package in order to avoid circular dependency with the "user" package. + CreatorInverseTable = "users" + // CreatorColumn is the table column denoting the creator relation/edge. + CreatorColumn = "job_creator" ) // Columns holds all SQL columns for job fields. @@ -64,6 +73,7 @@ var Columns = []string{ var ForeignKeys = []string{ "job_tome", "job_bundle", + "job_creator", } // ValidColumn reports if the column name is valid (part of the table columns). @@ -82,11 +92,11 @@ func ValidColumn(column string) bool { } var ( - // DefaultCreatedAt holds the default value on creation for the "createdAt" field. + // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time - // DefaultLastModifiedAt holds the default value on creation for the "lastModifiedAt" field. + // DefaultLastModifiedAt holds the default value on creation for the "last_modified_at" field. DefaultLastModifiedAt func() time.Time - // UpdateDefaultLastModifiedAt holds the default value on update for the "lastModifiedAt" field. + // UpdateDefaultLastModifiedAt holds the default value on update for the "last_modified_at" field. UpdateDefaultLastModifiedAt func() time.Time // NameValidator is a validator for the "name" field. It is called by the builders before save. NameValidator func(string) error diff --git a/tavern/ent/job/where.go b/tavern/ent/job/where.go index 1e871e87a..cc1647223 100644 --- a/tavern/ent/job/where.go +++ b/tavern/ent/job/where.go @@ -12,441 +12,287 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Job(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Job(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Job(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Job { - return predicate.Job(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.Job(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Job { - return predicate.Job(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.Job(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Job(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Job(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Job(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Job(sql.FieldLTE(FieldID, id)) } -// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Job(sql.FieldEQ(FieldCreatedAt, v)) } -// LastModifiedAt applies equality check predicate on the "lastModifiedAt" field. It's identical to LastModifiedAtEQ. +// LastModifiedAt applies equality check predicate on the "last_modified_at" field. It's identical to LastModifiedAtEQ. func LastModifiedAt(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Job(sql.FieldEQ(FieldLastModifiedAt, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldEQ(FieldName, v)) } // Parameters applies equality check predicate on the "parameters" field. It's identical to ParametersEQ. func Parameters(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldEQ(FieldParameters, v)) } -// CreatedAtEQ applies the EQ predicate on the "createdAt" field. +// CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Job(sql.FieldEQ(FieldCreatedAt, v)) } -// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Job(sql.FieldNEQ(FieldCreatedAt, v)) } -// CreatedAtIn applies the In predicate on the "createdAt" field. +// CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.Job { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.Job(sql.FieldIn(FieldCreatedAt, vs...)) } -// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.Job { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.Job(sql.FieldNotIn(FieldCreatedAt, vs...)) } -// CreatedAtGT applies the GT predicate on the "createdAt" field. +// CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.Job(sql.FieldGT(FieldCreatedAt, v)) } -// CreatedAtGTE applies the GTE predicate on the "createdAt" field. +// CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Job(sql.FieldGTE(FieldCreatedAt, v)) } -// CreatedAtLT applies the LT predicate on the "createdAt" field. +// CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.Job(sql.FieldLT(FieldCreatedAt, v)) } -// CreatedAtLTE applies the LTE predicate on the "createdAt" field. +// CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Job(sql.FieldLTE(FieldCreatedAt, v)) } -// LastModifiedAtEQ applies the EQ predicate on the "lastModifiedAt" field. +// LastModifiedAtEQ applies the EQ predicate on the "last_modified_at" field. func LastModifiedAtEQ(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Job(sql.FieldEQ(FieldLastModifiedAt, v)) } -// LastModifiedAtNEQ applies the NEQ predicate on the "lastModifiedAt" field. +// LastModifiedAtNEQ applies the NEQ predicate on the "last_modified_at" field. func LastModifiedAtNEQ(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Job(sql.FieldNEQ(FieldLastModifiedAt, v)) } -// LastModifiedAtIn applies the In predicate on the "lastModifiedAt" field. +// LastModifiedAtIn applies the In predicate on the "last_modified_at" field. func LastModifiedAtIn(vs ...time.Time) predicate.Job { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldLastModifiedAt), v...)) - }) + return predicate.Job(sql.FieldIn(FieldLastModifiedAt, vs...)) } -// LastModifiedAtNotIn applies the NotIn predicate on the "lastModifiedAt" field. +// LastModifiedAtNotIn applies the NotIn predicate on the "last_modified_at" field. func LastModifiedAtNotIn(vs ...time.Time) predicate.Job { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldLastModifiedAt), v...)) - }) + return predicate.Job(sql.FieldNotIn(FieldLastModifiedAt, vs...)) } -// LastModifiedAtGT applies the GT predicate on the "lastModifiedAt" field. +// LastModifiedAtGT applies the GT predicate on the "last_modified_at" field. func LastModifiedAtGT(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Job(sql.FieldGT(FieldLastModifiedAt, v)) } -// LastModifiedAtGTE applies the GTE predicate on the "lastModifiedAt" field. +// LastModifiedAtGTE applies the GTE predicate on the "last_modified_at" field. func LastModifiedAtGTE(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Job(sql.FieldGTE(FieldLastModifiedAt, v)) } -// LastModifiedAtLT applies the LT predicate on the "lastModifiedAt" field. +// LastModifiedAtLT applies the LT predicate on the "last_modified_at" field. func LastModifiedAtLT(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Job(sql.FieldLT(FieldLastModifiedAt, v)) } -// LastModifiedAtLTE applies the LTE predicate on the "lastModifiedAt" field. +// LastModifiedAtLTE applies the LTE predicate on the "last_modified_at" field. func LastModifiedAtLTE(v time.Time) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Job(sql.FieldLTE(FieldLastModifiedAt, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.Job { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.Job(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.Job { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.Job(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.Job(sql.FieldContainsFold(FieldName, v)) } // ParametersEQ applies the EQ predicate on the "parameters" field. func ParametersEQ(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldEQ(FieldParameters, v)) } // ParametersNEQ applies the NEQ predicate on the "parameters" field. func ParametersNEQ(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldNEQ(FieldParameters, v)) } // ParametersIn applies the In predicate on the "parameters" field. func ParametersIn(vs ...string) predicate.Job { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldParameters), v...)) - }) + return predicate.Job(sql.FieldIn(FieldParameters, vs...)) } // ParametersNotIn applies the NotIn predicate on the "parameters" field. func ParametersNotIn(vs ...string) predicate.Job { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldParameters), v...)) - }) + return predicate.Job(sql.FieldNotIn(FieldParameters, vs...)) } // ParametersGT applies the GT predicate on the "parameters" field. func ParametersGT(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldGT(FieldParameters, v)) } // ParametersGTE applies the GTE predicate on the "parameters" field. func ParametersGTE(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldGTE(FieldParameters, v)) } // ParametersLT applies the LT predicate on the "parameters" field. func ParametersLT(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldLT(FieldParameters, v)) } // ParametersLTE applies the LTE predicate on the "parameters" field. func ParametersLTE(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldLTE(FieldParameters, v)) } // ParametersContains applies the Contains predicate on the "parameters" field. func ParametersContains(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldContains(FieldParameters, v)) } // ParametersHasPrefix applies the HasPrefix predicate on the "parameters" field. func ParametersHasPrefix(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldHasPrefix(FieldParameters, v)) } // ParametersHasSuffix applies the HasSuffix predicate on the "parameters" field. func ParametersHasSuffix(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldHasSuffix(FieldParameters, v)) } // ParametersIsNil applies the IsNil predicate on the "parameters" field. func ParametersIsNil() predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldParameters))) - }) + return predicate.Job(sql.FieldIsNull(FieldParameters)) } // ParametersNotNil applies the NotNil predicate on the "parameters" field. func ParametersNotNil() predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldParameters))) - }) + return predicate.Job(sql.FieldNotNull(FieldParameters)) } // ParametersEqualFold applies the EqualFold predicate on the "parameters" field. func ParametersEqualFold(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldEqualFold(FieldParameters, v)) } // ParametersContainsFold applies the ContainsFold predicate on the "parameters" field. func ParametersContainsFold(v string) predicate.Job { - return predicate.Job(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldParameters), v)) - }) + return predicate.Job(sql.FieldContainsFold(FieldParameters, v)) } // HasTome applies the HasEdge predicate on the "tome" edge. @@ -454,7 +300,6 @@ func HasTome() predicate.Job { return predicate.Job(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(TomeTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, false, TomeTable, TomeColumn), ) sqlgraph.HasNeighbors(s, step) @@ -482,7 +327,6 @@ func HasBundle() predicate.Job { return predicate.Job(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(BundleTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, false, BundleTable, BundleColumn), ) sqlgraph.HasNeighbors(s, step) @@ -510,7 +354,6 @@ func HasTasks() predicate.Job { return predicate.Job(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(TasksTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, TasksTable, TasksColumn), ) sqlgraph.HasNeighbors(s, step) @@ -533,6 +376,33 @@ func HasTasksWith(preds ...predicate.Task) predicate.Job { }) } +// HasCreator applies the HasEdge predicate on the "creator" edge. +func HasCreator() predicate.Job { + return predicate.Job(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CreatorTable, CreatorColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCreatorWith applies the HasEdge predicate on the "creator" edge with a given conditions (other predicates). +func HasCreatorWith(preds ...predicate.User) predicate.Job { + return predicate.Job(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CreatorInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CreatorTable, CreatorColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.Job) predicate.Job { return predicate.Job(func(s *sql.Selector) { diff --git a/tavern/ent/job_create.go b/tavern/ent/job_create.go index 334c2906a..33f612669 100644 --- a/tavern/ent/job_create.go +++ b/tavern/ent/job_create.go @@ -14,6 +14,7 @@ import ( "github.com/kcarretto/realm/tavern/ent/job" "github.com/kcarretto/realm/tavern/ent/task" "github.com/kcarretto/realm/tavern/ent/tome" + "github.com/kcarretto/realm/tavern/ent/user" ) // JobCreate is the builder for creating a Job entity. @@ -23,13 +24,13 @@ type JobCreate struct { hooks []Hook } -// SetCreatedAt sets the "createdAt" field. +// SetCreatedAt sets the "created_at" field. func (jc *JobCreate) SetCreatedAt(t time.Time) *JobCreate { jc.mutation.SetCreatedAt(t) return jc } -// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (jc *JobCreate) SetNillableCreatedAt(t *time.Time) *JobCreate { if t != nil { jc.SetCreatedAt(*t) @@ -37,13 +38,13 @@ func (jc *JobCreate) SetNillableCreatedAt(t *time.Time) *JobCreate { return jc } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (jc *JobCreate) SetLastModifiedAt(t time.Time) *JobCreate { jc.mutation.SetLastModifiedAt(t) return jc } -// SetNillableLastModifiedAt sets the "lastModifiedAt" field if the given value is not nil. +// SetNillableLastModifiedAt sets the "last_modified_at" field if the given value is not nil. func (jc *JobCreate) SetNillableLastModifiedAt(t *time.Time) *JobCreate { if t != nil { jc.SetLastModifiedAt(*t) @@ -116,6 +117,25 @@ func (jc *JobCreate) AddTasks(t ...*Task) *JobCreate { return jc.AddTaskIDs(ids...) } +// SetCreatorID sets the "creator" edge to the User entity by ID. +func (jc *JobCreate) SetCreatorID(id int) *JobCreate { + jc.mutation.SetCreatorID(id) + return jc +} + +// SetNillableCreatorID sets the "creator" edge to the User entity by ID if the given value is not nil. +func (jc *JobCreate) SetNillableCreatorID(id *int) *JobCreate { + if id != nil { + jc = jc.SetCreatorID(*id) + } + return jc +} + +// SetCreator sets the "creator" edge to the User entity. +func (jc *JobCreate) SetCreator(u *User) *JobCreate { + return jc.SetCreatorID(u.ID) +} + // Mutation returns the JobMutation object of the builder. func (jc *JobCreate) Mutation() *JobMutation { return jc.mutation @@ -123,50 +143,8 @@ func (jc *JobCreate) Mutation() *JobMutation { // Save creates the Job in the database. func (jc *JobCreate) Save(ctx context.Context) (*Job, error) { - var ( - err error - node *Job - ) jc.defaults() - if len(jc.hooks) == 0 { - if err = jc.check(); err != nil { - return nil, err - } - node, err = jc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*JobMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = jc.check(); err != nil { - return nil, err - } - jc.mutation = mutation - if node, err = jc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(jc.hooks) - 1; i >= 0; i-- { - if jc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = jc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, jc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Job) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from JobMutation", v) - } - node = nv - } - return node, err + return withHooks[*Job, JobMutation](ctx, jc.sqlSave, jc.mutation, jc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -206,10 +184,10 @@ func (jc *JobCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (jc *JobCreate) check() error { if _, ok := jc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "Job.createdAt"`)} + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Job.created_at"`)} } if _, ok := jc.mutation.LastModifiedAt(); !ok { - return &ValidationError{Name: "lastModifiedAt", err: errors.New(`ent: missing required field "Job.lastModifiedAt"`)} + return &ValidationError{Name: "last_modified_at", err: errors.New(`ent: missing required field "Job.last_modified_at"`)} } if _, ok := jc.mutation.Name(); !ok { return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Job.name"`)} @@ -226,6 +204,9 @@ func (jc *JobCreate) check() error { } func (jc *JobCreate) sqlSave(ctx context.Context) (*Job, error) { + if err := jc.check(); err != nil { + return nil, err + } _node, _spec := jc.createSpec() if err := sqlgraph.CreateNode(ctx, jc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -235,19 +216,15 @@ func (jc *JobCreate) sqlSave(ctx context.Context) (*Job, error) { } id := _spec.ID.Value.(int64) _node.ID = int(id) + jc.mutation.id = &_node.ID + jc.mutation.done = true return _node, nil } func (jc *JobCreate) createSpec() (*Job, *sqlgraph.CreateSpec) { var ( _node = &Job{config: jc.config} - _spec = &sqlgraph.CreateSpec{ - Table: job.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: job.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(job.Table, sqlgraph.NewFieldSpec(job.FieldID, field.TypeInt)) ) if value, ok := jc.mutation.CreatedAt(); ok { _spec.SetField(job.FieldCreatedAt, field.TypeTime, value) @@ -324,6 +301,26 @@ func (jc *JobCreate) createSpec() (*Job, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := jc.mutation.CreatorIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: job.CreatorTable, + Columns: []string{job.CreatorColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: user.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.job_creator = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } return _node, _spec } diff --git a/tavern/ent/job_delete.go b/tavern/ent/job_delete.go index 677aca506..ff2eb5ea6 100644 --- a/tavern/ent/job_delete.go +++ b/tavern/ent/job_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (jd *JobDelete) Where(ps ...predicate.Job) *JobDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (jd *JobDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(jd.hooks) == 0 { - affected, err = jd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*JobMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - jd.mutation = mutation - affected, err = jd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(jd.hooks) - 1; i >= 0; i-- { - if jd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = jd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, jd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, JobMutation](ctx, jd.sqlExec, jd.mutation, jd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (jd *JobDelete) ExecX(ctx context.Context) int { } func (jd *JobDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: job.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: job.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(job.Table, sqlgraph.NewFieldSpec(job.FieldID, field.TypeInt)) if ps := jd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (jd *JobDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + jd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type JobDeleteOne struct { jd *JobDelete } +// Where appends a list predicates to the JobDelete builder. +func (jdo *JobDeleteOne) Where(ps ...predicate.Job) *JobDeleteOne { + jdo.jd.mutation.Where(ps...) + return jdo +} + // Exec executes the deletion query. func (jdo *JobDeleteOne) Exec(ctx context.Context) error { n, err := jdo.jd.Exec(ctx) @@ -111,5 +82,7 @@ func (jdo *JobDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (jdo *JobDeleteOne) ExecX(ctx context.Context) { - jdo.jd.ExecX(ctx) + if err := jdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/tavern/ent/job_query.go b/tavern/ent/job_query.go index 93743a4f3..a972941cb 100644 --- a/tavern/ent/job_query.go +++ b/tavern/ent/job_query.go @@ -16,20 +16,20 @@ import ( "github.com/kcarretto/realm/tavern/ent/predicate" "github.com/kcarretto/realm/tavern/ent/task" "github.com/kcarretto/realm/tavern/ent/tome" + "github.com/kcarretto/realm/tavern/ent/user" ) // JobQuery is the builder for querying Job entities. type JobQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.Job withTome *TomeQuery withBundle *FileQuery withTasks *TaskQuery + withCreator *UserQuery withFKs bool modifiers []func(*sql.Selector) loadTotal []func(context.Context, []*Job) error @@ -45,26 +45,26 @@ func (jq *JobQuery) Where(ps ...predicate.Job) *JobQuery { return jq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (jq *JobQuery) Limit(limit int) *JobQuery { - jq.limit = &limit + jq.ctx.Limit = &limit return jq } -// Offset adds an offset step to the query. +// Offset to start from. func (jq *JobQuery) Offset(offset int) *JobQuery { - jq.offset = &offset + jq.ctx.Offset = &offset return jq } // 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 (jq *JobQuery) Unique(unique bool) *JobQuery { - jq.unique = &unique + jq.ctx.Unique = &unique return jq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (jq *JobQuery) Order(o ...OrderFunc) *JobQuery { jq.order = append(jq.order, o...) return jq @@ -72,7 +72,7 @@ func (jq *JobQuery) Order(o ...OrderFunc) *JobQuery { // QueryTome chains the current query on the "tome" edge. func (jq *JobQuery) QueryTome() *TomeQuery { - query := &TomeQuery{config: jq.config} + query := (&TomeClient{config: jq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := jq.prepareQuery(ctx); err != nil { return nil, err @@ -94,7 +94,7 @@ func (jq *JobQuery) QueryTome() *TomeQuery { // QueryBundle chains the current query on the "bundle" edge. func (jq *JobQuery) QueryBundle() *FileQuery { - query := &FileQuery{config: jq.config} + query := (&FileClient{config: jq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := jq.prepareQuery(ctx); err != nil { return nil, err @@ -116,7 +116,7 @@ func (jq *JobQuery) QueryBundle() *FileQuery { // QueryTasks chains the current query on the "tasks" edge. func (jq *JobQuery) QueryTasks() *TaskQuery { - query := &TaskQuery{config: jq.config} + query := (&TaskClient{config: jq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := jq.prepareQuery(ctx); err != nil { return nil, err @@ -136,10 +136,32 @@ func (jq *JobQuery) QueryTasks() *TaskQuery { return query } +// QueryCreator chains the current query on the "creator" edge. +func (jq *JobQuery) QueryCreator() *UserQuery { + query := (&UserClient{config: jq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := jq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := jq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(job.Table, job.FieldID, selector), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, job.CreatorTable, job.CreatorColumn), + ) + fromU = sqlgraph.SetNeighbors(jq.driver.Dialect(), step) + return fromU, nil + } + return query +} + // First returns the first Job entity from the query. // Returns a *NotFoundError when no Job was found. func (jq *JobQuery) First(ctx context.Context) (*Job, error) { - nodes, err := jq.Limit(1).All(ctx) + nodes, err := jq.Limit(1).All(setContextOp(ctx, jq.ctx, "First")) if err != nil { return nil, err } @@ -162,7 +184,7 @@ func (jq *JobQuery) FirstX(ctx context.Context) *Job { // Returns a *NotFoundError when no Job ID was found. func (jq *JobQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = jq.Limit(1).IDs(ctx); err != nil { + if ids, err = jq.Limit(1).IDs(setContextOp(ctx, jq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -185,7 +207,7 @@ func (jq *JobQuery) FirstIDX(ctx context.Context) int { // Returns a *NotSingularError when more than one Job entity is found. // Returns a *NotFoundError when no Job entities are found. func (jq *JobQuery) Only(ctx context.Context) (*Job, error) { - nodes, err := jq.Limit(2).All(ctx) + nodes, err := jq.Limit(2).All(setContextOp(ctx, jq.ctx, "Only")) if err != nil { return nil, err } @@ -213,7 +235,7 @@ func (jq *JobQuery) OnlyX(ctx context.Context) *Job { // Returns a *NotFoundError when no entities are found. func (jq *JobQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = jq.Limit(2).IDs(ctx); err != nil { + if ids, err = jq.Limit(2).IDs(setContextOp(ctx, jq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -238,10 +260,12 @@ func (jq *JobQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of Jobs. func (jq *JobQuery) All(ctx context.Context) ([]*Job, error) { + ctx = setContextOp(ctx, jq.ctx, "All") if err := jq.prepareQuery(ctx); err != nil { return nil, err } - return jq.sqlAll(ctx) + qr := querierAll[[]*Job, *JobQuery]() + return withInterceptors[[]*Job](ctx, jq, qr, jq.inters) } // AllX is like All, but panics if an error occurs. @@ -254,9 +278,12 @@ func (jq *JobQuery) AllX(ctx context.Context) []*Job { } // IDs executes the query and returns a list of Job IDs. -func (jq *JobQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := jq.Select(job.FieldID).Scan(ctx, &ids); err != nil { +func (jq *JobQuery) IDs(ctx context.Context) (ids []int, err error) { + if jq.ctx.Unique == nil && jq.path != nil { + jq.Unique(true) + } + ctx = setContextOp(ctx, jq.ctx, "IDs") + if err = jq.Select(job.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -273,10 +300,11 @@ func (jq *JobQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (jq *JobQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, jq.ctx, "Count") if err := jq.prepareQuery(ctx); err != nil { return 0, err } - return jq.sqlCount(ctx) + return withInterceptors[int](ctx, jq, querierCount[*JobQuery](), jq.inters) } // CountX is like Count, but panics if an error occurs. @@ -290,10 +318,15 @@ func (jq *JobQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (jq *JobQuery) Exist(ctx context.Context) (bool, error) { - if err := jq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, jq.ctx, "Exist") + switch _, err := jq.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 jq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -312,25 +345,25 @@ func (jq *JobQuery) Clone() *JobQuery { return nil } return &JobQuery{ - config: jq.config, - limit: jq.limit, - offset: jq.offset, - order: append([]OrderFunc{}, jq.order...), - predicates: append([]predicate.Job{}, jq.predicates...), - withTome: jq.withTome.Clone(), - withBundle: jq.withBundle.Clone(), - withTasks: jq.withTasks.Clone(), + config: jq.config, + ctx: jq.ctx.Clone(), + order: append([]OrderFunc{}, jq.order...), + inters: append([]Interceptor{}, jq.inters...), + predicates: append([]predicate.Job{}, jq.predicates...), + withTome: jq.withTome.Clone(), + withBundle: jq.withBundle.Clone(), + withTasks: jq.withTasks.Clone(), + withCreator: jq.withCreator.Clone(), // clone intermediate query. - sql: jq.sql.Clone(), - path: jq.path, - unique: jq.unique, + sql: jq.sql.Clone(), + path: jq.path, } } // WithTome tells the query-builder to eager-load the nodes that are connected to // the "tome" edge. The optional arguments are used to configure the query builder of the edge. func (jq *JobQuery) WithTome(opts ...func(*TomeQuery)) *JobQuery { - query := &TomeQuery{config: jq.config} + query := (&TomeClient{config: jq.config}).Query() for _, opt := range opts { opt(query) } @@ -341,7 +374,7 @@ func (jq *JobQuery) WithTome(opts ...func(*TomeQuery)) *JobQuery { // WithBundle tells the query-builder to eager-load the nodes that are connected to // the "bundle" edge. The optional arguments are used to configure the query builder of the edge. func (jq *JobQuery) WithBundle(opts ...func(*FileQuery)) *JobQuery { - query := &FileQuery{config: jq.config} + query := (&FileClient{config: jq.config}).Query() for _, opt := range opts { opt(query) } @@ -352,7 +385,7 @@ func (jq *JobQuery) WithBundle(opts ...func(*FileQuery)) *JobQuery { // WithTasks tells the query-builder to eager-load the nodes that are connected to // the "tasks" edge. The optional arguments are used to configure the query builder of the edge. func (jq *JobQuery) WithTasks(opts ...func(*TaskQuery)) *JobQuery { - query := &TaskQuery{config: jq.config} + query := (&TaskClient{config: jq.config}).Query() for _, opt := range opts { opt(query) } @@ -360,13 +393,24 @@ func (jq *JobQuery) WithTasks(opts ...func(*TaskQuery)) *JobQuery { return jq } +// WithCreator tells the query-builder to eager-load the nodes that are connected to +// the "creator" edge. The optional arguments are used to configure the query builder of the edge. +func (jq *JobQuery) WithCreator(opts ...func(*UserQuery)) *JobQuery { + query := (&UserClient{config: jq.config}).Query() + for _, opt := range opts { + opt(query) + } + jq.withCreator = query + return jq +} + // GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // // Example: // // var v []struct { -// CreatedAt time.Time `json:"createdAt,omitempty"` +// CreatedAt time.Time `json:"created_at,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -375,16 +419,11 @@ func (jq *JobQuery) WithTasks(opts ...func(*TaskQuery)) *JobQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (jq *JobQuery) GroupBy(field string, fields ...string) *JobGroupBy { - grbuild := &JobGroupBy{config: jq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := jq.prepareQuery(ctx); err != nil { - return nil, err - } - return jq.sqlQuery(ctx), nil - } + jq.ctx.Fields = append([]string{field}, fields...) + grbuild := &JobGroupBy{build: jq} + grbuild.flds = &jq.ctx.Fields grbuild.label = job.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -394,18 +433,18 @@ func (jq *JobQuery) GroupBy(field string, fields ...string) *JobGroupBy { // Example: // // var v []struct { -// CreatedAt time.Time `json:"createdAt,omitempty"` +// CreatedAt time.Time `json:"created_at,omitempty"` // } // // client.Job.Query(). // Select(job.FieldCreatedAt). // Scan(ctx, &v) func (jq *JobQuery) Select(fields ...string) *JobSelect { - jq.fields = append(jq.fields, fields...) - selbuild := &JobSelect{JobQuery: jq} - selbuild.label = job.Label - selbuild.flds, selbuild.scan = &jq.fields, selbuild.Scan - return selbuild + jq.ctx.Fields = append(jq.ctx.Fields, fields...) + sbuild := &JobSelect{JobQuery: jq} + sbuild.label = job.Label + sbuild.flds, sbuild.scan = &jq.ctx.Fields, sbuild.Scan + return sbuild } // Aggregate returns a JobSelect configured with the given aggregations. @@ -414,7 +453,17 @@ func (jq *JobQuery) Aggregate(fns ...AggregateFunc) *JobSelect { } func (jq *JobQuery) prepareQuery(ctx context.Context) error { - for _, f := range jq.fields { + for _, inter := range jq.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, jq); err != nil { + return err + } + } + } + for _, f := range jq.ctx.Fields { if !job.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -434,13 +483,14 @@ func (jq *JobQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Job, err nodes = []*Job{} withFKs = jq.withFKs _spec = jq.querySpec() - loadedTypes = [3]bool{ + loadedTypes = [4]bool{ jq.withTome != nil, jq.withBundle != nil, jq.withTasks != nil, + jq.withCreator != nil, } ) - if jq.withTome != nil || jq.withBundle != nil { + if jq.withTome != nil || jq.withBundle != nil || jq.withCreator != nil { withFKs = true } if withFKs { @@ -486,6 +536,12 @@ func (jq *JobQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Job, err return nil, err } } + if query := jq.withCreator; query != nil { + if err := jq.loadCreator(ctx, query, nodes, nil, + func(n *Job, e *User) { n.Edges.Creator = e }); err != nil { + return nil, err + } + } for name, query := range jq.withNamedTasks { if err := jq.loadTasks(ctx, query, nodes, func(n *Job) { n.appendNamedTasks(name) }, @@ -514,6 +570,9 @@ func (jq *JobQuery) loadTome(ctx context.Context, query *TomeQuery, nodes []*Job } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(tome.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -543,6 +602,9 @@ func (jq *JobQuery) loadBundle(ctx context.Context, query *FileQuery, nodes []*J } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(file.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -590,47 +652,60 @@ func (jq *JobQuery) loadTasks(ctx context.Context, query *TaskQuery, nodes []*Jo } return nil } +func (jq *JobQuery) loadCreator(ctx context.Context, query *UserQuery, nodes []*Job, init func(*Job), assign func(*Job, *User)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*Job) + for i := range nodes { + if nodes[i].job_creator == nil { + continue + } + fk := *nodes[i].job_creator + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + 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 { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "job_creator" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} func (jq *JobQuery) sqlCount(ctx context.Context) (int, error) { _spec := jq.querySpec() if len(jq.modifiers) > 0 { _spec.Modifiers = jq.modifiers } - _spec.Node.Columns = jq.fields - if len(jq.fields) > 0 { - _spec.Unique = jq.unique != nil && *jq.unique + _spec.Node.Columns = jq.ctx.Fields + if len(jq.ctx.Fields) > 0 { + _spec.Unique = jq.ctx.Unique != nil && *jq.ctx.Unique } return sqlgraph.CountNodes(ctx, jq.driver, _spec) } -func (jq *JobQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := jq.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 (jq *JobQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: job.Table, - Columns: job.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: job.FieldID, - }, - }, - From: jq.sql, - Unique: true, - } - if unique := jq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(job.Table, job.Columns, sqlgraph.NewFieldSpec(job.FieldID, field.TypeInt)) + _spec.From = jq.sql + if unique := jq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if jq.path != nil { + _spec.Unique = true } - if fields := jq.fields; len(fields) > 0 { + if fields := jq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, job.FieldID) for i := range fields { @@ -646,10 +721,10 @@ func (jq *JobQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := jq.limit; limit != nil { + if limit := jq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := jq.offset; offset != nil { + if offset := jq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := jq.order; len(ps) > 0 { @@ -665,7 +740,7 @@ func (jq *JobQuery) querySpec() *sqlgraph.QuerySpec { func (jq *JobQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(jq.driver.Dialect()) t1 := builder.Table(job.Table) - columns := jq.fields + columns := jq.ctx.Fields if len(columns) == 0 { columns = job.Columns } @@ -674,7 +749,7 @@ func (jq *JobQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = jq.sql selector.Select(selector.Columns(columns...)...) } - if jq.unique != nil && *jq.unique { + if jq.ctx.Unique != nil && *jq.ctx.Unique { selector.Distinct() } for _, p := range jq.predicates { @@ -683,12 +758,12 @@ func (jq *JobQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range jq.order { p(selector) } - if offset := jq.offset; offset != nil { + if offset := jq.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 := jq.limit; limit != nil { + if limit := jq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -697,7 +772,7 @@ func (jq *JobQuery) sqlQuery(ctx context.Context) *sql.Selector { // WithNamedTasks tells the query-builder to eager-load the nodes that are connected to the "tasks" // edge with the given name. The optional arguments are used to configure the query builder of the edge. func (jq *JobQuery) WithNamedTasks(name string, opts ...func(*TaskQuery)) *JobQuery { - query := &TaskQuery{config: jq.config} + query := (&TaskClient{config: jq.config}).Query() for _, opt := range opts { opt(query) } @@ -710,13 +785,8 @@ func (jq *JobQuery) WithNamedTasks(name string, opts ...func(*TaskQuery)) *JobQu // JobGroupBy is the group-by builder for Job entities. type JobGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *JobQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -725,58 +795,46 @@ func (jgb *JobGroupBy) Aggregate(fns ...AggregateFunc) *JobGroupBy { return jgb } -// 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 (jgb *JobGroupBy) Scan(ctx context.Context, v any) error { - query, err := jgb.path(ctx) - if err != nil { + ctx = setContextOp(ctx, jgb.build.ctx, "GroupBy") + if err := jgb.build.prepareQuery(ctx); err != nil { return err } - jgb.sql = query - return jgb.sqlScan(ctx, v) + return scanWithInterceptors[*JobQuery, *JobGroupBy](ctx, jgb.build, jgb, jgb.build.inters, v) } -func (jgb *JobGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range jgb.fields { - if !job.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} +func (jgb *JobGroupBy) sqlScan(ctx context.Context, root *JobQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(jgb.fns)) + for _, fn := range jgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*jgb.flds)+len(jgb.fns)) + for _, f := range *jgb.flds { + columns = append(columns, selector.C(f)) } + columns = append(columns, aggregation...) + selector.Select(columns...) } - selector := jgb.sqlQuery() + selector.GroupBy(selector.Columns(*jgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := jgb.driver.Query(ctx, query, args, rows); err != nil { + if err := jgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (jgb *JobGroupBy) sqlQuery() *sql.Selector { - selector := jgb.sql.Select() - aggregation := make([]string, 0, len(jgb.fns)) - for _, fn := range jgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(jgb.fields)+len(jgb.fns)) - for _, f := range jgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(jgb.fields...)...) -} - // JobSelect is the builder for selecting fields of Job entities. type JobSelect struct { *JobQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -787,26 +845,27 @@ func (js *JobSelect) Aggregate(fns ...AggregateFunc) *JobSelect { // Scan applies the selector query and scans the result into the given value. func (js *JobSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, js.ctx, "Select") if err := js.prepareQuery(ctx); err != nil { return err } - js.sql = js.JobQuery.sqlQuery(ctx) - return js.sqlScan(ctx, v) + return scanWithInterceptors[*JobQuery, *JobSelect](ctx, js.JobQuery, js, js.inters, v) } -func (js *JobSelect) sqlScan(ctx context.Context, v any) error { +func (js *JobSelect) sqlScan(ctx context.Context, root *JobQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(js.fns)) for _, fn := range js.fns { - aggregation = append(aggregation, fn(js.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*js.selector.flds); { case n == 0 && len(aggregation) > 0: - js.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - js.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := js.sql.Query() + query, args := selector.Query() if err := js.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/tavern/ent/job_update.go b/tavern/ent/job_update.go index f9017b608..af4a9af0d 100644 --- a/tavern/ent/job_update.go +++ b/tavern/ent/job_update.go @@ -16,6 +16,7 @@ import ( "github.com/kcarretto/realm/tavern/ent/predicate" "github.com/kcarretto/realm/tavern/ent/task" "github.com/kcarretto/realm/tavern/ent/tome" + "github.com/kcarretto/realm/tavern/ent/user" ) // JobUpdate is the builder for updating Job entities. @@ -31,7 +32,7 @@ func (ju *JobUpdate) Where(ps ...predicate.Job) *JobUpdate { return ju } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (ju *JobUpdate) SetLastModifiedAt(t time.Time) *JobUpdate { ju.mutation.SetLastModifiedAt(t) return ju @@ -108,6 +109,25 @@ func (ju *JobUpdate) AddTasks(t ...*Task) *JobUpdate { return ju.AddTaskIDs(ids...) } +// SetCreatorID sets the "creator" edge to the User entity by ID. +func (ju *JobUpdate) SetCreatorID(id int) *JobUpdate { + ju.mutation.SetCreatorID(id) + return ju +} + +// SetNillableCreatorID sets the "creator" edge to the User entity by ID if the given value is not nil. +func (ju *JobUpdate) SetNillableCreatorID(id *int) *JobUpdate { + if id != nil { + ju = ju.SetCreatorID(*id) + } + return ju +} + +// SetCreator sets the "creator" edge to the User entity. +func (ju *JobUpdate) SetCreator(u *User) *JobUpdate { + return ju.SetCreatorID(u.ID) +} + // Mutation returns the JobMutation object of the builder. func (ju *JobUpdate) Mutation() *JobMutation { return ju.mutation @@ -146,43 +166,16 @@ func (ju *JobUpdate) RemoveTasks(t ...*Task) *JobUpdate { return ju.RemoveTaskIDs(ids...) } +// ClearCreator clears the "creator" edge to the User entity. +func (ju *JobUpdate) ClearCreator() *JobUpdate { + ju.mutation.ClearCreator() + return ju +} + // Save executes the query and returns the number of nodes affected by the update operation. func (ju *JobUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) ju.defaults() - if len(ju.hooks) == 0 { - if err = ju.check(); err != nil { - return 0, err - } - affected, err = ju.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*JobMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = ju.check(); err != nil { - return 0, err - } - ju.mutation = mutation - affected, err = ju.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(ju.hooks) - 1; i >= 0; i-- { - if ju.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ju.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ju.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, JobMutation](ctx, ju.sqlSave, ju.mutation, ju.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -229,16 +222,10 @@ func (ju *JobUpdate) check() error { } func (ju *JobUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: job.Table, - Columns: job.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: job.FieldID, - }, - }, + if err := ju.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(job.Table, job.Columns, sqlgraph.NewFieldSpec(job.FieldID, field.TypeInt)) if ps := ju.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -382,6 +369,41 @@ func (ju *JobUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if ju.mutation.CreatorCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: job.CreatorTable, + Columns: []string{job.CreatorColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: user.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := ju.mutation.CreatorIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: job.CreatorTable, + Columns: []string{job.CreatorColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: user.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if n, err = sqlgraph.UpdateNodes(ctx, ju.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{job.Label} @@ -390,6 +412,7 @@ func (ju *JobUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + ju.mutation.done = true return n, nil } @@ -401,7 +424,7 @@ type JobUpdateOne struct { mutation *JobMutation } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (juo *JobUpdateOne) SetLastModifiedAt(t time.Time) *JobUpdateOne { juo.mutation.SetLastModifiedAt(t) return juo @@ -478,6 +501,25 @@ func (juo *JobUpdateOne) AddTasks(t ...*Task) *JobUpdateOne { return juo.AddTaskIDs(ids...) } +// SetCreatorID sets the "creator" edge to the User entity by ID. +func (juo *JobUpdateOne) SetCreatorID(id int) *JobUpdateOne { + juo.mutation.SetCreatorID(id) + return juo +} + +// SetNillableCreatorID sets the "creator" edge to the User entity by ID if the given value is not nil. +func (juo *JobUpdateOne) SetNillableCreatorID(id *int) *JobUpdateOne { + if id != nil { + juo = juo.SetCreatorID(*id) + } + return juo +} + +// SetCreator sets the "creator" edge to the User entity. +func (juo *JobUpdateOne) SetCreator(u *User) *JobUpdateOne { + return juo.SetCreatorID(u.ID) +} + // Mutation returns the JobMutation object of the builder. func (juo *JobUpdateOne) Mutation() *JobMutation { return juo.mutation @@ -516,6 +558,18 @@ func (juo *JobUpdateOne) RemoveTasks(t ...*Task) *JobUpdateOne { return juo.RemoveTaskIDs(ids...) } +// ClearCreator clears the "creator" edge to the User entity. +func (juo *JobUpdateOne) ClearCreator() *JobUpdateOne { + juo.mutation.ClearCreator() + return juo +} + +// Where appends a list predicates to the JobUpdate builder. +func (juo *JobUpdateOne) Where(ps ...predicate.Job) *JobUpdateOne { + juo.mutation.Where(ps...) + return juo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (juo *JobUpdateOne) Select(field string, fields ...string) *JobUpdateOne { @@ -525,47 +579,8 @@ func (juo *JobUpdateOne) Select(field string, fields ...string) *JobUpdateOne { // Save executes the query and returns the updated Job entity. func (juo *JobUpdateOne) Save(ctx context.Context) (*Job, error) { - var ( - err error - node *Job - ) juo.defaults() - if len(juo.hooks) == 0 { - if err = juo.check(); err != nil { - return nil, err - } - node, err = juo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*JobMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = juo.check(); err != nil { - return nil, err - } - juo.mutation = mutation - node, err = juo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(juo.hooks) - 1; i >= 0; i-- { - if juo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = juo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, juo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Job) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from JobMutation", v) - } - node = nv - } - return node, err + return withHooks[*Job, JobMutation](ctx, juo.sqlSave, juo.mutation, juo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -612,16 +627,10 @@ func (juo *JobUpdateOne) check() error { } func (juo *JobUpdateOne) sqlSave(ctx context.Context) (_node *Job, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: job.Table, - Columns: job.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: job.FieldID, - }, - }, + if err := juo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(job.Table, job.Columns, sqlgraph.NewFieldSpec(job.FieldID, field.TypeInt)) id, ok := juo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Job.id" for update`)} @@ -782,6 +791,41 @@ func (juo *JobUpdateOne) sqlSave(ctx context.Context) (_node *Job, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if juo.mutation.CreatorCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: job.CreatorTable, + Columns: []string{job.CreatorColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: user.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := juo.mutation.CreatorIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: job.CreatorTable, + Columns: []string{job.CreatorColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: user.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _node = &Job{config: juo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues @@ -793,5 +837,6 @@ func (juo *JobUpdateOne) sqlSave(ctx context.Context) (_node *Job, err error) { } return nil, err } + juo.mutation.done = true return _node, nil } diff --git a/tavern/ent/migrate/schema.go b/tavern/ent/migrate/schema.go index edc420d28..ccfa0dd7a 100644 --- a/tavern/ent/migrate/schema.go +++ b/tavern/ent/migrate/schema.go @@ -42,6 +42,7 @@ var ( {Name: "parameters", Type: field.TypeString, Nullable: true}, {Name: "job_tome", Type: field.TypeInt}, {Name: "job_bundle", Type: field.TypeInt, Nullable: true}, + {Name: "job_creator", Type: field.TypeInt, Nullable: true}, } // JobsTable holds the schema information for the "jobs" table. JobsTable = &schema.Table{ @@ -61,6 +62,12 @@ var ( RefColumns: []*schema.Column{FilesColumns[0]}, OnDelete: schema.SetNull, }, + { + Symbol: "jobs_users_creator", + Columns: []*schema.Column{JobsColumns[7]}, + RefColumns: []*schema.Column{UsersColumns[0]}, + OnDelete: schema.SetNull, + }, }, } // SessionsColumns holds the columns for the "sessions" table. @@ -72,6 +79,8 @@ var ( {Name: "identifier", Type: field.TypeString, Unique: true}, {Name: "agent_identifier", Type: field.TypeString, Nullable: true}, {Name: "host_identifier", Type: field.TypeString, Nullable: true}, + {Name: "host_primary_ip", Type: field.TypeString, Nullable: true}, + {Name: "host_platform", Type: field.TypeEnum, Enums: []string{"Windows", "Linux", "MacOS", "BSD", "Unknown"}, Default: "Unknown"}, {Name: "last_seen_at", Type: field.TypeTime, Nullable: true}, } // SessionsTable holds the schema information for the "sessions" table. @@ -132,7 +141,7 @@ var ( {Name: "last_modified_at", Type: field.TypeTime}, {Name: "name", Type: field.TypeString, Unique: true}, {Name: "description", Type: field.TypeString}, - {Name: "parameters", Type: field.TypeString, Nullable: true}, + {Name: "param_defs", Type: field.TypeString, Nullable: true}, {Name: "hash", Type: field.TypeString, Size: 100}, {Name: "eldritch", Type: field.TypeString, SchemaType: map[string]string{"mysql": "LONGTEXT"}}, } @@ -200,6 +209,7 @@ func init() { FilesTable.ForeignKeys[0].RefTable = TomesTable JobsTable.ForeignKeys[0].RefTable = TomesTable JobsTable.ForeignKeys[1].RefTable = FilesTable + JobsTable.ForeignKeys[2].RefTable = UsersTable TasksTable.ForeignKeys[0].RefTable = JobsTable TasksTable.ForeignKeys[1].RefTable = SessionsTable SessionTagsTable.ForeignKeys[0].RefTable = SessionsTable diff --git a/tavern/ent/mutation.go b/tavern/ent/mutation.go index d0bd252ae..7261f7a54 100644 --- a/tavern/ent/mutation.go +++ b/tavern/ent/mutation.go @@ -9,6 +9,8 @@ import ( "sync" "time" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" "github.com/kcarretto/realm/tavern/ent/file" "github.com/kcarretto/realm/tavern/ent/job" "github.com/kcarretto/realm/tavern/ent/predicate" @@ -17,8 +19,6 @@ import ( "github.com/kcarretto/realm/tavern/ent/task" "github.com/kcarretto/realm/tavern/ent/tome" "github.com/kcarretto/realm/tavern/ent/user" - - "entgo.io/ent" ) const ( @@ -42,20 +42,20 @@ const ( // FileMutation represents an operation that mutates the File nodes in the graph. type FileMutation struct { config - op Op - typ string - id *int - createdAt *time.Time - lastModifiedAt *time.Time - name *string - size *int - addsize *int - hash *string - content *[]byte - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*File, error) - predicates []predicate.File + op Op + typ string + id *int + created_at *time.Time + last_modified_at *time.Time + name *string + size *int + addsize *int + hash *string + content *[]byte + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*File, error) + predicates []predicate.File } var _ ent.Mutation = (*FileMutation)(nil) @@ -156,21 +156,21 @@ func (m *FileMutation) IDs(ctx context.Context) ([]int, error) { } } -// SetCreatedAt sets the "createdAt" field. +// SetCreatedAt sets the "created_at" field. func (m *FileMutation) SetCreatedAt(t time.Time) { - m.createdAt = &t + m.created_at = &t } -// CreatedAt returns the value of the "createdAt" field in the mutation. +// CreatedAt returns the value of the "created_at" field in the mutation. func (m *FileMutation) CreatedAt() (r time.Time, exists bool) { - v := m.createdAt + v := m.created_at if v == nil { return } return *v, true } -// OldCreatedAt returns the old "createdAt" field's value of the File entity. +// OldCreatedAt returns the old "created_at" field's value of the File entity. // If the File object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *FileMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { @@ -187,26 +187,26 @@ func (m *FileMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error return oldValue.CreatedAt, nil } -// ResetCreatedAt resets all changes to the "createdAt" field. +// ResetCreatedAt resets all changes to the "created_at" field. func (m *FileMutation) ResetCreatedAt() { - m.createdAt = nil + m.created_at = nil } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (m *FileMutation) SetLastModifiedAt(t time.Time) { - m.lastModifiedAt = &t + m.last_modified_at = &t } -// LastModifiedAt returns the value of the "lastModifiedAt" field in the mutation. +// LastModifiedAt returns the value of the "last_modified_at" field in the mutation. func (m *FileMutation) LastModifiedAt() (r time.Time, exists bool) { - v := m.lastModifiedAt + v := m.last_modified_at if v == nil { return } return *v, true } -// OldLastModifiedAt returns the old "lastModifiedAt" field's value of the File entity. +// OldLastModifiedAt returns the old "last_modified_at" field's value of the File entity. // If the File object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *FileMutation) OldLastModifiedAt(ctx context.Context) (v time.Time, err error) { @@ -223,9 +223,9 @@ func (m *FileMutation) OldLastModifiedAt(ctx context.Context) (v time.Time, err return oldValue.LastModifiedAt, nil } -// ResetLastModifiedAt resets all changes to the "lastModifiedAt" field. +// ResetLastModifiedAt resets all changes to the "last_modified_at" field. func (m *FileMutation) ResetLastModifiedAt() { - m.lastModifiedAt = nil + m.last_modified_at = nil } // SetName sets the "name" field. @@ -397,11 +397,26 @@ func (m *FileMutation) Where(ps ...predicate.File) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the FileMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *FileMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.File, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *FileMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *FileMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (File). func (m *FileMutation) Type() string { return m.typ @@ -412,10 +427,10 @@ func (m *FileMutation) Type() string { // AddedFields(). func (m *FileMutation) Fields() []string { fields := make([]string, 0, 6) - if m.createdAt != nil { + if m.created_at != nil { fields = append(fields, file.FieldCreatedAt) } - if m.lastModifiedAt != nil { + if m.last_modified_at != nil { fields = append(fields, file.FieldLastModifiedAt) } if m.name != nil { @@ -659,24 +674,26 @@ func (m *FileMutation) ResetEdge(name string) error { // JobMutation represents an operation that mutates the Job nodes in the graph. type JobMutation struct { config - op Op - typ string - id *int - createdAt *time.Time - lastModifiedAt *time.Time - name *string - parameters *string - clearedFields map[string]struct{} - tome *int - clearedtome bool - bundle *int - clearedbundle bool - tasks map[int]struct{} - removedtasks map[int]struct{} - clearedtasks bool - done bool - oldValue func(context.Context) (*Job, error) - predicates []predicate.Job + op Op + typ string + id *int + created_at *time.Time + last_modified_at *time.Time + name *string + parameters *string + clearedFields map[string]struct{} + tome *int + clearedtome bool + bundle *int + clearedbundle bool + tasks map[int]struct{} + removedtasks map[int]struct{} + clearedtasks bool + creator *int + clearedcreator bool + done bool + oldValue func(context.Context) (*Job, error) + predicates []predicate.Job } var _ ent.Mutation = (*JobMutation)(nil) @@ -777,21 +794,21 @@ func (m *JobMutation) IDs(ctx context.Context) ([]int, error) { } } -// SetCreatedAt sets the "createdAt" field. +// SetCreatedAt sets the "created_at" field. func (m *JobMutation) SetCreatedAt(t time.Time) { - m.createdAt = &t + m.created_at = &t } -// CreatedAt returns the value of the "createdAt" field in the mutation. +// CreatedAt returns the value of the "created_at" field in the mutation. func (m *JobMutation) CreatedAt() (r time.Time, exists bool) { - v := m.createdAt + v := m.created_at if v == nil { return } return *v, true } -// OldCreatedAt returns the old "createdAt" field's value of the Job entity. +// OldCreatedAt returns the old "created_at" field's value of the Job entity. // If the Job object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *JobMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { @@ -808,26 +825,26 @@ func (m *JobMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) return oldValue.CreatedAt, nil } -// ResetCreatedAt resets all changes to the "createdAt" field. +// ResetCreatedAt resets all changes to the "created_at" field. func (m *JobMutation) ResetCreatedAt() { - m.createdAt = nil + m.created_at = nil } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (m *JobMutation) SetLastModifiedAt(t time.Time) { - m.lastModifiedAt = &t + m.last_modified_at = &t } -// LastModifiedAt returns the value of the "lastModifiedAt" field in the mutation. +// LastModifiedAt returns the value of the "last_modified_at" field in the mutation. func (m *JobMutation) LastModifiedAt() (r time.Time, exists bool) { - v := m.lastModifiedAt + v := m.last_modified_at if v == nil { return } return *v, true } -// OldLastModifiedAt returns the old "lastModifiedAt" field's value of the Job entity. +// OldLastModifiedAt returns the old "last_modified_at" field's value of the Job entity. // If the Job object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *JobMutation) OldLastModifiedAt(ctx context.Context) (v time.Time, err error) { @@ -844,9 +861,9 @@ func (m *JobMutation) OldLastModifiedAt(ctx context.Context) (v time.Time, err e return oldValue.LastModifiedAt, nil } -// ResetLastModifiedAt resets all changes to the "lastModifiedAt" field. +// ResetLastModifiedAt resets all changes to the "last_modified_at" field. func (m *JobMutation) ResetLastModifiedAt() { - m.lastModifiedAt = nil + m.last_modified_at = nil } // SetName sets the "name" field. @@ -1066,16 +1083,70 @@ func (m *JobMutation) ResetTasks() { m.removedtasks = nil } +// SetCreatorID sets the "creator" edge to the User entity by id. +func (m *JobMutation) SetCreatorID(id int) { + m.creator = &id +} + +// ClearCreator clears the "creator" edge to the User entity. +func (m *JobMutation) ClearCreator() { + m.clearedcreator = true +} + +// CreatorCleared reports if the "creator" edge to the User entity was cleared. +func (m *JobMutation) CreatorCleared() bool { + return m.clearedcreator +} + +// CreatorID returns the "creator" edge ID in the mutation. +func (m *JobMutation) CreatorID() (id int, exists bool) { + if m.creator != nil { + return *m.creator, true + } + return +} + +// CreatorIDs returns the "creator" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CreatorID instead. It exists only for internal usage by the builders. +func (m *JobMutation) CreatorIDs() (ids []int) { + if id := m.creator; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetCreator resets all changes to the "creator" edge. +func (m *JobMutation) ResetCreator() { + m.creator = nil + m.clearedcreator = false +} + // Where appends a list predicates to the JobMutation builder. func (m *JobMutation) Where(ps ...predicate.Job) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the JobMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *JobMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Job, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *JobMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *JobMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Job). func (m *JobMutation) Type() string { return m.typ @@ -1086,10 +1157,10 @@ func (m *JobMutation) Type() string { // AddedFields(). func (m *JobMutation) Fields() []string { fields := make([]string, 0, 4) - if m.createdAt != nil { + if m.created_at != nil { fields = append(fields, job.FieldCreatedAt) } - if m.lastModifiedAt != nil { + if m.last_modified_at != nil { fields = append(fields, job.FieldLastModifiedAt) } if m.name != nil { @@ -1244,7 +1315,7 @@ func (m *JobMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *JobMutation) AddedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 4) if m.tome != nil { edges = append(edges, job.EdgeTome) } @@ -1254,6 +1325,9 @@ func (m *JobMutation) AddedEdges() []string { if m.tasks != nil { edges = append(edges, job.EdgeTasks) } + if m.creator != nil { + edges = append(edges, job.EdgeCreator) + } return edges } @@ -1275,13 +1349,17 @@ func (m *JobMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case job.EdgeCreator: + if id := m.creator; id != nil { + return []ent.Value{*id} + } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *JobMutation) RemovedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 4) if m.removedtasks != nil { edges = append(edges, job.EdgeTasks) } @@ -1304,7 +1382,7 @@ func (m *JobMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *JobMutation) ClearedEdges() []string { - edges := make([]string, 0, 3) + edges := make([]string, 0, 4) if m.clearedtome { edges = append(edges, job.EdgeTome) } @@ -1314,6 +1392,9 @@ func (m *JobMutation) ClearedEdges() []string { if m.clearedtasks { edges = append(edges, job.EdgeTasks) } + if m.clearedcreator { + edges = append(edges, job.EdgeCreator) + } return edges } @@ -1327,6 +1408,8 @@ func (m *JobMutation) EdgeCleared(name string) bool { return m.clearedbundle case job.EdgeTasks: return m.clearedtasks + case job.EdgeCreator: + return m.clearedcreator } return false } @@ -1341,6 +1424,9 @@ func (m *JobMutation) ClearEdge(name string) error { case job.EdgeBundle: m.ClearBundle() return nil + case job.EdgeCreator: + m.ClearCreator() + return nil } return fmt.Errorf("unknown Job unique edge %s", name) } @@ -1358,6 +1444,9 @@ func (m *JobMutation) ResetEdge(name string) error { case job.EdgeTasks: m.ResetTasks() return nil + case job.EdgeCreator: + m.ResetCreator() + return nil } return fmt.Errorf("unknown Job edge %s", name) } @@ -1365,26 +1454,28 @@ func (m *JobMutation) ResetEdge(name string) error { // SessionMutation represents an operation that mutates the Session nodes in the graph. type SessionMutation struct { config - op Op - typ string - id *int - name *string - principal *string - hostname *string - identifier *string - agentIdentifier *string - hostIdentifier *string - lastSeenAt *time.Time - clearedFields map[string]struct{} - tags map[int]struct{} - removedtags map[int]struct{} - clearedtags bool - tasks map[int]struct{} - removedtasks map[int]struct{} - clearedtasks bool - done bool - oldValue func(context.Context) (*Session, error) - predicates []predicate.Session + op Op + typ string + id *int + name *string + principal *string + hostname *string + identifier *string + agent_identifier *string + host_identifier *string + host_primary_ip *string + host_platform *session.HostPlatform + last_seen_at *time.Time + clearedFields map[string]struct{} + tags map[int]struct{} + removedtags map[int]struct{} + clearedtags bool + tasks map[int]struct{} + removedtasks map[int]struct{} + clearedtasks bool + done bool + oldValue func(context.Context) (*Session, error) + predicates []predicate.Session } var _ ent.Mutation = (*SessionMutation)(nil) @@ -1655,21 +1746,21 @@ func (m *SessionMutation) ResetIdentifier() { m.identifier = nil } -// SetAgentIdentifier sets the "agentIdentifier" field. +// SetAgentIdentifier sets the "agent_identifier" field. func (m *SessionMutation) SetAgentIdentifier(s string) { - m.agentIdentifier = &s + m.agent_identifier = &s } -// AgentIdentifier returns the value of the "agentIdentifier" field in the mutation. +// AgentIdentifier returns the value of the "agent_identifier" field in the mutation. func (m *SessionMutation) AgentIdentifier() (r string, exists bool) { - v := m.agentIdentifier + v := m.agent_identifier if v == nil { return } return *v, true } -// OldAgentIdentifier returns the old "agentIdentifier" field's value of the Session entity. +// OldAgentIdentifier returns the old "agent_identifier" field's value of the Session entity. // If the Session object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SessionMutation) OldAgentIdentifier(ctx context.Context) (v string, err error) { @@ -1686,39 +1777,39 @@ func (m *SessionMutation) OldAgentIdentifier(ctx context.Context) (v string, err return oldValue.AgentIdentifier, nil } -// ClearAgentIdentifier clears the value of the "agentIdentifier" field. +// ClearAgentIdentifier clears the value of the "agent_identifier" field. func (m *SessionMutation) ClearAgentIdentifier() { - m.agentIdentifier = nil + m.agent_identifier = nil m.clearedFields[session.FieldAgentIdentifier] = struct{}{} } -// AgentIdentifierCleared returns if the "agentIdentifier" field was cleared in this mutation. +// AgentIdentifierCleared returns if the "agent_identifier" field was cleared in this mutation. func (m *SessionMutation) AgentIdentifierCleared() bool { _, ok := m.clearedFields[session.FieldAgentIdentifier] return ok } -// ResetAgentIdentifier resets all changes to the "agentIdentifier" field. +// ResetAgentIdentifier resets all changes to the "agent_identifier" field. func (m *SessionMutation) ResetAgentIdentifier() { - m.agentIdentifier = nil + m.agent_identifier = nil delete(m.clearedFields, session.FieldAgentIdentifier) } -// SetHostIdentifier sets the "hostIdentifier" field. +// SetHostIdentifier sets the "host_identifier" field. func (m *SessionMutation) SetHostIdentifier(s string) { - m.hostIdentifier = &s + m.host_identifier = &s } -// HostIdentifier returns the value of the "hostIdentifier" field in the mutation. +// HostIdentifier returns the value of the "host_identifier" field in the mutation. func (m *SessionMutation) HostIdentifier() (r string, exists bool) { - v := m.hostIdentifier + v := m.host_identifier if v == nil { return } return *v, true } -// OldHostIdentifier returns the old "hostIdentifier" field's value of the Session entity. +// OldHostIdentifier returns the old "host_identifier" field's value of the Session entity. // If the Session object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SessionMutation) OldHostIdentifier(ctx context.Context) (v string, err error) { @@ -1735,39 +1826,124 @@ func (m *SessionMutation) OldHostIdentifier(ctx context.Context) (v string, err return oldValue.HostIdentifier, nil } -// ClearHostIdentifier clears the value of the "hostIdentifier" field. +// ClearHostIdentifier clears the value of the "host_identifier" field. func (m *SessionMutation) ClearHostIdentifier() { - m.hostIdentifier = nil + m.host_identifier = nil m.clearedFields[session.FieldHostIdentifier] = struct{}{} } -// HostIdentifierCleared returns if the "hostIdentifier" field was cleared in this mutation. +// HostIdentifierCleared returns if the "host_identifier" field was cleared in this mutation. func (m *SessionMutation) HostIdentifierCleared() bool { _, ok := m.clearedFields[session.FieldHostIdentifier] return ok } -// ResetHostIdentifier resets all changes to the "hostIdentifier" field. +// ResetHostIdentifier resets all changes to the "host_identifier" field. func (m *SessionMutation) ResetHostIdentifier() { - m.hostIdentifier = nil + m.host_identifier = nil delete(m.clearedFields, session.FieldHostIdentifier) } -// SetLastSeenAt sets the "lastSeenAt" field. +// SetHostPrimaryIP sets the "host_primary_ip" field. +func (m *SessionMutation) SetHostPrimaryIP(s string) { + m.host_primary_ip = &s +} + +// HostPrimaryIP returns the value of the "host_primary_ip" field in the mutation. +func (m *SessionMutation) HostPrimaryIP() (r string, exists bool) { + v := m.host_primary_ip + if v == nil { + return + } + return *v, true +} + +// OldHostPrimaryIP returns the old "host_primary_ip" field's value of the Session entity. +// If the Session object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SessionMutation) OldHostPrimaryIP(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldHostPrimaryIP is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldHostPrimaryIP requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldHostPrimaryIP: %w", err) + } + return oldValue.HostPrimaryIP, nil +} + +// ClearHostPrimaryIP clears the value of the "host_primary_ip" field. +func (m *SessionMutation) ClearHostPrimaryIP() { + m.host_primary_ip = nil + m.clearedFields[session.FieldHostPrimaryIP] = struct{}{} +} + +// HostPrimaryIPCleared returns if the "host_primary_ip" field was cleared in this mutation. +func (m *SessionMutation) HostPrimaryIPCleared() bool { + _, ok := m.clearedFields[session.FieldHostPrimaryIP] + return ok +} + +// ResetHostPrimaryIP resets all changes to the "host_primary_ip" field. +func (m *SessionMutation) ResetHostPrimaryIP() { + m.host_primary_ip = nil + delete(m.clearedFields, session.FieldHostPrimaryIP) +} + +// SetHostPlatform sets the "host_platform" field. +func (m *SessionMutation) SetHostPlatform(sp session.HostPlatform) { + m.host_platform = &sp +} + +// HostPlatform returns the value of the "host_platform" field in the mutation. +func (m *SessionMutation) HostPlatform() (r session.HostPlatform, exists bool) { + v := m.host_platform + if v == nil { + return + } + return *v, true +} + +// OldHostPlatform returns the old "host_platform" field's value of the Session entity. +// If the Session object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SessionMutation) OldHostPlatform(ctx context.Context) (v session.HostPlatform, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldHostPlatform is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldHostPlatform requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldHostPlatform: %w", err) + } + return oldValue.HostPlatform, nil +} + +// ResetHostPlatform resets all changes to the "host_platform" field. +func (m *SessionMutation) ResetHostPlatform() { + m.host_platform = nil +} + +// SetLastSeenAt sets the "last_seen_at" field. func (m *SessionMutation) SetLastSeenAt(t time.Time) { - m.lastSeenAt = &t + m.last_seen_at = &t } -// LastSeenAt returns the value of the "lastSeenAt" field in the mutation. +// LastSeenAt returns the value of the "last_seen_at" field in the mutation. func (m *SessionMutation) LastSeenAt() (r time.Time, exists bool) { - v := m.lastSeenAt + v := m.last_seen_at if v == nil { return } return *v, true } -// OldLastSeenAt returns the old "lastSeenAt" field's value of the Session entity. +// OldLastSeenAt returns the old "last_seen_at" field's value of the Session entity. // If the Session object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SessionMutation) OldLastSeenAt(ctx context.Context) (v time.Time, err error) { @@ -1784,21 +1960,21 @@ func (m *SessionMutation) OldLastSeenAt(ctx context.Context) (v time.Time, err e return oldValue.LastSeenAt, nil } -// ClearLastSeenAt clears the value of the "lastSeenAt" field. +// ClearLastSeenAt clears the value of the "last_seen_at" field. func (m *SessionMutation) ClearLastSeenAt() { - m.lastSeenAt = nil + m.last_seen_at = nil m.clearedFields[session.FieldLastSeenAt] = struct{}{} } -// LastSeenAtCleared returns if the "lastSeenAt" field was cleared in this mutation. +// LastSeenAtCleared returns if the "last_seen_at" field was cleared in this mutation. func (m *SessionMutation) LastSeenAtCleared() bool { _, ok := m.clearedFields[session.FieldLastSeenAt] return ok } -// ResetLastSeenAt resets all changes to the "lastSeenAt" field. +// ResetLastSeenAt resets all changes to the "last_seen_at" field. func (m *SessionMutation) ResetLastSeenAt() { - m.lastSeenAt = nil + m.last_seen_at = nil delete(m.clearedFields, session.FieldLastSeenAt) } @@ -1915,11 +2091,26 @@ func (m *SessionMutation) Where(ps ...predicate.Session) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the SessionMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *SessionMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Session, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *SessionMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *SessionMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Session). func (m *SessionMutation) Type() string { return m.typ @@ -1929,7 +2120,7 @@ func (m *SessionMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SessionMutation) Fields() []string { - fields := make([]string, 0, 7) + fields := make([]string, 0, 9) if m.name != nil { fields = append(fields, session.FieldName) } @@ -1942,13 +2133,19 @@ func (m *SessionMutation) Fields() []string { if m.identifier != nil { fields = append(fields, session.FieldIdentifier) } - if m.agentIdentifier != nil { + if m.agent_identifier != nil { fields = append(fields, session.FieldAgentIdentifier) } - if m.hostIdentifier != nil { + if m.host_identifier != nil { fields = append(fields, session.FieldHostIdentifier) } - if m.lastSeenAt != nil { + if m.host_primary_ip != nil { + fields = append(fields, session.FieldHostPrimaryIP) + } + if m.host_platform != nil { + fields = append(fields, session.FieldHostPlatform) + } + if m.last_seen_at != nil { fields = append(fields, session.FieldLastSeenAt) } return fields @@ -1971,6 +2168,10 @@ func (m *SessionMutation) Field(name string) (ent.Value, bool) { return m.AgentIdentifier() case session.FieldHostIdentifier: return m.HostIdentifier() + case session.FieldHostPrimaryIP: + return m.HostPrimaryIP() + case session.FieldHostPlatform: + return m.HostPlatform() case session.FieldLastSeenAt: return m.LastSeenAt() } @@ -1994,6 +2195,10 @@ func (m *SessionMutation) OldField(ctx context.Context, name string) (ent.Value, return m.OldAgentIdentifier(ctx) case session.FieldHostIdentifier: return m.OldHostIdentifier(ctx) + case session.FieldHostPrimaryIP: + return m.OldHostPrimaryIP(ctx) + case session.FieldHostPlatform: + return m.OldHostPlatform(ctx) case session.FieldLastSeenAt: return m.OldLastSeenAt(ctx) } @@ -2047,6 +2252,20 @@ func (m *SessionMutation) SetField(name string, value ent.Value) error { } m.SetHostIdentifier(v) return nil + case session.FieldHostPrimaryIP: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetHostPrimaryIP(v) + return nil + case session.FieldHostPlatform: + v, ok := value.(session.HostPlatform) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetHostPlatform(v) + return nil case session.FieldLastSeenAt: v, ok := value.(time.Time) if !ok { @@ -2096,6 +2315,9 @@ func (m *SessionMutation) ClearedFields() []string { if m.FieldCleared(session.FieldHostIdentifier) { fields = append(fields, session.FieldHostIdentifier) } + if m.FieldCleared(session.FieldHostPrimaryIP) { + fields = append(fields, session.FieldHostPrimaryIP) + } if m.FieldCleared(session.FieldLastSeenAt) { fields = append(fields, session.FieldLastSeenAt) } @@ -2125,6 +2347,9 @@ func (m *SessionMutation) ClearField(name string) error { case session.FieldHostIdentifier: m.ClearHostIdentifier() return nil + case session.FieldHostPrimaryIP: + m.ClearHostPrimaryIP() + return nil case session.FieldLastSeenAt: m.ClearLastSeenAt() return nil @@ -2154,6 +2379,12 @@ func (m *SessionMutation) ResetField(name string) error { case session.FieldHostIdentifier: m.ResetHostIdentifier() return nil + case session.FieldHostPrimaryIP: + m.ResetHostPrimaryIP() + return nil + case session.FieldHostPlatform: + m.ResetHostPlatform() + return nil case session.FieldLastSeenAt: m.ResetLastSeenAt() return nil @@ -2517,11 +2748,26 @@ func (m *TagMutation) Where(ps ...predicate.Tag) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the TagMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *TagMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Tag, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *TagMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TagMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Tag). func (m *TagMutation) Type() string { return m.typ @@ -2732,24 +2978,24 @@ func (m *TagMutation) ResetEdge(name string) error { // TaskMutation represents an operation that mutates the Task nodes in the graph. type TaskMutation struct { config - op Op - typ string - id *int - createdAt *time.Time - lastModifiedAt *time.Time - claimedAt *time.Time - execStartedAt *time.Time - execFinishedAt *time.Time - output *string - error *string - clearedFields map[string]struct{} - job *int - clearedjob bool - session *int - clearedsession bool - done bool - oldValue func(context.Context) (*Task, error) - predicates []predicate.Task + op Op + typ string + id *int + created_at *time.Time + last_modified_at *time.Time + claimed_at *time.Time + exec_started_at *time.Time + exec_finished_at *time.Time + output *string + error *string + clearedFields map[string]struct{} + job *int + clearedjob bool + session *int + clearedsession bool + done bool + oldValue func(context.Context) (*Task, error) + predicates []predicate.Task } var _ ent.Mutation = (*TaskMutation)(nil) @@ -2850,21 +3096,21 @@ func (m *TaskMutation) IDs(ctx context.Context) ([]int, error) { } } -// SetCreatedAt sets the "createdAt" field. +// SetCreatedAt sets the "created_at" field. func (m *TaskMutation) SetCreatedAt(t time.Time) { - m.createdAt = &t + m.created_at = &t } -// CreatedAt returns the value of the "createdAt" field in the mutation. +// CreatedAt returns the value of the "created_at" field in the mutation. func (m *TaskMutation) CreatedAt() (r time.Time, exists bool) { - v := m.createdAt + v := m.created_at if v == nil { return } return *v, true } -// OldCreatedAt returns the old "createdAt" field's value of the Task entity. +// OldCreatedAt returns the old "created_at" field's value of the Task entity. // If the Task object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *TaskMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { @@ -2881,26 +3127,26 @@ func (m *TaskMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error return oldValue.CreatedAt, nil } -// ResetCreatedAt resets all changes to the "createdAt" field. +// ResetCreatedAt resets all changes to the "created_at" field. func (m *TaskMutation) ResetCreatedAt() { - m.createdAt = nil + m.created_at = nil } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (m *TaskMutation) SetLastModifiedAt(t time.Time) { - m.lastModifiedAt = &t + m.last_modified_at = &t } -// LastModifiedAt returns the value of the "lastModifiedAt" field in the mutation. +// LastModifiedAt returns the value of the "last_modified_at" field in the mutation. func (m *TaskMutation) LastModifiedAt() (r time.Time, exists bool) { - v := m.lastModifiedAt + v := m.last_modified_at if v == nil { return } return *v, true } -// OldLastModifiedAt returns the old "lastModifiedAt" field's value of the Task entity. +// OldLastModifiedAt returns the old "last_modified_at" field's value of the Task entity. // If the Task object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *TaskMutation) OldLastModifiedAt(ctx context.Context) (v time.Time, err error) { @@ -2917,26 +3163,26 @@ func (m *TaskMutation) OldLastModifiedAt(ctx context.Context) (v time.Time, err return oldValue.LastModifiedAt, nil } -// ResetLastModifiedAt resets all changes to the "lastModifiedAt" field. +// ResetLastModifiedAt resets all changes to the "last_modified_at" field. func (m *TaskMutation) ResetLastModifiedAt() { - m.lastModifiedAt = nil + m.last_modified_at = nil } -// SetClaimedAt sets the "claimedAt" field. +// SetClaimedAt sets the "claimed_at" field. func (m *TaskMutation) SetClaimedAt(t time.Time) { - m.claimedAt = &t + m.claimed_at = &t } -// ClaimedAt returns the value of the "claimedAt" field in the mutation. +// ClaimedAt returns the value of the "claimed_at" field in the mutation. func (m *TaskMutation) ClaimedAt() (r time.Time, exists bool) { - v := m.claimedAt + v := m.claimed_at if v == nil { return } return *v, true } -// OldClaimedAt returns the old "claimedAt" field's value of the Task entity. +// OldClaimedAt returns the old "claimed_at" field's value of the Task entity. // If the Task object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *TaskMutation) OldClaimedAt(ctx context.Context) (v time.Time, err error) { @@ -2953,39 +3199,39 @@ func (m *TaskMutation) OldClaimedAt(ctx context.Context) (v time.Time, err error return oldValue.ClaimedAt, nil } -// ClearClaimedAt clears the value of the "claimedAt" field. +// ClearClaimedAt clears the value of the "claimed_at" field. func (m *TaskMutation) ClearClaimedAt() { - m.claimedAt = nil + m.claimed_at = nil m.clearedFields[task.FieldClaimedAt] = struct{}{} } -// ClaimedAtCleared returns if the "claimedAt" field was cleared in this mutation. +// ClaimedAtCleared returns if the "claimed_at" field was cleared in this mutation. func (m *TaskMutation) ClaimedAtCleared() bool { _, ok := m.clearedFields[task.FieldClaimedAt] return ok } -// ResetClaimedAt resets all changes to the "claimedAt" field. +// ResetClaimedAt resets all changes to the "claimed_at" field. func (m *TaskMutation) ResetClaimedAt() { - m.claimedAt = nil + m.claimed_at = nil delete(m.clearedFields, task.FieldClaimedAt) } -// SetExecStartedAt sets the "execStartedAt" field. +// SetExecStartedAt sets the "exec_started_at" field. func (m *TaskMutation) SetExecStartedAt(t time.Time) { - m.execStartedAt = &t + m.exec_started_at = &t } -// ExecStartedAt returns the value of the "execStartedAt" field in the mutation. +// ExecStartedAt returns the value of the "exec_started_at" field in the mutation. func (m *TaskMutation) ExecStartedAt() (r time.Time, exists bool) { - v := m.execStartedAt + v := m.exec_started_at if v == nil { return } return *v, true } -// OldExecStartedAt returns the old "execStartedAt" field's value of the Task entity. +// OldExecStartedAt returns the old "exec_started_at" field's value of the Task entity. // If the Task object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *TaskMutation) OldExecStartedAt(ctx context.Context) (v time.Time, err error) { @@ -3002,39 +3248,39 @@ func (m *TaskMutation) OldExecStartedAt(ctx context.Context) (v time.Time, err e return oldValue.ExecStartedAt, nil } -// ClearExecStartedAt clears the value of the "execStartedAt" field. +// ClearExecStartedAt clears the value of the "exec_started_at" field. func (m *TaskMutation) ClearExecStartedAt() { - m.execStartedAt = nil + m.exec_started_at = nil m.clearedFields[task.FieldExecStartedAt] = struct{}{} } -// ExecStartedAtCleared returns if the "execStartedAt" field was cleared in this mutation. +// ExecStartedAtCleared returns if the "exec_started_at" field was cleared in this mutation. func (m *TaskMutation) ExecStartedAtCleared() bool { _, ok := m.clearedFields[task.FieldExecStartedAt] return ok } -// ResetExecStartedAt resets all changes to the "execStartedAt" field. +// ResetExecStartedAt resets all changes to the "exec_started_at" field. func (m *TaskMutation) ResetExecStartedAt() { - m.execStartedAt = nil + m.exec_started_at = nil delete(m.clearedFields, task.FieldExecStartedAt) } -// SetExecFinishedAt sets the "execFinishedAt" field. +// SetExecFinishedAt sets the "exec_finished_at" field. func (m *TaskMutation) SetExecFinishedAt(t time.Time) { - m.execFinishedAt = &t + m.exec_finished_at = &t } -// ExecFinishedAt returns the value of the "execFinishedAt" field in the mutation. +// ExecFinishedAt returns the value of the "exec_finished_at" field in the mutation. func (m *TaskMutation) ExecFinishedAt() (r time.Time, exists bool) { - v := m.execFinishedAt + v := m.exec_finished_at if v == nil { return } return *v, true } -// OldExecFinishedAt returns the old "execFinishedAt" field's value of the Task entity. +// OldExecFinishedAt returns the old "exec_finished_at" field's value of the Task entity. // If the Task object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *TaskMutation) OldExecFinishedAt(ctx context.Context) (v time.Time, err error) { @@ -3051,21 +3297,21 @@ func (m *TaskMutation) OldExecFinishedAt(ctx context.Context) (v time.Time, err return oldValue.ExecFinishedAt, nil } -// ClearExecFinishedAt clears the value of the "execFinishedAt" field. +// ClearExecFinishedAt clears the value of the "exec_finished_at" field. func (m *TaskMutation) ClearExecFinishedAt() { - m.execFinishedAt = nil + m.exec_finished_at = nil m.clearedFields[task.FieldExecFinishedAt] = struct{}{} } -// ExecFinishedAtCleared returns if the "execFinishedAt" field was cleared in this mutation. +// ExecFinishedAtCleared returns if the "exec_finished_at" field was cleared in this mutation. func (m *TaskMutation) ExecFinishedAtCleared() bool { _, ok := m.clearedFields[task.FieldExecFinishedAt] return ok } -// ResetExecFinishedAt resets all changes to the "execFinishedAt" field. +// ResetExecFinishedAt resets all changes to the "exec_finished_at" field. func (m *TaskMutation) ResetExecFinishedAt() { - m.execFinishedAt = nil + m.exec_finished_at = nil delete(m.clearedFields, task.FieldExecFinishedAt) } @@ -3250,11 +3496,26 @@ func (m *TaskMutation) Where(ps ...predicate.Task) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the TaskMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *TaskMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Task, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *TaskMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TaskMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Task). func (m *TaskMutation) Type() string { return m.typ @@ -3265,19 +3526,19 @@ func (m *TaskMutation) Type() string { // AddedFields(). func (m *TaskMutation) Fields() []string { fields := make([]string, 0, 7) - if m.createdAt != nil { + if m.created_at != nil { fields = append(fields, task.FieldCreatedAt) } - if m.lastModifiedAt != nil { + if m.last_modified_at != nil { fields = append(fields, task.FieldLastModifiedAt) } - if m.claimedAt != nil { + if m.claimed_at != nil { fields = append(fields, task.FieldClaimedAt) } - if m.execStartedAt != nil { + if m.exec_started_at != nil { fields = append(fields, task.FieldExecStartedAt) } - if m.execFinishedAt != nil { + if m.exec_finished_at != nil { fields = append(fields, task.FieldExecFinishedAt) } if m.output != nil { @@ -3591,23 +3852,23 @@ func (m *TaskMutation) ResetEdge(name string) error { // TomeMutation represents an operation that mutates the Tome nodes in the graph. type TomeMutation struct { config - op Op - typ string - id *int - createdAt *time.Time - lastModifiedAt *time.Time - name *string - description *string - parameters *string - hash *string - eldritch *string - clearedFields map[string]struct{} - files map[int]struct{} - removedfiles map[int]struct{} - clearedfiles bool - done bool - oldValue func(context.Context) (*Tome, error) - predicates []predicate.Tome + op Op + typ string + id *int + created_at *time.Time + last_modified_at *time.Time + name *string + description *string + param_defs *string + hash *string + eldritch *string + clearedFields map[string]struct{} + files map[int]struct{} + removedfiles map[int]struct{} + clearedfiles bool + done bool + oldValue func(context.Context) (*Tome, error) + predicates []predicate.Tome } var _ ent.Mutation = (*TomeMutation)(nil) @@ -3708,21 +3969,21 @@ func (m *TomeMutation) IDs(ctx context.Context) ([]int, error) { } } -// SetCreatedAt sets the "createdAt" field. +// SetCreatedAt sets the "created_at" field. func (m *TomeMutation) SetCreatedAt(t time.Time) { - m.createdAt = &t + m.created_at = &t } -// CreatedAt returns the value of the "createdAt" field in the mutation. +// CreatedAt returns the value of the "created_at" field in the mutation. func (m *TomeMutation) CreatedAt() (r time.Time, exists bool) { - v := m.createdAt + v := m.created_at if v == nil { return } return *v, true } -// OldCreatedAt returns the old "createdAt" field's value of the Tome entity. +// OldCreatedAt returns the old "created_at" field's value of the Tome entity. // If the Tome object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *TomeMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { @@ -3739,26 +4000,26 @@ func (m *TomeMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error return oldValue.CreatedAt, nil } -// ResetCreatedAt resets all changes to the "createdAt" field. +// ResetCreatedAt resets all changes to the "created_at" field. func (m *TomeMutation) ResetCreatedAt() { - m.createdAt = nil + m.created_at = nil } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (m *TomeMutation) SetLastModifiedAt(t time.Time) { - m.lastModifiedAt = &t + m.last_modified_at = &t } -// LastModifiedAt returns the value of the "lastModifiedAt" field in the mutation. +// LastModifiedAt returns the value of the "last_modified_at" field in the mutation. func (m *TomeMutation) LastModifiedAt() (r time.Time, exists bool) { - v := m.lastModifiedAt + v := m.last_modified_at if v == nil { return } return *v, true } -// OldLastModifiedAt returns the old "lastModifiedAt" field's value of the Tome entity. +// OldLastModifiedAt returns the old "last_modified_at" field's value of the Tome entity. // If the Tome object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *TomeMutation) OldLastModifiedAt(ctx context.Context) (v time.Time, err error) { @@ -3775,9 +4036,9 @@ func (m *TomeMutation) OldLastModifiedAt(ctx context.Context) (v time.Time, err return oldValue.LastModifiedAt, nil } -// ResetLastModifiedAt resets all changes to the "lastModifiedAt" field. +// ResetLastModifiedAt resets all changes to the "last_modified_at" field. func (m *TomeMutation) ResetLastModifiedAt() { - m.lastModifiedAt = nil + m.last_modified_at = nil } // SetName sets the "name" field. @@ -3852,53 +4113,53 @@ func (m *TomeMutation) ResetDescription() { m.description = nil } -// SetParameters sets the "parameters" field. -func (m *TomeMutation) SetParameters(s string) { - m.parameters = &s +// SetParamDefs sets the "param_defs" field. +func (m *TomeMutation) SetParamDefs(s string) { + m.param_defs = &s } -// Parameters returns the value of the "parameters" field in the mutation. -func (m *TomeMutation) Parameters() (r string, exists bool) { - v := m.parameters +// ParamDefs returns the value of the "param_defs" field in the mutation. +func (m *TomeMutation) ParamDefs() (r string, exists bool) { + v := m.param_defs if v == nil { return } return *v, true } -// OldParameters returns the old "parameters" field's value of the Tome entity. +// OldParamDefs returns the old "param_defs" field's value of the Tome entity. // If the Tome object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *TomeMutation) OldParameters(ctx context.Context) (v string, err error) { +func (m *TomeMutation) OldParamDefs(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldParameters is only allowed on UpdateOne operations") + return v, errors.New("OldParamDefs is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldParameters requires an ID field in the mutation") + return v, errors.New("OldParamDefs requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldParameters: %w", err) + return v, fmt.Errorf("querying old value for OldParamDefs: %w", err) } - return oldValue.Parameters, nil + return oldValue.ParamDefs, nil } -// ClearParameters clears the value of the "parameters" field. -func (m *TomeMutation) ClearParameters() { - m.parameters = nil - m.clearedFields[tome.FieldParameters] = struct{}{} +// ClearParamDefs clears the value of the "param_defs" field. +func (m *TomeMutation) ClearParamDefs() { + m.param_defs = nil + m.clearedFields[tome.FieldParamDefs] = struct{}{} } -// ParametersCleared returns if the "parameters" field was cleared in this mutation. -func (m *TomeMutation) ParametersCleared() bool { - _, ok := m.clearedFields[tome.FieldParameters] +// ParamDefsCleared returns if the "param_defs" field was cleared in this mutation. +func (m *TomeMutation) ParamDefsCleared() bool { + _, ok := m.clearedFields[tome.FieldParamDefs] return ok } -// ResetParameters resets all changes to the "parameters" field. -func (m *TomeMutation) ResetParameters() { - m.parameters = nil - delete(m.clearedFields, tome.FieldParameters) +// ResetParamDefs resets all changes to the "param_defs" field. +func (m *TomeMutation) ResetParamDefs() { + m.param_defs = nil + delete(m.clearedFields, tome.FieldParamDefs) } // SetHash sets the "hash" field. @@ -4032,11 +4293,26 @@ func (m *TomeMutation) Where(ps ...predicate.Tome) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the TomeMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *TomeMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Tome, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *TomeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TomeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Tome). func (m *TomeMutation) Type() string { return m.typ @@ -4047,10 +4323,10 @@ func (m *TomeMutation) Type() string { // AddedFields(). func (m *TomeMutation) Fields() []string { fields := make([]string, 0, 7) - if m.createdAt != nil { + if m.created_at != nil { fields = append(fields, tome.FieldCreatedAt) } - if m.lastModifiedAt != nil { + if m.last_modified_at != nil { fields = append(fields, tome.FieldLastModifiedAt) } if m.name != nil { @@ -4059,8 +4335,8 @@ func (m *TomeMutation) Fields() []string { if m.description != nil { fields = append(fields, tome.FieldDescription) } - if m.parameters != nil { - fields = append(fields, tome.FieldParameters) + if m.param_defs != nil { + fields = append(fields, tome.FieldParamDefs) } if m.hash != nil { fields = append(fields, tome.FieldHash) @@ -4084,8 +4360,8 @@ func (m *TomeMutation) Field(name string) (ent.Value, bool) { return m.Name() case tome.FieldDescription: return m.Description() - case tome.FieldParameters: - return m.Parameters() + case tome.FieldParamDefs: + return m.ParamDefs() case tome.FieldHash: return m.Hash() case tome.FieldEldritch: @@ -4107,8 +4383,8 @@ func (m *TomeMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldName(ctx) case tome.FieldDescription: return m.OldDescription(ctx) - case tome.FieldParameters: - return m.OldParameters(ctx) + case tome.FieldParamDefs: + return m.OldParamDefs(ctx) case tome.FieldHash: return m.OldHash(ctx) case tome.FieldEldritch: @@ -4150,12 +4426,12 @@ func (m *TomeMutation) SetField(name string, value ent.Value) error { } m.SetDescription(v) return nil - case tome.FieldParameters: + case tome.FieldParamDefs: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetParameters(v) + m.SetParamDefs(v) return nil case tome.FieldHash: v, ok := value.(string) @@ -4201,8 +4477,8 @@ func (m *TomeMutation) AddField(name string, value ent.Value) error { // mutation. func (m *TomeMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(tome.FieldParameters) { - fields = append(fields, tome.FieldParameters) + if m.FieldCleared(tome.FieldParamDefs) { + fields = append(fields, tome.FieldParamDefs) } return fields } @@ -4218,8 +4494,8 @@ func (m *TomeMutation) FieldCleared(name string) bool { // error if the field is not defined in the schema. func (m *TomeMutation) ClearField(name string) error { switch name { - case tome.FieldParameters: - m.ClearParameters() + case tome.FieldParamDefs: + m.ClearParamDefs() return nil } return fmt.Errorf("unknown Tome nullable field %s", name) @@ -4241,8 +4517,8 @@ func (m *TomeMutation) ResetField(name string) error { case tome.FieldDescription: m.ResetDescription() return nil - case tome.FieldParameters: - m.ResetParameters() + case tome.FieldParamDefs: + m.ResetParamDefs() return nil case tome.FieldHash: m.ResetHash() @@ -4344,12 +4620,12 @@ type UserMutation struct { op Op typ string id *int - _Name *string - _OAuthID *string - _PhotoURL *string - _SessionToken *string - _IsActivated *bool - _IsAdmin *bool + name *string + oauth_id *string + photo_url *string + session_token *string + is_activated *bool + is_admin *bool clearedFields map[string]struct{} done bool oldValue func(context.Context) (*User, error) @@ -4454,21 +4730,21 @@ func (m *UserMutation) IDs(ctx context.Context) ([]int, error) { } } -// SetName sets the "Name" field. +// SetName sets the "name" field. func (m *UserMutation) SetName(s string) { - m._Name = &s + m.name = &s } -// Name returns the value of the "Name" field in the mutation. +// Name returns the value of the "name" field in the mutation. func (m *UserMutation) Name() (r string, exists bool) { - v := m._Name + v := m.name if v == nil { return } return *v, true } -// OldName returns the old "Name" field's value of the User entity. +// OldName returns the old "name" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldName(ctx context.Context) (v string, err error) { @@ -4485,62 +4761,62 @@ func (m *UserMutation) OldName(ctx context.Context) (v string, err error) { return oldValue.Name, nil } -// ResetName resets all changes to the "Name" field. +// ResetName resets all changes to the "name" field. func (m *UserMutation) ResetName() { - m._Name = nil + m.name = nil } -// SetOAuthID sets the "OAuthID" field. -func (m *UserMutation) SetOAuthID(s string) { - m._OAuthID = &s +// SetOauthID sets the "oauth_id" field. +func (m *UserMutation) SetOauthID(s string) { + m.oauth_id = &s } -// OAuthID returns the value of the "OAuthID" field in the mutation. -func (m *UserMutation) OAuthID() (r string, exists bool) { - v := m._OAuthID +// OauthID returns the value of the "oauth_id" field in the mutation. +func (m *UserMutation) OauthID() (r string, exists bool) { + v := m.oauth_id if v == nil { return } return *v, true } -// OldOAuthID returns the old "OAuthID" field's value of the User entity. +// OldOauthID returns the old "oauth_id" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *UserMutation) OldOAuthID(ctx context.Context) (v string, err error) { +func (m *UserMutation) OldOauthID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldOAuthID is only allowed on UpdateOne operations") + return v, errors.New("OldOauthID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldOAuthID requires an ID field in the mutation") + return v, errors.New("OldOauthID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldOAuthID: %w", err) + return v, fmt.Errorf("querying old value for OldOauthID: %w", err) } - return oldValue.OAuthID, nil + return oldValue.OauthID, nil } -// ResetOAuthID resets all changes to the "OAuthID" field. -func (m *UserMutation) ResetOAuthID() { - m._OAuthID = nil +// ResetOauthID resets all changes to the "oauth_id" field. +func (m *UserMutation) ResetOauthID() { + m.oauth_id = nil } -// SetPhotoURL sets the "PhotoURL" field. +// SetPhotoURL sets the "photo_url" field. func (m *UserMutation) SetPhotoURL(s string) { - m._PhotoURL = &s + m.photo_url = &s } -// PhotoURL returns the value of the "PhotoURL" field in the mutation. +// PhotoURL returns the value of the "photo_url" field in the mutation. func (m *UserMutation) PhotoURL() (r string, exists bool) { - v := m._PhotoURL + v := m.photo_url if v == nil { return } return *v, true } -// OldPhotoURL returns the old "PhotoURL" field's value of the User entity. +// OldPhotoURL returns the old "photo_url" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldPhotoURL(ctx context.Context) (v string, err error) { @@ -4557,26 +4833,26 @@ func (m *UserMutation) OldPhotoURL(ctx context.Context) (v string, err error) { return oldValue.PhotoURL, nil } -// ResetPhotoURL resets all changes to the "PhotoURL" field. +// ResetPhotoURL resets all changes to the "photo_url" field. func (m *UserMutation) ResetPhotoURL() { - m._PhotoURL = nil + m.photo_url = nil } -// SetSessionToken sets the "SessionToken" field. +// SetSessionToken sets the "session_token" field. func (m *UserMutation) SetSessionToken(s string) { - m._SessionToken = &s + m.session_token = &s } -// SessionToken returns the value of the "SessionToken" field in the mutation. +// SessionToken returns the value of the "session_token" field in the mutation. func (m *UserMutation) SessionToken() (r string, exists bool) { - v := m._SessionToken + v := m.session_token if v == nil { return } return *v, true } -// OldSessionToken returns the old "SessionToken" field's value of the User entity. +// OldSessionToken returns the old "session_token" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldSessionToken(ctx context.Context) (v string, err error) { @@ -4593,26 +4869,26 @@ func (m *UserMutation) OldSessionToken(ctx context.Context) (v string, err error return oldValue.SessionToken, nil } -// ResetSessionToken resets all changes to the "SessionToken" field. +// ResetSessionToken resets all changes to the "session_token" field. func (m *UserMutation) ResetSessionToken() { - m._SessionToken = nil + m.session_token = nil } -// SetIsActivated sets the "IsActivated" field. +// SetIsActivated sets the "is_activated" field. func (m *UserMutation) SetIsActivated(b bool) { - m._IsActivated = &b + m.is_activated = &b } -// IsActivated returns the value of the "IsActivated" field in the mutation. +// IsActivated returns the value of the "is_activated" field in the mutation. func (m *UserMutation) IsActivated() (r bool, exists bool) { - v := m._IsActivated + v := m.is_activated if v == nil { return } return *v, true } -// OldIsActivated returns the old "IsActivated" field's value of the User entity. +// OldIsActivated returns the old "is_activated" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldIsActivated(ctx context.Context) (v bool, err error) { @@ -4629,26 +4905,26 @@ func (m *UserMutation) OldIsActivated(ctx context.Context) (v bool, err error) { return oldValue.IsActivated, nil } -// ResetIsActivated resets all changes to the "IsActivated" field. +// ResetIsActivated resets all changes to the "is_activated" field. func (m *UserMutation) ResetIsActivated() { - m._IsActivated = nil + m.is_activated = nil } -// SetIsAdmin sets the "IsAdmin" field. +// SetIsAdmin sets the "is_admin" field. func (m *UserMutation) SetIsAdmin(b bool) { - m._IsAdmin = &b + m.is_admin = &b } -// IsAdmin returns the value of the "IsAdmin" field in the mutation. +// IsAdmin returns the value of the "is_admin" field in the mutation. func (m *UserMutation) IsAdmin() (r bool, exists bool) { - v := m._IsAdmin + v := m.is_admin if v == nil { return } return *v, true } -// OldIsAdmin returns the old "IsAdmin" field's value of the User entity. +// OldIsAdmin returns the old "is_admin" field's value of the User entity. // If the User object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *UserMutation) OldIsAdmin(ctx context.Context) (v bool, err error) { @@ -4665,9 +4941,9 @@ func (m *UserMutation) OldIsAdmin(ctx context.Context) (v bool, err error) { return oldValue.IsAdmin, nil } -// ResetIsAdmin resets all changes to the "IsAdmin" field. +// ResetIsAdmin resets all changes to the "is_admin" field. func (m *UserMutation) ResetIsAdmin() { - m._IsAdmin = nil + m.is_admin = nil } // Where appends a list predicates to the UserMutation builder. @@ -4675,11 +4951,26 @@ func (m *UserMutation) Where(ps ...predicate.User) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the UserMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.User, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ @@ -4690,22 +4981,22 @@ func (m *UserMutation) Type() string { // AddedFields(). func (m *UserMutation) Fields() []string { fields := make([]string, 0, 6) - if m._Name != nil { + if m.name != nil { fields = append(fields, user.FieldName) } - if m._OAuthID != nil { - fields = append(fields, user.FieldOAuthID) + if m.oauth_id != nil { + fields = append(fields, user.FieldOauthID) } - if m._PhotoURL != nil { + if m.photo_url != nil { fields = append(fields, user.FieldPhotoURL) } - if m._SessionToken != nil { + if m.session_token != nil { fields = append(fields, user.FieldSessionToken) } - if m._IsActivated != nil { + if m.is_activated != nil { fields = append(fields, user.FieldIsActivated) } - if m._IsAdmin != nil { + if m.is_admin != nil { fields = append(fields, user.FieldIsAdmin) } return fields @@ -4718,8 +5009,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) { switch name { case user.FieldName: return m.Name() - case user.FieldOAuthID: - return m.OAuthID() + case user.FieldOauthID: + return m.OauthID() case user.FieldPhotoURL: return m.PhotoURL() case user.FieldSessionToken: @@ -4739,8 +5030,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er switch name { case user.FieldName: return m.OldName(ctx) - case user.FieldOAuthID: - return m.OldOAuthID(ctx) + case user.FieldOauthID: + return m.OldOauthID(ctx) case user.FieldPhotoURL: return m.OldPhotoURL(ctx) case user.FieldSessionToken: @@ -4765,12 +5056,12 @@ func (m *UserMutation) SetField(name string, value ent.Value) error { } m.SetName(v) return nil - case user.FieldOAuthID: + case user.FieldOauthID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetOAuthID(v) + m.SetOauthID(v) return nil case user.FieldPhotoURL: v, ok := value.(string) @@ -4852,8 +5143,8 @@ func (m *UserMutation) ResetField(name string) error { case user.FieldName: m.ResetName() return nil - case user.FieldOAuthID: - m.ResetOAuthID() + case user.FieldOauthID: + m.ResetOauthID() return nil case user.FieldPhotoURL: m.ResetPhotoURL() diff --git a/tavern/ent/runtime/runtime.go b/tavern/ent/runtime/runtime.go index 29e0773b1..6fef4d77b 100644 --- a/tavern/ent/runtime/runtime.go +++ b/tavern/ent/runtime/runtime.go @@ -26,15 +26,15 @@ func init() { _ = fileMixinFields0 fileFields := schema.File{}.Fields() _ = fileFields - // fileDescCreatedAt is the schema descriptor for createdAt field. + // fileDescCreatedAt is the schema descriptor for created_at field. fileDescCreatedAt := fileMixinFields0[0].Descriptor() - // file.DefaultCreatedAt holds the default value on creation for the createdAt field. + // file.DefaultCreatedAt holds the default value on creation for the created_at field. file.DefaultCreatedAt = fileDescCreatedAt.Default.(func() time.Time) - // fileDescLastModifiedAt is the schema descriptor for lastModifiedAt field. + // fileDescLastModifiedAt is the schema descriptor for last_modified_at field. fileDescLastModifiedAt := fileMixinFields0[1].Descriptor() - // file.DefaultLastModifiedAt holds the default value on creation for the lastModifiedAt field. + // file.DefaultLastModifiedAt holds the default value on creation for the last_modified_at field. file.DefaultLastModifiedAt = fileDescLastModifiedAt.Default.(func() time.Time) - // file.UpdateDefaultLastModifiedAt holds the default value on update for the lastModifiedAt field. + // file.UpdateDefaultLastModifiedAt holds the default value on update for the last_modified_at field. file.UpdateDefaultLastModifiedAt = fileDescLastModifiedAt.UpdateDefault.(func() time.Time) // fileDescName is the schema descriptor for name field. fileDescName := fileFields[0].Descriptor() @@ -55,15 +55,15 @@ func init() { _ = jobMixinFields0 jobFields := schema.Job{}.Fields() _ = jobFields - // jobDescCreatedAt is the schema descriptor for createdAt field. + // jobDescCreatedAt is the schema descriptor for created_at field. jobDescCreatedAt := jobMixinFields0[0].Descriptor() - // job.DefaultCreatedAt holds the default value on creation for the createdAt field. + // job.DefaultCreatedAt holds the default value on creation for the created_at field. job.DefaultCreatedAt = jobDescCreatedAt.Default.(func() time.Time) - // jobDescLastModifiedAt is the schema descriptor for lastModifiedAt field. + // jobDescLastModifiedAt is the schema descriptor for last_modified_at field. jobDescLastModifiedAt := jobMixinFields0[1].Descriptor() - // job.DefaultLastModifiedAt holds the default value on creation for the lastModifiedAt field. + // job.DefaultLastModifiedAt holds the default value on creation for the last_modified_at field. job.DefaultLastModifiedAt = jobDescLastModifiedAt.Default.(func() time.Time) - // job.UpdateDefaultLastModifiedAt holds the default value on update for the lastModifiedAt field. + // job.UpdateDefaultLastModifiedAt holds the default value on update for the last_modified_at field. job.UpdateDefaultLastModifiedAt = jobDescLastModifiedAt.UpdateDefault.(func() time.Time) // jobDescName is the schema descriptor for name field. jobDescName := jobFields[0].Descriptor() @@ -91,13 +91,13 @@ func init() { session.DefaultIdentifier = sessionDescIdentifier.Default.(func() string) // session.IdentifierValidator is a validator for the "identifier" field. It is called by the builders before save. session.IdentifierValidator = sessionDescIdentifier.Validators[0].(func(string) error) - // sessionDescAgentIdentifier is the schema descriptor for agentIdentifier field. + // sessionDescAgentIdentifier is the schema descriptor for agent_identifier field. sessionDescAgentIdentifier := sessionFields[4].Descriptor() - // session.AgentIdentifierValidator is a validator for the "agentIdentifier" field. It is called by the builders before save. + // session.AgentIdentifierValidator is a validator for the "agent_identifier" field. It is called by the builders before save. session.AgentIdentifierValidator = sessionDescAgentIdentifier.Validators[0].(func(string) error) - // sessionDescHostIdentifier is the schema descriptor for hostIdentifier field. + // sessionDescHostIdentifier is the schema descriptor for host_identifier field. sessionDescHostIdentifier := sessionFields[5].Descriptor() - // session.HostIdentifierValidator is a validator for the "hostIdentifier" field. It is called by the builders before save. + // session.HostIdentifierValidator is a validator for the "host_identifier" field. It is called by the builders before save. session.HostIdentifierValidator = sessionDescHostIdentifier.Validators[0].(func(string) error) tagFields := schema.Tag{}.Fields() _ = tagFields @@ -110,15 +110,15 @@ func init() { _ = taskMixinFields0 taskFields := schema.Task{}.Fields() _ = taskFields - // taskDescCreatedAt is the schema descriptor for createdAt field. + // taskDescCreatedAt is the schema descriptor for created_at field. taskDescCreatedAt := taskMixinFields0[0].Descriptor() - // task.DefaultCreatedAt holds the default value on creation for the createdAt field. + // task.DefaultCreatedAt holds the default value on creation for the created_at field. task.DefaultCreatedAt = taskDescCreatedAt.Default.(func() time.Time) - // taskDescLastModifiedAt is the schema descriptor for lastModifiedAt field. + // taskDescLastModifiedAt is the schema descriptor for last_modified_at field. taskDescLastModifiedAt := taskMixinFields0[1].Descriptor() - // task.DefaultLastModifiedAt holds the default value on creation for the lastModifiedAt field. + // task.DefaultLastModifiedAt holds the default value on creation for the last_modified_at field. task.DefaultLastModifiedAt = taskDescLastModifiedAt.Default.(func() time.Time) - // task.UpdateDefaultLastModifiedAt holds the default value on update for the lastModifiedAt field. + // task.UpdateDefaultLastModifiedAt holds the default value on update for the last_modified_at field. task.UpdateDefaultLastModifiedAt = taskDescLastModifiedAt.UpdateDefault.(func() time.Time) tomeMixin := schema.Tome{}.Mixin() tomeHooks := schema.Tome{}.Hooks() @@ -127,15 +127,15 @@ func init() { _ = tomeMixinFields0 tomeFields := schema.Tome{}.Fields() _ = tomeFields - // tomeDescCreatedAt is the schema descriptor for createdAt field. + // tomeDescCreatedAt is the schema descriptor for created_at field. tomeDescCreatedAt := tomeMixinFields0[0].Descriptor() - // tome.DefaultCreatedAt holds the default value on creation for the createdAt field. + // tome.DefaultCreatedAt holds the default value on creation for the created_at field. tome.DefaultCreatedAt = tomeDescCreatedAt.Default.(func() time.Time) - // tomeDescLastModifiedAt is the schema descriptor for lastModifiedAt field. + // tomeDescLastModifiedAt is the schema descriptor for last_modified_at field. tomeDescLastModifiedAt := tomeMixinFields0[1].Descriptor() - // tome.DefaultLastModifiedAt holds the default value on creation for the lastModifiedAt field. + // tome.DefaultLastModifiedAt holds the default value on creation for the last_modified_at field. tome.DefaultLastModifiedAt = tomeDescLastModifiedAt.Default.(func() time.Time) - // tome.UpdateDefaultLastModifiedAt holds the default value on update for the lastModifiedAt field. + // tome.UpdateDefaultLastModifiedAt holds the default value on update for the last_modified_at field. tome.UpdateDefaultLastModifiedAt = tomeDescLastModifiedAt.UpdateDefault.(func() time.Time) // tomeDescName is the schema descriptor for name field. tomeDescName := tomeFields[0].Descriptor() @@ -147,41 +147,41 @@ func init() { tome.HashValidator = tomeDescHash.Validators[0].(func(string) error) userFields := schema.User{}.Fields() _ = userFields - // userDescName is the schema descriptor for Name field. + // userDescName is the schema descriptor for name field. userDescName := userFields[0].Descriptor() - // user.NameValidator is a validator for the "Name" field. It is called by the builders before save. + // user.NameValidator is a validator for the "name" field. It is called by the builders before save. user.NameValidator = func() func(string) error { validators := userDescName.Validators fns := [...]func(string) error{ validators[0].(func(string) error), validators[1].(func(string) error), } - return func(_Name string) error { + return func(name string) error { for _, fn := range fns { - if err := fn(_Name); err != nil { + if err := fn(name); err != nil { return err } } return nil } }() - // userDescSessionToken is the schema descriptor for SessionToken field. + // userDescSessionToken is the schema descriptor for session_token field. userDescSessionToken := userFields[3].Descriptor() - // user.DefaultSessionToken holds the default value on creation for the SessionToken field. + // user.DefaultSessionToken holds the default value on creation for the session_token field. user.DefaultSessionToken = userDescSessionToken.Default.(func() string) - // user.SessionTokenValidator is a validator for the "SessionToken" field. It is called by the builders before save. + // user.SessionTokenValidator is a validator for the "session_token" field. It is called by the builders before save. user.SessionTokenValidator = userDescSessionToken.Validators[0].(func(string) error) - // userDescIsActivated is the schema descriptor for IsActivated field. + // userDescIsActivated is the schema descriptor for is_activated field. userDescIsActivated := userFields[4].Descriptor() - // user.DefaultIsActivated holds the default value on creation for the IsActivated field. + // user.DefaultIsActivated holds the default value on creation for the is_activated field. user.DefaultIsActivated = userDescIsActivated.Default.(bool) - // userDescIsAdmin is the schema descriptor for IsAdmin field. + // userDescIsAdmin is the schema descriptor for is_admin field. userDescIsAdmin := userFields[5].Descriptor() - // user.DefaultIsAdmin holds the default value on creation for the IsAdmin field. + // user.DefaultIsAdmin holds the default value on creation for the is_admin field. user.DefaultIsAdmin = userDescIsAdmin.Default.(bool) } const ( - Version = "v0.11.5-0.20221031135557-521f9b57bc3d" // Version of ent codegen. - Sum = "h1:slfuvOSWSiV0ldHU+V+O2cfOEgWRpbRloUeE9k7wXnw=" // Sum of ent codegen. + Version = "v0.11.9" // Version of ent codegen. + Sum = "h1:dbbCkAiPVTRBIJwoZctiSYjB7zxQIBOzVSU5H9VYIQI=" // Sum of ent codegen. ) diff --git a/tavern/ent/schema/file.go b/tavern/ent/schema/file.go index 442ff85b4..7fa4e2569 100644 --- a/tavern/ent/schema/file.go +++ b/tavern/ent/schema/file.go @@ -59,7 +59,7 @@ func (File) Annotations() []schema.Annotation { // Mixin defines common shared properties for the ent. func (File) Mixin() []ent.Mixin { return []ent.Mixin{ - MixinHistory{}, // createdAt, lastModifiedAt + MixinHistory{}, // created_at, last_modified_at } } diff --git a/tavern/ent/schema/job.go b/tavern/ent/schema/job.go index b7dcbd4ea..de3f3dce1 100644 --- a/tavern/ent/schema/job.go +++ b/tavern/ent/schema/job.go @@ -47,6 +47,12 @@ func (Job) Edges() []ent.Edge { entgql.Skip(entgql.SkipMutationCreateInput), ). Comment("Tasks tracking the status and output of individual tome execution on targets"), + edge.To("creator", User.Type). + Unique(). + Annotations( + entgql.Skip(entgql.SkipMutationCreateInput), + ). + Comment("User that created the job if available."), } } @@ -62,6 +68,6 @@ func (Job) Annotations() []schema.Annotation { // Mixin defines common shared properties for the ent. func (Job) Mixin() []ent.Mixin { return []ent.Mixin{ - MixinHistory{}, // createdAt, lastModifiedAt + MixinHistory{}, // created_at, last_modified_at } } diff --git a/tavern/ent/schema/mixin_history.go b/tavern/ent/schema/mixin_history.go index 1c71c3796..be2f89c3a 100644 --- a/tavern/ent/schema/mixin_history.go +++ b/tavern/ent/schema/mixin_history.go @@ -17,7 +17,7 @@ type MixinHistory struct { func (MixinHistory) Fields() []ent.Field { return []ent.Field{ - field.Time("createdAt"). + field.Time("created_at"). Comment("Timestamp of when this ent was created"). Immutable(). Default(time.Now). @@ -25,7 +25,7 @@ func (MixinHistory) Fields() []ent.Field { entgql.OrderField("CREATED_AT"), entgql.Skip(entgql.SkipMutationCreateInput), ), - field.Time("lastModifiedAt"). + field.Time("last_modified_at"). Comment("Timestamp of when this ent was last updated"). Default(time.Now). UpdateDefault(time.Now). diff --git a/tavern/ent/schema/session.go b/tavern/ent/schema/session.go index c9f79eb54..34fbd9798 100644 --- a/tavern/ent/schema/session.go +++ b/tavern/ent/schema/session.go @@ -47,21 +47,34 @@ func (Session) Fields() []ent.Field { entgql.Skip(entgql.SkipMutationUpdateInput), ). Comment("Unique identifier for the session. Unique to each instance of the session."), - field.String("agentIdentifier"). + field.String("agent_identifier"). Optional(). NotEmpty(). Annotations( entgql.Skip(entgql.SkipMutationUpdateInput), ). Comment("Identifies the agent that the session is running as (e.g. 'imix')."), - field.String("hostIdentifier"). + field.String("host_identifier"). Optional(). NotEmpty(). Annotations( entgql.Skip(entgql.SkipMutationUpdateInput), ). Comment("Unique identifier for the host the session is running on."), - field.Time("lastSeenAt"). + field.String("host_primary_ip"). + Optional(). + Annotations( + entgql.Skip(entgql.SkipMutationUpdateInput), + ). + Comment("Primary interface IP address reported by the agent."), + field.Enum("host_platform"). + Values("Windows", "Linux", "MacOS", "BSD", "Unknown"). + Default("Unknown"). + Annotations( + entgql.Skip(entgql.SkipMutationUpdateInput), + ). + Comment("Platform the agent is operating on."), + field.Time("last_seen_at"). Optional(). Annotations( entgql.OrderField("LAST_SEEN_AT"), diff --git a/tavern/ent/schema/task.go b/tavern/ent/schema/task.go index 44cf18b6a..416fa6d9b 100644 --- a/tavern/ent/schema/task.go +++ b/tavern/ent/schema/task.go @@ -15,19 +15,19 @@ type Task struct { // Fields of the Task. func (Task) Fields() []ent.Field { return []ent.Field{ - field.Time("claimedAt"). + field.Time("claimed_at"). Optional(). Annotations( entgql.OrderField("CLAIMED_AT"), ). Comment("Timestamp of when the task was claimed, null if not yet claimed"), - field.Time("execStartedAt"). + field.Time("exec_started_at"). Optional(). Annotations( entgql.OrderField("EXEC_STARTED_AT"), ). Comment("Timestamp of when execution of the task started, null if not yet started"), - field.Time("execFinishedAt"). + field.Time("exec_finished_at"). Optional(). Annotations( entgql.OrderField("EXEC_FINISHED_AT"), @@ -58,6 +58,6 @@ func (Task) Edges() []ent.Edge { // Mixin defines common shared properties for the ent. func (Task) Mixin() []ent.Mixin { return []ent.Mixin{ - MixinHistory{}, // createdAt, lastModifiedAt + MixinHistory{}, // created_at, last_modified_at } } diff --git a/tavern/ent/schema/tome.go b/tavern/ent/schema/tome.go index f2d0056bb..02b010a5c 100644 --- a/tavern/ent/schema/tome.go +++ b/tavern/ent/schema/tome.go @@ -31,7 +31,7 @@ func (Tome) Fields() []ent.Field { Comment("Name of the tome"), field.String("description"). Comment("Information about the tome"), - field.String("parameters"). + field.String("param_defs"). Optional(). Comment("JSON string describing what parameters are used with the tome"), field.String("hash"). diff --git a/tavern/ent/schema/user.go b/tavern/ent/schema/user.go index 58312c801..60c6107a9 100644 --- a/tavern/ent/schema/user.go +++ b/tavern/ent/schema/user.go @@ -20,18 +20,18 @@ type User struct { // Fields of the User. func (User) Fields() []ent.Field { return []ent.Field{ - field.String("Name"). + field.String("name"). MinLen(3). MaxLen(25). Comment("The name displayed for the user"), - field.String("OAuthID"). + field.String("oauth_id"). Sensitive(). Unique(). Immutable(). Comment("OAuth Subject ID of the user"), - field.String("PhotoURL"). + field.String("photo_url"). Comment("URL to the user's profile photo."), - field.String("SessionToken"). + field.String("session_token"). DefaultFunc(newSessionToken). Sensitive(). MaxLen(200). @@ -39,10 +39,10 @@ func (User) Fields() []ent.Field { entgql.Skip(), ). Comment("The session token currently authenticating the user"), - field.Bool("IsActivated"). + field.Bool("is_activated"). Default(false). Comment("True if the user is active and able to authenticate"), - field.Bool("IsAdmin"). + field.Bool("is_admin"). Default(false). Comment("True if the user is an Admin"), } diff --git a/tavern/ent/session.go b/tavern/ent/session.go index 8a8c5499f..0139a4d5f 100644 --- a/tavern/ent/session.go +++ b/tavern/ent/session.go @@ -25,11 +25,15 @@ type Session struct { // Unique identifier for the session. Unique to each instance of the session. Identifier string `json:"identifier,omitempty"` // Identifies the agent that the session is running as (e.g. 'imix'). - AgentIdentifier string `json:"agentIdentifier,omitempty"` + AgentIdentifier string `json:"agent_identifier,omitempty"` // Unique identifier for the host the session is running on. - HostIdentifier string `json:"hostIdentifier,omitempty"` + HostIdentifier string `json:"host_identifier,omitempty"` + // Primary interface IP address reported by the agent. + HostPrimaryIP string `json:"host_primary_ip,omitempty"` + // Platform the agent is operating on. + HostPlatform session.HostPlatform `json:"host_platform,omitempty"` // Timestamp of when a task was last claimed or updated for a target - LastSeenAt time.Time `json:"lastSeenAt,omitempty"` + LastSeenAt time.Time `json:"last_seen_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the SessionQuery when eager-loading is set. Edges SessionEdges `json:"edges"` @@ -76,7 +80,7 @@ func (*Session) scanValues(columns []string) ([]any, error) { switch columns[i] { case session.FieldID: values[i] = new(sql.NullInt64) - case session.FieldName, session.FieldPrincipal, session.FieldHostname, session.FieldIdentifier, session.FieldAgentIdentifier, session.FieldHostIdentifier: + case session.FieldName, session.FieldPrincipal, session.FieldHostname, session.FieldIdentifier, session.FieldAgentIdentifier, session.FieldHostIdentifier, session.FieldHostPrimaryIP, session.FieldHostPlatform: values[i] = new(sql.NullString) case session.FieldLastSeenAt: values[i] = new(sql.NullTime) @@ -127,19 +131,31 @@ func (s *Session) assignValues(columns []string, values []any) error { } case session.FieldAgentIdentifier: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field agentIdentifier", values[i]) + return fmt.Errorf("unexpected type %T for field agent_identifier", values[i]) } else if value.Valid { s.AgentIdentifier = value.String } case session.FieldHostIdentifier: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field hostIdentifier", values[i]) + return fmt.Errorf("unexpected type %T for field host_identifier", values[i]) } else if value.Valid { s.HostIdentifier = value.String } + case session.FieldHostPrimaryIP: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field host_primary_ip", values[i]) + } else if value.Valid { + s.HostPrimaryIP = value.String + } + case session.FieldHostPlatform: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field host_platform", values[i]) + } else if value.Valid { + s.HostPlatform = session.HostPlatform(value.String) + } case session.FieldLastSeenAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field lastSeenAt", values[i]) + return fmt.Errorf("unexpected type %T for field last_seen_at", values[i]) } else if value.Valid { s.LastSeenAt = value.Time } @@ -150,19 +166,19 @@ func (s *Session) assignValues(columns []string, values []any) error { // QueryTags queries the "tags" edge of the Session entity. func (s *Session) QueryTags() *TagQuery { - return (&SessionClient{config: s.config}).QueryTags(s) + return NewSessionClient(s.config).QueryTags(s) } // QueryTasks queries the "tasks" edge of the Session entity. func (s *Session) QueryTasks() *TaskQuery { - return (&SessionClient{config: s.config}).QueryTasks(s) + return NewSessionClient(s.config).QueryTasks(s) } // Update returns a builder for updating this Session. // Note that you need to call Session.Unwrap() before calling this method if this Session // was returned from a transaction, and the transaction was committed or rolled back. func (s *Session) Update() *SessionUpdateOne { - return (&SessionClient{config: s.config}).UpdateOne(s) + return NewSessionClient(s.config).UpdateOne(s) } // Unwrap unwraps the Session entity that was returned from a transaction after it was closed, @@ -193,13 +209,19 @@ func (s *Session) String() string { builder.WriteString("identifier=") builder.WriteString(s.Identifier) builder.WriteString(", ") - builder.WriteString("agentIdentifier=") + builder.WriteString("agent_identifier=") builder.WriteString(s.AgentIdentifier) builder.WriteString(", ") - builder.WriteString("hostIdentifier=") + builder.WriteString("host_identifier=") builder.WriteString(s.HostIdentifier) builder.WriteString(", ") - builder.WriteString("lastSeenAt=") + builder.WriteString("host_primary_ip=") + builder.WriteString(s.HostPrimaryIP) + builder.WriteString(", ") + builder.WriteString("host_platform=") + builder.WriteString(fmt.Sprintf("%v", s.HostPlatform)) + builder.WriteString(", ") + builder.WriteString("last_seen_at=") builder.WriteString(s.LastSeenAt.Format(time.ANSIC)) builder.WriteByte(')') return builder.String() @@ -255,9 +277,3 @@ func (s *Session) appendNamedTasks(name string, edges ...*Task) { // Sessions is a parsable slice of Session. type Sessions []*Session - -func (s Sessions) config(cfg config) { - for _i := range s { - s[_i].config = cfg - } -} diff --git a/tavern/ent/session/session.go b/tavern/ent/session/session.go index 9fdd38e16..c34acf5b0 100644 --- a/tavern/ent/session/session.go +++ b/tavern/ent/session/session.go @@ -2,6 +2,12 @@ package session +import ( + "fmt" + "io" + "strconv" +) + const ( // Label holds the string label denoting the session type in the database. Label = "session" @@ -15,11 +21,15 @@ const ( FieldHostname = "hostname" // FieldIdentifier holds the string denoting the identifier field in the database. FieldIdentifier = "identifier" - // FieldAgentIdentifier holds the string denoting the agentidentifier field in the database. + // FieldAgentIdentifier holds the string denoting the agent_identifier field in the database. FieldAgentIdentifier = "agent_identifier" - // FieldHostIdentifier holds the string denoting the hostidentifier field in the database. + // FieldHostIdentifier holds the string denoting the host_identifier field in the database. FieldHostIdentifier = "host_identifier" - // FieldLastSeenAt holds the string denoting the lastseenat field in the database. + // FieldHostPrimaryIP holds the string denoting the host_primary_ip field in the database. + FieldHostPrimaryIP = "host_primary_ip" + // FieldHostPlatform holds the string denoting the host_platform field in the database. + FieldHostPlatform = "host_platform" + // FieldLastSeenAt holds the string denoting the last_seen_at field in the database. FieldLastSeenAt = "last_seen_at" // EdgeTags holds the string denoting the tags edge name in mutations. EdgeTags = "tags" @@ -50,6 +60,8 @@ var Columns = []string{ FieldIdentifier, FieldAgentIdentifier, FieldHostIdentifier, + FieldHostPrimaryIP, + FieldHostPlatform, FieldLastSeenAt, } @@ -82,8 +94,55 @@ var ( DefaultIdentifier func() string // IdentifierValidator is a validator for the "identifier" field. It is called by the builders before save. IdentifierValidator func(string) error - // AgentIdentifierValidator is a validator for the "agentIdentifier" field. It is called by the builders before save. + // AgentIdentifierValidator is a validator for the "agent_identifier" field. It is called by the builders before save. AgentIdentifierValidator func(string) error - // HostIdentifierValidator is a validator for the "hostIdentifier" field. It is called by the builders before save. + // HostIdentifierValidator is a validator for the "host_identifier" field. It is called by the builders before save. HostIdentifierValidator func(string) error ) + +// HostPlatform defines the type for the "host_platform" enum field. +type HostPlatform string + +// HostPlatformUnknown is the default value of the HostPlatform enum. +const DefaultHostPlatform = HostPlatformUnknown + +// HostPlatform values. +const ( + HostPlatformWindows HostPlatform = "Windows" + HostPlatformLinux HostPlatform = "Linux" + HostPlatformMacOS HostPlatform = "MacOS" + HostPlatformBSD HostPlatform = "BSD" + HostPlatformUnknown HostPlatform = "Unknown" +) + +func (hp HostPlatform) String() string { + return string(hp) +} + +// HostPlatformValidator is a validator for the "host_platform" field enum values. It is called by the builders before save. +func HostPlatformValidator(hp HostPlatform) error { + switch hp { + case HostPlatformWindows, HostPlatformLinux, HostPlatformMacOS, HostPlatformBSD, HostPlatformUnknown: + return nil + default: + return fmt.Errorf("session: invalid enum value for host_platform field: %q", hp) + } +} + +// MarshalGQL implements graphql.Marshaler interface. +func (e HostPlatform) MarshalGQL(w io.Writer) { + io.WriteString(w, strconv.Quote(e.String())) +} + +// UnmarshalGQL implements graphql.Unmarshaler interface. +func (e *HostPlatform) UnmarshalGQL(val interface{}) error { + str, ok := val.(string) + if !ok { + return fmt.Errorf("enum %T must be a string", val) + } + *e = HostPlatform(str) + if err := HostPlatformValidator(*e); err != nil { + return fmt.Errorf("%s is not a valid HostPlatform", str) + } + return nil +} diff --git a/tavern/ent/session/where.go b/tavern/ent/session/where.go index 675b4da7c..aa5401ad1 100644 --- a/tavern/ent/session/where.go +++ b/tavern/ent/session/where.go @@ -12,850 +12,662 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Session(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Session(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Session(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Session { - return predicate.Session(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.Session(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Session { - return predicate.Session(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.Session(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Session(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Session(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Session(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Session(sql.FieldLTE(FieldID, id)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldEQ(FieldName, v)) } // Principal applies equality check predicate on the "principal" field. It's identical to PrincipalEQ. func Principal(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldEQ(FieldPrincipal, v)) } // Hostname applies equality check predicate on the "hostname" field. It's identical to HostnameEQ. func Hostname(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldEQ(FieldHostname, v)) } // Identifier applies equality check predicate on the "identifier" field. It's identical to IdentifierEQ. func Identifier(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldEQ(FieldIdentifier, v)) } -// AgentIdentifier applies equality check predicate on the "agentIdentifier" field. It's identical to AgentIdentifierEQ. +// AgentIdentifier applies equality check predicate on the "agent_identifier" field. It's identical to AgentIdentifierEQ. func AgentIdentifier(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldEQ(FieldAgentIdentifier, v)) } -// HostIdentifier applies equality check predicate on the "hostIdentifier" field. It's identical to HostIdentifierEQ. +// HostIdentifier applies equality check predicate on the "host_identifier" field. It's identical to HostIdentifierEQ. func HostIdentifier(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldEQ(FieldHostIdentifier, v)) +} + +// HostPrimaryIP applies equality check predicate on the "host_primary_ip" field. It's identical to HostPrimaryIPEQ. +func HostPrimaryIP(v string) predicate.Session { + return predicate.Session(sql.FieldEQ(FieldHostPrimaryIP, v)) } -// LastSeenAt applies equality check predicate on the "lastSeenAt" field. It's identical to LastSeenAtEQ. +// LastSeenAt applies equality check predicate on the "last_seen_at" field. It's identical to LastSeenAtEQ. func LastSeenAt(v time.Time) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastSeenAt), v)) - }) + return predicate.Session(sql.FieldEQ(FieldLastSeenAt, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.Session(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.Session(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.Session(sql.FieldContainsFold(FieldName, v)) } // PrincipalEQ applies the EQ predicate on the "principal" field. func PrincipalEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldEQ(FieldPrincipal, v)) } // PrincipalNEQ applies the NEQ predicate on the "principal" field. func PrincipalNEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldNEQ(FieldPrincipal, v)) } // PrincipalIn applies the In predicate on the "principal" field. func PrincipalIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldPrincipal), v...)) - }) + return predicate.Session(sql.FieldIn(FieldPrincipal, vs...)) } // PrincipalNotIn applies the NotIn predicate on the "principal" field. func PrincipalNotIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldPrincipal), v...)) - }) + return predicate.Session(sql.FieldNotIn(FieldPrincipal, vs...)) } // PrincipalGT applies the GT predicate on the "principal" field. func PrincipalGT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldGT(FieldPrincipal, v)) } // PrincipalGTE applies the GTE predicate on the "principal" field. func PrincipalGTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldGTE(FieldPrincipal, v)) } // PrincipalLT applies the LT predicate on the "principal" field. func PrincipalLT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldLT(FieldPrincipal, v)) } // PrincipalLTE applies the LTE predicate on the "principal" field. func PrincipalLTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldLTE(FieldPrincipal, v)) } // PrincipalContains applies the Contains predicate on the "principal" field. func PrincipalContains(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldContains(FieldPrincipal, v)) } // PrincipalHasPrefix applies the HasPrefix predicate on the "principal" field. func PrincipalHasPrefix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldHasPrefix(FieldPrincipal, v)) } // PrincipalHasSuffix applies the HasSuffix predicate on the "principal" field. func PrincipalHasSuffix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldHasSuffix(FieldPrincipal, v)) } // PrincipalIsNil applies the IsNil predicate on the "principal" field. func PrincipalIsNil() predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldPrincipal))) - }) + return predicate.Session(sql.FieldIsNull(FieldPrincipal)) } // PrincipalNotNil applies the NotNil predicate on the "principal" field. func PrincipalNotNil() predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldPrincipal))) - }) + return predicate.Session(sql.FieldNotNull(FieldPrincipal)) } // PrincipalEqualFold applies the EqualFold predicate on the "principal" field. func PrincipalEqualFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldEqualFold(FieldPrincipal, v)) } // PrincipalContainsFold applies the ContainsFold predicate on the "principal" field. func PrincipalContainsFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldPrincipal), v)) - }) + return predicate.Session(sql.FieldContainsFold(FieldPrincipal, v)) } // HostnameEQ applies the EQ predicate on the "hostname" field. func HostnameEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldEQ(FieldHostname, v)) } // HostnameNEQ applies the NEQ predicate on the "hostname" field. func HostnameNEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldNEQ(FieldHostname, v)) } // HostnameIn applies the In predicate on the "hostname" field. func HostnameIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldHostname), v...)) - }) + return predicate.Session(sql.FieldIn(FieldHostname, vs...)) } // HostnameNotIn applies the NotIn predicate on the "hostname" field. func HostnameNotIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldHostname), v...)) - }) + return predicate.Session(sql.FieldNotIn(FieldHostname, vs...)) } // HostnameGT applies the GT predicate on the "hostname" field. func HostnameGT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldGT(FieldHostname, v)) } // HostnameGTE applies the GTE predicate on the "hostname" field. func HostnameGTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldGTE(FieldHostname, v)) } // HostnameLT applies the LT predicate on the "hostname" field. func HostnameLT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldLT(FieldHostname, v)) } // HostnameLTE applies the LTE predicate on the "hostname" field. func HostnameLTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldLTE(FieldHostname, v)) } // HostnameContains applies the Contains predicate on the "hostname" field. func HostnameContains(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldContains(FieldHostname, v)) } // HostnameHasPrefix applies the HasPrefix predicate on the "hostname" field. func HostnameHasPrefix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldHasPrefix(FieldHostname, v)) } // HostnameHasSuffix applies the HasSuffix predicate on the "hostname" field. func HostnameHasSuffix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldHasSuffix(FieldHostname, v)) } // HostnameIsNil applies the IsNil predicate on the "hostname" field. func HostnameIsNil() predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldHostname))) - }) + return predicate.Session(sql.FieldIsNull(FieldHostname)) } // HostnameNotNil applies the NotNil predicate on the "hostname" field. func HostnameNotNil() predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldHostname))) - }) + return predicate.Session(sql.FieldNotNull(FieldHostname)) } // HostnameEqualFold applies the EqualFold predicate on the "hostname" field. func HostnameEqualFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldEqualFold(FieldHostname, v)) } // HostnameContainsFold applies the ContainsFold predicate on the "hostname" field. func HostnameContainsFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldHostname), v)) - }) + return predicate.Session(sql.FieldContainsFold(FieldHostname, v)) } // IdentifierEQ applies the EQ predicate on the "identifier" field. func IdentifierEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldEQ(FieldIdentifier, v)) } // IdentifierNEQ applies the NEQ predicate on the "identifier" field. func IdentifierNEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldNEQ(FieldIdentifier, v)) } // IdentifierIn applies the In predicate on the "identifier" field. func IdentifierIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldIdentifier), v...)) - }) + return predicate.Session(sql.FieldIn(FieldIdentifier, vs...)) } // IdentifierNotIn applies the NotIn predicate on the "identifier" field. func IdentifierNotIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldIdentifier), v...)) - }) + return predicate.Session(sql.FieldNotIn(FieldIdentifier, vs...)) } // IdentifierGT applies the GT predicate on the "identifier" field. func IdentifierGT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldGT(FieldIdentifier, v)) } // IdentifierGTE applies the GTE predicate on the "identifier" field. func IdentifierGTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldGTE(FieldIdentifier, v)) } // IdentifierLT applies the LT predicate on the "identifier" field. func IdentifierLT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldLT(FieldIdentifier, v)) } // IdentifierLTE applies the LTE predicate on the "identifier" field. func IdentifierLTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldLTE(FieldIdentifier, v)) } // IdentifierContains applies the Contains predicate on the "identifier" field. func IdentifierContains(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldContains(FieldIdentifier, v)) } // IdentifierHasPrefix applies the HasPrefix predicate on the "identifier" field. func IdentifierHasPrefix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldHasPrefix(FieldIdentifier, v)) } // IdentifierHasSuffix applies the HasSuffix predicate on the "identifier" field. func IdentifierHasSuffix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldHasSuffix(FieldIdentifier, v)) } // IdentifierEqualFold applies the EqualFold predicate on the "identifier" field. func IdentifierEqualFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldEqualFold(FieldIdentifier, v)) } // IdentifierContainsFold applies the ContainsFold predicate on the "identifier" field. func IdentifierContainsFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldIdentifier), v)) - }) + return predicate.Session(sql.FieldContainsFold(FieldIdentifier, v)) } -// AgentIdentifierEQ applies the EQ predicate on the "agentIdentifier" field. +// AgentIdentifierEQ applies the EQ predicate on the "agent_identifier" field. func AgentIdentifierEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldEQ(FieldAgentIdentifier, v)) } -// AgentIdentifierNEQ applies the NEQ predicate on the "agentIdentifier" field. +// AgentIdentifierNEQ applies the NEQ predicate on the "agent_identifier" field. func AgentIdentifierNEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldNEQ(FieldAgentIdentifier, v)) } -// AgentIdentifierIn applies the In predicate on the "agentIdentifier" field. +// AgentIdentifierIn applies the In predicate on the "agent_identifier" field. func AgentIdentifierIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldAgentIdentifier), v...)) - }) + return predicate.Session(sql.FieldIn(FieldAgentIdentifier, vs...)) } -// AgentIdentifierNotIn applies the NotIn predicate on the "agentIdentifier" field. +// AgentIdentifierNotIn applies the NotIn predicate on the "agent_identifier" field. func AgentIdentifierNotIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldAgentIdentifier), v...)) - }) + return predicate.Session(sql.FieldNotIn(FieldAgentIdentifier, vs...)) } -// AgentIdentifierGT applies the GT predicate on the "agentIdentifier" field. +// AgentIdentifierGT applies the GT predicate on the "agent_identifier" field. func AgentIdentifierGT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldGT(FieldAgentIdentifier, v)) } -// AgentIdentifierGTE applies the GTE predicate on the "agentIdentifier" field. +// AgentIdentifierGTE applies the GTE predicate on the "agent_identifier" field. func AgentIdentifierGTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldGTE(FieldAgentIdentifier, v)) } -// AgentIdentifierLT applies the LT predicate on the "agentIdentifier" field. +// AgentIdentifierLT applies the LT predicate on the "agent_identifier" field. func AgentIdentifierLT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldLT(FieldAgentIdentifier, v)) } -// AgentIdentifierLTE applies the LTE predicate on the "agentIdentifier" field. +// AgentIdentifierLTE applies the LTE predicate on the "agent_identifier" field. func AgentIdentifierLTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldLTE(FieldAgentIdentifier, v)) } -// AgentIdentifierContains applies the Contains predicate on the "agentIdentifier" field. +// AgentIdentifierContains applies the Contains predicate on the "agent_identifier" field. func AgentIdentifierContains(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldContains(FieldAgentIdentifier, v)) } -// AgentIdentifierHasPrefix applies the HasPrefix predicate on the "agentIdentifier" field. +// AgentIdentifierHasPrefix applies the HasPrefix predicate on the "agent_identifier" field. func AgentIdentifierHasPrefix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldHasPrefix(FieldAgentIdentifier, v)) } -// AgentIdentifierHasSuffix applies the HasSuffix predicate on the "agentIdentifier" field. +// AgentIdentifierHasSuffix applies the HasSuffix predicate on the "agent_identifier" field. func AgentIdentifierHasSuffix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldHasSuffix(FieldAgentIdentifier, v)) } -// AgentIdentifierIsNil applies the IsNil predicate on the "agentIdentifier" field. +// AgentIdentifierIsNil applies the IsNil predicate on the "agent_identifier" field. func AgentIdentifierIsNil() predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldAgentIdentifier))) - }) + return predicate.Session(sql.FieldIsNull(FieldAgentIdentifier)) } -// AgentIdentifierNotNil applies the NotNil predicate on the "agentIdentifier" field. +// AgentIdentifierNotNil applies the NotNil predicate on the "agent_identifier" field. func AgentIdentifierNotNil() predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldAgentIdentifier))) - }) + return predicate.Session(sql.FieldNotNull(FieldAgentIdentifier)) } -// AgentIdentifierEqualFold applies the EqualFold predicate on the "agentIdentifier" field. +// AgentIdentifierEqualFold applies the EqualFold predicate on the "agent_identifier" field. func AgentIdentifierEqualFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldEqualFold(FieldAgentIdentifier, v)) } -// AgentIdentifierContainsFold applies the ContainsFold predicate on the "agentIdentifier" field. +// AgentIdentifierContainsFold applies the ContainsFold predicate on the "agent_identifier" field. func AgentIdentifierContainsFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldAgentIdentifier), v)) - }) + return predicate.Session(sql.FieldContainsFold(FieldAgentIdentifier, v)) } -// HostIdentifierEQ applies the EQ predicate on the "hostIdentifier" field. +// HostIdentifierEQ applies the EQ predicate on the "host_identifier" field. func HostIdentifierEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldEQ(FieldHostIdentifier, v)) } -// HostIdentifierNEQ applies the NEQ predicate on the "hostIdentifier" field. +// HostIdentifierNEQ applies the NEQ predicate on the "host_identifier" field. func HostIdentifierNEQ(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldNEQ(FieldHostIdentifier, v)) } -// HostIdentifierIn applies the In predicate on the "hostIdentifier" field. +// HostIdentifierIn applies the In predicate on the "host_identifier" field. func HostIdentifierIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldHostIdentifier), v...)) - }) + return predicate.Session(sql.FieldIn(FieldHostIdentifier, vs...)) } -// HostIdentifierNotIn applies the NotIn predicate on the "hostIdentifier" field. +// HostIdentifierNotIn applies the NotIn predicate on the "host_identifier" field. func HostIdentifierNotIn(vs ...string) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldHostIdentifier), v...)) - }) + return predicate.Session(sql.FieldNotIn(FieldHostIdentifier, vs...)) } -// HostIdentifierGT applies the GT predicate on the "hostIdentifier" field. +// HostIdentifierGT applies the GT predicate on the "host_identifier" field. func HostIdentifierGT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldGT(FieldHostIdentifier, v)) } -// HostIdentifierGTE applies the GTE predicate on the "hostIdentifier" field. +// HostIdentifierGTE applies the GTE predicate on the "host_identifier" field. func HostIdentifierGTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldGTE(FieldHostIdentifier, v)) } -// HostIdentifierLT applies the LT predicate on the "hostIdentifier" field. +// HostIdentifierLT applies the LT predicate on the "host_identifier" field. func HostIdentifierLT(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldLT(FieldHostIdentifier, v)) } -// HostIdentifierLTE applies the LTE predicate on the "hostIdentifier" field. +// HostIdentifierLTE applies the LTE predicate on the "host_identifier" field. func HostIdentifierLTE(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldLTE(FieldHostIdentifier, v)) } -// HostIdentifierContains applies the Contains predicate on the "hostIdentifier" field. +// HostIdentifierContains applies the Contains predicate on the "host_identifier" field. func HostIdentifierContains(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldContains(FieldHostIdentifier, v)) } -// HostIdentifierHasPrefix applies the HasPrefix predicate on the "hostIdentifier" field. +// HostIdentifierHasPrefix applies the HasPrefix predicate on the "host_identifier" field. func HostIdentifierHasPrefix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldHasPrefix(FieldHostIdentifier, v)) } -// HostIdentifierHasSuffix applies the HasSuffix predicate on the "hostIdentifier" field. +// HostIdentifierHasSuffix applies the HasSuffix predicate on the "host_identifier" field. func HostIdentifierHasSuffix(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldHasSuffix(FieldHostIdentifier, v)) } -// HostIdentifierIsNil applies the IsNil predicate on the "hostIdentifier" field. +// HostIdentifierIsNil applies the IsNil predicate on the "host_identifier" field. func HostIdentifierIsNil() predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldHostIdentifier))) - }) + return predicate.Session(sql.FieldIsNull(FieldHostIdentifier)) } -// HostIdentifierNotNil applies the NotNil predicate on the "hostIdentifier" field. +// HostIdentifierNotNil applies the NotNil predicate on the "host_identifier" field. func HostIdentifierNotNil() predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldHostIdentifier))) - }) + return predicate.Session(sql.FieldNotNull(FieldHostIdentifier)) } -// HostIdentifierEqualFold applies the EqualFold predicate on the "hostIdentifier" field. +// HostIdentifierEqualFold applies the EqualFold predicate on the "host_identifier" field. func HostIdentifierEqualFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldEqualFold(FieldHostIdentifier, v)) } -// HostIdentifierContainsFold applies the ContainsFold predicate on the "hostIdentifier" field. +// HostIdentifierContainsFold applies the ContainsFold predicate on the "host_identifier" field. func HostIdentifierContainsFold(v string) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldHostIdentifier), v)) - }) + return predicate.Session(sql.FieldContainsFold(FieldHostIdentifier, v)) +} + +// HostPrimaryIPEQ applies the EQ predicate on the "host_primary_ip" field. +func HostPrimaryIPEQ(v string) predicate.Session { + return predicate.Session(sql.FieldEQ(FieldHostPrimaryIP, v)) +} + +// HostPrimaryIPNEQ applies the NEQ predicate on the "host_primary_ip" field. +func HostPrimaryIPNEQ(v string) predicate.Session { + return predicate.Session(sql.FieldNEQ(FieldHostPrimaryIP, v)) +} + +// HostPrimaryIPIn applies the In predicate on the "host_primary_ip" field. +func HostPrimaryIPIn(vs ...string) predicate.Session { + return predicate.Session(sql.FieldIn(FieldHostPrimaryIP, vs...)) +} + +// HostPrimaryIPNotIn applies the NotIn predicate on the "host_primary_ip" field. +func HostPrimaryIPNotIn(vs ...string) predicate.Session { + return predicate.Session(sql.FieldNotIn(FieldHostPrimaryIP, vs...)) +} + +// HostPrimaryIPGT applies the GT predicate on the "host_primary_ip" field. +func HostPrimaryIPGT(v string) predicate.Session { + return predicate.Session(sql.FieldGT(FieldHostPrimaryIP, v)) +} + +// HostPrimaryIPGTE applies the GTE predicate on the "host_primary_ip" field. +func HostPrimaryIPGTE(v string) predicate.Session { + return predicate.Session(sql.FieldGTE(FieldHostPrimaryIP, v)) +} + +// HostPrimaryIPLT applies the LT predicate on the "host_primary_ip" field. +func HostPrimaryIPLT(v string) predicate.Session { + return predicate.Session(sql.FieldLT(FieldHostPrimaryIP, v)) +} + +// HostPrimaryIPLTE applies the LTE predicate on the "host_primary_ip" field. +func HostPrimaryIPLTE(v string) predicate.Session { + return predicate.Session(sql.FieldLTE(FieldHostPrimaryIP, v)) +} + +// HostPrimaryIPContains applies the Contains predicate on the "host_primary_ip" field. +func HostPrimaryIPContains(v string) predicate.Session { + return predicate.Session(sql.FieldContains(FieldHostPrimaryIP, v)) +} + +// HostPrimaryIPHasPrefix applies the HasPrefix predicate on the "host_primary_ip" field. +func HostPrimaryIPHasPrefix(v string) predicate.Session { + return predicate.Session(sql.FieldHasPrefix(FieldHostPrimaryIP, v)) +} + +// HostPrimaryIPHasSuffix applies the HasSuffix predicate on the "host_primary_ip" field. +func HostPrimaryIPHasSuffix(v string) predicate.Session { + return predicate.Session(sql.FieldHasSuffix(FieldHostPrimaryIP, v)) +} + +// HostPrimaryIPIsNil applies the IsNil predicate on the "host_primary_ip" field. +func HostPrimaryIPIsNil() predicate.Session { + return predicate.Session(sql.FieldIsNull(FieldHostPrimaryIP)) +} + +// HostPrimaryIPNotNil applies the NotNil predicate on the "host_primary_ip" field. +func HostPrimaryIPNotNil() predicate.Session { + return predicate.Session(sql.FieldNotNull(FieldHostPrimaryIP)) +} + +// HostPrimaryIPEqualFold applies the EqualFold predicate on the "host_primary_ip" field. +func HostPrimaryIPEqualFold(v string) predicate.Session { + return predicate.Session(sql.FieldEqualFold(FieldHostPrimaryIP, v)) +} + +// HostPrimaryIPContainsFold applies the ContainsFold predicate on the "host_primary_ip" field. +func HostPrimaryIPContainsFold(v string) predicate.Session { + return predicate.Session(sql.FieldContainsFold(FieldHostPrimaryIP, v)) +} + +// HostPlatformEQ applies the EQ predicate on the "host_platform" field. +func HostPlatformEQ(v HostPlatform) predicate.Session { + return predicate.Session(sql.FieldEQ(FieldHostPlatform, v)) +} + +// HostPlatformNEQ applies the NEQ predicate on the "host_platform" field. +func HostPlatformNEQ(v HostPlatform) predicate.Session { + return predicate.Session(sql.FieldNEQ(FieldHostPlatform, v)) } -// LastSeenAtEQ applies the EQ predicate on the "lastSeenAt" field. +// HostPlatformIn applies the In predicate on the "host_platform" field. +func HostPlatformIn(vs ...HostPlatform) predicate.Session { + return predicate.Session(sql.FieldIn(FieldHostPlatform, vs...)) +} + +// HostPlatformNotIn applies the NotIn predicate on the "host_platform" field. +func HostPlatformNotIn(vs ...HostPlatform) predicate.Session { + return predicate.Session(sql.FieldNotIn(FieldHostPlatform, vs...)) +} + +// LastSeenAtEQ applies the EQ predicate on the "last_seen_at" field. func LastSeenAtEQ(v time.Time) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastSeenAt), v)) - }) + return predicate.Session(sql.FieldEQ(FieldLastSeenAt, v)) } -// LastSeenAtNEQ applies the NEQ predicate on the "lastSeenAt" field. +// LastSeenAtNEQ applies the NEQ predicate on the "last_seen_at" field. func LastSeenAtNEQ(v time.Time) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldLastSeenAt), v)) - }) + return predicate.Session(sql.FieldNEQ(FieldLastSeenAt, v)) } -// LastSeenAtIn applies the In predicate on the "lastSeenAt" field. +// LastSeenAtIn applies the In predicate on the "last_seen_at" field. func LastSeenAtIn(vs ...time.Time) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldLastSeenAt), v...)) - }) + return predicate.Session(sql.FieldIn(FieldLastSeenAt, vs...)) } -// LastSeenAtNotIn applies the NotIn predicate on the "lastSeenAt" field. +// LastSeenAtNotIn applies the NotIn predicate on the "last_seen_at" field. func LastSeenAtNotIn(vs ...time.Time) predicate.Session { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldLastSeenAt), v...)) - }) + return predicate.Session(sql.FieldNotIn(FieldLastSeenAt, vs...)) } -// LastSeenAtGT applies the GT predicate on the "lastSeenAt" field. +// LastSeenAtGT applies the GT predicate on the "last_seen_at" field. func LastSeenAtGT(v time.Time) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldLastSeenAt), v)) - }) + return predicate.Session(sql.FieldGT(FieldLastSeenAt, v)) } -// LastSeenAtGTE applies the GTE predicate on the "lastSeenAt" field. +// LastSeenAtGTE applies the GTE predicate on the "last_seen_at" field. func LastSeenAtGTE(v time.Time) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldLastSeenAt), v)) - }) + return predicate.Session(sql.FieldGTE(FieldLastSeenAt, v)) } -// LastSeenAtLT applies the LT predicate on the "lastSeenAt" field. +// LastSeenAtLT applies the LT predicate on the "last_seen_at" field. func LastSeenAtLT(v time.Time) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldLastSeenAt), v)) - }) + return predicate.Session(sql.FieldLT(FieldLastSeenAt, v)) } -// LastSeenAtLTE applies the LTE predicate on the "lastSeenAt" field. +// LastSeenAtLTE applies the LTE predicate on the "last_seen_at" field. func LastSeenAtLTE(v time.Time) predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldLastSeenAt), v)) - }) + return predicate.Session(sql.FieldLTE(FieldLastSeenAt, v)) } -// LastSeenAtIsNil applies the IsNil predicate on the "lastSeenAt" field. +// LastSeenAtIsNil applies the IsNil predicate on the "last_seen_at" field. func LastSeenAtIsNil() predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldLastSeenAt))) - }) + return predicate.Session(sql.FieldIsNull(FieldLastSeenAt)) } -// LastSeenAtNotNil applies the NotNil predicate on the "lastSeenAt" field. +// LastSeenAtNotNil applies the NotNil predicate on the "last_seen_at" field. func LastSeenAtNotNil() predicate.Session { - return predicate.Session(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldLastSeenAt))) - }) + return predicate.Session(sql.FieldNotNull(FieldLastSeenAt)) } // HasTags applies the HasEdge predicate on the "tags" edge. @@ -863,7 +675,6 @@ func HasTags() predicate.Session { return predicate.Session(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(TagsTable, FieldID), sqlgraph.Edge(sqlgraph.M2M, false, TagsTable, TagsPrimaryKey...), ) sqlgraph.HasNeighbors(s, step) @@ -891,7 +702,6 @@ func HasTasks() predicate.Session { return predicate.Session(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(TasksTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, true, TasksTable, TasksColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/tavern/ent/session_create.go b/tavern/ent/session_create.go index 4710cee69..6ce25fa36 100644 --- a/tavern/ent/session_create.go +++ b/tavern/ent/session_create.go @@ -78,13 +78,13 @@ func (sc *SessionCreate) SetNillableIdentifier(s *string) *SessionCreate { return sc } -// SetAgentIdentifier sets the "agentIdentifier" field. +// SetAgentIdentifier sets the "agent_identifier" field. func (sc *SessionCreate) SetAgentIdentifier(s string) *SessionCreate { sc.mutation.SetAgentIdentifier(s) return sc } -// SetNillableAgentIdentifier sets the "agentIdentifier" field if the given value is not nil. +// SetNillableAgentIdentifier sets the "agent_identifier" field if the given value is not nil. func (sc *SessionCreate) SetNillableAgentIdentifier(s *string) *SessionCreate { if s != nil { sc.SetAgentIdentifier(*s) @@ -92,13 +92,13 @@ func (sc *SessionCreate) SetNillableAgentIdentifier(s *string) *SessionCreate { return sc } -// SetHostIdentifier sets the "hostIdentifier" field. +// SetHostIdentifier sets the "host_identifier" field. func (sc *SessionCreate) SetHostIdentifier(s string) *SessionCreate { sc.mutation.SetHostIdentifier(s) return sc } -// SetNillableHostIdentifier sets the "hostIdentifier" field if the given value is not nil. +// SetNillableHostIdentifier sets the "host_identifier" field if the given value is not nil. func (sc *SessionCreate) SetNillableHostIdentifier(s *string) *SessionCreate { if s != nil { sc.SetHostIdentifier(*s) @@ -106,13 +106,41 @@ func (sc *SessionCreate) SetNillableHostIdentifier(s *string) *SessionCreate { return sc } -// SetLastSeenAt sets the "lastSeenAt" field. +// SetHostPrimaryIP sets the "host_primary_ip" field. +func (sc *SessionCreate) SetHostPrimaryIP(s string) *SessionCreate { + sc.mutation.SetHostPrimaryIP(s) + return sc +} + +// SetNillableHostPrimaryIP sets the "host_primary_ip" field if the given value is not nil. +func (sc *SessionCreate) SetNillableHostPrimaryIP(s *string) *SessionCreate { + if s != nil { + sc.SetHostPrimaryIP(*s) + } + return sc +} + +// SetHostPlatform sets the "host_platform" field. +func (sc *SessionCreate) SetHostPlatform(sp session.HostPlatform) *SessionCreate { + sc.mutation.SetHostPlatform(sp) + return sc +} + +// SetNillableHostPlatform sets the "host_platform" field if the given value is not nil. +func (sc *SessionCreate) SetNillableHostPlatform(sp *session.HostPlatform) *SessionCreate { + if sp != nil { + sc.SetHostPlatform(*sp) + } + return sc +} + +// SetLastSeenAt sets the "last_seen_at" field. func (sc *SessionCreate) SetLastSeenAt(t time.Time) *SessionCreate { sc.mutation.SetLastSeenAt(t) return sc } -// SetNillableLastSeenAt sets the "lastSeenAt" field if the given value is not nil. +// SetNillableLastSeenAt sets the "last_seen_at" field if the given value is not nil. func (sc *SessionCreate) SetNillableLastSeenAt(t *time.Time) *SessionCreate { if t != nil { sc.SetLastSeenAt(*t) @@ -157,50 +185,8 @@ func (sc *SessionCreate) Mutation() *SessionMutation { // Save creates the Session in the database. func (sc *SessionCreate) Save(ctx context.Context) (*Session, error) { - var ( - err error - node *Session - ) sc.defaults() - if len(sc.hooks) == 0 { - if err = sc.check(); err != nil { - return nil, err - } - node, err = sc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*SessionMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = sc.check(); err != nil { - return nil, err - } - sc.mutation = mutation - if node, err = sc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(sc.hooks) - 1; i >= 0; i-- { - if sc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = sc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, sc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Session) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from SessionMutation", v) - } - node = nv - } - return node, err + return withHooks[*Session, SessionMutation](ctx, sc.sqlSave, sc.mutation, sc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -235,6 +221,10 @@ func (sc *SessionCreate) defaults() { v := session.DefaultIdentifier() sc.mutation.SetIdentifier(v) } + if _, ok := sc.mutation.HostPlatform(); !ok { + v := session.DefaultHostPlatform + sc.mutation.SetHostPlatform(v) + } } // check runs all checks and user-defined validators on the builder. @@ -267,18 +257,29 @@ func (sc *SessionCreate) check() error { } if v, ok := sc.mutation.AgentIdentifier(); ok { if err := session.AgentIdentifierValidator(v); err != nil { - return &ValidationError{Name: "agentIdentifier", err: fmt.Errorf(`ent: validator failed for field "Session.agentIdentifier": %w`, err)} + return &ValidationError{Name: "agent_identifier", err: fmt.Errorf(`ent: validator failed for field "Session.agent_identifier": %w`, err)} } } if v, ok := sc.mutation.HostIdentifier(); ok { if err := session.HostIdentifierValidator(v); err != nil { - return &ValidationError{Name: "hostIdentifier", err: fmt.Errorf(`ent: validator failed for field "Session.hostIdentifier": %w`, err)} + return &ValidationError{Name: "host_identifier", err: fmt.Errorf(`ent: validator failed for field "Session.host_identifier": %w`, err)} + } + } + if _, ok := sc.mutation.HostPlatform(); !ok { + return &ValidationError{Name: "host_platform", err: errors.New(`ent: missing required field "Session.host_platform"`)} + } + if v, ok := sc.mutation.HostPlatform(); ok { + if err := session.HostPlatformValidator(v); err != nil { + return &ValidationError{Name: "host_platform", err: fmt.Errorf(`ent: validator failed for field "Session.host_platform": %w`, err)} } } return nil } func (sc *SessionCreate) sqlSave(ctx context.Context) (*Session, error) { + if err := sc.check(); err != nil { + return nil, err + } _node, _spec := sc.createSpec() if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -288,19 +289,15 @@ func (sc *SessionCreate) sqlSave(ctx context.Context) (*Session, error) { } id := _spec.ID.Value.(int64) _node.ID = int(id) + sc.mutation.id = &_node.ID + sc.mutation.done = true return _node, nil } func (sc *SessionCreate) createSpec() (*Session, *sqlgraph.CreateSpec) { var ( _node = &Session{config: sc.config} - _spec = &sqlgraph.CreateSpec{ - Table: session.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: session.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(session.Table, sqlgraph.NewFieldSpec(session.FieldID, field.TypeInt)) ) if value, ok := sc.mutation.Name(); ok { _spec.SetField(session.FieldName, field.TypeString, value) @@ -326,6 +323,14 @@ func (sc *SessionCreate) createSpec() (*Session, *sqlgraph.CreateSpec) { _spec.SetField(session.FieldHostIdentifier, field.TypeString, value) _node.HostIdentifier = value } + if value, ok := sc.mutation.HostPrimaryIP(); ok { + _spec.SetField(session.FieldHostPrimaryIP, field.TypeString, value) + _node.HostPrimaryIP = value + } + if value, ok := sc.mutation.HostPlatform(); ok { + _spec.SetField(session.FieldHostPlatform, field.TypeEnum, value) + _node.HostPlatform = value + } if value, ok := sc.mutation.LastSeenAt(); ok { _spec.SetField(session.FieldLastSeenAt, field.TypeTime, value) _node.LastSeenAt = value diff --git a/tavern/ent/session_delete.go b/tavern/ent/session_delete.go index b32916a1d..930cd0768 100644 --- a/tavern/ent/session_delete.go +++ b/tavern/ent/session_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (sd *SessionDelete) Where(ps ...predicate.Session) *SessionDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (sd *SessionDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(sd.hooks) == 0 { - affected, err = sd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*SessionMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - sd.mutation = mutation - affected, err = sd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(sd.hooks) - 1; i >= 0; i-- { - if sd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = sd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, sd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, SessionMutation](ctx, sd.sqlExec, sd.mutation, sd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (sd *SessionDelete) ExecX(ctx context.Context) int { } func (sd *SessionDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: session.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: session.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(session.Table, sqlgraph.NewFieldSpec(session.FieldID, field.TypeInt)) if ps := sd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (sd *SessionDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + sd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type SessionDeleteOne struct { sd *SessionDelete } +// Where appends a list predicates to the SessionDelete builder. +func (sdo *SessionDeleteOne) Where(ps ...predicate.Session) *SessionDeleteOne { + sdo.sd.mutation.Where(ps...) + return sdo +} + // Exec executes the deletion query. func (sdo *SessionDeleteOne) Exec(ctx context.Context) error { n, err := sdo.sd.Exec(ctx) @@ -111,5 +82,7 @@ func (sdo *SessionDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (sdo *SessionDeleteOne) ExecX(ctx context.Context) { - sdo.sd.ExecX(ctx) + if err := sdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/tavern/ent/session_query.go b/tavern/ent/session_query.go index 3747dfdaa..2efd68049 100644 --- a/tavern/ent/session_query.go +++ b/tavern/ent/session_query.go @@ -20,11 +20,9 @@ import ( // SessionQuery is the builder for querying Session entities. type SessionQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.Session withTags *TagQuery withTasks *TaskQuery @@ -43,26 +41,26 @@ func (sq *SessionQuery) Where(ps ...predicate.Session) *SessionQuery { return sq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (sq *SessionQuery) Limit(limit int) *SessionQuery { - sq.limit = &limit + sq.ctx.Limit = &limit return sq } -// Offset adds an offset step to the query. +// Offset to start from. func (sq *SessionQuery) Offset(offset int) *SessionQuery { - sq.offset = &offset + sq.ctx.Offset = &offset return sq } // 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 (sq *SessionQuery) Unique(unique bool) *SessionQuery { - sq.unique = &unique + sq.ctx.Unique = &unique return sq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (sq *SessionQuery) Order(o ...OrderFunc) *SessionQuery { sq.order = append(sq.order, o...) return sq @@ -70,7 +68,7 @@ func (sq *SessionQuery) Order(o ...OrderFunc) *SessionQuery { // QueryTags chains the current query on the "tags" edge. func (sq *SessionQuery) QueryTags() *TagQuery { - query := &TagQuery{config: sq.config} + query := (&TagClient{config: sq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := sq.prepareQuery(ctx); err != nil { return nil, err @@ -92,7 +90,7 @@ func (sq *SessionQuery) QueryTags() *TagQuery { // QueryTasks chains the current query on the "tasks" edge. func (sq *SessionQuery) QueryTasks() *TaskQuery { - query := &TaskQuery{config: sq.config} + query := (&TaskClient{config: sq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := sq.prepareQuery(ctx); err != nil { return nil, err @@ -115,7 +113,7 @@ func (sq *SessionQuery) QueryTasks() *TaskQuery { // First returns the first Session entity from the query. // Returns a *NotFoundError when no Session was found. func (sq *SessionQuery) First(ctx context.Context) (*Session, error) { - nodes, err := sq.Limit(1).All(ctx) + nodes, err := sq.Limit(1).All(setContextOp(ctx, sq.ctx, "First")) if err != nil { return nil, err } @@ -138,7 +136,7 @@ func (sq *SessionQuery) FirstX(ctx context.Context) *Session { // Returns a *NotFoundError when no Session ID was found. func (sq *SessionQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = sq.Limit(1).IDs(ctx); err != nil { + if ids, err = sq.Limit(1).IDs(setContextOp(ctx, sq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -161,7 +159,7 @@ func (sq *SessionQuery) FirstIDX(ctx context.Context) int { // Returns a *NotSingularError when more than one Session entity is found. // Returns a *NotFoundError when no Session entities are found. func (sq *SessionQuery) Only(ctx context.Context) (*Session, error) { - nodes, err := sq.Limit(2).All(ctx) + nodes, err := sq.Limit(2).All(setContextOp(ctx, sq.ctx, "Only")) if err != nil { return nil, err } @@ -189,7 +187,7 @@ func (sq *SessionQuery) OnlyX(ctx context.Context) *Session { // Returns a *NotFoundError when no entities are found. func (sq *SessionQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = sq.Limit(2).IDs(ctx); err != nil { + if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -214,10 +212,12 @@ func (sq *SessionQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of Sessions. func (sq *SessionQuery) All(ctx context.Context) ([]*Session, error) { + ctx = setContextOp(ctx, sq.ctx, "All") if err := sq.prepareQuery(ctx); err != nil { return nil, err } - return sq.sqlAll(ctx) + qr := querierAll[[]*Session, *SessionQuery]() + return withInterceptors[[]*Session](ctx, sq, qr, sq.inters) } // AllX is like All, but panics if an error occurs. @@ -230,9 +230,12 @@ func (sq *SessionQuery) AllX(ctx context.Context) []*Session { } // IDs executes the query and returns a list of Session IDs. -func (sq *SessionQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := sq.Select(session.FieldID).Scan(ctx, &ids); err != nil { +func (sq *SessionQuery) IDs(ctx context.Context) (ids []int, err error) { + if sq.ctx.Unique == nil && sq.path != nil { + sq.Unique(true) + } + ctx = setContextOp(ctx, sq.ctx, "IDs") + if err = sq.Select(session.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -249,10 +252,11 @@ func (sq *SessionQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (sq *SessionQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, sq.ctx, "Count") if err := sq.prepareQuery(ctx); err != nil { return 0, err } - return sq.sqlCount(ctx) + return withInterceptors[int](ctx, sq, querierCount[*SessionQuery](), sq.inters) } // CountX is like Count, but panics if an error occurs. @@ -266,10 +270,15 @@ func (sq *SessionQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (sq *SessionQuery) Exist(ctx context.Context) (bool, error) { - if err := sq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, sq.ctx, "Exist") + switch _, err := sq.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 sq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -289,23 +298,22 @@ func (sq *SessionQuery) Clone() *SessionQuery { } return &SessionQuery{ config: sq.config, - limit: sq.limit, - offset: sq.offset, + ctx: sq.ctx.Clone(), order: append([]OrderFunc{}, sq.order...), + inters: append([]Interceptor{}, sq.inters...), predicates: append([]predicate.Session{}, sq.predicates...), withTags: sq.withTags.Clone(), withTasks: sq.withTasks.Clone(), // clone intermediate query. - sql: sq.sql.Clone(), - path: sq.path, - unique: sq.unique, + sql: sq.sql.Clone(), + path: sq.path, } } // WithTags tells the query-builder to eager-load the nodes that are connected to // the "tags" edge. The optional arguments are used to configure the query builder of the edge. func (sq *SessionQuery) WithTags(opts ...func(*TagQuery)) *SessionQuery { - query := &TagQuery{config: sq.config} + query := (&TagClient{config: sq.config}).Query() for _, opt := range opts { opt(query) } @@ -316,7 +324,7 @@ func (sq *SessionQuery) WithTags(opts ...func(*TagQuery)) *SessionQuery { // WithTasks tells the query-builder to eager-load the nodes that are connected to // the "tasks" edge. The optional arguments are used to configure the query builder of the edge. func (sq *SessionQuery) WithTasks(opts ...func(*TaskQuery)) *SessionQuery { - query := &TaskQuery{config: sq.config} + query := (&TaskClient{config: sq.config}).Query() for _, opt := range opts { opt(query) } @@ -339,16 +347,11 @@ func (sq *SessionQuery) WithTasks(opts ...func(*TaskQuery)) *SessionQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (sq *SessionQuery) GroupBy(field string, fields ...string) *SessionGroupBy { - grbuild := &SessionGroupBy{config: sq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := sq.prepareQuery(ctx); err != nil { - return nil, err - } - return sq.sqlQuery(ctx), nil - } + sq.ctx.Fields = append([]string{field}, fields...) + grbuild := &SessionGroupBy{build: sq} + grbuild.flds = &sq.ctx.Fields grbuild.label = session.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -365,11 +368,11 @@ func (sq *SessionQuery) GroupBy(field string, fields ...string) *SessionGroupBy // Select(session.FieldName). // Scan(ctx, &v) func (sq *SessionQuery) Select(fields ...string) *SessionSelect { - sq.fields = append(sq.fields, fields...) - selbuild := &SessionSelect{SessionQuery: sq} - selbuild.label = session.Label - selbuild.flds, selbuild.scan = &sq.fields, selbuild.Scan - return selbuild + sq.ctx.Fields = append(sq.ctx.Fields, fields...) + sbuild := &SessionSelect{SessionQuery: sq} + sbuild.label = session.Label + sbuild.flds, sbuild.scan = &sq.ctx.Fields, sbuild.Scan + return sbuild } // Aggregate returns a SessionSelect configured with the given aggregations. @@ -378,7 +381,17 @@ func (sq *SessionQuery) Aggregate(fns ...AggregateFunc) *SessionSelect { } func (sq *SessionQuery) prepareQuery(ctx context.Context) error { - for _, f := range sq.fields { + for _, inter := range sq.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, sq); err != nil { + return err + } + } + } + for _, f := range sq.ctx.Fields { if !session.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -482,27 +495,30 @@ func (sq *SessionQuery) loadTags(ctx context.Context, query *TagQuery, 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(sql.NullInt64)}, values...), nil } - return append([]any{new(sql.NullInt64)}, values...), nil - } - spec.Assign = func(columns []string, values []any) error { - outValue := int(values[0].(*sql.NullInt64).Int64) - inValue := int(values[1].(*sql.NullInt64).Int64) - if nids[inValue] == nil { - nids[inValue] = map[*Session]struct{}{byID[outValue]: {}} - return assign(columns[1:], values[1:]) + spec.Assign = func(columns []string, values []any) error { + outValue := int(values[0].(*sql.NullInt64).Int64) + inValue := int(values[1].(*sql.NullInt64).Int64) + if nids[inValue] == nil { + nids[inValue] = map[*Session]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[[]*Tag](ctx, query, qr, query.inters) if err != nil { return err } @@ -554,41 +570,22 @@ func (sq *SessionQuery) sqlCount(ctx context.Context) (int, error) { if len(sq.modifiers) > 0 { _spec.Modifiers = sq.modifiers } - _spec.Node.Columns = sq.fields - if len(sq.fields) > 0 { - _spec.Unique = sq.unique != nil && *sq.unique + _spec.Node.Columns = sq.ctx.Fields + if len(sq.ctx.Fields) > 0 { + _spec.Unique = sq.ctx.Unique != nil && *sq.ctx.Unique } return sqlgraph.CountNodes(ctx, sq.driver, _spec) } -func (sq *SessionQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := sq.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 (sq *SessionQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: session.Table, - Columns: session.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: session.FieldID, - }, - }, - From: sq.sql, - Unique: true, - } - if unique := sq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(session.Table, session.Columns, sqlgraph.NewFieldSpec(session.FieldID, field.TypeInt)) + _spec.From = sq.sql + if unique := sq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if sq.path != nil { + _spec.Unique = true } - if fields := sq.fields; len(fields) > 0 { + if fields := sq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, session.FieldID) for i := range fields { @@ -604,10 +601,10 @@ func (sq *SessionQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := sq.limit; limit != nil { + if limit := sq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := sq.offset; offset != nil { + if offset := sq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := sq.order; len(ps) > 0 { @@ -623,7 +620,7 @@ func (sq *SessionQuery) querySpec() *sqlgraph.QuerySpec { func (sq *SessionQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(sq.driver.Dialect()) t1 := builder.Table(session.Table) - columns := sq.fields + columns := sq.ctx.Fields if len(columns) == 0 { columns = session.Columns } @@ -632,7 +629,7 @@ func (sq *SessionQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = sq.sql selector.Select(selector.Columns(columns...)...) } - if sq.unique != nil && *sq.unique { + if sq.ctx.Unique != nil && *sq.ctx.Unique { selector.Distinct() } for _, p := range sq.predicates { @@ -641,12 +638,12 @@ func (sq *SessionQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range sq.order { p(selector) } - if offset := sq.offset; offset != nil { + if offset := sq.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 := sq.limit; limit != nil { + if limit := sq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -655,7 +652,7 @@ func (sq *SessionQuery) sqlQuery(ctx context.Context) *sql.Selector { // WithNamedTags tells the query-builder to eager-load the nodes that are connected to the "tags" // edge with the given name. The optional arguments are used to configure the query builder of the edge. func (sq *SessionQuery) WithNamedTags(name string, opts ...func(*TagQuery)) *SessionQuery { - query := &TagQuery{config: sq.config} + query := (&TagClient{config: sq.config}).Query() for _, opt := range opts { opt(query) } @@ -669,7 +666,7 @@ func (sq *SessionQuery) WithNamedTags(name string, opts ...func(*TagQuery)) *Ses // WithNamedTasks tells the query-builder to eager-load the nodes that are connected to the "tasks" // edge with the given name. The optional arguments are used to configure the query builder of the edge. func (sq *SessionQuery) WithNamedTasks(name string, opts ...func(*TaskQuery)) *SessionQuery { - query := &TaskQuery{config: sq.config} + query := (&TaskClient{config: sq.config}).Query() for _, opt := range opts { opt(query) } @@ -682,13 +679,8 @@ func (sq *SessionQuery) WithNamedTasks(name string, opts ...func(*TaskQuery)) *S // SessionGroupBy is the group-by builder for Session entities. type SessionGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *SessionQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -697,58 +689,46 @@ func (sgb *SessionGroupBy) Aggregate(fns ...AggregateFunc) *SessionGroupBy { return sgb } -// 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 (sgb *SessionGroupBy) Scan(ctx context.Context, v any) error { - query, err := sgb.path(ctx) - if err != nil { + ctx = setContextOp(ctx, sgb.build.ctx, "GroupBy") + if err := sgb.build.prepareQuery(ctx); err != nil { return err } - sgb.sql = query - return sgb.sqlScan(ctx, v) + return scanWithInterceptors[*SessionQuery, *SessionGroupBy](ctx, sgb.build, sgb, sgb.build.inters, v) } -func (sgb *SessionGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range sgb.fields { - if !session.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} +func (sgb *SessionGroupBy) sqlScan(ctx context.Context, root *SessionQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(sgb.fns)) + for _, fn := range sgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*sgb.flds)+len(sgb.fns)) + for _, f := range *sgb.flds { + columns = append(columns, selector.C(f)) } + columns = append(columns, aggregation...) + selector.Select(columns...) } - selector := sgb.sqlQuery() + selector.GroupBy(selector.Columns(*sgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := sgb.driver.Query(ctx, query, args, rows); err != nil { + if err := sgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (sgb *SessionGroupBy) sqlQuery() *sql.Selector { - selector := sgb.sql.Select() - aggregation := make([]string, 0, len(sgb.fns)) - for _, fn := range sgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(sgb.fields)+len(sgb.fns)) - for _, f := range sgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(sgb.fields...)...) -} - // SessionSelect is the builder for selecting fields of Session entities. type SessionSelect struct { *SessionQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -759,26 +739,27 @@ func (ss *SessionSelect) Aggregate(fns ...AggregateFunc) *SessionSelect { // Scan applies the selector query and scans the result into the given value. func (ss *SessionSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ss.ctx, "Select") if err := ss.prepareQuery(ctx); err != nil { return err } - ss.sql = ss.SessionQuery.sqlQuery(ctx) - return ss.sqlScan(ctx, v) + return scanWithInterceptors[*SessionQuery, *SessionSelect](ctx, ss.SessionQuery, ss, ss.inters, v) } -func (ss *SessionSelect) sqlScan(ctx context.Context, v any) error { +func (ss *SessionSelect) sqlScan(ctx context.Context, root *SessionQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(ss.fns)) for _, fn := range ss.fns { - aggregation = append(aggregation, fn(ss.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*ss.selector.flds); { case n == 0 && len(aggregation) > 0: - ss.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - ss.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := ss.sql.Query() + query, args := selector.Query() if err := ss.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/tavern/ent/session_update.go b/tavern/ent/session_update.go index 2ac9cd885..2bbb825f9 100644 --- a/tavern/ent/session_update.go +++ b/tavern/ent/session_update.go @@ -98,13 +98,13 @@ func (su *SessionUpdate) SetNillableIdentifier(s *string) *SessionUpdate { return su } -// SetAgentIdentifier sets the "agentIdentifier" field. +// SetAgentIdentifier sets the "agent_identifier" field. func (su *SessionUpdate) SetAgentIdentifier(s string) *SessionUpdate { su.mutation.SetAgentIdentifier(s) return su } -// SetNillableAgentIdentifier sets the "agentIdentifier" field if the given value is not nil. +// SetNillableAgentIdentifier sets the "agent_identifier" field if the given value is not nil. func (su *SessionUpdate) SetNillableAgentIdentifier(s *string) *SessionUpdate { if s != nil { su.SetAgentIdentifier(*s) @@ -112,19 +112,19 @@ func (su *SessionUpdate) SetNillableAgentIdentifier(s *string) *SessionUpdate { return su } -// ClearAgentIdentifier clears the value of the "agentIdentifier" field. +// ClearAgentIdentifier clears the value of the "agent_identifier" field. func (su *SessionUpdate) ClearAgentIdentifier() *SessionUpdate { su.mutation.ClearAgentIdentifier() return su } -// SetHostIdentifier sets the "hostIdentifier" field. +// SetHostIdentifier sets the "host_identifier" field. func (su *SessionUpdate) SetHostIdentifier(s string) *SessionUpdate { su.mutation.SetHostIdentifier(s) return su } -// SetNillableHostIdentifier sets the "hostIdentifier" field if the given value is not nil. +// SetNillableHostIdentifier sets the "host_identifier" field if the given value is not nil. func (su *SessionUpdate) SetNillableHostIdentifier(s *string) *SessionUpdate { if s != nil { su.SetHostIdentifier(*s) @@ -132,19 +132,53 @@ func (su *SessionUpdate) SetNillableHostIdentifier(s *string) *SessionUpdate { return su } -// ClearHostIdentifier clears the value of the "hostIdentifier" field. +// ClearHostIdentifier clears the value of the "host_identifier" field. func (su *SessionUpdate) ClearHostIdentifier() *SessionUpdate { su.mutation.ClearHostIdentifier() return su } -// SetLastSeenAt sets the "lastSeenAt" field. +// SetHostPrimaryIP sets the "host_primary_ip" field. +func (su *SessionUpdate) SetHostPrimaryIP(s string) *SessionUpdate { + su.mutation.SetHostPrimaryIP(s) + return su +} + +// SetNillableHostPrimaryIP sets the "host_primary_ip" field if the given value is not nil. +func (su *SessionUpdate) SetNillableHostPrimaryIP(s *string) *SessionUpdate { + if s != nil { + su.SetHostPrimaryIP(*s) + } + return su +} + +// ClearHostPrimaryIP clears the value of the "host_primary_ip" field. +func (su *SessionUpdate) ClearHostPrimaryIP() *SessionUpdate { + su.mutation.ClearHostPrimaryIP() + return su +} + +// SetHostPlatform sets the "host_platform" field. +func (su *SessionUpdate) SetHostPlatform(sp session.HostPlatform) *SessionUpdate { + su.mutation.SetHostPlatform(sp) + return su +} + +// SetNillableHostPlatform sets the "host_platform" field if the given value is not nil. +func (su *SessionUpdate) SetNillableHostPlatform(sp *session.HostPlatform) *SessionUpdate { + if sp != nil { + su.SetHostPlatform(*sp) + } + return su +} + +// SetLastSeenAt sets the "last_seen_at" field. func (su *SessionUpdate) SetLastSeenAt(t time.Time) *SessionUpdate { su.mutation.SetLastSeenAt(t) return su } -// SetNillableLastSeenAt sets the "lastSeenAt" field if the given value is not nil. +// SetNillableLastSeenAt sets the "last_seen_at" field if the given value is not nil. func (su *SessionUpdate) SetNillableLastSeenAt(t *time.Time) *SessionUpdate { if t != nil { su.SetLastSeenAt(*t) @@ -152,7 +186,7 @@ func (su *SessionUpdate) SetNillableLastSeenAt(t *time.Time) *SessionUpdate { return su } -// ClearLastSeenAt clears the value of the "lastSeenAt" field. +// ClearLastSeenAt clears the value of the "last_seen_at" field. func (su *SessionUpdate) ClearLastSeenAt() *SessionUpdate { su.mutation.ClearLastSeenAt() return su @@ -237,40 +271,7 @@ func (su *SessionUpdate) RemoveTasks(t ...*Task) *SessionUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (su *SessionUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(su.hooks) == 0 { - if err = su.check(); err != nil { - return 0, err - } - affected, err = su.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*SessionMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = su.check(); err != nil { - return 0, err - } - su.mutation = mutation - affected, err = su.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(su.hooks) - 1; i >= 0; i-- { - if su.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = su.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, su.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, SessionMutation](ctx, su.sqlSave, su.mutation, su.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -319,28 +320,27 @@ func (su *SessionUpdate) check() error { } if v, ok := su.mutation.AgentIdentifier(); ok { if err := session.AgentIdentifierValidator(v); err != nil { - return &ValidationError{Name: "agentIdentifier", err: fmt.Errorf(`ent: validator failed for field "Session.agentIdentifier": %w`, err)} + return &ValidationError{Name: "agent_identifier", err: fmt.Errorf(`ent: validator failed for field "Session.agent_identifier": %w`, err)} } } if v, ok := su.mutation.HostIdentifier(); ok { if err := session.HostIdentifierValidator(v); err != nil { - return &ValidationError{Name: "hostIdentifier", err: fmt.Errorf(`ent: validator failed for field "Session.hostIdentifier": %w`, err)} + return &ValidationError{Name: "host_identifier", err: fmt.Errorf(`ent: validator failed for field "Session.host_identifier": %w`, err)} + } + } + if v, ok := su.mutation.HostPlatform(); ok { + if err := session.HostPlatformValidator(v); err != nil { + return &ValidationError{Name: "host_platform", err: fmt.Errorf(`ent: validator failed for field "Session.host_platform": %w`, err)} } } return nil } func (su *SessionUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: session.Table, - Columns: session.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: session.FieldID, - }, - }, + if err := su.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(session.Table, session.Columns, sqlgraph.NewFieldSpec(session.FieldID, field.TypeInt)) if ps := su.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -378,6 +378,15 @@ func (su *SessionUpdate) sqlSave(ctx context.Context) (n int, err error) { if su.mutation.HostIdentifierCleared() { _spec.ClearField(session.FieldHostIdentifier, field.TypeString) } + if value, ok := su.mutation.HostPrimaryIP(); ok { + _spec.SetField(session.FieldHostPrimaryIP, field.TypeString, value) + } + if su.mutation.HostPrimaryIPCleared() { + _spec.ClearField(session.FieldHostPrimaryIP, field.TypeString) + } + if value, ok := su.mutation.HostPlatform(); ok { + _spec.SetField(session.FieldHostPlatform, field.TypeEnum, value) + } if value, ok := su.mutation.LastSeenAt(); ok { _spec.SetField(session.FieldLastSeenAt, field.TypeTime, value) } @@ -500,6 +509,7 @@ func (su *SessionUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + su.mutation.done = true return n, nil } @@ -579,13 +589,13 @@ func (suo *SessionUpdateOne) SetNillableIdentifier(s *string) *SessionUpdateOne return suo } -// SetAgentIdentifier sets the "agentIdentifier" field. +// SetAgentIdentifier sets the "agent_identifier" field. func (suo *SessionUpdateOne) SetAgentIdentifier(s string) *SessionUpdateOne { suo.mutation.SetAgentIdentifier(s) return suo } -// SetNillableAgentIdentifier sets the "agentIdentifier" field if the given value is not nil. +// SetNillableAgentIdentifier sets the "agent_identifier" field if the given value is not nil. func (suo *SessionUpdateOne) SetNillableAgentIdentifier(s *string) *SessionUpdateOne { if s != nil { suo.SetAgentIdentifier(*s) @@ -593,19 +603,19 @@ func (suo *SessionUpdateOne) SetNillableAgentIdentifier(s *string) *SessionUpdat return suo } -// ClearAgentIdentifier clears the value of the "agentIdentifier" field. +// ClearAgentIdentifier clears the value of the "agent_identifier" field. func (suo *SessionUpdateOne) ClearAgentIdentifier() *SessionUpdateOne { suo.mutation.ClearAgentIdentifier() return suo } -// SetHostIdentifier sets the "hostIdentifier" field. +// SetHostIdentifier sets the "host_identifier" field. func (suo *SessionUpdateOne) SetHostIdentifier(s string) *SessionUpdateOne { suo.mutation.SetHostIdentifier(s) return suo } -// SetNillableHostIdentifier sets the "hostIdentifier" field if the given value is not nil. +// SetNillableHostIdentifier sets the "host_identifier" field if the given value is not nil. func (suo *SessionUpdateOne) SetNillableHostIdentifier(s *string) *SessionUpdateOne { if s != nil { suo.SetHostIdentifier(*s) @@ -613,19 +623,53 @@ func (suo *SessionUpdateOne) SetNillableHostIdentifier(s *string) *SessionUpdate return suo } -// ClearHostIdentifier clears the value of the "hostIdentifier" field. +// ClearHostIdentifier clears the value of the "host_identifier" field. func (suo *SessionUpdateOne) ClearHostIdentifier() *SessionUpdateOne { suo.mutation.ClearHostIdentifier() return suo } -// SetLastSeenAt sets the "lastSeenAt" field. +// SetHostPrimaryIP sets the "host_primary_ip" field. +func (suo *SessionUpdateOne) SetHostPrimaryIP(s string) *SessionUpdateOne { + suo.mutation.SetHostPrimaryIP(s) + return suo +} + +// SetNillableHostPrimaryIP sets the "host_primary_ip" field if the given value is not nil. +func (suo *SessionUpdateOne) SetNillableHostPrimaryIP(s *string) *SessionUpdateOne { + if s != nil { + suo.SetHostPrimaryIP(*s) + } + return suo +} + +// ClearHostPrimaryIP clears the value of the "host_primary_ip" field. +func (suo *SessionUpdateOne) ClearHostPrimaryIP() *SessionUpdateOne { + suo.mutation.ClearHostPrimaryIP() + return suo +} + +// SetHostPlatform sets the "host_platform" field. +func (suo *SessionUpdateOne) SetHostPlatform(sp session.HostPlatform) *SessionUpdateOne { + suo.mutation.SetHostPlatform(sp) + return suo +} + +// SetNillableHostPlatform sets the "host_platform" field if the given value is not nil. +func (suo *SessionUpdateOne) SetNillableHostPlatform(sp *session.HostPlatform) *SessionUpdateOne { + if sp != nil { + suo.SetHostPlatform(*sp) + } + return suo +} + +// SetLastSeenAt sets the "last_seen_at" field. func (suo *SessionUpdateOne) SetLastSeenAt(t time.Time) *SessionUpdateOne { suo.mutation.SetLastSeenAt(t) return suo } -// SetNillableLastSeenAt sets the "lastSeenAt" field if the given value is not nil. +// SetNillableLastSeenAt sets the "last_seen_at" field if the given value is not nil. func (suo *SessionUpdateOne) SetNillableLastSeenAt(t *time.Time) *SessionUpdateOne { if t != nil { suo.SetLastSeenAt(*t) @@ -633,7 +677,7 @@ func (suo *SessionUpdateOne) SetNillableLastSeenAt(t *time.Time) *SessionUpdateO return suo } -// ClearLastSeenAt clears the value of the "lastSeenAt" field. +// ClearLastSeenAt clears the value of the "last_seen_at" field. func (suo *SessionUpdateOne) ClearLastSeenAt() *SessionUpdateOne { suo.mutation.ClearLastSeenAt() return suo @@ -716,6 +760,12 @@ func (suo *SessionUpdateOne) RemoveTasks(t ...*Task) *SessionUpdateOne { return suo.RemoveTaskIDs(ids...) } +// Where appends a list predicates to the SessionUpdate builder. +func (suo *SessionUpdateOne) Where(ps ...predicate.Session) *SessionUpdateOne { + suo.mutation.Where(ps...) + return suo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (suo *SessionUpdateOne) Select(field string, fields ...string) *SessionUpdateOne { @@ -725,46 +775,7 @@ func (suo *SessionUpdateOne) Select(field string, fields ...string) *SessionUpda // Save executes the query and returns the updated Session entity. func (suo *SessionUpdateOne) Save(ctx context.Context) (*Session, error) { - var ( - err error - node *Session - ) - if len(suo.hooks) == 0 { - if err = suo.check(); err != nil { - return nil, err - } - node, err = suo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*SessionMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = suo.check(); err != nil { - return nil, err - } - suo.mutation = mutation - node, err = suo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(suo.hooks) - 1; i >= 0; i-- { - if suo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = suo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, suo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Session) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from SessionMutation", v) - } - node = nv - } - return node, err + return withHooks[*Session, SessionMutation](ctx, suo.sqlSave, suo.mutation, suo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -813,28 +824,27 @@ func (suo *SessionUpdateOne) check() error { } if v, ok := suo.mutation.AgentIdentifier(); ok { if err := session.AgentIdentifierValidator(v); err != nil { - return &ValidationError{Name: "agentIdentifier", err: fmt.Errorf(`ent: validator failed for field "Session.agentIdentifier": %w`, err)} + return &ValidationError{Name: "agent_identifier", err: fmt.Errorf(`ent: validator failed for field "Session.agent_identifier": %w`, err)} } } if v, ok := suo.mutation.HostIdentifier(); ok { if err := session.HostIdentifierValidator(v); err != nil { - return &ValidationError{Name: "hostIdentifier", err: fmt.Errorf(`ent: validator failed for field "Session.hostIdentifier": %w`, err)} + return &ValidationError{Name: "host_identifier", err: fmt.Errorf(`ent: validator failed for field "Session.host_identifier": %w`, err)} + } + } + if v, ok := suo.mutation.HostPlatform(); ok { + if err := session.HostPlatformValidator(v); err != nil { + return &ValidationError{Name: "host_platform", err: fmt.Errorf(`ent: validator failed for field "Session.host_platform": %w`, err)} } } return nil } func (suo *SessionUpdateOne) sqlSave(ctx context.Context) (_node *Session, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: session.Table, - Columns: session.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: session.FieldID, - }, - }, + if err := suo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(session.Table, session.Columns, sqlgraph.NewFieldSpec(session.FieldID, field.TypeInt)) id, ok := suo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Session.id" for update`)} @@ -889,6 +899,15 @@ func (suo *SessionUpdateOne) sqlSave(ctx context.Context) (_node *Session, err e if suo.mutation.HostIdentifierCleared() { _spec.ClearField(session.FieldHostIdentifier, field.TypeString) } + if value, ok := suo.mutation.HostPrimaryIP(); ok { + _spec.SetField(session.FieldHostPrimaryIP, field.TypeString, value) + } + if suo.mutation.HostPrimaryIPCleared() { + _spec.ClearField(session.FieldHostPrimaryIP, field.TypeString) + } + if value, ok := suo.mutation.HostPlatform(); ok { + _spec.SetField(session.FieldHostPlatform, field.TypeEnum, value) + } if value, ok := suo.mutation.LastSeenAt(); ok { _spec.SetField(session.FieldLastSeenAt, field.TypeTime, value) } @@ -1014,5 +1033,6 @@ func (suo *SessionUpdateOne) sqlSave(ctx context.Context) (_node *Session, err e } return nil, err } + suo.mutation.done = true return _node, nil } diff --git a/tavern/ent/tag.go b/tavern/ent/tag.go index a357c7782..a537b663a 100644 --- a/tavern/ent/tag.go +++ b/tavern/ent/tag.go @@ -95,14 +95,14 @@ func (t *Tag) assignValues(columns []string, values []any) error { // QuerySessions queries the "sessions" edge of the Tag entity. func (t *Tag) QuerySessions() *SessionQuery { - return (&TagClient{config: t.config}).QuerySessions(t) + return NewTagClient(t.config).QuerySessions(t) } // Update returns a builder for updating this Tag. // Note that you need to call Tag.Unwrap() before calling this method if this Tag // was returned from a transaction, and the transaction was committed or rolled back. func (t *Tag) Update() *TagUpdateOne { - return (&TagClient{config: t.config}).UpdateOne(t) + return NewTagClient(t.config).UpdateOne(t) } // Unwrap unwraps the Tag entity that was returned from a transaction after it was closed, @@ -156,9 +156,3 @@ func (t *Tag) appendNamedSessions(name string, edges ...*Session) { // Tags is a parsable slice of Tag. type Tags []*Tag - -func (t Tags) config(cfg config) { - for _i := range t { - t[_i].config = cfg - } -} diff --git a/tavern/ent/tag/where.go b/tavern/ent/tag/where.go index 5366fe6f0..637468d66 100644 --- a/tavern/ent/tag/where.go +++ b/tavern/ent/tag/where.go @@ -10,215 +10,137 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Tag(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Tag(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Tag(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Tag { - return predicate.Tag(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.Tag(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Tag { - return predicate.Tag(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.Tag(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Tag(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Tag(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Tag(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Tag(sql.FieldLTE(FieldID, id)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldEQ(FieldName, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.Tag { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.Tag(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.Tag { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.Tag(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.Tag(sql.FieldContainsFold(FieldName, v)) } // KindEQ applies the EQ predicate on the "kind" field. func KindEQ(v Kind) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldKind), v)) - }) + return predicate.Tag(sql.FieldEQ(FieldKind, v)) } // KindNEQ applies the NEQ predicate on the "kind" field. func KindNEQ(v Kind) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldKind), v)) - }) + return predicate.Tag(sql.FieldNEQ(FieldKind, v)) } // KindIn applies the In predicate on the "kind" field. func KindIn(vs ...Kind) predicate.Tag { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldKind), v...)) - }) + return predicate.Tag(sql.FieldIn(FieldKind, vs...)) } // KindNotIn applies the NotIn predicate on the "kind" field. func KindNotIn(vs ...Kind) predicate.Tag { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tag(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldKind), v...)) - }) + return predicate.Tag(sql.FieldNotIn(FieldKind, vs...)) } // HasSessions applies the HasEdge predicate on the "sessions" edge. @@ -226,7 +148,6 @@ func HasSessions() predicate.Tag { return predicate.Tag(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(SessionsTable, FieldID), sqlgraph.Edge(sqlgraph.M2M, true, SessionsTable, SessionsPrimaryKey...), ) sqlgraph.HasNeighbors(s, step) diff --git a/tavern/ent/tag_create.go b/tavern/ent/tag_create.go index e6dcc5ad6..984a426c0 100644 --- a/tavern/ent/tag_create.go +++ b/tavern/ent/tag_create.go @@ -54,49 +54,7 @@ func (tc *TagCreate) Mutation() *TagMutation { // Save creates the Tag in the database. func (tc *TagCreate) Save(ctx context.Context) (*Tag, error) { - var ( - err error - node *Tag - ) - if len(tc.hooks) == 0 { - if err = tc.check(); err != nil { - return nil, err - } - node, err = tc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = tc.check(); err != nil { - return nil, err - } - tc.mutation = mutation - if node, err = tc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(tc.hooks) - 1; i >= 0; i-- { - if tc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = tc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, tc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Tag) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from TagMutation", v) - } - node = nv - } - return node, err + return withHooks[*Tag, TagMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -143,6 +101,9 @@ func (tc *TagCreate) check() error { } func (tc *TagCreate) sqlSave(ctx context.Context) (*Tag, error) { + if err := tc.check(); err != nil { + return nil, err + } _node, _spec := tc.createSpec() if err := sqlgraph.CreateNode(ctx, tc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -152,19 +113,15 @@ func (tc *TagCreate) sqlSave(ctx context.Context) (*Tag, error) { } id := _spec.ID.Value.(int64) _node.ID = int(id) + tc.mutation.id = &_node.ID + tc.mutation.done = true return _node, nil } func (tc *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) { var ( _node = &Tag{config: tc.config} - _spec = &sqlgraph.CreateSpec{ - Table: tag.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: tag.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(tag.Table, sqlgraph.NewFieldSpec(tag.FieldID, field.TypeInt)) ) if value, ok := tc.mutation.Name(); ok { _spec.SetField(tag.FieldName, field.TypeString, value) diff --git a/tavern/ent/tag_delete.go b/tavern/ent/tag_delete.go index 3edbf7a6f..90090f0b0 100644 --- a/tavern/ent/tag_delete.go +++ b/tavern/ent/tag_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (td *TagDelete) Where(ps ...predicate.Tag) *TagDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TagDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(td.hooks) == 0 { - affected, err = td.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - td.mutation = mutation - affected, err = td.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(td.hooks) - 1; i >= 0; i-- { - if td.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = td.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, td.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, TagMutation](ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (td *TagDelete) ExecX(ctx context.Context) int { } func (td *TagDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: tag.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: tag.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(tag.Table, sqlgraph.NewFieldSpec(tag.FieldID, field.TypeInt)) if ps := td.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (td *TagDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + td.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type TagDeleteOne struct { td *TagDelete } +// Where appends a list predicates to the TagDelete builder. +func (tdo *TagDeleteOne) Where(ps ...predicate.Tag) *TagDeleteOne { + tdo.td.mutation.Where(ps...) + return tdo +} + // Exec executes the deletion query. func (tdo *TagDeleteOne) Exec(ctx context.Context) error { n, err := tdo.td.Exec(ctx) @@ -111,5 +82,7 @@ func (tdo *TagDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (tdo *TagDeleteOne) ExecX(ctx context.Context) { - tdo.td.ExecX(ctx) + if err := tdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/tavern/ent/tag_query.go b/tavern/ent/tag_query.go index eb714551e..54bd79be8 100644 --- a/tavern/ent/tag_query.go +++ b/tavern/ent/tag_query.go @@ -19,11 +19,9 @@ import ( // TagQuery is the builder for querying Tag entities. type TagQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.Tag withSessions *SessionQuery modifiers []func(*sql.Selector) @@ -40,26 +38,26 @@ func (tq *TagQuery) Where(ps ...predicate.Tag) *TagQuery { return tq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (tq *TagQuery) Limit(limit int) *TagQuery { - tq.limit = &limit + tq.ctx.Limit = &limit return tq } -// Offset adds an offset step to the query. +// Offset to start from. func (tq *TagQuery) Offset(offset int) *TagQuery { - tq.offset = &offset + tq.ctx.Offset = &offset return tq } // 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 (tq *TagQuery) Unique(unique bool) *TagQuery { - tq.unique = &unique + tq.ctx.Unique = &unique return tq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (tq *TagQuery) Order(o ...OrderFunc) *TagQuery { tq.order = append(tq.order, o...) return tq @@ -67,7 +65,7 @@ func (tq *TagQuery) Order(o ...OrderFunc) *TagQuery { // QuerySessions chains the current query on the "sessions" edge. func (tq *TagQuery) QuerySessions() *SessionQuery { - query := &SessionQuery{config: tq.config} + query := (&SessionClient{config: tq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := tq.prepareQuery(ctx); err != nil { return nil, err @@ -90,7 +88,7 @@ func (tq *TagQuery) QuerySessions() *SessionQuery { // First returns the first Tag entity from the query. // Returns a *NotFoundError when no Tag was found. func (tq *TagQuery) First(ctx context.Context) (*Tag, error) { - nodes, err := tq.Limit(1).All(ctx) + nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, "First")) if err != nil { return nil, err } @@ -113,7 +111,7 @@ func (tq *TagQuery) FirstX(ctx context.Context) *Tag { // Returns a *NotFoundError when no Tag ID was found. func (tq *TagQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = tq.Limit(1).IDs(ctx); err != nil { + if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -136,7 +134,7 @@ func (tq *TagQuery) FirstIDX(ctx context.Context) int { // Returns a *NotSingularError when more than one Tag entity is found. // Returns a *NotFoundError when no Tag entities are found. func (tq *TagQuery) Only(ctx context.Context) (*Tag, error) { - nodes, err := tq.Limit(2).All(ctx) + nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, "Only")) if err != nil { return nil, err } @@ -164,7 +162,7 @@ func (tq *TagQuery) OnlyX(ctx context.Context) *Tag { // Returns a *NotFoundError when no entities are found. func (tq *TagQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = tq.Limit(2).IDs(ctx); err != nil { + if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -189,10 +187,12 @@ func (tq *TagQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of Tags. func (tq *TagQuery) All(ctx context.Context) ([]*Tag, error) { + ctx = setContextOp(ctx, tq.ctx, "All") if err := tq.prepareQuery(ctx); err != nil { return nil, err } - return tq.sqlAll(ctx) + qr := querierAll[[]*Tag, *TagQuery]() + return withInterceptors[[]*Tag](ctx, tq, qr, tq.inters) } // AllX is like All, but panics if an error occurs. @@ -205,9 +205,12 @@ func (tq *TagQuery) AllX(ctx context.Context) []*Tag { } // IDs executes the query and returns a list of Tag IDs. -func (tq *TagQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := tq.Select(tag.FieldID).Scan(ctx, &ids); err != nil { +func (tq *TagQuery) IDs(ctx context.Context) (ids []int, err error) { + if tq.ctx.Unique == nil && tq.path != nil { + tq.Unique(true) + } + ctx = setContextOp(ctx, tq.ctx, "IDs") + if err = tq.Select(tag.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -224,10 +227,11 @@ func (tq *TagQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (tq *TagQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, tq.ctx, "Count") if err := tq.prepareQuery(ctx); err != nil { return 0, err } - return tq.sqlCount(ctx) + return withInterceptors[int](ctx, tq, querierCount[*TagQuery](), tq.inters) } // CountX is like Count, but panics if an error occurs. @@ -241,10 +245,15 @@ func (tq *TagQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (tq *TagQuery) Exist(ctx context.Context) (bool, error) { - if err := tq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, tq.ctx, "Exist") + switch _, err := tq.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 tq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -264,22 +273,21 @@ func (tq *TagQuery) Clone() *TagQuery { } return &TagQuery{ config: tq.config, - limit: tq.limit, - offset: tq.offset, + ctx: tq.ctx.Clone(), order: append([]OrderFunc{}, tq.order...), + inters: append([]Interceptor{}, tq.inters...), predicates: append([]predicate.Tag{}, tq.predicates...), withSessions: tq.withSessions.Clone(), // clone intermediate query. - sql: tq.sql.Clone(), - path: tq.path, - unique: tq.unique, + sql: tq.sql.Clone(), + path: tq.path, } } // WithSessions tells the query-builder to eager-load the nodes that are connected to // the "sessions" edge. The optional arguments are used to configure the query builder of the edge. func (tq *TagQuery) WithSessions(opts ...func(*SessionQuery)) *TagQuery { - query := &SessionQuery{config: tq.config} + query := (&SessionClient{config: tq.config}).Query() for _, opt := range opts { opt(query) } @@ -302,16 +310,11 @@ func (tq *TagQuery) WithSessions(opts ...func(*SessionQuery)) *TagQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (tq *TagQuery) GroupBy(field string, fields ...string) *TagGroupBy { - grbuild := &TagGroupBy{config: tq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := tq.prepareQuery(ctx); err != nil { - return nil, err - } - return tq.sqlQuery(ctx), nil - } + tq.ctx.Fields = append([]string{field}, fields...) + grbuild := &TagGroupBy{build: tq} + grbuild.flds = &tq.ctx.Fields grbuild.label = tag.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -328,11 +331,11 @@ func (tq *TagQuery) GroupBy(field string, fields ...string) *TagGroupBy { // Select(tag.FieldName). // Scan(ctx, &v) func (tq *TagQuery) Select(fields ...string) *TagSelect { - tq.fields = append(tq.fields, fields...) - selbuild := &TagSelect{TagQuery: tq} - selbuild.label = tag.Label - selbuild.flds, selbuild.scan = &tq.fields, selbuild.Scan - return selbuild + tq.ctx.Fields = append(tq.ctx.Fields, fields...) + sbuild := &TagSelect{TagQuery: tq} + sbuild.label = tag.Label + sbuild.flds, sbuild.scan = &tq.ctx.Fields, sbuild.Scan + return sbuild } // Aggregate returns a TagSelect configured with the given aggregations. @@ -341,7 +344,17 @@ func (tq *TagQuery) Aggregate(fns ...AggregateFunc) *TagSelect { } func (tq *TagQuery) prepareQuery(ctx context.Context) error { - for _, f := range tq.fields { + for _, inter := range tq.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, tq); err != nil { + return err + } + } + } + for _, f := range tq.ctx.Fields { if !tag.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -430,27 +443,30 @@ func (tq *TagQuery) loadSessions(ctx context.Context, query *SessionQuery, 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(sql.NullInt64)}, values...), nil } - return append([]any{new(sql.NullInt64)}, values...), nil - } - spec.Assign = func(columns []string, values []any) error { - outValue := int(values[0].(*sql.NullInt64).Int64) - inValue := int(values[1].(*sql.NullInt64).Int64) - if nids[inValue] == nil { - nids[inValue] = map[*Tag]struct{}{byID[outValue]: {}} - return assign(columns[1:], values[1:]) + spec.Assign = func(columns []string, values []any) error { + outValue := int(values[0].(*sql.NullInt64).Int64) + inValue := int(values[1].(*sql.NullInt64).Int64) + if nids[inValue] == nil { + nids[inValue] = map[*Tag]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[[]*Session](ctx, query, qr, query.inters) if err != nil { return err } @@ -471,41 +487,22 @@ func (tq *TagQuery) sqlCount(ctx context.Context) (int, error) { if len(tq.modifiers) > 0 { _spec.Modifiers = tq.modifiers } - _spec.Node.Columns = tq.fields - if len(tq.fields) > 0 { - _spec.Unique = tq.unique != nil && *tq.unique + _spec.Node.Columns = tq.ctx.Fields + if len(tq.ctx.Fields) > 0 { + _spec.Unique = tq.ctx.Unique != nil && *tq.ctx.Unique } return sqlgraph.CountNodes(ctx, tq.driver, _spec) } -func (tq *TagQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := tq.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 (tq *TagQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: tag.Table, - Columns: tag.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: tag.FieldID, - }, - }, - From: tq.sql, - Unique: true, - } - if unique := tq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(tag.Table, tag.Columns, sqlgraph.NewFieldSpec(tag.FieldID, field.TypeInt)) + _spec.From = tq.sql + if unique := tq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if tq.path != nil { + _spec.Unique = true } - if fields := tq.fields; len(fields) > 0 { + if fields := tq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, tag.FieldID) for i := range fields { @@ -521,10 +518,10 @@ func (tq *TagQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := tq.limit; limit != nil { + if limit := tq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := tq.offset; offset != nil { + if offset := tq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := tq.order; len(ps) > 0 { @@ -540,7 +537,7 @@ func (tq *TagQuery) querySpec() *sqlgraph.QuerySpec { func (tq *TagQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(tq.driver.Dialect()) t1 := builder.Table(tag.Table) - columns := tq.fields + columns := tq.ctx.Fields if len(columns) == 0 { columns = tag.Columns } @@ -549,7 +546,7 @@ func (tq *TagQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = tq.sql selector.Select(selector.Columns(columns...)...) } - if tq.unique != nil && *tq.unique { + if tq.ctx.Unique != nil && *tq.ctx.Unique { selector.Distinct() } for _, p := range tq.predicates { @@ -558,12 +555,12 @@ func (tq *TagQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range tq.order { p(selector) } - if offset := tq.offset; offset != nil { + if offset := tq.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 := tq.limit; limit != nil { + if limit := tq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -572,7 +569,7 @@ func (tq *TagQuery) sqlQuery(ctx context.Context) *sql.Selector { // WithNamedSessions tells the query-builder to eager-load the nodes that are connected to the "sessions" // edge with the given name. The optional arguments are used to configure the query builder of the edge. func (tq *TagQuery) WithNamedSessions(name string, opts ...func(*SessionQuery)) *TagQuery { - query := &SessionQuery{config: tq.config} + query := (&SessionClient{config: tq.config}).Query() for _, opt := range opts { opt(query) } @@ -585,13 +582,8 @@ func (tq *TagQuery) WithNamedSessions(name string, opts ...func(*SessionQuery)) // TagGroupBy is the group-by builder for Tag entities. type TagGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *TagQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -600,58 +592,46 @@ func (tgb *TagGroupBy) Aggregate(fns ...AggregateFunc) *TagGroupBy { return tgb } -// 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 (tgb *TagGroupBy) Scan(ctx context.Context, v any) error { - query, err := tgb.path(ctx) - if err != nil { + ctx = setContextOp(ctx, tgb.build.ctx, "GroupBy") + if err := tgb.build.prepareQuery(ctx); err != nil { return err } - tgb.sql = query - return tgb.sqlScan(ctx, v) + return scanWithInterceptors[*TagQuery, *TagGroupBy](ctx, tgb.build, tgb, tgb.build.inters, v) } -func (tgb *TagGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range tgb.fields { - if !tag.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} +func (tgb *TagGroupBy) sqlScan(ctx context.Context, root *TagQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(tgb.fns)) + for _, fn := range tgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*tgb.flds)+len(tgb.fns)) + for _, f := range *tgb.flds { + columns = append(columns, selector.C(f)) } + columns = append(columns, aggregation...) + selector.Select(columns...) } - selector := tgb.sqlQuery() + selector.GroupBy(selector.Columns(*tgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := tgb.driver.Query(ctx, query, args, rows); err != nil { + if err := tgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (tgb *TagGroupBy) sqlQuery() *sql.Selector { - selector := tgb.sql.Select() - aggregation := make([]string, 0, len(tgb.fns)) - for _, fn := range tgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(tgb.fields)+len(tgb.fns)) - for _, f := range tgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(tgb.fields...)...) -} - // TagSelect is the builder for selecting fields of Tag entities. type TagSelect struct { *TagQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -662,26 +642,27 @@ func (ts *TagSelect) Aggregate(fns ...AggregateFunc) *TagSelect { // Scan applies the selector query and scans the result into the given value. func (ts *TagSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ts.ctx, "Select") if err := ts.prepareQuery(ctx); err != nil { return err } - ts.sql = ts.TagQuery.sqlQuery(ctx) - return ts.sqlScan(ctx, v) + return scanWithInterceptors[*TagQuery, *TagSelect](ctx, ts.TagQuery, ts, ts.inters, v) } -func (ts *TagSelect) sqlScan(ctx context.Context, v any) error { +func (ts *TagSelect) sqlScan(ctx context.Context, root *TagQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(ts.fns)) for _, fn := range ts.fns { - aggregation = append(aggregation, fn(ts.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*ts.selector.flds); { case n == 0 && len(aggregation) > 0: - ts.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - ts.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := ts.sql.Query() + query, args := selector.Query() if err := ts.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/tavern/ent/tag_update.go b/tavern/ent/tag_update.go index a877244f1..ba8f7fc20 100644 --- a/tavern/ent/tag_update.go +++ b/tavern/ent/tag_update.go @@ -83,40 +83,7 @@ func (tu *TagUpdate) RemoveSessions(s ...*Session) *TagUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TagUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(tu.hooks) == 0 { - if err = tu.check(); err != nil { - return 0, err - } - affected, err = tu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = tu.check(); err != nil { - return 0, err - } - tu.mutation = mutation - affected, err = tu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(tu.hooks) - 1; i >= 0; i-- { - if tu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = tu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, tu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, TagMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -157,16 +124,10 @@ func (tu *TagUpdate) check() error { } func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: tag.Table, - Columns: tag.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: tag.FieldID, - }, - }, + if err := tu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(tag.Table, tag.Columns, sqlgraph.NewFieldSpec(tag.FieldID, field.TypeInt)) if ps := tu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -242,6 +203,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + tu.mutation.done = true return n, nil } @@ -306,6 +268,12 @@ func (tuo *TagUpdateOne) RemoveSessions(s ...*Session) *TagUpdateOne { return tuo.RemoveSessionIDs(ids...) } +// Where appends a list predicates to the TagUpdate builder. +func (tuo *TagUpdateOne) Where(ps ...predicate.Tag) *TagUpdateOne { + tuo.mutation.Where(ps...) + return tuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (tuo *TagUpdateOne) Select(field string, fields ...string) *TagUpdateOne { @@ -315,46 +283,7 @@ func (tuo *TagUpdateOne) Select(field string, fields ...string) *TagUpdateOne { // Save executes the query and returns the updated Tag entity. func (tuo *TagUpdateOne) Save(ctx context.Context) (*Tag, error) { - var ( - err error - node *Tag - ) - if len(tuo.hooks) == 0 { - if err = tuo.check(); err != nil { - return nil, err - } - node, err = tuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TagMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = tuo.check(); err != nil { - return nil, err - } - tuo.mutation = mutation - node, err = tuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(tuo.hooks) - 1; i >= 0; i-- { - if tuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = tuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, tuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Tag) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from TagMutation", v) - } - node = nv - } - return node, err + return withHooks[*Tag, TagMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -395,16 +324,10 @@ func (tuo *TagUpdateOne) check() error { } func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: tag.Table, - Columns: tag.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: tag.FieldID, - }, - }, + if err := tuo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(tag.Table, tag.Columns, sqlgraph.NewFieldSpec(tag.FieldID, field.TypeInt)) id, ok := tuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Tag.id" for update`)} @@ -500,5 +423,6 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { } return nil, err } + tuo.mutation.done = true return _node, nil } diff --git a/tavern/ent/task.go b/tavern/ent/task.go index a28e46b6a..6878cb4c7 100644 --- a/tavern/ent/task.go +++ b/tavern/ent/task.go @@ -19,15 +19,15 @@ type Task struct { // ID of the ent. ID int `json:"id,omitempty"` // Timestamp of when this ent was created - CreatedAt time.Time `json:"createdAt,omitempty"` + CreatedAt time.Time `json:"created_at,omitempty"` // Timestamp of when this ent was last updated - LastModifiedAt time.Time `json:"lastModifiedAt,omitempty"` + LastModifiedAt time.Time `json:"last_modified_at,omitempty"` // Timestamp of when the task was claimed, null if not yet claimed - ClaimedAt time.Time `json:"claimedAt,omitempty"` + ClaimedAt time.Time `json:"claimed_at,omitempty"` // Timestamp of when execution of the task started, null if not yet started - ExecStartedAt time.Time `json:"execStartedAt,omitempty"` + ExecStartedAt time.Time `json:"exec_started_at,omitempty"` // Timestamp of when execution of the task finished, null if not yet finished - ExecFinishedAt time.Time `json:"execFinishedAt,omitempty"` + ExecFinishedAt time.Time `json:"exec_finished_at,omitempty"` // Output from executing the task Output string `json:"output,omitempty"` // Error, if any, produced while executing the Task @@ -116,31 +116,31 @@ func (t *Task) assignValues(columns []string, values []any) error { t.ID = int(value.Int64) case task.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field createdAt", values[i]) + return fmt.Errorf("unexpected type %T for field created_at", values[i]) } else if value.Valid { t.CreatedAt = value.Time } case task.FieldLastModifiedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field lastModifiedAt", values[i]) + return fmt.Errorf("unexpected type %T for field last_modified_at", values[i]) } else if value.Valid { t.LastModifiedAt = value.Time } case task.FieldClaimedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field claimedAt", values[i]) + return fmt.Errorf("unexpected type %T for field claimed_at", values[i]) } else if value.Valid { t.ClaimedAt = value.Time } case task.FieldExecStartedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field execStartedAt", values[i]) + return fmt.Errorf("unexpected type %T for field exec_started_at", values[i]) } else if value.Valid { t.ExecStartedAt = value.Time } case task.FieldExecFinishedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field execFinishedAt", values[i]) + return fmt.Errorf("unexpected type %T for field exec_finished_at", values[i]) } else if value.Valid { t.ExecFinishedAt = value.Time } @@ -177,19 +177,19 @@ func (t *Task) assignValues(columns []string, values []any) error { // QueryJob queries the "job" edge of the Task entity. func (t *Task) QueryJob() *JobQuery { - return (&TaskClient{config: t.config}).QueryJob(t) + return NewTaskClient(t.config).QueryJob(t) } // QuerySession queries the "session" edge of the Task entity. func (t *Task) QuerySession() *SessionQuery { - return (&TaskClient{config: t.config}).QuerySession(t) + return NewTaskClient(t.config).QuerySession(t) } // Update returns a builder for updating this Task. // Note that you need to call Task.Unwrap() before calling this method if this Task // was returned from a transaction, and the transaction was committed or rolled back. func (t *Task) Update() *TaskUpdateOne { - return (&TaskClient{config: t.config}).UpdateOne(t) + return NewTaskClient(t.config).UpdateOne(t) } // Unwrap unwraps the Task entity that was returned from a transaction after it was closed, @@ -208,19 +208,19 @@ func (t *Task) String() string { var builder strings.Builder builder.WriteString("Task(") builder.WriteString(fmt.Sprintf("id=%v, ", t.ID)) - builder.WriteString("createdAt=") + builder.WriteString("created_at=") builder.WriteString(t.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") - builder.WriteString("lastModifiedAt=") + builder.WriteString("last_modified_at=") builder.WriteString(t.LastModifiedAt.Format(time.ANSIC)) builder.WriteString(", ") - builder.WriteString("claimedAt=") + builder.WriteString("claimed_at=") builder.WriteString(t.ClaimedAt.Format(time.ANSIC)) builder.WriteString(", ") - builder.WriteString("execStartedAt=") + builder.WriteString("exec_started_at=") builder.WriteString(t.ExecStartedAt.Format(time.ANSIC)) builder.WriteString(", ") - builder.WriteString("execFinishedAt=") + builder.WriteString("exec_finished_at=") builder.WriteString(t.ExecFinishedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("output=") @@ -234,9 +234,3 @@ func (t *Task) String() string { // Tasks is a parsable slice of Task. type Tasks []*Task - -func (t Tasks) config(cfg config) { - for _i := range t { - t[_i].config = cfg - } -} diff --git a/tavern/ent/task/task.go b/tavern/ent/task/task.go index 1f6ba4a9b..f08009b8c 100644 --- a/tavern/ent/task/task.go +++ b/tavern/ent/task/task.go @@ -11,15 +11,15 @@ const ( Label = "task" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldCreatedAt holds the string denoting the createdat field in the database. + // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" - // FieldLastModifiedAt holds the string denoting the lastmodifiedat field in the database. + // FieldLastModifiedAt holds the string denoting the last_modified_at field in the database. FieldLastModifiedAt = "last_modified_at" - // FieldClaimedAt holds the string denoting the claimedat field in the database. + // FieldClaimedAt holds the string denoting the claimed_at field in the database. FieldClaimedAt = "claimed_at" - // FieldExecStartedAt holds the string denoting the execstartedat field in the database. + // FieldExecStartedAt holds the string denoting the exec_started_at field in the database. FieldExecStartedAt = "exec_started_at" - // FieldExecFinishedAt holds the string denoting the execfinishedat field in the database. + // FieldExecFinishedAt holds the string denoting the exec_finished_at field in the database. FieldExecFinishedAt = "exec_finished_at" // FieldOutput holds the string denoting the output field in the database. FieldOutput = "output" @@ -82,10 +82,10 @@ func ValidColumn(column string) bool { } var ( - // DefaultCreatedAt holds the default value on creation for the "createdAt" field. + // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time - // DefaultLastModifiedAt holds the default value on creation for the "lastModifiedAt" field. + // DefaultLastModifiedAt holds the default value on creation for the "last_modified_at" field. DefaultLastModifiedAt func() time.Time - // UpdateDefaultLastModifiedAt holds the default value on update for the "lastModifiedAt" field. + // UpdateDefaultLastModifiedAt holds the default value on update for the "last_modified_at" field. UpdateDefaultLastModifiedAt func() time.Time ) diff --git a/tavern/ent/task/where.go b/tavern/ent/task/where.go index 5ed022788..6f127e2c8 100644 --- a/tavern/ent/task/where.go +++ b/tavern/ent/task/where.go @@ -12,710 +12,462 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Task(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Task(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Task(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Task { - return predicate.Task(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.Task(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Task { - return predicate.Task(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.Task(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Task(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Task(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Task(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Task(sql.FieldLTE(FieldID, id)) } -// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Task(sql.FieldEQ(FieldCreatedAt, v)) } -// LastModifiedAt applies equality check predicate on the "lastModifiedAt" field. It's identical to LastModifiedAtEQ. +// LastModifiedAt applies equality check predicate on the "last_modified_at" field. It's identical to LastModifiedAtEQ. func LastModifiedAt(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Task(sql.FieldEQ(FieldLastModifiedAt, v)) } -// ClaimedAt applies equality check predicate on the "claimedAt" field. It's identical to ClaimedAtEQ. +// ClaimedAt applies equality check predicate on the "claimed_at" field. It's identical to ClaimedAtEQ. func ClaimedAt(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimedAt), v)) - }) + return predicate.Task(sql.FieldEQ(FieldClaimedAt, v)) } -// ExecStartedAt applies equality check predicate on the "execStartedAt" field. It's identical to ExecStartedAtEQ. +// ExecStartedAt applies equality check predicate on the "exec_started_at" field. It's identical to ExecStartedAtEQ. func ExecStartedAt(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExecStartedAt), v)) - }) + return predicate.Task(sql.FieldEQ(FieldExecStartedAt, v)) } -// ExecFinishedAt applies equality check predicate on the "execFinishedAt" field. It's identical to ExecFinishedAtEQ. +// ExecFinishedAt applies equality check predicate on the "exec_finished_at" field. It's identical to ExecFinishedAtEQ. func ExecFinishedAt(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExecFinishedAt), v)) - }) + return predicate.Task(sql.FieldEQ(FieldExecFinishedAt, v)) } // Output applies equality check predicate on the "output" field. It's identical to OutputEQ. func Output(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldEQ(FieldOutput, v)) } // Error applies equality check predicate on the "error" field. It's identical to ErrorEQ. func Error(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldEQ(FieldError, v)) } -// CreatedAtEQ applies the EQ predicate on the "createdAt" field. +// CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Task(sql.FieldEQ(FieldCreatedAt, v)) } -// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Task(sql.FieldNEQ(FieldCreatedAt, v)) } -// CreatedAtIn applies the In predicate on the "createdAt" field. +// CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.Task(sql.FieldIn(FieldCreatedAt, vs...)) } -// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.Task(sql.FieldNotIn(FieldCreatedAt, vs...)) } -// CreatedAtGT applies the GT predicate on the "createdAt" field. +// CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.Task(sql.FieldGT(FieldCreatedAt, v)) } -// CreatedAtGTE applies the GTE predicate on the "createdAt" field. +// CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Task(sql.FieldGTE(FieldCreatedAt, v)) } -// CreatedAtLT applies the LT predicate on the "createdAt" field. +// CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.Task(sql.FieldLT(FieldCreatedAt, v)) } -// CreatedAtLTE applies the LTE predicate on the "createdAt" field. +// CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Task(sql.FieldLTE(FieldCreatedAt, v)) } -// LastModifiedAtEQ applies the EQ predicate on the "lastModifiedAt" field. +// LastModifiedAtEQ applies the EQ predicate on the "last_modified_at" field. func LastModifiedAtEQ(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Task(sql.FieldEQ(FieldLastModifiedAt, v)) } -// LastModifiedAtNEQ applies the NEQ predicate on the "lastModifiedAt" field. +// LastModifiedAtNEQ applies the NEQ predicate on the "last_modified_at" field. func LastModifiedAtNEQ(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Task(sql.FieldNEQ(FieldLastModifiedAt, v)) } -// LastModifiedAtIn applies the In predicate on the "lastModifiedAt" field. +// LastModifiedAtIn applies the In predicate on the "last_modified_at" field. func LastModifiedAtIn(vs ...time.Time) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldLastModifiedAt), v...)) - }) + return predicate.Task(sql.FieldIn(FieldLastModifiedAt, vs...)) } -// LastModifiedAtNotIn applies the NotIn predicate on the "lastModifiedAt" field. +// LastModifiedAtNotIn applies the NotIn predicate on the "last_modified_at" field. func LastModifiedAtNotIn(vs ...time.Time) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldLastModifiedAt), v...)) - }) + return predicate.Task(sql.FieldNotIn(FieldLastModifiedAt, vs...)) } -// LastModifiedAtGT applies the GT predicate on the "lastModifiedAt" field. +// LastModifiedAtGT applies the GT predicate on the "last_modified_at" field. func LastModifiedAtGT(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Task(sql.FieldGT(FieldLastModifiedAt, v)) } -// LastModifiedAtGTE applies the GTE predicate on the "lastModifiedAt" field. +// LastModifiedAtGTE applies the GTE predicate on the "last_modified_at" field. func LastModifiedAtGTE(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Task(sql.FieldGTE(FieldLastModifiedAt, v)) } -// LastModifiedAtLT applies the LT predicate on the "lastModifiedAt" field. +// LastModifiedAtLT applies the LT predicate on the "last_modified_at" field. func LastModifiedAtLT(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Task(sql.FieldLT(FieldLastModifiedAt, v)) } -// LastModifiedAtLTE applies the LTE predicate on the "lastModifiedAt" field. +// LastModifiedAtLTE applies the LTE predicate on the "last_modified_at" field. func LastModifiedAtLTE(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Task(sql.FieldLTE(FieldLastModifiedAt, v)) } -// ClaimedAtEQ applies the EQ predicate on the "claimedAt" field. +// ClaimedAtEQ applies the EQ predicate on the "claimed_at" field. func ClaimedAtEQ(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimedAt), v)) - }) + return predicate.Task(sql.FieldEQ(FieldClaimedAt, v)) } -// ClaimedAtNEQ applies the NEQ predicate on the "claimedAt" field. +// ClaimedAtNEQ applies the NEQ predicate on the "claimed_at" field. func ClaimedAtNEQ(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimedAt), v)) - }) + return predicate.Task(sql.FieldNEQ(FieldClaimedAt, v)) } -// ClaimedAtIn applies the In predicate on the "claimedAt" field. +// ClaimedAtIn applies the In predicate on the "claimed_at" field. func ClaimedAtIn(vs ...time.Time) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimedAt), v...)) - }) + return predicate.Task(sql.FieldIn(FieldClaimedAt, vs...)) } -// ClaimedAtNotIn applies the NotIn predicate on the "claimedAt" field. +// ClaimedAtNotIn applies the NotIn predicate on the "claimed_at" field. func ClaimedAtNotIn(vs ...time.Time) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimedAt), v...)) - }) + return predicate.Task(sql.FieldNotIn(FieldClaimedAt, vs...)) } -// ClaimedAtGT applies the GT predicate on the "claimedAt" field. +// ClaimedAtGT applies the GT predicate on the "claimed_at" field. func ClaimedAtGT(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimedAt), v)) - }) + return predicate.Task(sql.FieldGT(FieldClaimedAt, v)) } -// ClaimedAtGTE applies the GTE predicate on the "claimedAt" field. +// ClaimedAtGTE applies the GTE predicate on the "claimed_at" field. func ClaimedAtGTE(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimedAt), v)) - }) + return predicate.Task(sql.FieldGTE(FieldClaimedAt, v)) } -// ClaimedAtLT applies the LT predicate on the "claimedAt" field. +// ClaimedAtLT applies the LT predicate on the "claimed_at" field. func ClaimedAtLT(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimedAt), v)) - }) + return predicate.Task(sql.FieldLT(FieldClaimedAt, v)) } -// ClaimedAtLTE applies the LTE predicate on the "claimedAt" field. +// ClaimedAtLTE applies the LTE predicate on the "claimed_at" field. func ClaimedAtLTE(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimedAt), v)) - }) + return predicate.Task(sql.FieldLTE(FieldClaimedAt, v)) } -// ClaimedAtIsNil applies the IsNil predicate on the "claimedAt" field. +// ClaimedAtIsNil applies the IsNil predicate on the "claimed_at" field. func ClaimedAtIsNil() predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldClaimedAt))) - }) + return predicate.Task(sql.FieldIsNull(FieldClaimedAt)) } -// ClaimedAtNotNil applies the NotNil predicate on the "claimedAt" field. +// ClaimedAtNotNil applies the NotNil predicate on the "claimed_at" field. func ClaimedAtNotNil() predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldClaimedAt))) - }) + return predicate.Task(sql.FieldNotNull(FieldClaimedAt)) } -// ExecStartedAtEQ applies the EQ predicate on the "execStartedAt" field. +// ExecStartedAtEQ applies the EQ predicate on the "exec_started_at" field. func ExecStartedAtEQ(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExecStartedAt), v)) - }) + return predicate.Task(sql.FieldEQ(FieldExecStartedAt, v)) } -// ExecStartedAtNEQ applies the NEQ predicate on the "execStartedAt" field. +// ExecStartedAtNEQ applies the NEQ predicate on the "exec_started_at" field. func ExecStartedAtNEQ(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldExecStartedAt), v)) - }) + return predicate.Task(sql.FieldNEQ(FieldExecStartedAt, v)) } -// ExecStartedAtIn applies the In predicate on the "execStartedAt" field. +// ExecStartedAtIn applies the In predicate on the "exec_started_at" field. func ExecStartedAtIn(vs ...time.Time) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldExecStartedAt), v...)) - }) + return predicate.Task(sql.FieldIn(FieldExecStartedAt, vs...)) } -// ExecStartedAtNotIn applies the NotIn predicate on the "execStartedAt" field. +// ExecStartedAtNotIn applies the NotIn predicate on the "exec_started_at" field. func ExecStartedAtNotIn(vs ...time.Time) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldExecStartedAt), v...)) - }) + return predicate.Task(sql.FieldNotIn(FieldExecStartedAt, vs...)) } -// ExecStartedAtGT applies the GT predicate on the "execStartedAt" field. +// ExecStartedAtGT applies the GT predicate on the "exec_started_at" field. func ExecStartedAtGT(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldExecStartedAt), v)) - }) + return predicate.Task(sql.FieldGT(FieldExecStartedAt, v)) } -// ExecStartedAtGTE applies the GTE predicate on the "execStartedAt" field. +// ExecStartedAtGTE applies the GTE predicate on the "exec_started_at" field. func ExecStartedAtGTE(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldExecStartedAt), v)) - }) + return predicate.Task(sql.FieldGTE(FieldExecStartedAt, v)) } -// ExecStartedAtLT applies the LT predicate on the "execStartedAt" field. +// ExecStartedAtLT applies the LT predicate on the "exec_started_at" field. func ExecStartedAtLT(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldExecStartedAt), v)) - }) + return predicate.Task(sql.FieldLT(FieldExecStartedAt, v)) } -// ExecStartedAtLTE applies the LTE predicate on the "execStartedAt" field. +// ExecStartedAtLTE applies the LTE predicate on the "exec_started_at" field. func ExecStartedAtLTE(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldExecStartedAt), v)) - }) + return predicate.Task(sql.FieldLTE(FieldExecStartedAt, v)) } -// ExecStartedAtIsNil applies the IsNil predicate on the "execStartedAt" field. +// ExecStartedAtIsNil applies the IsNil predicate on the "exec_started_at" field. func ExecStartedAtIsNil() predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldExecStartedAt))) - }) + return predicate.Task(sql.FieldIsNull(FieldExecStartedAt)) } -// ExecStartedAtNotNil applies the NotNil predicate on the "execStartedAt" field. +// ExecStartedAtNotNil applies the NotNil predicate on the "exec_started_at" field. func ExecStartedAtNotNil() predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldExecStartedAt))) - }) + return predicate.Task(sql.FieldNotNull(FieldExecStartedAt)) } -// ExecFinishedAtEQ applies the EQ predicate on the "execFinishedAt" field. +// ExecFinishedAtEQ applies the EQ predicate on the "exec_finished_at" field. func ExecFinishedAtEQ(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExecFinishedAt), v)) - }) + return predicate.Task(sql.FieldEQ(FieldExecFinishedAt, v)) } -// ExecFinishedAtNEQ applies the NEQ predicate on the "execFinishedAt" field. +// ExecFinishedAtNEQ applies the NEQ predicate on the "exec_finished_at" field. func ExecFinishedAtNEQ(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldExecFinishedAt), v)) - }) + return predicate.Task(sql.FieldNEQ(FieldExecFinishedAt, v)) } -// ExecFinishedAtIn applies the In predicate on the "execFinishedAt" field. +// ExecFinishedAtIn applies the In predicate on the "exec_finished_at" field. func ExecFinishedAtIn(vs ...time.Time) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldExecFinishedAt), v...)) - }) + return predicate.Task(sql.FieldIn(FieldExecFinishedAt, vs...)) } -// ExecFinishedAtNotIn applies the NotIn predicate on the "execFinishedAt" field. +// ExecFinishedAtNotIn applies the NotIn predicate on the "exec_finished_at" field. func ExecFinishedAtNotIn(vs ...time.Time) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldExecFinishedAt), v...)) - }) + return predicate.Task(sql.FieldNotIn(FieldExecFinishedAt, vs...)) } -// ExecFinishedAtGT applies the GT predicate on the "execFinishedAt" field. +// ExecFinishedAtGT applies the GT predicate on the "exec_finished_at" field. func ExecFinishedAtGT(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldExecFinishedAt), v)) - }) + return predicate.Task(sql.FieldGT(FieldExecFinishedAt, v)) } -// ExecFinishedAtGTE applies the GTE predicate on the "execFinishedAt" field. +// ExecFinishedAtGTE applies the GTE predicate on the "exec_finished_at" field. func ExecFinishedAtGTE(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldExecFinishedAt), v)) - }) + return predicate.Task(sql.FieldGTE(FieldExecFinishedAt, v)) } -// ExecFinishedAtLT applies the LT predicate on the "execFinishedAt" field. +// ExecFinishedAtLT applies the LT predicate on the "exec_finished_at" field. func ExecFinishedAtLT(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldExecFinishedAt), v)) - }) + return predicate.Task(sql.FieldLT(FieldExecFinishedAt, v)) } -// ExecFinishedAtLTE applies the LTE predicate on the "execFinishedAt" field. +// ExecFinishedAtLTE applies the LTE predicate on the "exec_finished_at" field. func ExecFinishedAtLTE(v time.Time) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldExecFinishedAt), v)) - }) + return predicate.Task(sql.FieldLTE(FieldExecFinishedAt, v)) } -// ExecFinishedAtIsNil applies the IsNil predicate on the "execFinishedAt" field. +// ExecFinishedAtIsNil applies the IsNil predicate on the "exec_finished_at" field. func ExecFinishedAtIsNil() predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldExecFinishedAt))) - }) + return predicate.Task(sql.FieldIsNull(FieldExecFinishedAt)) } -// ExecFinishedAtNotNil applies the NotNil predicate on the "execFinishedAt" field. +// ExecFinishedAtNotNil applies the NotNil predicate on the "exec_finished_at" field. func ExecFinishedAtNotNil() predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldExecFinishedAt))) - }) + return predicate.Task(sql.FieldNotNull(FieldExecFinishedAt)) } // OutputEQ applies the EQ predicate on the "output" field. func OutputEQ(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldEQ(FieldOutput, v)) } // OutputNEQ applies the NEQ predicate on the "output" field. func OutputNEQ(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldNEQ(FieldOutput, v)) } // OutputIn applies the In predicate on the "output" field. func OutputIn(vs ...string) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldOutput), v...)) - }) + return predicate.Task(sql.FieldIn(FieldOutput, vs...)) } // OutputNotIn applies the NotIn predicate on the "output" field. func OutputNotIn(vs ...string) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldOutput), v...)) - }) + return predicate.Task(sql.FieldNotIn(FieldOutput, vs...)) } // OutputGT applies the GT predicate on the "output" field. func OutputGT(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldGT(FieldOutput, v)) } // OutputGTE applies the GTE predicate on the "output" field. func OutputGTE(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldGTE(FieldOutput, v)) } // OutputLT applies the LT predicate on the "output" field. func OutputLT(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldLT(FieldOutput, v)) } // OutputLTE applies the LTE predicate on the "output" field. func OutputLTE(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldLTE(FieldOutput, v)) } // OutputContains applies the Contains predicate on the "output" field. func OutputContains(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldContains(FieldOutput, v)) } // OutputHasPrefix applies the HasPrefix predicate on the "output" field. func OutputHasPrefix(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldHasPrefix(FieldOutput, v)) } // OutputHasSuffix applies the HasSuffix predicate on the "output" field. func OutputHasSuffix(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldHasSuffix(FieldOutput, v)) } // OutputIsNil applies the IsNil predicate on the "output" field. func OutputIsNil() predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldOutput))) - }) + return predicate.Task(sql.FieldIsNull(FieldOutput)) } // OutputNotNil applies the NotNil predicate on the "output" field. func OutputNotNil() predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldOutput))) - }) + return predicate.Task(sql.FieldNotNull(FieldOutput)) } // OutputEqualFold applies the EqualFold predicate on the "output" field. func OutputEqualFold(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldEqualFold(FieldOutput, v)) } // OutputContainsFold applies the ContainsFold predicate on the "output" field. func OutputContainsFold(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldOutput), v)) - }) + return predicate.Task(sql.FieldContainsFold(FieldOutput, v)) } // ErrorEQ applies the EQ predicate on the "error" field. func ErrorEQ(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldEQ(FieldError, v)) } // ErrorNEQ applies the NEQ predicate on the "error" field. func ErrorNEQ(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldNEQ(FieldError, v)) } // ErrorIn applies the In predicate on the "error" field. func ErrorIn(vs ...string) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldError), v...)) - }) + return predicate.Task(sql.FieldIn(FieldError, vs...)) } // ErrorNotIn applies the NotIn predicate on the "error" field. func ErrorNotIn(vs ...string) predicate.Task { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldError), v...)) - }) + return predicate.Task(sql.FieldNotIn(FieldError, vs...)) } // ErrorGT applies the GT predicate on the "error" field. func ErrorGT(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldGT(FieldError, v)) } // ErrorGTE applies the GTE predicate on the "error" field. func ErrorGTE(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldGTE(FieldError, v)) } // ErrorLT applies the LT predicate on the "error" field. func ErrorLT(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldLT(FieldError, v)) } // ErrorLTE applies the LTE predicate on the "error" field. func ErrorLTE(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldLTE(FieldError, v)) } // ErrorContains applies the Contains predicate on the "error" field. func ErrorContains(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldContains(FieldError, v)) } // ErrorHasPrefix applies the HasPrefix predicate on the "error" field. func ErrorHasPrefix(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldHasPrefix(FieldError, v)) } // ErrorHasSuffix applies the HasSuffix predicate on the "error" field. func ErrorHasSuffix(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldHasSuffix(FieldError, v)) } // ErrorIsNil applies the IsNil predicate on the "error" field. func ErrorIsNil() predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldError))) - }) + return predicate.Task(sql.FieldIsNull(FieldError)) } // ErrorNotNil applies the NotNil predicate on the "error" field. func ErrorNotNil() predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldError))) - }) + return predicate.Task(sql.FieldNotNull(FieldError)) } // ErrorEqualFold applies the EqualFold predicate on the "error" field. func ErrorEqualFold(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldEqualFold(FieldError, v)) } // ErrorContainsFold applies the ContainsFold predicate on the "error" field. func ErrorContainsFold(v string) predicate.Task { - return predicate.Task(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldError), v)) - }) + return predicate.Task(sql.FieldContainsFold(FieldError, v)) } // HasJob applies the HasEdge predicate on the "job" edge. @@ -723,7 +475,6 @@ func HasJob() predicate.Task { return predicate.Task(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(JobTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, JobTable, JobColumn), ) sqlgraph.HasNeighbors(s, step) @@ -751,7 +502,6 @@ func HasSession() predicate.Task { return predicate.Task(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(SessionTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, false, SessionTable, SessionColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/tavern/ent/task_create.go b/tavern/ent/task_create.go index f1d33e031..62dbb6b41 100644 --- a/tavern/ent/task_create.go +++ b/tavern/ent/task_create.go @@ -22,13 +22,13 @@ type TaskCreate struct { hooks []Hook } -// SetCreatedAt sets the "createdAt" field. +// SetCreatedAt sets the "created_at" field. func (tc *TaskCreate) SetCreatedAt(t time.Time) *TaskCreate { tc.mutation.SetCreatedAt(t) return tc } -// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (tc *TaskCreate) SetNillableCreatedAt(t *time.Time) *TaskCreate { if t != nil { tc.SetCreatedAt(*t) @@ -36,13 +36,13 @@ func (tc *TaskCreate) SetNillableCreatedAt(t *time.Time) *TaskCreate { return tc } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (tc *TaskCreate) SetLastModifiedAt(t time.Time) *TaskCreate { tc.mutation.SetLastModifiedAt(t) return tc } -// SetNillableLastModifiedAt sets the "lastModifiedAt" field if the given value is not nil. +// SetNillableLastModifiedAt sets the "last_modified_at" field if the given value is not nil. func (tc *TaskCreate) SetNillableLastModifiedAt(t *time.Time) *TaskCreate { if t != nil { tc.SetLastModifiedAt(*t) @@ -50,13 +50,13 @@ func (tc *TaskCreate) SetNillableLastModifiedAt(t *time.Time) *TaskCreate { return tc } -// SetClaimedAt sets the "claimedAt" field. +// SetClaimedAt sets the "claimed_at" field. func (tc *TaskCreate) SetClaimedAt(t time.Time) *TaskCreate { tc.mutation.SetClaimedAt(t) return tc } -// SetNillableClaimedAt sets the "claimedAt" field if the given value is not nil. +// SetNillableClaimedAt sets the "claimed_at" field if the given value is not nil. func (tc *TaskCreate) SetNillableClaimedAt(t *time.Time) *TaskCreate { if t != nil { tc.SetClaimedAt(*t) @@ -64,13 +64,13 @@ func (tc *TaskCreate) SetNillableClaimedAt(t *time.Time) *TaskCreate { return tc } -// SetExecStartedAt sets the "execStartedAt" field. +// SetExecStartedAt sets the "exec_started_at" field. func (tc *TaskCreate) SetExecStartedAt(t time.Time) *TaskCreate { tc.mutation.SetExecStartedAt(t) return tc } -// SetNillableExecStartedAt sets the "execStartedAt" field if the given value is not nil. +// SetNillableExecStartedAt sets the "exec_started_at" field if the given value is not nil. func (tc *TaskCreate) SetNillableExecStartedAt(t *time.Time) *TaskCreate { if t != nil { tc.SetExecStartedAt(*t) @@ -78,13 +78,13 @@ func (tc *TaskCreate) SetNillableExecStartedAt(t *time.Time) *TaskCreate { return tc } -// SetExecFinishedAt sets the "execFinishedAt" field. +// SetExecFinishedAt sets the "exec_finished_at" field. func (tc *TaskCreate) SetExecFinishedAt(t time.Time) *TaskCreate { tc.mutation.SetExecFinishedAt(t) return tc } -// SetNillableExecFinishedAt sets the "execFinishedAt" field if the given value is not nil. +// SetNillableExecFinishedAt sets the "exec_finished_at" field if the given value is not nil. func (tc *TaskCreate) SetNillableExecFinishedAt(t *time.Time) *TaskCreate { if t != nil { tc.SetExecFinishedAt(*t) @@ -149,50 +149,8 @@ func (tc *TaskCreate) Mutation() *TaskMutation { // Save creates the Task in the database. func (tc *TaskCreate) Save(ctx context.Context) (*Task, error) { - var ( - err error - node *Task - ) tc.defaults() - if len(tc.hooks) == 0 { - if err = tc.check(); err != nil { - return nil, err - } - node, err = tc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TaskMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = tc.check(); err != nil { - return nil, err - } - tc.mutation = mutation - if node, err = tc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(tc.hooks) - 1; i >= 0; i-- { - if tc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = tc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, tc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Task) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from TaskMutation", v) - } - node = nv - } - return node, err + return withHooks[*Task, TaskMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -232,10 +190,10 @@ func (tc *TaskCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (tc *TaskCreate) check() error { if _, ok := tc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "Task.createdAt"`)} + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Task.created_at"`)} } if _, ok := tc.mutation.LastModifiedAt(); !ok { - return &ValidationError{Name: "lastModifiedAt", err: errors.New(`ent: missing required field "Task.lastModifiedAt"`)} + return &ValidationError{Name: "last_modified_at", err: errors.New(`ent: missing required field "Task.last_modified_at"`)} } if _, ok := tc.mutation.JobID(); !ok { return &ValidationError{Name: "job", err: errors.New(`ent: missing required edge "Task.job"`)} @@ -247,6 +205,9 @@ func (tc *TaskCreate) check() error { } func (tc *TaskCreate) sqlSave(ctx context.Context) (*Task, error) { + if err := tc.check(); err != nil { + return nil, err + } _node, _spec := tc.createSpec() if err := sqlgraph.CreateNode(ctx, tc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -256,19 +217,15 @@ func (tc *TaskCreate) sqlSave(ctx context.Context) (*Task, error) { } id := _spec.ID.Value.(int64) _node.ID = int(id) + tc.mutation.id = &_node.ID + tc.mutation.done = true return _node, nil } func (tc *TaskCreate) createSpec() (*Task, *sqlgraph.CreateSpec) { var ( _node = &Task{config: tc.config} - _spec = &sqlgraph.CreateSpec{ - Table: task.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: task.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(task.Table, sqlgraph.NewFieldSpec(task.FieldID, field.TypeInt)) ) if value, ok := tc.mutation.CreatedAt(); ok { _spec.SetField(task.FieldCreatedAt, field.TypeTime, value) diff --git a/tavern/ent/task_delete.go b/tavern/ent/task_delete.go index 5e7e97034..861528977 100644 --- a/tavern/ent/task_delete.go +++ b/tavern/ent/task_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (td *TaskDelete) Where(ps ...predicate.Task) *TaskDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TaskDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(td.hooks) == 0 { - affected, err = td.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TaskMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - td.mutation = mutation - affected, err = td.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(td.hooks) - 1; i >= 0; i-- { - if td.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = td.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, td.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, TaskMutation](ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (td *TaskDelete) ExecX(ctx context.Context) int { } func (td *TaskDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: task.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: task.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(task.Table, sqlgraph.NewFieldSpec(task.FieldID, field.TypeInt)) if ps := td.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (td *TaskDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + td.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type TaskDeleteOne struct { td *TaskDelete } +// Where appends a list predicates to the TaskDelete builder. +func (tdo *TaskDeleteOne) Where(ps ...predicate.Task) *TaskDeleteOne { + tdo.td.mutation.Where(ps...) + return tdo +} + // Exec executes the deletion query. func (tdo *TaskDeleteOne) Exec(ctx context.Context) error { n, err := tdo.td.Exec(ctx) @@ -111,5 +82,7 @@ func (tdo *TaskDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (tdo *TaskDeleteOne) ExecX(ctx context.Context) { - tdo.td.ExecX(ctx) + if err := tdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/tavern/ent/task_query.go b/tavern/ent/task_query.go index a4b54c668..a2a8ce8ac 100644 --- a/tavern/ent/task_query.go +++ b/tavern/ent/task_query.go @@ -19,11 +19,9 @@ import ( // TaskQuery is the builder for querying Task entities. type TaskQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.Task withJob *JobQuery withSession *SessionQuery @@ -41,26 +39,26 @@ func (tq *TaskQuery) Where(ps ...predicate.Task) *TaskQuery { return tq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (tq *TaskQuery) Limit(limit int) *TaskQuery { - tq.limit = &limit + tq.ctx.Limit = &limit return tq } -// Offset adds an offset step to the query. +// Offset to start from. func (tq *TaskQuery) Offset(offset int) *TaskQuery { - tq.offset = &offset + tq.ctx.Offset = &offset return tq } // 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 (tq *TaskQuery) Unique(unique bool) *TaskQuery { - tq.unique = &unique + tq.ctx.Unique = &unique return tq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (tq *TaskQuery) Order(o ...OrderFunc) *TaskQuery { tq.order = append(tq.order, o...) return tq @@ -68,7 +66,7 @@ func (tq *TaskQuery) Order(o ...OrderFunc) *TaskQuery { // QueryJob chains the current query on the "job" edge. func (tq *TaskQuery) QueryJob() *JobQuery { - query := &JobQuery{config: tq.config} + query := (&JobClient{config: tq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := tq.prepareQuery(ctx); err != nil { return nil, err @@ -90,7 +88,7 @@ func (tq *TaskQuery) QueryJob() *JobQuery { // QuerySession chains the current query on the "session" edge. func (tq *TaskQuery) QuerySession() *SessionQuery { - query := &SessionQuery{config: tq.config} + query := (&SessionClient{config: tq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := tq.prepareQuery(ctx); err != nil { return nil, err @@ -113,7 +111,7 @@ func (tq *TaskQuery) QuerySession() *SessionQuery { // First returns the first Task entity from the query. // Returns a *NotFoundError when no Task was found. func (tq *TaskQuery) First(ctx context.Context) (*Task, error) { - nodes, err := tq.Limit(1).All(ctx) + nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, "First")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (tq *TaskQuery) FirstX(ctx context.Context) *Task { // Returns a *NotFoundError when no Task ID was found. func (tq *TaskQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = tq.Limit(1).IDs(ctx); err != nil { + if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -159,7 +157,7 @@ func (tq *TaskQuery) FirstIDX(ctx context.Context) int { // Returns a *NotSingularError when more than one Task entity is found. // Returns a *NotFoundError when no Task entities are found. func (tq *TaskQuery) Only(ctx context.Context) (*Task, error) { - nodes, err := tq.Limit(2).All(ctx) + nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, "Only")) if err != nil { return nil, err } @@ -187,7 +185,7 @@ func (tq *TaskQuery) OnlyX(ctx context.Context) *Task { // Returns a *NotFoundError when no entities are found. func (tq *TaskQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = tq.Limit(2).IDs(ctx); err != nil { + if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -212,10 +210,12 @@ func (tq *TaskQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of Tasks. func (tq *TaskQuery) All(ctx context.Context) ([]*Task, error) { + ctx = setContextOp(ctx, tq.ctx, "All") if err := tq.prepareQuery(ctx); err != nil { return nil, err } - return tq.sqlAll(ctx) + qr := querierAll[[]*Task, *TaskQuery]() + return withInterceptors[[]*Task](ctx, tq, qr, tq.inters) } // AllX is like All, but panics if an error occurs. @@ -228,9 +228,12 @@ func (tq *TaskQuery) AllX(ctx context.Context) []*Task { } // IDs executes the query and returns a list of Task IDs. -func (tq *TaskQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := tq.Select(task.FieldID).Scan(ctx, &ids); err != nil { +func (tq *TaskQuery) IDs(ctx context.Context) (ids []int, err error) { + if tq.ctx.Unique == nil && tq.path != nil { + tq.Unique(true) + } + ctx = setContextOp(ctx, tq.ctx, "IDs") + if err = tq.Select(task.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -247,10 +250,11 @@ func (tq *TaskQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (tq *TaskQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, tq.ctx, "Count") if err := tq.prepareQuery(ctx); err != nil { return 0, err } - return tq.sqlCount(ctx) + return withInterceptors[int](ctx, tq, querierCount[*TaskQuery](), tq.inters) } // CountX is like Count, but panics if an error occurs. @@ -264,10 +268,15 @@ func (tq *TaskQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (tq *TaskQuery) Exist(ctx context.Context) (bool, error) { - if err := tq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, tq.ctx, "Exist") + switch _, err := tq.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 tq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -287,23 +296,22 @@ func (tq *TaskQuery) Clone() *TaskQuery { } return &TaskQuery{ config: tq.config, - limit: tq.limit, - offset: tq.offset, + ctx: tq.ctx.Clone(), order: append([]OrderFunc{}, tq.order...), + inters: append([]Interceptor{}, tq.inters...), predicates: append([]predicate.Task{}, tq.predicates...), withJob: tq.withJob.Clone(), withSession: tq.withSession.Clone(), // clone intermediate query. - sql: tq.sql.Clone(), - path: tq.path, - unique: tq.unique, + sql: tq.sql.Clone(), + path: tq.path, } } // WithJob tells the query-builder to eager-load the nodes that are connected to // the "job" edge. The optional arguments are used to configure the query builder of the edge. func (tq *TaskQuery) WithJob(opts ...func(*JobQuery)) *TaskQuery { - query := &JobQuery{config: tq.config} + query := (&JobClient{config: tq.config}).Query() for _, opt := range opts { opt(query) } @@ -314,7 +322,7 @@ func (tq *TaskQuery) WithJob(opts ...func(*JobQuery)) *TaskQuery { // WithSession tells the query-builder to eager-load the nodes that are connected to // the "session" edge. The optional arguments are used to configure the query builder of the edge. func (tq *TaskQuery) WithSession(opts ...func(*SessionQuery)) *TaskQuery { - query := &SessionQuery{config: tq.config} + query := (&SessionClient{config: tq.config}).Query() for _, opt := range opts { opt(query) } @@ -328,7 +336,7 @@ func (tq *TaskQuery) WithSession(opts ...func(*SessionQuery)) *TaskQuery { // Example: // // var v []struct { -// CreatedAt time.Time `json:"createdAt,omitempty"` +// CreatedAt time.Time `json:"created_at,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -337,16 +345,11 @@ func (tq *TaskQuery) WithSession(opts ...func(*SessionQuery)) *TaskQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (tq *TaskQuery) GroupBy(field string, fields ...string) *TaskGroupBy { - grbuild := &TaskGroupBy{config: tq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := tq.prepareQuery(ctx); err != nil { - return nil, err - } - return tq.sqlQuery(ctx), nil - } + tq.ctx.Fields = append([]string{field}, fields...) + grbuild := &TaskGroupBy{build: tq} + grbuild.flds = &tq.ctx.Fields grbuild.label = task.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -356,18 +359,18 @@ func (tq *TaskQuery) GroupBy(field string, fields ...string) *TaskGroupBy { // Example: // // var v []struct { -// CreatedAt time.Time `json:"createdAt,omitempty"` +// CreatedAt time.Time `json:"created_at,omitempty"` // } // // client.Task.Query(). // Select(task.FieldCreatedAt). // Scan(ctx, &v) func (tq *TaskQuery) Select(fields ...string) *TaskSelect { - tq.fields = append(tq.fields, fields...) - selbuild := &TaskSelect{TaskQuery: tq} - selbuild.label = task.Label - selbuild.flds, selbuild.scan = &tq.fields, selbuild.Scan - return selbuild + tq.ctx.Fields = append(tq.ctx.Fields, fields...) + sbuild := &TaskSelect{TaskQuery: tq} + sbuild.label = task.Label + sbuild.flds, sbuild.scan = &tq.ctx.Fields, sbuild.Scan + return sbuild } // Aggregate returns a TaskSelect configured with the given aggregations. @@ -376,7 +379,17 @@ func (tq *TaskQuery) Aggregate(fns ...AggregateFunc) *TaskSelect { } func (tq *TaskQuery) prepareQuery(ctx context.Context) error { - for _, f := range tq.fields { + for _, inter := range tq.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, tq); err != nil { + return err + } + } + } + for _, f := range tq.ctx.Fields { if !task.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -461,6 +474,9 @@ func (tq *TaskQuery) loadJob(ctx context.Context, query *JobQuery, nodes []*Task } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(job.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -490,6 +506,9 @@ func (tq *TaskQuery) loadSession(ctx context.Context, query *SessionQuery, nodes } nodeids[fk] = append(nodeids[fk], nodes[i]) } + if len(ids) == 0 { + return nil + } query.Where(session.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { @@ -512,41 +531,22 @@ func (tq *TaskQuery) sqlCount(ctx context.Context) (int, error) { if len(tq.modifiers) > 0 { _spec.Modifiers = tq.modifiers } - _spec.Node.Columns = tq.fields - if len(tq.fields) > 0 { - _spec.Unique = tq.unique != nil && *tq.unique + _spec.Node.Columns = tq.ctx.Fields + if len(tq.ctx.Fields) > 0 { + _spec.Unique = tq.ctx.Unique != nil && *tq.ctx.Unique } return sqlgraph.CountNodes(ctx, tq.driver, _spec) } -func (tq *TaskQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := tq.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 (tq *TaskQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: task.Table, - Columns: task.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: task.FieldID, - }, - }, - From: tq.sql, - Unique: true, - } - if unique := tq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(task.Table, task.Columns, sqlgraph.NewFieldSpec(task.FieldID, field.TypeInt)) + _spec.From = tq.sql + if unique := tq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if tq.path != nil { + _spec.Unique = true } - if fields := tq.fields; len(fields) > 0 { + if fields := tq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, task.FieldID) for i := range fields { @@ -562,10 +562,10 @@ func (tq *TaskQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := tq.limit; limit != nil { + if limit := tq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := tq.offset; offset != nil { + if offset := tq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := tq.order; len(ps) > 0 { @@ -581,7 +581,7 @@ func (tq *TaskQuery) querySpec() *sqlgraph.QuerySpec { func (tq *TaskQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(tq.driver.Dialect()) t1 := builder.Table(task.Table) - columns := tq.fields + columns := tq.ctx.Fields if len(columns) == 0 { columns = task.Columns } @@ -590,7 +590,7 @@ func (tq *TaskQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = tq.sql selector.Select(selector.Columns(columns...)...) } - if tq.unique != nil && *tq.unique { + if tq.ctx.Unique != nil && *tq.ctx.Unique { selector.Distinct() } for _, p := range tq.predicates { @@ -599,12 +599,12 @@ func (tq *TaskQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range tq.order { p(selector) } - if offset := tq.offset; offset != nil { + if offset := tq.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 := tq.limit; limit != nil { + if limit := tq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -612,13 +612,8 @@ func (tq *TaskQuery) sqlQuery(ctx context.Context) *sql.Selector { // TaskGroupBy is the group-by builder for Task entities. type TaskGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *TaskQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -627,58 +622,46 @@ func (tgb *TaskGroupBy) Aggregate(fns ...AggregateFunc) *TaskGroupBy { return tgb } -// 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 (tgb *TaskGroupBy) Scan(ctx context.Context, v any) error { - query, err := tgb.path(ctx) - if err != nil { + ctx = setContextOp(ctx, tgb.build.ctx, "GroupBy") + if err := tgb.build.prepareQuery(ctx); err != nil { return err } - tgb.sql = query - return tgb.sqlScan(ctx, v) + return scanWithInterceptors[*TaskQuery, *TaskGroupBy](ctx, tgb.build, tgb, tgb.build.inters, v) } -func (tgb *TaskGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range tgb.fields { - if !task.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} +func (tgb *TaskGroupBy) sqlScan(ctx context.Context, root *TaskQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(tgb.fns)) + for _, fn := range tgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*tgb.flds)+len(tgb.fns)) + for _, f := range *tgb.flds { + columns = append(columns, selector.C(f)) } + columns = append(columns, aggregation...) + selector.Select(columns...) } - selector := tgb.sqlQuery() + selector.GroupBy(selector.Columns(*tgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := tgb.driver.Query(ctx, query, args, rows); err != nil { + if err := tgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (tgb *TaskGroupBy) sqlQuery() *sql.Selector { - selector := tgb.sql.Select() - aggregation := make([]string, 0, len(tgb.fns)) - for _, fn := range tgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(tgb.fields)+len(tgb.fns)) - for _, f := range tgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(tgb.fields...)...) -} - // TaskSelect is the builder for selecting fields of Task entities. type TaskSelect struct { *TaskQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -689,26 +672,27 @@ func (ts *TaskSelect) Aggregate(fns ...AggregateFunc) *TaskSelect { // Scan applies the selector query and scans the result into the given value. func (ts *TaskSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ts.ctx, "Select") if err := ts.prepareQuery(ctx); err != nil { return err } - ts.sql = ts.TaskQuery.sqlQuery(ctx) - return ts.sqlScan(ctx, v) + return scanWithInterceptors[*TaskQuery, *TaskSelect](ctx, ts.TaskQuery, ts, ts.inters, v) } -func (ts *TaskSelect) sqlScan(ctx context.Context, v any) error { +func (ts *TaskSelect) sqlScan(ctx context.Context, root *TaskQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(ts.fns)) for _, fn := range ts.fns { - aggregation = append(aggregation, fn(ts.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*ts.selector.flds); { case n == 0 && len(aggregation) > 0: - ts.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - ts.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := ts.sql.Query() + query, args := selector.Query() if err := ts.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/tavern/ent/task_update.go b/tavern/ent/task_update.go index 2ff281039..643652455 100644 --- a/tavern/ent/task_update.go +++ b/tavern/ent/task_update.go @@ -30,19 +30,19 @@ func (tu *TaskUpdate) Where(ps ...predicate.Task) *TaskUpdate { return tu } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (tu *TaskUpdate) SetLastModifiedAt(t time.Time) *TaskUpdate { tu.mutation.SetLastModifiedAt(t) return tu } -// SetClaimedAt sets the "claimedAt" field. +// SetClaimedAt sets the "claimed_at" field. func (tu *TaskUpdate) SetClaimedAt(t time.Time) *TaskUpdate { tu.mutation.SetClaimedAt(t) return tu } -// SetNillableClaimedAt sets the "claimedAt" field if the given value is not nil. +// SetNillableClaimedAt sets the "claimed_at" field if the given value is not nil. func (tu *TaskUpdate) SetNillableClaimedAt(t *time.Time) *TaskUpdate { if t != nil { tu.SetClaimedAt(*t) @@ -50,19 +50,19 @@ func (tu *TaskUpdate) SetNillableClaimedAt(t *time.Time) *TaskUpdate { return tu } -// ClearClaimedAt clears the value of the "claimedAt" field. +// ClearClaimedAt clears the value of the "claimed_at" field. func (tu *TaskUpdate) ClearClaimedAt() *TaskUpdate { tu.mutation.ClearClaimedAt() return tu } -// SetExecStartedAt sets the "execStartedAt" field. +// SetExecStartedAt sets the "exec_started_at" field. func (tu *TaskUpdate) SetExecStartedAt(t time.Time) *TaskUpdate { tu.mutation.SetExecStartedAt(t) return tu } -// SetNillableExecStartedAt sets the "execStartedAt" field if the given value is not nil. +// SetNillableExecStartedAt sets the "exec_started_at" field if the given value is not nil. func (tu *TaskUpdate) SetNillableExecStartedAt(t *time.Time) *TaskUpdate { if t != nil { tu.SetExecStartedAt(*t) @@ -70,19 +70,19 @@ func (tu *TaskUpdate) SetNillableExecStartedAt(t *time.Time) *TaskUpdate { return tu } -// ClearExecStartedAt clears the value of the "execStartedAt" field. +// ClearExecStartedAt clears the value of the "exec_started_at" field. func (tu *TaskUpdate) ClearExecStartedAt() *TaskUpdate { tu.mutation.ClearExecStartedAt() return tu } -// SetExecFinishedAt sets the "execFinishedAt" field. +// SetExecFinishedAt sets the "exec_finished_at" field. func (tu *TaskUpdate) SetExecFinishedAt(t time.Time) *TaskUpdate { tu.mutation.SetExecFinishedAt(t) return tu } -// SetNillableExecFinishedAt sets the "execFinishedAt" field if the given value is not nil. +// SetNillableExecFinishedAt sets the "exec_finished_at" field if the given value is not nil. func (tu *TaskUpdate) SetNillableExecFinishedAt(t *time.Time) *TaskUpdate { if t != nil { tu.SetExecFinishedAt(*t) @@ -90,7 +90,7 @@ func (tu *TaskUpdate) SetNillableExecFinishedAt(t *time.Time) *TaskUpdate { return tu } -// ClearExecFinishedAt clears the value of the "execFinishedAt" field. +// ClearExecFinishedAt clears the value of the "exec_finished_at" field. func (tu *TaskUpdate) ClearExecFinishedAt() *TaskUpdate { tu.mutation.ClearExecFinishedAt() return tu @@ -177,41 +177,8 @@ func (tu *TaskUpdate) ClearSession() *TaskUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TaskUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) tu.defaults() - if len(tu.hooks) == 0 { - if err = tu.check(); err != nil { - return 0, err - } - affected, err = tu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TaskMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = tu.check(); err != nil { - return 0, err - } - tu.mutation = mutation - affected, err = tu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(tu.hooks) - 1; i >= 0; i-- { - if tu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = tu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, tu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, TaskMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -256,16 +223,10 @@ func (tu *TaskUpdate) check() error { } func (tu *TaskUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: task.Table, - Columns: task.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: task.FieldID, - }, - }, + if err := tu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(task.Table, task.Columns, sqlgraph.NewFieldSpec(task.FieldID, field.TypeInt)) if ps := tu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -384,6 +345,7 @@ func (tu *TaskUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + tu.mutation.done = true return n, nil } @@ -395,19 +357,19 @@ type TaskUpdateOne struct { mutation *TaskMutation } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (tuo *TaskUpdateOne) SetLastModifiedAt(t time.Time) *TaskUpdateOne { tuo.mutation.SetLastModifiedAt(t) return tuo } -// SetClaimedAt sets the "claimedAt" field. +// SetClaimedAt sets the "claimed_at" field. func (tuo *TaskUpdateOne) SetClaimedAt(t time.Time) *TaskUpdateOne { tuo.mutation.SetClaimedAt(t) return tuo } -// SetNillableClaimedAt sets the "claimedAt" field if the given value is not nil. +// SetNillableClaimedAt sets the "claimed_at" field if the given value is not nil. func (tuo *TaskUpdateOne) SetNillableClaimedAt(t *time.Time) *TaskUpdateOne { if t != nil { tuo.SetClaimedAt(*t) @@ -415,19 +377,19 @@ func (tuo *TaskUpdateOne) SetNillableClaimedAt(t *time.Time) *TaskUpdateOne { return tuo } -// ClearClaimedAt clears the value of the "claimedAt" field. +// ClearClaimedAt clears the value of the "claimed_at" field. func (tuo *TaskUpdateOne) ClearClaimedAt() *TaskUpdateOne { tuo.mutation.ClearClaimedAt() return tuo } -// SetExecStartedAt sets the "execStartedAt" field. +// SetExecStartedAt sets the "exec_started_at" field. func (tuo *TaskUpdateOne) SetExecStartedAt(t time.Time) *TaskUpdateOne { tuo.mutation.SetExecStartedAt(t) return tuo } -// SetNillableExecStartedAt sets the "execStartedAt" field if the given value is not nil. +// SetNillableExecStartedAt sets the "exec_started_at" field if the given value is not nil. func (tuo *TaskUpdateOne) SetNillableExecStartedAt(t *time.Time) *TaskUpdateOne { if t != nil { tuo.SetExecStartedAt(*t) @@ -435,19 +397,19 @@ func (tuo *TaskUpdateOne) SetNillableExecStartedAt(t *time.Time) *TaskUpdateOne return tuo } -// ClearExecStartedAt clears the value of the "execStartedAt" field. +// ClearExecStartedAt clears the value of the "exec_started_at" field. func (tuo *TaskUpdateOne) ClearExecStartedAt() *TaskUpdateOne { tuo.mutation.ClearExecStartedAt() return tuo } -// SetExecFinishedAt sets the "execFinishedAt" field. +// SetExecFinishedAt sets the "exec_finished_at" field. func (tuo *TaskUpdateOne) SetExecFinishedAt(t time.Time) *TaskUpdateOne { tuo.mutation.SetExecFinishedAt(t) return tuo } -// SetNillableExecFinishedAt sets the "execFinishedAt" field if the given value is not nil. +// SetNillableExecFinishedAt sets the "exec_finished_at" field if the given value is not nil. func (tuo *TaskUpdateOne) SetNillableExecFinishedAt(t *time.Time) *TaskUpdateOne { if t != nil { tuo.SetExecFinishedAt(*t) @@ -455,7 +417,7 @@ func (tuo *TaskUpdateOne) SetNillableExecFinishedAt(t *time.Time) *TaskUpdateOne return tuo } -// ClearExecFinishedAt clears the value of the "execFinishedAt" field. +// ClearExecFinishedAt clears the value of the "exec_finished_at" field. func (tuo *TaskUpdateOne) ClearExecFinishedAt() *TaskUpdateOne { tuo.mutation.ClearExecFinishedAt() return tuo @@ -540,6 +502,12 @@ func (tuo *TaskUpdateOne) ClearSession() *TaskUpdateOne { return tuo } +// Where appends a list predicates to the TaskUpdate builder. +func (tuo *TaskUpdateOne) Where(ps ...predicate.Task) *TaskUpdateOne { + tuo.mutation.Where(ps...) + return tuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (tuo *TaskUpdateOne) Select(field string, fields ...string) *TaskUpdateOne { @@ -549,47 +517,8 @@ func (tuo *TaskUpdateOne) Select(field string, fields ...string) *TaskUpdateOne // Save executes the query and returns the updated Task entity. func (tuo *TaskUpdateOne) Save(ctx context.Context) (*Task, error) { - var ( - err error - node *Task - ) tuo.defaults() - if len(tuo.hooks) == 0 { - if err = tuo.check(); err != nil { - return nil, err - } - node, err = tuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TaskMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = tuo.check(); err != nil { - return nil, err - } - tuo.mutation = mutation - node, err = tuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(tuo.hooks) - 1; i >= 0; i-- { - if tuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = tuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, tuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Task) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from TaskMutation", v) - } - node = nv - } - return node, err + return withHooks[*Task, TaskMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -634,16 +563,10 @@ func (tuo *TaskUpdateOne) check() error { } func (tuo *TaskUpdateOne) sqlSave(ctx context.Context) (_node *Task, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: task.Table, - Columns: task.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: task.FieldID, - }, - }, + if err := tuo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(task.Table, task.Columns, sqlgraph.NewFieldSpec(task.FieldID, field.TypeInt)) id, ok := tuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Task.id" for update`)} @@ -782,5 +705,6 @@ func (tuo *TaskUpdateOne) sqlSave(ctx context.Context) (_node *Task, err error) } return nil, err } + tuo.mutation.done = true return _node, nil } diff --git a/tavern/ent/tome.go b/tavern/ent/tome.go index 44f3d6ee9..097f7f080 100644 --- a/tavern/ent/tome.go +++ b/tavern/ent/tome.go @@ -17,15 +17,15 @@ type Tome struct { // ID of the ent. ID int `json:"id,omitempty"` // Timestamp of when this ent was created - CreatedAt time.Time `json:"createdAt,omitempty"` + CreatedAt time.Time `json:"created_at,omitempty"` // Timestamp of when this ent was last updated - LastModifiedAt time.Time `json:"lastModifiedAt,omitempty"` + LastModifiedAt time.Time `json:"last_modified_at,omitempty"` // Name of the tome Name string `json:"name,omitempty"` // Information about the tome Description string `json:"description,omitempty"` // JSON string describing what parameters are used with the tome - Parameters string `json:"parameters,omitempty"` + ParamDefs string `json:"param_defs,omitempty"` // A SHA3 digest of the eldritch field Hash string `json:"hash,omitempty"` // Eldritch script that will be executed when the tome is run @@ -64,7 +64,7 @@ func (*Tome) scanValues(columns []string) ([]any, error) { switch columns[i] { case tome.FieldID: values[i] = new(sql.NullInt64) - case tome.FieldName, tome.FieldDescription, tome.FieldParameters, tome.FieldHash, tome.FieldEldritch: + case tome.FieldName, tome.FieldDescription, tome.FieldParamDefs, tome.FieldHash, tome.FieldEldritch: values[i] = new(sql.NullString) case tome.FieldCreatedAt, tome.FieldLastModifiedAt: values[i] = new(sql.NullTime) @@ -91,13 +91,13 @@ func (t *Tome) assignValues(columns []string, values []any) error { t.ID = int(value.Int64) case tome.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field createdAt", values[i]) + return fmt.Errorf("unexpected type %T for field created_at", values[i]) } else if value.Valid { t.CreatedAt = value.Time } case tome.FieldLastModifiedAt: if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field lastModifiedAt", values[i]) + return fmt.Errorf("unexpected type %T for field last_modified_at", values[i]) } else if value.Valid { t.LastModifiedAt = value.Time } @@ -113,11 +113,11 @@ func (t *Tome) assignValues(columns []string, values []any) error { } else if value.Valid { t.Description = value.String } - case tome.FieldParameters: + case tome.FieldParamDefs: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field parameters", values[i]) + return fmt.Errorf("unexpected type %T for field param_defs", values[i]) } else if value.Valid { - t.Parameters = value.String + t.ParamDefs = value.String } case tome.FieldHash: if value, ok := values[i].(*sql.NullString); !ok { @@ -138,14 +138,14 @@ func (t *Tome) assignValues(columns []string, values []any) error { // QueryFiles queries the "files" edge of the Tome entity. func (t *Tome) QueryFiles() *FileQuery { - return (&TomeClient{config: t.config}).QueryFiles(t) + return NewTomeClient(t.config).QueryFiles(t) } // Update returns a builder for updating this Tome. // Note that you need to call Tome.Unwrap() before calling this method if this Tome // was returned from a transaction, and the transaction was committed or rolled back. func (t *Tome) Update() *TomeUpdateOne { - return (&TomeClient{config: t.config}).UpdateOne(t) + return NewTomeClient(t.config).UpdateOne(t) } // Unwrap unwraps the Tome entity that was returned from a transaction after it was closed, @@ -164,10 +164,10 @@ func (t *Tome) String() string { var builder strings.Builder builder.WriteString("Tome(") builder.WriteString(fmt.Sprintf("id=%v, ", t.ID)) - builder.WriteString("createdAt=") + builder.WriteString("created_at=") builder.WriteString(t.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") - builder.WriteString("lastModifiedAt=") + builder.WriteString("last_modified_at=") builder.WriteString(t.LastModifiedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("name=") @@ -176,8 +176,8 @@ func (t *Tome) String() string { builder.WriteString("description=") builder.WriteString(t.Description) builder.WriteString(", ") - builder.WriteString("parameters=") - builder.WriteString(t.Parameters) + builder.WriteString("param_defs=") + builder.WriteString(t.ParamDefs) builder.WriteString(", ") builder.WriteString("hash=") builder.WriteString(t.Hash) @@ -214,9 +214,3 @@ func (t *Tome) appendNamedFiles(name string, edges ...*File) { // Tomes is a parsable slice of Tome. type Tomes []*Tome - -func (t Tomes) config(cfg config) { - for _i := range t { - t[_i].config = cfg - } -} diff --git a/tavern/ent/tome/tome.go b/tavern/ent/tome/tome.go index 919f6648f..8aace3377 100644 --- a/tavern/ent/tome/tome.go +++ b/tavern/ent/tome/tome.go @@ -13,16 +13,16 @@ const ( Label = "tome" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldCreatedAt holds the string denoting the createdat field in the database. + // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" - // FieldLastModifiedAt holds the string denoting the lastmodifiedat field in the database. + // FieldLastModifiedAt holds the string denoting the last_modified_at field in the database. FieldLastModifiedAt = "last_modified_at" // FieldName holds the string denoting the name field in the database. FieldName = "name" // FieldDescription holds the string denoting the description field in the database. FieldDescription = "description" - // FieldParameters holds the string denoting the parameters field in the database. - FieldParameters = "parameters" + // FieldParamDefs holds the string denoting the param_defs field in the database. + FieldParamDefs = "param_defs" // FieldHash holds the string denoting the hash field in the database. FieldHash = "hash" // FieldEldritch holds the string denoting the eldritch field in the database. @@ -47,7 +47,7 @@ var Columns = []string{ FieldLastModifiedAt, FieldName, FieldDescription, - FieldParameters, + FieldParamDefs, FieldHash, FieldEldritch, } @@ -69,11 +69,11 @@ func ValidColumn(column string) bool { // import _ "github.com/kcarretto/realm/tavern/ent/runtime" var ( Hooks [1]ent.Hook - // DefaultCreatedAt holds the default value on creation for the "createdAt" field. + // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() time.Time - // DefaultLastModifiedAt holds the default value on creation for the "lastModifiedAt" field. + // DefaultLastModifiedAt holds the default value on creation for the "last_modified_at" field. DefaultLastModifiedAt func() time.Time - // UpdateDefaultLastModifiedAt holds the default value on update for the "lastModifiedAt" field. + // UpdateDefaultLastModifiedAt holds the default value on update for the "last_modified_at" field. UpdateDefaultLastModifiedAt func() time.Time // NameValidator is a validator for the "name" field. It is called by the builders before save. NameValidator func(string) error diff --git a/tavern/ent/tome/where.go b/tavern/ent/tome/where.go index eba983148..0f865f58d 100644 --- a/tavern/ent/tome/where.go +++ b/tavern/ent/tome/where.go @@ -12,759 +12,497 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Tome(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Tome(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Tome(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Tome { - return predicate.Tome(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.Tome(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Tome { - return predicate.Tome(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.Tome(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Tome(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Tome(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Tome(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Tome(sql.FieldLTE(FieldID, id)) } -// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldCreatedAt, v)) } -// LastModifiedAt applies equality check predicate on the "lastModifiedAt" field. It's identical to LastModifiedAtEQ. +// LastModifiedAt applies equality check predicate on the "last_modified_at" field. It's identical to LastModifiedAtEQ. func LastModifiedAt(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldLastModifiedAt, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldName, v)) } // Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. func Description(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldDescription, v)) } -// Parameters applies equality check predicate on the "parameters" field. It's identical to ParametersEQ. -func Parameters(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldParameters), v)) - }) +// ParamDefs applies equality check predicate on the "param_defs" field. It's identical to ParamDefsEQ. +func ParamDefs(v string) predicate.Tome { + return predicate.Tome(sql.FieldEQ(FieldParamDefs, v)) } // Hash applies equality check predicate on the "hash" field. It's identical to HashEQ. func Hash(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldHash, v)) } // Eldritch applies equality check predicate on the "eldritch" field. It's identical to EldritchEQ. func Eldritch(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldEldritch, v)) } -// CreatedAtEQ applies the EQ predicate on the "createdAt" field. +// CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldCreatedAt, v)) } -// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.Tome(sql.FieldNEQ(FieldCreatedAt, v)) } -// CreatedAtIn applies the In predicate on the "createdAt" field. +// CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.Tome(sql.FieldIn(FieldCreatedAt, vs...)) } -// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.Tome(sql.FieldNotIn(FieldCreatedAt, vs...)) } -// CreatedAtGT applies the GT predicate on the "createdAt" field. +// CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.Tome(sql.FieldGT(FieldCreatedAt, v)) } -// CreatedAtGTE applies the GTE predicate on the "createdAt" field. +// CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Tome(sql.FieldGTE(FieldCreatedAt, v)) } -// CreatedAtLT applies the LT predicate on the "createdAt" field. +// CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.Tome(sql.FieldLT(FieldCreatedAt, v)) } -// CreatedAtLTE applies the LTE predicate on the "createdAt" field. +// CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.Tome(sql.FieldLTE(FieldCreatedAt, v)) } -// LastModifiedAtEQ applies the EQ predicate on the "lastModifiedAt" field. +// LastModifiedAtEQ applies the EQ predicate on the "last_modified_at" field. func LastModifiedAtEQ(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldLastModifiedAt, v)) } -// LastModifiedAtNEQ applies the NEQ predicate on the "lastModifiedAt" field. +// LastModifiedAtNEQ applies the NEQ predicate on the "last_modified_at" field. func LastModifiedAtNEQ(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Tome(sql.FieldNEQ(FieldLastModifiedAt, v)) } -// LastModifiedAtIn applies the In predicate on the "lastModifiedAt" field. +// LastModifiedAtIn applies the In predicate on the "last_modified_at" field. func LastModifiedAtIn(vs ...time.Time) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldLastModifiedAt), v...)) - }) + return predicate.Tome(sql.FieldIn(FieldLastModifiedAt, vs...)) } -// LastModifiedAtNotIn applies the NotIn predicate on the "lastModifiedAt" field. +// LastModifiedAtNotIn applies the NotIn predicate on the "last_modified_at" field. func LastModifiedAtNotIn(vs ...time.Time) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldLastModifiedAt), v...)) - }) + return predicate.Tome(sql.FieldNotIn(FieldLastModifiedAt, vs...)) } -// LastModifiedAtGT applies the GT predicate on the "lastModifiedAt" field. +// LastModifiedAtGT applies the GT predicate on the "last_modified_at" field. func LastModifiedAtGT(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Tome(sql.FieldGT(FieldLastModifiedAt, v)) } -// LastModifiedAtGTE applies the GTE predicate on the "lastModifiedAt" field. +// LastModifiedAtGTE applies the GTE predicate on the "last_modified_at" field. func LastModifiedAtGTE(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Tome(sql.FieldGTE(FieldLastModifiedAt, v)) } -// LastModifiedAtLT applies the LT predicate on the "lastModifiedAt" field. +// LastModifiedAtLT applies the LT predicate on the "last_modified_at" field. func LastModifiedAtLT(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Tome(sql.FieldLT(FieldLastModifiedAt, v)) } -// LastModifiedAtLTE applies the LTE predicate on the "lastModifiedAt" field. +// LastModifiedAtLTE applies the LTE predicate on the "last_modified_at" field. func LastModifiedAtLTE(v time.Time) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldLastModifiedAt), v)) - }) + return predicate.Tome(sql.FieldLTE(FieldLastModifiedAt, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.Tome(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.Tome(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.Tome(sql.FieldContainsFold(FieldName, v)) } // DescriptionEQ applies the EQ predicate on the "description" field. func DescriptionEQ(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldDescription, v)) } // DescriptionNEQ applies the NEQ predicate on the "description" field. func DescriptionNEQ(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldNEQ(FieldDescription, v)) } // DescriptionIn applies the In predicate on the "description" field. func DescriptionIn(vs ...string) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldDescription), v...)) - }) + return predicate.Tome(sql.FieldIn(FieldDescription, vs...)) } // DescriptionNotIn applies the NotIn predicate on the "description" field. func DescriptionNotIn(vs ...string) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldDescription), v...)) - }) + return predicate.Tome(sql.FieldNotIn(FieldDescription, vs...)) } // DescriptionGT applies the GT predicate on the "description" field. func DescriptionGT(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldGT(FieldDescription, v)) } // DescriptionGTE applies the GTE predicate on the "description" field. func DescriptionGTE(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldGTE(FieldDescription, v)) } // DescriptionLT applies the LT predicate on the "description" field. func DescriptionLT(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldLT(FieldDescription, v)) } // DescriptionLTE applies the LTE predicate on the "description" field. func DescriptionLTE(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldLTE(FieldDescription, v)) } // DescriptionContains applies the Contains predicate on the "description" field. func DescriptionContains(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldContains(FieldDescription, v)) } // DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. func DescriptionHasPrefix(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldHasPrefix(FieldDescription, v)) } // DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. func DescriptionHasSuffix(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldHasSuffix(FieldDescription, v)) } // DescriptionEqualFold applies the EqualFold predicate on the "description" field. func DescriptionEqualFold(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldEqualFold(FieldDescription, v)) } // DescriptionContainsFold applies the ContainsFold predicate on the "description" field. func DescriptionContainsFold(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldDescription), v)) - }) + return predicate.Tome(sql.FieldContainsFold(FieldDescription, v)) } -// ParametersEQ applies the EQ predicate on the "parameters" field. -func ParametersEQ(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldParameters), v)) - }) +// ParamDefsEQ applies the EQ predicate on the "param_defs" field. +func ParamDefsEQ(v string) predicate.Tome { + return predicate.Tome(sql.FieldEQ(FieldParamDefs, v)) } -// ParametersNEQ applies the NEQ predicate on the "parameters" field. -func ParametersNEQ(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldParameters), v)) - }) +// ParamDefsNEQ applies the NEQ predicate on the "param_defs" field. +func ParamDefsNEQ(v string) predicate.Tome { + return predicate.Tome(sql.FieldNEQ(FieldParamDefs, v)) } -// ParametersIn applies the In predicate on the "parameters" field. -func ParametersIn(vs ...string) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldParameters), v...)) - }) +// ParamDefsIn applies the In predicate on the "param_defs" field. +func ParamDefsIn(vs ...string) predicate.Tome { + return predicate.Tome(sql.FieldIn(FieldParamDefs, vs...)) } -// ParametersNotIn applies the NotIn predicate on the "parameters" field. -func ParametersNotIn(vs ...string) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldParameters), v...)) - }) +// ParamDefsNotIn applies the NotIn predicate on the "param_defs" field. +func ParamDefsNotIn(vs ...string) predicate.Tome { + return predicate.Tome(sql.FieldNotIn(FieldParamDefs, vs...)) } -// ParametersGT applies the GT predicate on the "parameters" field. -func ParametersGT(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldParameters), v)) - }) +// ParamDefsGT applies the GT predicate on the "param_defs" field. +func ParamDefsGT(v string) predicate.Tome { + return predicate.Tome(sql.FieldGT(FieldParamDefs, v)) } -// ParametersGTE applies the GTE predicate on the "parameters" field. -func ParametersGTE(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldParameters), v)) - }) +// ParamDefsGTE applies the GTE predicate on the "param_defs" field. +func ParamDefsGTE(v string) predicate.Tome { + return predicate.Tome(sql.FieldGTE(FieldParamDefs, v)) } -// ParametersLT applies the LT predicate on the "parameters" field. -func ParametersLT(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldParameters), v)) - }) +// ParamDefsLT applies the LT predicate on the "param_defs" field. +func ParamDefsLT(v string) predicate.Tome { + return predicate.Tome(sql.FieldLT(FieldParamDefs, v)) } -// ParametersLTE applies the LTE predicate on the "parameters" field. -func ParametersLTE(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldParameters), v)) - }) +// ParamDefsLTE applies the LTE predicate on the "param_defs" field. +func ParamDefsLTE(v string) predicate.Tome { + return predicate.Tome(sql.FieldLTE(FieldParamDefs, v)) } -// ParametersContains applies the Contains predicate on the "parameters" field. -func ParametersContains(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldParameters), v)) - }) +// ParamDefsContains applies the Contains predicate on the "param_defs" field. +func ParamDefsContains(v string) predicate.Tome { + return predicate.Tome(sql.FieldContains(FieldParamDefs, v)) } -// ParametersHasPrefix applies the HasPrefix predicate on the "parameters" field. -func ParametersHasPrefix(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldParameters), v)) - }) +// ParamDefsHasPrefix applies the HasPrefix predicate on the "param_defs" field. +func ParamDefsHasPrefix(v string) predicate.Tome { + return predicate.Tome(sql.FieldHasPrefix(FieldParamDefs, v)) } -// ParametersHasSuffix applies the HasSuffix predicate on the "parameters" field. -func ParametersHasSuffix(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldParameters), v)) - }) +// ParamDefsHasSuffix applies the HasSuffix predicate on the "param_defs" field. +func ParamDefsHasSuffix(v string) predicate.Tome { + return predicate.Tome(sql.FieldHasSuffix(FieldParamDefs, v)) } -// ParametersIsNil applies the IsNil predicate on the "parameters" field. -func ParametersIsNil() predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldParameters))) - }) +// ParamDefsIsNil applies the IsNil predicate on the "param_defs" field. +func ParamDefsIsNil() predicate.Tome { + return predicate.Tome(sql.FieldIsNull(FieldParamDefs)) } -// ParametersNotNil applies the NotNil predicate on the "parameters" field. -func ParametersNotNil() predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldParameters))) - }) +// ParamDefsNotNil applies the NotNil predicate on the "param_defs" field. +func ParamDefsNotNil() predicate.Tome { + return predicate.Tome(sql.FieldNotNull(FieldParamDefs)) } -// ParametersEqualFold applies the EqualFold predicate on the "parameters" field. -func ParametersEqualFold(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldParameters), v)) - }) +// ParamDefsEqualFold applies the EqualFold predicate on the "param_defs" field. +func ParamDefsEqualFold(v string) predicate.Tome { + return predicate.Tome(sql.FieldEqualFold(FieldParamDefs, v)) } -// ParametersContainsFold applies the ContainsFold predicate on the "parameters" field. -func ParametersContainsFold(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldParameters), v)) - }) +// ParamDefsContainsFold applies the ContainsFold predicate on the "param_defs" field. +func ParamDefsContainsFold(v string) predicate.Tome { + return predicate.Tome(sql.FieldContainsFold(FieldParamDefs, v)) } // HashEQ applies the EQ predicate on the "hash" field. func HashEQ(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldHash, v)) } // HashNEQ applies the NEQ predicate on the "hash" field. func HashNEQ(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldNEQ(FieldHash, v)) } // HashIn applies the In predicate on the "hash" field. func HashIn(vs ...string) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldHash), v...)) - }) + return predicate.Tome(sql.FieldIn(FieldHash, vs...)) } // HashNotIn applies the NotIn predicate on the "hash" field. func HashNotIn(vs ...string) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldHash), v...)) - }) + return predicate.Tome(sql.FieldNotIn(FieldHash, vs...)) } // HashGT applies the GT predicate on the "hash" field. func HashGT(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldGT(FieldHash, v)) } // HashGTE applies the GTE predicate on the "hash" field. func HashGTE(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldGTE(FieldHash, v)) } // HashLT applies the LT predicate on the "hash" field. func HashLT(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldLT(FieldHash, v)) } // HashLTE applies the LTE predicate on the "hash" field. func HashLTE(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldLTE(FieldHash, v)) } // HashContains applies the Contains predicate on the "hash" field. func HashContains(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldContains(FieldHash, v)) } // HashHasPrefix applies the HasPrefix predicate on the "hash" field. func HashHasPrefix(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldHasPrefix(FieldHash, v)) } // HashHasSuffix applies the HasSuffix predicate on the "hash" field. func HashHasSuffix(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldHasSuffix(FieldHash, v)) } // HashEqualFold applies the EqualFold predicate on the "hash" field. func HashEqualFold(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldEqualFold(FieldHash, v)) } // HashContainsFold applies the ContainsFold predicate on the "hash" field. func HashContainsFold(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldHash), v)) - }) + return predicate.Tome(sql.FieldContainsFold(FieldHash, v)) } // EldritchEQ applies the EQ predicate on the "eldritch" field. func EldritchEQ(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldEQ(FieldEldritch, v)) } // EldritchNEQ applies the NEQ predicate on the "eldritch" field. func EldritchNEQ(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldNEQ(FieldEldritch, v)) } // EldritchIn applies the In predicate on the "eldritch" field. func EldritchIn(vs ...string) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldEldritch), v...)) - }) + return predicate.Tome(sql.FieldIn(FieldEldritch, vs...)) } // EldritchNotIn applies the NotIn predicate on the "eldritch" field. func EldritchNotIn(vs ...string) predicate.Tome { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldEldritch), v...)) - }) + return predicate.Tome(sql.FieldNotIn(FieldEldritch, vs...)) } // EldritchGT applies the GT predicate on the "eldritch" field. func EldritchGT(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldGT(FieldEldritch, v)) } // EldritchGTE applies the GTE predicate on the "eldritch" field. func EldritchGTE(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldGTE(FieldEldritch, v)) } // EldritchLT applies the LT predicate on the "eldritch" field. func EldritchLT(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldLT(FieldEldritch, v)) } // EldritchLTE applies the LTE predicate on the "eldritch" field. func EldritchLTE(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldLTE(FieldEldritch, v)) } // EldritchContains applies the Contains predicate on the "eldritch" field. func EldritchContains(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldContains(FieldEldritch, v)) } // EldritchHasPrefix applies the HasPrefix predicate on the "eldritch" field. func EldritchHasPrefix(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldHasPrefix(FieldEldritch, v)) } // EldritchHasSuffix applies the HasSuffix predicate on the "eldritch" field. func EldritchHasSuffix(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldHasSuffix(FieldEldritch, v)) } // EldritchEqualFold applies the EqualFold predicate on the "eldritch" field. func EldritchEqualFold(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldEqualFold(FieldEldritch, v)) } // EldritchContainsFold applies the ContainsFold predicate on the "eldritch" field. func EldritchContainsFold(v string) predicate.Tome { - return predicate.Tome(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldEldritch), v)) - }) + return predicate.Tome(sql.FieldContainsFold(FieldEldritch, v)) } // HasFiles applies the HasEdge predicate on the "files" edge. @@ -772,7 +510,6 @@ func HasFiles() predicate.Tome { return predicate.Tome(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(FilesTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, FilesTable, FilesColumn), ) sqlgraph.HasNeighbors(s, step) diff --git a/tavern/ent/tome_create.go b/tavern/ent/tome_create.go index d68e439f7..ef26f456a 100644 --- a/tavern/ent/tome_create.go +++ b/tavern/ent/tome_create.go @@ -21,13 +21,13 @@ type TomeCreate struct { hooks []Hook } -// SetCreatedAt sets the "createdAt" field. +// SetCreatedAt sets the "created_at" field. func (tc *TomeCreate) SetCreatedAt(t time.Time) *TomeCreate { tc.mutation.SetCreatedAt(t) return tc } -// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (tc *TomeCreate) SetNillableCreatedAt(t *time.Time) *TomeCreate { if t != nil { tc.SetCreatedAt(*t) @@ -35,13 +35,13 @@ func (tc *TomeCreate) SetNillableCreatedAt(t *time.Time) *TomeCreate { return tc } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (tc *TomeCreate) SetLastModifiedAt(t time.Time) *TomeCreate { tc.mutation.SetLastModifiedAt(t) return tc } -// SetNillableLastModifiedAt sets the "lastModifiedAt" field if the given value is not nil. +// SetNillableLastModifiedAt sets the "last_modified_at" field if the given value is not nil. func (tc *TomeCreate) SetNillableLastModifiedAt(t *time.Time) *TomeCreate { if t != nil { tc.SetLastModifiedAt(*t) @@ -61,16 +61,16 @@ func (tc *TomeCreate) SetDescription(s string) *TomeCreate { return tc } -// SetParameters sets the "parameters" field. -func (tc *TomeCreate) SetParameters(s string) *TomeCreate { - tc.mutation.SetParameters(s) +// SetParamDefs sets the "param_defs" field. +func (tc *TomeCreate) SetParamDefs(s string) *TomeCreate { + tc.mutation.SetParamDefs(s) return tc } -// SetNillableParameters sets the "parameters" field if the given value is not nil. -func (tc *TomeCreate) SetNillableParameters(s *string) *TomeCreate { +// SetNillableParamDefs sets the "param_defs" field if the given value is not nil. +func (tc *TomeCreate) SetNillableParamDefs(s *string) *TomeCreate { if s != nil { - tc.SetParameters(*s) + tc.SetParamDefs(*s) } return tc } @@ -109,52 +109,10 @@ func (tc *TomeCreate) Mutation() *TomeMutation { // Save creates the Tome in the database. func (tc *TomeCreate) Save(ctx context.Context) (*Tome, error) { - var ( - err error - node *Tome - ) if err := tc.defaults(); err != nil { return nil, err } - if len(tc.hooks) == 0 { - if err = tc.check(); err != nil { - return nil, err - } - node, err = tc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TomeMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = tc.check(); err != nil { - return nil, err - } - tc.mutation = mutation - if node, err = tc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(tc.hooks) - 1; i >= 0; i-- { - if tc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = tc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, tc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Tome) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from TomeMutation", v) - } - node = nv - } - return node, err + return withHooks[*Tome, TomeMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -201,10 +159,10 @@ func (tc *TomeCreate) defaults() error { // check runs all checks and user-defined validators on the builder. func (tc *TomeCreate) check() error { if _, ok := tc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "Tome.createdAt"`)} + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Tome.created_at"`)} } if _, ok := tc.mutation.LastModifiedAt(); !ok { - return &ValidationError{Name: "lastModifiedAt", err: errors.New(`ent: missing required field "Tome.lastModifiedAt"`)} + return &ValidationError{Name: "last_modified_at", err: errors.New(`ent: missing required field "Tome.last_modified_at"`)} } if _, ok := tc.mutation.Name(); !ok { return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Tome.name"`)} @@ -232,6 +190,9 @@ func (tc *TomeCreate) check() error { } func (tc *TomeCreate) sqlSave(ctx context.Context) (*Tome, error) { + if err := tc.check(); err != nil { + return nil, err + } _node, _spec := tc.createSpec() if err := sqlgraph.CreateNode(ctx, tc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -241,19 +202,15 @@ func (tc *TomeCreate) sqlSave(ctx context.Context) (*Tome, error) { } id := _spec.ID.Value.(int64) _node.ID = int(id) + tc.mutation.id = &_node.ID + tc.mutation.done = true return _node, nil } func (tc *TomeCreate) createSpec() (*Tome, *sqlgraph.CreateSpec) { var ( _node = &Tome{config: tc.config} - _spec = &sqlgraph.CreateSpec{ - Table: tome.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: tome.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(tome.Table, sqlgraph.NewFieldSpec(tome.FieldID, field.TypeInt)) ) if value, ok := tc.mutation.CreatedAt(); ok { _spec.SetField(tome.FieldCreatedAt, field.TypeTime, value) @@ -271,9 +228,9 @@ func (tc *TomeCreate) createSpec() (*Tome, *sqlgraph.CreateSpec) { _spec.SetField(tome.FieldDescription, field.TypeString, value) _node.Description = value } - if value, ok := tc.mutation.Parameters(); ok { - _spec.SetField(tome.FieldParameters, field.TypeString, value) - _node.Parameters = value + if value, ok := tc.mutation.ParamDefs(); ok { + _spec.SetField(tome.FieldParamDefs, field.TypeString, value) + _node.ParamDefs = value } if value, ok := tc.mutation.Hash(); ok { _spec.SetField(tome.FieldHash, field.TypeString, value) diff --git a/tavern/ent/tome_delete.go b/tavern/ent/tome_delete.go index b2f1ffd98..376369e16 100644 --- a/tavern/ent/tome_delete.go +++ b/tavern/ent/tome_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (td *TomeDelete) Where(ps ...predicate.Tome) *TomeDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TomeDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(td.hooks) == 0 { - affected, err = td.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TomeMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - td.mutation = mutation - affected, err = td.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(td.hooks) - 1; i >= 0; i-- { - if td.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = td.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, td.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, TomeMutation](ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (td *TomeDelete) ExecX(ctx context.Context) int { } func (td *TomeDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: tome.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: tome.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(tome.Table, sqlgraph.NewFieldSpec(tome.FieldID, field.TypeInt)) if ps := td.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (td *TomeDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + td.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type TomeDeleteOne struct { td *TomeDelete } +// Where appends a list predicates to the TomeDelete builder. +func (tdo *TomeDeleteOne) Where(ps ...predicate.Tome) *TomeDeleteOne { + tdo.td.mutation.Where(ps...) + return tdo +} + // Exec executes the deletion query. func (tdo *TomeDeleteOne) Exec(ctx context.Context) error { n, err := tdo.td.Exec(ctx) @@ -111,5 +82,7 @@ func (tdo *TomeDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (tdo *TomeDeleteOne) ExecX(ctx context.Context) { - tdo.td.ExecX(ctx) + if err := tdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/tavern/ent/tome_query.go b/tavern/ent/tome_query.go index 9a8019719..501f67806 100644 --- a/tavern/ent/tome_query.go +++ b/tavern/ent/tome_query.go @@ -19,11 +19,9 @@ import ( // TomeQuery is the builder for querying Tome entities. type TomeQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.Tome withFiles *FileQuery modifiers []func(*sql.Selector) @@ -40,26 +38,26 @@ func (tq *TomeQuery) Where(ps ...predicate.Tome) *TomeQuery { return tq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (tq *TomeQuery) Limit(limit int) *TomeQuery { - tq.limit = &limit + tq.ctx.Limit = &limit return tq } -// Offset adds an offset step to the query. +// Offset to start from. func (tq *TomeQuery) Offset(offset int) *TomeQuery { - tq.offset = &offset + tq.ctx.Offset = &offset return tq } // 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 (tq *TomeQuery) Unique(unique bool) *TomeQuery { - tq.unique = &unique + tq.ctx.Unique = &unique return tq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (tq *TomeQuery) Order(o ...OrderFunc) *TomeQuery { tq.order = append(tq.order, o...) return tq @@ -67,7 +65,7 @@ func (tq *TomeQuery) Order(o ...OrderFunc) *TomeQuery { // QueryFiles chains the current query on the "files" edge. func (tq *TomeQuery) QueryFiles() *FileQuery { - query := &FileQuery{config: tq.config} + query := (&FileClient{config: tq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := tq.prepareQuery(ctx); err != nil { return nil, err @@ -90,7 +88,7 @@ func (tq *TomeQuery) QueryFiles() *FileQuery { // First returns the first Tome entity from the query. // Returns a *NotFoundError when no Tome was found. func (tq *TomeQuery) First(ctx context.Context) (*Tome, error) { - nodes, err := tq.Limit(1).All(ctx) + nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, "First")) if err != nil { return nil, err } @@ -113,7 +111,7 @@ func (tq *TomeQuery) FirstX(ctx context.Context) *Tome { // Returns a *NotFoundError when no Tome ID was found. func (tq *TomeQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = tq.Limit(1).IDs(ctx); err != nil { + if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -136,7 +134,7 @@ func (tq *TomeQuery) FirstIDX(ctx context.Context) int { // Returns a *NotSingularError when more than one Tome entity is found. // Returns a *NotFoundError when no Tome entities are found. func (tq *TomeQuery) Only(ctx context.Context) (*Tome, error) { - nodes, err := tq.Limit(2).All(ctx) + nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, "Only")) if err != nil { return nil, err } @@ -164,7 +162,7 @@ func (tq *TomeQuery) OnlyX(ctx context.Context) *Tome { // Returns a *NotFoundError when no entities are found. func (tq *TomeQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = tq.Limit(2).IDs(ctx); err != nil { + if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -189,10 +187,12 @@ func (tq *TomeQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of Tomes. func (tq *TomeQuery) All(ctx context.Context) ([]*Tome, error) { + ctx = setContextOp(ctx, tq.ctx, "All") if err := tq.prepareQuery(ctx); err != nil { return nil, err } - return tq.sqlAll(ctx) + qr := querierAll[[]*Tome, *TomeQuery]() + return withInterceptors[[]*Tome](ctx, tq, qr, tq.inters) } // AllX is like All, but panics if an error occurs. @@ -205,9 +205,12 @@ func (tq *TomeQuery) AllX(ctx context.Context) []*Tome { } // IDs executes the query and returns a list of Tome IDs. -func (tq *TomeQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := tq.Select(tome.FieldID).Scan(ctx, &ids); err != nil { +func (tq *TomeQuery) IDs(ctx context.Context) (ids []int, err error) { + if tq.ctx.Unique == nil && tq.path != nil { + tq.Unique(true) + } + ctx = setContextOp(ctx, tq.ctx, "IDs") + if err = tq.Select(tome.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -224,10 +227,11 @@ func (tq *TomeQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (tq *TomeQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, tq.ctx, "Count") if err := tq.prepareQuery(ctx); err != nil { return 0, err } - return tq.sqlCount(ctx) + return withInterceptors[int](ctx, tq, querierCount[*TomeQuery](), tq.inters) } // CountX is like Count, but panics if an error occurs. @@ -241,10 +245,15 @@ func (tq *TomeQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (tq *TomeQuery) Exist(ctx context.Context) (bool, error) { - if err := tq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, tq.ctx, "Exist") + switch _, err := tq.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 tq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -264,22 +273,21 @@ func (tq *TomeQuery) Clone() *TomeQuery { } return &TomeQuery{ config: tq.config, - limit: tq.limit, - offset: tq.offset, + ctx: tq.ctx.Clone(), order: append([]OrderFunc{}, tq.order...), + inters: append([]Interceptor{}, tq.inters...), predicates: append([]predicate.Tome{}, tq.predicates...), withFiles: tq.withFiles.Clone(), // clone intermediate query. - sql: tq.sql.Clone(), - path: tq.path, - unique: tq.unique, + sql: tq.sql.Clone(), + path: tq.path, } } // WithFiles tells the query-builder to eager-load the nodes that are connected to // the "files" edge. The optional arguments are used to configure the query builder of the edge. func (tq *TomeQuery) WithFiles(opts ...func(*FileQuery)) *TomeQuery { - query := &FileQuery{config: tq.config} + query := (&FileClient{config: tq.config}).Query() for _, opt := range opts { opt(query) } @@ -293,7 +301,7 @@ func (tq *TomeQuery) WithFiles(opts ...func(*FileQuery)) *TomeQuery { // Example: // // var v []struct { -// CreatedAt time.Time `json:"createdAt,omitempty"` +// CreatedAt time.Time `json:"created_at,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -302,16 +310,11 @@ func (tq *TomeQuery) WithFiles(opts ...func(*FileQuery)) *TomeQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (tq *TomeQuery) GroupBy(field string, fields ...string) *TomeGroupBy { - grbuild := &TomeGroupBy{config: tq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := tq.prepareQuery(ctx); err != nil { - return nil, err - } - return tq.sqlQuery(ctx), nil - } + tq.ctx.Fields = append([]string{field}, fields...) + grbuild := &TomeGroupBy{build: tq} + grbuild.flds = &tq.ctx.Fields grbuild.label = tome.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -321,18 +324,18 @@ func (tq *TomeQuery) GroupBy(field string, fields ...string) *TomeGroupBy { // Example: // // var v []struct { -// CreatedAt time.Time `json:"createdAt,omitempty"` +// CreatedAt time.Time `json:"created_at,omitempty"` // } // // client.Tome.Query(). // Select(tome.FieldCreatedAt). // Scan(ctx, &v) func (tq *TomeQuery) Select(fields ...string) *TomeSelect { - tq.fields = append(tq.fields, fields...) - selbuild := &TomeSelect{TomeQuery: tq} - selbuild.label = tome.Label - selbuild.flds, selbuild.scan = &tq.fields, selbuild.Scan - return selbuild + tq.ctx.Fields = append(tq.ctx.Fields, fields...) + sbuild := &TomeSelect{TomeQuery: tq} + sbuild.label = tome.Label + sbuild.flds, sbuild.scan = &tq.ctx.Fields, sbuild.Scan + return sbuild } // Aggregate returns a TomeSelect configured with the given aggregations. @@ -341,7 +344,17 @@ func (tq *TomeQuery) Aggregate(fns ...AggregateFunc) *TomeSelect { } func (tq *TomeQuery) prepareQuery(ctx context.Context) error { - for _, f := range tq.fields { + for _, inter := range tq.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, tq); err != nil { + return err + } + } + } + for _, f := range tq.ctx.Fields { if !tome.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -444,41 +457,22 @@ func (tq *TomeQuery) sqlCount(ctx context.Context) (int, error) { if len(tq.modifiers) > 0 { _spec.Modifiers = tq.modifiers } - _spec.Node.Columns = tq.fields - if len(tq.fields) > 0 { - _spec.Unique = tq.unique != nil && *tq.unique + _spec.Node.Columns = tq.ctx.Fields + if len(tq.ctx.Fields) > 0 { + _spec.Unique = tq.ctx.Unique != nil && *tq.ctx.Unique } return sqlgraph.CountNodes(ctx, tq.driver, _spec) } -func (tq *TomeQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := tq.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 (tq *TomeQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: tome.Table, - Columns: tome.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: tome.FieldID, - }, - }, - From: tq.sql, - Unique: true, - } - if unique := tq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(tome.Table, tome.Columns, sqlgraph.NewFieldSpec(tome.FieldID, field.TypeInt)) + _spec.From = tq.sql + if unique := tq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if tq.path != nil { + _spec.Unique = true } - if fields := tq.fields; len(fields) > 0 { + if fields := tq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, tome.FieldID) for i := range fields { @@ -494,10 +488,10 @@ func (tq *TomeQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := tq.limit; limit != nil { + if limit := tq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := tq.offset; offset != nil { + if offset := tq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := tq.order; len(ps) > 0 { @@ -513,7 +507,7 @@ func (tq *TomeQuery) querySpec() *sqlgraph.QuerySpec { func (tq *TomeQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(tq.driver.Dialect()) t1 := builder.Table(tome.Table) - columns := tq.fields + columns := tq.ctx.Fields if len(columns) == 0 { columns = tome.Columns } @@ -522,7 +516,7 @@ func (tq *TomeQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = tq.sql selector.Select(selector.Columns(columns...)...) } - if tq.unique != nil && *tq.unique { + if tq.ctx.Unique != nil && *tq.ctx.Unique { selector.Distinct() } for _, p := range tq.predicates { @@ -531,12 +525,12 @@ func (tq *TomeQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range tq.order { p(selector) } - if offset := tq.offset; offset != nil { + if offset := tq.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 := tq.limit; limit != nil { + if limit := tq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -545,7 +539,7 @@ func (tq *TomeQuery) sqlQuery(ctx context.Context) *sql.Selector { // WithNamedFiles tells the query-builder to eager-load the nodes that are connected to the "files" // edge with the given name. The optional arguments are used to configure the query builder of the edge. func (tq *TomeQuery) WithNamedFiles(name string, opts ...func(*FileQuery)) *TomeQuery { - query := &FileQuery{config: tq.config} + query := (&FileClient{config: tq.config}).Query() for _, opt := range opts { opt(query) } @@ -558,13 +552,8 @@ func (tq *TomeQuery) WithNamedFiles(name string, opts ...func(*FileQuery)) *Tome // TomeGroupBy is the group-by builder for Tome entities. type TomeGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *TomeQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -573,58 +562,46 @@ func (tgb *TomeGroupBy) Aggregate(fns ...AggregateFunc) *TomeGroupBy { return tgb } -// 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 (tgb *TomeGroupBy) Scan(ctx context.Context, v any) error { - query, err := tgb.path(ctx) - if err != nil { + ctx = setContextOp(ctx, tgb.build.ctx, "GroupBy") + if err := tgb.build.prepareQuery(ctx); err != nil { return err } - tgb.sql = query - return tgb.sqlScan(ctx, v) + return scanWithInterceptors[*TomeQuery, *TomeGroupBy](ctx, tgb.build, tgb, tgb.build.inters, v) } -func (tgb *TomeGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range tgb.fields { - if !tome.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} +func (tgb *TomeGroupBy) sqlScan(ctx context.Context, root *TomeQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(tgb.fns)) + for _, fn := range tgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*tgb.flds)+len(tgb.fns)) + for _, f := range *tgb.flds { + columns = append(columns, selector.C(f)) } + columns = append(columns, aggregation...) + selector.Select(columns...) } - selector := tgb.sqlQuery() + selector.GroupBy(selector.Columns(*tgb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := tgb.driver.Query(ctx, query, args, rows); err != nil { + if err := tgb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (tgb *TomeGroupBy) sqlQuery() *sql.Selector { - selector := tgb.sql.Select() - aggregation := make([]string, 0, len(tgb.fns)) - for _, fn := range tgb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(tgb.fields)+len(tgb.fns)) - for _, f := range tgb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(tgb.fields...)...) -} - // TomeSelect is the builder for selecting fields of Tome entities. type TomeSelect struct { *TomeQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -635,26 +612,27 @@ func (ts *TomeSelect) Aggregate(fns ...AggregateFunc) *TomeSelect { // Scan applies the selector query and scans the result into the given value. func (ts *TomeSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ts.ctx, "Select") if err := ts.prepareQuery(ctx); err != nil { return err } - ts.sql = ts.TomeQuery.sqlQuery(ctx) - return ts.sqlScan(ctx, v) + return scanWithInterceptors[*TomeQuery, *TomeSelect](ctx, ts.TomeQuery, ts, ts.inters, v) } -func (ts *TomeSelect) sqlScan(ctx context.Context, v any) error { +func (ts *TomeSelect) sqlScan(ctx context.Context, root *TomeQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(ts.fns)) for _, fn := range ts.fns { - aggregation = append(aggregation, fn(ts.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*ts.selector.flds); { case n == 0 && len(aggregation) > 0: - ts.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - ts.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := ts.sql.Query() + query, args := selector.Query() if err := ts.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/tavern/ent/tome_update.go b/tavern/ent/tome_update.go index 569af4f46..4890f28be 100644 --- a/tavern/ent/tome_update.go +++ b/tavern/ent/tome_update.go @@ -29,7 +29,7 @@ func (tu *TomeUpdate) Where(ps ...predicate.Tome) *TomeUpdate { return tu } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (tu *TomeUpdate) SetLastModifiedAt(t time.Time) *TomeUpdate { tu.mutation.SetLastModifiedAt(t) return tu @@ -47,23 +47,23 @@ func (tu *TomeUpdate) SetDescription(s string) *TomeUpdate { return tu } -// SetParameters sets the "parameters" field. -func (tu *TomeUpdate) SetParameters(s string) *TomeUpdate { - tu.mutation.SetParameters(s) +// SetParamDefs sets the "param_defs" field. +func (tu *TomeUpdate) SetParamDefs(s string) *TomeUpdate { + tu.mutation.SetParamDefs(s) return tu } -// SetNillableParameters sets the "parameters" field if the given value is not nil. -func (tu *TomeUpdate) SetNillableParameters(s *string) *TomeUpdate { +// SetNillableParamDefs sets the "param_defs" field if the given value is not nil. +func (tu *TomeUpdate) SetNillableParamDefs(s *string) *TomeUpdate { if s != nil { - tu.SetParameters(*s) + tu.SetParamDefs(*s) } return tu } -// ClearParameters clears the value of the "parameters" field. -func (tu *TomeUpdate) ClearParameters() *TomeUpdate { - tu.mutation.ClearParameters() +// ClearParamDefs clears the value of the "param_defs" field. +func (tu *TomeUpdate) ClearParamDefs() *TomeUpdate { + tu.mutation.ClearParamDefs() return tu } @@ -122,43 +122,10 @@ func (tu *TomeUpdate) RemoveFiles(f ...*File) *TomeUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TomeUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) if err := tu.defaults(); err != nil { return 0, err } - if len(tu.hooks) == 0 { - if err = tu.check(); err != nil { - return 0, err - } - affected, err = tu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TomeMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = tu.check(); err != nil { - return 0, err - } - tu.mutation = mutation - affected, err = tu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(tu.hooks) - 1; i >= 0; i-- { - if tu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = tu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, tu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, TomeMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -211,16 +178,10 @@ func (tu *TomeUpdate) check() error { } func (tu *TomeUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: tome.Table, - Columns: tome.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: tome.FieldID, - }, - }, + if err := tu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(tome.Table, tome.Columns, sqlgraph.NewFieldSpec(tome.FieldID, field.TypeInt)) if ps := tu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -237,11 +198,11 @@ func (tu *TomeUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := tu.mutation.Description(); ok { _spec.SetField(tome.FieldDescription, field.TypeString, value) } - if value, ok := tu.mutation.Parameters(); ok { - _spec.SetField(tome.FieldParameters, field.TypeString, value) + if value, ok := tu.mutation.ParamDefs(); ok { + _spec.SetField(tome.FieldParamDefs, field.TypeString, value) } - if tu.mutation.ParametersCleared() { - _spec.ClearField(tome.FieldParameters, field.TypeString) + if tu.mutation.ParamDefsCleared() { + _spec.ClearField(tome.FieldParamDefs, field.TypeString) } if value, ok := tu.mutation.Hash(); ok { _spec.SetField(tome.FieldHash, field.TypeString, value) @@ -311,6 +272,7 @@ func (tu *TomeUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + tu.mutation.done = true return n, nil } @@ -322,7 +284,7 @@ type TomeUpdateOne struct { mutation *TomeMutation } -// SetLastModifiedAt sets the "lastModifiedAt" field. +// SetLastModifiedAt sets the "last_modified_at" field. func (tuo *TomeUpdateOne) SetLastModifiedAt(t time.Time) *TomeUpdateOne { tuo.mutation.SetLastModifiedAt(t) return tuo @@ -340,23 +302,23 @@ func (tuo *TomeUpdateOne) SetDescription(s string) *TomeUpdateOne { return tuo } -// SetParameters sets the "parameters" field. -func (tuo *TomeUpdateOne) SetParameters(s string) *TomeUpdateOne { - tuo.mutation.SetParameters(s) +// SetParamDefs sets the "param_defs" field. +func (tuo *TomeUpdateOne) SetParamDefs(s string) *TomeUpdateOne { + tuo.mutation.SetParamDefs(s) return tuo } -// SetNillableParameters sets the "parameters" field if the given value is not nil. -func (tuo *TomeUpdateOne) SetNillableParameters(s *string) *TomeUpdateOne { +// SetNillableParamDefs sets the "param_defs" field if the given value is not nil. +func (tuo *TomeUpdateOne) SetNillableParamDefs(s *string) *TomeUpdateOne { if s != nil { - tuo.SetParameters(*s) + tuo.SetParamDefs(*s) } return tuo } -// ClearParameters clears the value of the "parameters" field. -func (tuo *TomeUpdateOne) ClearParameters() *TomeUpdateOne { - tuo.mutation.ClearParameters() +// ClearParamDefs clears the value of the "param_defs" field. +func (tuo *TomeUpdateOne) ClearParamDefs() *TomeUpdateOne { + tuo.mutation.ClearParamDefs() return tuo } @@ -413,6 +375,12 @@ func (tuo *TomeUpdateOne) RemoveFiles(f ...*File) *TomeUpdateOne { return tuo.RemoveFileIDs(ids...) } +// Where appends a list predicates to the TomeUpdate builder. +func (tuo *TomeUpdateOne) Where(ps ...predicate.Tome) *TomeUpdateOne { + tuo.mutation.Where(ps...) + return tuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (tuo *TomeUpdateOne) Select(field string, fields ...string) *TomeUpdateOne { @@ -422,49 +390,10 @@ func (tuo *TomeUpdateOne) Select(field string, fields ...string) *TomeUpdateOne // Save executes the query and returns the updated Tome entity. func (tuo *TomeUpdateOne) Save(ctx context.Context) (*Tome, error) { - var ( - err error - node *Tome - ) if err := tuo.defaults(); err != nil { return nil, err } - if len(tuo.hooks) == 0 { - if err = tuo.check(); err != nil { - return nil, err - } - node, err = tuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TomeMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = tuo.check(); err != nil { - return nil, err - } - tuo.mutation = mutation - node, err = tuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(tuo.hooks) - 1; i >= 0; i-- { - if tuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = tuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, tuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Tome) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from TomeMutation", v) - } - node = nv - } - return node, err + return withHooks[*Tome, TomeMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -517,16 +446,10 @@ func (tuo *TomeUpdateOne) check() error { } func (tuo *TomeUpdateOne) sqlSave(ctx context.Context) (_node *Tome, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: tome.Table, - Columns: tome.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: tome.FieldID, - }, - }, + if err := tuo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(tome.Table, tome.Columns, sqlgraph.NewFieldSpec(tome.FieldID, field.TypeInt)) id, ok := tuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Tome.id" for update`)} @@ -560,11 +483,11 @@ func (tuo *TomeUpdateOne) sqlSave(ctx context.Context) (_node *Tome, err error) if value, ok := tuo.mutation.Description(); ok { _spec.SetField(tome.FieldDescription, field.TypeString, value) } - if value, ok := tuo.mutation.Parameters(); ok { - _spec.SetField(tome.FieldParameters, field.TypeString, value) + if value, ok := tuo.mutation.ParamDefs(); ok { + _spec.SetField(tome.FieldParamDefs, field.TypeString, value) } - if tuo.mutation.ParametersCleared() { - _spec.ClearField(tome.FieldParameters, field.TypeString) + if tuo.mutation.ParamDefsCleared() { + _spec.ClearField(tome.FieldParamDefs, field.TypeString) } if value, ok := tuo.mutation.Hash(); ok { _spec.SetField(tome.FieldHash, field.TypeString, value) @@ -637,5 +560,6 @@ func (tuo *TomeUpdateOne) sqlSave(ctx context.Context) (_node *Tome, err error) } return nil, err } + tuo.mutation.done = true return _node, nil } diff --git a/tavern/ent/user.go b/tavern/ent/user.go index 7a6964277..d38accecd 100644 --- a/tavern/ent/user.go +++ b/tavern/ent/user.go @@ -16,17 +16,17 @@ type User struct { // ID of the ent. ID int `json:"id,omitempty"` // The name displayed for the user - Name string `json:"Name,omitempty"` + Name string `json:"name,omitempty"` // OAuth Subject ID of the user - OAuthID string `json:"-"` + OauthID string `json:"-"` // URL to the user's profile photo. - PhotoURL string `json:"PhotoURL,omitempty"` + PhotoURL string `json:"photo_url,omitempty"` // The session token currently authenticating the user SessionToken string `json:"-"` // True if the user is active and able to authenticate - IsActivated bool `json:"IsActivated,omitempty"` + IsActivated bool `json:"is_activated,omitempty"` // True if the user is an Admin - IsAdmin bool `json:"IsAdmin,omitempty"` + IsAdmin bool `json:"is_admin,omitempty"` } // scanValues returns the types for scanning values from sql.Rows. @@ -38,7 +38,7 @@ func (*User) scanValues(columns []string) ([]any, error) { values[i] = new(sql.NullBool) case user.FieldID: values[i] = new(sql.NullInt64) - case user.FieldName, user.FieldOAuthID, user.FieldPhotoURL, user.FieldSessionToken: + case user.FieldName, user.FieldOauthID, user.FieldPhotoURL, user.FieldSessionToken: values[i] = new(sql.NullString) default: return nil, fmt.Errorf("unexpected column %q for type User", columns[i]) @@ -63,37 +63,37 @@ func (u *User) assignValues(columns []string, values []any) error { u.ID = int(value.Int64) case user.FieldName: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field Name", values[i]) + return fmt.Errorf("unexpected type %T for field name", values[i]) } else if value.Valid { u.Name = value.String } - case user.FieldOAuthID: + case user.FieldOauthID: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field OAuthID", values[i]) + return fmt.Errorf("unexpected type %T for field oauth_id", values[i]) } else if value.Valid { - u.OAuthID = value.String + u.OauthID = value.String } case user.FieldPhotoURL: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field PhotoURL", values[i]) + return fmt.Errorf("unexpected type %T for field photo_url", values[i]) } else if value.Valid { u.PhotoURL = value.String } case user.FieldSessionToken: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field SessionToken", values[i]) + return fmt.Errorf("unexpected type %T for field session_token", values[i]) } else if value.Valid { u.SessionToken = value.String } case user.FieldIsActivated: if value, ok := values[i].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field IsActivated", values[i]) + return fmt.Errorf("unexpected type %T for field is_activated", values[i]) } else if value.Valid { u.IsActivated = value.Bool } case user.FieldIsAdmin: if value, ok := values[i].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field IsAdmin", values[i]) + return fmt.Errorf("unexpected type %T for field is_admin", values[i]) } else if value.Valid { u.IsAdmin = value.Bool } @@ -106,7 +106,7 @@ func (u *User) assignValues(columns []string, values []any) error { // Note that you need to call User.Unwrap() before calling this method if this User // was returned from a transaction, and the transaction was committed or rolled back. func (u *User) Update() *UserUpdateOne { - return (&UserClient{config: u.config}).UpdateOne(u) + return NewUserClient(u.config).UpdateOne(u) } // Unwrap unwraps the User entity that was returned from a transaction after it was closed, @@ -125,20 +125,20 @@ func (u *User) String() string { var builder strings.Builder builder.WriteString("User(") builder.WriteString(fmt.Sprintf("id=%v, ", u.ID)) - builder.WriteString("Name=") + builder.WriteString("name=") builder.WriteString(u.Name) builder.WriteString(", ") - builder.WriteString("OAuthID=") + builder.WriteString("oauth_id=") builder.WriteString(", ") - builder.WriteString("PhotoURL=") + builder.WriteString("photo_url=") builder.WriteString(u.PhotoURL) builder.WriteString(", ") - builder.WriteString("SessionToken=") + builder.WriteString("session_token=") builder.WriteString(", ") - builder.WriteString("IsActivated=") + builder.WriteString("is_activated=") builder.WriteString(fmt.Sprintf("%v", u.IsActivated)) builder.WriteString(", ") - builder.WriteString("IsAdmin=") + builder.WriteString("is_admin=") builder.WriteString(fmt.Sprintf("%v", u.IsAdmin)) builder.WriteByte(')') return builder.String() @@ -146,9 +146,3 @@ func (u *User) String() string { // Users is a parsable slice of User. type Users []*User - -func (u Users) config(cfg config) { - for _i := range u { - u[_i].config = cfg - } -} diff --git a/tavern/ent/user/user.go b/tavern/ent/user/user.go index 41c116b41..018a93244 100644 --- a/tavern/ent/user/user.go +++ b/tavern/ent/user/user.go @@ -9,15 +9,15 @@ const ( FieldID = "id" // FieldName holds the string denoting the name field in the database. FieldName = "name" - // FieldOAuthID holds the string denoting the oauthid field in the database. - FieldOAuthID = "oauth_id" - // FieldPhotoURL holds the string denoting the photourl field in the database. + // FieldOauthID holds the string denoting the oauth_id field in the database. + FieldOauthID = "oauth_id" + // FieldPhotoURL holds the string denoting the photo_url field in the database. FieldPhotoURL = "photo_url" - // FieldSessionToken holds the string denoting the sessiontoken field in the database. + // FieldSessionToken holds the string denoting the session_token field in the database. FieldSessionToken = "session_token" - // FieldIsActivated holds the string denoting the isactivated field in the database. + // FieldIsActivated holds the string denoting the is_activated field in the database. FieldIsActivated = "is_activated" - // FieldIsAdmin holds the string denoting the isadmin field in the database. + // FieldIsAdmin holds the string denoting the is_admin field in the database. FieldIsAdmin = "is_admin" // Table holds the table name of the user in the database. Table = "users" @@ -27,7 +27,7 @@ const ( var Columns = []string{ FieldID, FieldName, - FieldOAuthID, + FieldOauthID, FieldPhotoURL, FieldSessionToken, FieldIsActivated, @@ -45,14 +45,14 @@ func ValidColumn(column string) bool { } var ( - // NameValidator is a validator for the "Name" field. It is called by the builders before save. + // NameValidator is a validator for the "name" field. It is called by the builders before save. NameValidator func(string) error - // DefaultSessionToken holds the default value on creation for the "SessionToken" field. + // DefaultSessionToken holds the default value on creation for the "session_token" field. DefaultSessionToken func() string - // SessionTokenValidator is a validator for the "SessionToken" field. It is called by the builders before save. + // SessionTokenValidator is a validator for the "session_token" field. It is called by the builders before save. SessionTokenValidator func(string) error - // DefaultIsActivated holds the default value on creation for the "IsActivated" field. + // DefaultIsActivated holds the default value on creation for the "is_activated" field. DefaultIsActivated bool - // DefaultIsAdmin holds the default value on creation for the "IsAdmin" field. + // DefaultIsAdmin holds the default value on creation for the "is_admin" field. DefaultIsAdmin bool ) diff --git a/tavern/ent/user/where.go b/tavern/ent/user/where.go index 9c35c075a..e24ac83b9 100644 --- a/tavern/ent/user/where.go +++ b/tavern/ent/user/where.go @@ -9,539 +9,357 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.User { - return predicate.User(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.User(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.User { - return predicate.User(func(s *sql.Selector) { - v := make([]any, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.User(sql.FieldLTE(FieldID, id)) } -// Name applies equality check predicate on the "Name" field. It's identical to NameEQ. +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldEQ(FieldName, v)) } -// OAuthID applies equality check predicate on the "OAuthID" field. It's identical to OAuthIDEQ. -func OAuthID(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldOAuthID), v)) - }) +// OauthID applies equality check predicate on the "oauth_id" field. It's identical to OauthIDEQ. +func OauthID(v string) predicate.User { + return predicate.User(sql.FieldEQ(FieldOauthID, v)) } -// PhotoURL applies equality check predicate on the "PhotoURL" field. It's identical to PhotoURLEQ. +// PhotoURL applies equality check predicate on the "photo_url" field. It's identical to PhotoURLEQ. func PhotoURL(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldEQ(FieldPhotoURL, v)) } -// SessionToken applies equality check predicate on the "SessionToken" field. It's identical to SessionTokenEQ. +// SessionToken applies equality check predicate on the "session_token" field. It's identical to SessionTokenEQ. func SessionToken(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldEQ(FieldSessionToken, v)) } -// IsActivated applies equality check predicate on the "IsActivated" field. It's identical to IsActivatedEQ. +// IsActivated applies equality check predicate on the "is_activated" field. It's identical to IsActivatedEQ. func IsActivated(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldIsActivated), v)) - }) + return predicate.User(sql.FieldEQ(FieldIsActivated, v)) } -// IsAdmin applies equality check predicate on the "IsAdmin" field. It's identical to IsAdminEQ. +// IsAdmin applies equality check predicate on the "is_admin" field. It's identical to IsAdminEQ. func IsAdmin(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldIsAdmin), v)) - }) + return predicate.User(sql.FieldEQ(FieldIsAdmin, v)) } -// NameEQ applies the EQ predicate on the "Name" field. +// NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldEQ(FieldName, v)) } -// NameNEQ applies the NEQ predicate on the "Name" field. +// NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldNEQ(FieldName, v)) } -// NameIn applies the In predicate on the "Name" field. +// NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.User(sql.FieldIn(FieldName, vs...)) } -// NameNotIn applies the NotIn predicate on the "Name" field. +// NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldName, vs...)) } -// NameGT applies the GT predicate on the "Name" field. +// NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldGT(FieldName, v)) } -// NameGTE applies the GTE predicate on the "Name" field. +// NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldGTE(FieldName, v)) } -// NameLT applies the LT predicate on the "Name" field. +// NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldLT(FieldName, v)) } -// NameLTE applies the LTE predicate on the "Name" field. +// NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldLTE(FieldName, v)) } -// NameContains applies the Contains predicate on the "Name" field. +// NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldContains(FieldName, v)) } -// NameHasPrefix applies the HasPrefix predicate on the "Name" field. +// NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldHasPrefix(FieldName, v)) } -// NameHasSuffix applies the HasSuffix predicate on the "Name" field. +// NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldHasSuffix(FieldName, v)) } -// NameEqualFold applies the EqualFold predicate on the "Name" field. +// NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldEqualFold(FieldName, v)) } -// NameContainsFold applies the ContainsFold predicate on the "Name" field. +// NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.User(sql.FieldContainsFold(FieldName, v)) } -// OAuthIDEQ applies the EQ predicate on the "OAuthID" field. -func OAuthIDEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldOAuthID), v)) - }) +// OauthIDEQ applies the EQ predicate on the "oauth_id" field. +func OauthIDEQ(v string) predicate.User { + return predicate.User(sql.FieldEQ(FieldOauthID, v)) } -// OAuthIDNEQ applies the NEQ predicate on the "OAuthID" field. -func OAuthIDNEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldOAuthID), v)) - }) +// OauthIDNEQ applies the NEQ predicate on the "oauth_id" field. +func OauthIDNEQ(v string) predicate.User { + return predicate.User(sql.FieldNEQ(FieldOauthID, v)) } -// OAuthIDIn applies the In predicate on the "OAuthID" field. -func OAuthIDIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldOAuthID), v...)) - }) +// OauthIDIn applies the In predicate on the "oauth_id" field. +func OauthIDIn(vs ...string) predicate.User { + return predicate.User(sql.FieldIn(FieldOauthID, vs...)) } -// OAuthIDNotIn applies the NotIn predicate on the "OAuthID" field. -func OAuthIDNotIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldOAuthID), v...)) - }) +// OauthIDNotIn applies the NotIn predicate on the "oauth_id" field. +func OauthIDNotIn(vs ...string) predicate.User { + return predicate.User(sql.FieldNotIn(FieldOauthID, vs...)) } -// OAuthIDGT applies the GT predicate on the "OAuthID" field. -func OAuthIDGT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldOAuthID), v)) - }) +// OauthIDGT applies the GT predicate on the "oauth_id" field. +func OauthIDGT(v string) predicate.User { + return predicate.User(sql.FieldGT(FieldOauthID, v)) } -// OAuthIDGTE applies the GTE predicate on the "OAuthID" field. -func OAuthIDGTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldOAuthID), v)) - }) +// OauthIDGTE applies the GTE predicate on the "oauth_id" field. +func OauthIDGTE(v string) predicate.User { + return predicate.User(sql.FieldGTE(FieldOauthID, v)) } -// OAuthIDLT applies the LT predicate on the "OAuthID" field. -func OAuthIDLT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldOAuthID), v)) - }) +// OauthIDLT applies the LT predicate on the "oauth_id" field. +func OauthIDLT(v string) predicate.User { + return predicate.User(sql.FieldLT(FieldOauthID, v)) } -// OAuthIDLTE applies the LTE predicate on the "OAuthID" field. -func OAuthIDLTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldOAuthID), v)) - }) +// OauthIDLTE applies the LTE predicate on the "oauth_id" field. +func OauthIDLTE(v string) predicate.User { + return predicate.User(sql.FieldLTE(FieldOauthID, v)) } -// OAuthIDContains applies the Contains predicate on the "OAuthID" field. -func OAuthIDContains(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldOAuthID), v)) - }) +// OauthIDContains applies the Contains predicate on the "oauth_id" field. +func OauthIDContains(v string) predicate.User { + return predicate.User(sql.FieldContains(FieldOauthID, v)) } -// OAuthIDHasPrefix applies the HasPrefix predicate on the "OAuthID" field. -func OAuthIDHasPrefix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldOAuthID), v)) - }) +// OauthIDHasPrefix applies the HasPrefix predicate on the "oauth_id" field. +func OauthIDHasPrefix(v string) predicate.User { + return predicate.User(sql.FieldHasPrefix(FieldOauthID, v)) } -// OAuthIDHasSuffix applies the HasSuffix predicate on the "OAuthID" field. -func OAuthIDHasSuffix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldOAuthID), v)) - }) +// OauthIDHasSuffix applies the HasSuffix predicate on the "oauth_id" field. +func OauthIDHasSuffix(v string) predicate.User { + return predicate.User(sql.FieldHasSuffix(FieldOauthID, v)) } -// OAuthIDEqualFold applies the EqualFold predicate on the "OAuthID" field. -func OAuthIDEqualFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldOAuthID), v)) - }) +// OauthIDEqualFold applies the EqualFold predicate on the "oauth_id" field. +func OauthIDEqualFold(v string) predicate.User { + return predicate.User(sql.FieldEqualFold(FieldOauthID, v)) } -// OAuthIDContainsFold applies the ContainsFold predicate on the "OAuthID" field. -func OAuthIDContainsFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldOAuthID), v)) - }) +// OauthIDContainsFold applies the ContainsFold predicate on the "oauth_id" field. +func OauthIDContainsFold(v string) predicate.User { + return predicate.User(sql.FieldContainsFold(FieldOauthID, v)) } -// PhotoURLEQ applies the EQ predicate on the "PhotoURL" field. +// PhotoURLEQ applies the EQ predicate on the "photo_url" field. func PhotoURLEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldEQ(FieldPhotoURL, v)) } -// PhotoURLNEQ applies the NEQ predicate on the "PhotoURL" field. +// PhotoURLNEQ applies the NEQ predicate on the "photo_url" field. func PhotoURLNEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldNEQ(FieldPhotoURL, v)) } -// PhotoURLIn applies the In predicate on the "PhotoURL" field. +// PhotoURLIn applies the In predicate on the "photo_url" field. func PhotoURLIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldPhotoURL), v...)) - }) + return predicate.User(sql.FieldIn(FieldPhotoURL, vs...)) } -// PhotoURLNotIn applies the NotIn predicate on the "PhotoURL" field. +// PhotoURLNotIn applies the NotIn predicate on the "photo_url" field. func PhotoURLNotIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldPhotoURL), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldPhotoURL, vs...)) } -// PhotoURLGT applies the GT predicate on the "PhotoURL" field. +// PhotoURLGT applies the GT predicate on the "photo_url" field. func PhotoURLGT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldGT(FieldPhotoURL, v)) } -// PhotoURLGTE applies the GTE predicate on the "PhotoURL" field. +// PhotoURLGTE applies the GTE predicate on the "photo_url" field. func PhotoURLGTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldGTE(FieldPhotoURL, v)) } -// PhotoURLLT applies the LT predicate on the "PhotoURL" field. +// PhotoURLLT applies the LT predicate on the "photo_url" field. func PhotoURLLT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldLT(FieldPhotoURL, v)) } -// PhotoURLLTE applies the LTE predicate on the "PhotoURL" field. +// PhotoURLLTE applies the LTE predicate on the "photo_url" field. func PhotoURLLTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldLTE(FieldPhotoURL, v)) } -// PhotoURLContains applies the Contains predicate on the "PhotoURL" field. +// PhotoURLContains applies the Contains predicate on the "photo_url" field. func PhotoURLContains(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldContains(FieldPhotoURL, v)) } -// PhotoURLHasPrefix applies the HasPrefix predicate on the "PhotoURL" field. +// PhotoURLHasPrefix applies the HasPrefix predicate on the "photo_url" field. func PhotoURLHasPrefix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldHasPrefix(FieldPhotoURL, v)) } -// PhotoURLHasSuffix applies the HasSuffix predicate on the "PhotoURL" field. +// PhotoURLHasSuffix applies the HasSuffix predicate on the "photo_url" field. func PhotoURLHasSuffix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldHasSuffix(FieldPhotoURL, v)) } -// PhotoURLEqualFold applies the EqualFold predicate on the "PhotoURL" field. +// PhotoURLEqualFold applies the EqualFold predicate on the "photo_url" field. func PhotoURLEqualFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldEqualFold(FieldPhotoURL, v)) } -// PhotoURLContainsFold applies the ContainsFold predicate on the "PhotoURL" field. +// PhotoURLContainsFold applies the ContainsFold predicate on the "photo_url" field. func PhotoURLContainsFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldPhotoURL), v)) - }) + return predicate.User(sql.FieldContainsFold(FieldPhotoURL, v)) } -// SessionTokenEQ applies the EQ predicate on the "SessionToken" field. +// SessionTokenEQ applies the EQ predicate on the "session_token" field. func SessionTokenEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldEQ(FieldSessionToken, v)) } -// SessionTokenNEQ applies the NEQ predicate on the "SessionToken" field. +// SessionTokenNEQ applies the NEQ predicate on the "session_token" field. func SessionTokenNEQ(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldNEQ(FieldSessionToken, v)) } -// SessionTokenIn applies the In predicate on the "SessionToken" field. +// SessionTokenIn applies the In predicate on the "session_token" field. func SessionTokenIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldSessionToken), v...)) - }) + return predicate.User(sql.FieldIn(FieldSessionToken, vs...)) } -// SessionTokenNotIn applies the NotIn predicate on the "SessionToken" field. +// SessionTokenNotIn applies the NotIn predicate on the "session_token" field. func SessionTokenNotIn(vs ...string) predicate.User { - v := make([]any, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldSessionToken), v...)) - }) + return predicate.User(sql.FieldNotIn(FieldSessionToken, vs...)) } -// SessionTokenGT applies the GT predicate on the "SessionToken" field. +// SessionTokenGT applies the GT predicate on the "session_token" field. func SessionTokenGT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldGT(FieldSessionToken, v)) } -// SessionTokenGTE applies the GTE predicate on the "SessionToken" field. +// SessionTokenGTE applies the GTE predicate on the "session_token" field. func SessionTokenGTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldGTE(FieldSessionToken, v)) } -// SessionTokenLT applies the LT predicate on the "SessionToken" field. +// SessionTokenLT applies the LT predicate on the "session_token" field. func SessionTokenLT(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldLT(FieldSessionToken, v)) } -// SessionTokenLTE applies the LTE predicate on the "SessionToken" field. +// SessionTokenLTE applies the LTE predicate on the "session_token" field. func SessionTokenLTE(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldLTE(FieldSessionToken, v)) } -// SessionTokenContains applies the Contains predicate on the "SessionToken" field. +// SessionTokenContains applies the Contains predicate on the "session_token" field. func SessionTokenContains(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldContains(FieldSessionToken, v)) } -// SessionTokenHasPrefix applies the HasPrefix predicate on the "SessionToken" field. +// SessionTokenHasPrefix applies the HasPrefix predicate on the "session_token" field. func SessionTokenHasPrefix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldHasPrefix(FieldSessionToken, v)) } -// SessionTokenHasSuffix applies the HasSuffix predicate on the "SessionToken" field. +// SessionTokenHasSuffix applies the HasSuffix predicate on the "session_token" field. func SessionTokenHasSuffix(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldHasSuffix(FieldSessionToken, v)) } -// SessionTokenEqualFold applies the EqualFold predicate on the "SessionToken" field. +// SessionTokenEqualFold applies the EqualFold predicate on the "session_token" field. func SessionTokenEqualFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldEqualFold(FieldSessionToken, v)) } -// SessionTokenContainsFold applies the ContainsFold predicate on the "SessionToken" field. +// SessionTokenContainsFold applies the ContainsFold predicate on the "session_token" field. func SessionTokenContainsFold(v string) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldSessionToken), v)) - }) + return predicate.User(sql.FieldContainsFold(FieldSessionToken, v)) } -// IsActivatedEQ applies the EQ predicate on the "IsActivated" field. +// IsActivatedEQ applies the EQ predicate on the "is_activated" field. func IsActivatedEQ(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldIsActivated), v)) - }) + return predicate.User(sql.FieldEQ(FieldIsActivated, v)) } -// IsActivatedNEQ applies the NEQ predicate on the "IsActivated" field. +// IsActivatedNEQ applies the NEQ predicate on the "is_activated" field. func IsActivatedNEQ(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldIsActivated), v)) - }) + return predicate.User(sql.FieldNEQ(FieldIsActivated, v)) } -// IsAdminEQ applies the EQ predicate on the "IsAdmin" field. +// IsAdminEQ applies the EQ predicate on the "is_admin" field. func IsAdminEQ(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldIsAdmin), v)) - }) + return predicate.User(sql.FieldEQ(FieldIsAdmin, v)) } -// IsAdminNEQ applies the NEQ predicate on the "IsAdmin" field. +// IsAdminNEQ applies the NEQ predicate on the "is_admin" field. func IsAdminNEQ(v bool) predicate.User { - return predicate.User(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldIsAdmin), v)) - }) + return predicate.User(sql.FieldNEQ(FieldIsAdmin, v)) } // And groups predicates with the AND operator between them. diff --git a/tavern/ent/user_create.go b/tavern/ent/user_create.go index e5feca84e..a7f2311e4 100644 --- a/tavern/ent/user_create.go +++ b/tavern/ent/user_create.go @@ -19,31 +19,31 @@ type UserCreate struct { hooks []Hook } -// SetName sets the "Name" field. +// SetName sets the "name" field. func (uc *UserCreate) SetName(s string) *UserCreate { uc.mutation.SetName(s) return uc } -// SetOAuthID sets the "OAuthID" field. -func (uc *UserCreate) SetOAuthID(s string) *UserCreate { - uc.mutation.SetOAuthID(s) +// SetOauthID sets the "oauth_id" field. +func (uc *UserCreate) SetOauthID(s string) *UserCreate { + uc.mutation.SetOauthID(s) return uc } -// SetPhotoURL sets the "PhotoURL" field. +// SetPhotoURL sets the "photo_url" field. func (uc *UserCreate) SetPhotoURL(s string) *UserCreate { uc.mutation.SetPhotoURL(s) return uc } -// SetSessionToken sets the "SessionToken" field. +// SetSessionToken sets the "session_token" field. func (uc *UserCreate) SetSessionToken(s string) *UserCreate { uc.mutation.SetSessionToken(s) return uc } -// SetNillableSessionToken sets the "SessionToken" field if the given value is not nil. +// SetNillableSessionToken sets the "session_token" field if the given value is not nil. func (uc *UserCreate) SetNillableSessionToken(s *string) *UserCreate { if s != nil { uc.SetSessionToken(*s) @@ -51,13 +51,13 @@ func (uc *UserCreate) SetNillableSessionToken(s *string) *UserCreate { return uc } -// SetIsActivated sets the "IsActivated" field. +// SetIsActivated sets the "is_activated" field. func (uc *UserCreate) SetIsActivated(b bool) *UserCreate { uc.mutation.SetIsActivated(b) return uc } -// SetNillableIsActivated sets the "IsActivated" field if the given value is not nil. +// SetNillableIsActivated sets the "is_activated" field if the given value is not nil. func (uc *UserCreate) SetNillableIsActivated(b *bool) *UserCreate { if b != nil { uc.SetIsActivated(*b) @@ -65,13 +65,13 @@ func (uc *UserCreate) SetNillableIsActivated(b *bool) *UserCreate { return uc } -// SetIsAdmin sets the "IsAdmin" field. +// SetIsAdmin sets the "is_admin" field. func (uc *UserCreate) SetIsAdmin(b bool) *UserCreate { uc.mutation.SetIsAdmin(b) return uc } -// SetNillableIsAdmin sets the "IsAdmin" field if the given value is not nil. +// SetNillableIsAdmin sets the "is_admin" field if the given value is not nil. func (uc *UserCreate) SetNillableIsAdmin(b *bool) *UserCreate { if b != nil { uc.SetIsAdmin(*b) @@ -86,50 +86,8 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { - var ( - err error - node *User - ) uc.defaults() - if len(uc.hooks) == 0 { - if err = uc.check(); err != nil { - return nil, err - } - node, err = uc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = uc.check(); err != nil { - return nil, err - } - uc.mutation = mutation - if node, err = uc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(uc.hooks) - 1; i >= 0; i-- { - if uc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = uc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, uc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*User) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from UserMutation", v) - } - node = nv - } - return node, err + return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -173,37 +131,40 @@ func (uc *UserCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (uc *UserCreate) check() error { if _, ok := uc.mutation.Name(); !ok { - return &ValidationError{Name: "Name", err: errors.New(`ent: missing required field "User.Name"`)} + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "User.name"`)} } if v, ok := uc.mutation.Name(); ok { if err := user.NameValidator(v); err != nil { - return &ValidationError{Name: "Name", err: fmt.Errorf(`ent: validator failed for field "User.Name": %w`, err)} + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "User.name": %w`, err)} } } - if _, ok := uc.mutation.OAuthID(); !ok { - return &ValidationError{Name: "OAuthID", err: errors.New(`ent: missing required field "User.OAuthID"`)} + if _, ok := uc.mutation.OauthID(); !ok { + return &ValidationError{Name: "oauth_id", err: errors.New(`ent: missing required field "User.oauth_id"`)} } if _, ok := uc.mutation.PhotoURL(); !ok { - return &ValidationError{Name: "PhotoURL", err: errors.New(`ent: missing required field "User.PhotoURL"`)} + return &ValidationError{Name: "photo_url", err: errors.New(`ent: missing required field "User.photo_url"`)} } if _, ok := uc.mutation.SessionToken(); !ok { - return &ValidationError{Name: "SessionToken", err: errors.New(`ent: missing required field "User.SessionToken"`)} + return &ValidationError{Name: "session_token", err: errors.New(`ent: missing required field "User.session_token"`)} } if v, ok := uc.mutation.SessionToken(); ok { if err := user.SessionTokenValidator(v); err != nil { - return &ValidationError{Name: "SessionToken", err: fmt.Errorf(`ent: validator failed for field "User.SessionToken": %w`, err)} + return &ValidationError{Name: "session_token", err: fmt.Errorf(`ent: validator failed for field "User.session_token": %w`, err)} } } if _, ok := uc.mutation.IsActivated(); !ok { - return &ValidationError{Name: "IsActivated", err: errors.New(`ent: missing required field "User.IsActivated"`)} + return &ValidationError{Name: "is_activated", err: errors.New(`ent: missing required field "User.is_activated"`)} } if _, ok := uc.mutation.IsAdmin(); !ok { - return &ValidationError{Name: "IsAdmin", err: errors.New(`ent: missing required field "User.IsAdmin"`)} + return &ValidationError{Name: "is_admin", err: errors.New(`ent: missing required field "User.is_admin"`)} } return nil } func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { + if err := uc.check(); err != nil { + return nil, err + } _node, _spec := uc.createSpec() if err := sqlgraph.CreateNode(ctx, uc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -213,27 +174,23 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { } id := _spec.ID.Value.(int64) _node.ID = int(id) + uc.mutation.id = &_node.ID + uc.mutation.done = true return _node, nil } func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { var ( _node = &User{config: uc.config} - _spec = &sqlgraph.CreateSpec{ - Table: user.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: user.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) ) if value, ok := uc.mutation.Name(); ok { _spec.SetField(user.FieldName, field.TypeString, value) _node.Name = value } - if value, ok := uc.mutation.OAuthID(); ok { - _spec.SetField(user.FieldOAuthID, field.TypeString, value) - _node.OAuthID = value + if value, ok := uc.mutation.OauthID(); ok { + _spec.SetField(user.FieldOauthID, field.TypeString, value) + _node.OauthID = value } if value, ok := uc.mutation.PhotoURL(); ok { _spec.SetField(user.FieldPhotoURL, field.TypeString, value) diff --git a/tavern/ent/user_delete.go b/tavern/ent/user_delete.go index 948968601..72d58c91f 100644 --- a/tavern/ent/user_delete.go +++ b/tavern/ent/user_delete.go @@ -4,7 +4,6 @@ package ent import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ud.hooks) == 0 { - affected, err = ud.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ud.mutation = mutation - affected, err = ud.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ud.hooks) - 1; i >= 0; i-- { - if ud.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ud.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ud.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (ud *UserDelete) ExecX(ctx context.Context) int { } func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: user.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) if ps := ud.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + ud.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type UserDeleteOne struct { ud *UserDelete } +// Where appends a list predicates to the UserDelete builder. +func (udo *UserDeleteOne) Where(ps ...predicate.User) *UserDeleteOne { + udo.ud.mutation.Where(ps...) + return udo +} + // Exec executes the deletion query. func (udo *UserDeleteOne) Exec(ctx context.Context) error { n, err := udo.ud.Exec(ctx) @@ -111,5 +82,7 @@ func (udo *UserDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (udo *UserDeleteOne) ExecX(ctx context.Context) { - udo.ud.ExecX(ctx) + if err := udo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/tavern/ent/user_query.go b/tavern/ent/user_query.go index cd1eb253c..da2a5bc1d 100644 --- a/tavern/ent/user_query.go +++ b/tavern/ent/user_query.go @@ -17,11 +17,9 @@ import ( // UserQuery is the builder for querying User entities. type UserQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.User modifiers []func(*sql.Selector) loadTotal []func(context.Context, []*User) error @@ -36,26 +34,26 @@ func (uq *UserQuery) Where(ps ...predicate.User) *UserQuery { return uq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (uq *UserQuery) Limit(limit int) *UserQuery { - uq.limit = &limit + uq.ctx.Limit = &limit return uq } -// Offset adds an offset step to the query. +// Offset to start from. func (uq *UserQuery) Offset(offset int) *UserQuery { - uq.offset = &offset + uq.ctx.Offset = &offset return uq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (uq *UserQuery) Unique(unique bool) *UserQuery { - uq.unique = &unique + uq.ctx.Unique = &unique return uq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery { uq.order = append(uq.order, o...) return uq @@ -64,7 +62,7 @@ func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery { // First returns the first User entity from the query. // Returns a *NotFoundError when no User was found. func (uq *UserQuery) First(ctx context.Context) (*User, error) { - nodes, err := uq.Limit(1).All(ctx) + nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, "First")) if err != nil { return nil, err } @@ -87,7 +85,7 @@ func (uq *UserQuery) FirstX(ctx context.Context) *User { // Returns a *NotFoundError when no User ID was found. func (uq *UserQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = uq.Limit(1).IDs(ctx); err != nil { + if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -110,7 +108,7 @@ func (uq *UserQuery) FirstIDX(ctx context.Context) int { // Returns a *NotSingularError when more than one User entity is found. // Returns a *NotFoundError when no User entities are found. func (uq *UserQuery) Only(ctx context.Context) (*User, error) { - nodes, err := uq.Limit(2).All(ctx) + nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, "Only")) if err != nil { return nil, err } @@ -138,7 +136,7 @@ func (uq *UserQuery) OnlyX(ctx context.Context) *User { // Returns a *NotFoundError when no entities are found. func (uq *UserQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = uq.Limit(2).IDs(ctx); err != nil { + if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -163,10 +161,12 @@ func (uq *UserQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of Users. func (uq *UserQuery) All(ctx context.Context) ([]*User, error) { + ctx = setContextOp(ctx, uq.ctx, "All") if err := uq.prepareQuery(ctx); err != nil { return nil, err } - return uq.sqlAll(ctx) + qr := querierAll[[]*User, *UserQuery]() + return withInterceptors[[]*User](ctx, uq, qr, uq.inters) } // AllX is like All, but panics if an error occurs. @@ -179,9 +179,12 @@ func (uq *UserQuery) AllX(ctx context.Context) []*User { } // IDs executes the query and returns a list of User IDs. -func (uq *UserQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := uq.Select(user.FieldID).Scan(ctx, &ids); err != nil { +func (uq *UserQuery) IDs(ctx context.Context) (ids []int, err error) { + if uq.ctx.Unique == nil && uq.path != nil { + uq.Unique(true) + } + ctx = setContextOp(ctx, uq.ctx, "IDs") + if err = uq.Select(user.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -198,10 +201,11 @@ func (uq *UserQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (uq *UserQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, uq.ctx, "Count") if err := uq.prepareQuery(ctx); err != nil { return 0, err } - return uq.sqlCount(ctx) + return withInterceptors[int](ctx, uq, querierCount[*UserQuery](), uq.inters) } // CountX is like Count, but panics if an error occurs. @@ -215,10 +219,15 @@ func (uq *UserQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (uq *UserQuery) Exist(ctx context.Context) (bool, error) { - if err := uq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, uq.ctx, "Exist") + switch _, err := uq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil } - return uq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -238,14 +247,13 @@ func (uq *UserQuery) Clone() *UserQuery { } return &UserQuery{ config: uq.config, - limit: uq.limit, - offset: uq.offset, + ctx: uq.ctx.Clone(), order: append([]OrderFunc{}, uq.order...), + inters: append([]Interceptor{}, uq.inters...), predicates: append([]predicate.User{}, uq.predicates...), // clone intermediate query. - sql: uq.sql.Clone(), - path: uq.path, - unique: uq.unique, + sql: uq.sql.Clone(), + path: uq.path, } } @@ -255,7 +263,7 @@ func (uq *UserQuery) Clone() *UserQuery { // Example: // // var v []struct { -// Name string `json:"Name,omitempty"` +// Name string `json:"name,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -264,16 +272,11 @@ func (uq *UserQuery) Clone() *UserQuery { // Aggregate(ent.Count()). // Scan(ctx, &v) func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { - grbuild := &UserGroupBy{config: uq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := uq.prepareQuery(ctx); err != nil { - return nil, err - } - return uq.sqlQuery(ctx), nil - } + uq.ctx.Fields = append([]string{field}, fields...) + grbuild := &UserGroupBy{build: uq} + grbuild.flds = &uq.ctx.Fields grbuild.label = user.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -283,18 +286,18 @@ func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { // Example: // // var v []struct { -// Name string `json:"Name,omitempty"` +// Name string `json:"name,omitempty"` // } // // client.User.Query(). // Select(user.FieldName). // Scan(ctx, &v) func (uq *UserQuery) Select(fields ...string) *UserSelect { - uq.fields = append(uq.fields, fields...) - selbuild := &UserSelect{UserQuery: uq} - selbuild.label = user.Label - selbuild.flds, selbuild.scan = &uq.fields, selbuild.Scan - return selbuild + uq.ctx.Fields = append(uq.ctx.Fields, fields...) + sbuild := &UserSelect{UserQuery: uq} + sbuild.label = user.Label + sbuild.flds, sbuild.scan = &uq.ctx.Fields, sbuild.Scan + return sbuild } // Aggregate returns a UserSelect configured with the given aggregations. @@ -303,7 +306,17 @@ func (uq *UserQuery) Aggregate(fns ...AggregateFunc) *UserSelect { } func (uq *UserQuery) prepareQuery(ctx context.Context) error { - for _, f := range uq.fields { + for _, inter := range uq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, uq); err != nil { + return err + } + } + } + for _, f := range uq.ctx.Fields { if !user.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } @@ -356,41 +369,22 @@ func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) { if len(uq.modifiers) > 0 { _spec.Modifiers = uq.modifiers } - _spec.Node.Columns = uq.fields - if len(uq.fields) > 0 { - _spec.Unique = uq.unique != nil && *uq.unique + _spec.Node.Columns = uq.ctx.Fields + if len(uq.ctx.Fields) > 0 { + _spec.Unique = uq.ctx.Unique != nil && *uq.ctx.Unique } return sqlgraph.CountNodes(ctx, uq.driver, _spec) } -func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) { - switch _, err := uq.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - Columns: user.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: user.FieldID, - }, - }, - From: uq.sql, - Unique: true, - } - if unique := uq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) + _spec.From = uq.sql + if unique := uq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if uq.path != nil { + _spec.Unique = true } - if fields := uq.fields; len(fields) > 0 { + if fields := uq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, user.FieldID) for i := range fields { @@ -406,10 +400,10 @@ func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := uq.limit; limit != nil { + if limit := uq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := uq.offset; offset != nil { + if offset := uq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := uq.order; len(ps) > 0 { @@ -425,7 +419,7 @@ func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec { func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(uq.driver.Dialect()) t1 := builder.Table(user.Table) - columns := uq.fields + columns := uq.ctx.Fields if len(columns) == 0 { columns = user.Columns } @@ -434,7 +428,7 @@ func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = uq.sql selector.Select(selector.Columns(columns...)...) } - if uq.unique != nil && *uq.unique { + if uq.ctx.Unique != nil && *uq.ctx.Unique { selector.Distinct() } for _, p := range uq.predicates { @@ -443,12 +437,12 @@ func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range uq.order { p(selector) } - if offset := uq.offset; offset != nil { + if offset := uq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := uq.limit; limit != nil { + if limit := uq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -456,13 +450,8 @@ func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { // UserGroupBy is the group-by builder for User entities. type UserGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *UserQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -471,58 +460,46 @@ func (ugb *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy { return ugb } -// Scan applies the group-by query and scans the result into the given value. +// Scan applies the selector query and scans the result into the given value. func (ugb *UserGroupBy) Scan(ctx context.Context, v any) error { - query, err := ugb.path(ctx) - if err != nil { + ctx = setContextOp(ctx, ugb.build.ctx, "GroupBy") + if err := ugb.build.prepareQuery(ctx); err != nil { return err } - ugb.sql = query - return ugb.sqlScan(ctx, v) + return scanWithInterceptors[*UserQuery, *UserGroupBy](ctx, ugb.build, ugb, ugb.build.inters, v) } -func (ugb *UserGroupBy) sqlScan(ctx context.Context, v any) error { - for _, f := range ugb.fields { - if !user.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} +func (ugb *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(ugb.fns)) + for _, fn := range ugb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*ugb.flds)+len(ugb.fns)) + for _, f := range *ugb.flds { + columns = append(columns, selector.C(f)) } + columns = append(columns, aggregation...) + selector.Select(columns...) } - selector := ugb.sqlQuery() + selector.GroupBy(selector.Columns(*ugb.flds...)...) if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := ugb.driver.Query(ctx, query, args, rows); err != nil { + if err := ugb.build.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (ugb *UserGroupBy) sqlQuery() *sql.Selector { - selector := ugb.sql.Select() - aggregation := make([]string, 0, len(ugb.fns)) - for _, fn := range ugb.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(ugb.fields)+len(ugb.fns)) - for _, f := range ugb.fields { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(ugb.fields...)...) -} - // UserSelect is the builder for selecting fields of User entities. type UserSelect struct { *UserQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector } // Aggregate adds the given aggregation functions to the selector query. @@ -533,26 +510,27 @@ func (us *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect { // Scan applies the selector query and scans the result into the given value. func (us *UserSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, us.ctx, "Select") if err := us.prepareQuery(ctx); err != nil { return err } - us.sql = us.UserQuery.sqlQuery(ctx) - return us.sqlScan(ctx, v) + return scanWithInterceptors[*UserQuery, *UserSelect](ctx, us.UserQuery, us, us.inters, v) } -func (us *UserSelect) sqlScan(ctx context.Context, v any) error { +func (us *UserSelect) sqlScan(ctx context.Context, root *UserQuery, v any) error { + selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(us.fns)) for _, fn := range us.fns { - aggregation = append(aggregation, fn(us.sql)) + aggregation = append(aggregation, fn(selector)) } switch n := len(*us.selector.flds); { case n == 0 && len(aggregation) > 0: - us.sql.Select(aggregation...) + selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: - us.sql.AppendSelect(aggregation...) + selector.AppendSelect(aggregation...) } rows := &sql.Rows{} - query, args := us.sql.Query() + query, args := selector.Query() if err := us.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/tavern/ent/user_update.go b/tavern/ent/user_update.go index 3db70725b..152287199 100644 --- a/tavern/ent/user_update.go +++ b/tavern/ent/user_update.go @@ -27,25 +27,25 @@ func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate { return uu } -// SetName sets the "Name" field. +// SetName sets the "name" field. func (uu *UserUpdate) SetName(s string) *UserUpdate { uu.mutation.SetName(s) return uu } -// SetPhotoURL sets the "PhotoURL" field. +// SetPhotoURL sets the "photo_url" field. func (uu *UserUpdate) SetPhotoURL(s string) *UserUpdate { uu.mutation.SetPhotoURL(s) return uu } -// SetSessionToken sets the "SessionToken" field. +// SetSessionToken sets the "session_token" field. func (uu *UserUpdate) SetSessionToken(s string) *UserUpdate { uu.mutation.SetSessionToken(s) return uu } -// SetNillableSessionToken sets the "SessionToken" field if the given value is not nil. +// SetNillableSessionToken sets the "session_token" field if the given value is not nil. func (uu *UserUpdate) SetNillableSessionToken(s *string) *UserUpdate { if s != nil { uu.SetSessionToken(*s) @@ -53,13 +53,13 @@ func (uu *UserUpdate) SetNillableSessionToken(s *string) *UserUpdate { return uu } -// SetIsActivated sets the "IsActivated" field. +// SetIsActivated sets the "is_activated" field. func (uu *UserUpdate) SetIsActivated(b bool) *UserUpdate { uu.mutation.SetIsActivated(b) return uu } -// SetNillableIsActivated sets the "IsActivated" field if the given value is not nil. +// SetNillableIsActivated sets the "is_activated" field if the given value is not nil. func (uu *UserUpdate) SetNillableIsActivated(b *bool) *UserUpdate { if b != nil { uu.SetIsActivated(*b) @@ -67,13 +67,13 @@ func (uu *UserUpdate) SetNillableIsActivated(b *bool) *UserUpdate { return uu } -// SetIsAdmin sets the "IsAdmin" field. +// SetIsAdmin sets the "is_admin" field. func (uu *UserUpdate) SetIsAdmin(b bool) *UserUpdate { uu.mutation.SetIsAdmin(b) return uu } -// SetNillableIsAdmin sets the "IsAdmin" field if the given value is not nil. +// SetNillableIsAdmin sets the "is_admin" field if the given value is not nil. func (uu *UserUpdate) SetNillableIsAdmin(b *bool) *UserUpdate { if b != nil { uu.SetIsAdmin(*b) @@ -88,40 +88,7 @@ func (uu *UserUpdate) Mutation() *UserMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(uu.hooks) == 0 { - if err = uu.check(); err != nil { - return 0, err - } - affected, err = uu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = uu.check(); err != nil { - return 0, err - } - uu.mutation = mutation - affected, err = uu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(uu.hooks) - 1; i >= 0; i-- { - if uu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = uu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, uu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -150,28 +117,22 @@ func (uu *UserUpdate) ExecX(ctx context.Context) { func (uu *UserUpdate) check() error { if v, ok := uu.mutation.Name(); ok { if err := user.NameValidator(v); err != nil { - return &ValidationError{Name: "Name", err: fmt.Errorf(`ent: validator failed for field "User.Name": %w`, err)} + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "User.name": %w`, err)} } } if v, ok := uu.mutation.SessionToken(); ok { if err := user.SessionTokenValidator(v); err != nil { - return &ValidationError{Name: "SessionToken", err: fmt.Errorf(`ent: validator failed for field "User.SessionToken": %w`, err)} + return &ValidationError{Name: "session_token", err: fmt.Errorf(`ent: validator failed for field "User.session_token": %w`, err)} } } return nil } func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - Columns: user.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: user.FieldID, - }, - }, + if err := uu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) if ps := uu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -202,6 +163,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + uu.mutation.done = true return n, nil } @@ -213,25 +175,25 @@ type UserUpdateOne struct { mutation *UserMutation } -// SetName sets the "Name" field. +// SetName sets the "name" field. func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { uuo.mutation.SetName(s) return uuo } -// SetPhotoURL sets the "PhotoURL" field. +// SetPhotoURL sets the "photo_url" field. func (uuo *UserUpdateOne) SetPhotoURL(s string) *UserUpdateOne { uuo.mutation.SetPhotoURL(s) return uuo } -// SetSessionToken sets the "SessionToken" field. +// SetSessionToken sets the "session_token" field. func (uuo *UserUpdateOne) SetSessionToken(s string) *UserUpdateOne { uuo.mutation.SetSessionToken(s) return uuo } -// SetNillableSessionToken sets the "SessionToken" field if the given value is not nil. +// SetNillableSessionToken sets the "session_token" field if the given value is not nil. func (uuo *UserUpdateOne) SetNillableSessionToken(s *string) *UserUpdateOne { if s != nil { uuo.SetSessionToken(*s) @@ -239,13 +201,13 @@ func (uuo *UserUpdateOne) SetNillableSessionToken(s *string) *UserUpdateOne { return uuo } -// SetIsActivated sets the "IsActivated" field. +// SetIsActivated sets the "is_activated" field. func (uuo *UserUpdateOne) SetIsActivated(b bool) *UserUpdateOne { uuo.mutation.SetIsActivated(b) return uuo } -// SetNillableIsActivated sets the "IsActivated" field if the given value is not nil. +// SetNillableIsActivated sets the "is_activated" field if the given value is not nil. func (uuo *UserUpdateOne) SetNillableIsActivated(b *bool) *UserUpdateOne { if b != nil { uuo.SetIsActivated(*b) @@ -253,13 +215,13 @@ func (uuo *UserUpdateOne) SetNillableIsActivated(b *bool) *UserUpdateOne { return uuo } -// SetIsAdmin sets the "IsAdmin" field. +// SetIsAdmin sets the "is_admin" field. func (uuo *UserUpdateOne) SetIsAdmin(b bool) *UserUpdateOne { uuo.mutation.SetIsAdmin(b) return uuo } -// SetNillableIsAdmin sets the "IsAdmin" field if the given value is not nil. +// SetNillableIsAdmin sets the "is_admin" field if the given value is not nil. func (uuo *UserUpdateOne) SetNillableIsAdmin(b *bool) *UserUpdateOne { if b != nil { uuo.SetIsAdmin(*b) @@ -272,6 +234,12 @@ func (uuo *UserUpdateOne) Mutation() *UserMutation { return uuo.mutation } +// Where appends a list predicates to the UserUpdate builder. +func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne { + uuo.mutation.Where(ps...) + return uuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne { @@ -281,46 +249,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { - var ( - err error - node *User - ) - if len(uuo.hooks) == 0 { - if err = uuo.check(); err != nil { - return nil, err - } - node, err = uuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = uuo.check(); err != nil { - return nil, err - } - uuo.mutation = mutation - node, err = uuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(uuo.hooks) - 1; i >= 0; i-- { - if uuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = uuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, uuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*User) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from UserMutation", v) - } - node = nv - } - return node, err + return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -349,28 +278,22 @@ func (uuo *UserUpdateOne) ExecX(ctx context.Context) { func (uuo *UserUpdateOne) check() error { if v, ok := uuo.mutation.Name(); ok { if err := user.NameValidator(v); err != nil { - return &ValidationError{Name: "Name", err: fmt.Errorf(`ent: validator failed for field "User.Name": %w`, err)} + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "User.name": %w`, err)} } } if v, ok := uuo.mutation.SessionToken(); ok { if err := user.SessionTokenValidator(v); err != nil { - return &ValidationError{Name: "SessionToken", err: fmt.Errorf(`ent: validator failed for field "User.SessionToken": %w`, err)} + return &ValidationError{Name: "session_token", err: fmt.Errorf(`ent: validator failed for field "User.session_token": %w`, err)} } } return nil } func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - Columns: user.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: user.FieldID, - }, - }, + if err := uuo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) id, ok := uuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)} @@ -421,5 +344,6 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) } return nil, err } + uuo.mutation.done = true return _node, nil } diff --git a/tavern/env.go b/tavern/env.go new file mode 100644 index 000000000..80471e72e --- /dev/null +++ b/tavern/env.go @@ -0,0 +1,44 @@ +package main + +import ( + "log" + "os" + "strconv" +) + +// EnvString represents a string that is configured using environment variables. +type EnvString struct { + Key string + Default string +} + +// String parsed from the environment variable. +func (env EnvString) String() string { + if val := os.Getenv(env.Key); val != "" { + return val + } + if env.Default != "" { + log.Printf("[WARN] No value for '%s' provided, defaulting to %s", env.Key, env.Default) + } + return env.Default +} + +// EnvInteger represents an integer that is configured using environment variables. +type EnvInteger struct { + Key string + Default int +} + +// Int parsed from the environment variable. +func (env EnvInteger) Int() int { + envVar := os.Getenv(env.Key) + if envVar == "" { + log.Printf("[WARN] No value for '%s' provided, defaulting to %d", env.Key, env.Default) + return env.Default + } + val, err := strconv.Atoi(envVar) + if err != nil { + log.Fatalf("[FATAL] Invalid integer value (%q) provided for %s: %v", envVar, env.Key, err) + } + return val +} diff --git a/tavern/graphql/ent.resolvers.go b/tavern/graphql/ent.resolvers.go index 85adcc8c1..d1ca800b0 100644 --- a/tavern/graphql/ent.resolvers.go +++ b/tavern/graphql/ent.resolvers.go @@ -2,6 +2,7 @@ package graphql // This file will be automatically regenerated based on the schema, any resolver implementations // will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.26 import ( "context" diff --git a/tavern/graphql/generated/ent.generated.go b/tavern/graphql/generated/ent.generated.go index 989eff413..0dd867460 100644 --- a/tavern/graphql/generated/ent.generated.go +++ b/tavern/graphql/generated/ent.generated.go @@ -14,6 +14,7 @@ import ( "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" "github.com/kcarretto/realm/tavern/ent" + "github.com/kcarretto/realm/tavern/ent/session" "github.com/kcarretto/realm/tavern/ent/tag" "github.com/vektah/gqlparser/v2/ast" ) @@ -147,8 +148,8 @@ func (ec *executionContext) fieldContext_File_id(ctx context.Context, field grap return fc, nil } -func (ec *executionContext) _File_createdat(ctx context.Context, field graphql.CollectedField, obj *ent.File) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_File_createdat(ctx, field) +func (ec *executionContext) _File_createdAt(ctx context.Context, field graphql.CollectedField, obj *ent.File) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_File_createdAt(ctx, field) if err != nil { return graphql.Null } @@ -178,7 +179,7 @@ func (ec *executionContext) _File_createdat(ctx context.Context, field graphql.C return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_File_createdat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_File_createdAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "File", Field: field, @@ -191,8 +192,8 @@ func (ec *executionContext) fieldContext_File_createdat(ctx context.Context, fie return fc, nil } -func (ec *executionContext) _File_lastmodifiedat(ctx context.Context, field graphql.CollectedField, obj *ent.File) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_File_lastmodifiedat(ctx, field) +func (ec *executionContext) _File_lastModifiedAt(ctx context.Context, field graphql.CollectedField, obj *ent.File) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_File_lastModifiedAt(ctx, field) if err != nil { return graphql.Null } @@ -222,7 +223,7 @@ func (ec *executionContext) _File_lastmodifiedat(ctx context.Context, field grap return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_File_lastmodifiedat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_File_lastModifiedAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "File", Field: field, @@ -411,8 +412,8 @@ func (ec *executionContext) fieldContext_Job_id(ctx context.Context, field graph return fc, nil } -func (ec *executionContext) _Job_createdat(ctx context.Context, field graphql.CollectedField, obj *ent.Job) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Job_createdat(ctx, field) +func (ec *executionContext) _Job_createdAt(ctx context.Context, field graphql.CollectedField, obj *ent.Job) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Job_createdAt(ctx, field) if err != nil { return graphql.Null } @@ -442,7 +443,7 @@ func (ec *executionContext) _Job_createdat(ctx context.Context, field graphql.Co return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Job_createdat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Job_createdAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Job", Field: field, @@ -455,8 +456,8 @@ func (ec *executionContext) fieldContext_Job_createdat(ctx context.Context, fiel return fc, nil } -func (ec *executionContext) _Job_lastmodifiedat(ctx context.Context, field graphql.CollectedField, obj *ent.Job) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Job_lastmodifiedat(ctx, field) +func (ec *executionContext) _Job_lastModifiedAt(ctx context.Context, field graphql.CollectedField, obj *ent.Job) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Job_lastModifiedAt(ctx, field) if err != nil { return graphql.Null } @@ -486,7 +487,7 @@ func (ec *executionContext) _Job_lastmodifiedat(ctx context.Context, field graph return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Job_lastmodifiedat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Job_lastModifiedAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Job", Field: field, @@ -625,16 +626,16 @@ func (ec *executionContext) fieldContext_Job_tome(ctx context.Context, field gra switch field.Name { case "id": return ec.fieldContext_Tome_id(ctx, field) - case "createdat": - return ec.fieldContext_Tome_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_Tome_lastmodifiedat(ctx, field) + case "createdAt": + return ec.fieldContext_Tome_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_Tome_lastModifiedAt(ctx, field) case "name": return ec.fieldContext_Tome_name(ctx, field) case "description": return ec.fieldContext_Tome_description(ctx, field) - case "parameters": - return ec.fieldContext_Tome_parameters(ctx, field) + case "paramDefs": + return ec.fieldContext_Tome_paramDefs(ctx, field) case "eldritch": return ec.fieldContext_Tome_eldritch(ctx, field) case "files": @@ -684,10 +685,10 @@ func (ec *executionContext) fieldContext_Job_bundle(ctx context.Context, field g switch field.Name { case "id": return ec.fieldContext_File_id(ctx, field) - case "createdat": - return ec.fieldContext_File_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_File_lastmodifiedat(ctx, field) + case "createdAt": + return ec.fieldContext_File_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_File_lastModifiedAt(ctx, field) case "name": return ec.fieldContext_File_name(ctx, field) case "size": @@ -739,16 +740,16 @@ func (ec *executionContext) fieldContext_Job_tasks(ctx context.Context, field gr switch field.Name { case "id": return ec.fieldContext_Task_id(ctx, field) - case "createdat": - return ec.fieldContext_Task_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_Task_lastmodifiedat(ctx, field) - case "claimedat": - return ec.fieldContext_Task_claimedat(ctx, field) - case "execstartedat": - return ec.fieldContext_Task_execstartedat(ctx, field) - case "execfinishedat": - return ec.fieldContext_Task_execfinishedat(ctx, field) + case "createdAt": + return ec.fieldContext_Task_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_Task_lastModifiedAt(ctx, field) + case "claimedAt": + return ec.fieldContext_Task_claimedAt(ctx, field) + case "execStartedAt": + return ec.fieldContext_Task_execStartedAt(ctx, field) + case "execFinishedAt": + return ec.fieldContext_Task_execFinishedAt(ctx, field) case "output": return ec.fieldContext_Task_output(ctx, field) case "error": @@ -764,6 +765,59 @@ func (ec *executionContext) fieldContext_Job_tasks(ctx context.Context, field gr return fc, nil } +func (ec *executionContext) _Job_creator(ctx context.Context, field graphql.CollectedField, obj *ent.Job) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Job_creator(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Creator(ctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*ent.User) + fc.Result = res + return ec.marshalOUser2ᚖgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚐUser(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Job_creator(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Job", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_User_id(ctx, field) + case "name": + return ec.fieldContext_User_name(ctx, field) + case "photoURL": + return ec.fieldContext_User_photoURL(ctx, field) + case "isActivated": + return ec.fieldContext_User_isActivated(ctx, field) + case "isAdmin": + return ec.fieldContext_User_isAdmin(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type User", field.Name) + }, + } + return fc, nil +} + func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *ent.PageInfo) (ret graphql.Marshaler) { fc, err := ec.fieldContext_PageInfo_hasNextPage(ctx, field) if err != nil { @@ -1082,10 +1136,10 @@ func (ec *executionContext) fieldContext_Query_files(ctx context.Context, field switch field.Name { case "id": return ec.fieldContext_File_id(ctx, field) - case "createdat": - return ec.fieldContext_File_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_File_lastmodifiedat(ctx, field) + case "createdAt": + return ec.fieldContext_File_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_File_lastModifiedAt(ctx, field) case "name": return ec.fieldContext_File_name(ctx, field) case "size": @@ -1140,10 +1194,10 @@ func (ec *executionContext) fieldContext_Query_jobs(ctx context.Context, field g switch field.Name { case "id": return ec.fieldContext_Job_id(ctx, field) - case "createdat": - return ec.fieldContext_Job_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_Job_lastmodifiedat(ctx, field) + case "createdAt": + return ec.fieldContext_Job_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_Job_lastModifiedAt(ctx, field) case "name": return ec.fieldContext_Job_name(ctx, field) case "parameters": @@ -1154,6 +1208,8 @@ func (ec *executionContext) fieldContext_Query_jobs(ctx context.Context, field g return ec.fieldContext_Job_bundle(ctx, field) case "tasks": return ec.fieldContext_Job_tasks(ctx, field) + case "creator": + return ec.fieldContext_Job_creator(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Job", field.Name) }, @@ -1221,12 +1277,16 @@ func (ec *executionContext) fieldContext_Query_sessions(ctx context.Context, fie return ec.fieldContext_Session_hostname(ctx, field) case "identifier": return ec.fieldContext_Session_identifier(ctx, field) - case "agentidentifier": - return ec.fieldContext_Session_agentidentifier(ctx, field) - case "hostidentifier": - return ec.fieldContext_Session_hostidentifier(ctx, field) - case "lastseenat": - return ec.fieldContext_Session_lastseenat(ctx, field) + case "agentIdentifier": + return ec.fieldContext_Session_agentIdentifier(ctx, field) + case "hostIdentifier": + return ec.fieldContext_Session_hostIdentifier(ctx, field) + case "hostPrimaryIP": + return ec.fieldContext_Session_hostPrimaryIP(ctx, field) + case "hostPlatform": + return ec.fieldContext_Session_hostPlatform(ctx, field) + case "lastSeenAt": + return ec.fieldContext_Session_lastSeenAt(ctx, field) case "tags": return ec.fieldContext_Session_tags(ctx, field) case "tasks": @@ -1333,16 +1393,16 @@ func (ec *executionContext) fieldContext_Query_tomes(ctx context.Context, field switch field.Name { case "id": return ec.fieldContext_Tome_id(ctx, field) - case "createdat": - return ec.fieldContext_Tome_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_Tome_lastmodifiedat(ctx, field) + case "createdAt": + return ec.fieldContext_Tome_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_Tome_lastModifiedAt(ctx, field) case "name": return ec.fieldContext_Tome_name(ctx, field) case "description": return ec.fieldContext_Tome_description(ctx, field) - case "parameters": - return ec.fieldContext_Tome_parameters(ctx, field) + case "paramDefs": + return ec.fieldContext_Tome_paramDefs(ctx, field) case "eldritch": return ec.fieldContext_Tome_eldritch(ctx, field) case "files": @@ -1397,12 +1457,12 @@ func (ec *executionContext) fieldContext_Query_users(ctx context.Context, field return ec.fieldContext_User_id(ctx, field) case "name": return ec.fieldContext_User_name(ctx, field) - case "photourl": - return ec.fieldContext_User_photourl(ctx, field) - case "isactivated": - return ec.fieldContext_User_isactivated(ctx, field) - case "isadmin": - return ec.fieldContext_User_isadmin(ctx, field) + case "photoURL": + return ec.fieldContext_User_photoURL(ctx, field) + case "isActivated": + return ec.fieldContext_User_isActivated(ctx, field) + case "isAdmin": + return ec.fieldContext_User_isAdmin(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, @@ -1753,8 +1813,8 @@ func (ec *executionContext) fieldContext_Session_identifier(ctx context.Context, return fc, nil } -func (ec *executionContext) _Session_agentidentifier(ctx context.Context, field graphql.CollectedField, obj *ent.Session) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Session_agentidentifier(ctx, field) +func (ec *executionContext) _Session_agentIdentifier(ctx context.Context, field graphql.CollectedField, obj *ent.Session) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Session_agentIdentifier(ctx, field) if err != nil { return graphql.Null } @@ -1781,7 +1841,7 @@ func (ec *executionContext) _Session_agentidentifier(ctx context.Context, field return ec.marshalOString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Session_agentidentifier(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Session_agentIdentifier(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Session", Field: field, @@ -1794,8 +1854,8 @@ func (ec *executionContext) fieldContext_Session_agentidentifier(ctx context.Con return fc, nil } -func (ec *executionContext) _Session_hostidentifier(ctx context.Context, field graphql.CollectedField, obj *ent.Session) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Session_hostidentifier(ctx, field) +func (ec *executionContext) _Session_hostIdentifier(ctx context.Context, field graphql.CollectedField, obj *ent.Session) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Session_hostIdentifier(ctx, field) if err != nil { return graphql.Null } @@ -1822,7 +1882,48 @@ func (ec *executionContext) _Session_hostidentifier(ctx context.Context, field g return ec.marshalOString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Session_hostidentifier(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Session_hostIdentifier(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Session", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Session_hostPrimaryIP(ctx context.Context, field graphql.CollectedField, obj *ent.Session) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Session_hostPrimaryIP(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.HostPrimaryIP, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Session_hostPrimaryIP(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Session", Field: field, @@ -1835,8 +1936,52 @@ func (ec *executionContext) fieldContext_Session_hostidentifier(ctx context.Cont return fc, nil } -func (ec *executionContext) _Session_lastseenat(ctx context.Context, field graphql.CollectedField, obj *ent.Session) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Session_lastseenat(ctx, field) +func (ec *executionContext) _Session_hostPlatform(ctx context.Context, field graphql.CollectedField, obj *ent.Session) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Session_hostPlatform(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.HostPlatform, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(session.HostPlatform) + fc.Result = res + return ec.marshalNSessionSessionHostPlatform2githubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatform(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Session_hostPlatform(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Session", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type SessionSessionHostPlatform does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Session_lastSeenAt(ctx context.Context, field graphql.CollectedField, obj *ent.Session) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Session_lastSeenAt(ctx, field) if err != nil { return graphql.Null } @@ -1863,7 +2008,7 @@ func (ec *executionContext) _Session_lastseenat(ctx context.Context, field graph return ec.marshalOTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Session_lastseenat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Session_lastSeenAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Session", Field: field, @@ -1965,16 +2110,16 @@ func (ec *executionContext) fieldContext_Session_tasks(ctx context.Context, fiel switch field.Name { case "id": return ec.fieldContext_Task_id(ctx, field) - case "createdat": - return ec.fieldContext_Task_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_Task_lastmodifiedat(ctx, field) - case "claimedat": - return ec.fieldContext_Task_claimedat(ctx, field) - case "execstartedat": - return ec.fieldContext_Task_execstartedat(ctx, field) - case "execfinishedat": - return ec.fieldContext_Task_execfinishedat(ctx, field) + case "createdAt": + return ec.fieldContext_Task_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_Task_lastModifiedAt(ctx, field) + case "claimedAt": + return ec.fieldContext_Task_claimedAt(ctx, field) + case "execStartedAt": + return ec.fieldContext_Task_execStartedAt(ctx, field) + case "execFinishedAt": + return ec.fieldContext_Task_execFinishedAt(ctx, field) case "output": return ec.fieldContext_Task_output(ctx, field) case "error": @@ -2168,12 +2313,16 @@ func (ec *executionContext) fieldContext_Tag_sessions(ctx context.Context, field return ec.fieldContext_Session_hostname(ctx, field) case "identifier": return ec.fieldContext_Session_identifier(ctx, field) - case "agentidentifier": - return ec.fieldContext_Session_agentidentifier(ctx, field) - case "hostidentifier": - return ec.fieldContext_Session_hostidentifier(ctx, field) - case "lastseenat": - return ec.fieldContext_Session_lastseenat(ctx, field) + case "agentIdentifier": + return ec.fieldContext_Session_agentIdentifier(ctx, field) + case "hostIdentifier": + return ec.fieldContext_Session_hostIdentifier(ctx, field) + case "hostPrimaryIP": + return ec.fieldContext_Session_hostPrimaryIP(ctx, field) + case "hostPlatform": + return ec.fieldContext_Session_hostPlatform(ctx, field) + case "lastSeenAt": + return ec.fieldContext_Session_lastSeenAt(ctx, field) case "tags": return ec.fieldContext_Session_tags(ctx, field) case "tasks": @@ -2229,8 +2378,8 @@ func (ec *executionContext) fieldContext_Task_id(ctx context.Context, field grap return fc, nil } -func (ec *executionContext) _Task_createdat(ctx context.Context, field graphql.CollectedField, obj *ent.Task) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Task_createdat(ctx, field) +func (ec *executionContext) _Task_createdAt(ctx context.Context, field graphql.CollectedField, obj *ent.Task) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Task_createdAt(ctx, field) if err != nil { return graphql.Null } @@ -2260,7 +2409,7 @@ func (ec *executionContext) _Task_createdat(ctx context.Context, field graphql.C return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Task_createdat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Task_createdAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Task", Field: field, @@ -2273,8 +2422,8 @@ func (ec *executionContext) fieldContext_Task_createdat(ctx context.Context, fie return fc, nil } -func (ec *executionContext) _Task_lastmodifiedat(ctx context.Context, field graphql.CollectedField, obj *ent.Task) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Task_lastmodifiedat(ctx, field) +func (ec *executionContext) _Task_lastModifiedAt(ctx context.Context, field graphql.CollectedField, obj *ent.Task) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Task_lastModifiedAt(ctx, field) if err != nil { return graphql.Null } @@ -2304,7 +2453,7 @@ func (ec *executionContext) _Task_lastmodifiedat(ctx context.Context, field grap return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Task_lastmodifiedat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Task_lastModifiedAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Task", Field: field, @@ -2317,8 +2466,8 @@ func (ec *executionContext) fieldContext_Task_lastmodifiedat(ctx context.Context return fc, nil } -func (ec *executionContext) _Task_claimedat(ctx context.Context, field graphql.CollectedField, obj *ent.Task) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Task_claimedat(ctx, field) +func (ec *executionContext) _Task_claimedAt(ctx context.Context, field graphql.CollectedField, obj *ent.Task) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Task_claimedAt(ctx, field) if err != nil { return graphql.Null } @@ -2345,7 +2494,7 @@ func (ec *executionContext) _Task_claimedat(ctx context.Context, field graphql.C return ec.marshalOTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Task_claimedat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Task_claimedAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Task", Field: field, @@ -2358,8 +2507,8 @@ func (ec *executionContext) fieldContext_Task_claimedat(ctx context.Context, fie return fc, nil } -func (ec *executionContext) _Task_execstartedat(ctx context.Context, field graphql.CollectedField, obj *ent.Task) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Task_execstartedat(ctx, field) +func (ec *executionContext) _Task_execStartedAt(ctx context.Context, field graphql.CollectedField, obj *ent.Task) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Task_execStartedAt(ctx, field) if err != nil { return graphql.Null } @@ -2386,7 +2535,7 @@ func (ec *executionContext) _Task_execstartedat(ctx context.Context, field graph return ec.marshalOTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Task_execstartedat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Task_execStartedAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Task", Field: field, @@ -2399,8 +2548,8 @@ func (ec *executionContext) fieldContext_Task_execstartedat(ctx context.Context, return fc, nil } -func (ec *executionContext) _Task_execfinishedat(ctx context.Context, field graphql.CollectedField, obj *ent.Task) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Task_execfinishedat(ctx, field) +func (ec *executionContext) _Task_execFinishedAt(ctx context.Context, field graphql.CollectedField, obj *ent.Task) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Task_execFinishedAt(ctx, field) if err != nil { return graphql.Null } @@ -2427,7 +2576,7 @@ func (ec *executionContext) _Task_execfinishedat(ctx context.Context, field grap return ec.marshalOTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Task_execfinishedat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Task_execFinishedAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Task", Field: field, @@ -2563,10 +2712,10 @@ func (ec *executionContext) fieldContext_Task_job(ctx context.Context, field gra switch field.Name { case "id": return ec.fieldContext_Job_id(ctx, field) - case "createdat": - return ec.fieldContext_Job_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_Job_lastmodifiedat(ctx, field) + case "createdAt": + return ec.fieldContext_Job_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_Job_lastModifiedAt(ctx, field) case "name": return ec.fieldContext_Job_name(ctx, field) case "parameters": @@ -2577,6 +2726,8 @@ func (ec *executionContext) fieldContext_Task_job(ctx context.Context, field gra return ec.fieldContext_Job_bundle(ctx, field) case "tasks": return ec.fieldContext_Job_tasks(ctx, field) + case "creator": + return ec.fieldContext_Job_creator(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Job", field.Name) }, @@ -2633,12 +2784,16 @@ func (ec *executionContext) fieldContext_Task_session(ctx context.Context, field return ec.fieldContext_Session_hostname(ctx, field) case "identifier": return ec.fieldContext_Session_identifier(ctx, field) - case "agentidentifier": - return ec.fieldContext_Session_agentidentifier(ctx, field) - case "hostidentifier": - return ec.fieldContext_Session_hostidentifier(ctx, field) - case "lastseenat": - return ec.fieldContext_Session_lastseenat(ctx, field) + case "agentIdentifier": + return ec.fieldContext_Session_agentIdentifier(ctx, field) + case "hostIdentifier": + return ec.fieldContext_Session_hostIdentifier(ctx, field) + case "hostPrimaryIP": + return ec.fieldContext_Session_hostPrimaryIP(ctx, field) + case "hostPlatform": + return ec.fieldContext_Session_hostPlatform(ctx, field) + case "lastSeenAt": + return ec.fieldContext_Session_lastSeenAt(ctx, field) case "tags": return ec.fieldContext_Session_tags(ctx, field) case "tasks": @@ -2694,8 +2849,8 @@ func (ec *executionContext) fieldContext_Tome_id(ctx context.Context, field grap return fc, nil } -func (ec *executionContext) _Tome_createdat(ctx context.Context, field graphql.CollectedField, obj *ent.Tome) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Tome_createdat(ctx, field) +func (ec *executionContext) _Tome_createdAt(ctx context.Context, field graphql.CollectedField, obj *ent.Tome) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Tome_createdAt(ctx, field) if err != nil { return graphql.Null } @@ -2725,7 +2880,7 @@ func (ec *executionContext) _Tome_createdat(ctx context.Context, field graphql.C return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Tome_createdat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Tome_createdAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Tome", Field: field, @@ -2738,8 +2893,8 @@ func (ec *executionContext) fieldContext_Tome_createdat(ctx context.Context, fie return fc, nil } -func (ec *executionContext) _Tome_lastmodifiedat(ctx context.Context, field graphql.CollectedField, obj *ent.Tome) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Tome_lastmodifiedat(ctx, field) +func (ec *executionContext) _Tome_lastModifiedAt(ctx context.Context, field graphql.CollectedField, obj *ent.Tome) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Tome_lastModifiedAt(ctx, field) if err != nil { return graphql.Null } @@ -2769,7 +2924,7 @@ func (ec *executionContext) _Tome_lastmodifiedat(ctx context.Context, field grap return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Tome_lastmodifiedat(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Tome_lastModifiedAt(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Tome", Field: field, @@ -2870,8 +3025,8 @@ func (ec *executionContext) fieldContext_Tome_description(ctx context.Context, f return fc, nil } -func (ec *executionContext) _Tome_parameters(ctx context.Context, field graphql.CollectedField, obj *ent.Tome) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Tome_parameters(ctx, field) +func (ec *executionContext) _Tome_paramDefs(ctx context.Context, field graphql.CollectedField, obj *ent.Tome) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Tome_paramDefs(ctx, field) if err != nil { return graphql.Null } @@ -2884,7 +3039,7 @@ func (ec *executionContext) _Tome_parameters(ctx context.Context, field graphql. }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Parameters, nil + return obj.ParamDefs, nil }) if err != nil { ec.Error(ctx, err) @@ -2898,7 +3053,7 @@ func (ec *executionContext) _Tome_parameters(ctx context.Context, field graphql. return ec.marshalOString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Tome_parameters(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Tome_paramDefs(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Tome", Field: field, @@ -2993,10 +3148,10 @@ func (ec *executionContext) fieldContext_Tome_files(ctx context.Context, field g switch field.Name { case "id": return ec.fieldContext_File_id(ctx, field) - case "createdat": - return ec.fieldContext_File_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_File_lastmodifiedat(ctx, field) + case "createdAt": + return ec.fieldContext_File_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_File_lastModifiedAt(ctx, field) case "name": return ec.fieldContext_File_name(ctx, field) case "size": @@ -3098,8 +3253,8 @@ func (ec *executionContext) fieldContext_User_name(ctx context.Context, field gr return fc, nil } -func (ec *executionContext) _User_photourl(ctx context.Context, field graphql.CollectedField, obj *ent.User) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_User_photourl(ctx, field) +func (ec *executionContext) _User_photoURL(ctx context.Context, field graphql.CollectedField, obj *ent.User) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_User_photoURL(ctx, field) if err != nil { return graphql.Null } @@ -3129,7 +3284,7 @@ func (ec *executionContext) _User_photourl(ctx context.Context, field graphql.Co return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_User_photourl(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_User_photoURL(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "User", Field: field, @@ -3142,8 +3297,8 @@ func (ec *executionContext) fieldContext_User_photourl(ctx context.Context, fiel return fc, nil } -func (ec *executionContext) _User_isactivated(ctx context.Context, field graphql.CollectedField, obj *ent.User) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_User_isactivated(ctx, field) +func (ec *executionContext) _User_isActivated(ctx context.Context, field graphql.CollectedField, obj *ent.User) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_User_isActivated(ctx, field) if err != nil { return graphql.Null } @@ -3173,7 +3328,7 @@ func (ec *executionContext) _User_isactivated(ctx context.Context, field graphql return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_User_isactivated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_User_isActivated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "User", Field: field, @@ -3186,8 +3341,8 @@ func (ec *executionContext) fieldContext_User_isactivated(ctx context.Context, f return fc, nil } -func (ec *executionContext) _User_isadmin(ctx context.Context, field graphql.CollectedField, obj *ent.User) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_User_isadmin(ctx, field) +func (ec *executionContext) _User_isAdmin(ctx context.Context, field graphql.CollectedField, obj *ent.User) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_User_isAdmin(ctx, field) if err != nil { return graphql.Null } @@ -3217,7 +3372,7 @@ func (ec *executionContext) _User_isadmin(ctx context.Context, field graphql.Col return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_User_isadmin(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_User_isAdmin(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "User", Field: field, @@ -3329,7 +3484,7 @@ func (ec *executionContext) unmarshalInputCreateTomeInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"name", "description", "parameters", "eldritch", "fileIDs"} + fieldsInOrder := [...]string{"name", "description", "paramDefs", "eldritch", "fileIDs"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -3352,11 +3507,11 @@ func (ec *executionContext) unmarshalInputCreateTomeInput(ctx context.Context, o if err != nil { return it, err } - case "parameters": + case "paramDefs": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parameters")) - it.Parameters, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefs")) + it.ParamDefs, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } @@ -3429,7 +3584,7 @@ func (ec *executionContext) unmarshalInputFileWhereInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdat", "createdatNEQ", "createdatIn", "createdatNotIn", "createdatGT", "createdatGTE", "createdatLT", "createdatLTE", "lastmodifiedat", "lastmodifiedatNEQ", "lastmodifiedatIn", "lastmodifiedatNotIn", "lastmodifiedatGT", "lastmodifiedatGTE", "lastmodifiedatLT", "lastmodifiedatLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "size", "sizeNEQ", "sizeIn", "sizeNotIn", "sizeGT", "sizeGTE", "sizeLT", "sizeLTE", "hash", "hashNEQ", "hashIn", "hashNotIn", "hashGT", "hashGTE", "hashLT", "hashLTE", "hashContains", "hashHasPrefix", "hashHasSuffix", "hashEqualFold", "hashContainsFold"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "lastModifiedAt", "lastModifiedAtNEQ", "lastModifiedAtIn", "lastModifiedAtNotIn", "lastModifiedAtGT", "lastModifiedAtGTE", "lastModifiedAtLT", "lastModifiedAtLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "size", "sizeNEQ", "sizeIn", "sizeNotIn", "sizeGT", "sizeGTE", "sizeLT", "sizeLTE", "hash", "hashNEQ", "hashIn", "hashNotIn", "hashGT", "hashGTE", "hashLT", "hashLTE", "hashContains", "hashHasPrefix", "hashHasSuffix", "hashEqualFold", "hashContainsFold"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -3524,130 +3679,130 @@ func (ec *executionContext) unmarshalInputFileWhereInput(ctx context.Context, ob if err != nil { return it, err } - case "createdat": + case "createdAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAt")) it.CreatedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatNEQ": + case "createdAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNEQ")) it.CreatedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatIn": + case "createdAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtIn")) it.CreatedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "createdatNotIn": + case "createdAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNotIn")) it.CreatedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "createdatGT": + case "createdAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGT")) it.CreatedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatGTE": + case "createdAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGTE")) it.CreatedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatLT": + case "createdAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLT")) it.CreatedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatLTE": + case "createdAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLTE")) it.CreatedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedat": + case "lastModifiedAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAt")) it.LastModifiedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatNEQ": + case "lastModifiedAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtNEQ")) it.LastModifiedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatIn": + case "lastModifiedAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtIn")) it.LastModifiedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "lastmodifiedatNotIn": + case "lastModifiedAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtNotIn")) it.LastModifiedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "lastmodifiedatGT": + case "lastModifiedAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtGT")) it.LastModifiedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatGTE": + case "lastModifiedAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtGTE")) it.LastModifiedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatLT": + case "lastModifiedAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtLT")) it.LastModifiedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatLTE": + case "lastModifiedAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtLTE")) it.LastModifiedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err @@ -3977,7 +4132,7 @@ func (ec *executionContext) unmarshalInputJobWhereInput(ctx context.Context, obj asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdat", "createdatNEQ", "createdatIn", "createdatNotIn", "createdatGT", "createdatGTE", "createdatLT", "createdatLTE", "lastmodifiedat", "lastmodifiedatNEQ", "lastmodifiedatIn", "lastmodifiedatNotIn", "lastmodifiedatGT", "lastmodifiedatGTE", "lastmodifiedatLT", "lastmodifiedatLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "parameters", "parametersNEQ", "parametersIn", "parametersNotIn", "parametersGT", "parametersGTE", "parametersLT", "parametersLTE", "parametersContains", "parametersHasPrefix", "parametersHasSuffix", "parametersIsNil", "parametersNotNil", "parametersEqualFold", "parametersContainsFold", "hasTome", "hasTomeWith", "hasBundle", "hasBundleWith", "hasTasks", "hasTasksWith"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "lastModifiedAt", "lastModifiedAtNEQ", "lastModifiedAtIn", "lastModifiedAtNotIn", "lastModifiedAtGT", "lastModifiedAtGTE", "lastModifiedAtLT", "lastModifiedAtLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "parameters", "parametersNEQ", "parametersIn", "parametersNotIn", "parametersGT", "parametersGTE", "parametersLT", "parametersLTE", "parametersContains", "parametersHasPrefix", "parametersHasSuffix", "parametersIsNil", "parametersNotNil", "parametersEqualFold", "parametersContainsFold", "hasTome", "hasTomeWith", "hasBundle", "hasBundleWith", "hasTasks", "hasTasksWith", "hasCreator", "hasCreatorWith"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -4072,130 +4227,130 @@ func (ec *executionContext) unmarshalInputJobWhereInput(ctx context.Context, obj if err != nil { return it, err } - case "createdat": + case "createdAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAt")) it.CreatedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatNEQ": + case "createdAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNEQ")) it.CreatedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatIn": + case "createdAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtIn")) it.CreatedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "createdatNotIn": + case "createdAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNotIn")) it.CreatedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "createdatGT": + case "createdAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGT")) it.CreatedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatGTE": + case "createdAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGTE")) it.CreatedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatLT": + case "createdAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLT")) it.CreatedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatLTE": + case "createdAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLTE")) it.CreatedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedat": + case "lastModifiedAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAt")) it.LastModifiedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatNEQ": + case "lastModifiedAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtNEQ")) it.LastModifiedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatIn": + case "lastModifiedAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtIn")) it.LastModifiedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "lastmodifiedatNotIn": + case "lastModifiedAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtNotIn")) it.LastModifiedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "lastmodifiedatGT": + case "lastModifiedAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtGT")) it.LastModifiedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatGTE": + case "lastModifiedAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtGTE")) it.LastModifiedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatLT": + case "lastModifiedAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtLT")) it.LastModifiedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatLTE": + case "lastModifiedAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtLTE")) it.LastModifiedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err @@ -4472,6 +4627,22 @@ func (ec *executionContext) unmarshalInputJobWhereInput(ctx context.Context, obj if err != nil { return it, err } + case "hasCreator": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasCreator")) + it.HasCreator, err = ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + case "hasCreatorWith": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hasCreatorWith")) + it.HasCreatorWith, err = ec.unmarshalOUserWhereInput2ᚕᚖgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚐUserWhereInputᚄ(ctx, v) + if err != nil { + return it, err + } } } @@ -4525,7 +4696,7 @@ func (ec *executionContext) unmarshalInputSessionWhereInput(ctx context.Context, asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "principal", "principalNEQ", "principalIn", "principalNotIn", "principalGT", "principalGTE", "principalLT", "principalLTE", "principalContains", "principalHasPrefix", "principalHasSuffix", "principalIsNil", "principalNotNil", "principalEqualFold", "principalContainsFold", "hostname", "hostnameNEQ", "hostnameIn", "hostnameNotIn", "hostnameGT", "hostnameGTE", "hostnameLT", "hostnameLTE", "hostnameContains", "hostnameHasPrefix", "hostnameHasSuffix", "hostnameIsNil", "hostnameNotNil", "hostnameEqualFold", "hostnameContainsFold", "identifier", "identifierNEQ", "identifierIn", "identifierNotIn", "identifierGT", "identifierGTE", "identifierLT", "identifierLTE", "identifierContains", "identifierHasPrefix", "identifierHasSuffix", "identifierEqualFold", "identifierContainsFold", "agentidentifier", "agentidentifierNEQ", "agentidentifierIn", "agentidentifierNotIn", "agentidentifierGT", "agentidentifierGTE", "agentidentifierLT", "agentidentifierLTE", "agentidentifierContains", "agentidentifierHasPrefix", "agentidentifierHasSuffix", "agentidentifierIsNil", "agentidentifierNotNil", "agentidentifierEqualFold", "agentidentifierContainsFold", "hostidentifier", "hostidentifierNEQ", "hostidentifierIn", "hostidentifierNotIn", "hostidentifierGT", "hostidentifierGTE", "hostidentifierLT", "hostidentifierLTE", "hostidentifierContains", "hostidentifierHasPrefix", "hostidentifierHasSuffix", "hostidentifierIsNil", "hostidentifierNotNil", "hostidentifierEqualFold", "hostidentifierContainsFold", "lastseenat", "lastseenatNEQ", "lastseenatIn", "lastseenatNotIn", "lastseenatGT", "lastseenatGTE", "lastseenatLT", "lastseenatLTE", "lastseenatIsNil", "lastseenatNotNil", "hasTags", "hasTagsWith", "hasTasks", "hasTasksWith"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "principal", "principalNEQ", "principalIn", "principalNotIn", "principalGT", "principalGTE", "principalLT", "principalLTE", "principalContains", "principalHasPrefix", "principalHasSuffix", "principalIsNil", "principalNotNil", "principalEqualFold", "principalContainsFold", "hostname", "hostnameNEQ", "hostnameIn", "hostnameNotIn", "hostnameGT", "hostnameGTE", "hostnameLT", "hostnameLTE", "hostnameContains", "hostnameHasPrefix", "hostnameHasSuffix", "hostnameIsNil", "hostnameNotNil", "hostnameEqualFold", "hostnameContainsFold", "identifier", "identifierNEQ", "identifierIn", "identifierNotIn", "identifierGT", "identifierGTE", "identifierLT", "identifierLTE", "identifierContains", "identifierHasPrefix", "identifierHasSuffix", "identifierEqualFold", "identifierContainsFold", "agentIdentifier", "agentIdentifierNEQ", "agentIdentifierIn", "agentIdentifierNotIn", "agentIdentifierGT", "agentIdentifierGTE", "agentIdentifierLT", "agentIdentifierLTE", "agentIdentifierContains", "agentIdentifierHasPrefix", "agentIdentifierHasSuffix", "agentIdentifierIsNil", "agentIdentifierNotNil", "agentIdentifierEqualFold", "agentIdentifierContainsFold", "hostIdentifier", "hostIdentifierNEQ", "hostIdentifierIn", "hostIdentifierNotIn", "hostIdentifierGT", "hostIdentifierGTE", "hostIdentifierLT", "hostIdentifierLTE", "hostIdentifierContains", "hostIdentifierHasPrefix", "hostIdentifierHasSuffix", "hostIdentifierIsNil", "hostIdentifierNotNil", "hostIdentifierEqualFold", "hostIdentifierContainsFold", "hostPrimaryIP", "hostPrimaryIPNEQ", "hostPrimaryIPIn", "hostPrimaryIPNotIn", "hostPrimaryIPGT", "hostPrimaryIPGTE", "hostPrimaryIPLT", "hostPrimaryIPLTE", "hostPrimaryIPContains", "hostPrimaryIPHasPrefix", "hostPrimaryIPHasSuffix", "hostPrimaryIPIsNil", "hostPrimaryIPNotNil", "hostPrimaryIPEqualFold", "hostPrimaryIPContainsFold", "hostPlatform", "hostPlatformNEQ", "hostPlatformIn", "hostPlatformNotIn", "lastSeenAt", "lastSeenAtNEQ", "lastSeenAtIn", "lastSeenAtNotIn", "lastSeenAtGT", "lastSeenAtGTE", "lastSeenAtLT", "lastSeenAtLTE", "lastSeenAtIsNil", "lastSeenAtNotNil", "hasTags", "hasTagsWith", "hasTasks", "hasTasksWith"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -5068,322 +5239,474 @@ func (ec *executionContext) unmarshalInputSessionWhereInput(ctx context.Context, if err != nil { return it, err } - case "agentidentifier": + case "agentIdentifier": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifier")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifier")) it.AgentIdentifier, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "agentidentifierNEQ": + case "agentIdentifierNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierNEQ")) it.AgentIdentifierNEQ, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "agentidentifierIn": + case "agentIdentifierIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierIn")) it.AgentIdentifierIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) if err != nil { return it, err } - case "agentidentifierNotIn": + case "agentIdentifierNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierNotIn")) it.AgentIdentifierNotIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) if err != nil { return it, err } - case "agentidentifierGT": + case "agentIdentifierGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierGT")) it.AgentIdentifierGT, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "agentidentifierGTE": + case "agentIdentifierGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierGTE")) it.AgentIdentifierGTE, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "agentidentifierLT": + case "agentIdentifierLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierLT")) it.AgentIdentifierLT, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "agentidentifierLTE": + case "agentIdentifierLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierLTE")) it.AgentIdentifierLTE, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "agentidentifierContains": + case "agentIdentifierContains": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierContains")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierContains")) it.AgentIdentifierContains, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "agentidentifierHasPrefix": + case "agentIdentifierHasPrefix": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierHasPrefix")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierHasPrefix")) it.AgentIdentifierHasPrefix, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "agentidentifierHasSuffix": + case "agentIdentifierHasSuffix": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierHasSuffix")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierHasSuffix")) it.AgentIdentifierHasSuffix, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "agentidentifierIsNil": + case "agentIdentifierIsNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierIsNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierIsNil")) it.AgentIdentifierIsNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "agentidentifierNotNil": + case "agentIdentifierNotNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierNotNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierNotNil")) it.AgentIdentifierNotNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "agentidentifierEqualFold": + case "agentIdentifierEqualFold": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierEqualFold")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierEqualFold")) it.AgentIdentifierEqualFold, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "agentidentifierContainsFold": + case "agentIdentifierContainsFold": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentidentifierContainsFold")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("agentIdentifierContainsFold")) it.AgentIdentifierContainsFold, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifier": + case "hostIdentifier": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifier")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifier")) it.HostIdentifier, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifierNEQ": + case "hostIdentifierNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierNEQ")) it.HostIdentifierNEQ, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifierIn": + case "hostIdentifierIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierIn")) it.HostIdentifierIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) if err != nil { return it, err } - case "hostidentifierNotIn": + case "hostIdentifierNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierNotIn")) it.HostIdentifierNotIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) if err != nil { return it, err } - case "hostidentifierGT": + case "hostIdentifierGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierGT")) it.HostIdentifierGT, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifierGTE": + case "hostIdentifierGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierGTE")) it.HostIdentifierGTE, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifierLT": + case "hostIdentifierLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierLT")) it.HostIdentifierLT, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifierLTE": + case "hostIdentifierLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierLTE")) it.HostIdentifierLTE, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifierContains": + case "hostIdentifierContains": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierContains")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierContains")) it.HostIdentifierContains, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifierHasPrefix": + case "hostIdentifierHasPrefix": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierHasPrefix")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierHasPrefix")) it.HostIdentifierHasPrefix, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifierHasSuffix": + case "hostIdentifierHasSuffix": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierHasSuffix")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierHasSuffix")) it.HostIdentifierHasSuffix, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifierIsNil": + case "hostIdentifierIsNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierIsNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierIsNil")) it.HostIdentifierIsNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "hostidentifierNotNil": + case "hostIdentifierNotNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierNotNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierNotNil")) it.HostIdentifierNotNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "hostidentifierEqualFold": + case "hostIdentifierEqualFold": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierEqualFold")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierEqualFold")) it.HostIdentifierEqualFold, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostidentifierContainsFold": + case "hostIdentifierContainsFold": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostidentifierContainsFold")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostIdentifierContainsFold")) it.HostIdentifierContainsFold, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "lastseenat": + case "hostPrimaryIP": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIP")) + it.HostPrimaryIP, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPNEQ": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPNEQ")) + it.HostPrimaryIPNEQ, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPIn": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPIn")) + it.HostPrimaryIPIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPNotIn": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPNotIn")) + it.HostPrimaryIPNotIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPGT": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPGT")) + it.HostPrimaryIPGT, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPGTE": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPGTE")) + it.HostPrimaryIPGTE, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPLT": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPLT")) + it.HostPrimaryIPLT, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPLTE": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPLTE")) + it.HostPrimaryIPLTE, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPContains": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPContains")) + it.HostPrimaryIPContains, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPHasPrefix": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPHasPrefix")) + it.HostPrimaryIPHasPrefix, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPHasSuffix": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPHasSuffix")) + it.HostPrimaryIPHasSuffix, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPIsNil": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPIsNil")) + it.HostPrimaryIPIsNil, err = ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPNotNil": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPNotNil")) + it.HostPrimaryIPNotNil, err = ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPEqualFold": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPEqualFold")) + it.HostPrimaryIPEqualFold, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIPContainsFold": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIPContainsFold")) + it.HostPrimaryIPContainsFold, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "hostPlatform": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPlatform")) + it.HostPlatform, err = ec.unmarshalOSessionSessionHostPlatform2ᚖgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatform(ctx, v) + if err != nil { + return it, err + } + case "hostPlatformNEQ": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPlatformNEQ")) + it.HostPlatformNEQ, err = ec.unmarshalOSessionSessionHostPlatform2ᚖgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatform(ctx, v) + if err != nil { + return it, err + } + case "hostPlatformIn": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPlatformIn")) + it.HostPlatformIn, err = ec.unmarshalOSessionSessionHostPlatform2ᚕgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatformᚄ(ctx, v) + if err != nil { + return it, err + } + case "hostPlatformNotIn": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPlatformNotIn")) + it.HostPlatformNotIn, err = ec.unmarshalOSessionSessionHostPlatform2ᚕgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatformᚄ(ctx, v) + if err != nil { + return it, err + } + case "lastSeenAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastseenat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastSeenAt")) it.LastSeenAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastseenatNEQ": + case "lastSeenAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastseenatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastSeenAtNEQ")) it.LastSeenAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastseenatIn": + case "lastSeenAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastseenatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastSeenAtIn")) it.LastSeenAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "lastseenatNotIn": + case "lastSeenAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastseenatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastSeenAtNotIn")) it.LastSeenAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "lastseenatGT": + case "lastSeenAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastseenatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastSeenAtGT")) it.LastSeenAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastseenatGTE": + case "lastSeenAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastseenatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastSeenAtGTE")) it.LastSeenAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastseenatLT": + case "lastSeenAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastseenatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastSeenAtLT")) it.LastSeenAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastseenatLTE": + case "lastSeenAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastseenatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastSeenAtLTE")) it.LastSeenAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastseenatIsNil": + case "lastSeenAtIsNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastseenatIsNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastSeenAtIsNil")) it.LastSeenAtIsNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "lastseenatNotNil": + case "lastSeenAtNotNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastseenatNotNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastSeenAtNotNil")) it.LastSeenAtNotNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err @@ -5773,7 +6096,7 @@ func (ec *executionContext) unmarshalInputTaskWhereInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdat", "createdatNEQ", "createdatIn", "createdatNotIn", "createdatGT", "createdatGTE", "createdatLT", "createdatLTE", "lastmodifiedat", "lastmodifiedatNEQ", "lastmodifiedatIn", "lastmodifiedatNotIn", "lastmodifiedatGT", "lastmodifiedatGTE", "lastmodifiedatLT", "lastmodifiedatLTE", "claimedat", "claimedatNEQ", "claimedatIn", "claimedatNotIn", "claimedatGT", "claimedatGTE", "claimedatLT", "claimedatLTE", "claimedatIsNil", "claimedatNotNil", "execstartedat", "execstartedatNEQ", "execstartedatIn", "execstartedatNotIn", "execstartedatGT", "execstartedatGTE", "execstartedatLT", "execstartedatLTE", "execstartedatIsNil", "execstartedatNotNil", "execfinishedat", "execfinishedatNEQ", "execfinishedatIn", "execfinishedatNotIn", "execfinishedatGT", "execfinishedatGTE", "execfinishedatLT", "execfinishedatLTE", "execfinishedatIsNil", "execfinishedatNotNil", "output", "outputNEQ", "outputIn", "outputNotIn", "outputGT", "outputGTE", "outputLT", "outputLTE", "outputContains", "outputHasPrefix", "outputHasSuffix", "outputIsNil", "outputNotNil", "outputEqualFold", "outputContainsFold", "error", "errorNEQ", "errorIn", "errorNotIn", "errorGT", "errorGTE", "errorLT", "errorLTE", "errorContains", "errorHasPrefix", "errorHasSuffix", "errorIsNil", "errorNotNil", "errorEqualFold", "errorContainsFold", "hasJob", "hasJobWith", "hasSession", "hasSessionWith"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "lastModifiedAt", "lastModifiedAtNEQ", "lastModifiedAtIn", "lastModifiedAtNotIn", "lastModifiedAtGT", "lastModifiedAtGTE", "lastModifiedAtLT", "lastModifiedAtLTE", "claimedAt", "claimedAtNEQ", "claimedAtIn", "claimedAtNotIn", "claimedAtGT", "claimedAtGTE", "claimedAtLT", "claimedAtLTE", "claimedAtIsNil", "claimedAtNotNil", "execStartedAt", "execStartedAtNEQ", "execStartedAtIn", "execStartedAtNotIn", "execStartedAtGT", "execStartedAtGTE", "execStartedAtLT", "execStartedAtLTE", "execStartedAtIsNil", "execStartedAtNotNil", "execFinishedAt", "execFinishedAtNEQ", "execFinishedAtIn", "execFinishedAtNotIn", "execFinishedAtGT", "execFinishedAtGTE", "execFinishedAtLT", "execFinishedAtLTE", "execFinishedAtIsNil", "execFinishedAtNotNil", "output", "outputNEQ", "outputIn", "outputNotIn", "outputGT", "outputGTE", "outputLT", "outputLTE", "outputContains", "outputHasPrefix", "outputHasSuffix", "outputIsNil", "outputNotNil", "outputEqualFold", "outputContainsFold", "error", "errorNEQ", "errorIn", "errorNotIn", "errorGT", "errorGTE", "errorLT", "errorLTE", "errorContains", "errorHasPrefix", "errorHasSuffix", "errorIsNil", "errorNotNil", "errorEqualFold", "errorContainsFold", "hasJob", "hasJobWith", "hasSession", "hasSessionWith"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -5868,370 +6191,370 @@ func (ec *executionContext) unmarshalInputTaskWhereInput(ctx context.Context, ob if err != nil { return it, err } - case "createdat": + case "createdAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAt")) it.CreatedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatNEQ": + case "createdAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNEQ")) it.CreatedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatIn": + case "createdAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtIn")) it.CreatedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "createdatNotIn": + case "createdAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNotIn")) it.CreatedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "createdatGT": + case "createdAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGT")) it.CreatedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatGTE": + case "createdAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGTE")) it.CreatedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatLT": + case "createdAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLT")) it.CreatedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatLTE": + case "createdAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLTE")) it.CreatedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedat": + case "lastModifiedAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAt")) it.LastModifiedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatNEQ": + case "lastModifiedAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtNEQ")) it.LastModifiedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatIn": + case "lastModifiedAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtIn")) it.LastModifiedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "lastmodifiedatNotIn": + case "lastModifiedAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtNotIn")) it.LastModifiedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "lastmodifiedatGT": + case "lastModifiedAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtGT")) it.LastModifiedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatGTE": + case "lastModifiedAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtGTE")) it.LastModifiedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatLT": + case "lastModifiedAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtLT")) it.LastModifiedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatLTE": + case "lastModifiedAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtLTE")) it.LastModifiedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "claimedat": + case "claimedAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedAt")) it.ClaimedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "claimedatNEQ": + case "claimedAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedAtNEQ")) it.ClaimedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "claimedatIn": + case "claimedAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedAtIn")) it.ClaimedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "claimedatNotIn": + case "claimedAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedAtNotIn")) it.ClaimedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "claimedatGT": + case "claimedAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedAtGT")) it.ClaimedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "claimedatGTE": + case "claimedAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedAtGTE")) it.ClaimedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "claimedatLT": + case "claimedAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedAtLT")) it.ClaimedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "claimedatLTE": + case "claimedAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedAtLTE")) it.ClaimedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "claimedatIsNil": + case "claimedAtIsNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedatIsNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedAtIsNil")) it.ClaimedAtIsNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "claimedatNotNil": + case "claimedAtNotNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedatNotNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("claimedAtNotNil")) it.ClaimedAtNotNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "execstartedat": + case "execStartedAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execstartedat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execStartedAt")) it.ExecStartedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execstartedatNEQ": + case "execStartedAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execstartedatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execStartedAtNEQ")) it.ExecStartedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execstartedatIn": + case "execStartedAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execstartedatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execStartedAtIn")) it.ExecStartedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "execstartedatNotIn": + case "execStartedAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execstartedatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execStartedAtNotIn")) it.ExecStartedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "execstartedatGT": + case "execStartedAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execstartedatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execStartedAtGT")) it.ExecStartedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execstartedatGTE": + case "execStartedAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execstartedatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execStartedAtGTE")) it.ExecStartedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execstartedatLT": + case "execStartedAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execstartedatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execStartedAtLT")) it.ExecStartedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execstartedatLTE": + case "execStartedAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execstartedatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execStartedAtLTE")) it.ExecStartedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execstartedatIsNil": + case "execStartedAtIsNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execstartedatIsNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execStartedAtIsNil")) it.ExecStartedAtIsNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "execstartedatNotNil": + case "execStartedAtNotNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execstartedatNotNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execStartedAtNotNil")) it.ExecStartedAtNotNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "execfinishedat": + case "execFinishedAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execfinishedat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execFinishedAt")) it.ExecFinishedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execfinishedatNEQ": + case "execFinishedAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execfinishedatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execFinishedAtNEQ")) it.ExecFinishedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execfinishedatIn": + case "execFinishedAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execfinishedatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execFinishedAtIn")) it.ExecFinishedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "execfinishedatNotIn": + case "execFinishedAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execfinishedatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execFinishedAtNotIn")) it.ExecFinishedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "execfinishedatGT": + case "execFinishedAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execfinishedatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execFinishedAtGT")) it.ExecFinishedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execfinishedatGTE": + case "execFinishedAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execfinishedatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execFinishedAtGTE")) it.ExecFinishedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execfinishedatLT": + case "execFinishedAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execfinishedatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execFinishedAtLT")) it.ExecFinishedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execfinishedatLTE": + case "execFinishedAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execfinishedatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execFinishedAtLTE")) it.ExecFinishedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "execfinishedatIsNil": + case "execFinishedAtIsNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execfinishedatIsNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execFinishedAtIsNil")) it.ExecFinishedAtIsNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "execfinishedatNotNil": + case "execFinishedAtNotNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execfinishedatNotNil")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execFinishedAtNotNil")) it.ExecFinishedAtNotNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err @@ -6561,7 +6884,7 @@ func (ec *executionContext) unmarshalInputTomeWhereInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdat", "createdatNEQ", "createdatIn", "createdatNotIn", "createdatGT", "createdatGTE", "createdatLT", "createdatLTE", "lastmodifiedat", "lastmodifiedatNEQ", "lastmodifiedatIn", "lastmodifiedatNotIn", "lastmodifiedatGT", "lastmodifiedatGTE", "lastmodifiedatLT", "lastmodifiedatLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "description", "descriptionNEQ", "descriptionIn", "descriptionNotIn", "descriptionGT", "descriptionGTE", "descriptionLT", "descriptionLTE", "descriptionContains", "descriptionHasPrefix", "descriptionHasSuffix", "descriptionEqualFold", "descriptionContainsFold", "parameters", "parametersNEQ", "parametersIn", "parametersNotIn", "parametersGT", "parametersGTE", "parametersLT", "parametersLTE", "parametersContains", "parametersHasPrefix", "parametersHasSuffix", "parametersIsNil", "parametersNotNil", "parametersEqualFold", "parametersContainsFold", "eldritch", "eldritchNEQ", "eldritchIn", "eldritchNotIn", "eldritchGT", "eldritchGTE", "eldritchLT", "eldritchLTE", "eldritchContains", "eldritchHasPrefix", "eldritchHasSuffix", "eldritchEqualFold", "eldritchContainsFold", "hasFiles", "hasFilesWith"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "createdAt", "createdAtNEQ", "createdAtIn", "createdAtNotIn", "createdAtGT", "createdAtGTE", "createdAtLT", "createdAtLTE", "lastModifiedAt", "lastModifiedAtNEQ", "lastModifiedAtIn", "lastModifiedAtNotIn", "lastModifiedAtGT", "lastModifiedAtGTE", "lastModifiedAtLT", "lastModifiedAtLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "description", "descriptionNEQ", "descriptionIn", "descriptionNotIn", "descriptionGT", "descriptionGTE", "descriptionLT", "descriptionLTE", "descriptionContains", "descriptionHasPrefix", "descriptionHasSuffix", "descriptionEqualFold", "descriptionContainsFold", "paramDefs", "paramDefsNEQ", "paramDefsIn", "paramDefsNotIn", "paramDefsGT", "paramDefsGTE", "paramDefsLT", "paramDefsLTE", "paramDefsContains", "paramDefsHasPrefix", "paramDefsHasSuffix", "paramDefsIsNil", "paramDefsNotNil", "paramDefsEqualFold", "paramDefsContainsFold", "eldritch", "eldritchNEQ", "eldritchIn", "eldritchNotIn", "eldritchGT", "eldritchGTE", "eldritchLT", "eldritchLTE", "eldritchContains", "eldritchHasPrefix", "eldritchHasSuffix", "eldritchEqualFold", "eldritchContainsFold", "hasFiles", "hasFilesWith"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -6656,130 +6979,130 @@ func (ec *executionContext) unmarshalInputTomeWhereInput(ctx context.Context, ob if err != nil { return it, err } - case "createdat": + case "createdAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAt")) it.CreatedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatNEQ": + case "createdAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNEQ")) it.CreatedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatIn": + case "createdAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtIn")) it.CreatedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "createdatNotIn": + case "createdAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtNotIn")) it.CreatedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "createdatGT": + case "createdAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGT")) it.CreatedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatGTE": + case "createdAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtGTE")) it.CreatedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatLT": + case "createdAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLT")) it.CreatedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "createdatLTE": + case "createdAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("createdAtLTE")) it.CreatedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedat": + case "lastModifiedAt": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedat")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAt")) it.LastModifiedAt, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatNEQ": + case "lastModifiedAtNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtNEQ")) it.LastModifiedAtNEQ, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatIn": + case "lastModifiedAtIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtIn")) it.LastModifiedAtIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "lastmodifiedatNotIn": + case "lastModifiedAtNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtNotIn")) it.LastModifiedAtNotIn, err = ec.unmarshalOTime2ᚕtimeᚐTimeᚄ(ctx, v) if err != nil { return it, err } - case "lastmodifiedatGT": + case "lastModifiedAtGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtGT")) it.LastModifiedAtGT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatGTE": + case "lastModifiedAtGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtGTE")) it.LastModifiedAtGTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatLT": + case "lastModifiedAtLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtLT")) it.LastModifiedAtLT, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err } - case "lastmodifiedatLTE": + case "lastModifiedAtLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastmodifiedatLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("lastModifiedAtLTE")) it.LastModifiedAtLTE, err = ec.unmarshalOTime2ᚖtimeᚐTime(ctx, v) if err != nil { return it, err @@ -6992,123 +7315,123 @@ func (ec *executionContext) unmarshalInputTomeWhereInput(ctx context.Context, ob if err != nil { return it, err } - case "parameters": + case "paramDefs": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parameters")) - it.Parameters, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefs")) + it.ParamDefs, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "parametersNEQ": + case "paramDefsNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersNEQ")) - it.ParametersNEQ, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsNEQ")) + it.ParamDefsNEQ, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "parametersIn": + case "paramDefsIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersIn")) - it.ParametersIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsIn")) + it.ParamDefsIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) if err != nil { return it, err } - case "parametersNotIn": + case "paramDefsNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersNotIn")) - it.ParametersNotIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsNotIn")) + it.ParamDefsNotIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) if err != nil { return it, err } - case "parametersGT": + case "paramDefsGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersGT")) - it.ParametersGT, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsGT")) + it.ParamDefsGT, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "parametersGTE": + case "paramDefsGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersGTE")) - it.ParametersGTE, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsGTE")) + it.ParamDefsGTE, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "parametersLT": + case "paramDefsLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersLT")) - it.ParametersLT, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsLT")) + it.ParamDefsLT, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "parametersLTE": + case "paramDefsLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersLTE")) - it.ParametersLTE, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsLTE")) + it.ParamDefsLTE, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "parametersContains": + case "paramDefsContains": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersContains")) - it.ParametersContains, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsContains")) + it.ParamDefsContains, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "parametersHasPrefix": + case "paramDefsHasPrefix": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersHasPrefix")) - it.ParametersHasPrefix, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsHasPrefix")) + it.ParamDefsHasPrefix, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "parametersHasSuffix": + case "paramDefsHasSuffix": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersHasSuffix")) - it.ParametersHasSuffix, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsHasSuffix")) + it.ParamDefsHasSuffix, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "parametersIsNil": + case "paramDefsIsNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersIsNil")) - it.ParametersIsNil, err = ec.unmarshalOBoolean2bool(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsIsNil")) + it.ParamDefsIsNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "parametersNotNil": + case "paramDefsNotNil": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersNotNil")) - it.ParametersNotNil, err = ec.unmarshalOBoolean2bool(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsNotNil")) + it.ParamDefsNotNil, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } - case "parametersEqualFold": + case "paramDefsEqualFold": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersEqualFold")) - it.ParametersEqualFold, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsEqualFold")) + it.ParamDefsEqualFold, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "parametersContainsFold": + case "paramDefsContainsFold": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("parametersContainsFold")) - it.ParametersContainsFold, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paramDefsContainsFold")) + it.ParamDefsContainsFold, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } @@ -7245,7 +7568,7 @@ func (ec *executionContext) unmarshalInputUpdateSessionInput(ctx context.Context asMap[k] = v } - fieldsInOrder := [...]string{"name", "clearHostname", "hostname", "addTagIDs", "removeTagIDs"} + fieldsInOrder := [...]string{"name", "hostname", "clearHostname", "addTagIDs", "removeTagIDs", "clearTags"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -7260,19 +7583,19 @@ func (ec *executionContext) unmarshalInputUpdateSessionInput(ctx context.Context if err != nil { return it, err } - case "clearHostname": + case "hostname": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearHostname")) - it.ClearHostname, err = ec.unmarshalOBoolean2bool(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostname")) + it.Hostname, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "hostname": + case "clearHostname": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostname")) - it.Hostname, err = ec.unmarshalOString2ᚖstring(ctx, v) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearHostname")) + it.ClearHostname, err = ec.unmarshalOBoolean2bool(ctx, v) if err != nil { return it, err } @@ -7292,6 +7615,14 @@ func (ec *executionContext) unmarshalInputUpdateSessionInput(ctx context.Context if err != nil { return it, err } + case "clearTags": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearTags")) + it.ClearTags, err = ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } } } @@ -7305,7 +7636,7 @@ func (ec *executionContext) unmarshalInputUpdateTagInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"name", "kind", "addSessionIDs", "removeSessionIDs"} + fieldsInOrder := [...]string{"name", "kind", "addSessionIDs", "removeSessionIDs", "clearSessions"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -7344,6 +7675,14 @@ func (ec *executionContext) unmarshalInputUpdateTagInput(ctx context.Context, ob if err != nil { return it, err } + case "clearSessions": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clearSessions")) + it.ClearSessions, err = ec.unmarshalOBoolean2bool(ctx, v) + if err != nil { + return it, err + } } } @@ -7357,7 +7696,7 @@ func (ec *executionContext) unmarshalInputUpdateUserInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"name", "photourl", "isactivated", "isadmin"} + fieldsInOrder := [...]string{"name", "photoURL", "isActivated", "isAdmin"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -7372,26 +7711,26 @@ func (ec *executionContext) unmarshalInputUpdateUserInput(ctx context.Context, o if err != nil { return it, err } - case "photourl": + case "photoURL": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourl")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURL")) it.PhotoURL, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "isactivated": + case "isActivated": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isactivated")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isActivated")) it.IsActivated, err = ec.unmarshalOBoolean2ᚖbool(ctx, v) if err != nil { return it, err } - case "isadmin": + case "isAdmin": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isadmin")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isAdmin")) it.IsAdmin, err = ec.unmarshalOBoolean2ᚖbool(ctx, v) if err != nil { return it, err @@ -7409,7 +7748,7 @@ func (ec *executionContext) unmarshalInputUserWhereInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "photourl", "photourlNEQ", "photourlIn", "photourlNotIn", "photourlGT", "photourlGTE", "photourlLT", "photourlLTE", "photourlContains", "photourlHasPrefix", "photourlHasSuffix", "photourlEqualFold", "photourlContainsFold", "isactivated", "isactivatedNEQ", "isadmin", "isadminNEQ"} + fieldsInOrder := [...]string{"not", "and", "or", "id", "idNEQ", "idIn", "idNotIn", "idGT", "idGTE", "idLT", "idLTE", "name", "nameNEQ", "nameIn", "nameNotIn", "nameGT", "nameGTE", "nameLT", "nameLTE", "nameContains", "nameHasPrefix", "nameHasSuffix", "nameEqualFold", "nameContainsFold", "photoURL", "photoURLNEQ", "photoURLIn", "photoURLNotIn", "photoURLGT", "photoURLGTE", "photoURLLT", "photoURLLTE", "photoURLContains", "photoURLHasPrefix", "photoURLHasSuffix", "photoURLEqualFold", "photoURLContainsFold", "isActivated", "isActivatedNEQ", "isAdmin", "isAdminNEQ"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -7608,138 +7947,138 @@ func (ec *executionContext) unmarshalInputUserWhereInput(ctx context.Context, ob if err != nil { return it, err } - case "photourl": + case "photoURL": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourl")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURL")) it.PhotoURL, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "photourlNEQ": + case "photoURLNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLNEQ")) it.PhotoURLNEQ, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "photourlIn": + case "photoURLIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLIn")) it.PhotoURLIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) if err != nil { return it, err } - case "photourlNotIn": + case "photoURLNotIn": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlNotIn")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLNotIn")) it.PhotoURLNotIn, err = ec.unmarshalOString2ᚕstringᚄ(ctx, v) if err != nil { return it, err } - case "photourlGT": + case "photoURLGT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlGT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLGT")) it.PhotoURLGT, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "photourlGTE": + case "photoURLGTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlGTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLGTE")) it.PhotoURLGTE, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "photourlLT": + case "photoURLLT": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlLT")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLLT")) it.PhotoURLLT, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "photourlLTE": + case "photoURLLTE": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlLTE")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLLTE")) it.PhotoURLLTE, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "photourlContains": + case "photoURLContains": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlContains")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLContains")) it.PhotoURLContains, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "photourlHasPrefix": + case "photoURLHasPrefix": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlHasPrefix")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLHasPrefix")) it.PhotoURLHasPrefix, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "photourlHasSuffix": + case "photoURLHasSuffix": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlHasSuffix")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLHasSuffix")) it.PhotoURLHasSuffix, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "photourlEqualFold": + case "photoURLEqualFold": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlEqualFold")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLEqualFold")) it.PhotoURLEqualFold, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "photourlContainsFold": + case "photoURLContainsFold": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photourlContainsFold")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("photoURLContainsFold")) it.PhotoURLContainsFold, err = ec.unmarshalOString2ᚖstring(ctx, v) if err != nil { return it, err } - case "isactivated": + case "isActivated": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isactivated")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isActivated")) it.IsActivated, err = ec.unmarshalOBoolean2ᚖbool(ctx, v) if err != nil { return it, err } - case "isactivatedNEQ": + case "isActivatedNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isactivatedNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isActivatedNEQ")) it.IsActivatedNEQ, err = ec.unmarshalOBoolean2ᚖbool(ctx, v) if err != nil { return it, err } - case "isadmin": + case "isAdmin": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isadmin")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isAdmin")) it.IsAdmin, err = ec.unmarshalOBoolean2ᚖbool(ctx, v) if err != nil { return it, err } - case "isadminNEQ": + case "isAdminNEQ": var err error - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isadminNEQ")) + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("isAdminNEQ")) it.IsAdminNEQ, err = ec.unmarshalOBoolean2ᚖbool(ctx, v) if err != nil { return it, err @@ -7819,16 +8158,16 @@ func (ec *executionContext) _File(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { invalids++ } - case "createdat": + case "createdAt": - out.Values[i] = ec._File_createdat(ctx, field, obj) + out.Values[i] = ec._File_createdAt(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } - case "lastmodifiedat": + case "lastModifiedAt": - out.Values[i] = ec._File_lastmodifiedat(ctx, field, obj) + out.Values[i] = ec._File_lastModifiedAt(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ @@ -7882,16 +8221,16 @@ func (ec *executionContext) _Job(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } - case "createdat": + case "createdAt": - out.Values[i] = ec._Job_createdat(ctx, field, obj) + out.Values[i] = ec._Job_createdAt(ctx, field, obj) if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } - case "lastmodifiedat": + case "lastModifiedAt": - out.Values[i] = ec._Job_lastmodifiedat(ctx, field, obj) + out.Values[i] = ec._Job_lastModifiedAt(ctx, field, obj) if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) @@ -7957,6 +8296,23 @@ func (ec *executionContext) _Job(ctx context.Context, sel ast.SelectionSet, obj return res } + out.Concurrently(i, func() graphql.Marshaler { + return innerFunc(ctx) + + }) + case "creator": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Job_creator(ctx, field, obj) + return res + } + out.Concurrently(i, func() graphql.Marshaler { return innerFunc(ctx) @@ -8277,17 +8633,28 @@ func (ec *executionContext) _Session(ctx context.Context, sel ast.SelectionSet, if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } - case "agentidentifier": + case "agentIdentifier": + + out.Values[i] = ec._Session_agentIdentifier(ctx, field, obj) - out.Values[i] = ec._Session_agentidentifier(ctx, field, obj) + case "hostIdentifier": - case "hostidentifier": + out.Values[i] = ec._Session_hostIdentifier(ctx, field, obj) - out.Values[i] = ec._Session_hostidentifier(ctx, field, obj) + case "hostPrimaryIP": - case "lastseenat": + out.Values[i] = ec._Session_hostPrimaryIP(ctx, field, obj) - out.Values[i] = ec._Session_lastseenat(ctx, field, obj) + case "hostPlatform": + + out.Values[i] = ec._Session_hostPlatform(ctx, field, obj) + + if out.Values[i] == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + case "lastSeenAt": + + out.Values[i] = ec._Session_lastSeenAt(ctx, field, obj) case "tags": field := field @@ -8410,31 +8777,31 @@ func (ec *executionContext) _Task(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } - case "createdat": + case "createdAt": - out.Values[i] = ec._Task_createdat(ctx, field, obj) + out.Values[i] = ec._Task_createdAt(ctx, field, obj) if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } - case "lastmodifiedat": + case "lastModifiedAt": - out.Values[i] = ec._Task_lastmodifiedat(ctx, field, obj) + out.Values[i] = ec._Task_lastModifiedAt(ctx, field, obj) if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } - case "claimedat": + case "claimedAt": - out.Values[i] = ec._Task_claimedat(ctx, field, obj) + out.Values[i] = ec._Task_claimedAt(ctx, field, obj) - case "execstartedat": + case "execStartedAt": - out.Values[i] = ec._Task_execstartedat(ctx, field, obj) + out.Values[i] = ec._Task_execStartedAt(ctx, field, obj) - case "execfinishedat": + case "execFinishedAt": - out.Values[i] = ec._Task_execfinishedat(ctx, field, obj) + out.Values[i] = ec._Task_execFinishedAt(ctx, field, obj) case "output": @@ -8512,16 +8879,16 @@ func (ec *executionContext) _Tome(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } - case "createdat": + case "createdAt": - out.Values[i] = ec._Tome_createdat(ctx, field, obj) + out.Values[i] = ec._Tome_createdAt(ctx, field, obj) if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } - case "lastmodifiedat": + case "lastModifiedAt": - out.Values[i] = ec._Tome_lastmodifiedat(ctx, field, obj) + out.Values[i] = ec._Tome_lastModifiedAt(ctx, field, obj) if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) @@ -8540,9 +8907,9 @@ func (ec *executionContext) _Tome(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { atomic.AddUint32(&invalids, 1) } - case "parameters": + case "paramDefs": - out.Values[i] = ec._Tome_parameters(ctx, field, obj) + out.Values[i] = ec._Tome_paramDefs(ctx, field, obj) case "eldritch": @@ -8603,23 +8970,23 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { invalids++ } - case "photourl": + case "photoURL": - out.Values[i] = ec._User_photourl(ctx, field, obj) + out.Values[i] = ec._User_photoURL(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } - case "isactivated": + case "isActivated": - out.Values[i] = ec._User_isactivated(ctx, field, obj) + out.Values[i] = ec._User_isActivated(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } - case "isadmin": + case "isAdmin": - out.Values[i] = ec._User_isadmin(ctx, field, obj) + out.Values[i] = ec._User_isAdmin(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ @@ -8926,6 +9293,16 @@ func (ec *executionContext) marshalNSessionOrderField2ᚖgithubᚗcomᚋkcarrett return v } +func (ec *executionContext) unmarshalNSessionSessionHostPlatform2githubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatform(ctx context.Context, v interface{}) (session.HostPlatform, error) { + var res session.HostPlatform + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNSessionSessionHostPlatform2githubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatform(ctx context.Context, sel ast.SelectionSet, v session.HostPlatform) graphql.Marshaler { + return v +} + func (ec *executionContext) unmarshalNSessionWhereInput2ᚖgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚐSessionWhereInput(ctx context.Context, v interface{}) (*ent.SessionWhereInput, error) { res, err := ec.unmarshalInputSessionWhereInput(ctx, v) return &res, graphql.ErrorOnPath(ctx, err) @@ -9435,6 +9812,89 @@ func (ec *executionContext) marshalOSession2ᚕᚖgithubᚗcomᚋkcarrettoᚋrea return ret } +func (ec *executionContext) unmarshalOSessionSessionHostPlatform2ᚕgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatformᚄ(ctx context.Context, v interface{}) ([]session.HostPlatform, error) { + if v == nil { + return nil, nil + } + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]session.HostPlatform, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNSessionSessionHostPlatform2githubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatform(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalOSessionSessionHostPlatform2ᚕgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatformᚄ(ctx context.Context, sel ast.SelectionSet, v []session.HostPlatform) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNSessionSessionHostPlatform2githubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatform(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) unmarshalOSessionSessionHostPlatform2ᚖgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatform(ctx context.Context, v interface{}) (*session.HostPlatform, error) { + if v == nil { + return nil, nil + } + var res = new(session.HostPlatform) + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOSessionSessionHostPlatform2ᚖgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatform(ctx context.Context, sel ast.SelectionSet, v *session.HostPlatform) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return v +} + func (ec *executionContext) unmarshalOSessionWhereInput2ᚕᚖgithubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚐSessionWhereInputᚄ(ctx context.Context, v interface{}) ([]*ent.SessionWhereInput, error) { if v == nil { return nil, nil diff --git a/tavern/graphql/generated/inputs.generated.go b/tavern/graphql/generated/inputs.generated.go index c16a0fbf5..251dc76db 100644 --- a/tavern/graphql/generated/inputs.generated.go +++ b/tavern/graphql/generated/inputs.generated.go @@ -34,7 +34,7 @@ func (ec *executionContext) unmarshalInputClaimTasksInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"principal", "hostname", "sessionIdentifier", "hostIdentifier", "agentIdentifier"} + fieldsInOrder := [...]string{"principal", "hostname", "hostPlatform", "hostPrimaryIP", "sessionIdentifier", "hostIdentifier", "agentIdentifier"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -57,6 +57,22 @@ func (ec *executionContext) unmarshalInputClaimTasksInput(ctx context.Context, o if err != nil { return it, err } + case "hostPlatform": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPlatform")) + it.HostPlatform, err = ec.unmarshalNSessionSessionHostPlatform2githubᚗcomᚋkcarrettoᚋrealmᚋtavernᚋentᚋsessionᚐHostPlatform(ctx, v) + if err != nil { + return it, err + } + case "hostPrimaryIP": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hostPrimaryIP")) + it.HostPrimaryIP, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } case "sessionIdentifier": var err error diff --git a/tavern/graphql/generated/mutation.generated.go b/tavern/graphql/generated/mutation.generated.go index 7f153effb..6799a82c5 100644 --- a/tavern/graphql/generated/mutation.generated.go +++ b/tavern/graphql/generated/mutation.generated.go @@ -257,10 +257,10 @@ func (ec *executionContext) fieldContext_Mutation_createJob(ctx context.Context, switch field.Name { case "id": return ec.fieldContext_Job_id(ctx, field) - case "createdat": - return ec.fieldContext_Job_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_Job_lastmodifiedat(ctx, field) + case "createdAt": + return ec.fieldContext_Job_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_Job_lastModifiedAt(ctx, field) case "name": return ec.fieldContext_Job_name(ctx, field) case "parameters": @@ -271,6 +271,8 @@ func (ec *executionContext) fieldContext_Mutation_createJob(ctx context.Context, return ec.fieldContext_Job_bundle(ctx, field) case "tasks": return ec.fieldContext_Job_tasks(ctx, field) + case "creator": + return ec.fieldContext_Job_creator(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Job", field.Name) }, @@ -362,12 +364,16 @@ func (ec *executionContext) fieldContext_Mutation_updateSession(ctx context.Cont return ec.fieldContext_Session_hostname(ctx, field) case "identifier": return ec.fieldContext_Session_identifier(ctx, field) - case "agentidentifier": - return ec.fieldContext_Session_agentidentifier(ctx, field) - case "hostidentifier": - return ec.fieldContext_Session_hostidentifier(ctx, field) - case "lastseenat": - return ec.fieldContext_Session_lastseenat(ctx, field) + case "agentIdentifier": + return ec.fieldContext_Session_agentIdentifier(ctx, field) + case "hostIdentifier": + return ec.fieldContext_Session_hostIdentifier(ctx, field) + case "hostPrimaryIP": + return ec.fieldContext_Session_hostPrimaryIP(ctx, field) + case "hostPlatform": + return ec.fieldContext_Session_hostPlatform(ctx, field) + case "lastSeenAt": + return ec.fieldContext_Session_lastSeenAt(ctx, field) case "tags": return ec.fieldContext_Session_tags(ctx, field) case "tasks": @@ -609,16 +615,16 @@ func (ec *executionContext) fieldContext_Mutation_claimTasks(ctx context.Context switch field.Name { case "id": return ec.fieldContext_Task_id(ctx, field) - case "createdat": - return ec.fieldContext_Task_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_Task_lastmodifiedat(ctx, field) - case "claimedat": - return ec.fieldContext_Task_claimedat(ctx, field) - case "execstartedat": - return ec.fieldContext_Task_execstartedat(ctx, field) - case "execfinishedat": - return ec.fieldContext_Task_execfinishedat(ctx, field) + case "createdAt": + return ec.fieldContext_Task_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_Task_lastModifiedAt(ctx, field) + case "claimedAt": + return ec.fieldContext_Task_claimedAt(ctx, field) + case "execStartedAt": + return ec.fieldContext_Task_execStartedAt(ctx, field) + case "execFinishedAt": + return ec.fieldContext_Task_execFinishedAt(ctx, field) case "output": return ec.fieldContext_Task_output(ctx, field) case "error": @@ -683,16 +689,16 @@ func (ec *executionContext) fieldContext_Mutation_submitTaskResult(ctx context.C switch field.Name { case "id": return ec.fieldContext_Task_id(ctx, field) - case "createdat": - return ec.fieldContext_Task_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_Task_lastmodifiedat(ctx, field) - case "claimedat": - return ec.fieldContext_Task_claimedat(ctx, field) - case "execstartedat": - return ec.fieldContext_Task_execstartedat(ctx, field) - case "execfinishedat": - return ec.fieldContext_Task_execfinishedat(ctx, field) + case "createdAt": + return ec.fieldContext_Task_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_Task_lastModifiedAt(ctx, field) + case "claimedAt": + return ec.fieldContext_Task_claimedAt(ctx, field) + case "execStartedAt": + return ec.fieldContext_Task_execStartedAt(ctx, field) + case "execFinishedAt": + return ec.fieldContext_Task_execFinishedAt(ctx, field) case "output": return ec.fieldContext_Task_output(ctx, field) case "error": @@ -784,16 +790,16 @@ func (ec *executionContext) fieldContext_Mutation_createTome(ctx context.Context switch field.Name { case "id": return ec.fieldContext_Tome_id(ctx, field) - case "createdat": - return ec.fieldContext_Tome_createdat(ctx, field) - case "lastmodifiedat": - return ec.fieldContext_Tome_lastmodifiedat(ctx, field) + case "createdAt": + return ec.fieldContext_Tome_createdAt(ctx, field) + case "lastModifiedAt": + return ec.fieldContext_Tome_lastModifiedAt(ctx, field) case "name": return ec.fieldContext_Tome_name(ctx, field) case "description": return ec.fieldContext_Tome_description(ctx, field) - case "parameters": - return ec.fieldContext_Tome_parameters(ctx, field) + case "paramDefs": + return ec.fieldContext_Tome_paramDefs(ctx, field) case "eldritch": return ec.fieldContext_Tome_eldritch(ctx, field) case "files": @@ -880,12 +886,12 @@ func (ec *executionContext) fieldContext_Mutation_updateUser(ctx context.Context return ec.fieldContext_User_id(ctx, field) case "name": return ec.fieldContext_User_name(ctx, field) - case "photourl": - return ec.fieldContext_User_photourl(ctx, field) - case "isactivated": - return ec.fieldContext_User_isactivated(ctx, field) - case "isadmin": - return ec.fieldContext_User_isadmin(ctx, field) + case "photoURL": + return ec.fieldContext_User_photoURL(ctx, field) + case "isActivated": + return ec.fieldContext_User_isActivated(ctx, field) + case "isAdmin": + return ec.fieldContext_User_isAdmin(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type User", field.Name) }, diff --git a/tavern/graphql/generated/root_.generated.go b/tavern/graphql/generated/root_.generated.go index 01726d9f7..7aac95072 100644 --- a/tavern/graphql/generated/root_.generated.go +++ b/tavern/graphql/generated/root_.generated.go @@ -52,6 +52,7 @@ type ComplexityRoot struct { Job struct { Bundle func(childComplexity int) int CreatedAt func(childComplexity int) int + Creator func(childComplexity int) int ID func(childComplexity int) int LastModifiedAt func(childComplexity int) int Name func(childComplexity int) int @@ -92,6 +93,8 @@ type ComplexityRoot struct { Session struct { AgentIdentifier func(childComplexity int) int HostIdentifier func(childComplexity int) int + HostPlatform func(childComplexity int) int + HostPrimaryIP func(childComplexity int) int Hostname func(childComplexity int) int ID func(childComplexity int) int Identifier func(childComplexity int) int @@ -130,7 +133,7 @@ type ComplexityRoot struct { ID func(childComplexity int) int LastModifiedAt func(childComplexity int) int Name func(childComplexity int) int - Parameters func(childComplexity int) int + ParamDefs func(childComplexity int) int } User struct { @@ -157,7 +160,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { - case "File.createdat": + case "File.createdAt": if e.complexity.File.CreatedAt == nil { break } @@ -178,7 +181,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.File.ID(childComplexity), true - case "File.lastmodifiedat": + case "File.lastModifiedAt": if e.complexity.File.LastModifiedAt == nil { break } @@ -206,13 +209,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Job.Bundle(childComplexity), true - case "Job.createdat": + case "Job.createdAt": if e.complexity.Job.CreatedAt == nil { break } return e.complexity.Job.CreatedAt(childComplexity), true + case "Job.creator": + if e.complexity.Job.Creator == nil { + break + } + + return e.complexity.Job.Creator(childComplexity), true + case "Job.id": if e.complexity.Job.ID == nil { break @@ -220,7 +230,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Job.ID(childComplexity), true - case "Job.lastmodifiedat": + case "Job.lastModifiedAt": if e.complexity.Job.LastModifiedAt == nil { break } @@ -450,20 +460,34 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Users(childComplexity), true - case "Session.agentidentifier": + case "Session.agentIdentifier": if e.complexity.Session.AgentIdentifier == nil { break } return e.complexity.Session.AgentIdentifier(childComplexity), true - case "Session.hostidentifier": + case "Session.hostIdentifier": if e.complexity.Session.HostIdentifier == nil { break } return e.complexity.Session.HostIdentifier(childComplexity), true + case "Session.hostPlatform": + if e.complexity.Session.HostPlatform == nil { + break + } + + return e.complexity.Session.HostPlatform(childComplexity), true + + case "Session.hostPrimaryIP": + if e.complexity.Session.HostPrimaryIP == nil { + break + } + + return e.complexity.Session.HostPrimaryIP(childComplexity), true + case "Session.hostname": if e.complexity.Session.Hostname == nil { break @@ -485,7 +509,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Session.Identifier(childComplexity), true - case "Session.lastseenat": + case "Session.lastSeenAt": if e.complexity.Session.LastSeenAt == nil { break } @@ -548,14 +572,14 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Tag.Sessions(childComplexity), true - case "Task.claimedat": + case "Task.claimedAt": if e.complexity.Task.ClaimedAt == nil { break } return e.complexity.Task.ClaimedAt(childComplexity), true - case "Task.createdat": + case "Task.createdAt": if e.complexity.Task.CreatedAt == nil { break } @@ -569,14 +593,14 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Task.Error(childComplexity), true - case "Task.execfinishedat": + case "Task.execFinishedAt": if e.complexity.Task.ExecFinishedAt == nil { break } return e.complexity.Task.ExecFinishedAt(childComplexity), true - case "Task.execstartedat": + case "Task.execStartedAt": if e.complexity.Task.ExecStartedAt == nil { break } @@ -597,7 +621,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Task.Job(childComplexity), true - case "Task.lastmodifiedat": + case "Task.lastModifiedAt": if e.complexity.Task.LastModifiedAt == nil { break } @@ -618,7 +642,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Task.Session(childComplexity), true - case "Tome.createdat": + case "Tome.createdAt": if e.complexity.Tome.CreatedAt == nil { break } @@ -653,7 +677,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Tome.ID(childComplexity), true - case "Tome.lastmodifiedat": + case "Tome.lastModifiedAt": if e.complexity.Tome.LastModifiedAt == nil { break } @@ -667,12 +691,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Tome.Name(childComplexity), true - case "Tome.parameters": - if e.complexity.Tome.Parameters == nil { + case "Tome.paramDefs": + if e.complexity.Tome.ParamDefs == nil { break } - return e.complexity.Tome.Parameters(childComplexity), true + return e.complexity.Tome.ParamDefs(childComplexity), true case "User.id": if e.complexity.User.ID == nil { @@ -681,14 +705,14 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.User.ID(childComplexity), true - case "User.isactivated": + case "User.isActivated": if e.complexity.User.IsActivated == nil { break } return e.complexity.User.IsActivated(childComplexity), true - case "User.isadmin": + case "User.isAdmin": if e.complexity.User.IsAdmin == nil { break } @@ -702,7 +726,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.User.Name(childComplexity), true - case "User.photourl": + case "User.photoURL": if e.complexity.User.PhotoURL == nil { break } @@ -838,7 +862,7 @@ input CreateTomeInput { """Information about the tome""" description: String! """JSON string describing what parameters are used with the tome""" - parameters: String + paramDefs: String """Eldritch script that will be executed when the tome is run""" eldritch: String! fileIDs: [ID!] @@ -851,9 +875,9 @@ scalar Cursor type File implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """The name of the file, used to reference it for downloads""" name: String! """The size of the file in bytes""" @@ -892,24 +916,24 @@ input FileWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time """name field predicates""" name: String nameNEQ: String @@ -951,9 +975,9 @@ input FileWhereInput { type Job implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """Name of the job""" name: String! """Value of parameters that were specified for the job (as a JSON string).""" @@ -961,6 +985,7 @@ type Job implements Node { tome: Tome! bundle: File tasks: [Task!] + creator: User } """Ordering options for Job connections""" input JobOrder { @@ -992,24 +1017,24 @@ input JobWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time """name field predicates""" name: String nameNEQ: String @@ -1049,6 +1074,9 @@ input JobWhereInput { """tasks edge predicates""" hasTasks: Boolean hasTasksWith: [TaskWhereInput!] + """creator edge predicates""" + hasCreator: Boolean + hasCreatorWith: [UserWhereInput!] } """ An object with an ID. @@ -1102,11 +1130,15 @@ type Session implements Node { """Unique identifier for the session. Unique to each instance of the session.""" identifier: String! """Identifies the agent that the session is running as (e.g. 'imix').""" - agentidentifier: String @goField(name: "AgentIdentifier", forceResolver: false) + agentIdentifier: String """Unique identifier for the host the session is running on.""" - hostidentifier: String @goField(name: "HostIdentifier", forceResolver: false) + hostIdentifier: String + """Primary interface IP address reported by the agent.""" + hostPrimaryIP: String + """Platform the agent is operating on.""" + hostPlatform: SessionSessionHostPlatform! """Timestamp of when a task was last claimed or updated for a target""" - lastseenat: Time @goField(name: "LastSeenAt", forceResolver: false) + lastSeenAt: Time tags: [Tag!] tasks: [Task!] } @@ -1121,6 +1153,14 @@ input SessionOrder { enum SessionOrderField { LAST_SEEN_AT } +"""SessionSessionHostPlatform is enum for the field host_platform""" +enum SessionSessionHostPlatform @goModel(model: "github.com/kcarretto/realm/tavern/ent/session.HostPlatform") { + Windows + Linux + MacOS + BSD + Unknown +} """ SessionWhereInput is used for filtering Session objects. Input was generated by ent. @@ -1198,49 +1238,70 @@ input SessionWhereInput { identifierHasSuffix: String identifierEqualFold: String identifierContainsFold: String - """agentIdentifier field predicates""" - agentidentifier: String - agentidentifierNEQ: String - agentidentifierIn: [String!] - agentidentifierNotIn: [String!] - agentidentifierGT: String - agentidentifierGTE: String - agentidentifierLT: String - agentidentifierLTE: String - agentidentifierContains: String - agentidentifierHasPrefix: String - agentidentifierHasSuffix: String - agentidentifierIsNil: Boolean - agentidentifierNotNil: Boolean - agentidentifierEqualFold: String - agentidentifierContainsFold: String - """hostIdentifier field predicates""" - hostidentifier: String - hostidentifierNEQ: String - hostidentifierIn: [String!] - hostidentifierNotIn: [String!] - hostidentifierGT: String - hostidentifierGTE: String - hostidentifierLT: String - hostidentifierLTE: String - hostidentifierContains: String - hostidentifierHasPrefix: String - hostidentifierHasSuffix: String - hostidentifierIsNil: Boolean - hostidentifierNotNil: Boolean - hostidentifierEqualFold: String - hostidentifierContainsFold: String - """lastSeenAt field predicates""" - lastseenat: Time - lastseenatNEQ: Time - lastseenatIn: [Time!] - lastseenatNotIn: [Time!] - lastseenatGT: Time - lastseenatGTE: Time - lastseenatLT: Time - lastseenatLTE: Time - lastseenatIsNil: Boolean - lastseenatNotNil: Boolean + """agent_identifier field predicates""" + agentIdentifier: String + agentIdentifierNEQ: String + agentIdentifierIn: [String!] + agentIdentifierNotIn: [String!] + agentIdentifierGT: String + agentIdentifierGTE: String + agentIdentifierLT: String + agentIdentifierLTE: String + agentIdentifierContains: String + agentIdentifierHasPrefix: String + agentIdentifierHasSuffix: String + agentIdentifierIsNil: Boolean + agentIdentifierNotNil: Boolean + agentIdentifierEqualFold: String + agentIdentifierContainsFold: String + """host_identifier field predicates""" + hostIdentifier: String + hostIdentifierNEQ: String + hostIdentifierIn: [String!] + hostIdentifierNotIn: [String!] + hostIdentifierGT: String + hostIdentifierGTE: String + hostIdentifierLT: String + hostIdentifierLTE: String + hostIdentifierContains: String + hostIdentifierHasPrefix: String + hostIdentifierHasSuffix: String + hostIdentifierIsNil: Boolean + hostIdentifierNotNil: Boolean + hostIdentifierEqualFold: String + hostIdentifierContainsFold: String + """host_primary_ip field predicates""" + hostPrimaryIP: String + hostPrimaryIPNEQ: String + hostPrimaryIPIn: [String!] + hostPrimaryIPNotIn: [String!] + hostPrimaryIPGT: String + hostPrimaryIPGTE: String + hostPrimaryIPLT: String + hostPrimaryIPLTE: String + hostPrimaryIPContains: String + hostPrimaryIPHasPrefix: String + hostPrimaryIPHasSuffix: String + hostPrimaryIPIsNil: Boolean + hostPrimaryIPNotNil: Boolean + hostPrimaryIPEqualFold: String + hostPrimaryIPContainsFold: String + """host_platform field predicates""" + hostPlatform: SessionSessionHostPlatform + hostPlatformNEQ: SessionSessionHostPlatform + hostPlatformIn: [SessionSessionHostPlatform!] + hostPlatformNotIn: [SessionSessionHostPlatform!] + """last_seen_at field predicates""" + lastSeenAt: Time + lastSeenAtNEQ: Time + lastSeenAtIn: [Time!] + lastSeenAtNotIn: [Time!] + lastSeenAtGT: Time + lastSeenAtGTE: Time + lastSeenAtLT: Time + lastSeenAtLTE: Time + lastSeenAtIsNil: Boolean + lastSeenAtNotNil: Boolean """tags edge predicates""" hasTags: Boolean hasTagsWith: [TagWhereInput!] @@ -1315,15 +1376,15 @@ input TagWhereInput { type Task implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """Timestamp of when the task was claimed, null if not yet claimed""" - claimedat: Time @goField(name: "ClaimedAt", forceResolver: false) + claimedAt: Time """Timestamp of when execution of the task started, null if not yet started""" - execstartedat: Time @goField(name: "ExecStartedAt", forceResolver: false) + execStartedAt: Time """Timestamp of when execution of the task finished, null if not yet finished""" - execfinishedat: Time @goField(name: "ExecFinishedAt", forceResolver: false) + execFinishedAt: Time """Output from executing the task""" output: String """Error, if any, produced while executing the Task""" @@ -1363,57 +1424,57 @@ input TaskWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time - """claimedAt field predicates""" - claimedat: Time - claimedatNEQ: Time - claimedatIn: [Time!] - claimedatNotIn: [Time!] - claimedatGT: Time - claimedatGTE: Time - claimedatLT: Time - claimedatLTE: Time - claimedatIsNil: Boolean - claimedatNotNil: Boolean - """execStartedAt field predicates""" - execstartedat: Time - execstartedatNEQ: Time - execstartedatIn: [Time!] - execstartedatNotIn: [Time!] - execstartedatGT: Time - execstartedatGTE: Time - execstartedatLT: Time - execstartedatLTE: Time - execstartedatIsNil: Boolean - execstartedatNotNil: Boolean - """execFinishedAt field predicates""" - execfinishedat: Time - execfinishedatNEQ: Time - execfinishedatIn: [Time!] - execfinishedatNotIn: [Time!] - execfinishedatGT: Time - execfinishedatGTE: Time - execfinishedatLT: Time - execfinishedatLTE: Time - execfinishedatIsNil: Boolean - execfinishedatNotNil: Boolean + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time + """claimed_at field predicates""" + claimedAt: Time + claimedAtNEQ: Time + claimedAtIn: [Time!] + claimedAtNotIn: [Time!] + claimedAtGT: Time + claimedAtGTE: Time + claimedAtLT: Time + claimedAtLTE: Time + claimedAtIsNil: Boolean + claimedAtNotNil: Boolean + """exec_started_at field predicates""" + execStartedAt: Time + execStartedAtNEQ: Time + execStartedAtIn: [Time!] + execStartedAtNotIn: [Time!] + execStartedAtGT: Time + execStartedAtGTE: Time + execStartedAtLT: Time + execStartedAtLTE: Time + execStartedAtIsNil: Boolean + execStartedAtNotNil: Boolean + """exec_finished_at field predicates""" + execFinishedAt: Time + execFinishedAtNEQ: Time + execFinishedAtIn: [Time!] + execFinishedAtNotIn: [Time!] + execFinishedAtGT: Time + execFinishedAtGTE: Time + execFinishedAtLT: Time + execFinishedAtLTE: Time + execFinishedAtIsNil: Boolean + execFinishedAtNotNil: Boolean """output field predicates""" output: String outputNEQ: String @@ -1456,15 +1517,15 @@ input TaskWhereInput { type Tome implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """Name of the tome""" name: String! """Information about the tome""" description: String! """JSON string describing what parameters are used with the tome""" - parameters: String + paramDefs: String """Eldritch script that will be executed when the tome is run""" eldritch: String! files: [File!] @@ -1499,24 +1560,24 @@ input TomeWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time """name field predicates""" name: String nameNEQ: String @@ -1545,22 +1606,22 @@ input TomeWhereInput { descriptionHasSuffix: String descriptionEqualFold: String descriptionContainsFold: String - """parameters field predicates""" - parameters: String - parametersNEQ: String - parametersIn: [String!] - parametersNotIn: [String!] - parametersGT: String - parametersGTE: String - parametersLT: String - parametersLTE: String - parametersContains: String - parametersHasPrefix: String - parametersHasSuffix: String - parametersIsNil: Boolean - parametersNotNil: Boolean - parametersEqualFold: String - parametersContainsFold: String + """param_defs field predicates""" + paramDefs: String + paramDefsNEQ: String + paramDefsIn: [String!] + paramDefsNotIn: [String!] + paramDefsGT: String + paramDefsGTE: String + paramDefsLT: String + paramDefsLTE: String + paramDefsContains: String + paramDefsHasPrefix: String + paramDefsHasSuffix: String + paramDefsIsNil: Boolean + paramDefsNotNil: Boolean + paramDefsEqualFold: String + paramDefsContainsFold: String """eldritch field predicates""" eldritch: String eldritchNEQ: String @@ -1586,11 +1647,12 @@ Input was generated by ent. input UpdateSessionInput { """A human readable identifier for the session.""" name: String - clearHostname: Boolean """The hostname of the system the session is running on.""" hostname: String + clearHostname: Boolean addTagIDs: [ID!] removeTagIDs: [ID!] + clearTags: Boolean } """ UpdateTagInput is used for update Tag object. @@ -1603,6 +1665,7 @@ input UpdateTagInput { kind: TagTagKind addSessionIDs: [ID!] removeSessionIDs: [ID!] + clearSessions: Boolean } """ UpdateUserInput is used for update User object. @@ -1612,22 +1675,22 @@ input UpdateUserInput { """The name displayed for the user""" name: String """URL to the user's profile photo.""" - photourl: String + photoURL: String """True if the user is active and able to authenticate""" - isactivated: Boolean + isActivated: Boolean """True if the user is an Admin""" - isadmin: Boolean + isAdmin: Boolean } type User implements Node { id: ID! """The name displayed for the user""" name: String! """URL to the user's profile photo.""" - photourl: String! @goField(name: "PhotoURL", forceResolver: false) + photoURL: String! """True if the user is active and able to authenticate""" - isactivated: Boolean! @goField(name: "IsActivated", forceResolver: false) + isActivated: Boolean! """True if the user is an Admin""" - isadmin: Boolean! @goField(name: "IsAdmin", forceResolver: false) + isAdmin: Boolean! } """ UserWhereInput is used for filtering User objects. @@ -1646,7 +1709,7 @@ input UserWhereInput { idGTE: ID idLT: ID idLTE: ID - """Name field predicates""" + """name field predicates""" name: String nameNEQ: String nameIn: [String!] @@ -1660,26 +1723,26 @@ input UserWhereInput { nameHasSuffix: String nameEqualFold: String nameContainsFold: String - """PhotoURL field predicates""" - photourl: String - photourlNEQ: String - photourlIn: [String!] - photourlNotIn: [String!] - photourlGT: String - photourlGTE: String - photourlLT: String - photourlLTE: String - photourlContains: String - photourlHasPrefix: String - photourlHasSuffix: String - photourlEqualFold: String - photourlContainsFold: String - """IsActivated field predicates""" - isactivated: Boolean - isactivatedNEQ: Boolean - """IsAdmin field predicates""" - isadmin: Boolean - isadminNEQ: Boolean + """photo_url field predicates""" + photoURL: String + photoURLNEQ: String + photoURLIn: [String!] + photoURLNotIn: [String!] + photoURLGT: String + photoURLGTE: String + photoURLLT: String + photoURLLTE: String + photoURLContains: String + photoURLHasPrefix: String + photoURLHasSuffix: String + photoURLEqualFold: String + photoURLContainsFold: String + """is_activated field predicates""" + isActivated: Boolean + isActivatedNEQ: Boolean + """is_admin field predicates""" + isAdmin: Boolean + isAdminNEQ: Boolean } `, BuiltIn: false}, {Name: "../schema/scalars.graphql", Input: `scalar Time`, BuiltIn: false}, @@ -1731,6 +1794,12 @@ input UserWhereInput { """The hostname of the system the session is running on.""" hostname: String! + """The platform the agent is operating on.""" + hostPlatform: SessionSessionHostPlatform! + + """The IP address of the hosts primary interface (if available).""" + hostPrimaryIP: String + """Unique identifier of the session, each running instance will be different.""" sessionIdentifier: String! @@ -1749,7 +1818,7 @@ input SubmitTaskResultInput { execStartedAt: Time! """Timestamp of when the task execution finished (set only if it has completed). Format as RFC3339Nano.""" - execFinishedAt: Time + execFinishedAt: Time """ Output captured as the result of task execution. @@ -1758,7 +1827,7 @@ input SubmitTaskResultInput { output: String! """Error message captured as the result of task execution failure.""" - error: String + error: String }`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/tavern/graphql/gqlgen.yml b/tavern/graphql/gqlgen.yml index cce8ead8d..e92b9ab77 100644 --- a/tavern/graphql/gqlgen.yml +++ b/tavern/graphql/gqlgen.yml @@ -44,15 +44,18 @@ models: # ent.Noder is the new interface generated by the Node template. - github.com/kcarretto/realm/tavern/ent.Noder # - entgo.io/contrib/entgql/internal/todo/ent.Noder - + # Custom mapping from GraphQL `TagKind` # to the generated `tag.Kind` enum type. TagKind: model: - - github.com/kcarretto/realm/tavern/ent/tag.Kind + - github.com/kcarretto/realm/tavern/ent/tag.Kind + SessionHostPlatform: + model: + - github.com/kcarretto/realm/tavern/ent/session.HostPlatform # Custom mapping from GraphQL `CredentialKind` # to the generated `credential.Kind` enum type. # CredentialKind: # model: - # - github.com/kcarretto/realm/tavern/ent/credential.Kind \ No newline at end of file + # - github.com/kcarretto/realm/tavern/ent/credential.Kind \ No newline at end of file diff --git a/tavern/graphql/job_test.go b/tavern/graphql/job_test.go index b59e72cd9..a554e4f94 100644 --- a/tavern/graphql/job_test.go +++ b/tavern/graphql/job_test.go @@ -11,7 +11,7 @@ import ( "github.com/99designs/gqlgen/client" "github.com/99designs/gqlgen/graphql/handler" - "github.com/kcarretto/realm/tavern/auth/authtest" + "github.com/kcarretto/realm/tavern/auth" "github.com/kcarretto/realm/tavern/ent" "github.com/kcarretto/realm/tavern/ent/enttest" "github.com/kcarretto/realm/tavern/graphql" @@ -25,7 +25,7 @@ func TestCreateJob(t *testing.T) { ctx := context.Background() graph := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") defer graph.Close() - srv := authtest.Middleware(handler.NewDefaultServer(graphql.NewSchema(graph))) + srv := auth.AuthDisabledMiddleware(handler.NewDefaultServer(graphql.NewSchema(graph)), graph) gqlClient := client.New(srv) // Initialize sample data @@ -159,7 +159,7 @@ func TestCreateJob(t *testing.T) { func newCreateJobTest(gqlClient *client.Client, sessionIDs []int, input ent.CreateJobInput, checks ...func(t *testing.T, id int, err error)) func(t *testing.T) { return func(t *testing.T) { // Define the mutatation for testing, taking the input as a variable - mut := `mutation newCreateJobTest($sessionIDs: [ID!]!, $input: CreateJobInput!) { createJob(sessionIDs:$sessionIDs, input:$input) { + mut := `mutation newCreateJobTest($sessionIDs: [ID!]!, $input: CreateJobInput!) { createJob(sessionIDs:$sessionIDs, input:$input) { id tasks { id diff --git a/tavern/graphql/models/gqlgen_models.go b/tavern/graphql/models/gqlgen_models.go index a432fcc95..17cafe58a 100644 --- a/tavern/graphql/models/gqlgen_models.go +++ b/tavern/graphql/models/gqlgen_models.go @@ -7,6 +7,8 @@ import ( "io" "strconv" "time" + + "github.com/kcarretto/realm/tavern/ent/session" ) type ClaimTasksInput struct { @@ -14,6 +16,10 @@ type ClaimTasksInput struct { Principal string `json:"principal"` // The hostname of the system the session is running on. Hostname string `json:"hostname"` + // The platform the agent is operating on. + HostPlatform session.HostPlatform `json:"hostPlatform"` + // The IP address of the hosts primary interface (if available). + HostPrimaryIP *string `json:"hostPrimaryIP"` // Unique identifier of the session, each running instance will be different. SessionIdentifier string `json:"sessionIdentifier"` // Unique identifier of the underlying host system the session is running on. diff --git a/tavern/graphql/mutation.resolvers.go b/tavern/graphql/mutation.resolvers.go index 7c3e35e59..737595bbb 100644 --- a/tavern/graphql/mutation.resolvers.go +++ b/tavern/graphql/mutation.resolvers.go @@ -2,12 +2,14 @@ package graphql // This file will be automatically regenerated based on the schema, any resolver implementations // will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.26 import ( "context" "fmt" "time" + "github.com/kcarretto/realm/tavern/auth" "github.com/kcarretto/realm/tavern/ent" "github.com/kcarretto/realm/tavern/ent/file" "github.com/kcarretto/realm/tavern/ent/session" @@ -57,17 +59,24 @@ func (r *mutationResolver) CreateJob(ctx context.Context, sessionIDs []int, inpu bundleID = &bundle.ID } - // 6. Create Job + // 6. Get creator from context (if available) + var creatorID *int + if creator := auth.UserFromContext(ctx); creator != nil { + creatorID = &creator.ID + } + + // 7. Create Job job, err := client.Job.Create(). SetInput(input). SetNillableBundleID(bundleID). SetTome(jobTome). + SetNillableCreatorID(creatorID). Save(ctx) if err != nil { return nil, rollback(tx, fmt.Errorf("failed to create job: %w", err)) } - // 7. Create tasks for each session + // 8. Create tasks for each session for _, sid := range sessionIDs { _, err := client.Task.Create(). SetJob(job). @@ -78,12 +87,12 @@ func (r *mutationResolver) CreateJob(ctx context.Context, sessionIDs []int, inpu } } - // 8. Commit the transaction + // 9. Commit the transaction if err := tx.Commit(); err != nil { return nil, rollback(tx, fmt.Errorf("failed to commit transaction: %w", err)) } - // 9. Load the job with our non transactional client (cannot use transaction after commit) + // 10. Load the job with our non transactional client (cannot use transaction after commit) job, err = r.client.Job.Get(ctx, job.ID) if err != nil { return nil, fmt.Errorf("failed to load created job: %w", err) @@ -122,6 +131,8 @@ func (r *mutationResolver) ClaimTasks(ctx context.Context, input models.ClaimTas _, err = r.client.Session.Create(). SetPrincipal(input.Principal). SetHostname(input.Hostname). + SetNillableHostPrimaryIP(input.HostPrimaryIP). + SetHostPlatform(input.HostPlatform). SetIdentifier(input.SessionIdentifier). SetAgentIdentifier(input.AgentIdentifier). SetHostIdentifier(input.HostIdentifier). @@ -139,6 +150,8 @@ func (r *mutationResolver) ClaimTasks(ctx context.Context, input models.ClaimTas agentSession, err = agentSession.Update(). SetPrincipal(input.Principal). SetHostname(input.Hostname). + SetNillableHostPrimaryIP(input.HostPrimaryIP). + SetHostPlatform(input.HostPlatform). SetIdentifier(input.SessionIdentifier). SetAgentIdentifier(input.AgentIdentifier). SetHostIdentifier(input.HostIdentifier). diff --git a/tavern/graphql/query.resolvers.go b/tavern/graphql/query.resolvers.go index f979a4b9b..58f9fdf9f 100644 --- a/tavern/graphql/query.resolvers.go +++ b/tavern/graphql/query.resolvers.go @@ -2,6 +2,7 @@ package graphql // This file will be automatically regenerated based on the schema, any resolver implementations // will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.26 import ( "context" diff --git a/tavern/graphql/query_test.go b/tavern/graphql/query_test.go index 578a7016e..73655bf6b 100644 --- a/tavern/graphql/query_test.go +++ b/tavern/graphql/query_test.go @@ -6,7 +6,7 @@ import ( "github.com/99designs/gqlgen/client" "github.com/99designs/gqlgen/graphql/handler" - "github.com/kcarretto/realm/tavern/auth/authtest" + "github.com/kcarretto/realm/tavern/auth" "github.com/kcarretto/realm/tavern/ent" "github.com/kcarretto/realm/tavern/ent/enttest" "github.com/kcarretto/realm/tavern/graphql" @@ -20,7 +20,7 @@ func TestUsersQuery(t *testing.T) { ctx := context.Background() graph := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") defer graph.Close() - srv := authtest.Middleware(handler.NewDefaultServer(graphql.NewSchema(graph))) + srv := auth.AuthDisabledMiddleware(handler.NewDefaultServer(graphql.NewSchema(graph)), graph) gqlClient := client.New(srv) // Initialize sample data @@ -28,7 +28,7 @@ func TestUsersQuery(t *testing.T) { SetName("bobdylan"). SetIsActivated(false). SetIsAdmin(true). - SetOAuthID("likearollingstone"). + SetOauthID("likearollingstone"). SetPhotoURL("https://upload.wikimedia.org/wikipedia/commons/0/02/Bob_Dylan_-_Azkena_Rock_Festival_2010_2.jpg"). SaveX(ctx) @@ -74,7 +74,7 @@ func TestJobsQuery(t *testing.T) { ctx := context.Background() graph := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") defer graph.Close() - srv := authtest.Middleware(handler.NewDefaultServer(graphql.NewSchema(graph))) + srv := auth.AuthDisabledMiddleware(handler.NewDefaultServer(graphql.NewSchema(graph)), graph) gqlClient := client.New(srv) // Initialize sample data diff --git a/tavern/graphql/schema/ent.graphql b/tavern/graphql/schema/ent.graphql index 62bdadadf..c9095b957 100644 --- a/tavern/graphql/schema/ent.graphql +++ b/tavern/graphql/schema/ent.graphql @@ -32,7 +32,7 @@ input CreateTomeInput { """Information about the tome""" description: String! """JSON string describing what parameters are used with the tome""" - parameters: String + paramDefs: String """Eldritch script that will be executed when the tome is run""" eldritch: String! fileIDs: [ID!] @@ -45,9 +45,9 @@ scalar Cursor type File implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """The name of the file, used to reference it for downloads""" name: String! """The size of the file in bytes""" @@ -86,24 +86,24 @@ input FileWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time """name field predicates""" name: String nameNEQ: String @@ -145,9 +145,9 @@ input FileWhereInput { type Job implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """Name of the job""" name: String! """Value of parameters that were specified for the job (as a JSON string).""" @@ -155,6 +155,7 @@ type Job implements Node { tome: Tome! bundle: File tasks: [Task!] + creator: User } """Ordering options for Job connections""" input JobOrder { @@ -186,24 +187,24 @@ input JobWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time """name field predicates""" name: String nameNEQ: String @@ -243,6 +244,9 @@ input JobWhereInput { """tasks edge predicates""" hasTasks: Boolean hasTasksWith: [TaskWhereInput!] + """creator edge predicates""" + hasCreator: Boolean + hasCreatorWith: [UserWhereInput!] } """ An object with an ID. @@ -296,11 +300,15 @@ type Session implements Node { """Unique identifier for the session. Unique to each instance of the session.""" identifier: String! """Identifies the agent that the session is running as (e.g. 'imix').""" - agentidentifier: String @goField(name: "AgentIdentifier", forceResolver: false) + agentIdentifier: String """Unique identifier for the host the session is running on.""" - hostidentifier: String @goField(name: "HostIdentifier", forceResolver: false) + hostIdentifier: String + """Primary interface IP address reported by the agent.""" + hostPrimaryIP: String + """Platform the agent is operating on.""" + hostPlatform: SessionSessionHostPlatform! """Timestamp of when a task was last claimed or updated for a target""" - lastseenat: Time @goField(name: "LastSeenAt", forceResolver: false) + lastSeenAt: Time tags: [Tag!] tasks: [Task!] } @@ -315,6 +323,14 @@ input SessionOrder { enum SessionOrderField { LAST_SEEN_AT } +"""SessionSessionHostPlatform is enum for the field host_platform""" +enum SessionSessionHostPlatform @goModel(model: "github.com/kcarretto/realm/tavern/ent/session.HostPlatform") { + Windows + Linux + MacOS + BSD + Unknown +} """ SessionWhereInput is used for filtering Session objects. Input was generated by ent. @@ -392,49 +408,70 @@ input SessionWhereInput { identifierHasSuffix: String identifierEqualFold: String identifierContainsFold: String - """agentIdentifier field predicates""" - agentidentifier: String - agentidentifierNEQ: String - agentidentifierIn: [String!] - agentidentifierNotIn: [String!] - agentidentifierGT: String - agentidentifierGTE: String - agentidentifierLT: String - agentidentifierLTE: String - agentidentifierContains: String - agentidentifierHasPrefix: String - agentidentifierHasSuffix: String - agentidentifierIsNil: Boolean - agentidentifierNotNil: Boolean - agentidentifierEqualFold: String - agentidentifierContainsFold: String - """hostIdentifier field predicates""" - hostidentifier: String - hostidentifierNEQ: String - hostidentifierIn: [String!] - hostidentifierNotIn: [String!] - hostidentifierGT: String - hostidentifierGTE: String - hostidentifierLT: String - hostidentifierLTE: String - hostidentifierContains: String - hostidentifierHasPrefix: String - hostidentifierHasSuffix: String - hostidentifierIsNil: Boolean - hostidentifierNotNil: Boolean - hostidentifierEqualFold: String - hostidentifierContainsFold: String - """lastSeenAt field predicates""" - lastseenat: Time - lastseenatNEQ: Time - lastseenatIn: [Time!] - lastseenatNotIn: [Time!] - lastseenatGT: Time - lastseenatGTE: Time - lastseenatLT: Time - lastseenatLTE: Time - lastseenatIsNil: Boolean - lastseenatNotNil: Boolean + """agent_identifier field predicates""" + agentIdentifier: String + agentIdentifierNEQ: String + agentIdentifierIn: [String!] + agentIdentifierNotIn: [String!] + agentIdentifierGT: String + agentIdentifierGTE: String + agentIdentifierLT: String + agentIdentifierLTE: String + agentIdentifierContains: String + agentIdentifierHasPrefix: String + agentIdentifierHasSuffix: String + agentIdentifierIsNil: Boolean + agentIdentifierNotNil: Boolean + agentIdentifierEqualFold: String + agentIdentifierContainsFold: String + """host_identifier field predicates""" + hostIdentifier: String + hostIdentifierNEQ: String + hostIdentifierIn: [String!] + hostIdentifierNotIn: [String!] + hostIdentifierGT: String + hostIdentifierGTE: String + hostIdentifierLT: String + hostIdentifierLTE: String + hostIdentifierContains: String + hostIdentifierHasPrefix: String + hostIdentifierHasSuffix: String + hostIdentifierIsNil: Boolean + hostIdentifierNotNil: Boolean + hostIdentifierEqualFold: String + hostIdentifierContainsFold: String + """host_primary_ip field predicates""" + hostPrimaryIP: String + hostPrimaryIPNEQ: String + hostPrimaryIPIn: [String!] + hostPrimaryIPNotIn: [String!] + hostPrimaryIPGT: String + hostPrimaryIPGTE: String + hostPrimaryIPLT: String + hostPrimaryIPLTE: String + hostPrimaryIPContains: String + hostPrimaryIPHasPrefix: String + hostPrimaryIPHasSuffix: String + hostPrimaryIPIsNil: Boolean + hostPrimaryIPNotNil: Boolean + hostPrimaryIPEqualFold: String + hostPrimaryIPContainsFold: String + """host_platform field predicates""" + hostPlatform: SessionSessionHostPlatform + hostPlatformNEQ: SessionSessionHostPlatform + hostPlatformIn: [SessionSessionHostPlatform!] + hostPlatformNotIn: [SessionSessionHostPlatform!] + """last_seen_at field predicates""" + lastSeenAt: Time + lastSeenAtNEQ: Time + lastSeenAtIn: [Time!] + lastSeenAtNotIn: [Time!] + lastSeenAtGT: Time + lastSeenAtGTE: Time + lastSeenAtLT: Time + lastSeenAtLTE: Time + lastSeenAtIsNil: Boolean + lastSeenAtNotNil: Boolean """tags edge predicates""" hasTags: Boolean hasTagsWith: [TagWhereInput!] @@ -509,15 +546,15 @@ input TagWhereInput { type Task implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """Timestamp of when the task was claimed, null if not yet claimed""" - claimedat: Time @goField(name: "ClaimedAt", forceResolver: false) + claimedAt: Time """Timestamp of when execution of the task started, null if not yet started""" - execstartedat: Time @goField(name: "ExecStartedAt", forceResolver: false) + execStartedAt: Time """Timestamp of when execution of the task finished, null if not yet finished""" - execfinishedat: Time @goField(name: "ExecFinishedAt", forceResolver: false) + execFinishedAt: Time """Output from executing the task""" output: String """Error, if any, produced while executing the Task""" @@ -557,57 +594,57 @@ input TaskWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time - """claimedAt field predicates""" - claimedat: Time - claimedatNEQ: Time - claimedatIn: [Time!] - claimedatNotIn: [Time!] - claimedatGT: Time - claimedatGTE: Time - claimedatLT: Time - claimedatLTE: Time - claimedatIsNil: Boolean - claimedatNotNil: Boolean - """execStartedAt field predicates""" - execstartedat: Time - execstartedatNEQ: Time - execstartedatIn: [Time!] - execstartedatNotIn: [Time!] - execstartedatGT: Time - execstartedatGTE: Time - execstartedatLT: Time - execstartedatLTE: Time - execstartedatIsNil: Boolean - execstartedatNotNil: Boolean - """execFinishedAt field predicates""" - execfinishedat: Time - execfinishedatNEQ: Time - execfinishedatIn: [Time!] - execfinishedatNotIn: [Time!] - execfinishedatGT: Time - execfinishedatGTE: Time - execfinishedatLT: Time - execfinishedatLTE: Time - execfinishedatIsNil: Boolean - execfinishedatNotNil: Boolean + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time + """claimed_at field predicates""" + claimedAt: Time + claimedAtNEQ: Time + claimedAtIn: [Time!] + claimedAtNotIn: [Time!] + claimedAtGT: Time + claimedAtGTE: Time + claimedAtLT: Time + claimedAtLTE: Time + claimedAtIsNil: Boolean + claimedAtNotNil: Boolean + """exec_started_at field predicates""" + execStartedAt: Time + execStartedAtNEQ: Time + execStartedAtIn: [Time!] + execStartedAtNotIn: [Time!] + execStartedAtGT: Time + execStartedAtGTE: Time + execStartedAtLT: Time + execStartedAtLTE: Time + execStartedAtIsNil: Boolean + execStartedAtNotNil: Boolean + """exec_finished_at field predicates""" + execFinishedAt: Time + execFinishedAtNEQ: Time + execFinishedAtIn: [Time!] + execFinishedAtNotIn: [Time!] + execFinishedAtGT: Time + execFinishedAtGTE: Time + execFinishedAtLT: Time + execFinishedAtLTE: Time + execFinishedAtIsNil: Boolean + execFinishedAtNotNil: Boolean """output field predicates""" output: String outputNEQ: String @@ -650,15 +687,15 @@ input TaskWhereInput { type Tome implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """Name of the tome""" name: String! """Information about the tome""" description: String! """JSON string describing what parameters are used with the tome""" - parameters: String + paramDefs: String """Eldritch script that will be executed when the tome is run""" eldritch: String! files: [File!] @@ -693,24 +730,24 @@ input TomeWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time """name field predicates""" name: String nameNEQ: String @@ -739,22 +776,22 @@ input TomeWhereInput { descriptionHasSuffix: String descriptionEqualFold: String descriptionContainsFold: String - """parameters field predicates""" - parameters: String - parametersNEQ: String - parametersIn: [String!] - parametersNotIn: [String!] - parametersGT: String - parametersGTE: String - parametersLT: String - parametersLTE: String - parametersContains: String - parametersHasPrefix: String - parametersHasSuffix: String - parametersIsNil: Boolean - parametersNotNil: Boolean - parametersEqualFold: String - parametersContainsFold: String + """param_defs field predicates""" + paramDefs: String + paramDefsNEQ: String + paramDefsIn: [String!] + paramDefsNotIn: [String!] + paramDefsGT: String + paramDefsGTE: String + paramDefsLT: String + paramDefsLTE: String + paramDefsContains: String + paramDefsHasPrefix: String + paramDefsHasSuffix: String + paramDefsIsNil: Boolean + paramDefsNotNil: Boolean + paramDefsEqualFold: String + paramDefsContainsFold: String """eldritch field predicates""" eldritch: String eldritchNEQ: String @@ -780,11 +817,12 @@ Input was generated by ent. input UpdateSessionInput { """A human readable identifier for the session.""" name: String - clearHostname: Boolean """The hostname of the system the session is running on.""" hostname: String + clearHostname: Boolean addTagIDs: [ID!] removeTagIDs: [ID!] + clearTags: Boolean } """ UpdateTagInput is used for update Tag object. @@ -797,6 +835,7 @@ input UpdateTagInput { kind: TagTagKind addSessionIDs: [ID!] removeSessionIDs: [ID!] + clearSessions: Boolean } """ UpdateUserInput is used for update User object. @@ -806,22 +845,22 @@ input UpdateUserInput { """The name displayed for the user""" name: String """URL to the user's profile photo.""" - photourl: String + photoURL: String """True if the user is active and able to authenticate""" - isactivated: Boolean + isActivated: Boolean """True if the user is an Admin""" - isadmin: Boolean + isAdmin: Boolean } type User implements Node { id: ID! """The name displayed for the user""" name: String! """URL to the user's profile photo.""" - photourl: String! @goField(name: "PhotoURL", forceResolver: false) + photoURL: String! """True if the user is active and able to authenticate""" - isactivated: Boolean! @goField(name: "IsActivated", forceResolver: false) + isActivated: Boolean! """True if the user is an Admin""" - isadmin: Boolean! @goField(name: "IsAdmin", forceResolver: false) + isAdmin: Boolean! } """ UserWhereInput is used for filtering User objects. @@ -840,7 +879,7 @@ input UserWhereInput { idGTE: ID idLT: ID idLTE: ID - """Name field predicates""" + """name field predicates""" name: String nameNEQ: String nameIn: [String!] @@ -854,24 +893,24 @@ input UserWhereInput { nameHasSuffix: String nameEqualFold: String nameContainsFold: String - """PhotoURL field predicates""" - photourl: String - photourlNEQ: String - photourlIn: [String!] - photourlNotIn: [String!] - photourlGT: String - photourlGTE: String - photourlLT: String - photourlLTE: String - photourlContains: String - photourlHasPrefix: String - photourlHasSuffix: String - photourlEqualFold: String - photourlContainsFold: String - """IsActivated field predicates""" - isactivated: Boolean - isactivatedNEQ: Boolean - """IsAdmin field predicates""" - isadmin: Boolean - isadminNEQ: Boolean + """photo_url field predicates""" + photoURL: String + photoURLNEQ: String + photoURLIn: [String!] + photoURLNotIn: [String!] + photoURLGT: String + photoURLGTE: String + photoURLLT: String + photoURLLTE: String + photoURLContains: String + photoURLHasPrefix: String + photoURLHasSuffix: String + photoURLEqualFold: String + photoURLContainsFold: String + """is_activated field predicates""" + isActivated: Boolean + isActivatedNEQ: Boolean + """is_admin field predicates""" + isAdmin: Boolean + isAdminNEQ: Boolean } diff --git a/tavern/graphql/schema/inputs.graphql b/tavern/graphql/schema/inputs.graphql index 79aae24df..87bd316b3 100644 --- a/tavern/graphql/schema/inputs.graphql +++ b/tavern/graphql/schema/inputs.graphql @@ -5,6 +5,12 @@ input ClaimTasksInput { """The hostname of the system the session is running on.""" hostname: String! + """The platform the agent is operating on.""" + hostPlatform: SessionSessionHostPlatform! + + """The IP address of the hosts primary interface (if available).""" + hostPrimaryIP: String + """Unique identifier of the session, each running instance will be different.""" sessionIdentifier: String! @@ -23,7 +29,7 @@ input SubmitTaskResultInput { execStartedAt: Time! """Timestamp of when the task execution finished (set only if it has completed). Format as RFC3339Nano.""" - execFinishedAt: Time + execFinishedAt: Time """ Output captured as the result of task execution. @@ -32,5 +38,5 @@ input SubmitTaskResultInput { output: String! """Error message captured as the result of task execution failure.""" - error: String + error: String } \ No newline at end of file diff --git a/tavern/graphql/session_test.go b/tavern/graphql/session_test.go index a1baea8d6..799512677 100644 --- a/tavern/graphql/session_test.go +++ b/tavern/graphql/session_test.go @@ -8,7 +8,7 @@ import ( "github.com/99designs/gqlgen/client" "github.com/99designs/gqlgen/graphql/handler" - "github.com/kcarretto/realm/tavern/auth/authtest" + "github.com/kcarretto/realm/tavern/auth" "github.com/kcarretto/realm/tavern/ent" "github.com/kcarretto/realm/tavern/ent/enttest" "github.com/kcarretto/realm/tavern/ent/session" @@ -23,7 +23,7 @@ func TestSessionMutations(t *testing.T) { ctx := context.Background() graph := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") defer graph.Close() - srv := authtest.Middleware(handler.NewDefaultServer(graphql.NewSchema(graph))) + srv := auth.AuthDisabledMiddleware(handler.NewDefaultServer(graphql.NewSchema(graph)), graph) gqlClient := client.New(srv) // Initialize sample data @@ -114,6 +114,7 @@ mutation newClaimTasksTest($input: ClaimTasksInput!) { expected := map[string]any{ "principal": "newuser", "hostname": "NEW_HOSTNAME", + "hostPlatform": session.HostPlatformWindows, "sessionIdentifier": expectedIdentifier, "hostIdentifier": "NEW_HOST_ID", "agentIdentifier": "NEW_AGENT_ID", @@ -143,6 +144,8 @@ mutation newClaimTasksTest($input: ClaimTasksInput!) { expected := map[string]any{ "principal": "admin", "hostname": "SOME_HOSTNAME", + "hostPlatform": session.HostPlatformMacOS, + "hostPrimaryIP": "10.0.0.1", "sessionIdentifier": "SOME_ID", "hostIdentifier": "SOME_HOST_ID", "agentIdentifier": "SOME_AGENT_ID", @@ -163,6 +166,8 @@ mutation newClaimTasksTest($input: ClaimTasksInput!) { assert.Equal(t, expected["sessionIdentifier"], testSession.Identifier) assert.Equal(t, expected["hostIdentifier"], testSession.HostIdentifier) assert.Equal(t, expected["agentIdentifier"], testSession.AgentIdentifier) + assert.Equal(t, expected["hostPlatform"], testSession.HostPlatform) + assert.Equal(t, expected["hostPrimaryIP"], testSession.HostPrimaryIP) }) }) diff --git a/tavern/graphql/tag_test.go b/tavern/graphql/tag_test.go index a0d786b40..d3cbdfdd5 100644 --- a/tavern/graphql/tag_test.go +++ b/tavern/graphql/tag_test.go @@ -7,7 +7,7 @@ import ( "github.com/99designs/gqlgen/client" "github.com/99designs/gqlgen/graphql/handler" - "github.com/kcarretto/realm/tavern/auth/authtest" + "github.com/kcarretto/realm/tavern/auth" "github.com/kcarretto/realm/tavern/ent" "github.com/kcarretto/realm/tavern/ent/enttest" "github.com/kcarretto/realm/tavern/ent/tag" @@ -21,7 +21,7 @@ func TestTagMutations(t *testing.T) { ctx := context.Background() graph := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") defer graph.Close() - srv := authtest.Middleware(handler.NewDefaultServer(graphql.NewSchema(graph))) + srv := auth.AuthDisabledMiddleware(handler.NewDefaultServer(graphql.NewSchema(graph)), graph) gqlClient := client.New(srv) // Initialize sample data diff --git a/tavern/graphql/tome_test.go b/tavern/graphql/tome_test.go index ef566eab1..468bb234f 100644 --- a/tavern/graphql/tome_test.go +++ b/tavern/graphql/tome_test.go @@ -6,7 +6,7 @@ import ( "github.com/99designs/gqlgen/client" "github.com/99designs/gqlgen/graphql/handler" - "github.com/kcarretto/realm/tavern/auth/authtest" + "github.com/kcarretto/realm/tavern/auth" "github.com/kcarretto/realm/tavern/ent" "github.com/kcarretto/realm/tavern/ent/enttest" "github.com/kcarretto/realm/tavern/graphql" @@ -19,7 +19,7 @@ func TestTomeMutations(t *testing.T) { ctx := context.Background() graph := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") defer graph.Close() - srv := authtest.Middleware(handler.NewDefaultServer(graphql.NewSchema(graph))) + srv := auth.AuthDisabledMiddleware(handler.NewDefaultServer(graphql.NewSchema(graph)), graph) gqlClient := client.New(srv) // Initialize sample data diff --git a/tavern/graphql/user_test.go b/tavern/graphql/user_test.go index eb1a047cb..1ea52f5cc 100644 --- a/tavern/graphql/user_test.go +++ b/tavern/graphql/user_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/kcarretto/realm/tavern/auth/authtest" + "github.com/kcarretto/realm/tavern/auth" "github.com/kcarretto/realm/tavern/ent" "github.com/kcarretto/realm/tavern/ent/enttest" "github.com/kcarretto/realm/tavern/graphql" @@ -22,15 +22,15 @@ func TestUserMutations(t *testing.T) { ctx := context.Background() graph := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") defer graph.Close() - srv := authtest.Middleware(handler.NewDefaultServer(graphql.NewSchema(graph))) + srv := auth.AuthDisabledMiddleware(handler.NewDefaultServer(graphql.NewSchema(graph)), graph) gqlClient := client.New(srv) // Initialize sample data testUser := graph.User.Create(). SetName("bobdylan"). - SetIsActivated(false). + SetIsActivated(true). SetIsAdmin(true). - SetOAuthID("likearollingstone"). + SetOauthID("likearollingstone"). SetPhotoURL("https://upload.wikimedia.org/wikipedia/commons/0/02/Bob_Dylan_-_Azkena_Rock_Festival_2010_2.jpg"). SaveX(ctx) @@ -65,9 +65,9 @@ func newUpdateUserTest(gqlClient *client.Client, id int, input ent.UpdateUserInp client.Var("userID", id), client.Var("input", map[string]interface{}{ "name": input.Name, - "isactivated": input.IsActivated, - "isadmin": input.IsAdmin, - "photourl": input.PhotoURL, + "isActivated": input.IsActivated, + "isAdmin": input.IsAdmin, + "photoURL": input.PhotoURL, }), ) diff --git a/tavern/internal/www/schema.graphql b/tavern/internal/www/schema.graphql index 7065eac81..92c37cad4 100644 --- a/tavern/internal/www/schema.graphql +++ b/tavern/internal/www/schema.graphql @@ -37,7 +37,7 @@ input CreateTomeInput { """Information about the tome""" description: String! """JSON string describing what parameters are used with the tome""" - parameters: String + paramDefs: String """Eldritch script that will be executed when the tome is run""" eldritch: String! fileIDs: [ID!] @@ -50,9 +50,9 @@ scalar Cursor type File implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """The name of the file, used to reference it for downloads""" name: String! """The size of the file in bytes""" @@ -91,24 +91,24 @@ input FileWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time """name field predicates""" name: String nameNEQ: String @@ -150,9 +150,9 @@ input FileWhereInput { type Job implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """Name of the job""" name: String! """Value of parameters that were specified for the job (as a JSON string).""" @@ -160,6 +160,7 @@ type Job implements Node { tome: Tome! bundle: File tasks: [Task!] + creator: User } """Ordering options for Job connections""" input JobOrder { @@ -191,24 +192,24 @@ input JobWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time """name field predicates""" name: String nameNEQ: String @@ -248,6 +249,9 @@ input JobWhereInput { """tasks edge predicates""" hasTasks: Boolean hasTasksWith: [TaskWhereInput!] + """creator edge predicates""" + hasCreator: Boolean + hasCreatorWith: [UserWhereInput!] } """ An object with an ID. @@ -301,11 +305,15 @@ type Session implements Node { """Unique identifier for the session. Unique to each instance of the session.""" identifier: String! """Identifies the agent that the session is running as (e.g. 'imix').""" - agentidentifier: String @goField(name: "AgentIdentifier", forceResolver: false) + agentIdentifier: String """Unique identifier for the host the session is running on.""" - hostidentifier: String @goField(name: "HostIdentifier", forceResolver: false) + hostIdentifier: String + """Primary interface IP address reported by the agent.""" + hostPrimaryIP: String + """Platform the agent is operating on.""" + hostPlatform: SessionSessionHostPlatform! """Timestamp of when a task was last claimed or updated for a target""" - lastseenat: Time @goField(name: "LastSeenAt", forceResolver: false) + lastSeenAt: Time tags: [Tag!] tasks: [Task!] } @@ -320,6 +328,14 @@ input SessionOrder { enum SessionOrderField { LAST_SEEN_AT } +"""SessionSessionHostPlatform is enum for the field host_platform""" +enum SessionSessionHostPlatform @goModel(model: "github.com/kcarretto/realm/tavern/ent/session.HostPlatform") { + Windows + Linux + MacOS + BSD + Unknown +} """ SessionWhereInput is used for filtering Session objects. Input was generated by ent. @@ -397,49 +413,70 @@ input SessionWhereInput { identifierHasSuffix: String identifierEqualFold: String identifierContainsFold: String - """agentIdentifier field predicates""" - agentidentifier: String - agentidentifierNEQ: String - agentidentifierIn: [String!] - agentidentifierNotIn: [String!] - agentidentifierGT: String - agentidentifierGTE: String - agentidentifierLT: String - agentidentifierLTE: String - agentidentifierContains: String - agentidentifierHasPrefix: String - agentidentifierHasSuffix: String - agentidentifierIsNil: Boolean - agentidentifierNotNil: Boolean - agentidentifierEqualFold: String - agentidentifierContainsFold: String - """hostIdentifier field predicates""" - hostidentifier: String - hostidentifierNEQ: String - hostidentifierIn: [String!] - hostidentifierNotIn: [String!] - hostidentifierGT: String - hostidentifierGTE: String - hostidentifierLT: String - hostidentifierLTE: String - hostidentifierContains: String - hostidentifierHasPrefix: String - hostidentifierHasSuffix: String - hostidentifierIsNil: Boolean - hostidentifierNotNil: Boolean - hostidentifierEqualFold: String - hostidentifierContainsFold: String - """lastSeenAt field predicates""" - lastseenat: Time - lastseenatNEQ: Time - lastseenatIn: [Time!] - lastseenatNotIn: [Time!] - lastseenatGT: Time - lastseenatGTE: Time - lastseenatLT: Time - lastseenatLTE: Time - lastseenatIsNil: Boolean - lastseenatNotNil: Boolean + """agent_identifier field predicates""" + agentIdentifier: String + agentIdentifierNEQ: String + agentIdentifierIn: [String!] + agentIdentifierNotIn: [String!] + agentIdentifierGT: String + agentIdentifierGTE: String + agentIdentifierLT: String + agentIdentifierLTE: String + agentIdentifierContains: String + agentIdentifierHasPrefix: String + agentIdentifierHasSuffix: String + agentIdentifierIsNil: Boolean + agentIdentifierNotNil: Boolean + agentIdentifierEqualFold: String + agentIdentifierContainsFold: String + """host_identifier field predicates""" + hostIdentifier: String + hostIdentifierNEQ: String + hostIdentifierIn: [String!] + hostIdentifierNotIn: [String!] + hostIdentifierGT: String + hostIdentifierGTE: String + hostIdentifierLT: String + hostIdentifierLTE: String + hostIdentifierContains: String + hostIdentifierHasPrefix: String + hostIdentifierHasSuffix: String + hostIdentifierIsNil: Boolean + hostIdentifierNotNil: Boolean + hostIdentifierEqualFold: String + hostIdentifierContainsFold: String + """host_primary_ip field predicates""" + hostPrimaryIP: String + hostPrimaryIPNEQ: String + hostPrimaryIPIn: [String!] + hostPrimaryIPNotIn: [String!] + hostPrimaryIPGT: String + hostPrimaryIPGTE: String + hostPrimaryIPLT: String + hostPrimaryIPLTE: String + hostPrimaryIPContains: String + hostPrimaryIPHasPrefix: String + hostPrimaryIPHasSuffix: String + hostPrimaryIPIsNil: Boolean + hostPrimaryIPNotNil: Boolean + hostPrimaryIPEqualFold: String + hostPrimaryIPContainsFold: String + """host_platform field predicates""" + hostPlatform: SessionSessionHostPlatform + hostPlatformNEQ: SessionSessionHostPlatform + hostPlatformIn: [SessionSessionHostPlatform!] + hostPlatformNotIn: [SessionSessionHostPlatform!] + """last_seen_at field predicates""" + lastSeenAt: Time + lastSeenAtNEQ: Time + lastSeenAtIn: [Time!] + lastSeenAtNotIn: [Time!] + lastSeenAtGT: Time + lastSeenAtGTE: Time + lastSeenAtLT: Time + lastSeenAtLTE: Time + lastSeenAtIsNil: Boolean + lastSeenAtNotNil: Boolean """tags edge predicates""" hasTags: Boolean hasTagsWith: [TagWhereInput!] @@ -514,15 +551,15 @@ input TagWhereInput { type Task implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """Timestamp of when the task was claimed, null if not yet claimed""" - claimedat: Time @goField(name: "ClaimedAt", forceResolver: false) + claimedAt: Time """Timestamp of when execution of the task started, null if not yet started""" - execstartedat: Time @goField(name: "ExecStartedAt", forceResolver: false) + execStartedAt: Time """Timestamp of when execution of the task finished, null if not yet finished""" - execfinishedat: Time @goField(name: "ExecFinishedAt", forceResolver: false) + execFinishedAt: Time """Output from executing the task""" output: String """Error, if any, produced while executing the Task""" @@ -562,57 +599,57 @@ input TaskWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time - """claimedAt field predicates""" - claimedat: Time - claimedatNEQ: Time - claimedatIn: [Time!] - claimedatNotIn: [Time!] - claimedatGT: Time - claimedatGTE: Time - claimedatLT: Time - claimedatLTE: Time - claimedatIsNil: Boolean - claimedatNotNil: Boolean - """execStartedAt field predicates""" - execstartedat: Time - execstartedatNEQ: Time - execstartedatIn: [Time!] - execstartedatNotIn: [Time!] - execstartedatGT: Time - execstartedatGTE: Time - execstartedatLT: Time - execstartedatLTE: Time - execstartedatIsNil: Boolean - execstartedatNotNil: Boolean - """execFinishedAt field predicates""" - execfinishedat: Time - execfinishedatNEQ: Time - execfinishedatIn: [Time!] - execfinishedatNotIn: [Time!] - execfinishedatGT: Time - execfinishedatGTE: Time - execfinishedatLT: Time - execfinishedatLTE: Time - execfinishedatIsNil: Boolean - execfinishedatNotNil: Boolean + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time + """claimed_at field predicates""" + claimedAt: Time + claimedAtNEQ: Time + claimedAtIn: [Time!] + claimedAtNotIn: [Time!] + claimedAtGT: Time + claimedAtGTE: Time + claimedAtLT: Time + claimedAtLTE: Time + claimedAtIsNil: Boolean + claimedAtNotNil: Boolean + """exec_started_at field predicates""" + execStartedAt: Time + execStartedAtNEQ: Time + execStartedAtIn: [Time!] + execStartedAtNotIn: [Time!] + execStartedAtGT: Time + execStartedAtGTE: Time + execStartedAtLT: Time + execStartedAtLTE: Time + execStartedAtIsNil: Boolean + execStartedAtNotNil: Boolean + """exec_finished_at field predicates""" + execFinishedAt: Time + execFinishedAtNEQ: Time + execFinishedAtIn: [Time!] + execFinishedAtNotIn: [Time!] + execFinishedAtGT: Time + execFinishedAtGTE: Time + execFinishedAtLT: Time + execFinishedAtLTE: Time + execFinishedAtIsNil: Boolean + execFinishedAtNotNil: Boolean """output field predicates""" output: String outputNEQ: String @@ -655,15 +692,15 @@ input TaskWhereInput { type Tome implements Node { id: ID! """Timestamp of when this ent was created""" - createdat: Time! @goField(name: "CreatedAt", forceResolver: false) + createdAt: Time! """Timestamp of when this ent was last updated""" - lastmodifiedat: Time! @goField(name: "LastModifiedAt", forceResolver: false) + lastModifiedAt: Time! """Name of the tome""" name: String! """Information about the tome""" description: String! """JSON string describing what parameters are used with the tome""" - parameters: String + paramDefs: String """Eldritch script that will be executed when the tome is run""" eldritch: String! files: [File!] @@ -698,24 +735,24 @@ input TomeWhereInput { idGTE: ID idLT: ID idLTE: ID - """createdAt field predicates""" - createdat: Time - createdatNEQ: Time - createdatIn: [Time!] - createdatNotIn: [Time!] - createdatGT: Time - createdatGTE: Time - createdatLT: Time - createdatLTE: Time - """lastModifiedAt field predicates""" - lastmodifiedat: Time - lastmodifiedatNEQ: Time - lastmodifiedatIn: [Time!] - lastmodifiedatNotIn: [Time!] - lastmodifiedatGT: Time - lastmodifiedatGTE: Time - lastmodifiedatLT: Time - lastmodifiedatLTE: Time + """created_at field predicates""" + createdAt: Time + createdAtNEQ: Time + createdAtIn: [Time!] + createdAtNotIn: [Time!] + createdAtGT: Time + createdAtGTE: Time + createdAtLT: Time + createdAtLTE: Time + """last_modified_at field predicates""" + lastModifiedAt: Time + lastModifiedAtNEQ: Time + lastModifiedAtIn: [Time!] + lastModifiedAtNotIn: [Time!] + lastModifiedAtGT: Time + lastModifiedAtGTE: Time + lastModifiedAtLT: Time + lastModifiedAtLTE: Time """name field predicates""" name: String nameNEQ: String @@ -744,22 +781,22 @@ input TomeWhereInput { descriptionHasSuffix: String descriptionEqualFold: String descriptionContainsFold: String - """parameters field predicates""" - parameters: String - parametersNEQ: String - parametersIn: [String!] - parametersNotIn: [String!] - parametersGT: String - parametersGTE: String - parametersLT: String - parametersLTE: String - parametersContains: String - parametersHasPrefix: String - parametersHasSuffix: String - parametersIsNil: Boolean - parametersNotNil: Boolean - parametersEqualFold: String - parametersContainsFold: String + """param_defs field predicates""" + paramDefs: String + paramDefsNEQ: String + paramDefsIn: [String!] + paramDefsNotIn: [String!] + paramDefsGT: String + paramDefsGTE: String + paramDefsLT: String + paramDefsLTE: String + paramDefsContains: String + paramDefsHasPrefix: String + paramDefsHasSuffix: String + paramDefsIsNil: Boolean + paramDefsNotNil: Boolean + paramDefsEqualFold: String + paramDefsContainsFold: String """eldritch field predicates""" eldritch: String eldritchNEQ: String @@ -785,11 +822,12 @@ Input was generated by ent. input UpdateSessionInput { """A human readable identifier for the session.""" name: String - clearHostname: Boolean """The hostname of the system the session is running on.""" hostname: String + clearHostname: Boolean addTagIDs: [ID!] removeTagIDs: [ID!] + clearTags: Boolean } """ UpdateTagInput is used for update Tag object. @@ -802,6 +840,7 @@ input UpdateTagInput { kind: TagTagKind addSessionIDs: [ID!] removeSessionIDs: [ID!] + clearSessions: Boolean } """ UpdateUserInput is used for update User object. @@ -811,22 +850,22 @@ input UpdateUserInput { """The name displayed for the user""" name: String """URL to the user's profile photo.""" - photourl: String + photoURL: String """True if the user is active and able to authenticate""" - isactivated: Boolean + isActivated: Boolean """True if the user is an Admin""" - isadmin: Boolean + isAdmin: Boolean } type User implements Node { id: ID! """The name displayed for the user""" name: String! """URL to the user's profile photo.""" - photourl: String! @goField(name: "PhotoURL", forceResolver: false) + photoURL: String! """True if the user is active and able to authenticate""" - isactivated: Boolean! @goField(name: "IsActivated", forceResolver: false) + isActivated: Boolean! """True if the user is an Admin""" - isadmin: Boolean! @goField(name: "IsAdmin", forceResolver: false) + isAdmin: Boolean! } """ UserWhereInput is used for filtering User objects. @@ -845,7 +884,7 @@ input UserWhereInput { idGTE: ID idLT: ID idLTE: ID - """Name field predicates""" + """name field predicates""" name: String nameNEQ: String nameIn: [String!] @@ -859,26 +898,26 @@ input UserWhereInput { nameHasSuffix: String nameEqualFold: String nameContainsFold: String - """PhotoURL field predicates""" - photourl: String - photourlNEQ: String - photourlIn: [String!] - photourlNotIn: [String!] - photourlGT: String - photourlGTE: String - photourlLT: String - photourlLTE: String - photourlContains: String - photourlHasPrefix: String - photourlHasSuffix: String - photourlEqualFold: String - photourlContainsFold: String - """IsActivated field predicates""" - isactivated: Boolean - isactivatedNEQ: Boolean - """IsAdmin field predicates""" - isadmin: Boolean - isadminNEQ: Boolean + """photo_url field predicates""" + photoURL: String + photoURLNEQ: String + photoURLIn: [String!] + photoURLNotIn: [String!] + photoURLGT: String + photoURLGTE: String + photoURLLT: String + photoURLLTE: String + photoURLContains: String + photoURLHasPrefix: String + photoURLHasSuffix: String + photoURLEqualFold: String + photoURLContainsFold: String + """is_activated field predicates""" + isActivated: Boolean + isActivatedNEQ: Boolean + """is_admin field predicates""" + isAdmin: Boolean + isAdminNEQ: Boolean } input ClaimTasksInput { """The identity the session is authenticated as (e.g. 'root')""" @@ -887,6 +926,12 @@ input ClaimTasksInput { """The hostname of the system the session is running on.""" hostname: String! + """The platform the agent is operating on.""" + hostPlatform: SessionSessionHostPlatform! + + """The IP address of the hosts primary interface (if available).""" + hostPrimaryIP: String + """Unique identifier of the session, each running instance will be different.""" sessionIdentifier: String! @@ -905,7 +950,7 @@ input SubmitTaskResultInput { execStartedAt: Time! """Timestamp of when the task execution finished (set only if it has completed). Format as RFC3339Nano.""" - execFinishedAt: Time + execFinishedAt: Time """ Output captured as the result of task execution. @@ -914,7 +959,7 @@ input SubmitTaskResultInput { output: String! """Error message captured as the result of task execution failure.""" - error: String + error: String }type Mutation { ### # Job